ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
InputSoundingData Struct Reference

#include <ERF_InputSoundingData.H>

Collaboration diagram for InputSoundingData:

Public Member Functions

 InputSoundingData ()
 Construct input sounding metadata from the ERF input namespace. More...
 
void resize_arrays ()
 Check the sounding files and times, and resize the host and device sounding arrays. More...
 
void read_from_file (const amrex::Geometry &geom, const amrex::Vector< amrex::Real > &zlevels_stag, int itime, bool is_moist)
 Read and interpolate one input sounding profile onto level-0 heights. More...
 
void calc_rho_p (int itime)
 Hydrostatically integrate density and pressure for one sounding. More...
 
void calc_rho_p_isentropic (int itime)
 Compute density and pressure for an isentropic sounding profile. More...
 
void host_to_device (int itime)
 Copy host sounding arrays for one time index to device storage. More...
 
int size (int itime) const
 Return the number of interpolated samples for one sounding time. More...
 
void set_start_time (amrex::Real start_time)
 

Public Attributes

int ntimes
 Number of sounding times represented in the arrays. More...
 
amrex::Real tau_nudging = amrex::Real(5.0)
 Nudging time scale for relaxing toward input sounding data. More...
 
bool wind_above_ground {false}
 
bool theta_above_ground {false}
 
amrex::Vector< std::string > input_sounding_file = {}
 Sounding file path for each configured sounding time. More...
 
amrex::Vector< amrex::Real > input_sounding_time = {}
 Physical time associated with each input sounding file. More...
 
int n_sounding_files = 0
 Number of input sounding files. More...
 
int n_sounding_times = 0
 Number of input sounding times. More...
 
bool assume_dry {false}
 Whether to ignore moisture in isentropic pressure integration. More...
 
amrex::Real press_ref_inp_sound
 Surface reference pressure read from the input sounding [Pa]. More...
 
amrex::Real theta_ref_inp_sound
 Surface reference potential temperature read from the input sounding [K]. More...
 
amrex::Real qv_ref_inp_sound
 Surface reference water vapor mixing ratio read from the input sounding [kg/kg]. More...
 
bool have_first_surface {false}
 Whether the surface line of the first sounding has been read into the members above. More...
 
amrex::Vector< amrex::Vector< amrex::Real > > z_inp_sound
 Interpolated host sounding heights for each sounding time [m]. More...
 
amrex::Vector< amrex::Vector< amrex::Real > > theta_inp_sound
 Interpolated host potential temperature profiles [K]. More...
 
amrex::Vector< amrex::Vector< amrex::Real > > qv_inp_sound
 Interpolated host water vapor mixing ratio profiles [kg/kg]. More...
 
amrex::Vector< amrex::Vector< amrex::Real > > U_inp_sound
 Interpolated host x velocity profiles. More...
 
amrex::Vector< amrex::Vector< amrex::Real > > V_inp_sound
 Interpolated host y velocity profiles. More...
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > z_inp_sound_d
 Device sounding heights for each sounding time [m]. More...
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > theta_inp_sound_d
 Device potential temperature profiles [K]. More...
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > qv_inp_sound_d
 Device water vapor mixing ratio profiles [kg/kg]. More...
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > U_inp_sound_d
 Device x velocity profiles. More...
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > V_inp_sound_d
 Device y velocity profiles. More...
 
amrex::Vector< amrex::Real > pm_integ
 Hydrostatically integrated moist pressure profile. More...
 
amrex::Vector< amrex::Real > rhod_integ
 Hydrostatically integrated dry density profile. More...
 
amrex::Gpu::DeviceVector< amrex::Real > p_inp_sound_d
 Device pressure profile used to initialize solution fields. More...
 
amrex::Gpu::DeviceVector< amrex::Real > rho_inp_sound_d
 Device density profile used to initialize solution fields. More...
 

Static Public Attributes

static constexpr amrex::Real surface_pressure_rtol = amrex::Real(1.e-6)
 Relative tolerance on the surface pressure of a later sounding against the first one. More...
 

Detailed Description

Data structure storing input sounding data. Also handles reading the input file for sounding data and hydrostatic column integration.

Constructor & Destructor Documentation

◆ InputSoundingData()

InputSoundingData::InputSoundingData ( )
inline

Construct input sounding metadata from the ERF input namespace.

