REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_init.cpp
Go to the documentation of this file.
1/**
2 * \file REMORA_init.cpp
3 */
4
5#include <REMORA.H>
6#include <REMORA_Constants.H>
8
9using namespace amrex;
10
11/**
12 * @param[in ] lev level to initialize on
13 */
14void
16{
17 prob->init_analytic_prob(lev, geom[lev], solverChoice, *this, *cons_new[lev], *xvel_new[lev], *yvel_new[lev], *zvel_new[lev]);
18
19 set_grid_scale(lev);
20}
21
22/**
23 * @param[in ] lev level to initialize on
24 */
25void
27{
28 std::unique_ptr<MultiFab>& mf_fcor = vec_fcor[lev];
29 auto geomdata = Geom(lev).data();
30
31#ifdef _OPENMP
32#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
33#endif
34 for (MFIter mfi(*cons_new[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
35 {
36 Box bx = mfi.growntilebox(IntVect(NGROW+1,NGROW+1,0));
37 auto fcor_arr = (mf_fcor)->array(mfi);
38 Real coriolis_f0 = solverChoice.coriolis_f0;
39 Real coriolis_beta = solverChoice.coriolis_beta;
40 Real Esize = geomdata.ProbHi()[1] - geomdata.ProbLo()[1];
41 Real prob_lo = geomdata.ProbLo()[1];
42 Real dx = geomdata.CellSize()[1];
43
44 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int )
45 {
46 Real y = prob_lo + (j + 0.5_rt) * dx;
47 fcor_arr(i,j,0) = coriolis_f0 + coriolis_beta * (y - 0.5_rt * Esize);
48 });
49 } //mfi
50
51 vec_fcor[lev]->FillBoundary(geom[lev].periodicity());
52}
53
54/**
55 * @param[in ] lev level to operate on
56 */
57void
59{
60 std::unique_ptr<MultiFab>& mf_zeta = vec_zeta[lev];
61 std::unique_ptr<MultiFab>& mf_Zt_avg1 = vec_Zt_avg1[lev];
62 for ( MFIter mfi(*cons_new[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
63 {
64 int nstp = 0;
65 Array4<Real> const& Zt_avg1 = (mf_Zt_avg1)->array(mfi);
66 Array4<const Real> const& zeta = mf_zeta->const_array(mfi);
67
68 Box bx3 = mfi.tilebox() ; bx3.grow(IntVect(NGROW+1,NGROW+1,0)); // cell-centered, grown by 3
69
70 ParallelFor(makeSlab(bx3,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int )
71 {
72 Zt_avg1(i,j,0) = zeta(i,j,0,nstp);
73 });
74
75 }
76}
77
78/**
79 * @param[in ] lev level to operate on
80 */
81void
83{
84 auto N = Geom(lev).Domain().size()[2]-1; // Number of vertical "levs" aka, NZ
85
86 vec_ubar[lev]->setVal(0.0_rt);
87 vec_vbar[lev]->setVal(0.0_rt);
88
89 MultiFab* U_old = xvel_new[lev];
90 MultiFab* V_old = yvel_new[lev];
91 std::unique_ptr<MultiFab>& mf_ubar = vec_ubar[lev];
92 std::unique_ptr<MultiFab>& mf_vbar = vec_vbar[lev];
93 std::unique_ptr<MultiFab>& mf_Hz = vec_Hz[lev];
94 int nstp = 0;
95
96 for ( MFIter mfi(*cons_new[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
97 {
98 Array4<Real> const& ubar = (mf_ubar)->array(mfi);
99 Array4<Real> const& vbar = (mf_vbar)->array(mfi);
100
101 Array4<const Real> const& Hz = mf_Hz->const_array(mfi);
102 Array4<const Real> const& u = U_old->const_array(mfi);
103 Array4<const Real> const& v = V_old->const_array(mfi);
104
105 Box bx2 = mfi.tilebox() ; bx2.grow(IntVect(NGROW ,NGROW ,0)); // cell-centered, grown by 2
106 Box ubx2 = mfi.nodaltilebox(0); ubx2.grow(IntVect(NGROW ,NGROW ,0)); // x-face-centered, grown by 2
107 Box vbx2 = mfi.nodaltilebox(1); vbx2.grow(IntVect(NGROW ,NGROW ,0)); // y-face-centered, grown by 2
108
109 ParallelFor(makeSlab(ubx2,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int )
110 {
111 Real CF = 0.;
112 Real sum_of_hz = 0.;
113
114 for (int k=0; k<=N; k++) {
115 Real avg_hz = 0.5_rt*(Hz(i,j,k)+Hz(i-1,j,k));
116 sum_of_hz += avg_hz;
117 CF += avg_hz*u(i,j,k,nstp);
118 }
119 ubar(i,j,0,0) = CF / sum_of_hz;
120 });
121
122 ParallelFor(makeSlab(vbx2,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int )
123 {
124 Real CF = 0.;
125 Real sum_of_hz = 0.;
126
127 for(int k=0; k<=N; k++) {
128 Real avg_hz = 0.5_rt*(Hz(i,j,k)+Hz(i,j-1,k));
129 sum_of_hz += avg_hz;
130 CF += avg_hz*v(i,j,k,nstp);
131 }
132 vbar(i,j,0,0) = CF / sum_of_hz;
133 });
134 }
135
136 FillPatch(lev, t_new[lev], *vec_ubar[lev], GetVecOfPtrs(vec_ubar), BCVars::ubar_bc, BdyVars::ubar,0,false,false);
137 FillPatch(lev, t_new[lev], *vec_vbar[lev], GetVecOfPtrs(vec_vbar), BCVars::vbar_bc, BdyVars::vbar,0,false,false);
138}
139
140/**
141 * @param[in ] lev level to operate on
142 * @param[in ] solver_choice algorithmic choices
143 */
144void
145REMORA::init_gls_vmix (int lev, SolverChoice solver_choice)
146{
147 vec_tke[lev]->setVal(solver_choice.gls_Kmin);
148 vec_gls[lev]->setVal(solver_choice.gls_Pmin);
149 vec_Lscale[lev]->setVal(0.0_rt);
150 vec_Akk[lev]->setVal(solver_choice.Akk_bak);
151 vec_Akp[lev]->setVal(solver_choice.Akp_bak);
152 vec_Akv[lev]->setVal(solver_choice.Akv_bak);
153 vec_Akt[lev]->setVal(solver_choice.Akt_bak);
154
155 auto N = Geom(lev).Domain().size()[2]-1; // Number of vertical "levs" aka, NZ
156
157#ifdef _OPENMP
158#pragma omp parallel if (Gpu::notInLaunchRegion())
159#endif
160 for (MFIter mfi(*vec_Akk[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
161 Box bx = mfi.growntilebox(IntVect(NGROW,NGROW,0));
162 Array4<Real> const& Akk = vec_Akk[lev]->array(mfi);
163 Array4<Real> const& Akp = vec_Akp[lev]->array(mfi);
164 Array4<Real> const& Akt = vec_Akt[lev]->array(mfi);
165 Array4<Real> const& Akv = vec_Akv[lev]->array(mfi);
166
167 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int )
168 {
169 Akk(i,j, 0) = 0.0_rt;
170 Akk(i,j, N+1) = 0.0_rt;
171
172 Akp(i,j, 0) = 0.0_rt;
173 Akp(i,j, N+1) = 0.0_rt;
174
175 Akv(i,j, 0) = 0.0_rt;
176 Akv(i,j, N+1) = 0.0_rt;
177
178 Akt(i,j, 0) = 0.0_rt;
179 Akt(i,j, N+1) = 0.0_rt;
180 });
181 }
182}
183
184/**
185 * @param[in ] lev level to operate on
186 */
187void
189 // Fill nudging coefficients from constant values, then overwrite
190 // with coeffs read from file if using
198#ifdef REMORA_USE_NETCDF
200 amrex::Print() << "Calling init_clim_nudg_coeff_from_netcdf \n " << std::endl;
202 amrex::Print() << "Climatology weights loaded from netcdf file \n " << std::endl;
203 }
204#endif
205}
206
207void
209 int nz = geom[0].Domain().length(2);
210 s_r.resize(nz);
211 s_w.resize(nz+1);
212 Cs_r.resize(nz);
213 Cs_w.resize(nz+1);
214
216}
#define NGROW
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_fcor
coriolis factor (2D)
Definition REMORA.H:371
void init_gls_vmix(int lev, SolverChoice solver_choice)
Initialize GLS variables.
amrex::Vector< amrex::MultiFab * > cons_new
multilevel data container for current step's scalar data: temperature, salinity, passive scalar
Definition REMORA.H:223
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:274
std::unique_ptr< ProblemBase > prob
Pointer to container of analytical functions for problem definition.
Definition REMORA.H:1142
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_tke
Turbulent kinetic energy.
Definition REMORA.H:414
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_gls
Turbulent generic length scale.
Definition REMORA.H:416
amrex::Vector< amrex::MultiFab * > zvel_new
multilevel data container for current step's z velocities (largely unused; W stored separately)
Definition REMORA.H:229
void set_grid_scale(int lev)
Set pm and pn arrays on level lev. Only works if using analytic initialization.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Lscale
Vertical mixing turbulent length scale.
Definition REMORA.H:418
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Hz
Width of cells in the vertical (z-) direction (3D, Hz in ROMS)
Definition REMORA.H:238
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akt
Vertical diffusion coefficient (3D)
Definition REMORA.H:258
amrex::Vector< amrex::MultiFab * > yvel_new
multilevel data container for current step's y velocities (v in ROMS)
Definition REMORA.H:227
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:272
amrex::Vector< amrex::MultiFab * > xvel_new
multilevel data container for current step's x velocities (u in ROMS)
Definition REMORA.H:225
void init_beta_plane_coriolis(int lev)
Calculate Coriolis parameters from beta plane parametrization.
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.
void calc_stretch_coeffs()
calculate vertical stretch coefficients
void set_zeta_average(int lev)
Set Zt_avg1 to zeta.
amrex::Gpu::DeviceVector< amrex::Real > Cs_r
Stretching coefficients at rho points.
Definition REMORA.H:282
amrex::Vector< amrex::Real > t_new
new time at each level
Definition REMORA.H:1156
void init_stretch_coeffs()
initialize and calculate stretch coefficients
static SolverChoice solverChoice
Container for algorithmic choices.
Definition REMORA.H:1279
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akk
Turbulent kinetic energy vertical diffusion coefficient.
Definition REMORA.H:420
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_zeta
free surface height (2D)
Definition REMORA.H:354
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_vbar
barotropic y velocity (2D)
Definition REMORA.H:352
amrex::Gpu::DeviceVector< amrex::Real > Cs_w
Stretching coefficients at w points.
Definition REMORA.H:284
void set_2darrays(int lev)
Set 2D momentum arrays from 3D momentum.
void init_analytic(int lev)
Initialize initial problem data from analytic functions.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ubar
barotropic x velocity (2D)
Definition REMORA.H:350
void init_clim_nudg_coeff_from_netcdf(int lev)
Climatology nudging coefficient initialization from NetCDF file.
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > vec_nudg_coeff
Climatology nudging coefficients.
Definition REMORA.H:425
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akv
Vertical viscosity coefficient (3D)
Definition REMORA.H:256
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Zt_avg1
Average of the free surface, zeta (2D)
Definition REMORA.H:290
void init_clim_nudg_coeff(int lev)
Wrapper to initialize climatology nudging coefficient.
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akp
Turbulent length scale vertical diffusion coefficient.
Definition REMORA.H:422
amrex::Real Akv_bak
amrex::Real coriolis_beta
amrex::Vector< amrex::Real > nudg_coeff
amrex::Real coriolis_f0
amrex::Real Akk_bak
amrex::Real Akt_bak
amrex::Real gls_Kmin
amrex::Real gls_Pmin
amrex::Real Akp_bak