REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_DepthStretchTransform.H
Go to the documentation of this file.
1#ifndef _REMORA_STRETCH_H_
2#define _REMORA_STRETCH_H_
3
4#include <cmath>
5#include <REMORA_DataStruct.H>
6#include <REMORA.H>
8
9using namespace amrex;
10
11void
13{
14 BL_PROFILE("REMORA::calc_stretch_coeffs()");
15 int nz = geom[0].Domain().length(2);
16
17 auto N = nz; // Number of vertical "levels" aka, NZ
18 Real ds = one / Real(N);
19
20 Box bx(IntVect(0,0,0),IntVect(0,0,N));
23
24 //amrex::Vector<Real> s_w_vec(N+1); auto s_w_dat = s_w_vec.data();
25 //amrex::Vector<Real> Cs_w_vec(N+1); auto Cs_w_dat = Cs_w_vec.data();
26 //amrex::Vector<Real> s_r_vec(N); auto s_r_dat = s_r_vec.data();
27 //amrex::Vector<Real> Cs_r_vec(N); auto Cs_r_dat = Cs_r_vec.data();
28 auto s_w_dat = s_w.data();
29 auto Cs_w_dat = Cs_w.data();
30 auto s_r_dat = s_r.data();
31 auto Cs_r_dat = Cs_r.data();
32
33 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE (int , int , int k)
34 {
35 Real Csur,Cbot;
36
37 s_w_dat[k]=ds*(k-N);
38 if (local_theta_s > zero) {
39 Csur=(one-std::cosh(local_theta_s*s_w_dat[k]))/
40 (std::cosh(local_theta_s)-one);
41 } else {
43 }
44
45 if (local_theta_b > zero) {
46 Cbot=(std::exp(local_theta_b*Csur)-one)/
47 (one-std::exp(-local_theta_b));
49 } else {
51 }
52
53 if (k<N) {
54 s_r_dat[k]=ds*(k-N+Real(0.5));
55
56 if (local_theta_s > zero) {
57 Csur=(one-std::cosh(local_theta_s*s_r_dat[k]))/
58 (std::cosh(local_theta_s)-one);
59 } else {
61 }
62
63 if (local_theta_b > zero) {
64 Cbot=(std::exp(local_theta_b*Csur)-one)/
65 (one-std::exp(-local_theta_b));
67 } else {
69 }
70 }
71 });
72}
73
74/**
75 * @param[in] lev level to operate on
76 */
77void
79{
80 BL_PROFILE("REMORA::stretch_transform()");
81 std::unique_ptr<MultiFab>& mf_z_w = vec_z_w[lev];
82 std::unique_ptr<MultiFab>& mf_z_r = vec_z_r[lev];
83 std::unique_ptr<MultiFab>& mf_Hz = vec_Hz[lev];
84 std::unique_ptr<MultiFab>& mf_h = vec_h[lev];
85 std::unique_ptr<MultiFab>& mf_Zt_avg1 = vec_Zt_avg1[lev];
86 std::unique_ptr<MultiFab>& mf_z_phys_nd = vec_z_phys_nd[lev];
87
88 [[maybe_unused]] auto s_w_dat = s_w.data();
89 auto Cs_w_dat = Cs_w.data();
90 [[maybe_unused]] auto s_r_dat = s_r.data();
91 auto Cs_r_dat = Cs_r.data();
92
93 for ( MFIter mfi(*cons_new[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
94 {
95 Array4<Real> const& z_w = (mf_z_w)->array(mfi);
96 Array4<Real> const& z_r = (mf_z_r)->array(mfi);
97 Array4<Real> const& Hz = (mf_Hz)->array(mfi);
98 Array4<Real> const& h = (mf_h)->array(mfi);
99 Array4<Real> const& Zt_avg1 = (mf_Zt_avg1)->array(mfi);
100 Box bx = mfi.tilebox();
101 Box gbx2 = bx;
102 gbx2.grow(IntVect(NGROW,NGROW,0));
103 Box gbx3 = bx;
104 gbx3.grow(IntVect(NGROW+1,NGROW+1,0));
105 Box gbx2D = gbx2;
106 gbx2D.makeSlab(2,0);
107 Box gbx3D = gbx3;
108 gbx3D.makeSlab(2,0);
109 Box wgbx3 = gbx3;
110 wgbx3.surroundingNodes(2);
111
112 const auto & geomdata = Geom(lev).data();
113
114 int nz = geom[lev].Domain().length(2);
115
116 auto N = nz; // Number of vertical "levels" aka, NZ
117 //forcing tcline to be the same as probhi for now, one in DataStruct.H other in inputs
118
119 Real hc = -min(geomdata.ProbHi(2),-solverChoice.tcline); // Do we need to enforce min here?
120
121 Real ds = one / Real(N);
122
123 amrex::ParallelFor(wgbx3, [=] AMREX_GPU_DEVICE (int i, int j, int k)
124 {
125 z_w(i,j,k) = h(i,j,0);
126 });
127
128 // ROMS Transform 2
129 Gpu::streamSynchronize();
130
131 amrex::ParallelFor(wgbx3, [=] AMREX_GPU_DEVICE (int i, int j, int k)
132 {
133 if (k < N) {
134 Real sc_r=ds*(k-N+Real(0.5));
135 Real sc_w=ds*(k-N);
136 Real cff_r = hc*sc_r;
137 Real cff1_r = Cs_r_dat[k];
138 Real cff_w=hc*sc_w;
139 Real cff1_w=Cs_w_dat[k];
140 Real hwater=h(i,j,0);
141
142 Real hinv=one/(hc+hwater);
145
146 if (k==0) {
147 h(i,j,0,1) = Zt_avg1(i,j,0)+(Zt_avg1(i,j,0)+hwater)*cff2_w;
148 z_w(i,j,0) = h(i,j,0,1);
149 } else {
150 z_w(i,j,k)=Zt_avg1(i,j,0)+(Zt_avg1(i,j,0)+hwater)*cff2_w;
151 }
152
153 z_r(i,j,k)=Zt_avg1(i,j,0)+(Zt_avg1(i,j,0)+hwater)*cff2_r;
154
155 } else { // k == N
156 // HACK: should actually be the normal expression with coeffs evaluated at k=N-1
157 z_w(i,j,N)=Zt_avg1(i,j,0);
158 }
159 });
160
161 Gpu::streamSynchronize();
162
163 amrex::ParallelFor(gbx3, [=] AMREX_GPU_DEVICE (int i, int j, int k)
164 {
165 Hz(i,j,k)=z_w(i,j,k+1)-z_w(i,j,k);
166 });
167
168 } // mfi
169
170 vec_z_w[lev]->FillBoundary(geom[lev].periodicity());
171 vec_z_r[lev]->FillBoundary(geom[lev].periodicity());
172 vec_Hz[lev]->FillBoundary(geom[lev].periodicity());
173
174 // Define nodal z as average of z on w-faces
175 for ( MFIter mfi(*cons_new[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
176 {
177 Array4<Real> const& z_w = (mf_z_w)->array(mfi);
178 Array4<Real> const& z_phys_nd = (mf_z_phys_nd)->array(mfi);
179
180 Box z_w_box = Box(z_w);
181 auto const lo = amrex::lbound(z_w_box);
182 auto const hi = amrex::ubound(z_w_box);
183
184 //
185 // NOTE: we assume that all boxes extend the full extent of the domain in the vertical direction
186 //
187 // NOTE: z_phys_nd(i,j,k) and z_w(i,j,k) both refer to the node on the LOW side of cell (i,j,k)
188 //
189
190 // Nodal in all three directions so that the outermost node in x and y is
191 // filled as well. We do not grow in the vertical since z_phys_nd has a
192 // ghost node there which we fill by extrapolation, not from z_w.
193 Box bx = mfi.grownnodaltilebox(-1,IntVect(NGROW,NGROW,0));
194
195 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
196 {
197 // Node (i,j,k) is the low corner of cell (i,j,k), so the four water
198 // columns surrounding it are cells (i-1,j-1) through (i,j). This is
199 // the psi-point averaging ROMS uses in set_depth / metrics.
200 // Indices are clamped so that a node on the edge of the array picks up the
201 // one-sided value; for now we assume all boundaries are constant
202 // height -- we will enforce periodicity below.
203 int ii = std::min(std::max(i , lo.x), hi.x);
204 int im = std::min(std::max(i-1, lo.x), hi.x);
205 int jj = std::min(std::max(j , lo.y), hi.y);
206 int jm = std::min(std::max(j-1, lo.y), hi.y);
207
208 z_phys_nd(i,j,k)=Real(0.25)*( z_w(im,jm,k) + z_w(ii,jm,k) +
209 z_w(im,jj,k) + z_w(ii,jj,k) );
210 });
211
212 // Fill nodes below the surface (to avoid out of bounds errors in particle functions)
213 int klo = -1;
214 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int)
215 {
216 z_phys_nd(i,j,klo) = two * z_phys_nd(i,j,klo+1) - z_phys_nd(i,j,klo+2);
217 });
218 } // mf
219
220 // Note that we do *not* want to do a multilevel fill here -- we have
221 // already filled z_phys_nd on the grown boxes, but we enforce periodicity just in case
222 vec_z_phys_nd[lev]->FillBoundary(geom[lev].periodicity());
223}
224#endif
constexpr amrex::Real two
constexpr amrex::Real one
constexpr amrex::Real zero
#define NGROW
mf_h setVal(geomdata.ProbHi(2))
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_h
multilevel data container for current step's z velocities (largely unused; W stored separately)
Definition REMORA.H:406
amrex::Vector< amrex::MultiFab * > cons_new
multilevel data container for current step's scalar data: temperature, salinity, passive tracer
Definition REMORA.H:386
void stretch_transform(int lev)
Calculate vertical stretched coordinates.
amrex::Gpu::DeviceVector< amrex::Real > s_w
Scaled vertical coordinate (range [0,1]) that transforms to z, defined at w-points (cell faces)
Definition REMORA.H:448
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Hz
Width of cells in the vertical (z-) direction (3D, Hz in ROMS)
Definition REMORA.H:412
amrex::Gpu::DeviceVector< amrex::Real > s_r
Scaled vertical coordinate (range [0,1]) that transforms to z, defined at rho points (cell centers)
Definition REMORA.H:446
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_z_r
z coordinates at rho points (cell centers)
Definition REMORA.H:441
void calc_stretch_coeffs()
calculate vertical stretch coefficients
amrex::Gpu::DeviceVector< amrex::Real > Cs_r
Stretching coefficients at rho points.
Definition REMORA.H:456
static SolverChoice solverChoice
Container for algorithmic choices.
Definition REMORA.H:1717
amrex::Gpu::DeviceVector< amrex::Real > Cs_w
Stretching coefficients at w points.
Definition REMORA.H:458
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_z_phys_nd
z coordinates at psi points (cell nodes)
Definition REMORA.H:461
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Zt_avg1
Average of the free surface, zeta (2D)
Definition REMORA.H:464
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_z_w
z coordinates at w points (faces between z-cells)
Definition REMORA.H:444
amrex::Real theta_b
amrex::Real theta_s
amrex::Real tcline