29  {
30  amrex::ParmParse pp("erf");
31  pp.queryAdd("tau_nudging", tau_nudging);
32 
33  // Interpolate the sounding winds at the height above the local terrain
34  // instead of the physical height (terrain-fitted meshes)
35  pp.queryAdd("input_sounding_wind_above_ground", wind_above_ground);
36 
37  // Interpolate the sounding theta at the height above the local terrain as
38  // well; rho*theta, and so the pressure, stays at the physical height, and
39  // each column is then rebalanced hydrostatically with that theta
40  pp.queryAdd("input_sounding_theta_above_ground", theta_above_ground);
41 
42  // Read in input_sounding filename
43  n_sounding_files = pp.countval("input_sounding_file");
44  if (n_sounding_files > 0) {
46  pp.queryarr("input_sounding_file", input_sounding_file, 0, n_sounding_files);
47  } else {
48  n_sounding_files = 1;
50  input_sounding_file[0] = "input_sounding";
51  }
52 
53  // Read in input_sounding times
54  n_sounding_times = pp.countval("input_sounding_time");
55 
56  if (n_sounding_times > 0) {
58  pp.queryarr("input_sounding_time", input_sounding_time, 0, n_sounding_times);
59  } else {
60  n_sounding_times = 1;
63  }
64 
65  }
ParmParse pp("prob")
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
amrex::Vector< amrex::Real > input_sounding_time
Physical time associated with each input sounding file.
Definition: ERF_InputSoundingData.H:550
int n_sounding_times
Number of input sounding times.
Definition: ERF_InputSoundingData.H:552
bool wind_above_ground
Definition: ERF_InputSoundingData.H:546
bool theta_above_ground
Definition: ERF_InputSoundingData.H:547
amrex::Vector< std::string > input_sounding_file
Sounding file path for each configured sounding time.
Definition: ERF_InputSoundingData.H:549
amrex::Real tau_nudging
Nudging time scale for relaxing toward input sounding data.
Definition: ERF_InputSoundingData.H:545
int n_sounding_files
Number of input sounding files.
Definition: ERF_InputSoundingData.H:551
Here is the call graph for this function:

Member Function Documentation

◆ calc_rho_p()

void InputSoundingData::calc_rho_p ( int  itime)
inline

Hydrostatically integrate density and pressure for one sounding.

