1 #ifndef ERF_INPUT_SOUNDING_DATA_H_
2 #define ERF_INPUT_SOUNDING_DATA_H_
8 #include <AMReX_ParmParse.H>
9 #include <AMReX_Print.H>
10 #include <AMReX_Gpu.H>
11 #include <AMReX_Geometry.H>
30 amrex::ParmParse
pp(
"erf");
78 amrex::Abort(
"erf.input_sounding_file names " + std::to_string(
n_sounding_files) +
79 " file(s) but erf.input_sounding_time gives " + std::to_string(
n_sounding_times) +
80 " time(s); give one time for each file");
84 amrex::Abort(
"erf.input_sounding_time must be strictly increasing, but time " +
86 ") is not later than time " + std::to_string(n-1) +
" (" +
114 const amrex::Vector<amrex::Real>& zlevels_stag,
115 int itime,
bool is_moist)
118 const int khi = geom.Domain().bigEnd()[AMREX_SPACEDIM-1];
119 const int Nz = geom.Domain().size()[AMREX_SPACEDIM-1];
121 const amrex::Real zbot = zlevels_stag[
klo];
122 const amrex::Real
ztop = zlevels_stag[
khi+1];
131 amrex::Print() <<
"input_sounding file location : " <<
input_sounding_file[itime] << std::endl;
133 if(!input_sounding_reader.is_open()) {
134 amrex::Error(
"Error opening the input_sounding file\n");
138 amrex::Print() <<
"Successfully opened the input_sounding file. Now reading... " << std::endl;
143 amrex::Vector<amrex::Real> z_inp_sound_tmp, theta_inp_sound_tmp, qv_inp_sound_tmp,
144 U_inp_sound_tmp, V_inp_sound_tmp;
147 std::getline(input_sounding_reader, line);
148 std::istringstream iss(line);
149 amrex::Real press_sfc, theta_sfc, qv_sfc;
150 iss >> press_sfc >> theta_sfc >> qv_sfc;
152 qv_sfc *= amrex::Real(0.001);
166 "InputSoundingData::read_from_file: the first sounding must be read before the others");
169 " (" + std::to_string(press_sfc * amrex::Real(0.01)) +
" hPa) differs from that of " +
171 " hPa); the base state is set once from the first sounding, so every "
172 "input sounding must have the same surface pressure");
177 z_inp_sound_tmp.push_back(zbot);
178 theta_inp_sound_tmp.push_back(theta_sfc);
179 qv_inp_sound_tmp.push_back(qv_sfc);
180 U_inp_sound_tmp.push_back(0);
181 V_inp_sound_tmp.push_back(0);
188 amrex::ParmParse pp_erf(
"erf");
198 amrex::Real surf_temp = amrex::Real(-1.0);
199 amrex::Real old_surf_temp = amrex::Real(-1.0);
200 pp_erf.query(
"most.pot_surf_temp", surf_temp);
201 pp_erf.query(
"most.surf_temp", old_surf_temp);
202 if (old_surf_temp > amrex::Real(0.0)) { surf_temp = old_surf_temp; }
203 bool surf_temp_specified = (surf_temp > amrex::Real(0.0));
204 if ( itime == 0 && surf_temp_specified && (surf_temp != theta_inp_sound_tmp[0]) ) {
205 amrex::Print() <<
"Input sounding temp does not match most.pot_surf_temp" << std::endl;
206 amrex::Print() <<
"Modify one or both to match." << std::endl;
216 amrex::Real surf_moist = amrex::Real(-1.0);
217 pp_erf.queryAdd(
"most.surf_moist", surf_moist);
218 bool surf_moist_specified = (surf_moist >= amrex::Real(0.0));
219 if ( itime == 0 && surf_moist_specified && (surf_moist != qv_inp_sound_tmp[0]) ) {
220 amrex::Print() <<
"Input sounding qv does not match most.surf_moist" << std::endl;
221 amrex::Print() <<
"Modify one or both to match." << std::endl;
228 while(std::getline(input_sounding_reader, line)) {
229 std::istringstream iss_z(line);
238 U_inp_sound_tmp[0] =
U;
239 V_inp_sound_tmp[0] =
V;
242 z_inp_sound_tmp.push_back(
z);
244 theta_inp_sound_tmp.push_back(
theta);
245 qv_inp_sound_tmp.push_back(
qv*amrex::Real(0.001));
246 U_inp_sound_tmp.push_back(
U);
247 V_inp_sound_tmp.push_back(
V);
248 if (
z >=
ztop)
break;
254 const int Ninp = z_inp_sound_tmp.size();
260 for (
int k=0; k < Nz; ++k) {
274 amrex::Print() <<
"Successfully read the " << itime <<
"th input_sounding file..." << std::endl;
275 input_sounding_reader.close();
291 const int Ninp =
size(itime);
302 amrex::Print() <<
"ideal sounding init: surface dry air density = "
303 << std::setprecision(15)
314 amrex::Print() <<
"z p_m rho_d theta qv U V" << std::endl;
326 amrex::Real
dz, F, C;
328 amrex::Real rho_tot_hi, rho_tot_lo;
329 for (
int k=1; k <
size(itime); ++k)
343 #ifdef AMREX_USE_FLOAT
344 const amrex::Real tol = amrex::Real(4)
348 const amrex::Real tol = amrex::Real(1.0e-12);
366 if (std::abs(F)>tol) {
367 bool maintain_Th =
true;
402 const int Ninp =
size(itime);
416 amrex::Print() <<
"isentropic sounding init: surface dry air density = "
417 << std::setprecision(15)
423 amrex::Print() <<
"z p_m rho_d theta qv U V" << std::endl;
436 for (
int k=1; k <
size(itime); ++k)
443 amrex::Real thm0 = th0 * (
one +
RvoRd * qvmean);
483 const int Ninp =
size(itime);
490 amrex::Gpu::copy(amrex::Gpu::hostToDevice,
493 amrex::Gpu::copy(amrex::Gpu::hostToDevice,
496 amrex::Gpu::copy(amrex::Gpu::hostToDevice,
499 amrex::Gpu::copy(amrex::Gpu::hostToDevice,
502 amrex::Gpu::copy(amrex::Gpu::hostToDevice,
511 amrex::Gpu::copy(amrex::Gpu::hostToDevice,
514 amrex::Gpu::copy(amrex::Gpu::hostToDevice,
constexpr amrex::Real p_0
Definition: ERF_Constants.H:69
constexpr amrex::Real RvoRd
Definition: ERF_Constants.H:59
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:72
constexpr amrex::Real R_d
Definition: ERF_Constants.H:49
constexpr amrex::Real RdoCp
Definition: ERF_Constants.H:57
constexpr amrex::Real Gamma
Definition: ERF_Constants.H:70
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getRhogivenThetaPress(const amrex::Real th, const amrex::Real p, const amrex::Real rdOcp, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:96
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenPandTh(const amrex::Real P, const amrex::Real th, const amrex::Real rdOcp)
Definition: ERF_EOS.H:32
const Real ztop
Definition: ERF_InitCustomPertVels_ParticleTests.H:4
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
const int klo
Definition: ERF_InitCustomPert_KE.H:9
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real interpolate_1d(const amrex::Real *alpha, const amrex::Real *beta, const amrex::Real alpha_interp, const int alpha_size)
Definition: ERF_Interpolation_1D.H:15
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void Newton_Raphson_hse(const Real &m_tol, const Real &RdoCp, const Real &dz, const Real &g, const Real &C, const Real &Th, const Real &T, const Real &qt, const Real &qv, Real &P, Real &rd, Real &F, const bool &maintain_Th)
Definition: ERF_HSEUtils.H:46
@ theta
Definition: ERF_Kessler.H:26
@ qv
Definition: ERF_Kessler.H:31
@ U
Definition: ERF_IndexDefines.H:178
@ V
Definition: ERF_IndexDefines.H:179
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12