REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_update_massflux_3d.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 (coarsest level is 0)
7 * @param[in ] bx box on which to update
8 * @param[in ] ioff offset in x-direction
9 * @param[in ] joff offset in y-direction
10 * @param[inout] phi u or v
11 * @param[inout] phibar ubar or vbar
12 * @param[inout] Hphi phi-volume flux
13 * @param[in ] Hz vertical cell height
14 * @param[in ] pm_or_pn pm or pn
15 * @param[in ] Dphi_avg1 DU_avg1 or DV_avg1
16 * @param[in ] Dphi_avg2 DU_avg2 or DV_avg2
17 * @param DC temporary
18 * @param FC temporary
19 * @param[in ] msk land-sea mask
20 * @param[in ] nnew component of velocity
21 */
22void
23REMORA::update_massflux_3d (int lev, const Box& bx,
24 const int ioff, const int joff,
25 const Array4<Real >& phi,
26 const Array4<Real >& phibar,
27 const Array4<Real >& Hphi,
28 const Array4<Real const>& Hz,
29 const Array4<Real const>& pm_or_pn,
30 const Array4<Real const>& Dphi_avg1,
31 const Array4<Real const>& Dphi_avg2,
32 const Array4<Real >& DC,
33 const Array4<Real >& FC,
34 const Array4<Real const>& msk,
35 const int nnew)
36{
37 BL_PROFILE("REMORA::update_massflux_3d()");
38 const Box& domain = geom[lev].Domain();
39 const auto dlo = amrex::lbound(domain);
40 const auto dhi = amrex::ubound(domain);
41
42 GeometryData const& geomdata = geom[0].data();
43 bool is_periodic_in_x = geomdata.isPeriodic(0);
44 bool is_periodic_in_y = geomdata.isPeriodic(1);
45
46 int ncomp = 1;
47 Vector<BCRec> bcrs_x(ncomp);
48 Vector<BCRec> bcrs_y(ncomp);
49 amrex::setBC(bx,domain,BCVars::xvel_bc,0,1,domain_bcs_type,bcrs_x);
50 amrex::setBC(bx,domain,BCVars::yvel_bc,0,1,domain_bcs_type,bcrs_y);
51
52 auto N = Geom(0).Domain().size()[2]-1; // Number of vertical "levs" aka, NZ
53
54 auto bxD=bx;
55 auto bx_g1z=bx;
56 bxD.makeSlab(2,0);
57 bx_g1z.grow(IntVect(0,0,1));
58
59 FArrayBox fab_CF(bxD,1,amrex::The_Async_Arena()); fab_CF.template setVal<RunOn::Device>(0.);
60 auto CF=fab_CF.array();
61
62 //Copied depth of water column calculation from DepthStretchTransform
63 //Compute thicknesses of U-boxes DC(i,j,0:N-1), total depth of the water column DC(i,j,-1)
64
65 //This takes advantage of Hz being an extra grow cell size
66 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
67 {
68 Real om_v_or_on_u = 2.0_rt / (pm_or_pn(i,j,0) + pm_or_pn(i-ioff,j-joff,0));
69
70 DC(i,j,k) = 0.5_rt * om_v_or_on_u * (Hz(i,j,k)+Hz(i-ioff,j-joff,k));
71 });
72
73 ParallelFor(bxD, [=] AMREX_GPU_DEVICE (int i, int j, int )
74 {
75 for (int k=0; k<=N; k++) {
76 DC(i,j,-1) += DC(i,j,k);
77 CF(i,j,0) += DC(i,j,k) * phi(i,j,k,nnew);
78 }
79
80 DC(i,j,-1) = 1.0_rt / DC(i,j,-1);
81 CF(i,j,0) = DC(i,j,-1) * (CF(i,j,0) - Dphi_avg1(i,j,0));
82
83 for (int k=0; k<=N; k++) {
84 if (i == dlo.x-joff && !is_periodic_in_x) {
85 phi(i,j,k,nnew) -= CF(i,j,0);
86 phi(i,j,k,nnew) *= msk(i,j,0);
87 } else if (i == dhi.x+1 && !is_periodic_in_x) {
88 phi(i,j,k,nnew) -= CF(i,j,0);
89 phi(i,j,k,nnew) *= msk(i,j,0);
90 } else if (j == dlo.y-ioff && !is_periodic_in_y) {
91 phi(i,j,k,nnew) -= CF(i,j,0);
92 phi(i,j,k,nnew) *= msk(i,j,0);
93 } else if (j == dhi.y+1 && !is_periodic_in_y) {
94 phi(i,j,k,nnew) -= CF(i,j,0);
95 phi(i,j,k,nnew) *= msk(i,j,0);
96 }
97 }
98
99 for (int k=0; k<=N; k++) {
100 Hphi(i,j,k) = 0.5_rt * (Hphi(i,j,k)+phi(i,j,k,nnew)*DC(i,j,k));
101 FC(i,j,0) += Hphi(i,j,k);
102 } // k
103
104 FC(i,j,0) = DC(i,j,-1)*(FC(i,j,0)-Dphi_avg2(i,j,0));
105 });
106
107 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
108 {
109 Hphi(i,j,k) -= DC(i,j,k)*FC(i,j,0);
110 });
111
112 ParallelFor(bxD, [=] AMREX_GPU_DEVICE(int i, int j, int )
113 {
114 phibar(i,j,0,0) = DC(i,j,-1) * Dphi_avg1(i,j,0);
115 phibar(i,j,0,1) = phibar(i,j,0,0);
116 });
117
118}
void update_massflux_3d(int lev, const amrex::Box &bx, const int ioff, const int joff, const amrex::Array4< amrex::Real > &phi, const amrex::Array4< amrex::Real > &phibar, const amrex::Array4< amrex::Real > &Hphi, const amrex::Array4< amrex::Real const > &Hz, const amrex::Array4< amrex::Real const > &pm_or_pn, const amrex::Array4< amrex::Real const > &Dphi1, const amrex::Array4< amrex::Real const > &Dphi2, const amrex::Array4< amrex::Real > &DC, const amrex::Array4< amrex::Real > &FC, const amrex::Array4< amrex::Real const > &msk, const int nnew)
Correct mass flux.
amrex::Vector< amrex::BCRec > domain_bcs_type
vector (over BCVars) of BCRecs
Definition REMORA.H:1178