Parameters
itimeSounding time/file index to integrate.
285  {
286  /* Calculate density and pressure, roughly following the procedure in
287  * WRF dyn_em/module_initialize_ideal.F. We integrate hydrostatically
288  * from the surface up through the air column to get the dry density
289  * and moist pressure.
290  */
291  const int Ninp = size(itime);
292  pm_integ.resize(Ninp);
293  rhod_integ.resize(Ninp);
294 
295  // evaluate surface quantities (k=0): total pressure and dry air
299  RdoCp,
301 
302  amrex::Print() << "ideal sounding init: surface dry air density = "
303  << std::setprecision(15)
304  << rhod_integ[0] << " kg/m^3" << std::endl;
305 
306  // Note:
307  // p_dry = rho_d R_d T
308  // p_tot = rho_m R_d T_v
309  // = rho_d(1 + q_v) R_d T_v
310 
311 #if 0 // Printing
312  // In this absence of moisture, this moist profile will match the
313  // following dry profile
314  amrex::Print() << "z p_m rho_d theta qv U V" << std::endl;
315  amrex::Print() << z_inp_sound[itime][0]
316  << " " << pm_integ[0]
317  << " " << rhod_integ[0]
318  << " " << theta_inp_sound[itime][0]
319  << " " << qv_inp_sound[itime][0]
320  << " " << U_inp_sound[itime][0]
321  << " " << V_inp_sound[itime][0]
322  << std::endl;
323 #endif
324 
325  // integrate from surface to domain top
326  amrex::Real dz, F, C;
327  amrex::Real T_hi;
328  amrex::Real rho_tot_hi, rho_tot_lo;
329  for (int k=1; k < size(itime); ++k)
330  {
331  // Vertical grid spacing
332  dz = z_inp_sound[itime][k] - z_inp_sound[itime][k-1];
333 
334  // The Newton residual F below is a pressure, so the tolerance it is
335  // tested against has to be scaled to the pressure being solved for.
336  // The iterate cannot do better than settle into a one-ulp limit
337  // cycle about the true root, which puts a hard floor of roughly
338  // ulp(p) on |F| -- 3.6e-12 for a 1.6e4 Pa pressure in double, and
339  // ~1e-2 Pa at 1e5 Pa in single. The fixed 1e-12 Pa tolerance used
340  // here previously sat below that floor, so the iteration burned all
341  // of its allowed passes and reported a spurious non-convergence
342  // warning for a column that had in fact converged to roundoff.
343 #ifdef AMREX_USE_FLOAT
344  const amrex::Real tol = amrex::Real(4)
346  * pm_integ[k-1];
347 #else
348  const amrex::Real tol = amrex::Real(1.0e-12);
349 #endif
350 
351  // Establish known constant
352  rho_tot_lo = rhod_integ[k-1] * (one + qv_inp_sound[itime][k-1]);
353  C = -pm_integ[k-1] + myhalf*rho_tot_lo*CONST_GRAV*dz;
354 
355  // Initial guess and residual
356  pm_integ[k] = pm_integ[k-1];
357  T_hi = getTgivenPandTh(pm_integ[k], theta_inp_sound[itime][k], RdoCp);
359  pm_integ[k],
360  RdoCp,
361  qv_inp_sound[itime][k]);
362  rho_tot_hi = rhod_integ[k] * (one + qv_inp_sound[itime][k]);
363  F = pm_integ[k] + myhalf*rho_tot_hi*CONST_GRAV*dz + C;
364 
365  // Do iterations
366  if (std::abs(F)>tol) {
367  bool maintain_Th = true;
369  CONST_GRAV, C, theta_inp_sound[itime][k], T_hi,
370  qv_inp_sound[itime][k], qv_inp_sound[itime][k],
371  pm_integ[k], rhod_integ[k], F, maintain_Th);
372  }
373 
374 #if 0 // Printing
375  amrex::Print() << z_inp_sound[itime][k]
376  << " " << pm_integ[k]
377  << " " << rhod_integ[k]
378  << " " << theta_inp_sound[itime][k]
379  << " " << qv_inp_sound[itime][k]
380  << " " << U_inp_sound[itime][k]
381  << " " << V_inp_sound[itime][k]
382  << std::endl;
383 #endif
384  }
385  // Note: at this point, the surface pressure, density of the dry air
386  // column is stored in pm_integ[0], rhod_integ[0]
387 
388  // update
389  host_to_device(itime);
390  }
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:72
constexpr amrex::Real RdoCp
Definition: ERF_Constants.H:57
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
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
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
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
void host_to_device(int itime)
Copy host sounding arrays for one time index to device storage.
Definition: ERF_InputSoundingData.H:481
amrex::Vector< amrex::Vector< amrex::Real > > V_inp_sound
Interpolated host y velocity profiles.
Definition: ERF_InputSoundingData.H:565
amrex::Vector< amrex::Real > pm_integ
Hydrostatically integrated moist pressure profile.
Definition: ERF_InputSoundingData.H:571
amrex::Real qv_ref_inp_sound
Surface reference water vapor mixing ratio read from the input sounding [kg/kg].
Definition: ERF_InputSoundingData.H:557
amrex::Vector< amrex::Vector< amrex::Real > > theta_inp_sound
Interpolated host potential temperature profiles [K].
Definition: ERF_InputSoundingData.H:565
amrex::Vector< amrex::Real > rhod_integ
Hydrostatically integrated dry density profile.
Definition: ERF_InputSoundingData.H:573
amrex::Vector< amrex::Vector< amrex::Real > > U_inp_sound
Interpolated host x velocity profiles.
Definition: ERF_InputSoundingData.H:565
amrex::Real theta_ref_inp_sound
Surface reference potential temperature read from the input sounding [K].
Definition: ERF_InputSoundingData.H:557
amrex::Vector< amrex::Vector< amrex::Real > > z_inp_sound
Interpolated host sounding heights for each sounding time [m].
Definition: ERF_InputSoundingData.H:565
amrex::Vector< amrex::Vector< amrex::Real > > qv_inp_sound
Interpolated host water vapor mixing ratio profiles [kg/kg].
Definition: ERF_InputSoundingData.H:565
amrex::Real press_ref_inp_sound
Surface reference pressure read from the input sounding [Pa].
Definition: ERF_InputSoundingData.H:557
int size(int itime) const
Return the number of interpolated samples for one sounding time.
Definition: ERF_InputSoundingData.H:525
Here is the call graph for this function:

◆ calc_rho_p_isentropic()

void InputSoundingData::calc_rho_p_isentropic ( int  itime)
inline

Compute density and pressure for an isentropic sounding profile.

