REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_scale_rhs_vars.cpp
Go to the documentation of this file.
1#include <REMORA.H>
2
3using namespace amrex;
4
5/**
6 * Scale one level's RHS momentum terms by 1/cell area.
7 *
8 * @param[in] lev level of refinement
9 */
10void
12{
13 // Per level, not over all levels: /cff then *cff is not an identity in floating point,
14 // so scaling every level on every level's step perturbs untouched ones.
15 MultiFab& mf_cons = *cons_new[lev];
16#ifdef _OPENMP
17#pragma omp parallel if (Gpu::notInLaunchRegion())
18#endif
19 for ( MFIter mfi(mf_cons, TilingIfNotGPU()); mfi.isValid(); ++mfi )
20 {
21 Array4<Real const> const& pm = vec_pm[lev]->array(mfi);
22 Array4<Real const> const& pn = vec_pn[lev]->array(mfi);
23 Array4<Real > const& ru = vec_ru[lev]->array(mfi);
24 Array4<Real > const& rv = vec_rv[lev]->array(mfi);
25 Array4<Real > const& ru2d = vec_ru2d[lev]->array(mfi);
26 Array4<Real > const& rv2d = vec_rv2d[lev]->array(mfi);
27
28 Box ubx = mfi.grownnodaltilebox(0,IntVect(NGROW,NGROW,0));
29 Box vbx = mfi.grownnodaltilebox(1,IntVect(NGROW,NGROW,0));
30 Box ubx2d = ubx; ubx2d.makeSlab(2,0);
31 Box vbx2d = vbx; vbx2d.makeSlab(2,0);
32
33 ParallelFor(ubx, 2, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
34 {
35 Real cff = (pm(i,j,0)+pm(i-1,j,0)) * (pn(i,j,0)+pn(i-1,j,0));
36 ru(i,j,k,n) = ru(i,j,k,n) / cff;
37 });
38
39 ParallelFor(vbx, 2, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
40 {
41 Real cff = (pm(i,j,0)+pm(i,j-1,0)) * (pn(i,j,0)+pn(i,j-1,0));
42 rv(i,j,k,n) = rv(i,j,k,n) / cff;
43 });
44
45 ParallelFor(ubx2d, 2, [=] AMREX_GPU_DEVICE (int i, int j, int , int n)
46 {
47 Real cff = (pm(i,j,0)+pm(i-1,j,0)) * (pn(i,j,0)+pn(i-1,j,0));
48 ru2d(i,j,0,n) = ru2d(i,j,0,n) / cff;
49 });
50
51 ParallelFor(vbx2d, 2, [=] AMREX_GPU_DEVICE (int i, int j, int , int n)
52 {
53 Real cff = (pm(i,j,0)+pm(i,j-1,0)) * (pn(i,j,0)+pn(i,j-1,0));
54 rv2d(i,j,0,n) = rv2d(i,j,0,n) / cff;
55 });
56 }
57}
58
59/**
60 * Undo scale_rhs_vars on one level.
61 *
62 * @param[in] lev level of refinement
63 */
64void
66{
67 MultiFab& mf_cons = *cons_new[lev];
68#ifdef _OPENMP
69#pragma omp parallel if (Gpu::notInLaunchRegion())
70#endif
71 for ( MFIter mfi(mf_cons, TilingIfNotGPU()); mfi.isValid(); ++mfi )
72 {
73 Array4<Real const> const& pm = vec_pm[lev]->array(mfi);
74 Array4<Real const> const& pn = vec_pn[lev]->array(mfi);
75 Array4<Real > const& ru = vec_ru[lev]->array(mfi);
76 Array4<Real > const& rv = vec_rv[lev]->array(mfi);
77 Array4<Real > const& ru2d = vec_ru2d[lev]->array(mfi);
78 Array4<Real > const& rv2d = vec_rv2d[lev]->array(mfi);
79
80 Box ubx = mfi.grownnodaltilebox(0,IntVect(NGROW,NGROW,0));
81 Box vbx = mfi.grownnodaltilebox(1,IntVect(NGROW,NGROW,0));
82 Box ubx2d = ubx; ubx2d.makeSlab(2,0);
83 Box vbx2d = vbx; vbx2d.makeSlab(2,0);
84
85 ParallelFor(ubx, 2, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
86 {
87 Real cff = (pm(i,j,0)+pm(i-1,j,0)) * (pn(i,j,0)+pn(i-1,j,0));
88 ru(i,j,k,n) = ru(i,j,k,n) * cff;
89 });
90
91 ParallelFor(vbx, 2, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
92 {
93 Real cff = (pm(i,j,0)+pm(i,j-1,0)) * (pn(i,j,0)+pn(i,j-1,0));
94 rv(i,j,k,n) = rv(i,j,k,n) * cff;
95 });
96
97 ParallelFor(ubx2d, 2, [=] AMREX_GPU_DEVICE (int i, int j, int , int n)
98 {
99 Real cff = (pm(i,j,0)+pm(i-1,j,0)) * (pn(i,j,0)+pn(i-1,j,0));
100 ru2d(i,j,0,n) = ru2d(i,j,0,n) * cff;
101 });
102
103 ParallelFor(vbx2d, 2, [=] AMREX_GPU_DEVICE (int i, int j, int , int n)
104 {
105 Real cff = (pm(i,j,0)+pm(i,j-1,0)) * (pn(i,j,0)+pn(i,j-1,0));
106 rv2d(i,j,0,n) = rv2d(i,j,0,n) * cff;
107 });
108 }
109}
#define NGROW
mf_h setVal(geomdata.ProbHi(2))
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rv2d
v velocity RHS (2D, includes horizontal and vertical advection)
Definition REMORA.H:436
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pm
horizontal scaling factor: 1 / dx (2D)
Definition REMORA.H:603
amrex::Vector< amrex::MultiFab * > cons_new
multilevel data container for current step's scalar data: temperature, salinity, passive tracer
Definition REMORA.H:393
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ru2d
u velocity RHS (2D, includes horizontal and vertical advection)
Definition REMORA.H:434
void scale_rhs_vars_inv(int lev)
Scale RHS momentum variables by cell area, needed after FillPatch to different levels.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ru
u velocity RHS (3D, includes horizontal and vertical advection)
Definition REMORA.H:430
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pn
horizontal scaling factor: 1 / dy (2D)
Definition REMORA.H:605
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_rv
v velocity RHS (3D, includes horizontal and vertical advection)
Definition REMORA.H:432
void scale_rhs_vars(int lev)
Scale RHS momentum variables by 1/cell area, needed before FillPatch to different levels.