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));
21 const auto local_theta_s = solverChoice.theta_s;
22 const auto local_theta_b = solverChoice.theta_b;
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 {
42 Csur=-s_w_dat[k]*s_w_dat[k];
43 }
44
45 if (local_theta_b > zero) {
46 Cbot=(std::exp(local_theta_b*Csur)-one)/
47 (one-std::exp(-local_theta_b));
48 Cs_w_dat[k]=Cbot;
49 } else {
50 Cs_w_dat[k]=Csur;
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 {
60 Csur=-s_r_dat[k]*s_r_dat[k];
61 }
62
63 if (local_theta_b > zero) {
64 Cbot=(std::exp(local_theta_b*Csur)-one)/
65 (one-std::exp(-local_theta_b));
66 Cs_r_dat[k]=Cbot;
67 } else {
68 Cs_r_dat[k]=Csur;
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);
143 Real cff2_r=(cff_r+cff1_r*hwater)*hinv;
144 Real cff2_w=(cff_w+cff1_w*hwater)*hinv;
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 // We shrink the box in the vertical since z_phys_nd has a ghost cell in the vertical
191 // which we will fill by extrapolation, not from z_w
192 Box bx = mfi.growntilebox(IntVect(NGROW,NGROW,0));//Box(z_phys_nd); bx.grow(2,-1);
193
194 ParallelFor(convert(bx,IntVect(0,0,1)), [=] AMREX_GPU_DEVICE (int i, int j, int k)
195 {
196 // For now assume all boundaries are constant height --
197 // we will enforce periodicity below
198 if ( i >= lo.x && i <= hi.x-1 && j >= lo.y && j <= hi.y-1 )
199 {
200 z_phys_nd(i,j,k)=Real(0.25)*( z_w(i,j ,k) + z_w(i+1,j ,k) +
201 z_w(i,j+1,k) + z_w(i+1,j+1,k) );
202 } else {
203 int ii = std::min(std::max(i, lo.x), hi.x);
204 int jj = std::min(std::max(j, lo.y), hi.y);
205 z_phys_nd(i,j,k) = z_w(ii,jj,k);
206 }
207 });
208
209 // Fill nodes below the surface (to avoid out of bounds errors in particle functions)
210 int klo = -1;
211 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int)
212 {
213 z_phys_nd(i,j,klo) = two * z_phys_nd(i,j,klo+1) - z_phys_nd(i,j,klo+2);
214 });
215 } // mf
216
217 // Note that we do *not* want to do a multilevel fill here -- we have
218 // already filled z_phys_nd on the grown boxes, but we enforce periodicity just in case
219 vec_z_phys_nd[lev]->FillBoundary(geom[lev].periodicity());
220}
221#endif
constexpr amrex::Real two
constexpr amrex::Real one
constexpr amrex::Real zero
#define NGROW
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:388
amrex::Vector< amrex::MultiFab * > cons_new
multilevel data container for current step's scalar data: temperature, salinity, passive tracer
Definition REMORA.H:368
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:430
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Hz
Width of cells in the vertical (z-) direction (3D, Hz in ROMS)
Definition REMORA.H:394
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:428
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_z_r
z coordinates at rho points (cell centers)
Definition REMORA.H:423
void calc_stretch_coeffs()
calculate vertical stretch coefficients
amrex::Gpu::DeviceVector< amrex::Real > Cs_r
Stretching coefficients at rho points.
Definition REMORA.H:438
static SolverChoice solverChoice
Container for algorithmic choices.
Definition REMORA.H:1603
amrex::Gpu::DeviceVector< amrex::Real > Cs_w
Stretching coefficients at w points.
Definition REMORA.H:440
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_z_phys_nd
z coordinates at psi points (cell nodes)
Definition REMORA.H:443
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Zt_avg1
Average of the free surface, zeta (2D)
Definition REMORA.H:446
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_z_w
z coordinates at w points (faces between z-cells)
Definition REMORA.H:426
amrex::Real theta_b
amrex::Real theta_s
amrex::Real tcline