Parameters
itimeSounding time/file index to integrate.
397  {
398  /* Calculate density and pressure assuming isentropic (constant theta)
399  background conditions. This does not use Newton-Raphson iterations
400  to calculate rho and p.
401  */
402  const int Ninp = size(itime);
403  pm_integ.resize(Ninp);
404  rhod_integ.resize(Ninp);
405 
406  // evaluate surface quantities (k=0): total pressure and dry air
410  RdoCp,
412 
413  const amrex::Real th0 = theta_ref_inp_sound;
414  const amrex::Real p0_pow = std::pow(p_0, (Gamma-1)/Gamma);
415 
416  amrex::Print() << "isentropic sounding init: surface dry air density = "
417  << std::setprecision(15)
418  << rhod_integ[0] << " kg/m^3" << std::endl;
419 
420 #if 0 // Printing
421  // In this absence of moisture, this moist profile will match the
422  // following dry profile
423  amrex::Print() << "z p_m rho_d theta qv U V" << std::endl;
424  amrex::Print() << z_inp_sound[itime][0]
425  << " " << pm_integ[0]
426  << " " << rhod_integ[0]
427  << " " << theta_inp_sound[itime][0]
428  << " " << qv_inp_sound[itime][0]
429  << " " << U_inp_sound[itime][0]
430  << " " << V_inp_sound[itime][0]
431  << std::endl;
432 #endif
433 
434  // integrate from surface to domain top
435  amrex::Real dz;
436  for (int k=1; k < size(itime); ++k)
437  {
438  // Vertical grid spacing
439  dz = z_inp_sound[itime][k] - z_inp_sound[itime][k-1];
440 
441  // Isentropic pressure at next level
442  amrex::Real qvmean = (assume_dry) ? zero : myhalf*(qv_inp_sound[itime][k-1] + qv_inp_sound[itime][k]);
443  amrex::Real thm0 = th0 * (one + RvoRd * qvmean);
444  amrex::Real plo_pow = std::pow(pm_integ[k-1], (Gamma-1)/Gamma);
445  pm_integ[k] = (Gamma-1)/Gamma *
446  (-CONST_GRAV * p0_pow / (R_d * thm0) * (1 + qvmean) * dz
447  + Gamma/(Gamma-1) * plo_pow);
448  pm_integ[k] = std::pow(pm_integ[k], Gamma / (Gamma-1));
449 
450  // Note: The pressure calculated here is copied to `p_inp_sound_d`
451  // and currently not used.
452 
453  // Get corresponding dry air density
455  pm_integ[k],
456  RdoCp,
457  qv_inp_sound[itime][k]);
458 
459 #if 0 // Printing
460  amrex::Print() << z_inp_sound[itime][k]
461  << " " << pm_integ[k]
462  << " " << rhod_integ[k]
463  << " " << theta_inp_sound[itime][k]
464  << " " << qv_inp_sound[itime][k]
465  << " " << U_inp_sound[itime][k]
466  << " " << V_inp_sound[itime][k]
467  << std::endl;
468 #endif
469  }
470  // Note: at this point, the surface pressure, density of the dry air
471  // column is stored in pm_integ[0], rhod_integ[0]
472 
473  // update
474  host_to_device(itime);
475  }
constexpr amrex::Real p_0
Definition: ERF_Constants.H:69
constexpr amrex::Real RvoRd
Definition: ERF_Constants.H:59
constexpr amrex::Real R_d
Definition: ERF_Constants.H:49
constexpr amrex::Real Gamma
Definition: ERF_Constants.H:70
bool assume_dry
Whether to ignore moisture in isentropic pressure integration.
Definition: ERF_InputSoundingData.H:554
Here is the call graph for this function:

◆ host_to_device()

void InputSoundingData::host_to_device ( int  itime)
inline

Copy host sounding arrays for one time index to device storage.

