ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InputSoundingData.H
Go to the documentation of this file.
1 #ifndef ERF_INPUT_SOUNDING_DATA_H_
2 #define ERF_INPUT_SOUNDING_DATA_H_
3 
4 #include <limits>
5 #include <string>
6 #include <iostream>
7 
8 #include <AMReX_ParmParse.H>
9 #include <AMReX_Print.H>
10 #include <AMReX_Gpu.H>
11 #include <AMReX_Geometry.H>
12 
13 #include <ERF_EOS.H>
14 #include <ERF_Constants.H>
15 #include <ERF_Interpolation_1D.H>
16 #include <ERF_HSEUtils.H>
17 
18 /**
19  * Data structure storing input sounding data. Also
20  * handles reading the input file for sounding data and
21  * hydrostatic column integration.
22  */
24 public:
25  /**
26  * @brief Construct input sounding metadata from the ERF input namespace.
27  */
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  }
66 
67  /**
68  * @brief Check the sounding files and times, and resize the host and device sounding arrays.
69  *
70  * The checks are made here rather than in the constructor, which runs whatever erf.init_type
71  * is: they then apply only to a run that reads the soundings.
72  */
73  void resize_arrays ()
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  }
105 
106  /**
107  * @brief Read and interpolate one input sounding profile onto level-0 heights.
108  * @param geom Geometry defining the level-0 vertical domain.
109  * @param zlevels_stag Staggered vertical coordinates used for interpolation.
110  * @param itime Sounding time/file index to read.
111  * @param is_moist Whether the selected physics permits nonzero water vapor.
112  */
113  void read_from_file (const amrex::Geometry &geom,
114  const amrex::Vector<amrex::Real>& zlevels_stag,
115  int itime, bool is_moist)
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  }
279 
280  /**
281  * @brief Hydrostatically integrate density and pressure for one sounding.
282  * @param itime Sounding time/file index to integrate.
283  */
284  void calc_rho_p (int itime)
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  }
391 
392  /**
393  * @brief Compute density and pressure for an isentropic sounding profile.
394  * @param itime Sounding time/file index to integrate.
395  */
396  void calc_rho_p_isentropic (int itime)
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  }
476 
477  /**
478  * @brief Copy host sounding arrays for one time index to device storage.
479  * @param itime Sounding time/file index to copy.
480  */
481  void host_to_device (int itime)
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  }
519 
520  /**
521  * @brief Return the number of interpolated samples for one sounding time.
522  * @param itime Sounding time/file index to query.
523  * @return Number of stored sounding profile levels.
524  */
525  int size (int itime) const
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  }
533 
534  void set_start_time (amrex::Real start_time)
535  {
536  for (int i = 0; i < n_sounding_times; i++)
537  {
538  input_sounding_time[i] += start_time;
539  }
540  }
541 
542  // Members
543  int ntimes;
544 
545  amrex::Real tau_nudging = amrex::Real(5.0); // time scale used for nudging
546  bool wind_above_ground{false}; // sounding winds by height above the local terrain
547  bool theta_above_ground{false}; // sounding theta by height above the local terrain
548 
549  amrex::Vector<std::string> input_sounding_file = {};
550  amrex::Vector<amrex::Real> input_sounding_time = {};
553 
554  bool assume_dry{false};
555 
556  // - read from file: the surface line of the first sounding
558  bool have_first_surface{false};
559 
560  // Relative difference allowed between the surface pressure of a later sounding and that of
561  // the first sounding
562  static constexpr amrex::Real surface_pressure_rtol = amrex::Real(1.e-6);
563 
564  // This is a vector (over time) of Vectors
565  amrex::Vector<amrex::Vector<amrex::Real>> z_inp_sound, theta_inp_sound, qv_inp_sound, U_inp_sound, V_inp_sound;
566 
567  // This is a vector (over time) of DeviceVectors
568  amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real>> z_inp_sound_d, theta_inp_sound_d, qv_inp_sound_d, U_inp_sound_d, V_inp_sound_d;
569 
570  // - moist profiles
571  amrex::Vector<amrex::Real> pm_integ; // from integrating up air column
572  // - dry profiles
573  amrex::Vector<amrex::Real> rhod_integ; // from integrating down air column
574  // - to set solution fields
575  amrex::Gpu::DeviceVector<amrex::Real> p_inp_sound_d, rho_inp_sound_d;
576 };
577 
578 /**
579  * @var InputSoundingData::ntimes
580  * @brief Number of sounding times represented in the arrays.
581  * @var InputSoundingData::tau_nudging
582  * @brief Nudging time scale for relaxing toward input sounding data.
583  * @var InputSoundingData::input_sounding_file
584  * @brief Sounding file path for each configured sounding time.
585  * @var InputSoundingData::input_sounding_time
586  * @brief Physical time associated with each input sounding file.
587  * @var InputSoundingData::n_sounding_files
588  * @brief Number of input sounding files.
589  * @var InputSoundingData::n_sounding_times
590  * @brief Number of input sounding times.
591  * @var InputSoundingData::assume_dry
592  * @brief Whether to ignore moisture in isentropic pressure integration.
593  * @var InputSoundingData::press_ref_inp_sound
594  * @brief Surface reference pressure read from the input sounding [Pa].
595  * @var InputSoundingData::theta_ref_inp_sound
596  * @brief Surface reference potential temperature read from the input sounding [K].
597  * @var InputSoundingData::qv_ref_inp_sound
598  * @brief Surface reference water vapor mixing ratio read from the input sounding [kg/kg].
599  * @var InputSoundingData::have_first_surface
600  * @brief Whether the surface line of the first sounding has been read into the members above.
601  * @var InputSoundingData::surface_pressure_rtol
602  * @brief Relative tolerance on the surface pressure of a later sounding against the first one.
603  * @var InputSoundingData::z_inp_sound
604  * @brief Interpolated host sounding heights for each sounding time [m].
605  * @var InputSoundingData::theta_inp_sound
606  * @brief Interpolated host potential temperature profiles [K].
607  * @var InputSoundingData::qv_inp_sound
608  * @brief Interpolated host water vapor mixing ratio profiles [kg/kg].
609  * @var InputSoundingData::U_inp_sound
610  * @brief Interpolated host x velocity profiles.
611  * @var InputSoundingData::V_inp_sound
612  * @brief Interpolated host y velocity profiles.
613  * @var InputSoundingData::z_inp_sound_d
614  * @brief Device sounding heights for each sounding time [m].
615  * @var InputSoundingData::theta_inp_sound_d
616  * @brief Device potential temperature profiles [K].
617  * @var InputSoundingData::qv_inp_sound_d
618  * @brief Device water vapor mixing ratio profiles [kg/kg].
619  * @var InputSoundingData::U_inp_sound_d
620  * @brief Device x velocity profiles.
621  * @var InputSoundingData::V_inp_sound_d
622  * @brief Device y velocity profiles.
623  * @var InputSoundingData::pm_integ
624  * @brief Hydrostatically integrated moist pressure profile.
625  * @var InputSoundingData::rhod_integ
626  * @brief Hydrostatically integrated dry density profile.
627  * @var InputSoundingData::p_inp_sound_d
628  * @brief Device pressure profile used to initialize solution fields.
629  * @var InputSoundingData::rho_inp_sound_d
630  * @brief Device density profile used to initialize solution fields.
631  */
632 #endif
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")
ParmParse pp("prob")
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
Definition: ERF_InputSoundingData.H:23
bool have_first_surface
Whether the surface line of the first sounding has been read into the members above.
Definition: ERF_InputSoundingData.H:558
void host_to_device(int itime)
Copy host sounding arrays for one time index to device storage.
Definition: ERF_InputSoundingData.H:481
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::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::Real > input_sounding_time
Physical time associated with each input sounding file.
Definition: ERF_InputSoundingData.H:550
void resize_arrays()
Check the sounding files and times, and resize the host and device sounding arrays.
Definition: ERF_InputSoundingData.H:73
bool assume_dry
Whether to ignore moisture in isentropic pressure integration.
Definition: ERF_InputSoundingData.H:554
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
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
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
void set_start_time(amrex::Real start_time)
Definition: ERF_InputSoundingData.H:534
void calc_rho_p(int itime)
Hydrostatically integrate density and pressure for one sounding.
Definition: ERF_InputSoundingData.H:284
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
void calc_rho_p_isentropic(int itime)
Compute density and pressure for an isentropic sounding profile.
Definition: ERF_InputSoundingData.H:396
int ntimes
Number of sounding times represented in the arrays.
Definition: ERF_InputSoundingData.H:543
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.
Definition: ERF_InputSoundingData.H:113
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > theta_inp_sound_d
Device potential temperature profiles [K].
Definition: ERF_InputSoundingData.H:568
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< std::string > input_sounding_file
Sounding file path for each configured sounding time.
Definition: ERF_InputSoundingData.H:549
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
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 tau_nudging
Nudging time scale for relaxing toward input sounding data.
Definition: ERF_InputSoundingData.H:545
InputSoundingData()
Construct input sounding metadata from the ERF input namespace.
Definition: ERF_InputSoundingData.H:28
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
int n_sounding_files
Number of input sounding files.
Definition: ERF_InputSoundingData.H:551