REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA.cpp
Go to the documentation of this file.
1/**
2 * \file REMORA.cpp
3 */
4
6#include <REMORA.H>
8
9#ifdef REMORA_USE_NETCDF
10#include "REMORA_NCFile.H"
11#endif
12
13#include <AMReX_buildInfo.H>
14
15using namespace amrex;
16
17amrex::Real REMORA::startCPUTime = zero;
19
20Vector<REMORAErrorTag> REMORA::ref_tags;
21
23
24// Time step control
25amrex::Real REMORA::cfl = Real(0.8);
26amrex::Real REMORA::fixed_dt = -one;
27amrex::Real REMORA::change_max = Real(1.1);
28
29int REMORA::ndtfast = 0;
30
31// Dictate verbosity in screen output
32int REMORA::verbose = 0;
33
34// Frequency of diagnostic output
36amrex::Real REMORA::sum_per = -one;
37
38// Minimum number of digits in plotfile name
40
41// Do we include staggered velocities in the plotfile?
43
44// Do we include nodal data (Nu_nd) in the plotfile?
45bool REMORA::plot_nodal_data = true;
46
47// Native AMReX vs NetCDF
49
50#ifdef REMORA_USE_NETCDF
51
53
54// Do we write one file per timestep (false) or one file for all timesteps (true)
56
57// NetCDF initialization file
58amrex::Vector<std::string> REMORA::nc_bdry_file = {""}; // Must provide via input
59amrex::Vector<amrex::Vector<std::string>> REMORA::nc_init_file = {{""}}; // Must provide via input
60amrex::Vector<amrex::Vector<std::string>> REMORA::nc_grid_file = {{""}}; // Must provide via input
61#endif
62
63/**
64 * constructor:
65 * - reads in parameters from inputs file
66 * - sizes multilevel arrays and data structures
67 * - initializes BCRec boundary condition object
68 */
70{
71 BL_PROFILE("REMORA::REMORA()");
72
73 if (ParallelDescriptor::IOProcessor()) {
76 const char* buildgithash = amrex::buildInfoGetBuildGitHash();
77 const char* buildgitname = amrex::buildInfoGetBuildGitName();
78
79 if (strlen(remora_hash) > 0) {
80 amrex::Print() << "\n"
81 << "REMORA git hash: " << remora_hash << "\n";
82 }
83 if (strlen(amrex_hash) > 0) {
84 amrex::Print() << "AMReX git hash: " << amrex_hash << "\n";
85 }
86 if (strlen(buildgithash) > 0) {
87 amrex::Print() << buildgitname << " git hash: " << buildgithash << "\n";
88 }
89
90 amrex::Print() << "\n";
91 }
92
94
95 // Blocking factor in z set to very large value to be > nz
96 // This guarantees that there will be no domain decomposition in the z-direction
97 // We have to set this by hand here because setting it in the input file will
98 // cause checks in the AmrCore constructor to fail.
101 for (int lev = 0; lev <= max_level; ++lev) {
103 blocking_factor_vec[lev][2] = 4096;
104 }
106
107 const std::string& pv3d = "plot_vars_3d"; set3DPlotVariables(pv3d);
108 const std::string& pv2d = "plot_vars_2d"; set2DPlotVariables(pv2d);
109
111
112 // Geometry on all levels has been defined already.
113
114 // No valid BoxArray and DistributionMapping have been defined.
115 // But the arrays for them have been resized.
116
117 int nlevs_max = max_level + 1;
118
119 istep.resize(nlevs_max, 0);
121
122 physbcs.resize(nlevs_max);
123
124 t_new.resize(nlevs_max, zero);
127
128 cons_new.resize(nlevs_max);
129 cons_old.resize(nlevs_max);
130 xvel_new.resize(nlevs_max);
131 xvel_old.resize(nlevs_max);
132 yvel_new.resize(nlevs_max);
133 yvel_old.resize(nlevs_max);
134 zvel_new.resize(nlevs_max);
135 zvel_old.resize(nlevs_max);
136
137 advflux_reg.resize(nlevs_max);
138
139 // Initialize tagging criteria for mesh refinement
141
143}
144
145REMORA::REMORA (const amrex::RealBox& rb, int max_level_in, const amrex::Vector<int>& n_cell_in, int coord, const amrex::Vector<amrex::IntVect>& ref_ratio_in, const amrex::Array<int,AMREX_SPACEDIM>& is_per, std::string prefix)
147{
148 BL_PROFILE("REMORA::REMORA(explicit)");
150
151 if (ParallelDescriptor::IOProcessor()) {
153 const char* amrex_hash = amrex::buildInfoGetGitHash(2);
154 const char* buildgithash = amrex::buildInfoGetBuildGitHash();
155 const char* buildgitname = amrex::buildInfoGetBuildGitName();
156
157 if (strlen(remora_hash) > 0) {
158 amrex::Print() << "\n"
159 << "REMORA git hash: " << remora_hash << "\n";
160 }
161 if (strlen(amrex_hash) > 0) {
162 amrex::Print() << "AMReX git hash: " << amrex_hash << "\n";
163 }
164 if (strlen(buildgithash) > 0) {
165 amrex::Print() << buildgitname << " git hash: " << buildgithash << "\n";
166 }
167
168 amrex::Print() << "\n";
169 }
170
172
173 const std::string& pv3d = "plot_vars_3d"; set3DPlotVariables(pv3d);
174 const std::string& pv2d = "plot_vars_2d"; set2DPlotVariables(pv2d);
175
177
178 int nlevs_max = max_level + 1;
179
180 istep.resize(nlevs_max, 0);
182
183 physbcs.resize(nlevs_max);
184
185 t_new.resize(nlevs_max, zero);
188
189 cons_new.resize(nlevs_max);
190 cons_old.resize(nlevs_max);
191 xvel_new.resize(nlevs_max);
192 xvel_old.resize(nlevs_max);
193 yvel_new.resize(nlevs_max);
194 yvel_old.resize(nlevs_max);
195 zvel_new.resize(nlevs_max);
196 zvel_old.resize(nlevs_max);
197
198 advflux_reg.resize(nlevs_max);
199
201
203}
204
206{
207}
208
209/**
210 * Reject refinement in the vertical, and accumulate the refinement ratios.
211 *
212 * Shared by both constructors. It used to be written out in each of them, and the explicit one
213 * had been left without the cum_ref_ratios half -- so the vector stayed empty, and every
214 * full-domain hires array and every mask coarsening that indexes it read out of bounds.
215 */
216void
218{
220
221 IntVect cum_ref_ratio = IntVect(1,1,0);
222 cum_ref_ratios.push_back(cum_ref_ratio);
223 // We have already read in the ref_ratio (via amr.ref_ratio =) but we need to enforce
224 // that there is no refinement in the vertical so we test on that here.
225 for (int lev = 0; lev < max_level; ++lev)
226 {
227 amrex::Print() << "Refinement ratio at level " << lev << " set to be " <<
228 ref_ratio[lev][0] << " " << ref_ratio[lev][1] << " " << ref_ratio[lev][2] << std::endl;
229
230 if (ref_ratio[lev][2] != 1)
231 {
232 amrex::Print() << "********************************************************************************" << std::endl;
233 amrex::Print() << "We don't allow refinement in the vertical -- make sure to set ref_ratio = 1 in z" << std::endl;
234 amrex::Print() << "It's possible you set amr.ref_ratio when you meant to set amr.ref_ratio_vect " << std::endl;
235 amrex::Print() << "********************************************************************************" << std::endl;
236 amrex::Abort();
237 }
238
239 cum_ref_ratio[0] *= ref_ratio[lev][0];
240 cum_ref_ratio[1] *= ref_ratio[lev][1];
241 cum_ref_ratios.push_back(cum_ref_ratio);
242 }
243}
244
245void
247{
248 cons_names.clear();
249 cons_names.reserve(ncons);
250 cons_names.emplace_back("temp");
251 cons_names.emplace_back("salt");
252
253 // Passive (dye) scalars come first, then the biology block, matching the component
254 // layout: temp, salt, tracer, tracer_1, ..., NO3, NH4, ...
255 if (nscalar > 0) {
256 cons_names.emplace_back("tracer");
257 for (int i = 1; i < nscalar; ++i) {
258 cons_names.emplace_back("tracer_" + std::to_string(i));
259 }
260 }
261
264 for (const auto& name : bio_names) {
265 cons_names.emplace_back(name);
266 }
267 }
268
269 AMREX_ALWAYS_ASSERT(static_cast<int>(cons_names.size()) == ncons);
270}
271
272void
274{
275 BL_PROFILE_VAR("REMORA::Evolve()",evolve);
276 Real cur_time = t_new[0];
277 const Real stop_elapsed = elapsed_time(stop_time);
278
279 // istep[0] advances inside the loop, so keep the value it started at.
280 const int first_step = istep[0];
281
282 // Levels appear as tagging occurs, so reprint the hierarchy when finest_level changes.
283 int reported_finest = -1;
284
285 // Take one coarse timestep by calling timeStep -- which recursively calls timeStep
286 // for finer levels (with or without subcycling)
287 for (int step = istep[0]; step < max_step && cur_time < stop_elapsed; ++step)
288 {
289 amrex::Print() << "\nCoarse STEP " << step+1 << " starts ..." << std::endl;
290
291 ComputeDt();
292
293 // dt is only populated once ComputeDt has run.
297 }
298
299 int lev = 0;
300 int iteration = 1;
301 auto dEvolveTime0 = amrex::second();
302
303 // timeStep recurses into finer levels nsubsteps[lev+1] times; timeStepML advances
304 // every level once through one shared barotropic loop.
305 if (max_level == 0 || do_substep) {
307 }
308 else {
310 }
311
312 cur_time += dt[0];
313
314 amrex::Print() << "Coarse STEP " << step+1 << " ends." << " TIME = " << cur_time
315 << " DT = " << dt[0] << std::endl;
316
317 if (verbose > 0)
318 {
319 auto dEvolveTime = amrex::second() - dEvolveTime0;
320 ParallelDescriptor::ReduceRealMax(dEvolveTime,ParallelDescriptor::IOProcessorNumber());
321 amrex::Print() << "Timestep time = " << dEvolveTime << " seconds." << '\n';
322 }
323
325
327
328#ifdef AMREX_MEM_PROFILING
329 {
330 std::ostringstream ss;
331 ss << "[STEP " << step+1 << "]";
332 MemProfiler::report(ss.str());
333 }
334#endif
335
336 if (cur_time >= stop_elapsed - 1.e-6*dt[0]) break;
337 }
338
340
342}
343
344void
346{
347
348 if ( (plot_int > 0 || plot_int_time > zero) && istep[0] > last_plot_file_step)
349 {
352 }
353
354 if ((check_int > 0 || check_int_time > zero) && istep[0] > last_check_file_step) {
356 }
357}
358
359void
378
379/**
380 * Apply the tracer flux correction accumulated at the lev/lev+1 interface onto lev.
381 *
382 * Once per step of lev, pairing the reset at the top of Advance(lev), so the accumulate and
383 * apply window sits inside one step of lev. Applying it per step of level 0 instead would
384 * keep only the last correction whenever lev was itself substepped, and would let the regrid
385 * of lev+1 rebuild the register mid-accumulation.
386 *
387 * @param[in] lev coarse level of the interface
388 */
389void
391{
392 if (!(do_reflux && do_substep) || lev >= finest_level ||
394 return;
395 }
396
397 BL_PROFILE("REMORA::reflux_to()");
398
399 // The register holds the correction in Hz*t units, the form the tracer is advanced in.
400 // Reflux into a scratch fab and divide that down, rather than scaling the level into
401 // those units and back: that round trip is inexact for about a tenth of cells, which
402 // perturbs cells the correction never reached and leaves the clamp below unable to tell
403 // which ones it did.
405 dcons.setVal(zero);
406 getAdvFluxReg(lev+1)->Reflux(dcons, 0, 0, ncons);
407
408 const bool clamp = reflux_clamp;
409
410#ifdef _OPENMP
411#pragma omp parallel if (Gpu::notInLaunchRegion())
412#endif
413 for (MFIter mfi(*cons_new[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
414 {
415 Array4<Real > const& c = cons_new[lev]->array(mfi);
416 Array4<Real const> const& dc = dcons.const_array(mfi);
417 Array4<Real const> const& hz = vec_Hz[lev]->const_array(mfi);
418
419 ParallelFor(mfi.tilebox(), ncons, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
420 {
421 // No thickness is land or dry: leave it rather than divide by zero.
422 if (dc(i,j,k,n) == zero || hz(i,j,k) <= zero) { return; }
423
424 c(i,j,k,n) += dc(i,j,k,n) / hz(i,j,k);
425
426 // Clamping restores the mass the correction removed, so a step that clamps is
427 // not conservative: ROMS's trade, and why it is an option. Zero suits a
428 // concentration, less so temperature in Celsius.
429 if (clamp && c(i,j,k,n) < zero) { c(i,j,k,n) = zero; }
430 });
431 }
432}
433
434/**
435 * @param[in ] nstep which step we're on
436 * @param[in ] time current time
437 * @param[in ] dt_lev0 time step on level 0
438 */
439void
441{
442 BL_PROFILE("REMORA::post_timestep()");
443
444#ifdef REMORA_USE_PARTICLES
445 particleData.Redistribute();
446#endif
447
449 {
450 for (int lev = finest_level-1; lev >= 0; lev--)
451 {
453 }
454 }
455
458 }
459}
460
461/**
462 * This is called from main.cpp and handles all initialization, whether from start or restart
463 */
464void
466{
467 BL_PROFILE("REMORA::InitData()");
469 amrex::Print() << "REMORA InitData: driver-managed atm2ocn coupling enabled"
470 << " two_way=" << (driver_uses_two_way_coupling ? 1 : 0)
471 << " active_contract="
473 << "\n";
474 }
475 // Initialize the start time for our CPU-time tracker
476 startCPUTime = Real(ParallelDescriptor::second());
477
478 // Map the words in the inputs file to BC types, then translate
479 // those types into what they mean for each variable
480 init_bcs();
481
482 // Init vertical stretching coeffs
484
489
490 if (restart_chkfile == "") {
491 // start simulation from the beginning
492
493 // t_new counts from start_time, so a fresh run starts at zero.
495
497 AverageDown();
498 }
499
500 } else { // Restart from a checkpoint
501
502 restart();
503
504 }
505
506 // Every level's mask exists by now, whether built from scratch or read back
508
509#ifdef REMORA_USE_MOAB
510 InitMOABMesh();
511#endif
512 // Levels that appear later, or are regridded, define their own from make_new_level.
514 advflux_reg[0] = nullptr;
515 for (int lev = 1; lev <= finest_level; lev++) {
517 }
518 }
519
520 // Fill ghost cells/faces
521 for (int lev = 0; lev <= finest_level; ++lev)
522 {
523 if (lev > 0 && cf_width >= 0) {
525 }
526
527 if (restart_chkfile == "") {
529 FillPatch(lev, t_new[lev], *xvel_new[lev], xvel_new, xvel_bc(), BdyVars::u, 0, true, false,0,0,zero,*xvel_new[lev]);
530 FillPatch(lev, t_new[lev], *yvel_new[lev], yvel_new, yvel_bc(), BdyVars::v, 0, true, false,0,0,zero,*yvel_new[lev]);
531 FillPatch(lev, t_new[lev], *zvel_new[lev], zvel_new, zvel_bc(), BdyVars::null, 0, true, false);
532
533 // Copy from new into old just in case when initializing from scratch
534 int ngs = cons_new[lev]->nGrow();
535 int ngvel = xvel_new[lev]->nGrow();
536 MultiFab::Copy(*cons_old[lev],*cons_new[lev],0,0,ncons,ngs);
537 MultiFab::Copy(*xvel_old[lev],*xvel_new[lev],0,0,1,ngvel);
538 MultiFab::Copy(*yvel_old[lev],*yvel_new[lev],0,0,1,ngvel);
539 MultiFab::Copy(*zvel_old[lev],*zvel_new[lev],0,0,1,IntVect(ngvel,ngvel,0));
540 }
541 } // lev
542
543 // Check for additional plotting variables that are available after
544 // particle containers are setup.
545 const std::string& pv3d = "plot_vars_3d"; append3DPlotVariables(pv3d);
546 const std::string& pv2d = "plot_vars_2d"; append2DPlotVariables(pv2d);
547
548 if (restart_chkfile == "" && (check_int > 0 || check_int_time > zero))
549 {
552 }
553
554 // plot_file_on_restart currently always 1
555 if ( (restart_chkfile == "") ||
557 {
558 if (plot_int > 0 || plot_int_time > zero)
559 {
560 int step0 = 0;
564 }
565 }
566
569 }
570
571 // dt is read from checkpoint on restart so it only needs to be computed if
572 // not restarting
573 if (restart_chkfile == "") {
574 ComputeDt();
575 }
576
577}
578
579/**
580 * @param[in ] lev level to operate on
581 */
582void
584{
585 BL_PROFILE("REMORA::Construct_REMORAFillPatchers()");
586 amrex::Print() << ":::Construct_REMORAFillPatchers " << lev << std::endl;
587
588 auto& ba_fine = cons_new[lev ]->boxArray();
589 auto& ba_crse = cons_new[lev-1]->boxArray();
590 auto& dm_fine = cons_new[lev ]->DistributionMap();
591 auto& dm_crse = cons_new[lev-1]->DistributionMap();
592
593 BoxList bl2d_fine = ba_fine.boxList();
594 for (auto& b : bl2d_fine) {
595 b.setRange(2,0);
596 }
597 BoxArray ba2d_fine(std::move(bl2d_fine));
598
599 BoxList bl2d_crse = ba_crse.boxList();
600 for (auto& b : bl2d_crse) {
601 b.setRange(2,0);
602 }
603 BoxArray ba2d_crse(std::move(bl2d_crse));
604
605 int ncomp = cons_new[lev]->nComp();
606
607 FPr_c.emplace_back(ba_fine, dm_fine, geom[lev] ,
608 ba_crse, dm_crse, geom[lev-1],
610 FPr_u.emplace_back(convert(ba_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
611 convert(ba_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
613 FPr_v.emplace_back(convert(ba_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
614 convert(ba_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
616 FPr_w.emplace_back(convert(ba_fine, IntVect(0,0,1)), dm_fine, geom[lev] ,
617 convert(ba_crse, IntVect(0,0,1)), dm_crse, geom[lev-1],
619
620 FPr_ubar.emplace_back(convert(ba2d_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
621 convert(ba2d_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
623 FPr_vbar.emplace_back(convert(ba2d_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
624 convert(ba2d_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
626
627 FPr_Dubar.emplace_back(convert(ba2d_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
628 convert(ba2d_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
630 FPr_Dvbar.emplace_back(convert(ba2d_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
631 convert(ba2d_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
633}
634
635/**
636 * @param[in ] lev level to operate on
637 */
638void
640{
641 BL_PROFILE("REMORA::Define_REMORAFillPatchers()");
642 if (verbose > 0) {
643 amrex::Print() << ":::Define_REMORAFillPatchers " << lev << std::endl;
644 }
645
646 auto& ba_fine = cons_new[lev ]->boxArray();
647 auto& ba_crse = cons_new[lev-1]->boxArray();
648 auto& dm_fine = cons_new[lev ]->DistributionMap();
649 auto& dm_crse = cons_new[lev-1]->DistributionMap();
650
651 BoxList bl2d_fine = ba_fine.boxList();
652 for (auto& b : bl2d_fine) {
653 b.setRange(2,0);
654 }
655 BoxArray ba2d_fine(std::move(bl2d_fine));
656
657 BoxList bl2d_crse = ba_crse.boxList();
658 for (auto& b : bl2d_crse) {
659 b.setRange(2,0);
660 }
661 BoxArray ba2d_crse(std::move(bl2d_crse));
662
663
664 int ncomp = cons_new[lev]->nComp();
665
666 FPr_c[lev-1].Define(ba_fine, dm_fine, geom[lev] ,
667 ba_crse, dm_crse, geom[lev-1],
669 FPr_u[lev-1].Define(convert(ba_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
670 convert(ba_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
672 FPr_v[lev-1].Define(convert(ba_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
673 convert(ba_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
675 FPr_w[lev-1].Define(convert(ba_fine, IntVect(0,0,1)), dm_fine, geom[lev] ,
676 convert(ba_crse, IntVect(0,0,1)), dm_crse, geom[lev-1],
678
679 FPr_ubar[lev-1].Define(convert(ba2d_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
680 convert(ba2d_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
682 FPr_vbar[lev-1].Define(convert(ba2d_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
683 convert(ba2d_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
685
686 FPr_Dubar[lev-1].Define(convert(ba2d_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
687 convert(ba2d_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
689 FPr_Dvbar[lev-1].Define(convert(ba2d_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
690 convert(ba2d_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
692}
693
694void
696{
697 BL_PROFILE("REMORA::restart()");
699
700 // We set this here so that we don't over-write the checkpoint file we just started from
702 // last_plot_file_step will be updated when plotfile is unconditionally written after restart
703
706}
707
708/**
709 * @param[in ] lev level to operate on
710 */
711void
713{
714 BL_PROFILE("REMORA::set_zeta()");
715 if (lev==0) {
716 if (hires_init_level < 0) {
718 prob->init_analytic_zeta(lev, geom[lev], solverChoice, *this, prob_coords(lev), *vec_zeta[lev]);
719 } else if (solverChoice.ic_type == IC_Type::netcdf) {
720#ifdef REMORA_USE_NETCDF
721 amrex::Print() << "Calling init_zeta_from_netcdf on level " << lev << std::endl;
723 amrex::Print() << "Sea surface height loaded from netcdf file \n " << std::endl;
724#endif
725 } else {
726 amrex::Abort("Unknown IC_Type");
727 }
728 } else {
730 }
731 vec_zeta[lev]->FillBoundary(geom[lev].periodicity());
732 } else {
733 // If our level is higher than the high resolution grid or initialization
734 // is analytic, interpolate from level below. Otherwise, copy over the bathymetry
735 // data that has been averaged down
736 if (lev > hires_init_level) {
737 Real dummy_time = zero;
739 } else {
741 vec_zeta[lev]->FillBoundary(geom[lev].periodicity());
742 }
743 }
745}
746
747/**
748 * @param[in ] lev level to operate on
749 */
750void
752{
753 BL_PROFILE("REMORA::bathymetry()");
754 // Only set bathymetry on level 0, and interpolate for finer levels
755 if (lev==0) {
756 // If grid data is not defined on a level > 0 (negative level) then
757 // initialize from low-resolution grid normally. Otherwise use high-resolution
758 // grid data averaged down to level 0
759 if (hires_grid_level < 0) {
761 prob->init_analytic_bathymetry(lev, geom[lev], solverChoice, *this, *vec_h[lev]);
762 } else if (solverChoice.ic_type == IC_Type::netcdf) {
763#ifdef REMORA_USE_NETCDF
764 amrex::Print() << "Calling init_bathymetry_from_netcdf " << std::endl;
766 amrex::Print() << "Bathymetry loaded from netcdf file \n " << std::endl;
767 amrex::Print() << "Calling init_grid_vars_from_netcdf " << std::endl;
769 amrex::Print() << "Grid variables loaded from netcdf file \n " << std::endl;
770#endif
771 } else {
772 amrex::Abort("Unknown IC_Type");
773 }
774 } else {
776 // Only the netcdf path fills vec_pm/pn_full_domain; with analytic initialization
777 // init_bathymetry_full_domain_from_analytic fills h alone, and set_grid_scale
778 // below derives pm/pn from the geometry.
781 }
782 }
783 // Need FillBoundary to fill at grid-grid boundaries, and EnforcePeriodicity
784 // to make sure ghost cells in the domain corners are consistent.
785 vec_h[lev]->FillBoundary(geom[lev].periodicity());
786 vec_h[lev]->EnforcePeriodicity(geom[lev].periodicity());
787 } else {
788 // If our level is higher than the high resolution grid or initialization
789 // is analytic, interpolate from level below. Otherwise, copy over the bathymetry
790 // data that has been averaged down
791 if (lev > hires_grid_level) {
792 Real dummy_time = zero;
797 } else {
799 vec_h[lev]->FillBoundary(geom[lev].periodicity());
800 vec_h[lev]->EnforcePeriodicity(geom[lev].periodicity());
801 }
802 }
804}
805
806/**
807 * @param[in ] lev level to operate on
808 */
809void
811 Real dummy_time = zero;
812 // Note: don't understand why the grow vector args aren't vec_h and then vec_h_full_domain
817 BdyVars::null,0,false,false,1);
820 BdyVars::null,1,false,false,1);
821}
822
823/**
824 * @param[in ] lev level to operate on
825 */
826void
840
841/**
842 * @param[in ] lev level to operate on
843 */
844void
851
852/**
853 * @param[in ] lev level to operate on
854 */
855void
868
869/**
870 * @param[in ] lev level to operate on
871 */
872void
874 BL_PROFILE("REMORA::set_coriolis()");
877 prob->init_analytic_coriolis(lev, geom[lev], solverChoice, *this, *vec_fcor[lev]);
880#ifdef REMORA_USE_NETCDF
882 if (lev == 0) {
883 amrex::Print() << "Calling init_coriolis_from_netcdf " << std::endl;
885 amrex::Print() << "Coriolis loaded from netcdf file \n" << std::endl;
886 } else {
887 Real dummy_time = zero;
889 }
890#endif
891 } else {
892 Abort("Don't know this coriolis_type!");
893 }
894
895 Real time = zero;
897 vec_fcor[lev]->EnforcePeriodicity(geom[lev].periodicity());
898 }
899}
900
901void
903 BL_PROFILE("REMORA::init_set_vmix()");
908 // The GLS initialization just sets the multifab to a value, so there's
909 // no need to call FillPatch here
910 } else {
911 Abort("Don't know this vertical mixing type");
912 }
913}
914
915/**
916 * @param[in ] lev level to operate on
917 */
918void
920 BL_PROFILE("REMORA::set_analytic_vmix()");
921 Real time = zero;
923 for (int n = 0; n < NAT; n++) {
924 vec_Akt[lev]->setVal(solverChoice.Akt_bak[n], n, 1);
925 }
926 prob->init_analytic_vmix(lev, geom[lev], solverChoice, *this,*vec_Akv[lev], *vec_Akt[lev]);
928 for (int n = 0; n < NAT; n++) {
930 }
931}
932
933/**
934 * Initialize the land-sea mask on this level.
935 *
936 * Mirrors set_bathymetry: the mask is specified once, on level 0 or at hires_grid_level, and
937 * every other level derived from it, so the levels cannot disagree about the coastline.
938 *
939 * @param[in ] lev level to operate on
940 */
941void
943{
944 // Ahead of the mask_type == none return as well: that branch still fills the masks, and
945 // AverageDownTo still reads them, so its cached copies go stale here too.
947
950 return;
951 }
952
953 if (lev == 0) {
954 // If grid data is not defined on a level > 0 (negative level) then initialize from
955 // the low-resolution grid normally. Otherwise use high-resolution grid data
956 // coarsened down to level 0.
957 if (hires_grid_level < 0) {
959 prob->init_analytic_masks(lev,geom[lev], solverChoice, *this, *vec_mskr[lev]);
960 // The analytic hook writes each grid's own cells only, so this is what makes
961 // the mask agree across grid-grid and periodic boundaries.
962 vec_mskr[lev]->FillBoundary(geom[lev].periodicity());
965#ifdef REMORA_USE_NETCDF
966 amrex::Print() << "Calling init_masks_from_netcdf level " << lev << std::endl;
968 amrex::Print() << "Masks loaded from netcdf file \n " << std::endl;
969#endif
970 }
971 } else {
973 }
974 } else {
975 // If our level is higher than the high resolution grid, interpolate from the level
976 // below. Otherwise, copy over the mask that has been coarsened down.
977 if (lev > hires_grid_level) {
978 Real dummy_time = zero;
980 foextrap_bc());
982 } else {
984 }
985 }
987}
988
989/**
990 * @param[in ] lev level to operate on
991 */
992void
994 ParallelCopy(*vec_mskr[lev].get(), *vec_mskr_full_domain[lev].get(), 0, 0, 1,
996 // Not a FillPatch, unlike the bathymetry analogue: its interpolation from the coarser
997 // level is not piecewise constant, so it would put fractional values in a mask the rest
998 // of the code compares against 0 and 1 exactly.
999 vec_mskr[lev]->FillBoundary(geom[lev].periodicity());
1001}
1002
1003/**
1004 * Coarsen the full-domain rho-mask from crse_lev+1 onto crse_lev, grow cells included, so a
1005 * coarse cell is land only if every one of its fine cells is land.
1006 *
1007 * average_down_with_grow_cells cannot be used: an arithmetic mean over a partly wet group of
1008 * fine cells gives a fractional value, and the mask has to stay exactly 0 or 1. Taking the
1009 * cell as wet also means the coarse level never declares land where the fine grid found water.
1010 *
1011 * @param[in ] crse_lev level to coarsen onto
1012 */
1013void
1015{
1016 auto const& crsema = vec_mskr_full_domain[crse_lev]->arrays();
1017 auto const& finema = vec_mskr_full_domain[crse_lev+1]->const_arrays();
1018 auto ratio = refRatio(crse_lev);
1019 // As in average_down_with_grow_cells, but cell-centered, so no index-type correction.
1022 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
1023 {
1024 const int ii = i * ratio[0];
1025 const int jj = j * ratio[1];
1026 Real wet = zero;
1027 for (int jref = 0; jref < ratio[1]; ++jref) {
1028 for (int iref = 0; iref < ratio[0]; ++iref) {
1029 wet += amrex::min(Real(1.0), finema[box_no](ii+iref, jj+jref, k, n));
1030 }
1031 }
1032 crsema[box_no](i,j,k,n) = (wet > zero) ? one : zero;
1033 });
1034 Gpu::streamSynchronize();
1035}
1036
1037
1038/**
1039 * Check the land-sea masks for what the rest of the code relies on. Only runs when
1040 * remora.check_mask_consistency is set; remora.mask_consistency picks abort or warn.
1041 *
1042 * Per level, that the masks hold only the values they are meant to and that no water cell has
1043 * a non-positive depth. Per level pair, over the region the finer level covers, that no coarse
1044 * water point sits over fine points that are all land.
1045 */
1046void
1048{
1049 BL_PROFILE("REMORA::check_mask_consistency()");
1051 return;
1052 }
1053
1054 Long nbad_val = 0, nbad_h = 0, ndry_r = 0, ndry_u = 0, ndry_v = 0, nmissed = 0;
1055
1056 // Per-level checks. Mask values matter because the plotfile writer decides what to blank
1057 // by comparing them against 0 exactly, so a fractional mask stops masking; a water cell
1058 // with h <= 0 matters because stretch_transform divides by hc + h, giving quiet garbage
1059 // rather than a crash.
1060 for (int lev = 0; lev <= finest_level; ++lev)
1061 {
1064 using ReduceTuple = typename decltype(reduce_data)::Type;
1065
1066 for ( MFIter mfi(*vec_mskr[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
1067 {
1068 Array4<const Real> const& mskr = vec_mskr[lev]->const_array(mfi);
1069 Array4<const Real> const& msku = vec_msku[lev]->const_array(mfi);
1070 Array4<const Real> const& mskv = vec_mskv[lev]->const_array(mfi);
1071 Array4<const Real> const& mskp = vec_mskp[lev]->const_array(mfi);
1072 Array4<const Real> const& h = vec_h[lev]->const_array(mfi);
1073
1074 Box bx = mfi.tilebox(); bx.makeSlab(2,0);
1075
1076 reduce_op.eval(bx, reduce_data, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1077 -> ReduceTuple
1078 {
1079 auto is_01 = [] (Real v) {
1080 return v == Real(0.0) || v == Real(1.0);
1081 };
1082 const bool bad = !is_01(mskr(i,j,k)) || !is_01(msku(i,j,k)) ||
1083 !is_01(mskv(i,j,k)) ||
1084 !(is_01(mskp(i,j,k)) || mskp(i,j,k) == Real(2.0));
1085 const bool bad_h = (mskr(i,j,k) > Real(0.5)) && (h(i,j,k) <= Real(0.0));
1086 return {static_cast<Long>(bad), static_cast<Long>(bad_h)};
1087 });
1088 }
1090 nbad_val += amrex::get<0>(hv);
1091 nbad_h += amrex::get<1>(hv);
1092 }
1093
1094 // Level-pair checks, over the region the finer level covers. A coarse water point over
1095 // nothing but land would leave the average-down nothing to divide by. Coarsening makes
1096 // that unreachable for cell centers -- a wet coarse cell is wet because some fine cell in
1097 // its own block is -- but not for faces: a coarse u-face is open whenever both its cells
1098 // are wet, only the fine faces in its own plane count, and the wet fine cells that made
1099 // those coarse cells wet may all lie elsewhere in their blocks.
1100 for (int crse_lev = 0; crse_lev < finest_level; ++crse_lev)
1101 {
1102 const int flev = crse_lev + 1;
1103 const IntVect ratio = refRatio(crse_lev);
1104 const BoxArray cba = amrex::coarsen(vec_mskr[flev]->boxArray(), ratio);
1105 const DistributionMapping& dmf = vec_mskr[flev]->DistributionMap();
1106
1107 // Sentinel, so an incomplete copy shows up as itself rather than as a coarse land
1108 // point that the checks below would quietly pass over.
1109 MultiFab cmskr(cba, dmf, 1, 0);
1110 MultiFab cmsku(amrex::convert(cba, IntVect(1,0,0)), dmf, 1, 0);
1111 MultiFab cmskv(amrex::convert(cba, IntVect(0,1,0)), dmf, 1, 0);
1112 cmskr.setVal(-one); cmsku.setVal(-one); cmskv.setVal(-one);
1113 cmskr.ParallelCopy(*vec_mskr[crse_lev], 0, 0, 1);
1114 cmsku.ParallelCopy(*vec_msku[crse_lev], 0, 0, 1);
1115 cmskv.ParallelCopy(*vec_mskv[crse_lev], 0, 0, 1);
1116
1119 using ReduceTuple = typename decltype(reduce_data)::Type;
1120
1121 for ( MFIter mfi(cmskr, TilingIfNotGPU()); mfi.isValid(); ++mfi )
1122 {
1123 Array4<const Real> const& cr = cmskr.const_array(mfi);
1124 Array4<const Real> const& cu = cmsku.const_array(mfi);
1125 Array4<const Real> const& cv = cmskv.const_array(mfi);
1126 Array4<const Real> const& fr = vec_mskr[flev]->const_array(mfi);
1127 Array4<const Real> const& fu = vec_msku[flev]->const_array(mfi);
1128 Array4<const Real> const& fv = vec_mskv[flev]->const_array(mfi);
1129
1130 Box bx = mfi.tilebox(); bx.makeSlab(2,0);
1131 const int rx = ratio[0];
1132 const int ry = ratio[1];
1133
1134 // Three passes: a cell-centered box stops at hi, so it would miss the high-side
1135 // face that average_down_masked does iterate. nodaltilebox partitions the nodal
1136 // range; faces shared between boxes are still counted twice, which can only
1137 // inflate a diagnostic.
1138 const Long lzero = 0;
1139
1140 // Cell centers: the whole rx by ry block.
1141 reduce_op.eval(bx, reduce_data, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1142 -> ReduceTuple
1143 {
1144 const int ii = i * rx;
1145 const int jj = j * ry;
1146
1147 Real wet_r = zero;
1148 for (int jref = 0; jref < ry; ++jref) {
1149 for (int iref = 0; iref < rx; ++iref) {
1150 wet_r += amrex::min(Real(1.0), fr(ii+iref, jj+jref, k));
1151 }
1152 }
1153
1154 const bool missed = cr(i,j,k) < zero;
1155 return {static_cast<Long>(missed),
1156 static_cast<Long>(!missed && cr(i,j,k) > Real(0.5) && wet_r == zero),
1157 lzero, lzero};
1158 });
1159
1160 // u-faces: only the fine faces in the coarse face's plane. Tests the sentinel too,
1161 // so an incomplete copy reports itself instead of failing the > 0.5 test.
1162 Box ubx = mfi.nodaltilebox(0); ubx.makeSlab(2,0);
1163 reduce_op.eval(ubx, reduce_data, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1164 -> ReduceTuple
1165 {
1166 const int ii = i * rx;
1167 const int jj = j * ry;
1168
1169 Real wet_u = zero;
1170 for (int jref = 0; jref < ry; ++jref) {
1171 wet_u += amrex::min(Real(1.0), fu(ii, jj+jref, k));
1172 }
1173
1174 const bool missed = cu(i,j,k) < zero;
1175 return {static_cast<Long>(missed), lzero,
1176 static_cast<Long>(!missed && cu(i,j,k) > Real(0.5) && wet_u == zero),
1177 lzero};
1178 });
1179
1180 // v-faces, likewise.
1181 Box vbx = mfi.nodaltilebox(1); vbx.makeSlab(2,0);
1182 reduce_op.eval(vbx, reduce_data, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1183 -> ReduceTuple
1184 {
1185 const int ii = i * rx;
1186 const int jj = j * ry;
1187
1188 Real wet_v = zero;
1189 for (int iref = 0; iref < rx; ++iref) {
1190 wet_v += amrex::min(Real(1.0), fv(ii+iref, jj, k));
1191 }
1192
1193 const bool missed = cv(i,j,k) < zero;
1194 return {static_cast<Long>(missed), lzero, lzero,
1195 static_cast<Long>(!missed && cv(i,j,k) > Real(0.5) && wet_v == zero)};
1196 });
1197 }
1199 nmissed += amrex::get<0>(hv);
1200 ndry_r += amrex::get<1>(hv);
1201 ndry_u += amrex::get<2>(hv);
1202 ndry_v += amrex::get<3>(hv);
1203 }
1204
1205 ParallelDescriptor::ReduceLongSum(nbad_val);
1206 ParallelDescriptor::ReduceLongSum(nbad_h);
1207 ParallelDescriptor::ReduceLongSum(nmissed);
1208 ParallelDescriptor::ReduceLongSum(ndry_r);
1209 ParallelDescriptor::ReduceLongSum(ndry_u);
1210 ParallelDescriptor::ReduceLongSum(ndry_v);
1211
1212 if (nbad_val == 0 && nbad_h == 0 && nmissed == 0 &&
1213 ndry_r == 0 && ndry_u == 0 && ndry_v == 0) {
1214 if (verbose > 0) {
1215 amrex::Print() << "Land-sea masks are consistent across " << finest_level+1
1216 << " level(s)" << std::endl;
1217 }
1218 return;
1219 }
1220
1221 std::string msg = "Land-sea mask problems:";
1222 if (nbad_val > 0) {
1223 msg += "\n " + std::to_string(nbad_val) + " point(s) where a mask is neither 0 nor 1"
1224 " (psi may also be 2). The plotfile writer decides what to blank by comparing"
1225 " masks against 0 exactly, so a fractional mask silently stops masking.";
1226 }
1227 if (nbad_h > 0) {
1228 msg += "\n " + std::to_string(nbad_h) + " water point(s) with depth <= 0."
1229 " stretch_transform divides by hc + h, so this is quiet garbage rather than a"
1230 " crash.";
1231 }
1232 if (nmissed > 0) {
1233 msg += "\n " + std::to_string(nmissed) + " refined point(s) with no coarse point"
1234 " beneath them, which should be impossible under proper nesting.";
1235 }
1236 if (ndry_r > 0) {
1237 msg += "\n " + std::to_string(ndry_r) + " coarse water cell(s) with only land"
1238 " beneath them.";
1239 }
1240 if (ndry_u > 0 || ndry_v > 0) {
1241 msg += "\n " + std::to_string(ndry_u) + " coarse u-face(s) and " +
1242 std::to_string(ndry_v) + " v-face(s) that are open with no open fine face"
1243 " beneath them. The coarse grid cannot see a barrier the fine grid resolves."
1244 " Closing the coarse face would contradict the coarsening rule, so move the"
1245 " refined grids off it or coarsen the mask by hand.";
1246 }
1247 if (ndry_r > 0 || ndry_u > 0 || ndry_v > 0) {
1248 msg += "\nThe two-way average-down divides by the number of wet fine points, so these"
1249 " have no value to take.";
1250 }
1251 msg += "\nSet remora.mask_consistency = warn to continue anyway.";
1252
1254 amrex::Abort(msg);
1255 } else {
1256 amrex::Print() << "WARNING: " << msg << std::endl;
1257 }
1258}
1259
1260/**
1261 * Coarsen the full-domain bathymetry from crse_lev+1 onto crse_lev, grow cells included,
1262 * weighted by the land/sea mask.
1263 *
1264 * Averaging every fine cell would mix in whatever the grid file holds under land, which on a
1265 * ROMS grid is a fill value with no physical meaning. A wet coarse cell should take the depth
1266 * of the water under it. See REMORA_MaskedAverageDown.H for why the arithmetic is written the
1267 * way it is.
1268 *
1269 * @param[in ] crse_lev level to coarsen onto
1270 */
1271void
1273{
1274 // The mask is indexed by the same local box number as the bathymetry, so the two have to
1275 // be distributed alike. full_domain_dmap is what makes that true; assert it here rather
1276 // than read another rank's box.
1279
1280 auto const& crsema = vec_h_full_domain[crse_lev]->arrays();
1281 auto const& finema = vec_h_full_domain[crse_lev+1]->const_arrays();
1282 auto const& fmskma = vec_mskr_full_domain[crse_lev+1]->const_arrays();
1283 auto ratio = refRatio(crse_lev);
1285 const int ncomp = vec_h_full_domain[crse_lev]->nComp();
1287 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
1288 {
1289 const int ii = i * ratio[0];
1290 const int jj = j * ratio[1];
1291 Real num = zero, den = zero, sum_all = zero;
1292 for (int jref = 0; jref < ratio[1]; ++jref) {
1293 for (int iref = 0; iref < ratio[0]; ++iref) {
1294 const Real hf = finema[box_no](ii+iref, jj+jref, k, n);
1295 const Real m = amrex::min(Real(1.0), fmskma[box_no](ii+iref, jj+jref, k));
1296 num += hf * m;
1297 den += m;
1298 sum_all += hf;
1299 }
1300 }
1301 // All-land: no water to average, but h still has to hold something, so fall back to
1302 // the plain mean. That also makes an all-wet or all-land group reproduce
1303 // average_down_with_grow_cells bit for bit. This is where the bathymetry parts company
1304 // with avgdown_masked, which multiplies by the coarse mask and so leaves an all-land
1305 // point at zero: a free surface under land need not hold anything, a depth does.
1306 crsema[box_no](i,j,k,n) = (den > zero)
1307 ? num * (one/den)
1308 : sum_all * (one/Real(ratio[0]*ratio[1]));
1309 });
1310 Gpu::streamSynchronize();
1311}
1312
1313/**
1314 * @param[in ] lev level to operate on
1315 */
1316void
1318{
1319 BL_PROFILE("REMORA::set_hmixcoef()");
1320
1321 // Optional AMR scaling: decrease coefficients on refined levels linearly
1322 // with grid size (i.e., proportional to sqrt(cell area)). For a horizontal
1323 // refinement ratio rx x ry, the effective scale factor is 1/sqrt(rx*ry).
1324 Real lev_scale = one;
1326 Real rf = one;
1327 for (int l = 0; l < lev; ++l) {
1328 rf *= std::sqrt(static_cast<Real>(ref_ratio[l][0]) * static_cast<Real>(ref_ratio[l][1]));
1329 }
1330 lev_scale = one / rf;
1331 }
1332
1334 prob->init_analytic_hmix(lev, geom[lev], solverChoice,
1335 *this, *vec_visc2_p[lev], *vec_visc2_r[lev], *vec_diff2[lev]);
1336
1340 for (int n = 0; n < ncons; n++) {
1341 vec_diff2[lev]->setVal(solverChoice.tnu2[n] * lev_scale, n, 1);
1342 }
1343
1344 // Scale harmonic viscosity and diffusivity by the grid size as ROMS
1345 // does in Utility/ini_hmixcoef.F. Intended for curvilinear grids.
1346 //
1347 // Define the ROMS grid factor (grdscl):
1348 // G(i,j) = sqrt( 1 / (pm(i,j) * pn(i,j)) )
1349 // = sqrt(cell area)
1350 // Gmax = max over grid of G(i,j)
1351 //
1352 // Then horizontal harmonic mixing coefficients are scaled as:
1353 // nu(i,j) = nu0 * G(i,j) / Gmax
1354 // kappa_n(i,j) = kappa0 * G(i,j) / Gmax
1355 //
1356 // where:
1357 // nu0 = solverChoice.visc2
1358 // kappa0 = solverChoice.tnu2[n]
1359 //
1360 // This makes mixing strongest where grid spacing is largest.
1361 //
1362 // NOTE: The normalization (Gmax) is computed over the entire grid (ignoring masks).
1363 // Therefore, if the largest cell area occurs over land, the maximum over *wet* cells
1364 // (or in masked output files) may be smaller than the user-specified value.
1365
1367
1368 // ------------------------------------------------------------
1369 // Step 1: Compute grdmax over entire grid
1370 // ------------------------------------------------------------
1373 for (int n = 0; n < ncons; n++) {
1374 vec_diff2[lev]->setVal(solverChoice.tnu2[n], n, 1);
1375 }
1376
1377 // NOTE: This must be GPU-safe. Do not dereference MultiFab data on host.
1378 // Force the reduction to run in the GPU launch region if GPUs are enabled.
1379 // (If the launch region is disabled at runtime, ReduceMax may fall back to
1380 // a host path that can try to read device-only data.)
1381 amrex::Gpu::LaunchSafeGuard lsg(true);
1382 Real denom_min = amrex::ReduceMin(*vec_pm[lev], *vec_pn[lev], 0,
1383 [=] AMREX_GPU_HOST_DEVICE (Box const& bx,
1384 Array4<Real const> const& pm,
1385 Array4<Real const> const& pn) -> Real
1386 {
1388 amrex::Loop(bx, [=,&local_min] (int i, int j, int) noexcept
1389 {
1390 local_min = amrex::min(local_min, pm(i,j,0) * pn(i,j,0));
1391 });
1392 return local_min;
1393 });
1394
1395 ParallelDescriptor::ReduceRealMin(denom_min);
1396 if (denom_min <= zero) {
1397 Abort("scaled_to_grid: found non-positive pm*pn (grid metrics must be > 0)");
1398 }
1399
1400 Real grdmax = amrex::ReduceMax(*vec_pm[lev], *vec_pn[lev], 0,
1401 [=] AMREX_GPU_HOST_DEVICE (Box const& bx,
1402 Array4<Real const> const& pm,
1403 Array4<Real const> const& pn) -> Real
1404 {
1405 Real local_max = zero;
1406 amrex::Loop(bx, [=,&local_max] (int i, int j, int) noexcept
1407 {
1408 Real denom = pm(i,j,0) * pn(i,j,0);
1409 if (denom > zero) {
1410 Real G = std::sqrt(one / denom);
1411 local_max = amrex::max(local_max, G);
1412 }
1413 });
1414 return local_max;
1415 });
1416
1417 ParallelDescriptor::ReduceRealMax(grdmax);
1418 if (grdmax <= zero) {
1419 Abort("scaled_to_grid: grdmax <= 0");
1420 }
1421
1422 // Optional AMR scaling: decrease coefficients on refined levels linearly
1423 // with grid size (i.e., proportional to sqrt(cell area)). For a horizontal
1424 // refinement ratio rx x ry, the effective scale factor is 1/sqrt(rx*ry).
1425 lev_scale = one;
1427 Real rf = one;
1428 for (int l = 0; l < lev; ++l) {
1429 rf *= std::sqrt(static_cast<Real>(ref_ratio[l][0]) * static_cast<Real>(ref_ratio[l][1]));
1430 }
1431 lev_scale = one / rf;
1432 }
1433
1435 Real cff = visc0 / grdmax;
1436
1437 // ------------------------------------------------------------
1438 // Step 2: Set rho coefficients everywhere
1439 // ------------------------------------------------------------
1440 amrex::Gpu::DeviceVector<Real> diff0_d(ncons);
1441 amrex::Gpu::copy(amrex::Gpu::hostToDevice,
1442 solverChoice.tnu2.begin(), solverChoice.tnu2.begin() + ncons,
1443 diff0_d.begin());
1444 Real const* diff0_ptr = diff0_d.data();
1445
1446 for (MFIter mfi(*vec_visc2_r[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
1447 {
1448 const Box& bx = mfi.validbox();
1449 auto pm = vec_pm[lev]->const_array(mfi);
1450 auto pn = vec_pn[lev]->const_array(mfi);
1451 auto visc2_r = vec_visc2_r[lev]->array(mfi);
1452 auto diff2 = vec_diff2[lev]->array(mfi);
1453
1454 int ncons_local = ncons;
1455 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
1456 {
1457 Real denom = pm(i,j,0) * pn(i,j,0);
1458 Real grdscl = (denom > zero) ? std::sqrt(one / denom) : zero;
1459 visc2_r(i,j,0) = cff * grdscl;
1460
1461 for (int n = 0; n < ncons_local; n++) {
1462 diff2(i,j,0,n) = ((diff0_ptr[n] * lev_scale) / grdmax) * grdscl;
1463 }
1464 });
1465 }
1466
1467 // Fill ghost cells for rho coefficients BEFORE psi averaging
1468 Real time = zero;
1470
1471 // ------------------------------------------------------------
1472 // Step 3: Psi coefficients = average of 4 surrounding rho
1473 // ------------------------------------------------------------
1474 for (MFIter mfi(*vec_visc2_p[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
1475 {
1476 const Box& bx = mfi.validbox();
1477 auto visc2_p = vec_visc2_p[lev]->array(mfi);
1478 auto visc2_r = vec_visc2_r[lev]->const_array(mfi);
1479
1480 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
1481 {
1482 visc2_p(i,j,0) = fourth * (
1483 visc2_r(i-1,j-1,0) +
1484 visc2_r(i ,j-1,0) +
1485 visc2_r(i-1,j ,0) +
1486 visc2_r(i ,j ,0)
1487 );
1488 });
1489 }
1490
1492
1493 // Diagnostics
1494 // NOTE: coefficients are computed everywhere (including land). Output routines may later
1495 // mask land points (e.g., to FillValue in NetCDF/plotfiles), and analysis tools may
1496 // additionally apply mask_rho (setting land to 0). Report both conventions.
1497 //
1498 // Global (MPI-reduced) extrema over all valid cells (no ghost).
1499 Real visc_min_all = vec_visc2_r[lev]->min(0,0,false);
1500 Real visc_max_all = vec_visc2_r[lev]->max(0,0,false);
1501
1502 // Global extrema over *wet* rho points only, k=0.
1503 amrex::Gpu::LaunchSafeGuard lsg_diag(true);
1504 Real visc_min_wet = amrex::ReduceMin(*vec_visc2_r[lev], *vec_mskr[lev], 0,
1505 [=] AMREX_GPU_HOST_DEVICE (Box const& bx,
1506 Array4<Real const> const& visc2,
1507 Array4<Real const> const& mskr) -> Real
1508 {
1510 amrex::Loop(bx, [=,&local_min] (int i, int j, int) noexcept
1511 {
1512 if (mskr(i,j,0) > zero) {
1513 local_min = amrex::min(local_min, visc2(i,j,0));
1514 }
1515 });
1516 return local_min;
1517 });
1518 ParallelDescriptor::ReduceRealMin(visc_min_wet);
1519
1520 Real visc_max_wet = amrex::ReduceMax(*vec_visc2_r[lev], *vec_mskr[lev], 0,
1521 [=] AMREX_GPU_HOST_DEVICE (Box const& bx,
1522 Array4<Real const> const& visc2,
1523 Array4<Real const> const& mskr) -> Real
1524 {
1526 amrex::Loop(bx, [=,&local_max] (int i, int j, int) noexcept
1527 {
1528 if (mskr(i,j,0) > zero) {
1529 local_max = amrex::max(local_max, visc2(i,j,0));
1530 }
1531 });
1532 return local_max;
1533 });
1534 ParallelDescriptor::ReduceRealMax(visc_max_wet);
1535
1536 // Mimic "apply mask_rho" convention (dry -> 0).
1537 Real visc_min_mask0 = amrex::ReduceMin(*vec_visc2_r[lev], *vec_mskr[lev], 0,
1538 [=] AMREX_GPU_HOST_DEVICE (Box const& bx,
1539 Array4<Real const> const& visc2,
1540 Array4<Real const> const& mskr) -> Real
1541 {
1543 amrex::Loop(bx, [=,&local_min] (int i, int j, int) noexcept
1544 {
1545 const Real v = (mskr(i,j,0) > zero) ? visc2(i,j,0) : zero;
1546 local_min = amrex::min(local_min, v);
1547 });
1548 return local_min;
1549 });
1550 ParallelDescriptor::ReduceRealMin(visc_min_mask0);
1551
1552 Real visc_max_mask0 = amrex::ReduceMax(*vec_visc2_r[lev], *vec_mskr[lev], 0,
1553 [=] AMREX_GPU_HOST_DEVICE (Box const& bx,
1554 Array4<Real const> const& visc2,
1555 Array4<Real const> const& mskr) -> Real
1556 {
1558 amrex::Loop(bx, [=,&local_max] (int i, int j, int) noexcept
1559 {
1560 const Real v = (mskr(i,j,0) > zero) ? visc2(i,j,0) : zero;
1561 local_max = amrex::max(local_max, v);
1562 });
1563 return local_max;
1564 });
1565 ParallelDescriptor::ReduceRealMax(visc_max_mask0);
1566 if (ParallelDescriptor::IOProcessor() && lev == 0)
1567 {
1568 Print() << "\nHorizontal mixing scaled by grid metric\n";
1569 Print() << "grdmax = " << grdmax << "\n";
1571 Print() << "AMR scaling (linear) lev_scale = " << lev_scale << "\n";
1572 }
1573 Print() << "visc2(all) min/max = "
1574 << visc_min_all << " / "
1575 << visc_max_all << "\n";
1576 Print() << "visc2(wet,k=0) min/max = "
1577 << visc_min_wet << " / "
1578 << visc_max_wet << "\n";
1579 Print() << "visc2(mask->0) min/max = "
1580 << visc_min_mask0 << " / "
1581 << visc_max_mask0 << "\n";
1582 }
1583
1584 } else {
1585 Abort("Don't know this horizontal mixing type");
1586 }
1587
1588 // Final FillPatch for all fields
1589 Real time = zero;
1592 for (int n = 0; n < ncons; n++) {
1594 foextrap_periodic_bc(), BdyVars::null, n, false);
1595 }
1596}
1597
1598/**
1599 * @param[in ] lev level to operate on
1600 */
1601void
1603{
1604 BL_PROFILE("REMORA::set_smflux()");
1606 prob->init_analytic_smflux(lev, geom[lev], solverChoice, *this,*vec_sustr[lev], *vec_svstr[lev]);
1608#ifdef REMORA_USE_NETCDF
1609 sustr_data_from_file->update_interpolated_to_time(model_time(t_old[lev]), lev, vec_sustr[lev].get(), geom, ref_ratio);
1610 svstr_data_from_file->update_interpolated_to_time(model_time(t_old[lev]), lev, vec_svstr[lev].get(), geom, ref_ratio);
1613#endif
1614 }
1615}
1616
1617/**
1618 * @param[in ] lev level to operate on
1619 */
1620void
1622{
1623 BL_PROFILE("REMORA::set_surface_state()");
1624
1625 auto& bulk_flux_type = solverChoice.bulk_flux_type;
1626
1627 // Every update below skips driver-supplied lanes individually, on
1628 // !driver_atmos_state_from_driver[...]. This used to abort outright if any
1629 // lane was driver-supplied, which made the function unreachable in a coupled
1630 // run and so denied the *withheld* lanes the fallback those guards provide.
1631
1632#ifdef REMORA_USE_NETCDF
1633 auto update_from_netcdf = [&](std::unique_ptr<NCTimeSeries>& data_from_file,
1635 data_from_file->update_interpolated_to_time(model_time(t_old[lev]), lev, mf_vec[lev].get(), geom, ref_ratio);
1637 foextrap_periodic_bc(), BdyVars::null, 0, false);
1638 };
1639
1642 }
1645 }
1646
1649 }
1653 vec_qair[lev]->mult(amrex::Real(0.01));
1654 }
1655 }
1658 }
1661 }
1664 }
1667 }
1670 }
1671 if (bulk_flux_type[BulkFlux::EminusP] == BulkForcingType::netcdf) {
1673 }
1674#else
1675 for (int idx = 0; idx < BulkFlux::NumTypes; ++idx) {
1676 if (bulk_flux_type[idx] == BulkForcingType::netcdf) {
1677 amrex::Abort("NetCDF bulk-flux forcing requires building with NetCDF");
1678 }
1679 }
1680#endif
1681
1682 MultiFab* analytic_uwind = (bulk_flux_type[BulkFlux::Uwind] == BulkForcingType::analytic &&
1684 MultiFab* analytic_vwind = (bulk_flux_type[BulkFlux::Vwind] == BulkForcingType::analytic &&
1686 MultiFab* analytic_Tair = (bulk_flux_type[BulkFlux::Tair] == BulkForcingType::analytic &&
1688 MultiFab* analytic_qair = (bulk_flux_type[BulkFlux::Qair] == BulkForcingType::analytic &&
1690 MultiFab* analytic_Pair = (bulk_flux_type[BulkFlux::Pair] == BulkForcingType::analytic &&
1692 MultiFab* analytic_srflx = (bulk_flux_type[BulkFlux::SWrad] == BulkForcingType::analytic &&
1694 MultiFab* analytic_lwrad = (bulk_flux_type[BulkFlux::LWrad] == BulkForcingType::analytic &&
1696 MultiFab* analytic_rain = (bulk_flux_type[BulkFlux::Rain] == BulkForcingType::analytic &&
1698 MultiFab* analytic_cloud = (bulk_flux_type[BulkFlux::Cloud] == BulkForcingType::analytic &&
1700 MultiFab* analytic_EminusP = bulk_flux_type[BulkFlux::EminusP] == BulkForcingType::analytic ? vec_EminusP[lev].get() : nullptr;
1701
1702 if (analytic_uwind != nullptr || analytic_vwind != nullptr ||
1703 analytic_Tair != nullptr || analytic_qair != nullptr || analytic_Pair != nullptr ||
1704 analytic_srflx != nullptr || analytic_lwrad != nullptr || analytic_rain != nullptr ||
1705 analytic_cloud != nullptr || analytic_EminusP != nullptr) {
1706 // Every field has to be passed to init_analytic_surface_var, but only the
1707 // analytic ones may be modified: the others hold constant or NetCDF data that is
1708 // set once at level creation or interpolated just above. Hand the non-analytic
1709 // slots scratch data that is thrown away on return, so the problem code can write
1710 // to all ten references unconditionally without clobbering anything.
1712 auto analytic_or_scratch = [&] (MultiFab* mf_analytic,
1713 const std::unique_ptr<MultiFab>& mf_lev) -> MultiFab&
1714 {
1715 if (mf_analytic != nullptr) { return *mf_analytic; }
1716 scratch_mf.emplace_back(new MultiFab(mf_lev->boxArray(), mf_lev->DistributionMap(),
1717 mf_lev->nComp(), mf_lev->nGrowVect()));
1718 return *scratch_mf.back();
1719 };
1720
1721 prob->init_analytic_surface_var(lev, geom[lev], solverChoice, *this,
1732 }
1733
1734 if (vec_uwind[lev] != nullptr) { vec_uwind[lev]->FillBoundary(geom[lev].periodicity()); }
1735 if (vec_vwind[lev] != nullptr) { vec_vwind[lev]->FillBoundary(geom[lev].periodicity()); }
1736 if (vec_Tair[lev] != nullptr) { vec_Tair[lev]->FillBoundary(geom[lev].periodicity()); }
1737 if (vec_qair[lev] != nullptr) { vec_qair[lev]->FillBoundary(geom[lev].periodicity()); }
1738 if (vec_Pair[lev] != nullptr) { vec_Pair[lev]->FillBoundary(geom[lev].periodicity()); }
1739 if (vec_srflx[lev] != nullptr) { vec_srflx[lev]->FillBoundary(geom[lev].periodicity()); }
1740 if (vec_longwave_down[lev] != nullptr) { vec_longwave_down[lev]->FillBoundary(geom[lev].periodicity()); }
1741 if (vec_rain[lev] != nullptr) { vec_rain[lev]->FillBoundary(geom[lev].periodicity()); }
1742 if (vec_cloud[lev] != nullptr) { vec_cloud[lev]->FillBoundary(geom[lev].periodicity()); }
1743 if (vec_EminusP[lev] != nullptr) { vec_EminusP[lev]->FillBoundary(geom[lev].periodicity()); }
1744}
1745
1746/**
1747 * @param[in ] lev level to operate on
1748 * @param[in ] time current time for initialization
1749 */
1750void
1752{
1753 BL_PROFILE("REMORA::init_only()");
1754 t_new[lev] = time;
1756
1757 cons_new[lev]->setVal(zero);
1758 xvel_new[lev]->setVal(zero);
1759 yvel_new[lev]->setVal(zero);
1760 zvel_new[lev]->setVal(zero);
1761
1762 xvel_old[lev]->setVal(zero);
1763 yvel_old[lev]->setVal(zero);
1764 zvel_old[lev]->setVal(zero);
1765
1766 vec_ru[lev]->setVal(zero);
1767 vec_rv[lev]->setVal(zero);
1768
1769 vec_ru2d[lev]->setVal(zero);
1770 vec_rv2d[lev]->setVal(zero);
1771
1774 }
1775
1776 // High-resolution grid data, both sources in one place because the order matters: the mask
1777 // is coarsened first, and the bathymetry is then coarsened with it, so a coarse cell only
1778 // partly covered by water takes the depth of that water. mask_type and ic_type are set
1779 // independently, so each is dispatched on its own.
1780 if (lev==0 and hires_grid_level > 0) {
1782
1785 } else if (solverChoice.mask_type == MaskType::netcdf) {
1786#ifdef REMORA_USE_NETCDF
1787 amrex::Print() << "Reading high resolution land-sea mask" << std::endl;
1789 amrex::Print() << "Done reading in high resolution land-sea mask" << std::endl;
1790#endif
1791 }
1792
1795 } else if (solverChoice.ic_type == IC_Type::netcdf) {
1796#ifdef REMORA_USE_NETCDF
1797 amrex::Print() << "Reading high resolution bathymetry and grid data" << std::endl;
1800 amrex::Print() << "Done reading in high resolution bathymetry and grid data" << std::endl;
1801#endif
1802 }
1803 }
1804
1805#ifdef REMORA_USE_NETCDF
1808
1809 if (solverChoice.do_any_clim_nudg && lev == 0) {
1810 if (nc_clim_his_file.empty() || nc_clim_his_file[0].empty()) {
1811 amrex::Error("NetCDF climatology file name must be provided via input");
1812 }
1815 clim_ubar_time_varname, geom[lev].Domain(),vec_ubar[lev].get(),true,true));
1817 clim_ubar_time_varname, geom[lev].Domain(),vec_vbar[lev].get(),true,true));
1818 ubar_clim_data_from_file->Initialize();
1819 vbar_clim_data_from_file->Initialize();
1820 }
1824 u_clim_data_from_file->Initialize();
1825 v_clim_data_from_file->Initialize();
1826 }
1827 // Since the NCTimeSeries object isn't filling the cons_new MultiFab directly, we don't have to specify a component.
1828 // It just needs to know the shape of the MultiFab
1830 for (int icomp = 0; icomp < ncons; ++icomp) {
1831 if (!solverChoice.do_cons_clim_nudg[icomp]) { continue; }
1832 // A tracer's climatology is stored in the file under the tracer's own
1833 // name, following the same convention ROMS uses. Check up front rather
1834 // than letting the read fail deep inside NCTimeSeries.
1835 for (const auto& fname : nc_clim_his_file) {
1837 amrex::Abort("Climatology file " + fname + " does not contain '" +
1838 cons_names[icomp] + "', which is required by remora.do_" +
1839 cons_names[icomp] + "_clim_nudg. Either add it to the file "
1840 "or turn that flag off.");
1841 }
1842 }
1845 cons_clim_data_from_file[icomp]->Initialize();
1846 }
1847 }
1848 }
1849
1851 amrex::Print() << "Calling init_bdry_from_netcdf at level " << lev << std::endl;
1853 amrex::Print() << "Boundary data loaded from netcdf file \n " << std::endl;
1854 }
1855
1856 // This will be a non-op if forcings specified analytically
1858 if (lev==0) {
1859 if (nc_frc_file.empty() || nc_frc_file[0].empty()) {
1860 amrex::Error("NetCDF forcing file name must be provided via input for surface momentum fluxes");
1861 }
1862 sustr_data_from_file.reset(new NCTimeSeries(nc_frc_file, "sustr", frc_time_varname, geom[lev].Domain(),vec_sustr[lev].get(), true, false));
1863 svstr_data_from_file.reset(new NCTimeSeries(nc_frc_file, "svstr", frc_time_varname, geom[lev].Domain(),vec_svstr[lev].get(), true, false));
1864 sustr_data_from_file->Initialize();
1865 svstr_data_from_file->Initialize();
1866 } else {
1869 }
1870 }
1871
1872 // Conditionally load atmospheric forcing fields from NetCDF based on source type.
1873 const auto& bulk_flux_type = solverChoice.bulk_flux_type;
1874 bool any_bulk_netcdf = false;
1875 for (int idx = 0; idx < BulkFlux::NumTypes; ++idx) {
1877 }
1878 if (lev == 0 && any_bulk_netcdf && (nc_frc_file.empty() || nc_frc_file[0].empty())) {
1879 amrex::Error("NetCDF forcing file name must be provided via input for bulk-flux atmospheric forcing");
1880 }
1881
1882 if (lev==0) {
1883 if (bulk_flux_type[BulkFlux::Uwind] == BulkForcingType::netcdf) {
1884 Uwind_data_from_file.reset(new NCTimeSeries(nc_frc_file, "Uwind", frc_time_varname, geom[lev].Domain(),vec_uwind[lev].get(), true, false));
1885 Uwind_data_from_file->Initialize();
1886 }
1887 if (bulk_flux_type[BulkFlux::Vwind] == BulkForcingType::netcdf) {
1888 Vwind_data_from_file.reset(new NCTimeSeries(nc_frc_file, "Vwind", frc_time_varname, geom[lev].Domain(),vec_vwind[lev].get(), true, false));
1889 Vwind_data_from_file->Initialize();
1890 }
1891 if (bulk_flux_type[BulkFlux::Tair] == BulkForcingType::netcdf) {
1892 Tair_data_from_file.reset(new NCTimeSeries(nc_frc_file, "Tair", frc_time_varname, geom[lev].Domain(),vec_Tair[lev].get(), true, false));
1893 Tair_data_from_file->Initialize();
1894 }
1895 if (bulk_flux_type[BulkFlux::Qair] == BulkForcingType::netcdf) {
1896 qair_data_from_file.reset(new NCTimeSeries(nc_frc_file, "qair", frc_time_varname, geom[lev].Domain(),vec_qair[lev].get(), true, false));
1897 qair_data_from_file->Initialize();
1898 }
1899 if (bulk_flux_type[BulkFlux::Pair] == BulkForcingType::netcdf) {
1900 Pair_data_from_file.reset(new NCTimeSeries(nc_frc_file, "Pair", frc_time_varname, geom[lev].Domain(),vec_Pair[lev].get(), true, false));
1901 Pair_data_from_file->Initialize();
1902 }
1903 if (bulk_flux_type[BulkFlux::SWrad] == BulkForcingType::netcdf) {
1904 srflx_data_from_file.reset(new NCTimeSeries(nc_frc_file, "swrad", frc_time_varname, geom[lev].Domain(),vec_srflx[lev].get(), true, false));
1905 srflx_data_from_file->Initialize();
1906 }
1907 if (bulk_flux_type[BulkFlux::Rain] == BulkForcingType::netcdf) {
1908 rain_data_from_file.reset(new NCTimeSeries(nc_frc_file, "rain", frc_time_varname, geom[lev].Domain(),vec_rain[lev].get(), true, false));
1909 rain_data_from_file->Initialize();
1910 }
1911 if (bulk_flux_type[BulkFlux::Cloud] == BulkForcingType::netcdf) {
1912 cloud_data_from_file.reset(new NCTimeSeries(nc_frc_file, "cloud", frc_time_varname, geom[lev].Domain(),vec_cloud[lev].get(), true, false));
1913 cloud_data_from_file->Initialize();
1914 }
1915 if (bulk_flux_type[BulkFlux::EminusP] == BulkForcingType::netcdf) {
1916 EminusP_data_from_file.reset(new NCTimeSeries(nc_frc_file, "EminusP", frc_time_varname, geom[lev].Domain(),vec_EminusP[lev].get(), true, false));
1917 EminusP_data_from_file->Initialize();
1918 }
1919 if (bulk_flux_type[BulkFlux::LWrad] == BulkForcingType::netcdf) {
1921 geom[lev].Domain(), vec_longwave_down[lev].get(), true, false));
1922 longwave_down_data_from_file->Initialize();
1923 }
1924 } else {
1925 if (bulk_flux_type[BulkFlux::Uwind] == BulkForcingType::netcdf) {
1927 }
1928 if (bulk_flux_type[BulkFlux::Vwind] == BulkForcingType::netcdf) {
1930 }
1931 if (bulk_flux_type[BulkFlux::Tair] == BulkForcingType::netcdf) {
1932 FillCoarsePatch(lev, time, vec_Tair[lev].get(), vec_Tair[lev-1].get(), foextrap_bc());
1933 }
1934 if (bulk_flux_type[BulkFlux::Qair] == BulkForcingType::netcdf) {
1935 FillCoarsePatch(lev, time, vec_qair[lev].get(), vec_qair[lev-1].get(), foextrap_bc());
1936 }
1937 if (bulk_flux_type[BulkFlux::Pair] == BulkForcingType::netcdf) {
1938 FillCoarsePatch(lev, time, vec_Pair[lev].get(), vec_Pair[lev-1].get(), foextrap_bc());
1939 }
1940 if (bulk_flux_type[BulkFlux::SWrad] == BulkForcingType::netcdf) {
1942 }
1943 if (bulk_flux_type[BulkFlux::Rain] == BulkForcingType::netcdf) {
1944 FillCoarsePatch(lev, time, vec_rain[lev].get(), vec_rain[lev-1].get(), foextrap_bc());
1945 }
1946 if (bulk_flux_type[BulkFlux::Cloud] == BulkForcingType::netcdf) {
1948 }
1949 if (bulk_flux_type[BulkFlux::EminusP] == BulkForcingType::netcdf) {
1951 }
1952 if (bulk_flux_type[BulkFlux::LWrad] == BulkForcingType::netcdf) {
1954 }
1955 }
1956
1957 // Only need to read in rivers on level 0
1958 // Will need to be on higher levels eventually
1959 if (solverChoice.do_rivers) {
1960 if (nc_riv_file.empty() || nc_riv_file[0].empty()) {
1961 amrex::Error("NetCDF river file name must be provided via input for rivers");
1962 }
1963 auto dom = geom[0].Domain();
1964 int nz = dom.length(2);
1965 // Every cell-centered tracer can take river input. The field is named for the
1966 // tracer, as in ROMS: river_temp, river_salt, river_tracer, river_NO3, ...
1967 river_source_cons.resize(ncons);
1968 for (int icomp = 0; icomp < ncons; ++icomp) {
1969 if (!solverChoice.do_rivers_cons[icomp]) { continue; }
1970
1971 const std::string field = "river_" + cons_names[icomp];
1972 for (const auto& fname : nc_riv_file) {
1973 if (!QueryNetCDFHasVars(fname, {field})) {
1974 // The flag may have come from remora.do_rivers_scalar rather than the
1975 // per-tracer key, so name the tracer and the key that switches it off.
1976 amrex::Abort("River file " + fname + " does not contain '" + field +
1977 "', but river input is enabled for tracer '" +
1978 cons_names[icomp] + "'. Either add that variable to the "
1979 "file, or set remora.do_rivers_" + cons_names[icomp] +
1980 " = false.");
1981 }
1982 }
1983
1985 river_source_cons[icomp]->Initialize();
1986 }
1987 river_source_transport.reset(new NCTimeSeriesRiver(nc_riv_file, "river_transport", riv_time_varname, nz, 0, 1));
1988 river_source_transport->Initialize();
1989 river_source_transportbar.reset(new NCTimeSeriesRiver(nc_riv_file, "river_transport", riv_time_varname, nz, 1, 1));
1990 river_source_transportbar->Initialize();
1992 }
1993
1994#else
1996 Abort("Not compiled with NetCDF, but remora.ic_type = netcdf reads initial and grid data from file");
1997 }
1998 // hires_grid_level and hires_init_level need no guard: with analytic initialization
1999 // neither reads NetCDF, and the netcdf case is caught above.
2001 Abort("Not compiled with NetCDF, but selected boundary conditions require NetCDF");
2002 }
2003 if (solverChoice.do_rivers) {
2004 Abort("Not compiled with NetCDF, but using river sources requires NetCDF");
2005 }
2006#endif
2007
2009 // Has to follow set_bathymetry, not precede it as it used to: the mask now has a
2010 // hires_grid_level path of its own, which needs the full-domain data read just above,
2011 // and an analytic mask needs the grid coordinates that set_bathymetry -> set_grid_scale
2012 // fills on the netcdf path.
2013 set_masks(lev);
2014
2015 // Has to sit between set_masks and set_zeta. After set_masks, since
2016 // ensure_full_domain_masks seeds level 0 from vec_mskr[0], and init_masks' all-water
2017 // placeholder would reduce the weighting below to a plain mean. Before set_zeta, which
2018 // reads the vec_zeta_full_domain this fills.
2019 if (lev==0 and hires_init_level > 0) {
2021#ifdef REMORA_USE_NETCDF
2022 amrex::Print() << "Reading high resolution initial data" << std::endl;
2024 // The initial-state cascade is mask-weighted, so a mask has to exist this high up.
2027 // Biology source is chosen by remora.biology_ic_type, not by ic_type,
2028 // so this goes through the same dispatcher as the per-level path.
2029 // Must follow init_data_full_domain_from_netcdf: the analytic biology
2030 // profiles read temperature.
2033 amrex::Print() << "Done reading in high resolution initial data" << std::endl;
2034#endif
2035 } else if (solverChoice.ic_type == IC_Type::analytic) {
2039 }
2040 }
2041
2042 set_zeta(lev);
2044
2045 if (lev==0) {
2046 if (hires_init_level < 0) {
2049 } else if (solverChoice.ic_type == IC_Type::netcdf) {
2050#ifdef REMORA_USE_NETCDF
2051 amrex::Print() << "Calling init_data_from_netcdf " << std::endl;
2053 bool apply_eminusp = false;
2055 amrex::Print() << "Initial data loaded from netcdf file \n " << std::endl;
2056#endif
2057 } else {
2058 amrex::Abort("Unknown IC_Type");
2059 }
2060 // Biology last, and outside the ic_type branches: its source is
2061 // chosen independently by remora.biology_ic_type, and the analytic
2062 // profiles need the physical fields already in place.
2064 } else {
2065 set_init_data_averaged_down(lev); // also sets biology data
2066 bool apply_eminusp = false;
2068 // Since set_grid_scale is usually called from init_analytic for analytic problems
2071 }
2072 }
2073 } else {
2074 if (lev > hires_init_level) {
2079 } else {
2080 set_init_data_averaged_down(lev); // also sets biology data
2081 bool apply_eminusp = false;
2084 // Since set_grid_scale is usually called from init_analytic for analytic problems
2086 }
2087 }
2088 }
2089
2090 // Ensure that the face-based data are the same on both sides of a periodic domain.
2091 // The data associated with the lower grid ID is considered the correct value.
2092 xvel_new[lev]->OverrideSync(geom[lev].periodicity());
2093 yvel_new[lev]->OverrideSync(geom[lev].periodicity());
2094 zvel_new[lev]->OverrideSync(geom[lev].periodicity());
2095
2097
2101
2102 // Previously set smflux here with OverrideSync:
2103// set_smflux(lev);
2104// prob->init_analytic_smflux(lev, geom[lev], solverChoice, *this, *vec_sustr[lev], *vec_svstr[lev]);
2105// vec_sustr[lev]->OverrideSync(geom[lev].periodicity());
2106// vec_svstr[lev]->OverrideSync(geom[lev].periodicity());
2107
2108}
2109
2110void
2112{
2113 BL_PROFILE("REMORA::ReadParameters()");
2114 {
2115 ParmParse pp; // Traditionally, max_step and stop_time do not have prefix, so allow it for now.
2116 bool noprefix_max_step = pp.queryAdd("max_step", max_step);
2117 bool noprefix_stop_time = pp.queryAdd("stop_time", stop_time);
2118 bool remora_max_step = pp.queryAdd("remora.max_step", max_step);
2119 bool remora_stop_time = pp.queryAdd("remora.stop_time", stop_time);
2121 Abort("remora.max_step and max_step are both specified. Please use only one!");
2122 }
2124 Abort("remora.stop_time and stop_time are both specified. Please use only one!");
2125 }
2126 }
2127
2129
2130 // Common physics and simulation parameters
2132 pp.queryAdd("biology_model", biology_model_string);
2134
2137
2138 // Source of the biology initial condition, independent of ic_type.
2139 // Default "follow" reproduces the previous behaviour exactly.
2141 pp.queryAdd("biology_ic_type", biology_ic_string);
2143
2144 // Bridge-vs-native selection and diagnostic verbosity are runtime
2145 // controls so a parity comparison never requires a rebuild. Both
2146 // parse unconditionally; without USE_FENNEL_FORT there is no bridge
2147 // to select, so asking for it is an error rather than a silent
2148 // fallback to the path being validated.
2149 pp.queryAdd("use_biology_cpp_answer", use_biology_cpp_answer);
2150 pp.queryAdd("biology_debug", biology_debug);
2151 pp.queryAdd("biology_debug_i", biology_debug_i);
2152 pp.queryAdd("biology_debug_j", biology_debug_j);
2153#ifndef REMORA_USE_FENNEL_FORT
2154 if (use_biology_cpp_answer == 0) {
2155 amrex::Abort("remora.use_biology_cpp_answer = 0 selects the ROMS "
2156 "Fennel Fortran bridge, which is not compiled in. "
2157 "Rebuild with USE_FENNEL_FORT=TRUE (GNUmake) or "
2158 "-DREMORA_ENABLE_FENNEL_FORT=ON (CMake).");
2159 }
2160#endif
2161#ifndef REMORA_USE_BIOLOGY_DIAG
2162 if (biology_debug > 0) {
2163 amrex::Abort("remora.biology_debug > 0 requests the Fennel parity "
2164 "diagnostics, which are not compiled in. Rebuild with "
2165 "USE_BIOLOGY_DIAG=TRUE (GNUmake) or "
2166 "-DREMORA_ENABLE_BIOLOGY_DIAG=ON (CMake).");
2167 }
2168#endif
2169
2170 // Biology tracers are counted separately from the passive scalars, so a run can
2171 // carry dye and biology at once.
2172 nbio = static_cast<int>(REMORABiology::tracer_names(biology_model, fennel_params).size());
2173 } else {
2174 nbio = 0;
2175 }
2176 // Dye is opt-in, biology or not: a component nothing asked for is one more thing to
2177 // advect, diffuse, and explain in every plotfile and boundary file.
2178 pp.queryAdd("nscalar", nscalar);
2179 if (nscalar < 0) {
2180 amrex::Abort("remora.nscalar must be non-negative");
2181 }
2185
2186 // remora.nscalar used to be required to equal the biology tracer count; it now counts
2187 // dye only and adds to it. Print the layout so a run carrying both is unmistakable,
2188 // and an input written against the old meaning is caught by eye rather than by a
2189 // surprising component count much later.
2190 if (nbio > 0 && nscalar > 0) {
2191 amrex::Print() << "Carrying " << nscalar << " passive scalar(s) and " << nbio
2192 << " biology tracer(s), for " << ncons << " cell-centered components: ";
2193 for (int icomp = 0; icomp < ncons; ++icomp) {
2194 amrex::Print() << cons_names[icomp] << (icomp + 1 < ncons ? " " : "\n");
2195 }
2196 }
2197
2198 pp.queryAdd("check_file", check_file);
2199 pp.queryAdd("check_int", check_int);
2200 pp.queryAdd("check_int_time", check_int_time);
2201 pp.queryAdd("expand_plotvars_to_unif_rr", expand_plotvars_to_unif_rr);
2202 pp.query("plotfile_fill_value", plotfile_fill_value);
2203 pp.query("netcdf_fill_value", netcdf_fill_value);
2204 pp.queryAdd("restart", restart_chkfile);
2205 pp.queryAdd("start_time", start_time);
2206
2207 num_boxes_at_level.resize(max_level + 1, 0);
2208 boxes_at_level.resize(max_level + 1);
2209 num_boxes_at_level[0] = 1;
2210 boxes_at_level[0].resize(1);
2211 boxes_at_level[0][0] = geom[0].Domain();
2212
2213 if (pp.contains("data_log")) {
2214 int num_datalogs = pp.countval("data_log");
2215 datalog.resize(num_datalogs);
2216 datalogname.resize(num_datalogs);
2217 pp.queryarr("data_log", datalogname, 0, num_datalogs);
2218 for (int i = 0; i < num_datalogs; i++)
2220 }
2221
2222 pp.queryAdd("v", verbose);
2223 pp.queryAdd("sum_interval", sum_interval);
2224 pp.queryAdd("sum_period", sum_per);
2225 pp.queryAdd("file_min_digits", file_min_digits);
2226
2227 if (file_min_digits < 0) {
2228 amrex::Abort("remora.file_min_digits must be non-negative");
2229 }
2230
2231 pp.queryAdd("cfl", cfl);
2232 pp.queryAdd("change_max", change_max);
2233 pp.queryAdd("fixed_dt", fixed_dt);
2234
2235 // remora.fixed_fast_dt has been removed. It only ever served to infer the number of
2236 // barotropic substeps, and only when remora.fixed_dt was also given -- which left the
2237 // ratio at zero on every other path, including a CFL-driven run. amrex does not abort
2238 // on unused inputs by default, so catch it here rather than letting a stale input file
2239 // silently fall back to whatever remora.ndtfast happens to be.
2240 if (pp.contains("fixed_fast_dt")) {
2241 amrex::Abort("remora.fixed_fast_dt has been removed. Set remora.ndtfast (the "
2242 "number of barotropic steps per baroclinic step) instead; it is what "
2243 "fixed_fast_dt was used to infer, as remora.fixed_dt / "
2244 "remora.fixed_fast_dt");
2245 }
2246
2247 // remora.ndtfast is the preferred name; remora.fixed_ndtfast_ratio is kept as a
2248 // deprecated alias so existing input files keep working. Read the alias first, so
2249 // that the queryAdd below records the resulting value under the preferred name.
2250 if (pp.contains("fixed_ndtfast_ratio")) {
2251 if (pp.contains("ndtfast")) {
2252 amrex::Abort("remora.ndtfast and remora.fixed_ndtfast_ratio are both "
2253 "specified. Please use only remora.ndtfast");
2254 }
2255 amrex::Print() << "WARNING: remora.fixed_ndtfast_ratio is deprecated. "
2256 << "Please use remora.ndtfast instead." << std::endl;
2257 // Deprecated alias for remora.ndtfast.
2258 pp.queryAdd("fixed_ndtfast_ratio", ndtfast);
2259 }
2260 // Number of barotropic (fast) steps taken per baroclinic (slow) step.
2261 pp.queryAdd("ndtfast", ndtfast);
2262
2263 // 0 selects timeStepML, kept as a comparison path. amr.do_substep is the original
2264 // spelling; read it first so the queryAdd below records the value under the new name.
2265 {
2266 ParmParse pp_amr("amr");
2267 if (pp_amr.contains("do_substep")) {
2268 if (pp.contains("do_substep")) {
2269 amrex::Abort("remora.do_substep and amr.do_substep are both specified. "
2270 "Please use only remora.do_substep");
2271 }
2272 amrex::Print() << "WARNING: amr.do_substep is deprecated. "
2273 << "Please use remora.do_substep instead." << std::endl;
2274 pp_amr.queryAdd("do_substep", do_substep);
2275 }
2276 }
2277 pp.queryAdd("do_substep", do_substep);
2278
2279 if (max_level > 0) {
2280 if (do_substep) {
2281 amrex::Print() << "WARNING: subcycling refined levels in time is EXPERIMENTAL.\n"
2282 << " Multi-level answers are not yet considered production\n"
2283 << " quality; check them against a single-level run before\n"
2284 << " relying on them. remora.do_substep = 0 selects the older\n"
2285 << " lockstep driver instead.\n";
2286 } else {
2287 amrex::Print() << "NOTE: remora.do_substep = 0 selects the lockstep driver. It cannot\n"
2288 << " impose the parent's mass flux at a coarse-fine interface, so\n"
2289 << " it conserves volume less well: 2.0e-6 against 2.9e-08 on\n"
2290 << " Dogbone. Refinement is EXPERIMENTAL on either driver.\n";
2291 }
2292 }
2293
2294 // Write the parent's flux straight onto DUon/DVom instead of letting the solver rebuild it
2295 // from the imposed velocity. See set_2d_cf_flux.
2296 pp.queryAdd("cf_impose_flux", cf_impose_flux);
2297
2298 // See set_2d_cf_bcs. Only has an effect when remora.do_substep = 1.
2299 pp.queryAdd("time_interp_flux", time_interp_flux);
2300
2301 // Tracer flux correction at the coarse-fine interface. Needs remora.do_substep and
2302 // two-way coupling to do anything.
2303 pp.queryAdd("do_reflux", do_reflux);
2304
2305 // Mirror ROMS's fine2coarse, which returns every covered cell but not the perimeter's
2306 // normal-velocity faces. 0 restores the behaviour from before that was matched.
2307 pp.queryAdd("cf_avgdown_perimeter", cf_avgdown_perimeter);
2308
2309 // Diagnostics; see the declarations in REMORA.H.
2310 pp.queryAdd("cf_fill_vel_after", cf_fill_vel_after);
2311 pp.queryAdd("cf_set_2d_bcs", cf_set_2d_bcs);
2312 pp.queryAdd("cf_avgdown_bar", cf_avgdown_bar);
2313 pp.queryAdd("cf_fill_all_kcomp", cf_fill_all_kcomp);
2314 pp.queryAdd("cf_time_interp_zeta", cf_time_interp_zeta);
2315 pp.queryAdd("cf_flux_pc", cf_flux_pc);
2316 pp.queryAdd("cf_avgdown_stencil", cf_avgdown_stencil);
2317 pp.queryAdd("cf_print_iface", cf_print_iface);
2318
2319 // Whether to zero a tracer the correction drives negative, as ROMS does.
2320 pp.queryAdd("reflux_clamp", reflux_clamp);
2321
2322 // See check_cf_metrics. Off by default: it is a property of the grid, so one run says as
2323 // much as every run.
2324 pp.queryAdd("check_cf_metrics", check_cf_metrics_flag);
2325 pp.queryAdd("check_cf_tol", check_cf_tol);
2326
2327 // Advance and timeStepML form the fast step as dt / ndtfast, and set_weights sizes
2328 // the barotropic filter with the same number, so a non-positive value divides by zero
2329 // at all three sites. Nothing can infer it: dt is not known until run time on a
2330 // CFL-driven run.
2331 if (ndtfast <= 0) {
2332 amrex::Abort("remora.ndtfast must be a positive integer: it is the number of "
2333 "barotropic steps taken per baroclinic step");
2334 }
2335
2336 // remora.use_barotropic has been removed -- the barotropic mode is always on. Reject
2337 // it on presence rather than on value: amrex does not abort on unused inputs by
2338 // default, so a stale "= false" would otherwise silently run different physics than
2339 // the input file asks for. Tested with contains() rather than query() so the schema
2340 // scraper behind Exec/Generic does not re-advertise a parameter that no longer exists.
2341 if (pp.contains("use_barotropic")) {
2342 amrex::Abort("remora.use_barotropic has been removed. The barotropic (2D) mode is "
2343 "always active; please delete this line from your inputs file");
2344 }
2345
2347
2348 num_files_at_level.resize(max_level + 1, 0);
2349 num_boxes_at_level.resize(max_level + 1, 0);
2350 boxes_at_level.resize(max_level + 1);
2351 num_boxes_at_level[0] = 1;
2352 boxes_at_level[0].resize(1);
2353 boxes_at_level[0][0] = geom[0].Domain();
2354
2355 pp.queryAdd("plot_file", plot_file_name);
2356 pp.queryAdd("plot_int", plot_int);
2357 pp.queryAdd("plot_int_time", plot_int_time);
2358 pp.query("plot_staggered_vels", plot_staggered_vels);
2359 pp.query("plot_nodal_data", plot_nodal_data);
2360
2361 std::string plotfile_type_str = "amrex";
2362 pp.queryAdd("plotfile_type", plotfile_type_str);
2363 if (plotfile_type_str == "amrex") {
2365 } else if (plotfile_type_str == "netcdf" || plotfile_type_str == "NetCDF") {
2367#ifdef REMORA_USE_NETCDF
2368 pp.queryAdd("write_history_file",write_history_file);
2369 pp.queryAdd("chunk_history_file",chunk_history_file);
2370 pp.queryAdd("steps_per_history_file",steps_per_history_file);
2371 // CDF-5 output has no practical size limit, so REMORA doesn't size history
2372 // files. Chunking is opt-in; the writer divides by steps_per_history_file.
2374 if (steps_per_history_file <= 0) {
2375 amrex::Abort("remora.chunk_history_file requires remora.steps_per_history_file > 0");
2376 }
2377 Print() << "NetCDF history files will have " << steps_per_history_file << " steps per file." << std::endl;
2378 }
2379#endif
2380 } else {
2381 amrex::Print() << "User selected plotfile_type = " << plotfile_type_str << std::endl;
2382 amrex::Abort("Dont know this plotfile_type");
2383 }
2384#ifndef REMORA_USE_NETCDF
2386 {
2387 amrex::Abort("Please compile with NetCDF in order to enable NetCDF plotfiles");
2388 }
2389
2390#endif
2391#ifdef REMORA_USE_NETCDF
2392 nc_init_file.resize(max_level+1);
2393 nc_grid_file.resize(max_level+1);
2394 num_files_at_level.resize(max_level + 1, 0);
2395
2396 boundary_series.resize(max_level+1);
2397
2398
2399 // NetCDF initialization and grid files, read independently of each other: with
2400 // hires_grid_level or hires_init_level set, the corresponding level 0 file is not
2401 // needed. Whether a level 0 file is required is checked once the solver choices
2402 // are known, below.
2403 for (int lev = 0; lev <= max_level; lev++)
2404 {
2405 const std::string nc_file_names = amrex::Concatenate("nc_init_file_",lev,1);
2406 const std::string nc_bathy_file_names = amrex::Concatenate("nc_grid_file_",lev,1);
2407
2408 if (pp.contains(nc_file_names.c_str()))
2409 {
2410 int num_files = pp.countval(nc_file_names.c_str());
2412 nc_init_file[lev].resize(num_files);
2413 pp.queryarr(nc_file_names.c_str(), nc_init_file[lev], 0, num_files);
2414 }
2415 if (pp.contains(nc_bathy_file_names.c_str()))
2416 {
2417 int num_bathy_files = pp.countval(nc_bathy_file_names.c_str());
2419 pp.queryarr(nc_bathy_file_names.c_str(), nc_grid_file[lev], 0, num_bathy_files);
2420 }
2421 }
2422
2423 pp.queryAdd("nc_grid_file_hires", nc_grid_file_hires);
2424 pp.queryAdd("nc_init_file_hires", nc_init_file_hires);
2425
2426 // We only read boundary data at level 0
2427 pp.queryarr("nc_bdry_file", nc_bdry_file);
2428
2429 // Also only read forcings at level 0 (for now)
2430 if (pp.contains("nc_frc_file")) {
2431 int num_files = pp.countval("nc_frc_file");
2432 nc_frc_file.resize(num_files);
2433 pp.queryarr("nc_frc_file", nc_frc_file, 0, num_files);
2434 }
2435
2436 // Get river file
2437 if (pp.contains("nc_river_file")) {
2438 int num_files = pp.countval("nc_river_file");
2439 nc_riv_file.resize(num_files);
2440 pp.queryarr("nc_river_file", nc_riv_file, 0, num_files);
2441 }
2442
2443 // Read in file names for climatology history and nudging weights
2444 if (pp.contains("nc_clim_his_file")) {
2445 int num_files = pp.countval("nc_clim_his_file");
2447 pp.queryarr("nc_clim_his_file", nc_clim_his_file, 0, num_files);
2448 }
2449 pp.queryAdd("nc_clim_coeff_file", nc_clim_coeff_file);
2450
2451 for (int i=0; i<BdyVars::NumTypes(ncons); i++) {
2452 bdry_time_name_byvar.push_back("");
2453 }
2454 pp.queryAdd("bdy_time_varname",bdry_time_varname);
2455 // Every tracer takes its time-axis name from its own variable name, so temp and salt
2456 // keep bdy_temp_time_varname / bdy_salt_time_varname and a biology tracer uses e.g.
2457 // bdy_NO3_time_varname
2458 for (int icomp = 0; icomp < ncons; ++icomp) {
2459 pp.queryAdd(("bdy_"+cons_names[icomp]+"_time_varname").c_str(),
2461 }
2462 pp.queryAdd("bdy_u_time_varname",bdry_time_name_byvar[BdyVars::u]);
2463 pp.queryAdd("bdy_v_time_varname",bdry_time_name_byvar[BdyVars::v]);
2464 pp.queryAdd("bdy_ubar_time_varname",bdry_time_name_byvar[BdyVars::ubar(ncons)]);
2465 pp.queryAdd("bdy_vbar_time_varname",bdry_time_name_byvar[BdyVars::vbar(ncons)]);
2466 pp.queryAdd("bdy_zeta_time_varname",bdry_time_name_byvar[BdyVars::zeta(ncons)]);
2467
2468 // If not specified per variable, populate with the default
2469 for (int i=0; i<BdyVars::NumTypes(ncons); i++) {
2470 if (bdry_time_name_byvar[i] == "") {
2472 }
2473 }
2474
2475 pp.queryAdd("frc_time_varname",frc_time_varname);
2476
2477 pp.queryAdd("riv_time_varname",riv_time_varname);
2478
2479 pp.queryAdd("clim_ubar_time_varname",clim_ubar_time_varname);
2480 pp.queryAdd("clim_vbar_time_varname",clim_vbar_time_varname);
2481 pp.queryAdd("clim_u_time_varname",clim_u_time_varname);
2482 pp.queryAdd("clim_v_time_varname",clim_v_time_varname);
2483 // As for the boundary data, each tracer takes its climatology time-axis name from its
2484 // own variable name, so temp and salt keep clim_temp_time_varname /
2485 // clim_salt_time_varname and a biology tracer uses e.g. clim_NO3_time_varname
2486 clim_cons_time_varname.assign(ncons, "ocean_time");
2487 for (int icomp = 0; icomp < ncons; ++icomp) {
2488 pp.queryAdd(("clim_"+cons_names[icomp]+"_time_varname").c_str(),
2490 }
2491
2492#endif
2493 // A hires level of 0 is not "level 0 is the hires level", it is a null pointer: the
2494 // full-domain arrays are only allocated for lev > 0 (see allocate_init_full_domain and
2495 // allocate_bathymetry_grid_vars_full_domain), while every consumer branch tests < 0 and
2496 // so would take the averaged-down path against an unallocated MultiFab. -1 means off.
2497 pp.queryAdd("hires_grid_level", hires_grid_level);
2499 amrex::Abort("hires_grid_level must be less than or equal to amr.max_level");
2500 }
2501 if (hires_grid_level == 0) {
2502 amrex::Abort("hires_grid_level must be greater than 0; use -1 to specify grid data at level 0");
2503 }
2504 pp.queryAdd("hires_init_level", hires_init_level);
2506 amrex::Abort("hires_init_level must be less than or equal to amr.max_level");
2507 }
2508 if (hires_init_level == 0) {
2509 amrex::Abort("hires_init_level must be greater than 0; use -1 to specify initial data at level 0");
2510 }
2511#ifdef REMORA_USE_PARTICLES
2513#endif
2514
2515 {
2516 ParmParse pp_amr("amr");
2517 pp_amr.queryAdd("regrid_int", regrid_int);
2518 }
2520
2521 // The biology IC source is chosen independently of ic_type, but only one of the two
2522 // mixed combinations works: NetCDF physics with analytic biology. The reverse has no
2523 // file to read from -- nc_init_file is only populated on the netcdf path -- so catch
2524 // it here instead of failing inside PnetCDF on an empty file name.
2528 amrex::Abort("remora.biology_ic_type = netcdf requires remora.ic_type = netcdf: the biology "
2529 "initial data is read from the same files as the physical initial data, and no "
2530 "such file is given for analytic initial conditions. Use "
2531 "remora.biology_ic_type = analytic (or follow) instead.");
2532 }
2533
2534#ifndef REMORA_USE_NETCDF
2536 amrex::Abort("Please compile with NetCDF in order to use remora.ic_type = netcdf");
2537 }
2538#else
2539 // Level 0 files are read only for the fields not supplied at hires_init_level or
2540 // hires_grid_level, so require each one only where it will be read.
2541 {
2542 const bool have_init_0 = !nc_init_file[0].empty() && !nc_init_file[0][0].empty();
2543 const bool have_grid_0 = !nc_grid_file[0].empty() && !nc_grid_file[0][0].empty();
2545 amrex::Abort("remora.ic_type = netcdf requires remora.nc_init_file_0 unless "
2546 "remora.hires_init_level is set");
2547 }
2548 if (hires_grid_level < 0 && !have_grid_0 &&
2550 amrex::Abort("remora.ic_type = netcdf or remora.mask_type = netcdf requires "
2551 "remora.nc_grid_file_0 unless remora.hires_grid_level is set");
2552 }
2554 !have_grid_0) {
2555 amrex::Abort("remora.coriolis_type = netcdf requires remora.nc_grid_file_0");
2556 }
2557 }
2558#endif
2559
2560 // init_full_domain_from_analytic builds x_r and y_r from the cell size.
2563 amrex::Abort("High-resolution initialization with analytic initial conditions requires "
2564 "remora.grid_scale_type = constant");
2565 }
2566
2567}
2568
2569
2570void
2572{
2573 BL_PROFILE("REMORA::AverageDown()");
2574 for (int lev = finest_level-1; lev >= 0; --lev)
2575 {
2577 }
2578}
2579
2580/**
2581 * Drop the cached average-down masks of every level pair that involves lev, so the next
2582 * AverageDownTo rebuilds them.
2583 *
2584 * Called from set_masks, which is the one place a level's mask is written, so a regrid cannot
2585 * leave a cached copy of a mask that no longer exists behind.
2586 *
2587 * @param[in ] lev level whose mask has just been rebuilt
2588 */
2589void
2591{
2592 // lev as the coarse half of a pair, and lev as the fine half, whose layout is what the
2593 // cached arrays are built on.
2594 for (int crse_lev : {lev-1, lev}) {
2595 if (crse_lev >= 0 && crse_lev < static_cast<int>(vec_mskr_crse_on_fine.size())) {
2599 }
2600 }
2601}
2602
2603/**
2604 * Measure whether the fine cell edges tile the coarse ones across a coarse-fine interface:
2605 * the sum of on_u over the r covering fine faces against on_u on the coarse face.
2606 *
2607 * Exact where pm and pn are uniform, and not guaranteed otherwise -- on the NetCDF path a
2608 * finer level interpolates its metrics from the parent's and rescales them, which need not
2609 * preserve a sum. set_2d_cf_bcs cannot impose a conservative flux without this identity.
2610 *
2611 * @param[in ] crse_lev coarse side of the interface
2612 */
2613void
2615{
2616 const int rrx = ref_ratio[crse_lev][0];
2617 const int rry = ref_ratio[crse_lev][1];
2618
2619 auto edge_residual = [&] (int dir, int ratio) -> Real
2620 {
2621 const IntVect ixt = (dir == 0) ? IntVect(1,0,0) : IntVect(0,1,0);
2622 const MultiFab& metric_f = (dir == 0) ? *vec_pn[crse_lev+1] : *vec_pm[crse_lev+1];
2623 const MultiFab& metric_c = (dir == 0) ? *vec_pn[crse_lev ] : *vec_pm[crse_lev ];
2624
2625 auto edge_lengths = [&] (const MultiFab& metric, int lev, MultiFab& out)
2626 {
2627 // pm and pn already live on the z-flattened BoxArray.
2628 BoxArray ba = convert(metric.boxArray(), ixt);
2629 out.define(ba, metric.DistributionMap(), 1, 0);
2630 for (MFIter mfi(out, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
2631 Array4<Real > const& e = out.array(mfi);
2632 Array4<Real const> const& m = metric.const_array(mfi);
2633 const int d = dir;
2634 ParallelFor(mfi.tilebox(), [=] AMREX_GPU_DEVICE (int i, int j, int)
2635 {
2636 const int im = (d == 0) ? i-1 : i;
2637 const int jm = (d == 0) ? j : j-1;
2638 e(i,j,0) = two / (m(i,j,0) + m(im,jm,0));
2639 });
2640 }
2641 amrex::ignore_unused(lev);
2642 };
2643
2644 MultiFab edge_f, edge_c;
2647
2648 // average_down_faces leaves faces the finer level does not cover untouched. Seeding
2649 // with the coarse value over the ratio makes those contribute exactly zero below,
2650 // rather than whatever the allocation happened to hold.
2651 MultiFab avg(edge_c.boxArray(), edge_c.DistributionMap(), 1, 0);
2652 MultiFab::Copy(avg, edge_c, 0, 0, 1, 0);
2653 avg.mult(one / Real(ratio), 0, 1, 0);
2654
2656
2657 // avg is the mean over the covering fine faces, so ratio*avg is their sum.
2658 Real worst = zero;
2659 for (MFIter mfi(avg, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
2660 Array4<Real const> const& a = avg.const_array(mfi);
2661 Array4<Real const> const& c = edge_c.const_array(mfi);
2664 reduce_op.eval(mfi.tilebox(), reduce_data,
2665 [=] AMREX_GPU_DEVICE (int i, int j, int k) -> GpuTuple<Real>
2666 {
2667 if (c(i,j,k) == zero) { return {zero}; }
2668 return {amrex::Math::abs(Real(ratio) * a(i,j,k) - c(i,j,k)) /
2669 amrex::Math::abs(c(i,j,k))};
2670 });
2671 worst = amrex::max(worst, amrex::get<0>(reduce_data.value(reduce_op)));
2672 }
2673 ParallelDescriptor::ReduceRealMax(worst);
2674 return worst;
2675 };
2676
2677 const Real res_u = edge_residual(0, rry);
2678 const Real res_v = edge_residual(1, rrx);
2679
2680 amrex::Print() << "CF edge tiling, levels " << crse_lev << "/" << crse_lev+1
2681 << ": max relative residual on_u " << res_u
2682 << ", om_v " << res_v << std::endl;
2683
2685 amrex::max(res_u, res_v) < check_cf_tol,
2686 "REMORA::check_cf_metrics: fine cell edges do not sum to the coarse edge across the "
2687 "coarse-fine interface, so the mass flux set_2d_cf_bcs imposes there cannot be "
2688 "conservative. Raise remora.check_cf_tol only if you know why the grid does this.");
2689}
2690
2691/**
2692 * Build the flux register holding the tracer flux mismatch between lev and lev-1. Called
2693 * whenever a level is created or its grids change, since one appearing mid-run through
2694 * tagging would otherwise have no register.
2695 *
2696 * @param[in ] lev level of refinement, > 0
2697 */
2698void
2700{
2701 if (lev == 0 || solverChoice.coupling_type != CouplingType::two_way) { return; }
2702
2703 // Take the layout from the MultiFabs rather than grids/dmap: when a level is first
2704 // created those have not been set on AmrCore yet, as the fill patchers here also assume.
2706 cons_new[lev-1]->boxArray(),
2709 geom[lev], geom[lev-1],
2710 ref_ratio[lev-1], lev, ncons));
2711
2712 // The constructor sizes the accumulators without zeroing them, and Reflux adds all of
2713 // m_crse_data to the state, so a register must be zero before its first use whichever
2714 // path built it.
2715 advflux_reg[lev]->reset();
2716}
2717
2718/**
2719 * Set how many steps each level takes per parent step, from remora.dt_ref_ratio.
2720 *
2721 * @param[in ] nlevs_max max_level + 1
2722 */
2723void
2725{
2726 nsubsteps.resize(nlevs_max, 1);
2727 if (!do_substep) { return; }
2728
2729 for (int lev = 1; lev <= max_level; ++lev) {
2731 }
2732
2733 // Defaults to the spatial ratio, but the two are independent in ROMS (RefineSteps
2734 // against RefineScale) and in ERF. One value for all levels or one per level.
2735 if (max_level > 0) {
2736 ParmParse pp("remora");
2737 int count = pp.countval("dt_ref_ratio");
2738 if (count > 0) {
2739 Vector<int> nsub(nlevs_max, 0);
2740 if (count == 1) {
2741 pp.queryarr("dt_ref_ratio", nsub, 0, 1);
2742 for (int lev = 1; lev <= max_level; ++lev) { nsubsteps[lev] = nsub[0]; }
2743 } else {
2744 pp.queryarr("dt_ref_ratio", nsub, 0, max_level);
2745 for (int lev = 1; lev <= max_level; ++lev) { nsubsteps[lev] = nsub[lev-1]; }
2746 }
2747 for (int lev = 1; lev <= max_level; ++lev) {
2749 "remora.dt_ref_ratio must be positive: it divides the parent timestep");
2750 }
2751 }
2752 }
2753}
2754
2755/**
2756 * Make sure the coarse rho-, u- and v-masks are defined on the layout average_down_masked
2757 * computes on: level crse_lev+1's grids coarsened, rather than level crse_lev's own grids.
2758 *
2759 * The masks are a function of position alone, so between regrids this is the same answer every
2760 * step; building it once turns three allocations and three ParallelCopy calls per step into
2761 * three per regrid.
2762 *
2763 * @param[in ] crse_lev coarse level of the pair
2764 */
2765void
2767{
2768 BL_PROFILE("REMORA::update_avgdown_masks()");
2769 const int flev = crse_lev + 1;
2770 const IntVect ratio = refRatio(crse_lev);
2771
2772 const BoxArray cba = amrex::coarsen(vec_mskr[flev]->boxArray(), ratio);
2773 const DistributionMapping& dmf = vec_mskr[flev]->DistributionMap();
2774
2775 // clear_avgdown_masks drops the cache whenever a mask is rewritten; this catches anything
2776 // that gets here without having gone through it, by rebuilding when the layout has moved.
2780 return;
2781 }
2782
2783 vec_mskr_crse_on_fine[crse_lev].reset(new MultiFab(cba, dmf, 1, 0));
2785 new MultiFab(amrex::convert(cba, IntVect(1,0,0)), dmf, 1, 0));
2787 new MultiFab(amrex::convert(cba, IntVect(0,1,0)), dmf, 1, 0));
2788
2789 vec_mskr_crse_on_fine[crse_lev]->ParallelCopy(*vec_mskr[crse_lev], 0, 0, 1);
2790 vec_msku_crse_on_fine[crse_lev]->ParallelCopy(*vec_msku[crse_lev], 0, 0, 1);
2791 vec_mskv_crse_on_fine[crse_lev]->ParallelCopy(*vec_mskv[crse_lev], 0, 0, 1);
2792}
2793
2794/**
2795 * @param[in ] crse_lev level to average down to
2796 */
2797
2798namespace {
2799/** \brief Replace each face by the mean of itself and its neighbours along dir.
2800 *
2801 * ROMS's fine2coarse2d averages the donor over a (Rscale-1)/2 half-width stencil in both
2802 * horizontal directions, so at ratio 3 a coarse face takes the mean of nine fine faces;
2803 * AMReX's average_down_faces takes only the three, all tangential, that tile it. Smoothing
2804 * along the face normal first supplies the missing direction and reproduces ROMS exactly.
2805 * Masked as ROMS does it: sum over wet points, divide by the wet count.
2806 *
2807 * Deliberately not conservative -- the nine-point mean does not preserve the transport through
2808 * the interface, where average_down_faces alone does. ROMS accepts that trade.
2809 */
2810void smooth_faces_along (amrex::MultiFab& mf, const amrex::MultiFab& msk, int dir,
2811 const amrex::Geometry& geom, int ncomp)
2812{
2813 mf.FillBoundary(geom.periodicity());
2814 amrex::MultiFab orig(mf.boxArray(), mf.DistributionMap(), ncomp, mf.nGrowVect());
2815 amrex::MultiFab::Copy(orig, mf, 0, 0, ncomp, mf.nGrowVect());
2816 const int di = (dir == 0) ? 1 : 0;
2817 const int dj = (dir == 1) ? 1 : 0;
2818 for (amrex::MFIter mfi(mf, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
2819 const amrex::Box& bx = mfi.tilebox();
2820 const auto& a = mf.array(mfi);
2821 const auto& o = orig.const_array(mfi);
2822 const auto& m = msk.const_array(mfi);
2823 amrex::ParallelFor(bx, ncomp,
2824 [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
2825 {
2826 amrex::Real sum = amrex::Real(0.0), cnt = amrex::Real(0.0);
2827 for (int t = -1; t <= 1; ++t) {
2828 const int ii = i + t*di, jj = j + t*dj;
2829 const amrex::Real w = amrex::min(amrex::Real(1.0), m(ii,jj,0));
2830 sum += o(ii,jj,k,n) * m(ii,jj,0);
2831 cnt += w;
2832 }
2833 if (cnt > amrex::Real(0.0)) { a(i,j,k,n) = sum / cnt; }
2834 });
2835 }
2836}
2837} // namespace
2838
2839void
2841{
2842 BL_PROFILE("REMORA::AverageDownTo()");
2843 const int flev = crse_lev + 1;
2844
2845 // average_down_masked indexes the coarse mask with the same MFIter as its coarsened-fine
2846 // temporary, so the mask has to be defined on that layout. It is the same between regrids,
2847 // so this builds it once instead of every step.
2849 const MultiFab& cmskr = *vec_mskr_crse_on_fine[crse_lev];
2850 const MultiFab& cmsku = *vec_msku_crse_on_fine[crse_lev];
2851 const MultiFab& cmskv = *vec_mskv_crse_on_fine[crse_lev];
2852
2853 // Which mask goes with which field follows the ROMS fine2coarse call sites: rmask for the
2854 // free surface and the tracers, umask and vmask for the momenta.
2859 // ROMS returns every covered cell but not the perimeter's normal-velocity faces, so the
2860 // transport its nested boundary condition imposes there never comes back to the parent.
2861 // Without that exclusion set_2d_cf_bcs writes the parent's own flux onto the interface and
2862 // the average hands it straight back: a factor of 20 to 40 in the barotropic mode against
2863 // ROMS on the matched dogbone.
2864 MultiFab covered;
2865 MultiFab u_save, v_save;
2866 const bool keep_perimeter = (cf_avgdown_perimeter != 0);
2867 if (keep_perimeter) {
2870 1, 0, MFInfo());
2872 1, 0, MFInfo());
2873 MultiFab::Copy(u_save, *xvel_new[crse_lev], 0, 0, 1, 0);
2874 MultiFab::Copy(v_save, *yvel_new[crse_lev], 0, 0, 1, 0);
2875 }
2876
2877 // See smooth_faces_along: ROMS averages the donor over nine fine faces, AMReX over the
2878 // three that tile the coarse face, so the normal direction is smoothed in first.
2879 MultiFab xv_sm, yv_sm;
2880 const MultiFab* xv_f = xvel_new[flev];
2881 const MultiFab* yv_f = yvel_new[flev];
2882 if (cf_avgdown_stencil) {
2884 1, xvel_new[flev]->nGrowVect());
2885 MultiFab::Copy(xv_sm, *xvel_new[flev], 0, 0, 1, xvel_new[flev]->nGrowVect());
2887 xv_f = &xv_sm;
2888
2890 1, yvel_new[flev]->nGrowVect());
2891 MultiFab::Copy(yv_sm, *yvel_new[flev], 0, 0, 1, yvel_new[flev]->nGrowVect());
2893 yv_f = &yv_sm;
2894 }
2895
2897 *vec_msku[flev], cmsku, 1, 0);
2899 *vec_mskv[flev], cmskv, 1, 1);
2900
2901 if (keep_perimeter) {
2904 }
2906 *vec_mskr[flev], cmskr, 1, 2);
2907
2909
2910 // Hand the child's 2D momentum back, as ROMS's fine2coarse does. The parent's next
2911 // advance_2d reads ubar(krhs) to form DUon, so dropping this moves Dogbone's x-velocity
2912 // by 9%. Subcycling only: timeStepML keeps the behaviour its answers were recorded with.
2913 if (do_substep && cf_avgdown_bar) {
2914 // Components 0 and 1 only. The three are leapfrog slots rotating per level, so the
2915 // two levels need not agree on which holds what -- but update_massflux_3d has just
2916 // set both of these to the same velocity, so averaging them cannot mix time levels.
2917 MultiFab ub_save, vb_save;
2918 if (keep_perimeter) {
2919 ub_save.define(vec_ubar[crse_lev]->boxArray(),
2921 vb_save.define(vec_vbar[crse_lev]->boxArray(),
2923 MultiFab::Copy(ub_save, *vec_ubar[crse_lev], 0, 0, 2, 0);
2924 MultiFab::Copy(vb_save, *vec_vbar[crse_lev], 0, 0, 2, 0);
2925 }
2926
2927 MultiFab ub_sm, vb_sm;
2928 const MultiFab* ub_src = vec_ubar[crse_lev+1].get();
2929 const MultiFab* vb_src = vec_vbar[crse_lev+1].get();
2930 if (cf_avgdown_stencil) {
2932 2, vec_ubar[flev]->nGrowVect());
2933 MultiFab::Copy(ub_sm, *vec_ubar[flev], 0, 0, 2, vec_ubar[flev]->nGrowVect());
2935 ub_src = &ub_sm;
2936
2938 2, vec_vbar[flev]->nGrowVect());
2939 MultiFab::Copy(vb_sm, *vec_vbar[flev], 0, 0, 2, vec_vbar[flev]->nGrowVect());
2941 vb_src = &vb_sm;
2942 }
2943
2944 for (int icomp = 0; icomp < 2; ++icomp) {
2945 MultiFab ubar_f(*ub_src, make_alias, icomp, 1);
2946 MultiFab ubar_c(*vec_ubar[crse_lev ], make_alias, icomp, 1);
2948
2949 MultiFab vbar_f(*vb_src, make_alias, icomp, 1);
2950 MultiFab vbar_c(*vec_vbar[crse_lev ], make_alias, icomp, 1);
2952 }
2953
2954 if (keep_perimeter) {
2957 }
2958
2959 // The averages above rewrote this level's valid cells under the patch but not the
2960 // ghosts imaging them across a periodic seam, and nothing else refreshes those before
2961 // the next barotropic step: FillPatch refills one component, fill_ghost_kcomps runs on
2962 // fine levels only. Where the patch abuts a periodic boundary the two copies of the
2963 // coarse periodic u-face then read different vbar for the same physical cell -- freshly
2964 // averaged against stale -- and the asymmetry grows step by step. On Channel_Test with
2965 // a half-width patch on the seam: 3.4e-4 by step 20 and NaN by ~300 without this,
2966 // exactly zero with it, and an interior patch unaffected either way.
2967 vec_ubar[crse_lev]->FillBoundary(geom[crse_lev].periodicity());
2968 vec_vbar[crse_lev]->FillBoundary(geom[crse_lev].periodicity());
2969
2970 // zeta is deliberately absent: set_zeta_to_Ztavg overwrites all three of its
2971 // components from Zt_avg1 next step and stretch_transform reads Zt_avg1 anyway, so
2972 // averaging it here would write something nothing reads.
2973 }
2974
2976}
2977
2978/**
2979 * Coarse-level cell mask: 1 where level crse_lev+1 covers the cell, 0 elsewhere, with one grow
2980 * cell so a face straddling the patch edge can see the cell outside it.
2981 *
2982 * @param[in ] crse_lev coarse level
2983 * @param[out ] covered mask on the coarse layout
2984 */
2985void
2987{
2988 // makeFineMask's (crse_value, fine_value) = (0, 1) puts a 1 exactly on the covered cells.
2990 ref_ratio[crse_lev], 0, 1);
2991
2992 covered.define(grids[crse_lev], dmap[crse_lev], 1, 1, MFInfo());
2993 covered.setVal(zero); // grow cells outside the patch read as uncovered
2994 const auto cma = covered.arrays();
2995 const auto ima = imask.const_arrays();
2996 ParallelFor(covered, [=] AMREX_GPU_DEVICE (int bno, int i, int j, int k) noexcept
2997 {
2998 cma[bno](i,j,k) = Real(ima[bno](i,j,k));
2999 });
3000 Gpu::streamSynchronize();
3001 covered.FillBoundary(geom[crse_lev].periodicity());
3002}
3003
3004/**
3005 * Put back the values a fine-to-coarse average just wrote onto the fine patch's perimeter
3006 * normal-velocity faces.
3007 *
3008 * ROMS's fine2coarse hands back every covered cell but excludes those faces: for a child
3009 * spanning coarse cells I_lo..I_hi it updates u-faces I_lo+1..I_hi only, so the face the
3010 * nested barotropic boundary condition writes is never returned to the parent. A face is
3011 * interior exactly when both of the cells it separates are covered, which is the test used
3012 * here.
3013 *
3014 * @param[in ] saved coarse field as it was before the average
3015 * @param[inout] mf coarse field to repair
3016 * @param[in ] covered cell mask from build_covered_mask
3017 * @param[in ] dir face normal direction
3018 * @param[in ] ncomp components to repair
3019 */
3020void
3021REMORA::restore_perimeter_faces (const MultiFab& saved, MultiFab& mf,
3022 const MultiFab& covered, int dir, int ncomp)
3023{
3024 const IntVect off = IntVect::TheDimensionVector(dir);
3025 for (MFIter mfi(mf, TilingIfNotGPU()); mfi.isValid(); ++mfi)
3026 {
3027 const Box& bx = mfi.tilebox();
3028 Array4<Real > const& a = mf.array(mfi);
3029 Array4<Real const> const& o = saved.const_array(mfi);
3030 Array4<Real const> const& c = covered.const_array(mfi);
3031 ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
3032 {
3033 const bool interior = (c(i,j,0) > Real(0.5)) &&
3034 (c(i-off[0], j-off[1], 0) > Real(0.5));
3035 if (!interior) { a(i,j,k,n) = o(i,j,k,n); }
3036 });
3037 }
3038 Gpu::streamSynchronize();
3039}
3040
3041/**
3042 * Average one field from crse_lev+1 onto crse_lev, weighting by the land/sea mask.
3043 *
3044 * Follows amrex::average_down's non-MFIter-safe branch, since coarsen(grids[flev]) does not
3045 * match grids[crse_lev] in general: compute onto a temporary on the coarsened-fine layout,
3046 * then ParallelCopy that onto the coarse level.
3047 *
3048 * @param[in ] crse_lev level to average down to
3049 * @param[in ] S_fine fine-level field
3050 * @param[out ] S_crse coarse-level field
3051 * @param[in ] msk_fine fine-level mask, on S_fine's layout and nodality
3052 * @param[in ] cmsk coarse-level mask, already on the coarsened-fine layout
3053 * @param[in ] ncomp number of components to average
3054 * @param[in ] face_dir face direction, or -1 for a cell-centered field
3055 */
3056void
3057REMORA::average_down_masked (int crse_lev, const MultiFab& S_fine, MultiFab& S_crse,
3058 const MultiFab& msk_fine, const MultiFab& cmsk,
3059 int ncomp, int face_dir)
3060{
3061 BL_PROFILE("REMORA::average_down_masked()");
3062 const IntVect ratio = refRatio(crse_lev);
3063
3064 BoxArray cba = amrex::coarsen(S_fine.boxArray(), ratio);
3065 MultiFab ctmp(cba, S_fine.DistributionMap(), ncomp, 0);
3066
3067 // One MFIter indexes all four arrays in the loop below, by local box index, so the masks
3068 // have to be distributed exactly as S_fine is. Equal DistributionMappings imply equal box
3069 // counts, since a ProcessorMap holds one entry per box.
3070 AMREX_ALWAYS_ASSERT(msk_fine.DistributionMap() == S_fine.DistributionMap());
3071 AMREX_ALWAYS_ASSERT(cmsk.DistributionMap() == S_fine.DistributionMap());
3072
3073 for (MFIter mfi(ctmp, TilingIfNotGPU()); mfi.isValid(); ++mfi)
3074 {
3075 const Box& bx = mfi.tilebox();
3076 Array4< Real> const& c = ctmp.array(mfi);
3077 Array4<const Real> const& f = S_fine.const_array(mfi);
3078 Array4<const Real> const& fm = msk_fine.const_array(mfi);
3079 Array4<const Real> const& cm = cmsk.const_array(mfi);
3080
3081 if (face_dir < 0) {
3082 ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
3083 {
3085 });
3086 } else {
3087 ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
3088 {
3090 });
3091 }
3092 }
3093 Gpu::streamSynchronize();
3094
3095 // Periodicity arguments as amrex::average_down and average_down_faces pass them: the
3096 // cell-centered copy takes none, the face copy needs it so shared faces across a periodic
3097 // boundary agree.
3098 if (face_dir < 0) {
3099 S_crse.ParallelCopy(ctmp, 0, 0, ncomp);
3100 } else {
3101 S_crse.ParallelCopy(ctmp, 0, 0, ncomp, IntVect(0), IntVect(0),
3103 }
3104}
3105
3106/**
3107 * Inject the full-domain rho-mask from fine_lev-1 up onto fine_lev, grow cells included.
3108 *
3109 * Piecewise constant, which is the rule set_masks already uses for a level above the one the
3110 * mask was specified on. Nothing finer is known there, so refining cannot add coastline.
3111 *
3112 * @param[in ] fine_lev level to inject onto
3113 */
3114void
3116{
3117 auto const& finema = vec_mskr_full_domain[fine_lev]->arrays();
3118 auto const& crsema = vec_mskr_full_domain[fine_lev-1]->const_arrays();
3119 auto ratio = refRatio(fine_lev-1);
3122 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
3123 {
3124 // amrex::coarsen floors rather than truncating, which is what the negative indices of
3125 // the grow cells need.
3126 finema[box_no](i,j,k,n) = crsema[box_no](amrex::coarsen(i, ratio[0]),
3127 amrex::coarsen(j, ratio[1]), k, n);
3128 });
3129 Gpu::streamSynchronize();
3130}
3131
3132/**
3133 * Make sure the full-domain rho-mask exists on levels 0 through top_lev.
3134 *
3135 * Only fills what the hires_grid_level coarsening has not: levels above it, by injection, and
3136 * level 0 itself when there is no high-resolution grid and the mask was given per level.
3137 *
3138 * @param[in ] top_lev highest level that needs a mask
3139 */
3140void
3142{
3143 if (solverChoice.mask_type == MaskType::none || top_lev <= 0) { return; }
3144
3145 // Levels up to hires_grid_level were coarsened down from it already.
3146 const int have = (hires_grid_level > 0) ? hires_grid_level : 0;
3147 if (top_lev <= have) { return; }
3148
3149 BoxArray ba;
3150 ba.define(makeSlab(geom[0].Domain(),2,0));
3151 const DistributionMapping& dm = full_domain_dmap();
3152 auto mskr_growvect = vec_mskr[0]->nGrowVect();
3153
3154 if (hires_grid_level < 0) {
3155 // No high-resolution grid, so the specification lives on level 0. Seed from it.
3156 vec_mskr_full_domain[0].reset(new MultiFab(ba, dm, 1, IntVect(1,1,0)));
3157 vec_mskr_full_domain[0]->setVal(one);
3158 ParallelCopy(*vec_mskr_full_domain[0].get(), *vec_mskr[0].get(), 0, 0, 1,
3160 }
3161
3162 for (int lev = 1; lev <= top_lev; lev++) {
3163 ba = ba.refine(refRatio(lev-1));
3164 if (lev <= have) { continue; }
3165 vec_mskr_full_domain[lev].reset(new MultiFab(ba, dm, 1,
3167 vec_mskr_full_domain[lev]->setVal(one);
3169 }
3170}
3171
3172namespace {
3173/**
3174 * Build a face-centered mask from a rho-point one, following ROMS set_masks.F:
3175 * msku = mskr(i-1,j)*mskr(i,j) and mskv = mskr(i,j-1)*mskr(i,j).
3176 *
3177 * Derived where it is needed rather than stored. Only the full-domain average-down wants
3178 * these, at most once per level during initialization, so a stored pair would be two more
3179 * arrays to keep in step with the rho mask for no measurable saving.
3180 */
3181void derive_face_mask (const MultiFab& mskr, MultiFab& mskf, int idir)
3182{
3183 const IntVect ndir = (idir == 0) ? IntVect(1,0,0) : IntVect(0,1,0);
3184 // One ring narrower than the rho mask in the normal direction, where the stencil reaches.
3185 const IntVect ng = max(mskr.nGrowVect() - ndir, IntVect(0));
3186 mskf.define(convert(mskr.boxArray(), ndir), mskr.DistributionMap(), 1, ng);
3187 mskf.setVal(one);
3188
3189 for (MFIter mfi(mskf, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
3190 const Box& bx = mfi.growntilebox();
3191 Array4< Real> const& mf = mskf.array(mfi);
3192 Array4<const Real> const& mr = mskr.const_array(mfi);
3193 const int l_idir = idir;
3194 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
3195 {
3196 mf(i,j,k) = (l_idir == 0) ? mr(i-1,j,0) * mr(i,j,0)
3197 : mr(i,j-1,0) * mr(i,j,0);
3198 });
3199 }
3200}
3201} // namespace
3202
3203/**
3204 * Average a full-domain field from crse_lev+1 onto crse_lev, grow cells included.
3205 *
3206 * With use_mask this takes REMORAMaskedAvgDown's mask-weighted mean instead of the plain one,
3207 * so the initial state on a coarse cell only partly covered by water comes from that water.
3208 * It is the formula AverageDownTo applies every step, so the initial and the running state
3209 * agree on what a land point holds. Leave use_mask off for grid metrics: a cell size is well
3210 * defined under land, and masking pm/pn would corrupt it.
3211 *
3212 * @param[in ] crse_lev level to average data down to
3213 * @param[inout] vec_mf vector over levels of multifabs containing data to average
3214 * @param[in ] use_mask weight by the land/sea mask rather than averaging every fine cell
3215 */
3216void
3218 bool use_mask)
3219{
3220 auto const& crsema = vec_mf[crse_lev]->arrays();
3221 auto const& finema = vec_mf[crse_lev+1]->const_arrays();
3223 auto index_type = (vec_mf[crse_lev]->boxArray().ixType()).toIntVect();
3224 auto nghost_crse = cum_ref_ratios[crse_lev] - index_type;
3225
3227 if (masked) {
3228 // One box per level on a matching DistributionMapping, so an MFIter over one array
3229 // indexes the other. Assert it rather than assume it.
3235
3236 const int idir = (index_type[0]==1) ? 0 : ((index_type[1]==1) ? 1 : -1);
3237 MultiFab fmsk, cmsk;
3238 if (idir >= 0) {
3241 }
3242 auto const& fmskma = (idir >= 0) ? fmsk.const_arrays()
3243 : vec_mskr_full_domain[crse_lev+1]->const_arrays();
3244 auto const& cmskma = (idir >= 0) ? cmsk.const_arrays()
3245 : vec_mskr_full_domain[crse_lev]->const_arrays();
3247 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
3248 {
3249 if (idir < 0) {
3252 } else {
3255 }
3256 });
3257 Gpu::streamSynchronize();
3258 return;
3259 }
3260
3261 if (index_type[0]==0 and index_type[1]==0) {
3263 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
3264 {
3266 });
3267 } else if (index_type[0]==1 and index_type[1]==0) {
3269 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
3270 {
3272 });
3273 } else if (index_type[0]==0 and index_type[1]==1) {
3275 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
3276 {
3278 });
3279 } else {
3280 amrex::Abort("Unexpected nodality in average_down_with_grow_cells");
3281 }
3282 Gpu::streamSynchronize();
3283}
3284
3285/**
3286 * @param[in ] lev level at which to get time
3287 */
3288amrex::Real REMORA::get_t_old(int lev) const
3289{
3290 return t_old[lev];
3291}
constexpr amrex::Real two
constexpr amrex::Real bogus_large_value
constexpr amrex::Real one
constexpr amrex::Real fourth
constexpr amrex::Real zero
PlotfileType
plotfile format
#define NAT
#define Tracer_comp
mf_h setVal(geomdata.ProbHi(2))
AMREX_ALWAYS_ASSERT(!NSPeriodic||!EWPeriodic)
bool QueryNetCDFHasVars(const std::string &fname, const amrex::Vector< std::string > &var_names)
Helper function for testing whether a file carries every named variable.
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.
Definition REMORA.H:2002
std::string nc_grid_file_hires
Grid file for high resolution bathymetry.
Definition REMORA.H:2014
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskr_full_domain
Land/sea mask at cell centers on the whole domain at each potential level. Specified at hires_grid_le...
Definition REMORA.H:421
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_EminusP
evaporation minus precipitation [kg/m^2/s], defined at rho-points
Definition REMORA.H:521
ProbCoords prob_coords(int lev) const
Coordinate arrays of level lev, for the prob functions.
amrex::Vector< std::string > nc_riv_file
NetCDF river file(s)
Definition REMORA.H:2031
void set_grid_vars_averaged_down(int lev)
Set pm/pn by averaging down from higher-resolution grid.
Definition REMORA.cpp:827
std::string riv_time_varname
Name of time field for river time.
Definition REMORA.H:2055
int foextrap_periodic_bc() const noexcept
Definition REMORA.H:1455
amrex::Vector< std::string > nc_clim_his_file
NetCDF climatology history file(s)
Definition REMORA.H:2034
int ncons
Number of conserved scalars in the state (temperature + salt + passive scalars + biology tracers)
Definition REMORA.H:1797
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskr_crse_on_fine
the level's rho-, u- and v-masks copied onto the layout of the level above it coarsened,...
Definition REMORA.H:598
double stop_time
Whether max_step was set in the inputs; the default above is not a distinguishable sentinel.
Definition REMORA.H:1774
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_zeta_full_domain
high resolution initial free surface height (2D)
Definition REMORA.H:581
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rv2d
v velocity RHS (2D, includes horizontal and vertical advection)
Definition REMORA.H:436
std::string nc_init_file_hires
Init file for high resolution.
Definition REMORA.H:2021
int biology_debug_i
Target column i index for biology_debug = 1.
Definition REMORA.H:1814
static amrex::Real fixed_dt
User specified fixed baroclinic time step.
Definition REMORA.H:1824
amrex::Real last_plot_file_time
Simulation time when we last output a plotfile.
Definition REMORA.H:1757
int zvel_bc() const noexcept
Definition REMORA.H:1450
static bool plot_staggered_vels
Whether to write the staggered velocities (not averaged to cell centers)
Definition REMORA.H:1996
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
Definition REMORA.H:1448
void set_zeta_averaged_down(int lev)
Copy over zeta data that has been averaged down from high res.
Definition REMORA.cpp:845
std::unique_ptr< NCTimeSeries > qair_data_from_file
Data container for specific humidity read from file.
Definition REMORA.H:1588
static amrex::Real previousCPUTimeUsed
Accumulator variable for CPU time used thusfar.
Definition REMORA.H:2117
amrex::Vector< std::string > cons_names
Names of scalars for plotfile output.
Definition REMORA.H:1941
bool running_with_coupling_driver
True once REMORA has received forcing through the coupling driver.
Definition REMORA.H:526
amrex::Vector< std::unique_ptr< amrex::YAFluxRegister > > advflux_reg
array of flux registers for refluxing in multilevel
Definition REMORA.H:1713
std::unique_ptr< NCTimeSeries > sustr_data_from_file
Data container for u-component surface momentum flux read from file.
Definition REMORA.H:1578
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_fcor
coriolis factor (2D)
Definition REMORA.H:612
int cf_print_iface
print the imposed coarse-fine interface velocity at this baroclinic step (-1 = off)....
Definition REMORA.H:1900
void allocate_init_full_domain()
Allocate multifabs for storing full-domain high resolution initial data.
void init_gls_vmix(int lev, SolverChoice solver_choice)
Initialize GLS variables.
bool time_interp_flux
interpolate the parent's barotropic mass flux in time at the coarse-fine interface,...
Definition REMORA.H:1836
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_xvel_full_domain
multilevel data container for high res initial x velocities (u in ROMS)
Definition REMORA.H:404
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_h
multilevel data container for current step's z velocities (largely unused; W stored separately)
Definition REMORA.H:413
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pm
horizontal scaling factor: 1 / dx (2D)
Definition REMORA.H:603
void set2DPlotVariables(const std::string &pp_plot_var_names_2d)
amrex::Vector< REMORAFillPatcher > FPr_v
Vector over levels of FillPatchers for v (3D)
Definition REMORA.H:1646
void init_biology_ic(int lev)
Initialize biology tracers from whichever source remora.biology_ic_type selects. Call after the physi...
void init_zeta_full_domain_from_netcdf()
Full-domain high res sea-surface height data initialization from NetCDF file.
amrex::Vector< amrex::MultiFab * > cons_new
multilevel data container for current step's scalar data: temperature, salinity, passive tracer
Definition REMORA.H:393
static bool write_history_file
Whether to output NetCDF files as a single history file with several time steps.
Definition REMORA.H:1575
void init_biology_ic_full_domain()
Full-domain counterpart of init_biology_ic, for the hires_init_level average-down path.
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.
Definition REMORA.H:1596
void define_flux_register(int lev)
build or rebuild the flux register between lev and lev-1
Definition REMORA.cpp:2699
void init_masks_full_domain_from_netcdf()
Full domain high-res mask data initialization from NetCDF file.
REMORABiology::BiologyModel biology_model
Active biology package.
Definition REMORA.H:1799
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_vwind
Wind in the v direction, defined at rho-points.
Definition REMORA.H:486
std::unique_ptr< ProblemBase > prob
Pointer to container of analytical functions for problem definition.
Definition REMORA.H:1679
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskr
land/sea mask at cell centers (2D)
Definition REMORA.H:584
void check_mask_consistency()
Check every level pair's masks against each other, and every level's mask values, reporting according...
Definition REMORA.cpp:1047
void Construct_REMORAFillPatchers(int lev)
Construct FillPatchers.
Definition REMORA.cpp:583
void init_grid_vars_from_netcdf(int lev)
Grid variable initialization from NetCDF file.
static int sum_interval
Diagnostic sum output interval in number of steps.
Definition REMORA.H:1988
int history_count
Counter for which time index we are writing to in the netcdf history file.
Definition REMORA.H:1934
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rain
precipitation rate [kg/m^2/s]
Definition REMORA.H:515
int do_substep
Whether to substep fine levels in time.
Definition REMORA.H:1831
void Evolve()
Advance solution to final time.
Definition REMORA.cpp:273
void update_nodal_masks(int lev)
Rebuild the u-, v- and psi-point masks from vec_mskr and fill their ghosts.
std::string bdry_time_varname
Default name of time field for boundary data.
Definition REMORA.H:2039
amrex::Real plotfile_fill_value
fill value for masked arrays in amrex plotfiles
Definition REMORA.H:1955
void ReadCheckpointFile()
read checkpoint file from disk
int biology_debug
Biology diagnostic verbosity: 0 off, 1 target column, 2 all columns. See Source/Biology/Fortran/tag_m...
Definition REMORA.H:1812
bool chunk_history_file
Whether to split the netcdf history file into fixed-length chunks.
Definition REMORA.H:1930
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_sustr
Surface stress in the u direction.
Definition REMORA.H:479
amrex::Real get_t_old(int lev) const
Accessor method for t_old to expose to outside classes.
Definition REMORA.cpp:3288
int yvel_bc() const noexcept
Definition REMORA.H:1449
void build_covered_mask(int crse_lev, amrex::MultiFab &covered)
Average one field down a level, weighted by the land/sea mask.
Definition REMORA.cpp:2986
std::unique_ptr< NCTimeSeries > longwave_down_data_from_file
Data container for downward longwave radiation flux read from file.
Definition REMORA.H:1594
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ru2d
u velocity RHS (2D, includes horizontal and vertical advection)
Definition REMORA.H:434
amrex::Vector< std::string > datalogname
Definition REMORA.H:2149
amrex::Vector< amrex::MultiFab * > zvel_new
multilevel data container for current step's z velocities (largely unused; W stored separately)
Definition REMORA.H:399
void reflux_to(int lev)
apply the lev/lev+1 tracer flux correction onto lev
Definition REMORA.cpp:390
void set_surface_state(int lev)
Initialize or calculate wind speed and other surface state vars from file or analytic.
Definition REMORA.cpp:1621
void check_cf_metrics(int crse_lev)
check that fine cell edges sum to the coarse edge across an interface
Definition REMORA.cpp:2614
void WriteAtIntermediateTime(int step, amrex::Real cur_time)
Write checkpoint and plotfiles at intermediate point of simulation, if needed.
Definition REMORA.cpp:360
double start_time
Time of the start of the simulation, in seconds on the model clock.
Definition REMORA.H:1780
void init_only(int lev, amrex::Real time)
Init (NOT restart or regrid)
Definition REMORA.cpp:1751
void init_set_vmix(int lev)
Initialize vertical mixing coefficients from file or analytic.
Definition REMORA.cpp:902
std::unique_ptr< NCTimeSeries > v_clim_data_from_file
Data container for v-velocity climatology data read from file.
Definition REMORA.H:1609
std::string clim_u_time_varname
Name of time field for u climatology data.
Definition REMORA.H:2048
void set_grid_scale(int lev)
Set pm and pn arrays and x/y coords on level lev.
void set_coriolis(int lev)
Initialize Coriolis factor from file or analytic.
Definition REMORA.cpp:873
int foextrap_bc() const noexcept
Definition REMORA.H:1456
amrex::Vector< REMORAFillPatcher > FPr_u
Vector over levels of FillPatchers for u (3D)
Definition REMORA.H:1644
void set_masks_averaged_down(int lev)
Copy this level's land-sea mask out of the full-domain mask that was coarsened down from hires_grid_l...
Definition REMORA.cpp:993
amrex::Vector< amrex::Vector< amrex::Box > > boxes_at_level
the boxes specified at each level by tagging criteria
Definition REMORA.H:1686
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Hz
Width of cells in the vertical (z-) direction (3D, Hz in ROMS)
Definition REMORA.H:424
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akt
Vertical diffusion coefficient (3D)
Definition REMORA.H:444
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_msku
land/sea mask at x-faces (2D)
Definition REMORA.H:586
std::unique_ptr< NCTimeSeriesRiver > river_source_transportbar
Data container for vertically integrated momentum transport in rivers.
Definition REMORA.H:1620
std::array< bool, AtmosState::NumTypes > driver_atmos_state_from_driver
provenance flags for driver-supplied atmospheric forcing lanes
Definition REMORA.H:524
std::string clim_ubar_time_varname
Name of time field for ubar climatology data.
Definition REMORA.H:2044
std::unique_ptr< NCTimeSeries > u_clim_data_from_file
Data container for u-velocity climatology data read from file.
Definition REMORA.H:1607
std::string check_file
Checkpoint file prefix.
Definition REMORA.H:1923
static amrex::Real startCPUTime
Variable for CPU timing.
Definition REMORA.H:2115
int cf_flux_pc
distribute the parent's interface mass flux piecewise-constantly over the fine faces under each paren...
Definition REMORA.H:1887
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pm_full_domain
horizontal scaling factor: 1 / dx (2D) on whole domain
Definition REMORA.H:607
amrex::Vector< amrex::MultiFab * > xvel_old
multilevel data container for last step's x velocities (u in ROMS)
Definition REMORA.H:386
int cf_avgdown_perimeter
exclude the coarse-fine perimeter's normal-velocity faces from the fine-to-coarse average,...
Definition REMORA.H:1851
void ensure_full_domain_masks(int top_lev)
Make sure the full-domain rho-mask exists on levels 0 through top_lev.
Definition REMORA.cpp:3141
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)
Definition REMORA.H:397
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_uwind
Wind in the u direction, defined at rho-points.
Definition REMORA.H:484
void refine_masks_with_grow_cells(int fine_lev)
Inject the full-domain rho-mask from fine_lev-1 onto fine_lev, piecewise constant,...
Definition REMORA.cpp:3115
static bool plot_nodal_data
Whether to write nodal data (Nu_nd) to plotfiles.
Definition REMORA.H:1999
int regrid_int
how often each level regrids the higher levels of refinement (after a level advances that many time s...
Definition REMORA.H:1913
amrex::Real check_int_time
Checkpoint output interval in seconds.
Definition REMORA.H:1927
DriverAtmosForcingMode driver_atmos_forcing_mode
Active atmosphere-to-ocean forcing contract on the most recent driver apply.
Definition REMORA.H:530
void init_scalar_metadata()
Build runtime scalar names after nscalar is known.
Definition REMORA.cpp:246
int zeta_bc() const noexcept
Definition REMORA.H:1453
void Define_REMORAFillPatchers(int lev)
Define FillPatchers.
Definition REMORA.cpp:639
amrex::Vector< amrex::IntVect > cum_ref_ratios
Cumulative refinement ratio between level 0 and level i.
Definition REMORA.H:2026
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_visc2_p
Harmonic viscosity defined on the psi points (corners of horizontal grid cells)
Definition REMORA.H:446
amrex::Real plot_int_time
Plotfile output interval in seconds.
Definition REMORA.H:1921
amrex::Vector< int > num_files_at_level
how many netcdf input files specified at each level
Definition REMORA.H:1684
amrex::Vector< REMORAFillPatcher > FPr_vbar
Vector over levels of FillPatchers for vbar (2D)
Definition REMORA.H:1654
void AverageDownTo(int crse_lev)
more flexible version of AverageDown() that lets you average down across multiple levels
Definition REMORA.cpp:2840
int steps_per_history_file
Time steps per netcdf history file. Must be > 0 if chunk_history_file.
Definition REMORA.H:1932
void post_timestep(int nstep, amrex::Real time, amrex::Real dt_lev)
Called after every level 0 timestep.
Definition REMORA.cpp:440
int max_step
maximum number of steps
Definition REMORA.H:1770
amrex::Vector< amrex::MultiFab * > zvel_old
multilevel data container for last step's z velocities (largely unused; W stored separately)
Definition REMORA.H:390
std::unique_ptr< NCTimeSeries > svstr_data_from_file
Data container for v-component surface momentum flux read from file.
Definition REMORA.H:1580
void coarsen_bathymetry_with_grow_cells(int crse_lev)
Coarsen the full-domain bathymetry from crse_lev+1 onto crse_lev, grow cells included,...
Definition REMORA.cpp:1272
amrex::Vector< std::string > nc_frc_file
NetCDF forcing file(s)
Definition REMORA.H:2029
amrex::Vector< int > num_boxes_at_level
how many boxes specified at each level by tagging criteria
Definition REMORA.H:1682
amrex::Vector< amrex::MultiFab * > xvel_new
multilevel data container for current step's x velocities (u in ROMS)
Definition REMORA.H:395
void refinement_criteria_setup()
Set refinement criteria.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskp
land/sea mask at cell corners (2D)
Definition REMORA.H:590
int Bio_comp
First cons component of the biology block, i.e. Tracer_comp + nscalar. The state is laid out as temp,...
Definition REMORA.H:1794
int last_check_file_step
Step when we last output a checkpoint file.
Definition REMORA.H:1760
int bdy_zeta() const noexcept
Definition REMORA.H:1466
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.
Definition REMORA.H:2046
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskv
land/sea mask at y-faces (2D)
Definition REMORA.H:588
amrex::Vector< int > nsubsteps
How many substeps on each level?
Definition REMORA.H:1691
amrex::Vector< std::unique_ptr< REMORAPhysBCFunct > > physbcs
Vector (over level) of functors to apply physical boundary conditions.
Definition REMORA.H:1710
void ComputeDt()
a wrapper for estTimeStep()
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_msku_crse_on_fine
Definition REMORA.H:599
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.
Definition REMORA.H:1600
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=zero, const amrex::MultiFab &mf_calc=amrex::MultiFab())
fill an entire multifab by interpolating from the coarser level
int plot_int
Plotfile output interval in iterations.
Definition REMORA.H:1919
std::unique_ptr< NCTimeSeries > cloud_data_from_file
Data container for cloud cover fraction read from file.
Definition REMORA.H:1598
amrex::YAFluxRegister * getAdvFluxReg(int lev)
flux register between lev and lev-1
Definition REMORA.H:1716
int nbio
Number of biology tracers, set by the active biology model. Zero when no biology model is active.
Definition REMORA.H:1791
void WriteAtFinalTime()
Write checkpoint and plotfiles at end of simulation.
Definition REMORA.cpp:345
void InitData()
Initialize multilevel data.
Definition REMORA.cpp:465
void update_avgdown_masks(int crse_lev)
Make sure the coarse masks the average-down kernels read sit on the coarsened layout of level crse_le...
Definition REMORA.cpp:2766
void set3DPlotVariables(const std::string &pp_plot_var_names_3d)
amrex::Vector< int > istep
which step?
Definition REMORA.H:1689
void WriteCheckpointFile()
write checkpoint file to disk
std::string nc_clim_coeff_file
NetCDF climatology coefficient file.
Definition REMORA.H:2036
void setRecordDataInfo(int i, const std::string &filename)
Definition REMORA.H:2135
void set_analytic_vmix(int lev)
Set vertical mixing coefficients from analytic.
Definition REMORA.cpp:919
void coarsen_masks_with_grow_cells(int crse_lev)
Coarsen the full-domain rho-mask from crse_lev+1 onto crse_lev, grow cells included,...
Definition REMORA.cpp:1014
amrex::Vector< std::string > bdry_time_name_byvar
Name of time fields for boundary data.
Definition REMORA.H:2041
static int file_min_digits
Minimum number of digits in plotfile name or chunked history file.
Definition REMORA.H:1993
void init_riv_pos_from_netcdf(int lev)
static amrex::Vector< std::string > nc_bdry_file
NetCDF boundary data.
Definition REMORA.H:58
amrex::Vector< REMORAFillPatcher > FPr_Dubar
Vector over levels of FillPatchers for Dubar (2D)
Definition REMORA.H:1656
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_visc2_r
Harmonic viscosity defined on the rho points (centers)
Definition REMORA.H:448
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_yvel_full_domain
multilevel data container for high res initial y velocities (v in ROMS)
Definition REMORA.H:406
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_svstr
Surface stress in the v direction.
Definition REMORA.H:481
std::unique_ptr< NCTimeSeries > srflx_data_from_file
Data container for shortwave radiation flux read from file.
Definition REMORA.H:1592
REMORA()
Definition REMORA.cpp:69
void set_zeta(int lev)
Initialize zeta from file or analytic.
Definition REMORA.cpp:712
static amrex::Real change_max
Fraction maximum change in subsequent time steps.
Definition REMORA.H:1822
int check_cf_metrics_flag
measure whether fine cell edges tile the coarse ones at a coarse-fine interface, which is what makes ...
Definition REMORA.H:1908
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.
amrex::Vector< REMORAFillPatcher > FPr_Dvbar
Vector over levels of FillPatchers for Dvbar (2D)
Definition REMORA.H:1658
std::string pp_prefix
default prefix for input file parameters
Definition REMORA.H:381
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_h_full_domain
Bathymetry data on the whole domain at each potential level.
Definition REMORA.H:416
void set_bathymetry(int lev)
Initialize bathymetry from file or analytic.
Definition REMORA.cpp:751
amrex::Vector< amrex::MultiFab * > yvel_old
multilevel data container for last step's y velocities (v in ROMS)
Definition REMORA.H:388
std::unique_ptr< NCTimeSeries > ubar_clim_data_from_file
Data container for ubar climatology data read from file.
Definition REMORA.H:1603
void init_full_domain_from_analytic()
Initialize high-resolution initial data, zeta included, from analytic functions.
void init_data_full_domain_from_netcdf()
High resolution roblem initialization from NetCDF file.
void init_ref_ratios()
Reject vertical refinement and accumulate the refinement ratios.
Definition REMORA.cpp:217
amrex::Vector< REMORAFillPatcher > FPr_c
Vector over levels of FillPatchers for scalars.
Definition REMORA.H:1642
int hires_init_level
Which level the high resolution initialization data is at.
Definition REMORA.H:2019
amrex::Vector< std::string > clim_cons_time_varname
Vector over cons components of the name of the time field for that tracer's climatology data.
Definition REMORA.H:2053
std::unique_ptr< NCTimeSeries > Tair_data_from_file
Data container for air temperature read from file.
Definition REMORA.H:1586
int cf_avgdown_bar
Definition REMORA.H:1868
int nscalar
Number of passive (dye) scalars carried in the state, beyond temperature and salinity....
Definition REMORA.H:1788
std::string clim_v_time_varname
Name of time field for v climatology data.
Definition REMORA.H:2050
amrex::Vector< REMORAFillPatcher > FPr_w
Vector over levels of FillPatchers for w.
Definition REMORA.H:1648
std::unique_ptr< NCTimeSeries > Uwind_data_from_file
Data container for u-direction wind read from file.
Definition REMORA.H:1582
std::unique_ptr< NCTimeSeries > Pair_data_from_file
Data container for air pressure read from file.
Definition REMORA.H:1590
int cf_fill_vel_after
re-fill the child's 3D velocity from the parent after the step, so the coarse-fine boundary carries t...
Definition REMORA.H:1859
amrex::Vector< amrex::Real > t_new
new time at each level, in seconds since start_time
Definition REMORA.H:1700
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.
Definition REMORA.H:1949
void set_masks(int lev)
Initialize land-sea masks from file or analytic.
Definition REMORA.cpp:942
void set_zeta_to_Ztavg(int lev, bool apply_eminusp=true)
Set zeta components to be equal to time-averaged Zt_avg1.
bool driver_uses_two_way_coupling
Driver-level direction flag copied in before InitData.
Definition REMORA.H:528
amrex::Vector< amrex::Vector< std::unique_ptr< NCTimeSeriesBoundary > > > boundary_series
Vector over BdyVars of boundary series data containers.
Definition REMORA.H:1623
int cf_set_width
Width for fixing values at coarse-fine interface.
Definition REMORA.H:1639
int biology_debug_j
Target column j index for biology_debug = 1.
Definition REMORA.H:1816
void ReadParameters()
read in some parameters from inputs file
Definition REMORA.cpp:2111
int do_reflux
correct the coarse tracer with the finer level's accumulated advective flux at their interface....
Definition REMORA.H:1847
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ru
u velocity RHS (3D, includes horizontal and vertical advection)
Definition REMORA.H:430
void clear_avgdown_masks(int lev)
Drop the cached average-down masks of every level pair that involves lev.
Definition REMORA.cpp:2590
void sum_integrated_quantities(amrex::Real time)
Integrate conserved quantities for diagnostics.
static int total_nc_plot_file_step
Definition REMORA.H:1480
int cf_impose_flux
impose the parent's barotropic mass flux on DUon/DVom at the coarse-fine interface,...
Definition REMORA.H:1842
static amrex::Vector< amrex::Vector< std::string > > nc_grid_file
NetCDF grid file.
Definition REMORA.H:60
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_longwave_down
Downward longwave radiation.
Definition REMORA.H:499
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_zeta
free surface height (2D)
Definition REMORA.H:578
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_vbar
barotropic y velocity (2D)
Definition REMORA.H:576
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=zero, const amrex::MultiFab &mf_calc=amrex::MultiFab())
fill an entire multifab by interpolating from the coarser level using the piecewise constant interpol...
bool expand_plotvars_to_unif_rr
whether plotfile variables should be expanded to a uniform refinement ratio
Definition REMORA.H:1952
int plot_file_on_restart
Whether to output a plotfile on restart from checkpoint.
Definition REMORA.H:1764
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)
Definition REMORA.H:574
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=false, const int n_not_fill=0, const int icomp_calc=0, const amrex::Real dt=zero, const amrex::MultiFab &mf_calc=amrex::MultiFab(), amrex::Vector< amrex::MultiFab * > const &mfs_crse_old={}, amrex::Vector< amrex::MultiFab * > const &mfs_crse_new={})
Fill a new MultiFab by copying in phi from valid region and filling ghost cells.
void restore_perimeter_faces(const amrex::MultiFab &saved, amrex::MultiFab &mf, const amrex::MultiFab &covered, int dir, int ncomp)
put back the coarse normal-velocity faces on the fine patch's perimeter
Definition REMORA.cpp:3021
amrex::Vector< amrex::MultiFab * > cons_old
multilevel data container for last step's scalar data: temperature, salinity, passive tracer
Definition REMORA.H:384
std::string frc_time_varname
Name of time field for forcing data.
Definition REMORA.H:2057
amrex::Vector< REMORAFillPatcher > FPr_ubar
Vector over levels of FillPatchers for ubar (2D)
Definition REMORA.H:1652
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.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_cons_full_domain
multilevel data container for high res initial data: temperature, salinity, passive tracer
Definition REMORA.H:402
std::unique_ptr< NCTimeSeries > Vwind_data_from_file
Data container for v-direction wind read from file.
Definition REMORA.H:1584
static constexpr bool DriverUsesStateForcing(DriverAtmosForcingMode mode) noexcept
Definition REMORA.H:100
static int ndtfast
User specified, number of barotropic steps per baroclinic step.
Definition REMORA.H:1826
void init_bathymetry_full_domain_from_netcdf()
Full domain high-res bathymetry data initialization from NetCDF file.
amrex::Vector< std::unique_ptr< NCTimeSeries > > cons_clim_data_from_file
Vector over cons components of climatology data read from file.
Definition REMORA.H:1613
void set_hmixcoef(int lev)
Initialize horizontal mixing coefficients.
Definition REMORA.cpp:1317
amrex::Vector< std::unique_ptr< NCTimeSeriesRiver > > river_source_cons
Vector of data containers for scalar data in rivers.
Definition REMORA.H:1616
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.
Definition REMORA.H:1618
int cf_time_interp_zeta
interpolate the parent in time onto the child's own sub-time, as put_refine2d does,...
Definition REMORA.H:1881
void init_grid_vars_full_domain_from_netcdf()
Full domain high-res grid variable initialization from NetCDF file.
void AverageDown()
set covered coarse cells to be the average of overlying fine cells
Definition REMORA.cpp:2571
amrex::Real netcdf_fill_value
fill value for masked arrays in netcdf output
Definition REMORA.H:1957
void set_nsubsteps(int nlevs_max)
size nsubsteps and set how many steps each level takes per parent step
Definition REMORA.cpp:2724
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pn_full_domain
horizontal scaling factor: 1 / dy (2D) on whole domain
Definition REMORA.H:609
void timeStepML(amrex::Real time, int iteration)
advance all levels by dt, loops over finer levels
void print_timestep_hierarchy() const
report the per-level slow/fast timestep hierarchy; call after ComputeDt
const amrex::DistributionMapping & full_domain_dmap()
The shared full-domain DistributionMapping, built on first use.
int cf_avgdown_stencil
average the fine velocity onto the coarse over ROMS's nine-point stencil (fine2coarse2d,...
Definition REMORA.H:1896
int cf_set_2d_bcs
0 = never impose the 2D coarse-fine interface condition, 1 = every fast step, 2 = only the first fast...
Definition REMORA.H:1867
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pn
horizontal scaling factor: 1 / dy (2D)
Definition REMORA.H:605
amrex::Vector< std::unique_ptr< std::fstream > > datalog
Definition REMORA.H:2148
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akv
Vertical viscosity coefficient (3D)
Definition REMORA.H:442
static amrex::Real cfl
CFL condition.
Definition REMORA.H:1820
void init_masks_full_domain_from_analytic()
Full domain land-sea mask initialization from analytic.
void append3DPlotVariables(const std::string &pp_plot_var_names_3d)
REMORABiology::FennelParameters fennel_params
Runtime parameters for the Fennel biology package.
Definition REMORA.H:1801
void allocate_bathymetry_grid_vars_full_domain()
Allocate multifabs for storing full-domain bathymetry and grid vars data.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskv_crse_on_fine
Definition REMORA.H:600
amrex::Real elapsed_time(double time) const noexcept
Elapsed time since start_time of a time on the model clock.
Definition REMORA.H:2176
void set_init_data_averaged_down(int lev)
Problem initialization from averaged-down high resolution data.
Definition REMORA.cpp:856
static int verbose
Verbosity level of output.
Definition REMORA.H:1985
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_cloud
cloud cover fraction [0-1], defined at rho-points
Definition REMORA.H:519
std::string plot_file_name
Plotfile prefix.
Definition REMORA.H:1917
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Zt_avg1
Average of the free surface, zeta (2D)
Definition REMORA.H:476
int check_int
Checkpoint output interval in iterations.
Definition REMORA.H:1925
amrex::Real check_cf_tol
tolerance for the above
Definition REMORA.H:1910
void set_smflux(int lev)
Initialize or calculate surface momentum flux from file or analytic.
Definition REMORA.cpp:1602
void WritePlotFile(int istep)
main driver for writing AMReX plotfiles
std::string restart_chkfile
If set, restart from this checkpoint file.
Definition REMORA.H:1783
void average_down_with_grow_cells(int lev, amrex::Vector< std::unique_ptr< amrex::MultiFab > > &mf, bool use_mask=false)
Average down from level lev+1 to lev in mf, including grow cells.
Definition REMORA.cpp:3217
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)
Definition REMORA.H:432
int cf_width
Nudging width at coarse-fine interface.
Definition REMORA.H:1637
static amrex::Vector< amrex::Vector< std::string > > nc_init_file
NetCDF initialization file.
Definition REMORA.H:59
int last_plot_file_step
Step when we last output a plotfile.
Definition REMORA.H:1755
int use_biology_cpp_answer
Select the native C++ biology kernel (1) or the ROMS Fortran bridge oracle (0). Only meaningful when ...
Definition REMORA.H:1809
amrex::Vector< amrex::Real > t_old
old time at each level, in seconds since start_time
Definition REMORA.H:1702
double model_time(amrex::Real elapsed) const noexcept
Time on the model clock, in seconds, of an elapsed time such as t_new.
Definition REMORA.H:2170
int cf_fill_all_kcomp
write every leapfrog record of the coarse-fine ghost band, as put_refine2d does when it sets zeta(:,...
Definition REMORA.H:1876
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_srflx
Shortwave radiation flux [W/m²], defined at rho-points.
Definition REMORA.H:495
amrex::Real last_check_file_time
Simulation time when we last output a checkpoint file.
Definition REMORA.H:1762
static amrex::Vector< REMORAErrorTag > ref_tags
Holds info for dynamically generated tagging criteria.
Definition REMORA.H:2066
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.
Definition REMORA.cpp:810
amrex::Vector< amrex::Real > dt
time step at each level
Definition REMORA.H:1704
static amrex::Real sum_per
Diagnostic sum output interval in time.
Definition REMORA.H:1990
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Pair
Air pressure [mb], defined at rho-points.
Definition REMORA.H:492
virtual ~REMORA()
Definition REMORA.cpp:205
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_qair
Specific humidity [kg/kg], defined at rho-points.
Definition REMORA.H:490
int hires_grid_level
Which level the high resolution bathymetry is at.
Definition REMORA.H:2012
void restart()
Definition REMORA.cpp:695
int reflux_clamp
stop that correction driving a tracer negative, as ROMS does. On by default to match ROMS; costs exac...
Definition REMORA.H:1904
std::unique_ptr< NCTimeSeries > vbar_clim_data_from_file
Data container for vbar climatology data read from file.
Definition REMORA.H:1605
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Tair
Air temperature [°C], defined at rho-points.
Definition REMORA.H:488
void average_down_masked(int crse_lev, const amrex::MultiFab &S_fine, amrex::MultiFab &S_crse, const amrex::MultiFab &msk_fine, const amrex::MultiFab &cmsk, int ncomp, int face_dir)
Definition REMORA.cpp:3057
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_diff2
Harmonic diffusivity for temperature / salinity.
Definition REMORA.H:450
REMORABiology::BiologyICType biology_ic_type
Source of the biology tracer initial condition, independent of remora.ic_type. Default follows ic_typ...
Definition REMORA.H:1804
@ Pair
atmospheric pressure [Pa from driver, mb in REMORA]
@ Vwind
10-m meridional wind [m/s]
@ Qair
specific humidity [kg/kg]
@ SWrad
downward shortwave radiation [W/m^2]
@ LWrad
downward longwave radiation [W/m^2]
@ Uwind
10-m zonal wind [m/s]
@ Rain
precipitation rate [kg/m^2/s]
@ Cloud
cloud fraction [0-1]
@ Tair
air temperature [K from driver, degC in REMORA]
static constexpr int cons_bc
static constexpr int Temp_bc_comp
static constexpr int t
cons component Temp_comp
static constexpr int u
int NumTypes(int ncons) noexcept
static constexpr int v
int vbar(int ncons) noexcept
int cons(int icomp) noexcept
static constexpr int null
int zeta(int ncons) noexcept
int ubar(int ncons) noexcept
@ Vwind
10-m meridional wind [m/s]
@ Pair
atmospheric pressure [mb]
@ Uwind
10-m zonal wind [m/s]
@ LWrad
longwave radiation [W/m^2]
@ Tair
air temperature [degC]
@ Qair
specific humidity or relative humidity [kg/kg or fraction]
@ Cloud
cloud fraction [0-1]
@ SWrad
downward shortwave radiation [W/m^2]
@ Rain
precipitation rate [kg/m^2/s]
@ EminusP
evaporation minus precipitation [m/s]
Vector< std::string > tracer_names(BiologyModel model, FennelParameters const &fennel_parameters)
std::string biology_ic_type_name(BiologyICType type)
bool has_biology(BiologyModel model) noexcept
BiologyICType parse_biology_ic_type(const std::string &name)
BiologyModel parse_biology_model(const std::string &name)
std::string biology_model_name(BiologyModel model)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void avgdown_faces_masked(int i, int j, int k, int n, amrex::Array4< amrex::Real > const &crse, amrex::Array4< amrex::Real const > const &fine, amrex::Array4< amrex::Real const > const &fmsk, amrex::Array4< amrex::Real const > const &cmsk, int ccomp, int fcomp, amrex::IntVect const &ratio, int idir) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void avgdown_masked(int i, int j, int k, int n, amrex::Array4< amrex::Real > const &crse, amrex::Array4< amrex::Real const > const &fine, amrex::Array4< amrex::Real const > const &fmsk, amrex::Array4< amrex::Real const > const &cmsk, int ccomp, int fcomp, amrex::IntVect const &ratio) noexcept
const char * buildInfoGetGitHash(int i)
void init_params(const std::string &remora_prefix)
amrex::Vector< amrex::Real > Akt_bak
HorizMixingType horiz_mixing_type
amrex::Real Akv_bak
amrex::Vector< amrex::Real > tnu2
std::string longwave_netcdf_varname
amrex::Vector< int > do_rivers_cons
ScaledToGridAMRScaling scaled_to_grid_amr_scaling
MaskConsistency mask_consistency
void init_params(int ncons, int nscalar, const amrex::Vector< std::string > &cons_names)
read in and initialize parameters
SMFluxType smflux_type
VertMixingType vert_mixing_type
std::array< BulkForcingType, BulkFlux::NumTypes > bulk_flux_type
GridScaleType grid_scale_type
amrex::Vector< int > do_cons_clim_nudg
CouplingType coupling_type