Parameters
itimeSounding time/file index to copy.
482  {
483  const int Ninp = size(itime);
484  z_inp_sound_d[itime].resize(Ninp);
485  theta_inp_sound_d[itime].resize(Ninp);
486  qv_inp_sound_d[itime].resize(Ninp);
487  U_inp_sound_d[itime].resize(Ninp);
488  V_inp_sound_d[itime].resize(Ninp);
489 
490  amrex::Gpu::copy(amrex::Gpu::hostToDevice,
491  z_inp_sound[itime].begin(), z_inp_sound[itime].end(),
492  z_inp_sound_d[itime].begin());
493  amrex::Gpu::copy(amrex::Gpu::hostToDevice,
494  theta_inp_sound[itime].begin(), theta_inp_sound[itime].end(),
495  theta_inp_sound_d[itime].begin());
496  amrex::Gpu::copy(amrex::Gpu::hostToDevice,
497  qv_inp_sound[itime].begin(), qv_inp_sound[itime].end(),
498  qv_inp_sound_d[itime].begin());
499  amrex::Gpu::copy(amrex::Gpu::hostToDevice,
500  U_inp_sound[itime].begin(), U_inp_sound[itime].end(),
501  U_inp_sound_d[itime].begin());
502  amrex::Gpu::copy(amrex::Gpu::hostToDevice,
503  V_inp_sound[itime].begin(), V_inp_sound[itime].end(),
504  V_inp_sound_d[itime].begin());
505 
506  if (rhod_integ.size() > 0)
507  {
508  //amrex::Print() << "Copying rho_d, p_d to device" << std::endl;
509  rho_inp_sound_d.resize(size(itime)+2);
510  p_inp_sound_d.resize(size(itime)+2);
511  amrex::Gpu::copy(amrex::Gpu::hostToDevice,
512  rhod_integ.begin(), rhod_integ.end(),
513  rho_inp_sound_d.begin());
514  amrex::Gpu::copy(amrex::Gpu::hostToDevice,
515  pm_integ.begin(), pm_integ.end(),
516  p_inp_sound_d.begin());
517  }
518  }
amrex::Gpu::DeviceVector< amrex::Real > rho_inp_sound_d
Device density profile used to initialize solution fields.
Definition: ERF_InputSoundingData.H:575
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > qv_inp_sound_d
Device water vapor mixing ratio profiles [kg/kg].
Definition: ERF_InputSoundingData.H:568
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > V_inp_sound_d
Device y velocity profiles.
Definition: ERF_InputSoundingData.H:568
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > z_inp_sound_d
Device sounding heights for each sounding time [m].
Definition: ERF_InputSoundingData.H:568
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > theta_inp_sound_d
Device potential temperature profiles [K].
Definition: ERF_InputSoundingData.H:568
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > U_inp_sound_d
Device x velocity profiles.
Definition: ERF_InputSoundingData.H:568
amrex::Gpu::DeviceVector< amrex::Real > p_inp_sound_d
Device pressure profile used to initialize solution fields.
Definition: ERF_InputSoundingData.H:575

Referenced by calc_rho_p(), calc_rho_p_isentropic(), and read_from_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_from_file()

void InputSoundingData::read_from_file ( const amrex::Geometry &  geom,
const amrex::Vector< amrex::Real > &  zlevels_stag,
int  itime,
bool  is_moist 
)
inline

Read and interpolate one input sounding profile onto level-0 heights.

