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 auto fcor_arr = (mf_fcor)->array(mfi);
37 Real coriolis_f0 = solverChoice.coriolis_f0;
38 Real coriolis_beta = solverChoice.coriolis_beta;
39 Real Esize = geomdata.ProbHi()[1] - geomdata.ProbLo()[1];
40 Real prob_lo = geomdata.ProbLo()[1];
41 Real dx = geomdata.CellSize()[1];
42
43 ParallelFor(Box(fcor_arr), [=] AMREX_GPU_DEVICE (int i, int j, int )
44 {
45 Real y = prob_lo + (j + 0.5_rt) * dx;
46 fcor_arr(i,j,0) = coriolis_f0 + coriolis_beta * (y - 0.5_rt * Esize);
47 });
48 } //mfi
49
50 vec_fcor[lev]->FillBoundary(geom[lev].periodicity());
51}
52
53/**
54 * @param[in ] lev level to operate on
55 */
56void
58{
59 std::unique_ptr<MultiFab>& mf_zeta = vec_zeta[lev];
60 std::unique_ptr<MultiFab>& mf_Zt_avg1 = vec_Zt_avg1[lev];
61 for ( MFIter mfi(*cons_new[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
62 {
63 int nstp = 0;
64 Array4<Real> const& Zt_avg1 = (mf_Zt_avg1)->array(mfi);
65 Array4<const Real> const& zeta = mf_zeta->const_array(mfi);
66
67 Box bx3 = mfi.tilebox() ; bx3.grow(IntVect(NGROW+1,NGROW+1,0)); // cell-centered, grown by 3
68
69 ParallelFor(makeSlab(bx3,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int )
70 {
71 Zt_avg1(i,j,0) = zeta(i,j,0,nstp);
72 });
73
74 }
75}
76
77/**
78 * @param[in ] lev level to operate on
79 */
80void
82{
83 auto N = Geom(lev).Domain().size()[2]-1; // Number of vertical "levs" aka, NZ
84
85 vec_ubar[lev]->setVal(0.0_rt);
86 vec_vbar[lev]->setVal(0.0_rt);
87
88 MultiFab* U_old = xvel_new[lev];
89 MultiFab* V_old = yvel_new[lev];
90 std::unique_ptr<MultiFab>& mf_ubar = vec_ubar[lev];
91 std::unique_ptr<MultiFab>& mf_vbar = vec_vbar[lev];
92 std::unique_ptr<MultiFab>& mf_Hz = vec_Hz[lev];
93 int nstp = 0;
94
95 for ( MFIter mfi(*cons_new[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
96 {
97 Array4<Real> const& ubar = (mf_ubar)->array(mfi);
98 Array4<Real> const& vbar = (mf_vbar)->array(mfi);
99
100 Array4<const Real> const& Hz = mf_Hz->const_array(mfi);
101 Array4<const Real> const& u = U_old->const_array(mfi);
102 Array4<const Real> const& v = V_old->const_array(mfi);
103
104 Box bx2 = mfi.tilebox() ; bx2.grow(IntVect(NGROW ,NGROW ,0)); // cell-centered, grown by 2
105 Box ubx2 = mfi.nodaltilebox(0); ubx2.grow(IntVect(NGROW ,NGROW ,0)); // x-face-centered, grown by 2
106 Box vbx2 = mfi.nodaltilebox(1); vbx2.grow(IntVect(NGROW ,NGROW ,0)); // y-face-centered, grown by 2
107
108 ParallelFor(makeSlab(ubx2,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int )
109 {
110 Real CF = 0.;
111 Real sum_of_hz = 0.;
112
113 for (int k=0; k<=N; k++) {
114 Real avg_hz = 0.5_rt*(Hz(i,j,k)+Hz(i-1,j,k));
115 sum_of_hz += avg_hz;
116 CF += avg_hz*u(i,j,k,nstp);
117 }
118 ubar(i,j,0,0) = CF / sum_of_hz;
119 });
120
121 ParallelFor(makeSlab(vbx2,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int )
122 {
123 Real CF = 0.;
124 Real sum_of_hz = 0.;
125
126 for(int k=0; k<=N; k++) {
127 Real avg_hz = 0.5_rt*(Hz(i,j,k)+Hz(i,j-1,k));
128 sum_of_hz += avg_hz;
129 CF += avg_hz*v(i,j,k,nstp);
130 }
131 vbar(i,j,0,0) = CF / sum_of_hz;
132 });
133 }
134
135 FillPatch(lev, t_new[lev], *vec_ubar[lev], GetVecOfPtrs(vec_ubar), BCVars::ubar_bc, BdyVars::ubar,0,false,false);
136 FillPatch(lev, t_new[lev], *vec_vbar[lev], GetVecOfPtrs(vec_vbar), BCVars::vbar_bc, BdyVars::vbar,0,false,false);
137}
138
139/**
140 * @param[in ] lev level to operate on
141 * @param[in ] solver_choice algorithmic choices
142 */
143void
144REMORA::init_gls_vmix (int lev, SolverChoice solver_choice)
145{
146 vec_tke[lev]->setVal(solver_choice.gls_Kmin);
147 vec_gls[lev]->setVal(solver_choice.gls_Pmin);
148 vec_Lscale[lev]->setVal(0.0_rt);
149 vec_Akk[lev]->setVal(solver_choice.Akk_bak);
150 vec_Akp[lev]->setVal(solver_choice.Akp_bak);
151 vec_Akv[lev]->setVal(solver_choice.Akv_bak);
152 vec_Akt[lev]->setVal(solver_choice.Akt_bak);
153
154 auto N = Geom(lev).Domain().size()[2]-1; // Number of vertical "levs" aka, NZ
155
156#ifdef _OPENMP
157#pragma omp parallel if (Gpu::notInLaunchRegion())
158#endif
159 for (MFIter mfi(*vec_Akk[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
160 Array4<Real> const& Akk = vec_Akk[lev]->array(mfi);
161 Array4<Real> const& Akp = vec_Akp[lev]->array(mfi);
162 Array4<Real> const& Akt = vec_Akt[lev]->array(mfi);
163 Array4<Real> const& Akv = vec_Akv[lev]->array(mfi);
164
165 ParallelFor(makeSlab(Box(Akk),2,0), [=] AMREX_GPU_DEVICE (int i, int j, int )
166 {
167 Akk(i,j, 0) = 0.0_rt;
168 Akk(i,j, N+1) = 0.0_rt;
169
170 Akp(i,j, 0) = 0.0_rt;
171 Akp(i,j, N+1) = 0.0_rt;
172
173 Akv(i,j, 0) = 0.0_rt;
174 Akv(i,j, N+1) = 0.0_rt;
175
176 Akt(i,j, 0) = 0.0_rt;
177 Akt(i,j, N+1) = 0.0_rt;
178 });
179 }
180}
181
182/**
183 * @param[in ] lev level to operate on
184 */
185void
187 // Fill nudging coefficients from constant values, then overwrite
188 // with coeffs read from file if using
196#ifdef REMORA_USE_NETCDF
198 amrex::Print() << "Calling init_clim_nudg_coeff_from_netcdf \n " << std::endl;
200 amrex::Print() << "Climatology weights loaded from netcdf file \n " << std::endl;
201 }
202#endif
203}
#define NGROW
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_fcor
coriolis factor (2D)
Definition REMORA.H:360
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:217
std::unique_ptr< ProblemBase > prob
Pointer to container of analytical functions for problem definition.
Definition REMORA.H:1084
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_tke
Turbulent kinetic energy.
Definition REMORA.H:403
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_gls
Turbulent generic length scale.
Definition REMORA.H:405
amrex::Vector< amrex::MultiFab * > zvel_new
multilevel data container for current step's z velocities (largely unused; W stored separately)
Definition REMORA.H:223
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:407
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Hz
Width of cells in the vertical (z-) direction (3D, Hz in ROMS)
Definition REMORA.H:232
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akt
Vertical diffusion coefficient (3D)
Definition REMORA.H:252
amrex::Vector< amrex::MultiFab * > yvel_new
multilevel data container for current step's y velocities (v in ROMS)
Definition REMORA.H:221
amrex::Vector< amrex::MultiFab * > xvel_new
multilevel data container for current step's x velocities (u in ROMS)
Definition REMORA.H:219
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 set_zeta_average(int lev)
Set Zt_avg1 to zeta.
amrex::Vector< amrex::Real > t_new
new time at each level
Definition REMORA.H:1098
static SolverChoice solverChoice
Container for algorithmic choices.
Definition REMORA.H:1221
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akk
Turbulent kinetic energy vertical diffusion coefficient.
Definition REMORA.H:409
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_zeta
free surface height (2D)
Definition REMORA.H:343
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_vbar
barotropic y velocity (2D)
Definition REMORA.H:341
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:339
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:414
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Akv
Vertical viscosity coefficient (3D)
Definition REMORA.H:250
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Zt_avg1
Average of the free surface, zeta (2D)
Definition REMORA.H:279
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:411
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