REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_TimeStepML.cpp
Go to the documentation of this file.
1#include <REMORA.H>
2
3using namespace amrex;
4
5/**
6 * @param[in] time simulation time at start of step
7 * @param[in] iteration iteration in subcycling, if using
8 */
9void
10REMORA::timeStepML (Real time, int /*iteration*/)
11{
12#if 0
15 0, cons_new[0]->nComp(), refRatio(0));
17 }
18#endif
19
20 // HACK HACK so lev is defined and compiler won't complain, but always say regrid_int=-1
21 for (int lev=0; lev <= finest_level;lev++) {
22 if (regrid_int > 0) // We may need to regrid
23 {
24 // help keep track of whether a level was already regridded
25 // from a coarser level call to regrid
26 static Vector<int> last_regrid_step(max_level+1, 0);
27
28 // regrid changes level "lev+1" so we don't regrid on max_level
29 // also make sure we don't regrid fine levels again if
30 // it was taken care of during a coarser regrid
32 {
33 if (istep[lev] % regrid_int == 0)
34 {
35 // regrid could add newly refine levels (if finest_level < max_level)
36 // so we save the previous finest level index
38 regrid(lev, time);
39
40 // Mark that we have regridded this level already
41 for (int k = lev; k <= finest_level; ++k) {
43 }
44
45 // If there are newly created levels, set the time step
46 for (int k = old_finest+1; k <= finest_level; ++k) {
47 dt[k] = dt[k-1] / nsubsteps[lev];
48 }
49 }
50 }
51 }
52 }
53
55
56 for (int lev=0; lev <= finest_level;lev++)
57 {
58 // Update what we call "old" and "new" time
59 t_old[lev] = t_new[lev];
60 t_new[lev] += dt[lev];
61
62 if (Verbose()) {
63 amrex::Print() << "[Level " << lev << " step " << istep[lev]+1 << "] ";
64 amrex::Print() << "ADVANCE from time = " << t_old[lev] << " to " << t_new[lev]
65 << " with dt = " << dt[lev] << std::endl;
66 }
67
68 // We must swap the pointers so the previous step's "new" is now this step's "old"
69 std::swap(cons_old[lev], cons_new[lev]);
70 std::swap(xvel_old[lev], xvel_new[lev]);
71 std::swap(yvel_old[lev], yvel_new[lev]);
72 std::swap(zvel_old[lev], zvel_new[lev]);
73
75
76 // **************************************************************************************
77 // Register old and new coarse data if we are at a level less than the finest level
78 // **************************************************************************************
79 if (lev < finest_level)
80 {
81 if (cf_width > 0) {
82 // We must fill the ghost cells of these so that the parallel copy works correctly
83 cons_old[lev]->FillBoundary(geom[lev].periodicity());
84 cons_new[lev]->FillBoundary(geom[lev].periodicity());
85 FPr_c[lev].RegisterCoarseData({cons_old[lev], cons_new[lev]}, {time, time + dt[lev]});
86 }
87
88 if (cf_width >= 0) {
89 // We must fill the ghost cells of these so that the parallel copy works correctly
90 xvel_old[lev]->FillBoundary(geom[lev].periodicity());
91 xvel_new[lev]->FillBoundary(geom[lev].periodicity());
92 FPr_u[lev].RegisterCoarseData({xvel_old[lev], xvel_new[lev]}, {time, time + dt[lev]});
93
94 yvel_old[lev]->FillBoundary(geom[lev].periodicity());
95 yvel_new[lev]->FillBoundary(geom[lev].periodicity());
96 FPr_v[lev].RegisterCoarseData({yvel_old[lev], yvel_new[lev]}, {time, time + dt[lev]});
97
98 zvel_old[lev]->FillBoundary(geom[lev].periodicity());
99 zvel_new[lev]->FillBoundary(geom[lev].periodicity());
100 FPr_w[lev].RegisterCoarseData({zvel_old[lev], zvel_new[lev]}, {time, time + dt[lev]});
101 }
102 }
103 }
104
105 int nfast_counter=nfast + 1;
106
107 for (int my_iif = 0; my_iif < nfast_counter; my_iif++) {
108 //Compute fast timestep from dt[lev] and ratio
109 for (int lev=0; lev <= finest_level; lev++)
110 {
111 Real dtfast_lev=dt[lev]/Real(ndtfast);
113 // **************************************************************************************
114 // Register old and new coarse data if we are at a level less than the finest level
115 // **************************************************************************************
116 if (lev < finest_level)
117 {
118 if (cf_width >= 0) {
119 // We must fill the ghost cells of these so that the parallel copy works correctly
120 vec_ubar[lev]->FillBoundary(geom[lev].periodicity());
121 FPr_ubar[lev].RegisterCoarseData({vec_ubar[lev].get(), vec_ubar[lev].get()}, {time, time + dt[lev]});
122
123 vec_vbar[lev]->FillBoundary(geom[lev].periodicity());
124 FPr_vbar[lev].RegisterCoarseData({vec_vbar[lev].get(), vec_vbar[lev].get()}, {time, time + dt[lev]});
125 }
126 }
127 } // lev
128 } // my_iif
129
130 for (int lev=0; lev <= finest_level; lev++) {
132 ++istep[lev];
133
134 if (Verbose())
135 {
136 amrex::Print() << "[Level " << lev << " step " << istep[lev] << "] ";
137 amrex::Print() << "Advanced " << CountCells(lev) << " cells" << std::endl;
138 }
139 // **************************************************************************************
140 // Register old and new coarse data if we are at a level less than the finest level
141 // **************************************************************************************
142 if (lev < finest_level)
143 {
144 if (cf_width > 0) {
145 // We must fill the ghost cells of these so that the parallel copy works correctly
146 cons_old[lev]->FillBoundary(geom[lev].periodicity());
147 cons_new[lev]->FillBoundary(geom[lev].periodicity());
148 FPr_c[lev].RegisterCoarseData({cons_old[lev], cons_new[lev]}, {time, time + dt[lev]});
149 }
150
151 if (cf_width >= 0) {
152 // We must fill the ghost cells of these so that the parallel copy works correctly
153 xvel_old[lev]->FillBoundary(geom[lev].periodicity());
154 xvel_new[lev]->FillBoundary(geom[lev].periodicity());
155 FPr_u[lev].RegisterCoarseData({xvel_old[lev], xvel_new[lev]}, {time, time + dt[lev]});
156
157 yvel_old[lev]->FillBoundary(geom[lev].periodicity());
158 yvel_new[lev]->FillBoundary(geom[lev].periodicity());
159 FPr_v[lev].RegisterCoarseData({yvel_old[lev], yvel_new[lev]}, {time, time + dt[lev]});
160
161 zvel_old[lev]->FillBoundary(geom[lev].periodicity());
162 zvel_new[lev]->FillBoundary(geom[lev].periodicity());
163 FPr_w[lev].RegisterCoarseData({zvel_old[lev], zvel_new[lev]}, {time, time + dt[lev]});
164 }
165 }
166 if ( (solverChoice.boundary_from_netcdf) && (lev==0) ) {
167 // We might need to go back to normal FillPatch once the refined patches are allowed to intersect the boundary in NetCDF
171 } else {
175 }
176 }
177
179
181 for (int lev=0; lev <= finest_level-1; lev++) {
182 AverageDownTo(lev); // average lev+1 down to lev
183 }
184 }
185}
constexpr amrex::Real zero
mf_h setVal(geomdata.ProbHi(2))
int nfast
Number of fast steps to take.
Definition REMORA.H:1675
void scale_rhs_vars()
Scale RHS momentum variables by 1/cell area, needed before FillPatch to different levels.
int zvel_bc() const noexcept
Definition REMORA.H:1315
int xvel_bc() const noexcept
Definition REMORA.H:1313
amrex::Vector< REMORAFillPatcher > FPr_v
Vector over levels of FillPatchers for v (3D)
Definition REMORA.H:1513
amrex::Vector< amrex::MultiFab * > cons_new
multilevel data container for current step's scalar data: temperature, salinity, passive tracer
Definition REMORA.H:386
int yvel_bc() const noexcept
Definition REMORA.H:1314
amrex::Vector< amrex::MultiFab * > zvel_new
multilevel data container for current step's z velocities (largely unused; W stored separately)
Definition REMORA.H:392
amrex::Vector< REMORAFillPatcher > FPr_u
Vector over levels of FillPatchers for u (3D)
Definition REMORA.H:1511
amrex::Vector< amrex::MultiFab * > xvel_old
multilevel data container for last step's x velocities (u in ROMS)
Definition REMORA.H:379
amrex::Vector< amrex::MultiFab * > yvel_new
multilevel data container for current step's y velocities (v in ROMS)
Definition REMORA.H:390
int regrid_int
how often each level regrids the higher levels of refinement (after a level advances that many time s...
Definition REMORA.H:1681
void advance_2d_onestep(int lev, amrex::Real dt_lev, amrex::Real dtfast_lev, int my_iif, int nfast_counter)
2D advance, one predictor/corrector step
amrex::Vector< REMORAFillPatcher > FPr_vbar
Vector over levels of FillPatchers for vbar (2D)
Definition REMORA.H:1521
void AverageDownTo(int crse_lev)
more flexible version of AverageDown() that lets you average down across multiple levels
Definition REMORA.cpp:2051
amrex::Vector< amrex::MultiFab * > zvel_old
multilevel data container for last step's z velocities (largely unused; W stored separately)
Definition REMORA.H:383
amrex::Vector< amrex::MultiFab * > xvel_new
multilevel data container for current step's x velocities (u in ROMS)
Definition REMORA.H:388
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)
Fill a new MultiFab by copying in phi from valid region and filling ghost cells without applying boun...
amrex::Vector< int > nsubsteps
How many substeps on each level?
Definition REMORA.H:1554
amrex::Vector< int > istep
which step?
Definition REMORA.H:1552
void advance_3d_ml(int lev, amrex::Real dt_lev)
3D advance on a single level
amrex::Vector< amrex::MultiFab * > yvel_old
multilevel data container for last step's y velocities (v in ROMS)
Definition REMORA.H:381
amrex::Vector< REMORAFillPatcher > FPr_c
Vector over levels of FillPatchers for scalars.
Definition REMORA.H:1509
void scale_rhs_vars_inv()
Scale RHS momentum variables by cell area, needed after FillPatch to different levels.
amrex::Vector< REMORAFillPatcher > FPr_w
Vector over levels of FillPatchers for w.
Definition REMORA.H:1515
amrex::Vector< amrex::Real > t_new
new time at each level
Definition REMORA.H:1556
static SolverChoice solverChoice
Container for algorithmic choices.
Definition REMORA.H:1717
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_vbar
barotropic y velocity (2D)
Definition REMORA.H:549
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ubar
barotropic x velocity (2D)
Definition REMORA.H:547
amrex::Vector< amrex::MultiFab * > cons_old
multilevel data container for last step's scalar data: temperature, salinity, passive tracer
Definition REMORA.H:377
amrex::Vector< REMORAFillPatcher > FPr_ubar
Vector over levels of FillPatchers for ubar (2D)
Definition REMORA.H:1519
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())
Fill a new MultiFab by copying in phi from valid region and filling ghost cells.
static int ndtfast
User specified, number of barotropic steps per baroclinic step.
Definition REMORA.H:1673
void timeStepML(amrex::Real time, int iteration)
advance all levels by dt, loops over finer levels
void setup_step(int lev, amrex::Real time, amrex::Real dt_lev)
Set everything up for a step on a level.
void WritePlotFile(int istep)
main driver for writing AMReX plotfiles
int cf_width
Nudging width at coarse-fine interface.
Definition REMORA.H:1504
amrex::Vector< amrex::Real > t_old
old time at each level
Definition REMORA.H:1558
amrex::Vector< amrex::Real > dt
time step at each level
Definition REMORA.H:1560
static constexpr int u
static constexpr int v
static constexpr int null
CouplingType coupling_type