Parameters
geomGeometry defining the level-0 vertical domain.
zlevels_stagStaggered vertical coordinates used for interpolation.
itimeSounding time/file index to read.
is_moistWhether the selected physics permits nonzero water vapor.
116  {
117  const int klo = 0;
118  const int khi = geom.Domain().bigEnd()[AMREX_SPACEDIM-1];
119  const int Nz = geom.Domain().size()[AMREX_SPACEDIM-1];
120 
121  const amrex::Real zbot = zlevels_stag[klo];
122  const amrex::Real ztop = zlevels_stag[khi+1];
123 
124  z_inp_sound[itime].resize(Nz+2);
125  theta_inp_sound[itime].resize(Nz+2);
126  qv_inp_sound[itime].resize(Nz+2);
127  U_inp_sound[itime].resize(Nz+2);
128  V_inp_sound[itime].resize(Nz+2);
129 
130  // Read the input_sounding file
131  amrex::Print() << "input_sounding file location : " << input_sounding_file[itime] << std::endl;
132  std::ifstream input_sounding_reader(input_sounding_file[itime]);
133  if(!input_sounding_reader.is_open()) {
134  amrex::Error("Error opening the input_sounding file\n");
135  }
136  else {
137  // Read the contents of the input_sounding file
138  amrex::Print() << "Successfully opened the input_sounding file. Now reading... " << std::endl;
139  std::string line;
140 
141  // First, read the input data into temp vectors; then, interpolate vectors to the
142  // domain lo/hi and cell centers (from level 0)
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;
145 
146  // Read surface quantities from the first line
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;
151  press_sfc *= 100; // convert from hPa to Pa
152  qv_sfc *= amrex::Real(0.001); // convert from g/kg to kg/kg
153 
154  // Only the first sounding sets the base state, the initial state and the surface
155  // layer, so only its surface values are kept in the members. A later sounding's
156  // surface theta and qv are the bottom point of its own profiles, which the nudging
157  // reads; its surface pressure would be used by nothing, so it must be that of the
158  // first sounding (the base state does not change in time)
159  if (itime == 0) {
160  press_ref_inp_sound = press_sfc;
161  theta_ref_inp_sound = theta_sfc;
162  qv_ref_inp_sound = qv_sfc;
163  have_first_surface = true;
164  } else {
166  "InputSoundingData::read_from_file: the first sounding must be read before the others");
167  if (std::abs(press_sfc - press_ref_inp_sound) > surface_pressure_rtol * press_ref_inp_sound) {
168  amrex::Abort("The surface pressure of input sounding " + input_sounding_file[itime] +
169  " (" + std::to_string(press_sfc * amrex::Real(0.01)) + " hPa) differs from that of " +
170  input_sounding_file[0] + " (" + std::to_string(press_ref_inp_sound * amrex::Real(0.01)) +
171  " hPa); the base state is set once from the first sounding, so every "
172  "input sounding must have the same surface pressure");
173  }
174  }
175 
176  // Add surface
177  z_inp_sound_tmp.push_back(zbot); // height above sea level [m]
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);
182 
183  // *************************************************************************************************
184  // Make sure that if we specify surface values for temp in the inputs file and in the input sounding file,
185  // those values must match. The surface layer takes them from the first sounding, so
186  // later soundings, whose surface values may change, are not checked
187  // *************************************************************************************************
188  amrex::ParmParse pp_erf("erf");
189 
190  // Read with query, not queryAdd: ERF_SurfaceLayer.H reads the same keys and
191  // treats a key that is present as given, so adding an absent key here would
192  // make it look given there (and be rejected as non-positive). ERF_SurfaceLayer.H
193  // also rejects a given value that is not positive, so the sentinel test below
194  // is the same as testing that the key was given.
195  // Only a surface potential temperature (most.pot_surf_temp, or the deprecated
196  // most.surf_temp) is comparable to the sounding's surface theta;
197  // most.abs_surf_temp is not checked.
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;
207  amrex::Abort();
208  }
209 
210  // *************************************************************************************************
211  // Make sure that if we specify surface values for qv in the inputs file and in the input sounding file,
212  // those values must match
213  // *************************************************************************************************
214  // Negative sentinel rather than the queryAdd return value: a mixing ratio is
215  // never negative, and ERF_SurfaceLayer.H parses this same key.
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;
222  amrex::Abort();
223  }
224 
225  // Read the vertical profile at each given height
226  amrex::Real z, theta, qv, U, V;
227 
228  while(std::getline(input_sounding_reader, line)) {
229  std::istringstream iss_z(line);
230  iss_z >> z >> theta >> qv >> U >> V;
231 
232  // Dont read in non-zero qv if not using a moisture model
233  AMREX_ALWAYS_ASSERT(qv == zero || is_moist);
234 
235  if (z == zbot) {
236  AMREX_ALWAYS_ASSERT(theta == theta_inp_sound_tmp[0]);
237  AMREX_ALWAYS_ASSERT(qv*amrex::Real(0.001) == qv_inp_sound_tmp[0]); // convert from g/kg to kg/kg
238  U_inp_sound_tmp[0] = U;
239  V_inp_sound_tmp[0] = V;
240  } else {
241  AMREX_ALWAYS_ASSERT(z > z_inp_sound_tmp[z_inp_sound_tmp.size()-1]); // sounding is increasing in height
242  z_inp_sound_tmp.push_back(z);
243 
244  theta_inp_sound_tmp.push_back(theta);
245  qv_inp_sound_tmp.push_back(qv*amrex::Real(0.001)); // convert from g/kg to kg/kg
246  U_inp_sound_tmp.push_back(U);
247  V_inp_sound_tmp.push_back(V);
248  if (z >= ztop) break;
249  }
250  }
251 
252  // At this point, we have an input_sounding from zbot up to
253  // z_inp_sound_tmp[N-1] >= ztop. Now, interpolate to grid level 0 heights
254  const int Ninp = z_inp_sound_tmp.size();
255  z_inp_sound[itime][0] = zbot;
256  theta_inp_sound[itime][0] = theta_inp_sound_tmp[0];
257  qv_inp_sound[itime][0] = qv_inp_sound_tmp[0];
258  U_inp_sound[itime][0] = U_inp_sound_tmp[0];
259  V_inp_sound[itime][0] = V_inp_sound_tmp[0];
260  for (int k=0; k < Nz; ++k) {
261  z_inp_sound[itime][k+1] = myhalf * (zlevels_stag[k] + zlevels_stag[k+1]);
262  theta_inp_sound[itime][k+1] = interpolate_1d(z_inp_sound_tmp.dataPtr(), theta_inp_sound_tmp.dataPtr(), z_inp_sound[itime][k+1], Ninp);
263  qv_inp_sound[itime][k+1] = interpolate_1d(z_inp_sound_tmp.dataPtr(), qv_inp_sound_tmp.dataPtr(), z_inp_sound[itime][k+1], Ninp);
264  U_inp_sound[itime][k+1] = interpolate_1d(z_inp_sound_tmp.dataPtr(), U_inp_sound_tmp.dataPtr(), z_inp_sound[itime][k+1], Ninp);
265  V_inp_sound[itime][k+1] = interpolate_1d(z_inp_sound_tmp.dataPtr(), V_inp_sound_tmp.dataPtr(), z_inp_sound[itime][k+1], Ninp);
266  }
267  z_inp_sound[itime][Nz+1] = ztop;
268  theta_inp_sound[itime][Nz+1] = interpolate_1d(z_inp_sound_tmp.dataPtr(), theta_inp_sound_tmp.dataPtr(), ztop, Ninp);
269  qv_inp_sound[itime][Nz+1] = interpolate_1d(z_inp_sound_tmp.dataPtr(), qv_inp_sound_tmp.dataPtr(), ztop, Ninp);
270  U_inp_sound[itime][Nz+1] = interpolate_1d(z_inp_sound_tmp.dataPtr(), U_inp_sound_tmp.dataPtr(), ztop, Ninp);
271  V_inp_sound[itime][Nz+1] = interpolate_1d(z_inp_sound_tmp.dataPtr(), V_inp_sound_tmp.dataPtr(), ztop, Ninp);
272  }
273 
274  amrex::Print() << "Successfully read the " << itime << "th input_sounding file..." << std::endl;
275  input_sounding_reader.close();
276 
277  host_to_device(itime);
278  }
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
@ theta
Definition: ERF_Kessler.H:26
@ qv
Definition: ERF_Kessler.H:31
@ U
Definition: ERF_IndexDefines.H:178
@ V
Definition: ERF_IndexDefines.H:179
bool have_first_surface
Whether the surface line of the first sounding has been read into the members above.
Definition: ERF_InputSoundingData.H:558
static constexpr amrex::Real surface_pressure_rtol
Relative tolerance on the surface pressure of a later sounding against the first one.
Definition: ERF_InputSoundingData.H:562
Here is the call graph for this function:

