8#include <AMReX_buildInfo.H>
43#ifdef REMORA_USE_NETCDF
56amrex::Vector<std::string>
BCNames = {
"xlo",
"ylo",
"zlo",
"xhi",
"yhi",
"zhi"};
66 BL_PROFILE(
"REMORA::REMORA()");
67 if (ParallelDescriptor::IOProcessor()) {
70 const char* buildgithash = amrex::buildInfoGetBuildGitHash();
71 const char* buildgitname = amrex::buildInfoGetBuildGitName();
73 if (strlen(remora_hash) > 0) {
74 amrex::Print() <<
"\n"
75 <<
"REMORA git hash: " << remora_hash <<
"\n";
77 if (strlen(amrex_hash) > 0) {
78 amrex::Print() <<
"AMReX git hash: " << amrex_hash <<
"\n";
80 if (strlen(buildgithash) > 0) {
81 amrex::Print() << buildgitname <<
" git hash: " << buildgithash <<
"\n";
84 amrex::Print() <<
"\n";
99 int nlevs_max = max_level + 1;
101 istep.resize(nlevs_max, 0);
103 for (
int lev = 1; lev <= max_level; ++lev) {
109 t_new.resize(nlevs_max, 0.0_rt);
110 t_old.resize(nlevs_max, -1.e100_rt);
111 dt.resize(nlevs_max, 1.e100_rt);
129 for (
int lev = 0; lev < max_level; ++lev)
131 amrex::Print() <<
"Refinement ratio at level " << lev <<
" set to be " <<
132 ref_ratio[lev][0] <<
" " << ref_ratio[lev][1] <<
" " << ref_ratio[lev][2] << std::endl;
134 if (ref_ratio[lev][2] != 1)
136 amrex::Print() <<
"********************************************************************************" << std::endl;
137 amrex::Print() <<
"We don't allow refinement in the vertical -- make sure to set ref_ratio = 1 in z" << std::endl;
138 amrex::Print() <<
"It's possible you set amr.ref_ratio when you meant to set amr.ref_ratio_vect " << std::endl;
139 amrex::Print() <<
"********************************************************************************" << std::endl;
157 for (
int i = 1; i <
nscalar; ++i) {
158 cons_names.emplace_back(
"tracer_" + std::to_string(i));
165 BL_PROFILE(
"REMORA::Evolve()");
166 Real cur_time =
t_new[0];
172 amrex::Print() <<
"\nCoarse STEP " << step+1 <<
" starts ..." << std::endl;
179 if (max_level == 0) {
188 amrex::Print() <<
"Coarse STEP " << step+1 <<
" ends." <<
" TIME = " << cur_time
189 <<
" DT = " <<
dt[0] << std::endl;
209#ifdef AMREX_MEM_PROFILING
211 std::ostringstream ss;
212 ss <<
"[STEP " << step+1 <<
"]";
213 MemProfiler::report(ss.str());
239 BL_PROFILE(
"REMORA::post_timestep()");
241#ifdef REMORA_USE_PARTICLES
242 particleData.Redistribute();
247 for (
int lev = finest_level-1; lev >= 0; lev--)
271 BL_PROFILE(
"REMORA::InitData()");
301#ifdef REMORA_USE_MOAB
307 for (
int lev = 1; lev <= finest_level; lev++)
309 advflux_reg[lev].reset(
new YAFluxRegister(grids[lev], grids[lev-1],
310 dmap[lev], dmap[lev-1],
311 geom[lev], geom[lev-1],
312 ref_ratio[lev-1], lev,
ncons));
317 for (
int lev = 0; lev <= finest_level; ++lev)
324 FillPatch(lev,
t_new[lev], *
cons_new[lev],
cons_new,
BCVars::cons_bc,
BdyVars::t, 0,
true,
false,0,0,0.0,*
cons_new[lev]);
325 FillPatch(lev,
t_new[lev], *
xvel_new[lev],
xvel_new,
xvel_bc(),
BdyVars::u, 0,
true,
false,0,0,0.0,*
xvel_new[lev]);
326 FillPatch(lev,
t_new[lev], *
yvel_new[lev],
yvel_new,
yvel_bc(),
BdyVars::v, 0,
true,
false,0,0,0.0,*
yvel_new[lev]);
376 BL_PROFILE(
"REMORA::Construct_REMORAFillPatchers()");
377 amrex::Print() <<
":::Construct_REMORAFillPatchers " << lev << std::endl;
379 auto& ba_fine =
cons_new[lev ]->boxArray();
380 auto& ba_crse =
cons_new[lev-1]->boxArray();
381 auto& dm_fine =
cons_new[lev ]->DistributionMap();
382 auto& dm_crse =
cons_new[lev-1]->DistributionMap();
384 BoxList bl2d_fine = ba_fine.boxList();
385 for (
auto& b : bl2d_fine) {
388 BoxArray ba2d_fine(std::move(bl2d_fine));
390 BoxList bl2d_crse = ba_crse.boxList();
391 for (
auto& b : bl2d_crse) {
394 BoxArray ba2d_crse(std::move(bl2d_crse));
398 FPr_c.emplace_back(ba_fine, dm_fine, geom[lev] ,
399 ba_crse, dm_crse, geom[lev-1],
401 FPr_u.emplace_back(convert(ba_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
402 convert(ba_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
404 FPr_v.emplace_back(convert(ba_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
405 convert(ba_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
407 FPr_w.emplace_back(convert(ba_fine, IntVect(0,0,1)), dm_fine, geom[lev] ,
408 convert(ba_crse, IntVect(0,0,1)), dm_crse, geom[lev-1],
411 FPr_ubar.emplace_back(convert(ba2d_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
412 convert(ba2d_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
414 FPr_vbar.emplace_back(convert(ba2d_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
415 convert(ba2d_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
425 BL_PROFILE(
"REMORA::Define_REMORAFillPatchers()");
426 amrex::Print() <<
":::Define_REMORAFillPatchers " << lev << std::endl;
428 auto& ba_fine =
cons_new[lev ]->boxArray();
429 auto& ba_crse =
cons_new[lev-1]->boxArray();
430 auto& dm_fine =
cons_new[lev ]->DistributionMap();
431 auto& dm_crse =
cons_new[lev-1]->DistributionMap();
433 BoxList bl2d_fine = ba_fine.boxList();
434 for (
auto& b : bl2d_fine) {
437 BoxArray ba2d_fine(std::move(bl2d_fine));
439 BoxList bl2d_crse = ba_crse.boxList();
440 for (
auto& b : bl2d_crse) {
443 BoxArray ba2d_crse(std::move(bl2d_crse));
448 FPr_c[lev-1].Define(ba_fine, dm_fine, geom[lev] ,
449 ba_crse, dm_crse, geom[lev-1],
451 FPr_u[lev-1].Define(convert(ba_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
452 convert(ba_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
454 FPr_v[lev-1].Define(convert(ba_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
455 convert(ba_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
457 FPr_w[lev-1].Define(convert(ba_fine, IntVect(0,0,1)), dm_fine, geom[lev] ,
458 convert(ba_crse, IntVect(0,0,1)), dm_crse, geom[lev-1],
461 FPr_ubar[lev-1].Define(convert(ba2d_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
462 convert(ba2d_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
464 FPr_vbar[lev-1].Define(convert(ba2d_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
465 convert(ba2d_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
472 BL_PROFILE(
"REMORA::restart()");
485 BL_PROFILE(
"REMORA::set_zeta()");
489#ifdef REMORA_USE_NETCDF
492 amrex::Print() <<
"Calling init_zeta_from_netcdf on level " << lev << std::endl;
494 amrex::Print() <<
"Sea surface height loaded from netcdf file \n " << std::endl;
496 Real dummy_time = 0.0_rt;
501 Abort(
"Don't know this ic_type!");
503 vec_zeta[lev]->FillBoundary(geom[lev].periodicity());
513 BL_PROFILE(
"REMORA::bathymetry()");
525#ifdef REMORA_USE_NETCDF
526 amrex::Print() <<
"Calling init_bathymetry_from_netcdf " << std::endl;
528 amrex::Print() <<
"Bathymetry loaded from netcdf file \n " << std::endl;
531 amrex::Abort(
"Unknown IC_Type");
538 vec_h[lev]->FillBoundary(geom[lev].periodicity());
539 vec_h[lev]->EnforcePeriodicity(geom[lev].periodicity());
545 Real dummy_time = 0.0_rt;
549 vec_h[lev]->FillBoundary(geom[lev].periodicity());
550 vec_h[lev]->EnforcePeriodicity(geom[lev].periodicity());
563 Real dummy_time = 0.0_rt;
564 ParallelCopy(*
vec_h[lev].get(), *
vec_h_full_domain[lev].get(), 0, 0, 1,IntVect(1,1,0),IntVect(1,1,0));
565 ParallelCopy(*
vec_h[lev].get(), *
vec_h_full_domain[lev].get(), 0, 1, 1,IntVect(1,1,0),IntVect(1,1,0));
579 BL_PROFILE(
"REMORA::set_coriolis()");
585#ifdef REMORA_USE_NETCDF
588 amrex::Print() <<
"Calling init_coriolis_from_netcdf " << std::endl;
590 amrex::Print() <<
"Coriolis loaded from netcdf file \n" << std::endl;
592 Real dummy_time = 0.0_rt;
597 Abort(
"Don't know this coriolis_type!");
602 vec_fcor[lev]->EnforcePeriodicity(geom[lev].periodicity());
608 BL_PROFILE(
"REMORA::init_set_vmix()");
616 Abort(
"Don't know this vertical mixing type");
625 BL_PROFILE(
"REMORA::set_analytic_vmix()");
631 for (
int n = 0; n <
ncons; n++) {
646#ifdef REMORA_USE_NETCDF
648 amrex::Print() <<
"Calling init_masks_from_netcdf level " << lev << std::endl;
650 amrex::Print() <<
"Masks loaded from netcdf file \n " << std::endl;
652 Real dummy_time = 0.0_rt;
668 BL_PROFILE(
"REMORA::set_hmixcoef()");
673 Real lev_scale = 1.0_rt;
676 for (
int l = 0; l < lev; ++l) {
677 rf *= std::sqrt(
static_cast<Real
>(ref_ratio[l][0]) *
static_cast<Real
>(ref_ratio[l][1]));
679 lev_scale = 1.0_rt / rf;
689 for (
int n = 0; n <
ncons; n++) {
722 for (
int n = 0; n <
ncons; n++) {
730 amrex::Gpu::LaunchSafeGuard lsg(
true);
731 Real denom_min = amrex::ReduceMin(*
vec_pm[lev], *
vec_pn[lev], 0,
732 [=] AMREX_GPU_HOST_DEVICE (Box
const& bx,
733 Array4<Real const>
const& pm,
734 Array4<Real const>
const& pn) -> Real
736 Real local_min = 1.0e200_rt;
737 amrex::Loop(bx, [=,&local_min] (
int i,
int j,
int)
noexcept
739 local_min = amrex::min(local_min, pm(i,j,0) * pn(i,j,0));
744 ParallelDescriptor::ReduceRealMin(denom_min);
745 if (denom_min <= 0.0_rt) {
746 Abort(
"scaled_to_grid: found non-positive pm*pn (grid metrics must be > 0)");
749 Real grdmax = amrex::ReduceMax(*
vec_pm[lev], *
vec_pn[lev], 0,
750 [=] AMREX_GPU_HOST_DEVICE (Box
const& bx,
751 Array4<Real const>
const& pm,
752 Array4<Real const>
const& pn) -> Real
754 Real local_max = 0.0_rt;
755 amrex::Loop(bx, [=,&local_max] (
int i,
int j,
int)
noexcept
757 Real denom = pm(i,j,0) * pn(i,j,0);
758 if (denom > 0.0_rt) {
759 Real G = std::sqrt(1.0_rt / denom);
760 local_max = amrex::max(local_max, G);
766 ParallelDescriptor::ReduceRealMax(grdmax);
767 if (grdmax <= 0.0_rt) {
768 Abort(
"scaled_to_grid: grdmax <= 0");
777 for (
int l = 0; l < lev; ++l) {
778 rf *= std::sqrt(
static_cast<Real
>(ref_ratio[l][0]) *
static_cast<Real
>(ref_ratio[l][1]));
780 lev_scale = 1.0_rt / rf;
784 Real cff = visc0 / grdmax;
789 amrex::Gpu::DeviceVector<Real> diff0_d(
ncons);
790 amrex::Gpu::copy(amrex::Gpu::hostToDevice,
793 Real
const* diff0_ptr = diff0_d.data();
795 for (MFIter mfi(*
vec_visc2_r[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
797 const Box& bx = mfi.validbox();
798 auto pm =
vec_pm[lev]->const_array(mfi);
799 auto pn =
vec_pn[lev]->const_array(mfi);
803 int ncons_local =
ncons;
804 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (
int i,
int j,
int)
noexcept
806 Real denom = pm(i,j,0) * pn(i,j,0);
807 Real grdscl = (denom > 0.0_rt) ? std::sqrt(1.0_rt / denom) : 0.0_rt;
808 visc2_r(i,j,0) = cff * grdscl;
810 for (
int n = 0; n < ncons_local; n++) {
811 diff2(i,j,0,n) = ((diff0_ptr[n] * lev_scale) / grdmax) * grdscl;
823 for (MFIter mfi(*
vec_visc2_p[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
825 const Box& bx = mfi.validbox();
829 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (
int i,
int j,
int)
noexcept
831 visc2_p(i,j,0) = 0.25_rt * (
848 Real visc_min_all =
vec_visc2_r[lev]->min(0,0,
false);
849 Real visc_max_all =
vec_visc2_r[lev]->max(0,0,
false);
852 amrex::Gpu::LaunchSafeGuard lsg_diag(
true);
854 [=] AMREX_GPU_HOST_DEVICE (Box
const& bx,
855 Array4<Real const>
const& visc2,
856 Array4<Real const>
const& mskr) -> Real
858 Real local_min = 1.0e200_rt;
859 amrex::Loop(bx, [=,&local_min] (
int i,
int j,
int)
noexcept
861 if (mskr(i,j,0) > 0.0_rt) {
862 local_min = amrex::min(local_min, visc2(i,j,0));
867 ParallelDescriptor::ReduceRealMin(visc_min_wet);
870 [=] AMREX_GPU_HOST_DEVICE (Box
const& bx,
871 Array4<Real const>
const& visc2,
872 Array4<Real const>
const& mskr) -> Real
874 Real local_max = -1.0e200_rt;
875 amrex::Loop(bx, [=,&local_max] (
int i,
int j,
int)
noexcept
877 if (mskr(i,j,0) > 0.0_rt) {
878 local_max = amrex::max(local_max, visc2(i,j,0));
883 ParallelDescriptor::ReduceRealMax(visc_max_wet);
887 [=] AMREX_GPU_HOST_DEVICE (Box
const& bx,
888 Array4<Real const>
const& visc2,
889 Array4<Real const>
const& mskr) -> Real
891 Real local_min = 1.0e200_rt;
892 amrex::Loop(bx, [=,&local_min] (
int i,
int j,
int)
noexcept
894 const Real v = (mskr(i,j,0) > 0.0_rt) ? visc2(i,j,0) : 0.0_rt;
895 local_min = amrex::min(local_min, v);
899 ParallelDescriptor::ReduceRealMin(visc_min_mask0);
902 [=] AMREX_GPU_HOST_DEVICE (Box
const& bx,
903 Array4<Real const>
const& visc2,
904 Array4<Real const>
const& mskr) -> Real
906 Real local_max = -1.0e200_rt;
907 amrex::Loop(bx, [=,&local_max] (
int i,
int j,
int)
noexcept
909 const Real v = (mskr(i,j,0) > 0.0_rt) ? visc2(i,j,0) : 0.0_rt;
910 local_max = amrex::max(local_max, v);
914 ParallelDescriptor::ReduceRealMax(visc_max_mask0);
915 if (ParallelDescriptor::IOProcessor() && lev == 0)
917 Print() <<
"\nHorizontal mixing scaled by grid metric\n";
918 Print() <<
"grdmax = " << grdmax <<
"\n";
920 Print() <<
"AMR scaling (linear) lev_scale = " << lev_scale <<
"\n";
922 Print() <<
"visc2(all) min/max = "
923 << visc_min_all <<
" / "
924 << visc_max_all <<
"\n";
925 Print() <<
"visc2(wet,k=0) min/max = "
926 << visc_min_wet <<
" / "
927 << visc_max_wet <<
"\n";
928 Print() <<
"visc2(mask->0) min/max = "
929 << visc_min_mask0 <<
" / "
930 << visc_max_mask0 <<
"\n";
934 Abort(
"Don't know this horizontal mixing type");
941 for (
int n = 0; n <
ncons; n++) {
953 BL_PROFILE(
"REMORA::init_flat_bathymetry()");
954 vec_h[lev]->setVal(-geom[0].ProbLo()[2]);
963 BL_PROFILE(
"REMORA::set_smflux()");
967#ifdef REMORA_USE_NETCDF
982 BL_PROFILE(
"REMORA::set_wind()");
986#ifdef REMORA_USE_NETCDF
1010 vec_qair[lev]->FillBoundary(geom[lev].periodicity());
1054 BL_PROFILE(
"REMORA::init_only()");
1056 t_old[lev] = time - 1.e200_rt;
1067 vec_ru[lev]->setVal(0.0_rt);
1068 vec_rv[lev]->setVal(0.0_rt);
1078#ifdef REMORA_USE_NETCDF
1084 amrex::Error(
"NetCDF climatology file name must be provided via input");
1114 amrex::Print() <<
"Calling init_bdry_from_netcdf at level " << lev << std::endl;
1116 amrex::Print() <<
"Boundary data loaded from netcdf file \n " << std::endl;
1123 amrex::Error(
"NetCDF forcing file name must be provided via input for winds");
1136 amrex::Error(
"NetCDF forcing file name must be provided via input for surface momentum fluxes");
1204 amrex::Error(
"NetCDF forcing file name must be provided via input for longwave radiation");
1218 amrex::Error(
"NetCDF river file name must be provided via input for rivers");
1220 auto dom = geom[0].Domain();
1221 int nz = dom.length(2);
1243 amrex::Print() <<
"Reading high resolution bathymetry data" << std::endl;
1246 amrex::Print() <<
"Done reading in high resolution bathymetry data" << std::endl;
1250 Abort(
"Not compiled with NetCDF, but selected boundary conditions require NetCDF");
1253 Abort(
"Not compiled with NetCDF, but using river sources requires NetCDF");
1271#ifdef REMORA_USE_NETCDF
1273 amrex::Print() <<
"Calling init_data_from_netcdf " << std::endl;
1276 amrex::Print() <<
"Initial data loaded from netcdf file \n " << std::endl;
1280 Abort(
"Need to specify ic_type");
1292#ifdef REMORA_USE_NETCDF
1294 amrex::Print() <<
"Calling init_data_from_netcdf on level " << lev << std::endl;
1297 amrex::Print() <<
"Initial data loaded from netcdf file on level " << lev << std::endl;
1301 Abort(
"Need to specify ic_type");
1304 amrex::Abort(
"Need to specify T init procedure");
1309 xvel_new[lev]->OverrideSync(geom[lev].periodicity());
1310 yvel_new[lev]->OverrideSync(geom[lev].periodicity());
1311 zvel_new[lev]->OverrideSync(geom[lev].periodicity());
1330 BL_PROFILE(
"REMORA::ReadParameters()");
1333 bool noprefix_max_step = pp.queryAdd(
"max_step",
max_step);
1334 bool noprefix_stop_time = pp.queryAdd(
"stop_time",
stop_time);
1335 bool remora_max_step = pp.queryAdd(
"remora.max_step",
max_step);
1336 bool remora_stop_time = pp.queryAdd(
"remora.stop_time",
stop_time);
1337 if (remora_max_step and noprefix_max_step) {
1338 Abort(
"remora.max_step and max_step are both specified. Please use only one!");
1340 if (remora_stop_time and noprefix_stop_time) {
1341 Abort(
"remora.stop_time and stop_time are both specified. Please use only one!");
1346 ParmParse pp_amr(
"amr");
1348 pp.queryAdd(
"nscalar",
nscalar);
1350 amrex::Abort(
"remora.nscalar must be at least 1");
1358 pp_amr.queryAdd(
"check_int",
check_int);
1371 if (pp.contains(
"data_log"))
1373 int num_datalogs = pp.countval(
"data_log");
1376 pp.queryarr(
"data_log",
datalogname,0,num_datalogs);
1377 for (
int i = 0; i < num_datalogs; i++)
1386 pp.queryAdd(
"sum_period" ,
sum_per);
1390 amrex::Abort(
"remora.file_min_digits must be non-negative");
1394 pp.queryAdd(
"cfl",
cfl);
1407 amrex::Abort(
"Dt is over-specfied");
1420 amrex::Abort(
"Time substepping is not yet implemented. amr.do_substep must be 0");
1444 std::string plotfile_type_str =
"amrex";
1445 pp.queryAdd(
"plotfile_type", plotfile_type_str);
1446 if (plotfile_type_str ==
"amrex") {
1448 }
else if (plotfile_type_str ==
"netcdf" || plotfile_type_str ==
"NetCDF") {
1450#ifdef REMORA_USE_NETCDF
1455 auto dom = geom[0].Domain();
1456 int nx = dom.length(0) + 2;
1457 int ny = dom.length(1) + 2;
1458 int nz = dom.length(2);
1462 / (nx * ny * 64.0_rt * (
NC3D*nz +
NC2D)));
1467 amrex::Warning(
"NetCDF output for a single timestep appears to exceed 2GB. NetCDF output may not work. See Documentation for information about tested MPICH versions.");
1473 Real est_hist_file_size =
NCH2D * nx * ny * 64.0_rt + nt_out * nx * ny * 64.0_rt * (
NC3D*nz +
NC2D);
1474 if (est_hist_file_size > 1.6e10) {
1475 amrex::Warning(
"WARNING: NetCDF history file may be larger than 2GB limit. Consider setting remora.chunk_history_file=true");
1479 Print() <<
"NetCDF history files will have " <<
steps_per_history_file <<
" steps per file." << std::endl;
1483 amrex::Print() <<
"User selected plotfile_type = " << plotfile_type_str << std::endl;
1484 amrex::Abort(
"Dont know this plotfile_type");
1486#ifndef REMORA_USE_NETCDF
1489 amrex::Abort(
"Please compile with NetCDF in order to enable NetCDF plotfiles");
1493#ifdef REMORA_USE_NETCDF
1501 for (
int lev = 0; lev <= max_level; lev++)
1503 const std::string nc_file_names = amrex::Concatenate(
"nc_init_file_",lev,1);
1504 const std::string nc_bathy_file_names = amrex::Concatenate(
"nc_grid_file_",lev,1);
1506 if (pp.contains(nc_file_names.c_str()))
1508 int num_files = pp.countval(nc_file_names.c_str());
1509 int num_bathy_files = pp.countval(nc_bathy_file_names.c_str());
1510 if (num_files != num_bathy_files) {
1511 amrex::Error(
"Must have same number of netcdf files for grid info as for solution");
1518 pp.queryarr(nc_file_names.c_str() ,
nc_init_file[lev] ,0,num_files);
1519 pp.queryarr(nc_bathy_file_names.c_str(),
nc_grid_file[lev],0,num_files);
1529 if (pp.contains(
"nc_frc_file")) {
1530 int num_files = pp.countval(
"nc_frc_file");
1532 pp.queryarr(
"nc_frc_file",
nc_frc_file, 0, num_files);
1536 if (pp.contains(
"nc_river_file")) {
1537 int num_files = pp.countval(
"nc_river_file");
1539 pp.queryarr(
"nc_river_file",
nc_riv_file, 0, num_files);
1543 if (pp.contains(
"nc_clim_his_file")) {
1544 int num_files = pp.countval(
"nc_clim_his_file");
1583 amrex::Abort(
"hires_grid_level must be less than or equal to amr.max_level");
1586#ifdef REMORA_USE_PARTICLES
1587 readTracersParams();
1597 BL_PROFILE(
"REMORA::AverageDown()");
1598 for (
int lev = finest_level-1; lev >= 0; --lev)
1610 BL_PROFILE(
"REMORA::AverageDownTo()");
1612 0,
cons_new[crse_lev]->nComp(), refRatio(crse_lev));
1614 0,
vec_Zt_avg1[crse_lev]->nComp(), refRatio(crse_lev));
1616 Array<MultiFab*,AMREX_SPACEDIM> faces_crse;
1617 Array<MultiFab*,AMREX_SPACEDIM> faces_fine;
1618 faces_crse[0] =
xvel_new[crse_lev];
1619 faces_crse[1] =
yvel_new[crse_lev];
1620 faces_crse[2] =
zvel_new[crse_lev];
1622 faces_fine[0] =
xvel_new[crse_lev+1];
1623 faces_fine[1] =
yvel_new[crse_lev+1];
1624 faces_fine[2] =
zvel_new[crse_lev+1];
1626 average_down_faces(GetArrOfConstPtrs(faces_fine), faces_crse,
1627 refRatio(crse_lev),geom[crse_lev]);
1638 auto const& crsema = vec_mf[crse_lev]->arrays();
1639 auto const& finema = vec_mf[crse_lev+1]->const_arrays();
1641 auto ref_ratio_crse = refRatio(crse_lev);
1642 ParallelFor(*vec_mf[crse_lev], nghost_crse, 1,
1643 [=] AMREX_GPU_DEVICE (
int box_no,
int i,
int j,
int k,
int n)
noexcept
1645 amrex_avgdown(i,j,k,n,crsema[box_no],finema[box_no],0,0,ref_ratio_crse);
1647 Gpu::streamSynchronize();
amrex::Vector< std::string > BCNames
PlotfileType
plotfile format
std::unique_ptr< ProblemBase > amrex_probinit(const amrex_real *problo, const amrex_real *probhi) AMREX_ATTRIBUTE_WEAK
Function to init the physical bounds of the domain and instantiate a Problem derived from ProblemBase...
A class to hold and interpolate time series data read from a NetCDF file.
static PlotfileType plotfile_type
Native or NetCDF plotfile output.
std::string nc_grid_file_hires
Grid file for high resolution bathymetry.
void FillCoarsePatchPC(int lev, amrex::Real time, amrex::MultiFab *mf_fine, amrex::MultiFab *mf_crse, const int bccomp, const int bdy_var_type=BdyVars::null, const int icomp=0, const bool fill_all=true, const int n_not_fill=0, const int icomp_calc=0, const amrex::Real dt=amrex::Real(0.0), const amrex::MultiFab &mf_calc=amrex::MultiFab())
fill an entire multifab by interpolating from the coarser level using the piecewise constant interpol...
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_EminusP
evaporation minus precipitation [kg/m^2/s], defined at rho-points
amrex::Vector< std::string > nc_riv_file
NetCDF river file(s)
void allocate_bathymetry_full_domain()
Allocate multifabs for storing full-domain bathymetry data.
std::string riv_time_varname
Name of time field for river time.
int foextrap_periodic_bc() const noexcept
amrex::Vector< std::string > nc_clim_his_file
NetCDF climatology history file(s)
int ncons
Number of conserved scalars in the state (temperature + salt + passive scalars)
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rv2d
v velocity RHS (2D, includes horizontal and vertical advection)
static amrex::Real fixed_dt
User specified fixed baroclinic time step.
amrex::Real last_plot_file_time
Simulation time when we last output a plotfile.
int zvel_bc() const noexcept
void init_bathymetry_from_netcdf(int lev)
Bathymetry data initialization from NetCDF file.
void init_bcs()
Read in boundary parameters from input file and set up data structures.
int xvel_bc() const noexcept
void calculate_nodal_masks(int lev)
Calculate u-, v-, and psi-point masks based on rho-point masks after analytic initialization.
std::unique_ptr< NCTimeSeries > qair_data_from_file
Data container for specific humidity read from file.
static amrex::Real previousCPUTimeUsed
Accumulator variable for CPU time used thusfar.
amrex::Vector< std::string > cons_names
Names of scalars for plotfile output.
amrex::Vector< std::unique_ptr< amrex::YAFluxRegister > > advflux_reg
array of flux registers for refluxing in multilevel
std::unique_ptr< NCTimeSeries > sustr_data_from_file
Data container for u-component surface momentum flux read from file.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_fcor
coriolis factor (2D)
void init_gls_vmix(int lev, SolverChoice solver_choice)
Initialize GLS variables.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_h
Bathymetry data (2D, positive valued, h in ROMS)
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pm
horizontal scaling factor: 1 / dx (2D)
void set2DPlotVariables(const std::string &pp_plot_var_names_2d)
amrex::Vector< REMORAFillPatcher > FPr_v
Vector over levels of FillPatchers for v (3D)
amrex::Vector< amrex::MultiFab * > cons_new
multilevel data container for current step's scalar data: temperature, salinity, passive tracer
static bool write_history_file
Whether to output NetCDF files as a single history file with several time steps.
void FillCoarsePatch(int lev, amrex::Real time, amrex::MultiFab *mf_fine, amrex::MultiFab *mf_crse, const int bccomp, const int bdy_var_type=BdyVars::null, const int icomp=0, const bool fill_all=true, const int n_not_fill=0, const int icomp_calc=0, const amrex::Real dt=amrex::Real(0.0), const amrex::MultiFab &mf_calc=amrex::MultiFab())
fill an entire multifab by interpolating from the coarser level
void stretch_transform(int lev)
Calculate vertical stretched coordinates.
std::unique_ptr< NCTimeSeries > rain_data_from_file
Data container for precipitation rate read from file.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_vwind
Wind in the v direction, defined at rho-points.
std::unique_ptr< ProblemBase > prob
Pointer to container of analytical functions for problem definition.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskr
land/sea mask at cell centers (2D)
void Construct_REMORAFillPatchers(int lev)
Construct FillPatchers.
static int sum_interval
Diagnostic sum output interval in number of steps.
int history_count
Counter for which time index we are writing to in the netcdf history file.
amrex::Real stop_time
Time to stop.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rain
precipitation rate [kg/m^2/s]
int do_substep
Whether to substep fine levels in time.
void Evolve()
Advance solution to final time.
std::string bdry_time_varname
Default name of time field for boundary data.
amrex::Real plotfile_fill_value
fill value for masked arrays in amrex plotfiles
void ReadCheckpointFile()
read checkpoint file from disk
bool chunk_history_file
Whether to chunk netcdf history file.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_sustr
Surface stress in the u direction.
amrex::Real get_t_old(int lev) const
Accessor method for t_old to expose to outside classes.
int yvel_bc() const noexcept
std::unique_ptr< NCTimeSeries > longwave_down_data_from_file
Data container for downward longwave radiation flux read from file.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ru2d
u velocity RHS (2D, includes horizontal and vertical advection)
amrex::Vector< std::string > datalogname
amrex::Vector< amrex::MultiFab * > zvel_new
multilevel data container for current step's z velocities (largely unused; W stored separately)
void init_only(int lev, amrex::Real time)
Init (NOT restart or regrid)
void init_set_vmix(int lev)
Initialize vertical mixing coefficients from file or analytic.
std::unique_ptr< NCTimeSeries > v_clim_data_from_file
Data container for v-velocity climatology data read from file.
std::string clim_u_time_varname
Name of time field for u climatology data.
void set_grid_scale(int lev)
Set pm and pn arrays on level lev. Only works if using analytic initialization.
void set_coriolis(int lev)
Initialize Coriolis factor from file or analytic.
int foextrap_bc() const noexcept
amrex::Vector< REMORAFillPatcher > FPr_u
Vector over levels of FillPatchers for u (3D)
std::string clim_temp_time_varname
Name of time field for temperature climatology data.
amrex::Vector< amrex::Vector< amrex::Box > > boxes_at_level
the boxes specified at each level by tagging criteria
static amrex::Vector< amrex::AMRErrorTag > ref_tags
Holds info for dynamically generated tagging criteria.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akt
Vertical diffusion coefficient (3D)
std::unique_ptr< NCTimeSeriesRiver > river_source_transportbar
Data container for vertically integrated momentum transport in rivers.
std::string clim_ubar_time_varname
Name of time field for ubar climatology data.
std::unique_ptr< NCTimeSeries > u_clim_data_from_file
Data container for u-velocity climatology data read from file.
std::string check_file
Checkpoint file prefix.
static amrex::Real startCPUTime
Variable for CPU timing.
amrex::Vector< amrex::MultiFab * > xvel_old
multilevel data container for last step's x velocities (u in ROMS)
amrex::Real start_time
Time of the start of the simulation, in seconds.
void init_data_from_netcdf(int lev)
Problem initialization from NetCDF file.
void init_masks_from_netcdf(int lev)
Mask data initialization from NetCDF file.
amrex::Vector< amrex::MultiFab * > yvel_new
multilevel data container for current step's y velocities (v in ROMS)
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_uwind
Wind in the u direction, defined at rho-points.
static amrex::Real fixed_fast_dt
User specified fixed barotropic time step.
int regrid_int
how often each level regrids the higher levels of refinement (after a level advances that many time s...
amrex::Real check_int_time
Checkpoint output interval in seconds.
void init_scalar_metadata()
Build runtime scalar names after nscalar is known.
void Define_REMORAFillPatchers(int lev)
Define FillPatchers.
amrex::Vector< amrex::IntVect > cum_ref_ratios
Cumulative refinement ratio between level 0 and level i.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_visc2_p
Harmonic viscosity defined on the psi points (corners of horizontal grid cells)
amrex::Real plot_int_time
Plotfile output interval in seconds.
amrex::Vector< int > num_files_at_level
how many netcdf input files specified at each level
amrex::Vector< REMORAFillPatcher > FPr_vbar
Vector over levels of FillPatchers for vbar (2D)
void AverageDownTo(int crse_lev)
more flexible version of AverageDown() that lets you average down across multiple levels
int steps_per_history_file
Number of time steps per netcdf history file.
void post_timestep(int nstep, amrex::Real time, amrex::Real dt_lev)
Called after every level 0 timestep.
int max_step
maximum number of steps
amrex::Vector< amrex::MultiFab * > zvel_old
multilevel data container for last step's z velocities (largely unused; W stored separately)
std::unique_ptr< NCTimeSeries > svstr_data_from_file
Data container for v-component surface momentum flux read from file.
amrex::Vector< std::string > nc_frc_file
NetCDF forcing file(s)
amrex::Vector< int > num_boxes_at_level
how many boxes specified at each level by tagging criteria
amrex::Vector< amrex::MultiFab * > xvel_new
multilevel data container for current step's x velocities (u in ROMS)
void refinement_criteria_setup()
Set refinement criteria.
int last_check_file_step
Step when we last output a checkpoint file.
void init_beta_plane_coriolis(int lev)
Calculate Coriolis parameters from beta plane parametrization.
std::string clim_vbar_time_varname
Name of time field for vbar climatology data.
amrex::Vector< int > nsubsteps
How many substeps on each level?
amrex::Vector< std::unique_ptr< REMORAPhysBCFunct > > physbcs
Vector (over level) of functors to apply physical boundary conditions.
void ComputeDt()
a wrapper for estTimeStep()
void fill_3d_masks(int lev)
Copy maskr to all z levels.
std::unique_ptr< NCTimeSeries > EminusP_data_from_file
Data container for evaporation minus precipitation read from file.
int plot_int
Plotfile output interval in iterations.
void FillPatch(int lev, amrex::Real time, amrex::MultiFab &mf_to_be_filled, amrex::Vector< amrex::MultiFab * > const &mfs, const int bccomp, const int bdy_var_type=BdyVars::null, const int icomp=0, const bool fill_all=true, const bool fill_set=true, const int n_not_fill=0, const int icomp_calc=0, const amrex::Real dt=amrex::Real(0.0), const amrex::MultiFab &mf_calc=amrex::MultiFab())
Fill a new MultiFab by copying in phi from valid region and filling ghost cells.
std::unique_ptr< NCTimeSeries > cloud_data_from_file
Data container for cloud cover fraction read from file.
void InitData()
Initialize multilevel data.
void set3DPlotVariables(const std::string &pp_plot_var_names_3d)
amrex::Vector< int > istep
which step?
void WriteCheckpointFile()
write checkpoint file to disk
std::string nc_clim_coeff_file
NetCDF climatology coefficient file.
void setRecordDataInfo(int i, const std::string &filename)
void set_analytic_vmix(int lev)
Set vertical mixing coefficients from analytic.
void init_flat_bathymetry(int lev)
Initialize flat bathymetry to value from problo.
std::unique_ptr< NCTimeSeries > temp_clim_data_from_file
Data container for temperature climatology data read from file.
amrex::Vector< std::string > bdry_time_name_byvar
Name of time fields for boundary data.
static int file_min_digits
Minimum number of digits in plotfile name or chunked history file.
void init_riv_pos_from_netcdf(int lev)
static amrex::Vector< std::string > nc_bdry_file
NetCDF boundary data.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_visc2_r
Harmonic viscosity defined on the rho points (centers)
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_svstr
Surface stress in the v direction.
std::unique_ptr< NCTimeSeries > srflx_data_from_file
Data container for shortwave radiation flux read from file.
void set_zeta(int lev)
Initialize zeta from file or analytic.
static amrex::Real change_max
Fraction maximum change in subsequent time steps.
void init_zeta_from_netcdf(int lev)
Sea-surface height data initialization from NetCDF file.
void set_zeta_average(int lev)
Set Zt_avg1 to zeta.
void init_coriolis_from_netcdf(int lev)
Coriolis parameter data initialization from NetCDF file.
std::string pp_prefix
default prefix for input file parameters
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_h_full_domain
Bathymetry data on the whole domain at each potential level.
void set_bathymetry(int lev)
Initialize bathymetry from file or analytic.
amrex::Vector< amrex::MultiFab * > yvel_old
multilevel data container for last step's y velocities (v in ROMS)
std::unique_ptr< NCTimeSeries > ubar_clim_data_from_file
Data container for ubar climatology data read from file.
amrex::Vector< REMORAFillPatcher > FPr_c
Vector over levels of FillPatchers for scalars.
std::unique_ptr< NCTimeSeries > Tair_data_from_file
Data container for air temperature read from file.
int nscalar
Number of passive scalars carried in the state.
std::string clim_v_time_varname
Name of time field for v climatology data.
amrex::Vector< REMORAFillPatcher > FPr_w
Vector over levels of FillPatchers for w.
void average_down_with_grow_cells(int lev, amrex::Vector< std::unique_ptr< amrex::MultiFab > > &mf)
Average down from level lev+1 to lev in mf, including grow cells.
std::string clim_salt_time_varname
Name of time field for salinity climatology data.
std::unique_ptr< NCTimeSeries > Uwind_data_from_file
Data container for u-direction wind read from file.
std::unique_ptr< NCTimeSeries > Pair_data_from_file
Data container for air pressure read from file.
amrex::Vector< amrex::Real > t_new
new time at each level
void init_stretch_coeffs()
initialize and calculate stretch coefficients
void init_bdry_from_netcdf(int lev)
Boundary data initialization from NetCDF file.
static SolverChoice solverChoice
Container for algorithmic choices.
void set_masks(int lev)
Initialize land-sea masks from file or analytic.
amrex::Vector< amrex::Vector< std::unique_ptr< NCTimeSeriesBoundary > > > boundary_series
Vector over BdyVars of boundary series data containers.
int cf_set_width
Width for fixing values at coarse-fine interface.
void ReadParameters()
read in some parameters from inputs file
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ru
u velocity RHS (3D, includes horizontal and vertical advection)
void sum_integrated_quantities(amrex::Real time)
Integrate conserved quantities for diagnostics.
static int total_nc_plot_file_step
static int plot_staggered_vels
Whether to write the staggered velocities (not averaged to cell centers)
static amrex::Vector< amrex::Vector< std::string > > nc_grid_file
NetCDF grid file.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_longwave_down
Downward longwave radiation.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_zeta
free surface height (2D)
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_vbar
barotropic y velocity (2D)
void set_zeta_to_Ztavg(int lev)
Set zeta components to be equal to time-averaged Zt_avg1.
bool expand_plotvars_to_unif_rr
whether plotfile variables should be expanded to a uniform refinement ratio
int plot_file_on_restart
Whether to output a plotfile on restart from checkpoint.
void set_2darrays(int lev)
Set 2D momentum arrays from 3D momentum.
void init_analytic(int lev)
Initialize initial problem data from analytic functions.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ubar
barotropic x velocity (2D)
amrex::Vector< amrex::MultiFab * > cons_old
multilevel data container for last step's scalar data: temperature, salinity, passive tracer
std::string frc_time_varname
Name of time field for forcing data.
void set_wind(int lev)
Initialize or calculate wind speed from file or analytic.
amrex::Vector< REMORAFillPatcher > FPr_ubar
Vector over levels of FillPatchers for ubar (2D)
bool is_it_time_for_action(int nstep, amrex::Real time, amrex::Real dt, int action_interval, amrex::Real action_per)
Decide if it is time to take an action.
std::unique_ptr< NCTimeSeries > Vwind_data_from_file
Data container for v-direction wind read from file.
void init_bathymetry_full_domain_from_netcdf()
Full domain bathymetry data initialization from NetCDF file.
void set_hmixcoef(int lev)
Initialize horizontal mixing coefficients.
amrex::Vector< std::unique_ptr< NCTimeSeriesRiver > > river_source_cons
Vector of data containers for scalar data in rivers.
void timeStep(int lev, amrex::Real time, int iteration)
advance a level by dt, includes a recursive call for finer levels
std::unique_ptr< NCTimeSeriesRiver > river_source_transport
Data container for momentum transport in rivers.
void AverageDown()
set covered coarse cells to be the average of overlying fine cells
static int fixed_ndtfast_ratio
User specified, number of barotropic steps per baroclinic step.
amrex::Real netcdf_fill_value
fill value for masked arrays in netcdf output
void timeStepML(amrex::Real time, int iteration)
advance all levels by dt, loops over finer levels
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pn
horizontal scaling factor: 1 / dy (2D)
amrex::Vector< std::unique_ptr< std::fstream > > datalog
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akv
Vertical viscosity coefficient (3D)
static amrex::Real cfl
CFL condition.
void append3DPlotVariables(const std::string &pp_plot_var_names_3d)
static int verbose
Verbosity level of output.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_cloud
cloud cover fraction [0-1], defined at rho-points
std::string plot_file_name
Plotfile prefix.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Zt_avg1
Average of the free surface, zeta (2D)
std::unique_ptr< NCTimeSeries > salt_clim_data_from_file
Data container for salinity climatology data read from file.
int check_int
Checkpoint output interval in iterations.
void set_smflux(int lev)
Initialize or calculate surface momentum flux from file or analytic.
void WritePlotFile(int istep)
main driver for writing AMReX plotfiles
std::string restart_chkfile
If set, restart from this checkpoint file.
void init_clim_nudg_coeff(int lev)
Wrapper to initialize climatology nudging coefficient.
void init_bathymetry_full_domain_from_analytic()
Full domain bathymetry data initialization from analytic.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rv
v velocity RHS (3D, includes horizontal and vertical advection)
int cf_width
Nudging width at coarse-fine interface.
static amrex::Vector< amrex::Vector< std::string > > nc_init_file
NetCDF initialization file.
int last_plot_file_step
Step when we last output a plotfile.
amrex::Vector< amrex::Real > t_old
old time at each level
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_srflx
Shortwave radiation flux [W/m²], defined at rho-points.
amrex::Real last_check_file_time
Simulation time when we last output a checkpoint file.
void append2DPlotVariables(const std::string &pp_plot_var_names_2d)
void set_bathymetry_averaged_down(int lev)
Copy over bathymetry data that has been averaged down from high resolution input netcdf file.
amrex::Vector< amrex::Real > dt
time step at each level
static amrex::Real sum_per
Diagnostic sum output interval in time.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Pair
Air pressure [mb], defined at rho-points.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_qair
Specific humidity [kg/kg], defined at rho-points.
int hires_grid_level
Which level the high resolution bathymetry is at.
std::unique_ptr< NCTimeSeries > vbar_clim_data_from_file
Data container for vbar climatology data read from file.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Tair
Air temperature [°C], defined at rho-points.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_diff2
Harmonic diffusivity for temperature / salinity.
static constexpr int cons_bc
static constexpr int Temp_bc_comp
const char * buildInfoGetGitHash(int i)
HorizMixingType horiz_mixing_type
bool longwave_down_from_netcdf
amrex::Vector< amrex::Real > tnu2
std::string longwave_netcdf_varname
amrex::Vector< int > do_rivers_cons
ScaledToGridAMRScaling scaled_to_grid_amr_scaling
bool boundary_from_netcdf
void init_params(int ncons)
read in and initialize parameters
VertMixingType vert_mixing_type
CouplingType coupling_type