REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_make_new_level.cpp
Go to the documentation of this file.
1/**
2 * \file REMORA_make_new_level.cpp
3 */
4
5#include <REMORA.H>
7
8#include <AMReX_buildInfo.H>
9
10using namespace amrex;
11
12/**
13 * Make a new level using provided BoxArray and DistributionMapping and
14 * fill with interpolated coarse level data (overrides the pure virtual function in AmrCore)
15 * regrid --> RemakeLevel (if level already existed)
16 * regrid --> MakeNewLevelFromCoarse (if adding new level)
17 *
18 * @param[in ] lev level to make
19 * @param[in ] time current time
20 * @param[in ] ba BoxArray for the level
21 * @param[in ] dm DistributionMapping for the level
22 */
23void
24REMORA::MakeNewLevelFromCoarse (int lev, Real time, const BoxArray& ba,
25 const DistributionMapping& dm)
26{
27 BoxList bl2d = ba.boxList();
28 for (auto& b : bl2d) {
29 b.setRange(2,0);
30 }
31 BoxArray ba2d(std::move(bl2d));
32
33 amrex::Print() << "Making level " << lev << " from coarse" << std::endl;
34 amrex::Print() << "GRIDS AT LEVEL " << lev << " ARE " << ba << std::endl;
35
36 cons_new[lev] = new MultiFab(ba, dm, NCONS, cons_new[lev-1]->nGrowVect());
37 cons_old[lev] = new MultiFab(ba, dm, NCONS, cons_new[lev-1]->nGrowVect());
38
39 xvel_new[lev] = new MultiFab(convert(ba, IntVect(1,0,0)), dm, 1, xvel_new[lev-1]->nGrowVect());
40 xvel_old[lev] = new MultiFab(convert(ba, IntVect(1,0,0)), dm, 1, xvel_new[lev-1]->nGrowVect());
41
42 yvel_new[lev] = new MultiFab(convert(ba, IntVect(0,1,0)), dm, 1, yvel_new[lev-1]->nGrowVect());
43 yvel_old[lev] = new MultiFab(convert(ba, IntVect(0,1,0)), dm, 1, yvel_new[lev-1]->nGrowVect());
44
45 zvel_new[lev] = new MultiFab(convert(ba, IntVect(0,0,1)), dm, 1, zvel_new[lev-1]->nGrowVect());
46 zvel_old[lev] = new MultiFab(convert(ba, IntVect(0,0,1)), dm, 1, zvel_new[lev-1]->nGrowVect());
47
48 resize_stuff(lev);
49
50 vec_Zt_avg1[lev].reset(new MultiFab(ba2d ,dm,1,IntVect(NGROW+1,NGROW+1,0))); //2d, average of the free surface (zeta)
51 vec_h[lev].reset(new MultiFab(ba2d ,dm,2,IntVect(NGROW+1,NGROW+1,0))); //2d, average of the free surface (zeta)
52 vec_ubar[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,3,IntVect(NGROW,NGROW,0)));
53 vec_vbar[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,3,IntVect(NGROW,NGROW,0)));
54
55 vec_ru[lev].reset(new MultiFab(convert(ba,IntVect(1,0,0)),dm,2,IntVect(NGROW,NGROW,0))); // RHS u (incl horizontal and vertical advection)
56 vec_rv[lev].reset(new MultiFab(convert(ba,IntVect(0,1,0)),dm,2,IntVect(NGROW,NGROW,0))); // RHS v
57
58 vec_ru2d[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,2,IntVect(NGROW,NGROW,0))); // RHS u for 2d
59 vec_rv2d[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,2,IntVect(NGROW,NGROW,0))); // RHS v for 2d
60
61 t_new[lev] = time;
62 t_old[lev] = time - 1.e200_rt;
63
64 init_masks(lev, ba, dm);
65
66 init_stuff(lev, ba, dm);
67
68 cons_new[lev]->setVal(0.0_rt);
69 xvel_new[lev]->setVal(0.0_rt);
70 yvel_new[lev]->setVal(0.0_rt);
71 zvel_new[lev]->setVal(0.0_rt);
72
73 cons_old[lev]->setVal(0.0_rt);
74 xvel_old[lev]->setVal(0.0_rt);
75 yvel_old[lev]->setVal(0.0_rt);
76 zvel_old[lev]->setVal(0.0_rt);
77
78 vec_ru[lev]->setVal(0.0_rt);
79 vec_rv[lev]->setVal(0.0_rt);
80
81 vec_ru2d[lev]->setVal(0.0_rt);
82 vec_rv2d[lev]->setVal(0.0_rt);
83
84 vec_ubar[lev]->setVal(0.0_rt);
85 vec_vbar[lev]->setVal(0.0_rt);
86
87
92
93 FillCoarsePatch(lev, time, vec_h[lev].get(), vec_h[lev-1].get(),
95 FillCoarsePatch(lev, time, vec_Zt_avg1[lev].get(), vec_Zt_avg1[lev-1].get(),BCVars::cons_bc);
96 for (int icomp=0; icomp<3; icomp++) {
97 FillCoarsePatch(lev, time, vec_ubar[lev].get(), vec_ubar[lev-1].get(),BCVars::ubar_bc,
98 BdyVars::ubar,icomp,false);
99 FillCoarsePatch(lev, time, vec_vbar[lev].get(), vec_vbar[lev-1].get(),BCVars::vbar_bc,
100 BdyVars::vbar,icomp,false);
101 }
102 for (int icomp=0; icomp<2; icomp++) {
103 FillCoarsePatch(lev, time, vec_ru[lev].get(), vec_ru[lev-1].get(),BCVars::xvel_bc,
104 BdyVars::null,icomp,false);
105 FillCoarsePatch(lev, time, vec_rv[lev].get(), vec_rv[lev-1].get(),BCVars::yvel_bc,
106 BdyVars::null,icomp,false);
107 FillCoarsePatch(lev, time, vec_ru2d[lev].get(), vec_ru2d[lev-1].get(),BCVars::xvel_bc,
108 BdyVars::null,icomp,false);
109 FillCoarsePatch(lev, time, vec_rv2d[lev].get(), vec_rv2d[lev-1].get(),BCVars::yvel_bc,
110 BdyVars::null,icomp,false);
111 }
112
113 // Not totally sure foextrap is right here
114 FillCoarsePatchPC(lev, time, vec_mskr[lev].get(), vec_mskr[lev-1].get(),
116
118
119
120 set_grid_scale(lev);
122
123 init_set_vmix(lev);
124 set_hmixcoef(lev);
125 set_coriolis(lev);
127 // Previously set smflux
128
129 // ********************************************************************************************
130 // If we are making a new level then the FillPatcher for this level hasn't been allocated yet
131 // ********************************************************************************************
132 if (cf_width >= 0) {
135 }
136
137#ifdef REMORA_USE_PARTICLES
138 // particleData.Redistribute();
139#endif
140}
141
142/**
143 * Remake an existing level using provided BoxArray and DistributionMapping and
144 * fill with existing fine and coarse data.
145 * overrides the pure virtual function in AmrCore
146 * @param[in ] lev level to make
147 * @param[in ] time current time
148 * @param[in ] ba BoxArray for the level
149 * @param[in ] dm DistributionMapping for the level
150 */
151void
152REMORA::RemakeLevel (int lev, Real time, const BoxArray& ba, const DistributionMapping& dm)
153{
154 BoxArray ba_old(cons_new[lev]->boxArray());
155 DistributionMapping dm_old(cons_new[lev]->DistributionMap());
156
157 BoxList bl2d = ba.boxList();
158 for (auto& b : bl2d) {
159 b.setRange(2,0);
160 }
161 BoxArray ba2d(std::move(bl2d));
162
163 amrex::Print() << "Remaking level " << lev << std::endl;
164 amrex::Print() << "GRIDS AT LEVEL " << lev << " ARE " << ba << std::endl;
165
166#if (NGROW==2)
167 int ngrow_state = ComputeGhostCells(solverChoice.spatial_order)+1;
168 int ngrow_vels = ComputeGhostCells(solverChoice.spatial_order)+1;
169 int ngrow_zeta = ComputeGhostCells(solverChoice.spatial_order)+1;
171 int ngrow_velbar = ComputeGhostCells(solverChoice.spatial_order);
172#else
173 int ngrow_state = ComputeGhostCells(solverChoice.spatial_order)+2;
174 int ngrow_vels = ComputeGhostCells(solverChoice.spatial_order)+2;
175 int ngrow_zeta = ComputeGhostCells(solverChoice.spatial_order)+2;
177 int ngrow_velbar = ComputeGhostCells(solverChoice.spatial_order)+1;
178#endif
179
180 MultiFab tmp_cons_new(ba, dm, NCONS, ngrow_state);
181 MultiFab tmp_cons_old(ba, dm, NCONS, ngrow_state);
182
183 MultiFab tmp_xvel_new(convert(ba, IntVect(1,0,0)), dm, 1, ngrow_vels);
184 MultiFab tmp_xvel_old(convert(ba, IntVect(1,0,0)), dm, 1, ngrow_vels);
185
186 MultiFab tmp_yvel_new(convert(ba, IntVect(0,1,0)), dm, 1, ngrow_vels);
187 MultiFab tmp_yvel_old(convert(ba, IntVect(0,1,0)), dm, 1, ngrow_vels);
188
189 MultiFab tmp_zvel_new(convert(ba, IntVect(0,0,1)), dm, 1, IntVect(ngrow_vels,ngrow_vels,0));
190 MultiFab tmp_zvel_old(convert(ba, IntVect(0,0,1)), dm, 1, IntVect(ngrow_vels,ngrow_vels,0));
191
192 MultiFab tmp_Zt_avg1_new(ba2d, dm, 1, IntVect(ngrow_zeta,ngrow_zeta,0));
193 MultiFab tmp_h(ba2d, dm, 2, IntVect(ngrow_h,ngrow_h,0));
194
195 MultiFab tmp_ubar_new(convert(ba2d, IntVect(1,0,0)), dm, 3, IntVect(ngrow_velbar,ngrow_velbar,0));
196
197 MultiFab tmp_vbar_new(convert(ba2d, IntVect(0,1,0)), dm, 3, IntVect(ngrow_velbar,ngrow_velbar,0));
198
199 MultiFab tmp_ru_new(convert(ba, IntVect(1,0,0)),dm,2,IntVect(NGROW,NGROW,0));
200 MultiFab tmp_rv_new(convert(ba, IntVect(0,1,0)),dm,2,IntVect(NGROW,NGROW,0));
201
202 MultiFab tmp_ru2d_new(convert(ba2d, IntVect(1,0,0)),dm,2,IntVect(NGROW,NGROW,0));
203 MultiFab tmp_rv2d_new(convert(ba2d, IntVect(0,1,0)),dm,2,IntVect(NGROW,NGROW,0));
204
205 init_masks(lev, ba, dm);
206
207 tmp_cons_new.setVal(0.0_rt);
208 tmp_xvel_new.setVal(0.0_rt);
209 tmp_yvel_new.setVal(0.0_rt);
210 tmp_zvel_new.setVal(0.0_rt);
211
212 tmp_cons_old.setVal(0.0_rt);
213 tmp_xvel_old.setVal(0.0_rt);
214 tmp_yvel_old.setVal(0.0_rt);
215 tmp_zvel_old.setVal(0.0_rt);
216
217 tmp_ru_new.setVal(0.0_rt);
218 tmp_rv_new.setVal(0.0_rt);
219
220 tmp_ru2d_new.setVal(0.0_rt);
221 tmp_rv2d_new.setVal(0.0_rt);
222
223 tmp_ubar_new.setVal(0.0_rt);
224 tmp_vbar_new.setVal(0.0_rt);
225
226
227 // This will fill the temporary MultiFabs with data from previous fine data as well as coarse where needed
228 FillPatch(lev, time, tmp_cons_new, cons_new, BCVars::cons_bc, BdyVars::t,0,true,false);
229 FillPatch(lev, time, tmp_xvel_new, xvel_new, BCVars::xvel_bc, BdyVars::u,0,true,false,0,0,0.0,tmp_xvel_new);
230 FillPatch(lev, time, tmp_yvel_new, yvel_new, BCVars::yvel_bc, BdyVars::v,0,true,false,0,0,0.0,tmp_yvel_new);
231 FillPatch(lev, time, tmp_zvel_new, zvel_new, BCVars::zvel_bc, BdyVars::null,0,true,false);
232
233 FillPatch(lev, time, tmp_h, GetVecOfPtrs(vec_h), BCVars::cons_bc, BdyVars::null,0,false,false);
234 FillPatch(lev, time, tmp_h, GetVecOfPtrs(vec_h), BCVars::cons_bc, BdyVars::null,1,false,false);
235 FillPatch(lev, time, tmp_Zt_avg1_new, GetVecOfPtrs(vec_Zt_avg1), BCVars::zeta_bc, BdyVars::null,0,true,false);
236 for (int icomp=0; icomp<3; icomp++) {
237 FillPatch(lev, time, tmp_ubar_new, GetVecOfPtrs(vec_ubar), BCVars::ubar_bc, BdyVars::ubar, icomp,false,false);
238 FillPatch(lev, time, tmp_vbar_new, GetVecOfPtrs(vec_vbar), BCVars::vbar_bc, BdyVars::vbar, icomp,false,false);
239 }
240 for (int icomp=0; icomp<2; icomp++) {
241 FillPatch(lev, time, tmp_ru_new, GetVecOfPtrs(vec_ru),BCVars::xvel_bc, BdyVars::null, icomp,false,false);
242 FillPatch(lev, time, tmp_rv_new, GetVecOfPtrs(vec_rv),BCVars::yvel_bc, BdyVars::null, icomp,false,false);
243 // These might want to have BCVars::ubar_bc and vbar_bc
244 FillPatch(lev, time, tmp_ru2d_new, GetVecOfPtrs(vec_ru2d),BCVars::xvel_bc, BdyVars::null, icomp,false,false);
245 FillPatch(lev, time, tmp_rv2d_new, GetVecOfPtrs(vec_rv2d),BCVars::yvel_bc, BdyVars::null, icomp,false,false);
246 }
247
248 MultiFab::Copy(tmp_cons_old,tmp_cons_new,0,0,NCONS,tmp_cons_new.nGrowVect());
249 MultiFab::Copy(tmp_xvel_old,tmp_xvel_new,0,0, 1,tmp_xvel_new.nGrowVect());
250 MultiFab::Copy(tmp_yvel_old,tmp_yvel_new,0,0, 1,tmp_yvel_new.nGrowVect());
251 MultiFab::Copy(tmp_zvel_old,tmp_zvel_new,0,0, 1,tmp_zvel_new.nGrowVect());
252
253 std::swap(tmp_cons_new, *cons_new[lev]);
254 std::swap(tmp_cons_old, *cons_old[lev]);
255 std::swap(tmp_xvel_new, *xvel_new[lev]);
256 std::swap(tmp_xvel_old, *xvel_old[lev]);
257 std::swap(tmp_yvel_new, *yvel_new[lev]);
258 std::swap(tmp_yvel_old, *yvel_old[lev]);
259 std::swap(tmp_zvel_new, *zvel_new[lev]);
260 std::swap(tmp_zvel_old, *zvel_old[lev]);
261 std::swap(tmp_Zt_avg1_new, *vec_Zt_avg1[lev]);
262 std::swap(tmp_h, *vec_h[lev]);
263 std::swap(tmp_ubar_new, *vec_ubar[lev]);
264 std::swap(tmp_vbar_new, *vec_vbar[lev]);
265 std::swap(tmp_ru_new, *vec_ru[lev]);
266 std::swap(tmp_rv_new, *vec_rv[lev]);
267 std::swap(tmp_ru2d_new, *vec_ru2d[lev]);
268 std::swap(tmp_rv2d_new, *vec_rv2d[lev]);
269
270 t_new[lev] = time;
271 t_old[lev] = time - 1.e200_rt;
272
273 init_masks(lev, ba, dm);
274 FillCoarsePatchPC(lev, time, vec_mskr[lev].get(), vec_mskr[lev-1].get(),
277
278 init_stuff(lev, ba, dm);
279
280 set_grid_scale(lev);
282
283 init_set_vmix(lev);
284 set_hmixcoef(lev);
285 set_coriolis(lev);
287 // Previously set smflux here
288
289 // We need to re-define the FillPatcher if the grids have changed
290 if (lev > 0 && cf_width >= 0) {
291 bool ba_changed = (ba != ba_old);
292 bool dm_changed = (dm != dm_old);
293 if (ba_changed || dm_changed) {
295 }
296 }
297
298#ifdef REMORA_USE_PARTICLES
299 particleData.Redistribute();
300#endif
301}
302
303/**
304 * Make a new level from scratch using provided BoxArray and DistributionMapping.
305 * This is called both for initialization and for restart
306 * (overrides the pure virtual function in AmrCore)
307 * main.cpp --> REMORA::InitData --> InitFromScratch --> MakeNewGrids --> MakeNewLevelFromScratch
308 * restart --> MakeNewGrids --> MakeNewLevelFromScratch
309 *
310 * @param[in ] lev level to make
311 * @param[in ] time current time
312 * @param[in ] ba BoxArray for the level
313 * @param[in ] dm DistributionMapping for the level
314 */
315void REMORA::MakeNewLevelFromScratch (int lev, Real time, const BoxArray& ba,
316 const DistributionMapping& dm)
317{
318 // Set BoxArray grids and DistributionMapping dmap in AMReX_AmrMesh.H class
319 SetBoxArray(lev, ba);
320 SetDistributionMap(lev, dm);
321
322 BoxList bl2d = ba.boxList();
323 for (auto& b : bl2d) {
324 b.setRange(2,0);
325 }
326 BoxArray ba2d(std::move(bl2d));
327
328 amrex::Print() << "Making level " << lev << " from scratch" << std::endl;
329 amrex::Print() << "GRIDS AT LEVEL " << lev << " ARE " << ba << std::endl;
330
331 // The number of ghost cells for density must be 1 greater than that for velocity
332 // so that we can go back in forth between velocity and momentum on all faces
333#if NGROW==2
334 int ngrow_state = ComputeGhostCells(solverChoice.spatial_order)+1;
335 int ngrow_vels = ComputeGhostCells(solverChoice.spatial_order)+1;
336#else
337 int ngrow_state = ComputeGhostCells(solverChoice.spatial_order)+2;
338 int ngrow_vels = ComputeGhostCells(solverChoice.spatial_order)+2;
339#endif
340
341 cons_old[lev] = new MultiFab(ba, dm, NCONS, ngrow_state);
342 cons_new[lev] = new MultiFab(ba, dm, NCONS, ngrow_state);
343
344 xvel_new[lev] = new MultiFab(convert(ba, IntVect(1,0,0)), dm, 1, ngrow_vels);
345 xvel_old[lev] = new MultiFab(convert(ba, IntVect(1,0,0)), dm, 1, ngrow_vels);
346
347 yvel_new[lev] = new MultiFab(convert(ba, IntVect(0,1,0)), dm, 1, ngrow_vels);
348 yvel_old[lev] = new MultiFab(convert(ba, IntVect(0,1,0)), dm, 1, ngrow_vels);
349
350 zvel_new[lev] = new MultiFab(convert(ba, IntVect(0,0,1)), dm, 1, IntVect(ngrow_vels,ngrow_vels,0));
351 zvel_old[lev] = new MultiFab(convert(ba, IntVect(0,0,1)), dm, 1, IntVect(ngrow_vels,ngrow_vels,0));
352
353 resize_stuff(lev);
354
355 vec_Zt_avg1[lev].reset(new MultiFab(ba2d ,dm,1,IntVect(NGROW+1,NGROW+1,0))); //2d, average of the free surface (zeta)
356 vec_h[lev].reset(new MultiFab(ba2d ,dm,2,IntVect(NGROW+1,NGROW+1,0))); //2d, bathymetry
357 vec_ubar[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,3,IntVect(NGROW,NGROW,0)));
358 vec_vbar[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,3,IntVect(NGROW,NGROW,0)));
359
360 vec_ru[lev].reset(new MultiFab(convert(ba,IntVect(1,0,0)),dm,2,IntVect(NGROW,NGROW,0))); // RHS u (incl horizontal and vertical advection)
361 vec_rv[lev].reset(new MultiFab(convert(ba,IntVect(0,1,0)),dm,2,IntVect(NGROW,NGROW,0))); // RHS v
362
363 vec_ru2d[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,2,IntVect(NGROW,NGROW,0))); // RHS u (incl horizontal and vertical advection)
364 vec_rv2d[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,2,IntVect(NGROW,NGROW,0))); // RHS v
365
366 init_masks(lev, ba, dm);
367 init_stuff(lev, ba, dm);
368
369 init_only(lev, time);
370
371#ifdef REMORA_USE_PARTICLES
372 if (restart_chkfile.empty()) {
373 if (lev == 0) {
374 initializeTracers((ParGDBBase*)GetParGDB(),vec_z_phys_nd);
375 } else {
376 particleData.Redistribute();
377 }
378 }
379#endif
380}
381
382/**
383 * @param[in ] lev level do operate on
384 */
386{
387 vec_z_phys_nd.resize(lev+1);
388
389 vec_h.resize(lev+1);
390 vec_Zt_avg1.resize(lev+1);
391 vec_z_w.resize(lev+1);
392 vec_z_r.resize(lev+1);
393 vec_Hz.resize(lev+1);
394 vec_Huon.resize(lev+1);
395 vec_Hvom.resize(lev+1);
396 vec_Akv.resize(lev+1);
397 vec_Akt.resize(lev+1);
398 vec_visc2_p.resize(lev+1);
399 vec_visc2_r.resize(lev+1);
400 vec_diff2.resize(lev+1);
401 vec_ru.resize(lev+1);
402 vec_rv.resize(lev+1);
403 vec_ru2d.resize(lev+1);
404 vec_rv2d.resize(lev+1);
405 vec_rufrc.resize(lev+1);
406 vec_rvfrc.resize(lev+1);
407 vec_sustr.resize(lev+1);
408 vec_svstr.resize(lev+1);
409 vec_btflx.resize(lev+1);
410 vec_stflx.resize(lev+1);
411 vec_btflux.resize(lev+1);
412 vec_stflux.resize(lev+1);
413 vec_lrflx.resize(lev+1);
414 vec_lhflx.resize(lev+1);
415 vec_shflx.resize(lev+1);
416 vec_rain.resize(lev+1);
417 vec_evap.resize(lev+1);
418 vec_rdrag.resize(lev+1);
419 vec_rdrag2.resize(lev+1);
420 vec_ZoBot.resize(lev+1);
421 vec_bustr.resize(lev+1);
422 vec_bvstr.resize(lev+1);
423 vec_uwind.resize(lev+1);
424 vec_vwind.resize(lev+1);
425 vec_alpha.resize(lev+1);
426 vec_beta.resize(lev+1);
427
428 vec_DU_avg1.resize(lev+1);
429 vec_DU_avg2.resize(lev+1);
430 vec_DV_avg1.resize(lev+1);
431 vec_DV_avg2.resize(lev+1);
432 vec_rubar.resize(lev+1);
433 vec_rvbar.resize(lev+1);
434 vec_rzeta.resize(lev+1);
435 vec_ubar.resize(lev+1);
436 vec_vbar.resize(lev+1);
437 vec_zeta.resize(lev+1);
438 vec_mskr.resize(lev+1);
439 vec_msku.resize(lev+1);
440 vec_mskv.resize(lev+1);
441 vec_mskp.resize(lev+1);
442 vec_mskr3d.resize(lev+1);
443 vec_sstore.resize(lev+1);
444
445 vec_pm.resize(lev+1);
446 vec_pn.resize(lev+1);
447 vec_fcor.resize(lev+1);
448
449 vec_xr.resize(lev+1);
450 vec_yr.resize(lev+1);
451 vec_xu.resize(lev+1);
452 vec_yu.resize(lev+1);
453 vec_xv.resize(lev+1);
454 vec_yv.resize(lev+1);
455 vec_xp.resize(lev+1);
456 vec_yp.resize(lev+1);
457
458 vec_rhoS.resize(lev+1);
459 vec_rhoA.resize(lev+1);
460 vec_bvf.resize(lev+1);
461
462 vec_tke.resize(lev+1);
463 vec_gls.resize(lev+1);
464 vec_Lscale.resize(lev+1);
465 vec_Akk.resize(lev+1);
466 vec_Akp.resize(lev+1);
467
468 vec_river_position.resize(lev+1);
469
470 if (lev==0) vec_nudg_coeff.resize(BdyVars::NumTypes);
471
472 vec_nudg_coeff[BdyVars::u].resize(lev+1);
473 vec_nudg_coeff[BdyVars::v].resize(lev+1);
474 vec_nudg_coeff[BdyVars::t].resize(lev+1);
475 vec_nudg_coeff[BdyVars::s].resize(lev+1);
476 vec_nudg_coeff[BdyVars::ubar].resize(lev+1);
477 vec_nudg_coeff[BdyVars::vbar].resize(lev+1);
478 vec_nudg_coeff[BdyVars::zeta].resize(lev+1);
479}
480
481/**
482 * @param[in ] lev level to operate on
483 * @param[in ] ba BoxArray for the level
484 * @param[in ] dm DistributionMapping for the level
485 */
486void REMORA::init_masks (int lev, const BoxArray& ba, const DistributionMapping& dm)
487{
488 BoxList bl2d = ba.boxList();
489 for (auto& b : bl2d) {
490 b.setRange(2,0);
491 }
492
493 BoxArray ba2d(std::move(bl2d));
494 vec_mskr[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW+1,NGROW+1,0)));
495 vec_msku[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,1,IntVect(NGROW+1,NGROW+1,0)));
496 vec_mskv[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,1,IntVect(NGROW+1,NGROW+1,0)));
497 vec_mskp[lev].reset(new MultiFab(convert(ba2d,IntVect(1,1,0)),dm,1,IntVect(NGROW+1,NGROW+1,0)));
498
499 vec_mskr3d[lev].reset(new MultiFab(ba,dm,1,IntVect(NGROW+1,NGROW+1,0)));
500
501 vec_mskr[lev]->setVal(1.0_rt);
502 vec_msku[lev]->setVal(1.0_rt);
503 vec_mskv[lev]->setVal(1.0_rt);
504 vec_mskp[lev]->setVal(1.0_rt);
505
506 vec_mskr3d[lev]->setVal(1.0_rt);
507}
508
509/**
510 * @param[in ] lev level to operate on
511 * @param[in ] ba BoxArray for the level
512 * @param[in ] dm DistributionMapping for the level
513 */
514void REMORA::init_stuff (int lev, const BoxArray& ba, const DistributionMapping& dm)
515{
516 // ********************************************************************************************
517 // Initialize the boundary conditions
518 // ********************************************************************************************
519 physbcs[lev] = std::make_unique<REMORAPhysBCFunct> (lev, geom[lev], domain_bcs_type, domain_bcs_type_d,
521
522 BoxList bl2d = ba.boxList();
523 for (auto& b : bl2d) {
524 b.setRange(2,0);
525 }
526 BoxArray ba2d(std::move(bl2d));
527
528 BoxList bl1d = ba.boxList();
529 for (auto& b : bl1d) {
530 b.setRange(0,0);
531 b.setRange(1,0);
532 }
533 BoxArray ba1d(std::move(bl1d));
534
535 BoxArray ba_nd(ba);
536 ba_nd.surroundingNodes();
537 BoxArray ba_w(ba);
538 ba_w.surroundingNodes(2);
539
540 vec_z_phys_nd[lev].reset (new MultiFab(ba_nd,dm,1,IntVect(NGROW,NGROW,1))); // z at psi points (nodes) MIGHT NEED NGROW+1
541 vec_z_w[lev].reset (new MultiFab(convert(ba,IntVect(0,0,1)),dm,1,IntVect(NGROW+1,NGROW+1,0))); // z at w points (cell faces)
542 vec_z_r[lev].reset (new MultiFab(ba,dm,1,IntVect(NGROW+1,NGROW+1,0))); // z at r points (cell center)
543 vec_Hz[lev].reset (new MultiFab(ba,dm,1,IntVect(NGROW+1,NGROW+1,NGROW+1))); // like in ROMS, thickness of cell in z
544
545 vec_Huon[lev].reset (new MultiFab(convert(ba,IntVect(1,0,0)),dm,1,IntVect(NGROW,NGROW,0))); // mass flux for u component
546 vec_Hvom[lev].reset (new MultiFab(convert(ba,IntVect(0,1,0)),dm,1,IntVect(NGROW,NGROW,0))); // mass flux for v component
547
548 vec_Akv[lev].reset (new MultiFab(convert(ba,IntVect(0,0,1)),dm,1,IntVect(NGROW,NGROW,0))); // vertical mixing coefficient (.in)
549 vec_Akt[lev].reset (new MultiFab(convert(ba,IntVect(0,0,1)),dm,NCONS,IntVect(NGROW,NGROW,0))); // vertical mixing coefficient (.in)
550
551 // check dimensionality
552 vec_visc2_p[lev].reset(new MultiFab(ba,dm,1,IntVect(NGROW,NGROW,0))); // harmonic viscosity at psi points -- difference to 3d?
553 vec_visc2_r[lev].reset(new MultiFab(ba,dm,1,IntVect(NGROW,NGROW,0))); // harmonic viscosity at rho points
554 vec_diff2[lev].reset(new MultiFab(ba,dm,NCONS,IntVect(NGROW,NGROW,0))); // harmonic diffusivity temperature/salt
555
556 //2d, (incl advection terms and surface/bottom stresses, integral over the whole column, k=0)
557 vec_rufrc[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,2,IntVect(NGROW,NGROW,0)));
558 vec_rvfrc[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,2,IntVect(NGROW,NGROW,0))); //2d, same as above but v
559
560 vec_sustr[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,1,IntVect(NGROW,NGROW,0))); //2d, surface stress
561 vec_svstr[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,1,IntVect(NGROW,NGROW,0))); //2d
562
564 //2d, linear drag coefficient [m/s], defined at rho, somehow related to rdrg
565 vec_rdrag[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
567 vec_rdrag2[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
568 }
569
572 vec_ZoBot[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
573 }
574
575 vec_bustr[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,1,IntVect(NGROW,NGROW,0))); //2d, bottom stress
576 vec_bvstr[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,1,IntVect(NGROW,NGROW,0)));
577
578 //all 2d -- all associated with the 2D advance
579 //2d DU: sum(height[incl free surface?] * u)
580 vec_DU_avg1[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,1,IntVect(NGROW,NGROW,0)));
581
582 //2d like above, but correct(or)?
583 vec_DU_avg2[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,1,IntVect(NGROW,NGROW,0)));
584
585 vec_DV_avg1[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,1,IntVect(NGROW,NGROW,0)));
586 vec_DV_avg2[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,1,IntVect(NGROW,NGROW,0)));
587
588 vec_rubar[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,4,IntVect(NGROW,NGROW,0))); // 2d RHS ubar
589 vec_rvbar[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,4,IntVect(NGROW,NGROW,0)));
590 vec_rzeta[lev].reset(new MultiFab(ba2d,dm,4,IntVect(NGROW,NGROW,0))); // 2d RHS zeta
591
592 // starts off kind of like a depth-averaged u, but exists at more points and more timesteps (b/c fast 2D update) than full u
593 vec_zeta[lev].reset(new MultiFab(ba2d,dm,3,IntVect(NGROW+1,NGROW+1,0))); // 2d free surface
594
595 vec_pm[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW+1,NGROW+2,0)));
596 vec_pn[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW+2,NGROW+1,0)));
597 vec_fcor[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW+1,NGROW+1,0)));
598
599 vec_xr[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW+1,NGROW+1,0)));
600 vec_yr[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW+1,NGROW+1,0)));
601
602 vec_xu[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,1,IntVect(NGROW,NGROW,0)));
603 vec_yu[lev].reset(new MultiFab(convert(ba2d,IntVect(1,0,0)),dm,1,IntVect(NGROW,NGROW,0)));
604 vec_xv[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,1,IntVect(NGROW,NGROW,0)));
605 vec_yv[lev].reset(new MultiFab(convert(ba2d,IntVect(0,1,0)),dm,1,IntVect(NGROW,NGROW,0)));
606 vec_xp[lev].reset(new MultiFab(convert(ba2d,IntVect(1,1,0)),dm,1,IntVect(NGROW,NGROW,0)));
607 vec_yp[lev].reset(new MultiFab(convert(ba2d,IntVect(1,1,0)),dm,1,IntVect(NGROW,NGROW,0)));
608
609
610 // tempstore, saltstore, etc
611 vec_sstore[lev].reset(new MultiFab(ba,dm,NCONS,IntVect(NGROW,NGROW,0)));
612
613 vec_rhoS[lev].reset(new MultiFab(ba,dm,1,IntVect(NGROW,NGROW,0)));
614 vec_rhoA[lev].reset(new MultiFab(ba,dm,1,IntVect(NGROW,NGROW,0)));
615 vec_bvf[lev].reset(new MultiFab(convert(ba,IntVect(0,0,1)),dm,1,IntVect(NGROW,NGROW,0)));
616
617 vec_tke[lev].reset(new MultiFab(convert(ba,IntVect(0,0,1)),dm,3,IntVect(NGROW,NGROW,0)));
618 vec_gls[lev].reset(new MultiFab(convert(ba,IntVect(0,0,1)),dm,3,IntVect(NGROW,NGROW,0)));
619 vec_Lscale[lev].reset(new MultiFab(convert(ba,IntVect(0,0,1)),dm,1,IntVect(NGROW,NGROW,0)));
620 vec_Akk[lev].reset(new MultiFab(convert(ba,IntVect(0,0,1)),dm,1,IntVect(NGROW,NGROW,0)));
621 vec_Akp[lev].reset(new MultiFab(convert(ba,IntVect(0,0,1)),dm,1,IntVect(NGROW,NGROW,0)));
622
623 // surface/bottom tracer fluxes for update
624 vec_stflx[lev].reset(new MultiFab(ba2d,dm,NCONS,IntVect(NGROW,NGROW,0)));
625 vec_btflx[lev].reset(new MultiFab(ba2d,dm,NCONS,IntVect(NGROW,NGROW,0)));
626 // surface/bottom tracer fluxes to be filled by inputs
627 vec_stflux[lev].reset(new MultiFab(ba2d,dm,NCONS,IntVect(NGROW,NGROW,0)));
628 vec_btflux[lev].reset(new MultiFab(ba2d,dm,NCONS,IntVect(NGROW,NGROW,0)));
629
631 vec_uwind[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0))); //2d, surface wind u
632 vec_vwind[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0))); //2d, surface wind v
633 vec_alpha[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
634 vec_beta[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
635 vec_lrflx[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
636 vec_lhflx[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
637 vec_shflx[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
638 vec_rain[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
639 vec_evap[lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
640 vec_lhflx[lev]->setVal(0.0_rt);
641 vec_shflx[lev]->setVal(0.0_rt);
642 vec_rain[lev]->setVal(solverChoice.rain);
643 }
644
646 vec_river_position[lev].reset(new iMultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
647 vec_river_position[lev]->setVal(-1);
648 }
649
650 vec_nudg_coeff[BdyVars::u][lev].reset(new MultiFab(ba,dm,1,IntVect(NGROW,NGROW,0)));
651 vec_nudg_coeff[BdyVars::v][lev].reset(new MultiFab(ba,dm,1,IntVect(NGROW,NGROW,0)));
652 vec_nudg_coeff[BdyVars::t][lev].reset(new MultiFab(ba,dm,1,IntVect(NGROW,NGROW,0)));
653 vec_nudg_coeff[BdyVars::s][lev].reset(new MultiFab(ba,dm,1,IntVect(NGROW,NGROW,0)));
654 vec_nudg_coeff[BdyVars::ubar][lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
655 vec_nudg_coeff[BdyVars::vbar][lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
656 vec_nudg_coeff[BdyVars::zeta][lev].reset(new MultiFab(ba2d,dm,1,IntVect(NGROW,NGROW,0)));
657
658 set_weights(lev);
659
660 vec_DU_avg1[lev]->setVal(0.0_rt);
661 vec_DU_avg2[lev]->setVal(0.0_rt);
662 vec_DV_avg1[lev]->setVal(0.0_rt);
663 vec_DV_avg2[lev]->setVal(0.0_rt);
664 vec_rubar[lev]->setVal(0.0_rt);
665 vec_rvbar[lev]->setVal(0.0_rt);
666 vec_rzeta[lev]->setVal(0.0_rt);
667
668 // Initialize these vars even if we aren't using GLS to
669 // avoid issues on e.g. checkpoint
670 vec_tke[lev]->setVal(solverChoice.gls_Kmin);
671 vec_gls[lev]->setVal(solverChoice.gls_Pmin);
672 vec_Lscale[lev]->setVal(0.0_rt);
673 vec_Akk[lev]->setVal(solverChoice.Akk_bak);
674 vec_Akp[lev]->setVal(solverChoice.Akp_bak);
675
676 vec_stflx[lev]->setVal(0.0_rt);
677 vec_btflx[lev]->setVal(0.0_rt);
678 vec_stflux[lev]->setVal(0.0_rt);
679 vec_btflux[lev]->setVal(0.0_rt);
680
681 // NOTE: Used to set vec_pm and vec_pn to 1e34 here to make foextrap work
682 // when init_type = real. However, this does not appear to be necessary so removing
683
684 // Set initial linear drag coefficient
686 vec_rdrag[lev]->setVal(solverChoice.rdrag);
688 vec_rdrag2[lev]->setVal(solverChoice.rdrag2);
689 }
690
693 vec_ZoBot[lev]->setVal(solverChoice.Zob);
694 }
695
696
697 // ********************************************************************************************
698 // Create the REMORAFillPatcher object
699 // ********************************************************************************************
700 if (lev > 0 && cf_width >= 0) {
703 }
704}
705
706/**
707 * Delete level data. Overrides the pure virtual function in AmrCore
708 *
709 * @param[in ] lev level to operate on
710 */
711void
713{
714 delete cons_new[lev]; delete xvel_new[lev]; delete yvel_new[lev]; delete zvel_new[lev];
715 delete cons_old[lev]; delete xvel_old[lev]; delete yvel_old[lev]; delete zvel_old[lev];
716}
717
718/**
719 * @param[in ] lev level to operate on
720 */
721void
723{
726 const auto dxi = Geom(lev).InvCellSize();
727 vec_pm[lev]->setVal(dxi[0]); vec_pm[lev]->FillBoundary(geom[lev].periodicity());
728 vec_pn[lev]->setVal(dxi[1]); vec_pn[lev]->FillBoundary(geom[lev].periodicity());
730 prob->init_analytic_grid_scale(lev, Geom(lev), solverChoice, *this, *vec_pm[lev].get(), *vec_pn[lev].get());
731 vec_pm[lev]->FillBoundary(geom[lev].periodicity());
732 vec_pn[lev]->FillBoundary(geom[lev].periodicity());
733 }
734 } else if (solverChoice.ic_type == IC_Type::netcdf && lev > 0) { // if lev==0, pm/pn are set by init_bathymetry
735 Real dummy_time = 0.0_rt;
736 FillCoarsePatch(lev,dummy_time,vec_pm[lev].get(), vec_pm[lev-1].get(), BCVars::foextrap_bc);
737 FillCoarsePatch(lev,dummy_time,vec_pn[lev].get(), vec_pn[lev-1].get(), BCVars::foextrap_bc);
738
739 int rrx = (lev == 1) ? ref_ratio[lev-1][0] : ref_ratio[lev-1][0] / ref_ratio[lev-2][0];
740 int rry = (lev == 1) ? ref_ratio[lev-1][1] : ref_ratio[lev-1][1] / ref_ratio[lev-2][1];
741 // pm and pn need to be rescaled by the refinement ratio
742 for ( MFIter mfi(*cons_new[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
743 {
744 Array4<Real> const& pm = vec_pm[lev]->array(mfi);
745 Array4<Real> const& pn = vec_pn[lev]->array(mfi);
746 Box ubx = mfi.growntilebox(IntVect(NGROW+1,NGROW+2,0));
747 Box vbx = mfi.growntilebox(IntVect(NGROW+2,NGROW+1,0));
748 ParallelFor(makeSlab(ubx,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int ) {
749 pm(i,j,0) = pm(i,j,0) * (rrx);
750 });
751 ParallelFor(makeSlab(vbx,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int ) {
752 pn(i,j,0) = pn(i,j,0) * (rry);
753 });
754 }
755 }
756
757 for ( MFIter mfi(*vec_xr[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
758 {
759 Array4<const Real> const& pm = vec_pm[lev]->const_array(mfi);
760 Array4<const Real> const& pn = vec_pn[lev]->const_array(mfi);
761 Array4<Real> const& xr = vec_xr[lev]->array(mfi);
762 Array4<Real> const& yr = vec_yr[lev]->array(mfi);
763 Array4<Real> const& xu = vec_xu[lev]->array(mfi);
764 Array4<Real> const& yu = vec_yu[lev]->array(mfi);
765 Array4<Real> const& xv = vec_xv[lev]->array(mfi);
766 Array4<Real> const& yv = vec_yv[lev]->array(mfi);
767 Array4<Real> const& xp = vec_xp[lev]->array(mfi);
768 Array4<Real> const& yp = vec_yp[lev]->array(mfi);
769
770 Box bx = mfi.growntilebox(IntVect(NGROW,NGROW,0));
771 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int)
772 {
773 xr(i,j,0) = (i + 0.5_rt) / pm(i,j,0);
774 yr(i,j,0) = (j + 0.5_rt) / pn(i,j,0);
775 });
776
777 ParallelFor(grow(convert(bx,IntVect(1,0,0)),IntVect(-1,0,0)), [=] AMREX_GPU_DEVICE (int i, int j, int)
778 {
779 xu(i,j,0) = i / pm(i,j,0);
780 yu(i,j,0) = (j + 0.5_rt) / pn(i,j,0);
781 });
782
783 ParallelFor(grow(convert(bx,IntVect(0,1,0)),IntVect(0,-1,0)), [=] AMREX_GPU_DEVICE (int i, int j, int)
784 {
785 xv(i,j,0) = (i + 0.5_rt) / pm(i,j,0);
786 yv(i,j,0) = j / pn(i,j,0);
787 });
788
789 ParallelFor(grow(convert(bx,IntVect(1,1,0)),IntVect(-1,-1,0)), [=] AMREX_GPU_DEVICE (int i, int j, int)
790 {
791 xp(i,j,0) = i / pm(i,j,0);
792 yp(i,j,0) = j / pn(i,j,0);
793 });
794 }
795}
796
797/**
798 * @param[in ] lev level to operate on
799 */
800void
802{
803 BL_PROFILE("REMORA::set_zeta_to_Ztavg()");
804 std::unique_ptr<MultiFab>& mf_zeta = vec_zeta[lev];
805 std::unique_ptr<MultiFab>& mf_Zt_avg1 = vec_Zt_avg1[lev];
807 for ( MFIter mfi(*vec_zeta[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
808 {
809 Array4<Real> const& Zt_avg1 = (mf_Zt_avg1)->array(mfi);
810 Array4<const Real> const& evap = vec_evap[lev]->const_array(mfi);
811 Array4<const Real> const& rain = vec_rain[lev]->const_array(mfi);
812
813 Box bx2 = mfi.growntilebox(IntVect(NGROW,NGROW,0));// bx2.grow(IntVect(NGROW,NGROW,0));
814
815 Real cff = dt[lev] / rhow;
816
817 ParallelFor(bx2, [=] AMREX_GPU_DEVICE (int i, int j, int )
818 {
819 Zt_avg1(i,j,0) = Zt_avg1(i,j,0) - (evap(i,j,0) - rain(i,j,0)) * cff;
820 });
821 }
822 }
823 Gpu::streamSynchronize();
824
825 vec_Zt_avg1[lev]->FillBoundary(geom[lev].periodicity());
826
827 for ( MFIter mfi(*vec_zeta[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
828 {
829 Box bx3 = mfi.tilebox(); bx3.grow(IntVect(NGROW+1,NGROW+1,0));
830 Array4<Real> const& zeta = mf_zeta->array(mfi);
831 Array4<Real> const& Zt_avg1 = (mf_Zt_avg1)->array(mfi);
832
833 ParallelFor(bx3, 3, [=] AMREX_GPU_DEVICE (int i, int j, int , int n)
834 {
835 zeta(i,j,0,n) = Zt_avg1(i,j,0);
836 });
837 }
838}
839
840/**
841 * @param[in ] lev level to operate on
842 */
843void
845{
846 for ( MFIter mfi(*vec_mskr[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
847 {
848 Array4<const Real> const& mskr = vec_mskr[lev]->const_array(mfi);
849 Array4< Real> const& mskp = vec_mskp[lev]->array(mfi);
850
851 Box bx = mfi.tilebox(); bx.grow(IntVect(1,1,0)); bx.makeSlab(2,0);
852
853 Real cff1 = 1.0_rt;
854 Real cff2 = 2.0_rt;
855
856 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int)
857 {
858 if ((mskr(i-1,j,0) > 0.5) and (mskr(i,j,0) > 0.5) and (mskr(i-1,j-1,0) > 0.5) and (mskr(i,j-1,0) > 0.5)) {
859 mskp(i,j,0) = 1.0_rt;
860 } else if ((mskr(i-1,j,0) < 0.5) and (mskr(i,j,0) > 0.5) and (mskr(i-1,j-1,0) > 0.5) and (mskr(i,j-1,0) > 0.5)) {
861 mskp(i,j,0) = cff1;
862 } else if ((mskr(i-1,j,0) > 0.5) and (mskr(i,j,0) < 0.5) and (mskr(i-1,j-1,0) > 0.5) and (mskr(i,j-1,0) > 0.5)) {
863 mskp(i,j,0) = cff1;
864 } else if ((mskr(i-1,j,0) > 0.5) and (mskr(i,j,0) > 0.5) and (mskr(i-1,j-1,0) < 0.5) and (mskr(i,j-1,0) > 0.5)) {
865 mskp(i,j,0) = cff1;
866 } else if ((mskr(i-1,j,0) > 0.5) and (mskr(i,j,0) > 0.5) and (mskr(i-1,j-1,0) > 0.5) and (mskr(i,j-1,0) < 0.5)) {
867 mskp(i,j,0) = cff1;
868 } else if ((mskr(i-1,j,0) > 0.5) and (mskr(i,j,0) < 0.5) and (mskr(i-1,j-1,0) > 0.5) and (mskr(i,j-1,0) < 0.5)) {
869 mskp(i,j,0) = cff2;
870 } else if ((mskr(i-1,j,0) < 0.5) and (mskr(i,j,0) > 0.5) and (mskr(i-1,j-1,0) < 0.5) and (mskr(i,j-1,0) > 0.5)) {
871 mskp(i,j,0) = cff2;
872 } else if ((mskr(i-1,j,0) > 0.5) and (mskr(i,j,0) > 0.5) and (mskr(i-1,j-1,0) < 0.5) and (mskr(i,j-1,0) < 0.5)) {
873 mskp(i,j,0) = cff2;
874 } else if ((mskr(i-1,j,0) < 0.5) and (mskr(i,j,0) < 0.5) and (mskr(i-1,j-1,0) > 0.5) and (mskr(i,j-1,0) > 0.5)) {
875 mskp(i,j,0) = cff2;
876 } else {
877 mskp(i,j,0) = 0.0_rt;
878 }
879
880 });
881 }
882}
883
884/**
885 * @param[in ] lev level to operate on
886 */
887void
889{
890 for ( MFIter mfi(*vec_mskr[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
891 {
892 Array4<const Real> const& mskr = vec_mskr[lev]->const_array(mfi);
893 Array4< Real> const& msku = vec_msku[lev]->array(mfi);
894 Array4< Real> const& mskv = vec_mskv[lev]->array(mfi);
895 Array4< Real> const& mskp = vec_mskp[lev]->array(mfi);
896
897 Box bx = mfi.tilebox(); bx.grow(IntVect(1,1,0)); bx.makeSlab(2,0);
898
899 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int)
900 {
901 msku(i,j,0) = mskr(i-1,j ,0) * mskr(i,j,0);
902 mskv(i,j,0) = mskr(i ,j-1,0) * mskr(i,j,0);
903 mskp(i,j,0) = mskr(i-1,j-1,0) * mskr(i,j,0) * mskr(i-1,j,0) * mskr(i,j-1,0);
904 });
905 }
906}
907
908/**
909 * @param[in ] lev level to operate on
910 */
911void
913{
914 for ( MFIter mfi(*vec_mskr3d[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
915 {
916 Array4<const Real> const& mskr = vec_mskr[lev]->const_array(mfi);
917 Array4< Real> const& mskr3d = vec_mskr3d[lev]->array(mfi);
918
919 Box bx = mfi.tilebox(); bx.grow(IntVect(1,1,0)); bx.makeSlab(2,0);
920
921 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
922 {
923 mskr3d(i,j,k) = mskr(i,j,0);
924 });
925 }
926}
constexpr amrex::Real rhow
#define NGROW
#define NCONS
void FillCoarsePatchPC(int lev, amrex::Real time, amrex::MultiFab *mf_fine, amrex::MultiFab *mf_crse, const int bccomp, const int bdy_var_type=BdyVars::null, const int icomp=0, const bool fill_all=true, const int n_not_fill=0, const int icomp_calc=0, const amrex::Real dt=amrex::Real(0.0), const amrex::MultiFab &mf_calc=amrex::MultiFab())
fill an entire multifab by interpolating from the coarser level using the piecewise constant interpol...
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rv2d
v velocity RHS (2D, includes horizontal and vertical advection)
Definition REMORA.H:268
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_evap
evaporation rate [kg/m^2/s]
Definition REMORA.H:339
amrex::Vector< amrex::BCRec > domain_bcs_type
vector (over BCVars) of BCRecs
Definition REMORA.H:1196
void calculate_nodal_masks(int lev)
Calculate u-, v-, and psi-point masks based on rho-point masks after analytic initialization.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_fcor
coriolis factor (2D)
Definition REMORA.H:391
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_btflux
Bottom tracer flux; input arrays.
Definition REMORA.H:334
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rubar
barotropic x velocity for the RHS (2D)
Definition REMORA.H:362
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_h
Bathymetry data (2D, positive valued, h in ROMS)
Definition REMORA.H:253
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pm
horizontal scaling factor: 1 / dx (2D)
Definition REMORA.H:386
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ZoBot
Bottom roughness length [m], defined at rho points.
Definition REMORA.H:346
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_DU_avg2
correct time average of barotropic x velocity flux for coupling (2D)
Definition REMORA.H:356
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_lrflx
longwave radiation
Definition REMORA.H:321
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_yv
y_grid on v-points (2D)
Definition REMORA.H:406
amrex::Vector< amrex::MultiFab * > cons_new
multilevel data container for current step's scalar data: temperature, salinity, passive scalar
Definition REMORA.H:241
virtual void MakeNewLevelFromCoarse(int lev, amrex::Real time, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm) override
Make a new level using provided BoxArray and DistributionMapping and fill with interpolated coarse le...
void FillCoarsePatch(int lev, amrex::Real time, amrex::MultiFab *mf_fine, amrex::MultiFab *mf_crse, const int bccomp, const int bdy_var_type=BdyVars::null, const int icomp=0, const bool fill_all=true, const int n_not_fill=0, const int icomp_calc=0, const amrex::Real dt=amrex::Real(0.0), const amrex::MultiFab &mf_calc=amrex::MultiFab())
fill an entire multifab by interpolating from the coarser level
void stretch_transform(int lev)
Calculate vertical stretched coordinates.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_vwind
Wind in the v direction, defined at rho-points.
Definition REMORA.H:318
std::unique_ptr< ProblemBase > prob
Pointer to container of analytical functions for problem definition.
Definition REMORA.H:1160
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskr
land/sea mask at cell centers (2D)
Definition REMORA.H:375
void Construct_REMORAFillPatchers(int lev)
Construct FillPatchers.
Definition REMORA.cpp:376
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rain
precipitation rate [kg/m^2/s]
Definition REMORA.H:337
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_tke
Turbulent kinetic energy.
Definition REMORA.H:434
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_stflx
Surface tracer flux; working arrays.
Definition REMORA.H:328
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_gls
Turbulent generic length scale.
Definition REMORA.H:436
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_sustr
Surface stress in the u direction.
Definition REMORA.H:311
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_yp
y_grid on psi-points (2D)
Definition REMORA.H:411
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_xr
x_grid on rho points (2D)
Definition REMORA.H:394
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ru2d
u velocity RHS (2D, includes horizontal and vertical advection)
Definition REMORA.H:266
virtual void ClearLevel(int lev) override
Delete level data Overrides the pure virtual function in AmrCore.
amrex::Vector< amrex::MultiFab * > zvel_new
multilevel data container for current step's z velocities (largely unused; W stored separately)
Definition REMORA.H:247
AMREX_FORCE_INLINE int ComputeGhostCells(const int &spatial_order)
Helper function to determine number of ghost cells.
Definition REMORA.H:1396
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_sstore
additional scratch space for calculations on temp, salt, etc
Definition REMORA.H:414
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_xv
x_grid on v-points (2D)
Definition REMORA.H:404
void init_only(int lev, amrex::Real time)
Init (NOT restart or regrid)
Definition REMORA.cpp:763
void init_set_vmix(int lev)
Initialize vertical mixing coefficients from file or analytic.
Definition REMORA.cpp:631
void set_grid_scale(int lev)
Set pm and pn arrays on level lev. Only works if using analytic initialization.
void set_coriolis(int lev)
Initialize Coriolis factor from file or analytic.
Definition REMORA.cpp:602
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Lscale
Vertical mixing turbulent length scale.
Definition REMORA.H:438
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Hz
Width of cells in the vertical (z-) direction (3D, Hz in ROMS)
Definition REMORA.H:256
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akt
Vertical diffusion coefficient (3D)
Definition REMORA.H:276
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_msku
land/sea mask at x-faces (2D)
Definition REMORA.H:377
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rvfrc
v velocity RHS, integrated, including advection and bottom/surface stresses (2D)
Definition REMORA.H:272
amrex::Vector< amrex::MultiFab * > xvel_old
multilevel data container for last step's x velocities (u in ROMS)
Definition REMORA.H:234
amrex::Vector< amrex::MultiFab * > yvel_new
multilevel data container for current step's y velocities (v in ROMS)
Definition REMORA.H:245
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_uwind
Wind in the u direction, defined at rho-points.
Definition REMORA.H:316
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rufrc
u velocity RHS, integrated, including advection and bottom/surface stresses (2D)
Definition REMORA.H:270
void Define_REMORAFillPatchers(int lev)
Define FillPatchers.
Definition REMORA.cpp:425
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_shflx
sensible heat flux
Definition REMORA.H:325
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:278
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rvbar
barotropic y velocity for the RHS (2D)
Definition REMORA.H:364
amrex::Vector< amrex::MultiFab * > zvel_old
multilevel data container for last step's z velocities (largely unused; W stored separately)
Definition REMORA.H:238
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_z_r
z coordinates at rho points (cell centers)
Definition REMORA.H:285
amrex::Vector< amrex::MultiFab * > xvel_new
multilevel data container for current step's x velocities (u in ROMS)
Definition REMORA.H:243
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_lhflx
latent heat flux
Definition REMORA.H:323
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskp
land/sea mask at cell corners (2D)
Definition REMORA.H:381
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_bvf
Brunt-Vaisala frequency (3D)
Definition REMORA.H:421
virtual void RemakeLevel(int lev, amrex::Real time, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm) override
Remake an existing level using provided BoxArray and DistributionMapping and fill with existing fine ...
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskv
land/sea mask at y-faces (2D)
Definition REMORA.H:379
void init_masks(int lev, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm)
Allocate MultiFabs for masks.
amrex::Vector< std::unique_ptr< REMORAPhysBCFunct > > physbcs
Vector (over level) of functors to apply physical boundary conditions.
Definition REMORA.H:1184
void fill_3d_masks(int lev)
Copy maskr to all z levels.
void FillPatch(int lev, amrex::Real time, amrex::MultiFab &mf_to_be_filled, amrex::Vector< amrex::MultiFab * > const &mfs, const int bccomp, const int bdy_var_type=BdyVars::null, const int icomp=0, const bool fill_all=true, const bool fill_set=true, const int n_not_fill=0, const int icomp_calc=0, const amrex::Real dt=amrex::Real(0.0), const amrex::MultiFab &mf_calc=amrex::MultiFab())
Fill a new MultiFab by copying in phi from valid region and filling ghost cells.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rhoS
density perturbation
Definition REMORA.H:417
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_visc2_r
Harmonic viscosity defined on the rho points (centers)
Definition REMORA.H:280
void update_mskp(int lev)
Set psi-point mask to be consistent with rho-point mask.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_svstr
Surface stress in the v direction.
Definition REMORA.H:313
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Huon
u-volume flux (3D)
Definition REMORA.H:258
amrex::Vector< amrex::MultiFab * > yvel_old
multilevel data container for last step's y velocities (v in ROMS)
Definition REMORA.H:236
void init_stuff(int lev, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm)
Allocate MultiFabs for state and evolution variables.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rhoA
vertically-averaged density
Definition REMORA.H:419
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_DV_avg1
time average of barotropic y velocity flux
Definition REMORA.H:358
amrex::Vector< amrex::Real > t_new
new time at each level
Definition REMORA.H:1174
static SolverChoice solverChoice
Container for algorithmic choices.
Definition REMORA.H:1299
void resize_stuff(int lev)
Resize variable containers to accommodate data on levels 0 to max_lev.
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > vec_river_position
iMultiFab for river positions; contents are indices of rivers
Definition REMORA.H:1112
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akk
Turbulent kinetic energy vertical diffusion coefficient.
Definition REMORA.H:440
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rdrag2
Quadratic drag coefficient [unitless], defined at rho points.
Definition REMORA.H:344
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ru
u velocity RHS (3D, includes horizontal and vertical advection)
Definition REMORA.H:262
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_xp
x_grid on psi-points (2D)
Definition REMORA.H:409
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_zeta
free surface height (2D)
Definition REMORA.H:372
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_vbar
barotropic y velocity (2D)
Definition REMORA.H:370
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_DU_avg1
time average of barotropic x velocity flux (2D)
Definition REMORA.H:354
void set_zeta_to_Ztavg(int lev)
Set zeta components to be equal to time-averaged Zt_avg1.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_alpha
Thermal expansion coefficient (3D)
Definition REMORA.H:423
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NCONS+8 > m_bc_extdir_vals
Array holding the Dirichlet values at walls which need them.
Definition REMORA.H:1204
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ubar
barotropic x velocity (2D)
Definition REMORA.H:368
amrex::Vector< amrex::MultiFab * > cons_old
multilevel data container for last step's scalar data: temperature, salinity, passive scalar
Definition REMORA.H:232
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_bustr
Bottom stress in the u direction.
Definition REMORA.H:349
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_DV_avg2
correct time average of barotropic y velocity flux for coupling (2D)
Definition REMORA.H:360
void set_hmixcoef(int lev)
Initialize horizontal mixing coefficients.
Definition REMORA.cpp:662
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_yu
y_grid on u-points (2D)
Definition REMORA.H:401
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_bvstr
Bottom stress in the v direction.
Definition REMORA.H:351
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rzeta
free surface height for the RHS (2D)
Definition REMORA.H:366
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_z_phys_nd
z coordinates at psi points (cell nodes)
Definition REMORA.H:305
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_xu
x_grid on u-points (2D)
Definition REMORA.H:399
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > vec_nudg_coeff
Climatology nudging coefficients.
Definition REMORA.H:445
void set_weights(int lev)
Set weights for averaging 3D variables to 2D.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pn
horizontal scaling factor: 1 / dy (2D)
Definition REMORA.H:388
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akv
Vertical viscosity coefficient (3D)
Definition REMORA.H:274
virtual void MakeNewLevelFromScratch(int lev, amrex::Real time, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm) override
Make a new level from scratch using provided BoxArray and DistributionMapping. Only used during initi...
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_stflux
Surface tracer flux; input arrays.
Definition REMORA.H:330
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rdrag
Linear drag coefficient [m/s], defined at rho points.
Definition REMORA.H:342
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Zt_avg1
Average of the free surface, zeta (2D)
Definition REMORA.H:308
std::string restart_chkfile
If set, restart from this checkpoint file.
Definition REMORA.H:1242
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rv
v velocity RHS (3D, includes horizontal and vertical advection)
Definition REMORA.H:264
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_btflx
Bottom tracer flux; working arrays.
Definition REMORA.H:332
int cf_width
Nudging width at coarse-fine interface.
Definition REMORA.H:1122
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_beta
Saline contraction coefficient (3D)
Definition REMORA.H:425
amrex::Vector< amrex::Real > t_old
old time at each level
Definition REMORA.H:1176
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskr3d
land/sea mask at cell centers, copied to all z levels (3D)
Definition REMORA.H:383
amrex::Vector< amrex::Real > dt
time step at each level
Definition REMORA.H:1178
amrex::Gpu::DeviceVector< amrex::BCRec > domain_bcs_type_d
GPU vector (over BCVars) of BCRecs.
Definition REMORA.H:1198
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_z_w
z coordinates at w points (faces between z-cells)
Definition REMORA.H:288
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_yr
y_grid on rho points (2D)
Definition REMORA.H:396
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Hvom
v-volume flux (3D)
Definition REMORA.H:260
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akp
Turbulent length scale vertical diffusion coefficient.
Definition REMORA.H:442
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_diff2
Harmonic diffusivity for temperature / salinity.
Definition REMORA.H:282
amrex::Real rdrag2
amrex::Real Akk_bak
BottomStressType bottom_stress_type
amrex::Real gls_Kmin
amrex::Real rdrag
VertMixingType vert_mixing_type
GridScaleType grid_scale_type
amrex::Real gls_Pmin
amrex::Real Akp_bak