◆ resize_arrays()

void InputSoundingData::resize_arrays ( )
inline

Check the sounding files and times, and resize the host and device sounding arrays.

The checks are made here rather than in the constructor, which runs whatever erf.init_type is: they then apply only to a run that reads the soundings.

74  {
75  // One time per file, in increasing order: the nudging interpolates between consecutive
76  // soundings in time
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");
81  }
82  for (int n = 1; n < n_sounding_times; ++n) {
84  amrex::Abort("erf.input_sounding_time must be strictly increasing, but time " +
85  std::to_string(n) + " (" + std::to_string(input_sounding_time[n]) +
86  ") is not later than time " + std::to_string(n-1) + " (" +
87  std::to_string(input_sounding_time[n-1]) + ")");
88  }
89  }
90 
92 
93  z_inp_sound.resize(ntimes);
94  theta_inp_sound.resize(ntimes);
95  qv_inp_sound.resize(ntimes);
96  U_inp_sound.resize(ntimes);
97  V_inp_sound.resize(ntimes);
98 
99  z_inp_sound_d.resize(ntimes);
100  theta_inp_sound_d.resize(ntimes);
101  qv_inp_sound_d.resize(ntimes);
102  U_inp_sound_d.resize(ntimes);
103  V_inp_sound_d.resize(ntimes);
104  }
int ntimes
Number of sounding times represented in the arrays.
Definition: ERF_InputSoundingData.H:543

◆ set_start_time()

void InputSoundingData::set_start_time ( amrex::Real  start_time)
inline
535  {
536  for (int i = 0; i < n_sounding_times; i++)
537  {
538  input_sounding_time[i] += start_time;
539  }
540  }

◆ size()

int InputSoundingData::size ( int  itime) const
inline

Return the number of interpolated samples for one sounding time.

Parameters
itimeSounding time/file index to query.
Returns
Number of stored sounding profile levels.
526  {
528  AMREX_ALWAYS_ASSERT(z_inp_sound[itime].size() == qv_inp_sound[itime].size());
529  AMREX_ALWAYS_ASSERT(z_inp_sound[itime].size() == U_inp_sound[itime].size());
530  AMREX_ALWAYS_ASSERT(z_inp_sound[itime].size() == V_inp_sound[itime].size());
531  return z_inp_sound[itime].size();
532  }

Referenced by calc_rho_p(), calc_rho_p_isentropic(), host_to_device(), init_state_from_input_sounding(), init_state_from_input_sounding_hse(), init_velocities_from_input_sounding(), and ERF::setRayleighRefFromSounding_at_level().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ assume_dry

