REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_TimeStep.cpp
Go to the documentation of this file.
1#include <REMORA.H>
2
3using namespace amrex;
4
5/**
6 * @param[in] lev level of refinement
7 * @param[in] time simulation time at start of step
8 * @param[in] iteration iteration in subcycling, if using
9 */
10void
12{
13 if (regrid_int > 0) // We may need to regrid
14 {
15 // help keep track of whether a level was already regridded
16 // from a coarser level call to regrid
17 static Vector<int> last_regrid_step(max_level+1, 0);
18
19 // regrid changes level "lev+1" so we don't regrid on max_level
20 // also make sure we don't regrid fine levels again if
21 // it was taken care of during a coarser regrid
23 {
24 if (istep[lev] % regrid_int == 0)
25 {
26 // regrid interpolates this level's data to build lev+1, so its ghost cells
27 // must be current. The swap has not happened, so "new" is what regrid reads.
32
33 // regrid could add newly refine levels (if finest_level < max_level)
34 // so we save the previous finest level index
36 regrid(lev, time);
37
38 // The refined footprint moved, so the level pairs are new
40
41#ifdef REMORA_USE_PARTICLES
42 if (finest_level != old_finest) {
43 particleData.Redistribute();
44 }
45#endif
46
47 // Mark that we have regridded this level already
48 for (int k = lev; k <= finest_level; ++k) {
50 }
51
52 // If there are newly created levels, set the time step. nsubsteps, not the
53 // refinement ratio: without subcycling every level shares dt[0].
54 for (int k = old_finest+1; k <= finest_level; ++k) {
55 dt[k] = dt[k-1] / nsubsteps[k];
56 }
57 }
58 }
59 }
60
62
63 // Update what we call "old" and "new" time
64 t_old[lev] = t_new[lev];
65 // A child's last substep lands exactly on its parent's new time. Summing dt[lev] would
66 // drift when it is inexact (dt/3 in single precision), leaving the next step's t_old
67 // just before the parent's t_old -- outside the interval the fill patchers bracket.
68 if (lev > 0 && iteration == nsubsteps[lev]) {
69 t_new[lev] = t_new[lev-1];
70 } else {
71 t_new[lev] += dt[lev];
72 }
73
74 // A child must stay inside its parent's step, or the fill patchers have nothing to
75 // interpolate within. REMORAFillPatcher asserts this too, but cannot name the level.
76 if (lev > 0) {
77 const Real eps = Real(1.e-6) * dt[lev];
79 t_old[lev] >= t_old[lev-1] - eps && t_new[lev] <= t_new[lev-1] + eps,
80 "REMORA::timeStep: level " + std::to_string(lev) + " stepped outside the time "
81 "interval of level " + std::to_string(lev-1));
82 }
83
84 if (Verbose()) {
85 amrex::Print() << "[Level " << lev << " step " << istep[lev]+1 << "] ";
86 amrex::Print() << "ADVANCE from time = " << t_old[lev] << " to " << t_new[lev]
87 << " with dt = " << dt[lev] << std::endl;
88 }
89
90 // We must swap the pointers so the previous step's "new" is now this step's "old"
91 std::swap(cons_old[lev], cons_new[lev]);
92 std::swap(xvel_old[lev], xvel_new[lev]);
93 std::swap(yvel_old[lev], yvel_new[lev]);
94 std::swap(zvel_old[lev], zvel_new[lev]);
95
96 // Advance a single level for a single time step
98
99 ++istep[lev];
100
102
103 if (Verbose())
104 {
105 amrex::Print() << "[Level " << lev << " step " << istep[lev] << "] ";
106 amrex::Print() << "Advanced " << CountCells(lev) << " cells" << std::endl;
107 }
108
109 if (lev < finest_level)
110 {
111 // recursive call for next-finer level
112 for (int i = 1; i <= nsubsteps[lev+1]; ++i)
113 {
114 timeStep(lev+1, time+(i-1)*dt[lev+1], i);
115 }
116
117 // Before the average-down: refluxing writes coarse cells under the fine grid on the
118 // assumption they are about to be overwritten from it.
119 reflux_to(lev);
120
122 AverageDownTo(lev); // average lev+1 down to lev
123 }
124 }
125}
mf_h setVal(geomdata.ProbHi(2))
int zvel_bc() const noexcept
Definition REMORA.H:1450
amrex::Vector< amrex::MultiFab * > cons_new
multilevel data container for current step's scalar data: temperature, salinity, passive tracer
Definition REMORA.H:393
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
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
amrex::Vector< amrex::MultiFab * > xvel_old
multilevel data container for last step's x velocities (u in ROMS)
Definition REMORA.H:386
amrex::Vector< amrex::MultiFab * > yvel_new
multilevel data container for current step's y velocities (v in ROMS)
Definition REMORA.H:397
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
void AverageDownTo(int crse_lev)
more flexible version of AverageDown() that lets you average down across multiple levels
Definition REMORA.cpp:2840
amrex::Vector< amrex::MultiFab * > zvel_old
multilevel data container for last step's z velocities (largely unused; W stored separately)
Definition REMORA.H:390
amrex::Vector< amrex::MultiFab * > xvel_new
multilevel data container for current step's x velocities (u in ROMS)
Definition REMORA.H:395
amrex::Vector< int > nsubsteps
How many substeps on each level?
Definition REMORA.H:1691
amrex::Vector< int > istep
which step?
Definition REMORA.H:1689
amrex::Vector< amrex::MultiFab * > yvel_old
multilevel data container for last step's y velocities (v in ROMS)
Definition REMORA.H:388
void Advance(int lev, amrex::Real time, amrex::Real dt_lev, int iteration, int ncycle)
advance a single level for a single time step
amrex::Vector< amrex::Real > t_new
new time at each level, in seconds since start_time
Definition REMORA.H:1700
void scale_rhs_vars_inv(int lev)
Scale RHS momentum variables by cell area, needed after FillPatch to different levels.
static SolverChoice solverChoice
Container for algorithmic choices.
Definition REMORA.H:1949
void FillPatchNoBC(int lev, amrex::Real time, amrex::MultiFab &mf_to_be_filled, amrex::Vector< amrex::MultiFab * > const &mfs, const int bdy_var_type=BdyVars::null, const int icomp=0, const bool fill_all=true, const bool fill_set=false, 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 without applying boun...
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.
amrex::Vector< amrex::MultiFab * > cons_old
multilevel data container for last step's scalar data: temperature, salinity, passive tracer
Definition REMORA.H:384
void timeStep(int lev, amrex::Real time, int iteration)
advance a level by dt, includes a recursive call for finer levels
amrex::Vector< amrex::Real > t_old
old time at each level, in seconds since start_time
Definition REMORA.H:1702
void scale_rhs_vars(int lev)
Scale RHS momentum variables by 1/cell area, needed before FillPatch to different levels.
amrex::Vector< amrex::Real > dt
time step at each level
Definition REMORA.H:1704
static constexpr int t
cons component Temp_comp
static constexpr int u
static constexpr int v
static constexpr int null
CouplingType coupling_type