InputSoundingData::assume_dry {false}

Whether to ignore moisture in isentropic pressure integration.

Referenced by calc_rho_p_isentropic(), and init_state_from_input_sounding_hse().

◆ have_first_surface

InputSoundingData::have_first_surface {false}

Whether the surface line of the first sounding has been read into the members above.

Referenced by read_from_file().

◆ input_sounding_file

InputSoundingData::input_sounding_file = {}

Sounding file path for each configured sounding time.

Referenced by InputSoundingData(), and read_from_file().

◆ input_sounding_time

InputSoundingData::input_sounding_time = {}

Physical time associated with each input sounding file.

Referenced by ERF::advance_dycore(), InputSoundingData(), make_mom_sources(), resize_arrays(), and set_start_time().

◆ n_sounding_files

InputSoundingData::n_sounding_files = 0

Number of input sounding files.

Referenced by InputSoundingData(), and resize_arrays().

◆ n_sounding_times

InputSoundingData::n_sounding_times = 0

Number of input sounding times.

Referenced by InputSoundingData(), resize_arrays(), and set_start_time().

◆ ntimes

InputSoundingData::ntimes

Number of sounding times represented in the arrays.

Referenced by resize_arrays().

◆ p_inp_sound_d

InputSoundingData::p_inp_sound_d

Device pressure profile used to initialize solution fields.

Referenced by host_to_device().

◆ pm_integ

InputSoundingData::pm_integ

Hydrostatically integrated moist pressure profile.

Referenced by calc_rho_p(), calc_rho_p_isentropic(), host_to_device(), and LargeScaleForcingData::interp_forcing().

◆ press_ref_inp_sound

InputSoundingData::press_ref_inp_sound

Surface reference pressure read from the input sounding [Pa].

Referenced by calc_rho_p(), calc_rho_p_isentropic(), and read_from_file().

◆ qv_inp_sound

InputSoundingData::qv_inp_sound

Interpolated host water vapor mixing ratio profiles [kg/kg].

Referenced by calc_rho_p(), calc_rho_p_isentropic(), host_to_device(), read_from_file(), resize_arrays(), and size().

◆ qv_inp_sound_d

InputSoundingData::qv_inp_sound_d

◆ qv_ref_inp_sound

InputSoundingData::qv_ref_inp_sound

Surface reference water vapor mixing ratio read from the input sounding [kg/kg].

Referenced by calc_rho_p(), calc_rho_p_isentropic(), and read_from_file().

◆ rho_inp_sound_d

InputSoundingData::rho_inp_sound_d

Device density profile used to initialize solution fields.

Referenced by host_to_device(), and init_state_from_input_sounding_hse().

◆ rhod_integ

InputSoundingData::rhod_integ

Hydrostatically integrated dry density profile.

Referenced by calc_rho_p(), calc_rho_p_isentropic(), and host_to_device().

◆ surface_pressure_rtol

InputSoundingData::surface_pressure_rtol = amrex::Real(1.e-6)
staticconstexpr

Relative tolerance on the surface pressure of a later sounding against the first one.

Referenced by read_from_file().

◆ tau_nudging

InputSoundingData::tau_nudging = amrex::Real(5.0)

Nudging time scale for relaxing toward input sounding data.

Referenced by ERF::advance_dycore(), InputSoundingData(), and make_mom_sources().

◆ theta_above_ground

bool InputSoundingData::theta_above_ground {false}

◆ theta_inp_sound

InputSoundingData::theta_inp_sound

Interpolated host potential temperature profiles [K].

Referenced by calc_rho_p(), calc_rho_p_isentropic(), host_to_device(), read_from_file(), resize_arrays(), ERF::setRayleighRefFromSounding_at_level(), and size().

◆ theta_inp_sound_d

InputSoundingData::theta_inp_sound_d

◆ theta_ref_inp_sound

InputSoundingData::theta_ref_inp_sound

Surface reference potential temperature read from the input sounding [K].

Referenced by calc_rho_p(), calc_rho_p_isentropic(), and read_from_file().

◆ U_inp_sound

InputSoundingData::U_inp_sound

◆ U_inp_sound_d

InputSoundingData::U_inp_sound_d

◆ V_inp_sound

InputSoundingData::V_inp_sound

◆ V_inp_sound_d

InputSoundingData::V_inp_sound_d

◆ wind_above_ground

bool InputSoundingData::wind_above_ground {false}

◆ z_inp_sound

InputSoundingData::z_inp_sound

◆ z_inp_sound_d

InputSoundingData::z_inp_sound_d

The documentation for this struct was generated from the following file: