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

#include <ERF_SampleData.H>

Collaboration diagram for LineSampler:

Classes

struct  InterpPlan
 

Public Member Functions

 LineSampler ()
 
 LineSampler (const amrex::Vector< amrex::IntVect > &cells, const amrex::Vector< std::string > &log_names, const amrex::Box &domain)
 
 LineSampler (const amrex::Vector< amrex::IntVect > &cells, const amrex::Vector< amrex::RealVect > &points, const amrex::Vector< std::string > &log_names, bool z_agl)
 
void open_logs (const amrex::Vector< std::string > &log_names)
 Open one log per line, appended to, on the I/O rank. More...
 
void expand_conserved (int ncons)
 Replace "conserved" by one name per component of the conserved state, cons_0, cons_1, ... More...
 
void open_ascii_streams ()
 
bool uses_latlon () const
 Whether the lines are given by latitude and longitude (erf.sample_line_lo/hi_latlon) More...
 
void resolve_latlon (const LatLonMap &latlon_map, const amrex::Geometry &geom0)
 
bool needs_ground () const
 
void check_interp_heights (int iline) const
 Abort unless the number of heights of line iline suits its ends (erf.sample_line_interp) More...
 
amrex::Vector< amrex::Real > interp_heights (int iline) const
 
amrex::Box interp_sample_box (int iline, const amrex::Box &cols) const
 The samples of line iline, along its direction: its heights (vertical) or its columns (horizontal) More...
 
InterpPlan make_interp_plan (int iline, int lev, const amrex::Geometry &geom, const amrex::Geometry &geom0, const amrex::MultiFab &z_cc, const amrex::MultiFab *z_nd, const amrex::MultiFab *volfrac, const amrex::MultiFab *ground, const amrex::MultiFab *ground0) const
 
const InterpPlan & cachedInterpPlan (int iline, int lev, const amrex::Geometry &geom, const amrex::Geometry &geom0, const amrex::MultiFab &z_cc, const amrex::MultiFab *z_nd, const amrex::MultiFab *volfrac, const amrex::MultiFab *ground, const amrex::MultiFab *ground0)
 make_interp_plan, kept until the grids of the level change More...
 
amrex::MultiFab interp_line_data (int iline, const InterpPlan &plan, const amrex::MultiFab &data, int z_comp, int vf_comp) const
 
bool use_column_heights () const
 
amrex::Real line_ground (int iline, const amrex::Geometry &geom0, const amrex::MultiFab *ground_nd)
 The ground under line iline, found once: level 0 and the terrain do not change. More...
 
const amrex::Box & cachedLineIndexBox (int iline, int lev, const amrex::Geometry &geom, const amrex::MultiFab &z_nd, amrex::Real ground)
 
amrex::Box lineIndexBox (int iline, const amrex::Geometry &geom, const amrex::MultiFab &z_nd, amrex::Real ground)
 
amrex::Box getIndexBox (const amrex::RealBox &real_box, const amrex::Geometry &geom)
 
void write_coords (amrex::Vector< std::unique_ptr< amrex::MultiFab > > &z_phys_cc, amrex::Vector< std::unique_ptr< amrex::MultiFab > > &z_phys_nd, amrex::Vector< amrex::Geometry > &geom, const amrex::MultiFab *ground_nd=nullptr, const amrex::Vector< const amrex::MultiFab * > &ground_lev={}, const amrex::Vector< const amrex::MultiFab * > &volfrac_lev={})
 
void get_sample_data (amrex::Vector< amrex::Geometry > &geom, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_new, const amrex::Vector< amrex::Vector< amrex::MultiFab * >> &tau_lev={}, const amrex::Vector< amrex::MultiFab * > &hfx3_lev={}, const amrex::Vector< int > &prognostic_tke_available={}, const amrex::Vector< amrex::MultiFab * > &z_cc_lev={}, const amrex::Vector< amrex::MultiFab * > &z_nd_lev={}, const amrex::MultiFab *ground_nd=nullptr, const amrex::Vector< const amrex::MultiFab * > &volfrac_lev={}, const amrex::Vector< const amrex::MultiFab * > &ground_lev={})
 
void write_sample_data (amrex::Vector< double > &time, amrex::Vector< int > &level_steps, amrex::Vector< amrex::IntVect > &ref_ratio, amrex::Vector< amrex::Geometry > &geom)
 
void write_line_log (amrex::Vector< double > &time)
 One row per line in its log: the time, then each variable along the line. More...
 
void write_line_ascii (amrex::Vector< double > &time)
 
void write_line_plotfile (amrex::Vector< double > &time, amrex::Vector< int > &level_steps, amrex::Vector< amrex::IntVect > &ref_ratio, amrex::Vector< amrex::Geometry > &geom)
 

Static Public Member Functions

static const amrex::Vector< std::string > & line_sampling_var_order ()
 The variables that may be sampled, in the order they are stored and written. More...
 
static amrex::Vector< amrex::Real > gather_box (const amrex::MultiFab &src, int scomp, int ncomp, const amrex::Box &bx, bool to_all)
 
static const amrex::MultiFab * level_ptr (const amrex::Vector< const amrex::MultiFab * > &v, int lev)
 The entry of level lev, or nullptr past the end. More...
 
static amrex::Vector< amrex::Gpu::HostVector< amrex::Real > > column_face_heights (const amrex::MultiFab &z_nd, const amrex::Geometry &geom, const amrex::IntVect &cell)
 
static amrex::Real column_ground (const amrex::MultiFab &ground_nd, const amrex::Geometry &geom, const amrex::IntVect &cell)
 
static amrex::Box lineIndexBoxXY (const amrex::RealBox &rb, const amrex::Geometry &geom)
 The cells of a real box in x and y on a level, with k = 0: its k comes from heights. More...
 

Public Attributes

amrex::Vector< int > m_dir
 
amrex::Vector< int > m_lev
 
amrex::Vector< amrex::Box > m_bnd_bx
 
amrex::Vector< amrex::RealBox > m_bnd_rbx
 
amrex::Vector< amrex::MultiFab > m_ls_mf
 
amrex::Vector< std::string > m_name
 
bool m_use_real_bx {false}
 
bool m_use_latlon {false}
 
amrex::Vector< amrex::Real > m_latlon_lo
 
amrex::Vector< amrex::Real > m_latlon_hi
 
bool m_write_ascii {false}
 
bool m_write_log {false}
 
bool m_z_agl {false}
 
bool m_interp {false}
 
amrex::Vector< int > m_npts
 
amrex::Real m_covered_value {sampling_covered_value()}
 
int m_max_level {-1}
 
int m_ncons {-1}
 
amrex::Vector< std::string > m_varnames {"magvel","theta"}
 
amrex::Vector< std::unique_ptr< std::fstream > > m_datastream
 
amrex::Vector< std::unique_ptr< std::fstream > > m_logstream
 
amrex::Vector< amrex::Real > m_ground
 
amrex::Vector< amrex::Vector< amrex::Box > > m_box_cache
 
amrex::Vector< amrex::Vector< int > > m_box_cache_found
 
amrex::Vector< amrex::BoxArray > m_box_cache_ba
 
amrex::Vector< amrex::BoxArray > m_zcc_ba
 
amrex::Vector< amrex::Vector< InterpPlan > > m_interp_plan
 

Constructor & Destructor Documentation

◆ LineSampler() [1/3]

LineSampler::LineSampler ( )
inline
58  {
59  amrex::ParmParse pp("erf");
60 
61  bool has_line_idx = pp.contains("sample_line_lo") || pp.contains("sample_line_hi");
62  bool has_line_real = pp.contains("sample_line_lo_real") || pp.contains("sample_line_hi_real");
63  bool has_line_latlon = pp.contains("sample_line_lo_latlon") || pp.contains("sample_line_hi_latlon");
64  if (int(has_line_idx) + int(has_line_real) + int(has_line_latlon) > 1) {
65  amrex::Abort("Specify only one of erf.sample_line_lo/hi, erf.sample_line_lo_real/hi_real"
66  " or erf.sample_line_lo_latlon/hi_latlon");
67  }
68 
69  // Count number of lo and hi points define the line
70  int n_line_lo = pp.countval("sample_line_lo") / AMREX_SPACEDIM;
71  int n_line_hi = pp.countval("sample_line_hi") / AMREX_SPACEDIM;
72  int n_line_lo_real = pp.countval("sample_line_lo_real") / AMREX_SPACEDIM;
73  int n_line_hi_real = pp.countval("sample_line_hi_real") / AMREX_SPACEDIM;
74  int n_line_lo_latlon = pp.countval("sample_line_lo_latlon") / 3;
75  int n_line_hi_latlon = pp.countval("sample_line_hi_latlon") / 3;
76  int n_line_dir = pp.countval("sample_line_dir");
77  if (has_line_idx) {
78  AMREX_ALWAYS_ASSERT( (n_line_lo==n_line_hi ) &&
79  (n_line_lo==n_line_dir) );
80  } else if (has_line_real) {
81  AMREX_ALWAYS_ASSERT( (n_line_lo_real==n_line_hi_real ) &&
82  (n_line_lo_real==n_line_dir) );
83  } else if (has_line_latlon) {
84  if (pp.countval("sample_line_lo_latlon") != 3*n_line_lo_latlon ||
85  pp.countval("sample_line_hi_latlon") != 3*n_line_hi_latlon ||
86  n_line_lo_latlon != n_line_hi_latlon || n_line_lo_latlon != n_line_dir) {
87  amrex::Abort("erf.sample_line_lo_latlon and erf.sample_line_hi_latlon must each give"
88  " lat, long and z for every line of erf.sample_line_dir");
89  }
90  }
91 
92  // Parse the data
93  int nline = 0;
94  if (has_line_idx) {
95  nline = n_line_lo;
96  if (nline > 0) {
97  // Parse lo
98  amrex::Vector<int> idx_lo; idx_lo.resize(nline*AMREX_SPACEDIM);
99  amrex::Vector<amrex::IntVect> iv_lo; iv_lo.resize(nline);
100  pp.queryarr("sample_line_lo",idx_lo,0,nline*AMREX_SPACEDIM);
101  for (int i(0); i < nline; i++) {
102  amrex::IntVect iv(idx_lo[AMREX_SPACEDIM*i+0],
103  idx_lo[AMREX_SPACEDIM*i+1],
104  idx_lo[AMREX_SPACEDIM*i+2]);
105  iv_lo[i] = iv;
106  }
107 
108  // Parse hi
109  amrex::Vector<int> idx_hi; idx_hi.resize(nline*AMREX_SPACEDIM);
110  amrex::Vector<amrex::IntVect> iv_hi; iv_hi.resize(nline);
111  pp.queryarr("sample_line_hi",idx_hi,0,nline*AMREX_SPACEDIM);
112  for (int i(0); i < nline; i++) {
113  amrex::IntVect iv(idx_hi[AMREX_SPACEDIM*i+0],
114  idx_hi[AMREX_SPACEDIM*i+1],
115  idx_hi[AMREX_SPACEDIM*i+2]);
116  iv_hi[i] = iv;
117  }
118 
119  // Construct vector of bounding boxes
120  m_bnd_bx.resize(nline);
121  for (int i = 0; i < nline; i++){
122  amrex::Box lbx(iv_lo[i],iv_hi[i]);
123  m_bnd_bx[i] = lbx;
124  }
125 
126  // The indices are those of level 0; on a finer level the same indices are
127  // somewhere else, so these lines are sampled on level 0 only
128  m_max_level = 0;
129  int amr_max_level = 0;
130  amrex::ParmParse("amr").query("max_level", amr_max_level);
131  if (amr_max_level > 0) {
132  amrex::Print() << "Line sampling: erf.sample_line_lo/hi are level-0 indices, so "
133  << "these lines are sampled on level 0 only; give "
134  << "erf.sample_line_lo_real/hi_real to sample the finest level "
135  << "that holds a line" << std::endl;
136  }
137  }
138  } else if (has_line_real) {
139  m_use_real_bx = true;
140  nline = n_line_lo_real;
141  if (nline > 0) {
142  // Parse lo
143  amrex::Vector<amrex::Real> real_lo; real_lo.resize(nline*AMREX_SPACEDIM);
144  amrex::Vector<amrex::Vector<amrex::Real>> rv_lo;
145  pp.queryarr("sample_line_lo_real",real_lo,0,nline*AMREX_SPACEDIM);
146  for (int i(0); i < nline; i++) {
147  amrex::Vector<amrex::Real> rv = {real_lo[AMREX_SPACEDIM*i+0],
148  real_lo[AMREX_SPACEDIM*i+1],
149  real_lo[AMREX_SPACEDIM*i+2]};
150  rv_lo.push_back(rv);
151  }
152 
153  // Parse hi
154  amrex::Vector<amrex::Real> real_hi; real_hi.resize(nline*AMREX_SPACEDIM);
155  amrex::Vector<amrex::Vector<amrex::Real>> rv_hi;
156  pp.queryarr("sample_line_hi_real",real_hi,0,nline*AMREX_SPACEDIM);
157  for (int i(0); i < nline; i++) {
158  amrex::Vector<amrex::Real> rv = {real_hi[AMREX_SPACEDIM*i+0],
159  real_hi[AMREX_SPACEDIM*i+1],
160  real_hi[AMREX_SPACEDIM*i+2]};
161  rv_hi.push_back(rv);
162  }
163 
164  // Construct vector of bounding real boxes
165  m_bnd_rbx.resize(nline);
166  for (int i = 0; i < nline; i++){
167  amrex::RealBox rbx(rv_lo[i].data(),rv_hi[i].data());
168  m_bnd_rbx[i] = rbx;
169  }
170 
171  // Construct vector of bounding boxes
172  m_bnd_bx.resize(nline);
173  }
174  } else if (has_line_latlon) {
175  // The ends are turned into domain coordinates by resolve_latlon, once the run
176  // has its latitude/longitude arrays; until then the line is not along any
177  // direction, so its ends are checked there
178  m_use_real_bx = true;
179  m_use_latlon = true;
180  nline = n_line_lo_latlon;
181  if (nline > 0) {
182  pp.getarr("sample_line_lo_latlon", m_latlon_lo, 0, 3*nline);
183  pp.getarr("sample_line_hi_latlon", m_latlon_hi, 0, 3*nline);
184  m_bnd_rbx.resize(nline);
185  m_bnd_bx.resize(nline);
186  }
187  }
188 
189  if (nline > 0) {
190  // Parse directionality
191  m_dir.resize(n_line_dir);
192  pp.queryarr("sample_line_dir",m_dir,0,n_line_dir);
193 
194  // A line runs along one direction: its two ends must agree in the other two, or
195  // the sampler would take a slab of cells and add them up at each point
196  for (int iline(0); iline<nline; ++iline) {
197  const int dir = m_dir[iline];
198  if (dir < 0 || dir >= AMREX_SPACEDIM) {
199  amrex::Abort("erf.sample_line_dir must be 0, 1 or 2");
200  }
201  if (m_use_latlon) { continue; }
202  for (int d(0); d<AMREX_SPACEDIM; ++d) {
203  const bool differ = has_line_idx
204  ? (m_bnd_bx[iline].smallEnd(d) != m_bnd_bx[iline].bigEnd(d))
205  : (m_bnd_rbx[iline].lo(d) != m_bnd_rbx[iline].hi(d));
206  const bool reversed = has_line_idx
207  ? (m_bnd_bx[iline].smallEnd(d) > m_bnd_bx[iline].bigEnd(d))
208  : (m_bnd_rbx[iline].lo(d) > m_bnd_rbx[iline].hi(d));
209  if (d != dir && differ) {
210  amrex::Abort("Line " + std::to_string(iline) + " of erf.sample_line_lo/hi"
211  + std::string(has_line_idx ? "" : "_real")
212  + " is not along erf.sample_line_dir: its ends differ in direction "
213  + std::to_string(d));
214  }
215  if (d == dir && reversed) {
216  amrex::Abort("Line " + std::to_string(iline) + " of erf.sample_line_lo/hi"
217  + std::string(has_line_idx ? "" : "_real")
218  + " has its lo end above its hi end");
219  }
220  }
221  }
222 
223  // Parse names
224  std::string name_base = "plt_line_";
225  m_name.resize(nline);
226  int n_names = pp.countval("sample_line_name");
227  if (n_names > 0) {
228  AMREX_ALWAYS_ASSERT( n_names==nline );
229  pp.queryarr("sample_line_name",m_name,0,n_names);
230  } else {
231  for (int iline(0); iline<nline; ++iline) {
232  m_name[iline] = amrex::Concatenate(name_base, iline , 5);
233  }
234  }
235 
236  // Allocate space for level indicator
237  m_lev.resize(n_line_dir,0);
238 
239  // Allocate space for MF pointers
240  m_ls_mf.resize(nline);
241 
242  // Get requested vars. They are stored, sampled and written in the order of
243  // line_sampling_var_order(), whatever order they are requested in
244  if (pp.countval("line_sampling_vars") > 0) {
245  m_varnames.clear();
246  amrex::Vector<std::string> requested_vars;
247  pp.queryarr("line_sampling_vars",requested_vars);
248  amrex::Print() << "Selected line sampling vars :";
249  for (const auto& name : line_sampling_var_order()) {
250  if (containerHasElement(requested_vars, name)) {
251  m_varnames.push_back(name);
252  amrex::Print() << " " << name;
253  }
254  }
255  amrex::Print() << std::endl;
256  }
257 
258  // Write outputs to text files, one file per variable, with all
259  // times appended to the same file. The files are opened at the first
260  // write, once "conserved" has been expanded into its components
261  pp.queryAdd("line_sampling_text_output",m_write_ascii);
262 
263  // The z of erf.sample_line_lo_real/hi_real of a vertical line is the height above
264  // the ground under it instead of the height above sea level
265  pp.queryAdd("sample_line_z_agl",m_z_agl);
266 
267  // Interpolate to the requested heights rather than take the cells that hold them:
268  // a vertical line at erf.sample_line_npts heights from its lo z to its hi z, a
269  // horizontal line at its z in every column it crosses
270  pp.queryAdd("sample_line_interp",m_interp);
271  if (m_interp) {
272  if (!m_use_real_bx) {
273  amrex::Abort("erf.sample_line_interp needs lines given by heights, with "
274  "erf.sample_line_lo_real/hi_real or erf.sample_line_lo_latlon/hi_latlon; "
275  "a line given by erf.sample_line_lo/hi names cells, not heights");
276  }
277  m_npts.assign(nline, 0);
278  const int n_npts = pp.countval("sample_line_npts");
279  if (n_npts > 0) {
280  if (n_npts != nline) {
281  amrex::Abort("erf.sample_line_npts must give one value per line (0 for a horizontal line)");
282  }
283  pp.getarr("sample_line_npts", m_npts, 0, nline);
284  } else {
285  // A vertical line whose two ends are at one height is sampled at that height
286  for (int iline(0); iline<nline; ++iline) {
287  if (m_dir[iline] == 2) { m_npts[iline] = 1; }
288  }
289  }
290  // The heights of lines given by latitude and longitude are checked once they are placed
291  if (!m_use_latlon) {
292  for (int iline(0); iline<nline; ++iline) { check_interp_heights(iline); }
293  }
294  } else if (pp.contains("sample_line_npts")) {
295  amrex::Abort("erf.sample_line_npts is used only with erf.sample_line_interp = true");
296  }
297 
298  // The cells of a line placed by height are found once, so they do not follow a
299  // mesh that moves; lines given by indices do not use heights
301  SolverChoice::terrain_type == TerrainType::MovingFittedMesh) {
302  amrex::Abort("Line sampling with erf.sample_line_lo_real/hi_real is not supported "
303  "with erf.terrain_type = MovingFittedMesh");
304  }
305 
306  // Where the levels are not equally spaced, the z of the plotfile of a line is not
307  // the height of its samples, so the height is written with them; an interpolated
308  // line writes the height of each sample above sea level on any mesh
309  if ((SolverChoice::mesh_type != MeshType::ConstantDz || m_interp) &&
310  !containerHasElement(m_varnames, std::string("z"))) {
311  const bool cons_first = !m_varnames.empty() && m_varnames[0] == "conserved";
312  m_varnames.insert(m_varnames.begin() + (cons_first ? 1 : 0), "z");
313  }
314  }
315  }
bool containerHasElement(const V &iterable, const T &query)
Definition: ERF_Container.H:5
ParmParse pp("prob")
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
amrex::Vector< std::string > m_varnames
Definition: ERF_SampleData.H:1710
amrex::Vector< amrex::MultiFab > m_ls_mf
Definition: ERF_SampleData.H:1696
amrex::Vector< amrex::Real > m_latlon_lo
Definition: ERF_SampleData.H:1701
int m_max_level
Definition: ERF_SampleData.H:1708
bool m_interp
Definition: ERF_SampleData.H:1705
bool m_use_real_bx
Definition: ERF_SampleData.H:1699
amrex::Vector< int > m_dir
Definition: ERF_SampleData.H:1692
bool use_column_heights() const
Definition: ERF_SampleData.H:897
bool m_z_agl
Definition: ERF_SampleData.H:1704
amrex::Vector< int > m_npts
Definition: ERF_SampleData.H:1706
amrex::Vector< std::string > m_name
Definition: ERF_SampleData.H:1697
void check_interp_heights(int iline) const
Abort unless the number of heights of line iline suits its ends (erf.sample_line_interp)
Definition: ERF_SampleData.H:556
amrex::Vector< amrex::Real > m_latlon_hi
Definition: ERF_SampleData.H:1701
static const amrex::Vector< std::string > & line_sampling_var_order()
The variables that may be sampled, in the order they are stored and written.
Definition: ERF_SampleData.H:425
amrex::Vector< amrex::Box > m_bnd_bx
Definition: ERF_SampleData.H:1694
bool m_use_latlon
Definition: ERF_SampleData.H:1700
bool m_write_ascii
Definition: ERF_SampleData.H:1702
amrex::Vector< amrex::RealBox > m_bnd_rbx
Definition: ERF_SampleData.H:1695
amrex::Vector< int > m_lev
Definition: ERF_SampleData.H:1693
static MeshType mesh_type
Vertical mesh representation.
Definition: ERF_DataStruct.H:3004
static TerrainType terrain_type
Terrain or immersed-boundary representation.
Definition: ERF_DataStruct.H:2989
Here is the call graph for this function:

◆ LineSampler() [2/3]

LineSampler::LineSampler ( const amrex::Vector< amrex::IntVect > &  cells,
const amrex::Vector< std::string > &  log_names,
const amrex::Box &  domain 
)
inline

Sample the full-depth vertical column through each cell on level 0, with the variables erf.sample_line writes: every conserved component, the cell-centered velocities and the six stresses at cell centers. Each column is written to its own log, one row per sample: the time, then each variable over the column, bottom to top.

Parameters
[in]cellsa cell in each column; its k is ignored
[in]log_namesthe log file of each column
[in]domainthe level-0 domain
330  {
331  AMREX_ALWAYS_ASSERT(cells.size() == log_names.size());
332  const int nline = static_cast<int>(cells.size());
333  constexpr int dir = 2;
334 
335  m_bnd_bx.resize(nline);
336  for (int iline(0); iline<nline; ++iline) {
337  amrex::IntVect lo(cells[iline]); lo[dir] = domain.smallEnd(dir);
338  amrex::IntVect hi(cells[iline]); hi[dir] = domain.bigEnd(dir);
339  m_bnd_bx[iline] = amrex::Box(lo, hi);
340  }
341  m_dir.assign(nline, dir);
342  m_lev.assign(nline, 0);
343  m_ls_mf.resize(nline);
344  m_name = log_names;
345  m_max_level = 0;
346  m_varnames = {"conserved", "x_velocity", "y_velocity", "z_velocity",
347  "sgs_tau11", "sgs_tau12", "sgs_tau13", "sgs_tau22", "sgs_tau23", "sgs_tau33"};
348 
349  open_logs(log_names);
350  }
void open_logs(const amrex::Vector< std::string > &log_names)
Open one log per line, appended to, on the I/O rank.
Definition: ERF_SampleData.H:406
Here is the call graph for this function:

◆ LineSampler() [3/3]

LineSampler::LineSampler ( const amrex::Vector< amrex::IntVect > &  cells,
const amrex::Vector< amrex::RealVect > &  points,
const amrex::Vector< std::string > &  log_names,
bool  z_agl 
)
inline

Sample single cells with every conserved component, as erf.sample_point does: each point is written to its own log, one row per sample, the time and then each component. A point given by a cell (erf.sample_point) is that cell of level 0. A point given by real coordinates (erf.sample_point_real, or erf.sample_point_latlon once placed) is a line of one cell, sampled on the finest level that holds it; on a stretched or terrain-fitted mesh its cell is found from the heights of its column, and with z_agl its z is the height above the ground under it.

Parameters
[in]cellsthe cell of each point given by indices, or empty
[in]pointsthe (x,y,z) of each point given by real coordinates, or empty
[in]log_namesthe log file of each point
[in]z_aglwhether the z of points are heights above the ground
370  {
371  AMREX_ALWAYS_ASSERT(cells.empty() || points.empty());
372  const int nline = static_cast<int>(log_names.size());
373  AMREX_ALWAYS_ASSERT(static_cast<int>(cells.size() + points.size()) == nline);
374 
375  m_bnd_bx.resize(nline);
376  if (!cells.empty()) {
377  for (int iline(0); iline<nline; ++iline) {
378  m_bnd_bx[iline] = amrex::Box(cells[iline], cells[iline]);
379  }
380  m_max_level = 0;
381  } else {
382  m_use_real_bx = true;
383  m_z_agl = z_agl;
384  m_bnd_rbx.resize(nline);
385  for (int iline(0); iline<nline; ++iline) {
386  m_bnd_rbx[iline] = amrex::RealBox(points[iline].dataPtr(), points[iline].dataPtr());
387  }
388  // As for lines placed by height, the cells are found once
389  if (use_column_heights() && SolverChoice::terrain_type == TerrainType::MovingFittedMesh) {
390  amrex::Abort("erf.sample_point_real and erf.sample_point_latlon are not supported "
391  "with erf.terrain_type = MovingFittedMesh");
392  }
393  }
394  // A point is a vertical line of one cell
395  m_dir.assign(nline, 2);
396  m_lev.assign(nline, 0);
397  m_ls_mf.resize(nline);
398  m_name = log_names;
399  m_varnames = {"conserved"};
400 
401  open_logs(log_names);
402  }
Here is the call graph for this function:

Member Function Documentation

◆ cachedInterpPlan()

const InterpPlan& LineSampler::cachedInterpPlan ( int  iline,
int  lev,
const amrex::Geometry &  geom,
const amrex::Geometry &  geom0,
const amrex::MultiFab &  z_cc,
const amrex::MultiFab *  z_nd,
const amrex::MultiFab *  volfrac,
const amrex::MultiFab *  ground,
const amrex::MultiFab *  ground0 
)
inline

make_interp_plan, kept until the grids of the level change

837  {
838  if (lev >= static_cast<int>(m_interp_plan.size())) { m_interp_plan.resize(lev+1); }
839  auto& plans = m_interp_plan[lev];
840  const int nline = static_cast<int>(m_bnd_rbx.size());
841  if (static_cast<int>(plans.size()) != nline) { plans.assign(nline, InterpPlan{}); }
842  if (plans[iline].ba.empty() || !(plans[iline].ba == z_cc.boxArray())) {
843  plans[iline] = make_interp_plan(iline, lev, geom, geom0, z_cc, z_nd, volfrac, ground, ground0);
844  }
845  return plans[iline];
846  }
amrex::Vector< amrex::Vector< InterpPlan > > m_interp_plan
Definition: ERF_SampleData.H:1723
InterpPlan make_interp_plan(int iline, int lev, const amrex::Geometry &geom, const amrex::Geometry &geom0, const amrex::MultiFab &z_cc, const amrex::MultiFab *z_nd, const amrex::MultiFab *volfrac, const amrex::MultiFab *ground, const amrex::MultiFab *ground0) const
Definition: ERF_SampleData.H:659
Here is the call graph for this function:

◆ cachedLineIndexBox()

const amrex::Box& LineSampler::cachedLineIndexBox ( int  iline,
int  lev,
const amrex::Geometry &  geom,
const amrex::MultiFab &  z_nd,
amrex::Real  ground 
)
inline

lineIndexBox, found once per level and kept until the grids of the level change: the mesh does not move, so only which cells the level holds can change

988  {
989  if (lev >= static_cast<int>(m_box_cache.size())) {
990  m_box_cache.resize(lev+1);
991  m_box_cache_found.resize(lev+1);
992  m_box_cache_ba.resize(lev+1);
993  }
994  const int nline = static_cast<int>(m_bnd_rbx.size());
995  if (static_cast<int>(m_box_cache[lev].size()) != nline || !(m_box_cache_ba[lev] == z_nd.boxArray())) {
996  m_box_cache[lev].assign(nline, amrex::Box());
997  m_box_cache_found[lev].assign(nline, 0);
998  m_box_cache_ba[lev] = z_nd.boxArray();
999  }
1000  if (m_box_cache_found[lev][iline] == 0) {
1001  m_box_cache[lev][iline] = lineIndexBox(iline, geom, z_nd, ground);
1002  m_box_cache_found[lev][iline] = 1;
1003  }
1004  return m_box_cache[lev][iline];
1005  }
amrex::Vector< amrex::Vector< int > > m_box_cache_found
Definition: ERF_SampleData.H:1718
amrex::Vector< amrex::BoxArray > m_box_cache_ba
Definition: ERF_SampleData.H:1719
amrex::Vector< amrex::Vector< amrex::Box > > m_box_cache
Definition: ERF_SampleData.H:1717
amrex::Box lineIndexBox(int iline, const amrex::Geometry &geom, const amrex::MultiFab &z_nd, amrex::Real ground)
Definition: ERF_SampleData.H:1016
Here is the call graph for this function:

◆ check_interp_heights()

void LineSampler::check_interp_heights ( int  iline) const
inline

Abort unless the number of heights of line iline suits its ends (erf.sample_line_interp)

557  {
558  const std::string line = "Line " + std::to_string(iline) + " of erf.sample_line_interp";
559  const int n = m_npts[iline];
560  const amrex::RealBox& rb = m_bnd_rbx[iline];
561  if (m_dir[iline] != 2) {
562  if (n != 0) {
563  amrex::Abort(line + " is horizontal, so it is sampled once in every column it crosses: "
564  "its erf.sample_line_npts must be 0");
565  }
566  } else if (n < 1) {
567  amrex::Abort(line + " is vertical: give erf.sample_line_npts, the number of heights (at least 1)");
568  } else if (n == 1 && rb.lo(2) != rb.hi(2)) {
569  amrex::Abort(line + " has one height, so its lo z and hi z must be equal; give erf.sample_line_npts "
570  "of at least 2 for heights from its lo z to its hi z");
571  } else if (n > 1 && !(rb.lo(2) < rb.hi(2))) {
572  amrex::Abort(line + " has " + std::to_string(n) + " heights, so its lo z must be below its hi z");
573  }
574  }

Referenced by LineSampler(), and resolve_latlon().

Here is the caller graph for this function:

◆ column_face_heights()

static amrex::Vector<amrex::Gpu::HostVector<amrex::Real> > LineSampler::column_face_heights ( const amrex::MultiFab &  z_nd,
const amrex::Geometry &  geom,
const amrex::IntVect &  cell 
)
inlinestatic

The heights of the faces of the column through cell (i,j) on a level, from the nodal heights z_nd: the lower face of each cell, its upper face, and 1 where the level holds the cell (0 where it does not). Each is indexed from the bottom of the domain.

910  {
911  const amrex::Box& dom = geom.Domain();
912  amrex::IntVect lo(cell); lo[2] = dom.smallEnd(2);
913  amrex::IntVect hi(cell); hi[2] = dom.bigEnd(2);
914  const amrex::Box col(lo, hi);
915 
916  amrex::MultiFab f(amrex::convert(z_nd.boxArray(), amrex::IntVect(0)),
917  z_nd.DistributionMap(), 3, 0);
918  f.setVal(amrex::Real(0.0));
919  for (amrex::MFIter mfi(f); mfi.isValid(); ++mfi) {
920  const amrex::Box b = mfi.validbox() & col;
921  if (!b.ok()) { continue; }
922  const auto& out = f.array(mfi);
923  const auto& z = z_nd.const_array(mfi);
924  amrex::ParallelFor(b, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
925  out(i,j,k,0) = amrex::Real(0.25) * (z(i,j,k ) + z(i+1,j,k ) + z(i,j+1,k ) + z(i+1,j+1,k ));
926  out(i,j,k,1) = amrex::Real(0.25) * (z(i,j,k+1) + z(i+1,j,k+1) + z(i,j+1,k+1) + z(i+1,j+1,k+1));
927  out(i,j,k,2) = amrex::Real(1.0);
928  });
929  }
930  return {amrex::sumToLine(f, 0, 1, col, 2), amrex::sumToLine(f, 1, 1, col, 2),
931  amrex::sumToLine(f, 2, 1, col, 2)};
932  }
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})

Referenced by lineIndexBox().

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

◆ column_ground()

static amrex::Real LineSampler::column_ground ( const amrex::MultiFab &  ground_nd,
const amrex::Geometry &  geom,
const amrex::IntVect &  cell 
)
inlinestatic

The height of the ground under cell (i,j) of level 0: the mean of the four nodes at the bottom of its column in ground_nd, which is z_phys_nd or, with immersed terrain, the terrain surface (ERF::station_ground)

942  {
943  const int i = cell[0], j = cell[1], k = geom.Domain().smallEnd(2);
944  amrex::ReduceOps<amrex::ReduceOpSum> reduce_op;
945  amrex::ReduceData<amrex::Real> reduce_data(reduce_op);
946  for (amrex::MFIter mfi(ground_nd); mfi.isValid(); ++mfi) {
947  // The nodal box that holds the cell, so that a node shared by two boxes counts once
948  const amrex::Box& vb = mfi.validbox();
949  if (i < vb.smallEnd(0) || i >= vb.bigEnd(0) ||
950  j < vb.smallEnd(1) || j >= vb.bigEnd(1) ||
951  k < vb.smallEnd(2) || k > vb.bigEnd(2)) { continue; }
952  const auto& z = ground_nd.const_array(mfi);
953  reduce_op.eval(amrex::Box(amrex::IntVect(i,j,k), amrex::IntVect(i,j,k)), reduce_data,
954  [=] AMREX_GPU_DEVICE (int ii, int jj, int kk) -> amrex::GpuTuple<amrex::Real> {
955  return { amrex::Real(0.25) * (z(ii,jj,kk) + z(ii+1,jj,kk) + z(ii,jj+1,kk) + z(ii+1,jj+1,kk)) };
956  });
957  }
958  amrex::Real ground = amrex::get<0>(reduce_data.value(reduce_op));
959  amrex::ParallelAllReduce::Sum(ground, amrex::ParallelContext::CommunicatorSub());
960  return ground;
961  }

Referenced by line_ground().

Here is the caller graph for this function:

◆ expand_conserved()

void LineSampler::expand_conserved ( int  ncons)
inline

Replace "conserved" by one name per component of the conserved state, cons_0, cons_1, ...

437  {
438  auto it = std::find(m_varnames.begin(), m_varnames.end(), std::string("conserved"));
439  if (it == m_varnames.end()) { m_ncons = 0; return; }
440  amrex::Vector<std::string> names;
441  for (int n(0); n<ncons; ++n) { names.push_back(amrex::Concatenate("cons_", n, 1)); }
442  it = m_varnames.erase(it);
443  m_varnames.insert(it, names.begin(), names.end());
444  m_ncons = ncons;
445  }
int m_ncons
Definition: ERF_SampleData.H:1709

◆ gather_box()

static amrex::Vector<amrex::Real> LineSampler::gather_box ( const amrex::MultiFab &  src,
int  scomp,
int  ncomp,
const amrex::Box &  bx,
bool  to_all 
)
inlinestatic

Components scomp .. scomp+ncomp-1 of src over the cells (or nodes) of bx, in the order of a FArrayBox on bx, on the I/O rank, and on every rank with to_all. Collective.

607  {
608  const int io = amrex::ParallelDescriptor::IOProcessorNumber();
609  amrex::MultiFab dst(amrex::BoxArray(bx), amrex::DistributionMapping(amrex::Vector<int>{io}),
610  ncomp, 0, amrex::MFInfo().SetArena(amrex::The_Pinned_Arena()));
611  dst.setVal(amrex::Real(0.0));
612  dst.ParallelCopy(src, scomp, 0, ncomp);
613  amrex::Gpu::streamSynchronize();
614  amrex::Vector<amrex::Real> v(static_cast<std::size_t>(bx.numPts()) * ncomp, amrex::Real(0.0));
615  if (amrex::ParallelDescriptor::IOProcessor()) {
616  const amrex::Real* p = dst[0].dataPtr();
617  std::copy(p, p + v.size(), v.begin());
618  }
619  if (to_all) { amrex::ParallelDescriptor::Bcast(v.data(), v.size(), io); }
620  return v;
621  }
@ p
Definition: ERF_WSM6.H:303

Referenced by interp_line_data(), and make_interp_plan().

Here is the caller graph for this function:

◆ get_sample_data()

void LineSampler::get_sample_data ( amrex::Vector< amrex::Geometry > &  geom,
amrex::Vector< amrex::Vector< amrex::MultiFab >> &  vars_new,
const amrex::Vector< amrex::Vector< amrex::MultiFab * >> &  tau_lev = {},
const amrex::Vector< amrex::MultiFab * > &  hfx3_lev = {},
const amrex::Vector< int > &  prognostic_tke_available = {},
const amrex::Vector< amrex::MultiFab * > &  z_cc_lev = {},
const amrex::Vector< amrex::MultiFab * > &  z_nd_lev = {},
const amrex::MultiFab *  ground_nd = nullptr,
const amrex::Vector< const amrex::MultiFab * > &  volfrac_lev = {},
const amrex::Vector< const amrex::MultiFab * > &  ground_lev = {} 
)
inline
1179  {},
1180  const amrex::Vector<amrex::MultiFab*>& hfx3_lev = {},
1181  const amrex::Vector<int>& prognostic_tke_available = {},
1182  const amrex::Vector<amrex::MultiFab*>& z_cc_lev = {},
1183  const amrex::Vector<amrex::MultiFab*>& z_nd_lev = {},
1184  const amrex::MultiFab* ground_nd = nullptr,
1185  const amrex::Vector<const amrex::MultiFab*>& volfrac_lev = {},
1186  const amrex::Vector<const amrex::MultiFab*>& ground_lev = {})
1187  {
1188  if (m_ncons < 0) { expand_conserved(vars_new[0][Vars::cons].nComp()); }
1189 
1190  int nlev = sampling_num_levels(vars_new);
1191  if (m_max_level >= 0) { nlev = std::min(nlev, m_max_level + 1); }
1192  int nline = static_cast<int>(m_bnd_bx.size());
1193  int ncomp = static_cast<int>(m_varnames.size());
1194 
1195  int qv_comp = -1;
1196 
1197  // The stress tau_type on level ilev, or nullptr where it is not stored
1198  auto get_tau = [&] (int ilev, int tau_type) -> amrex::MultiFab* {
1199  if (ilev >= static_cast<int>(tau_lev.size()) ||
1200  tau_type >= static_cast<int>(tau_lev[ilev].size())) { return nullptr; }
1201  return tau_lev[ilev][tau_type];
1202  };
1203 
1204  // For a line given by real coordinates, its cells come from the heights of the column
1205  // through its first point, and a height above ground from the ground under it
1206  const bool by_height = m_use_real_bx && use_column_heights();
1207  if (by_height) {
1208  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!z_nd_lev.empty() && z_nd_lev[0] != nullptr,
1209  "Line sampling by height needs the nodal heights of each level");
1210  }
1211  // An interpolated line is sampled on the finest level that holds every cell it reads
1212  auto interp_plan = [&] (int iline, int ilev) -> const InterpPlan& {
1213  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ilev < static_cast<int>(z_cc_lev.size()) && z_cc_lev[ilev] != nullptr,
1214  "Line sampling with erf.sample_line_interp needs the cell-centre heights of each level");
1215  const amrex::MultiFab* z_nd = ilev < static_cast<int>(z_nd_lev.size()) ? z_nd_lev[ilev] : nullptr;
1216  return cachedInterpPlan(iline, ilev, geom[ilev], geom[0], *z_cc_lev[ilev], z_nd,
1217  level_ptr(volfrac_lev, ilev), level_ptr(ground_lev, ilev), ground_nd);
1218  };
1219  auto line_box = [&] (int iline, int ilev) -> amrex::Box {
1220  if (m_interp) {
1221  const InterpPlan& plan = interp_plan(iline, ilev);
1222  return plan.holds ? plan.cols : amrex::Box();
1223  }
1224  if (by_height) {
1225  if (ilev >= static_cast<int>(z_nd_lev.size()) || z_nd_lev[ilev] == nullptr) { return amrex::Box(); }
1226  return cachedLineIndexBox(iline, ilev, geom[ilev], *z_nd_lev[ilev],
1227  line_ground(iline, geom[0], ground_nd));
1228  }
1229  return (m_use_real_bx) ? getIndexBox(m_bnd_rbx[iline], geom[ilev]) : m_bnd_bx[iline];
1230  };
1231 
1232  // Search each level, from the finest, to get the finest data possible. The data of a
1233  // level are built once for all the lines that are sampled there
1234  amrex::Vector<int> done(nline, 0);
1235  for (int ilev(nlev-1); ilev>=0; --ilev) {
1236  amrex::Vector<int> lines;
1237  amrex::Vector<amrex::Box> boxes;
1238  for (int iline(0); iline<nline; ++iline) {
1239  if (done[iline] != 0) { continue; }
1240  const amrex::Box bnd_bx = line_box(iline, ilev);
1241  if (bnd_bx.isEmpty()) { continue; }
1242  lines.push_back(iline);
1243  boxes.push_back(bnd_bx);
1244  }
1245  if (lines.empty()) { continue; }
1246 
1247  // Construct CC velocities
1248  amrex::MultiFab mf_cc_vel;
1249  auto ba = vars_new[ilev][Vars::cons].boxArray();
1250  auto dm = vars_new[ilev][Vars::cons].DistributionMap();
1251  mf_cc_vel.define(ba, dm, AMREX_SPACEDIM, amrex::IntVect(1,1,1));
1252  average_face_to_cellcenter(mf_cc_vel,0,
1253  amrex::Array<const amrex::MultiFab*,3>{&vars_new[ilev][Vars::xvel],
1254  &vars_new[ilev][Vars::yvel],
1255  &vars_new[ilev][Vars::zvel]});
1256 
1257  // Construct MultiFab holding requested variables
1258  amrex::MultiFab mf_cc_data;
1259  mf_cc_data.define(ba, dm, ncomp, 1);
1260 
1261  int mf_comp = 0;
1262  int z_comp = -1;
1263  int vf_comp = -1;
1264 
1265  // The raw conserved components, cons_0, cons_1, ..., come first
1266  if (m_ncons > 0) {
1267  amrex::MultiFab::Copy(mf_cc_data, vars_new[ilev][Vars::cons], 0, mf_comp, m_ncons, 0);
1268  mf_comp += m_ncons;
1269  }
1270 
1271  // The height of each cell center
1272  if (containerHasElement(m_varnames, std::string("z"))) {
1273  amrex::MultiFab* z_cc = ilev < static_cast<int>(z_cc_lev.size()) ? z_cc_lev[ilev] : nullptr;
1274  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(z_cc != nullptr,
1275  "Line sampling of z needs the cell-centre heights of each level");
1276  amrex::MultiFab::Copy(mf_cc_data, *z_cc, 0, mf_comp, 1, 0);
1277  z_comp = mf_comp;
1278  mf_comp += 1;
1279  }
1280 
1281  // The volume fraction of each cell: 1 without immersed terrain, 0 where covered
1282  const amrex::MultiFab* volfrac = ilev < static_cast<int>(volfrac_lev.size())
1283  ? volfrac_lev[ilev] : nullptr;
1284  if (containerHasElement(m_varnames, std::string("volfrac"))) {
1285  if (volfrac != nullptr) {
1286  amrex::MultiFab::Copy(mf_cc_data, *volfrac, 0, mf_comp, 1, 0);
1287  } else {
1288  mf_cc_data.setVal(1.0, mf_comp, 1, 0);
1289  }
1290  vf_comp = mf_comp;
1291  mf_comp += 1;
1292  }
1293 
1294  if (containerHasElement(m_varnames, "density")) {
1295  amrex::MultiFab::Copy(mf_cc_data, vars_new[ilev][Vars::cons], Rho_comp, mf_comp, 1, 0);
1296  mf_comp += 1;
1297  }
1298 
1299  if (containerHasElement(m_varnames, "x_velocity")) {
1300  amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 0, mf_comp, 1, 0);
1301  mf_comp += 1;
1302  }
1303  if (containerHasElement(m_varnames, "y_velocity")) {
1304  amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 1, mf_comp, 1, 0);
1305  mf_comp += 1;
1306  }
1307  if (containerHasElement(m_varnames, "z_velocity")) {
1308  amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 2, mf_comp, 1, 0);
1309  mf_comp += 1;
1310  }
1311 
1312  if (containerHasElement(m_varnames, "magvel")) {
1313 #ifdef _OPENMP
1314 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1315 #endif
1316  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1317  const amrex::Box& tbx = mfi.tilebox();
1318  auto const& dfab = mf_cc_data.array(mfi);
1319  auto const& vfab = mf_cc_vel.array(mfi);
1320 
1321  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1322  {
1323  dfab(i,j,k,mf_comp) = std::sqrt(vfab(i,j,k,0)*vfab(i,j,k,0)
1324  + vfab(i,j,k,1)*vfab(i,j,k,1)
1325  + vfab(i,j,k,2)*vfab(i,j,k,2)) ;
1326  });
1327  }
1328  mf_comp += 1;
1329  }
1330 
1331  if (containerHasElement(m_varnames, "theta")) {
1332 #ifdef _OPENMP
1333 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1334 #endif
1335  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1336  const amrex::Box& tbx = mfi.tilebox();
1337  auto const& dfab = mf_cc_data.array(mfi);
1338  auto const& cfab = vars_new[ilev][Vars::cons].array(mfi);
1339 
1340  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1341  {
1342  dfab(i,j,k,mf_comp) = cfab(i,j,k,RhoTheta_comp) / cfab(i,j,k,Rho_comp);
1343  });
1344  }
1345  mf_comp += 1;
1346  }
1347 
1348  if (containerHasElement(m_varnames, "qv")) {
1349  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(vars_new[ilev][Vars::cons].nComp() > RhoQ1_comp,
1350  "qv sampling requested but moisture components not present in state");
1351  if (qv_comp >= 0) AMREX_ALWAYS_ASSERT(qv_comp == mf_comp);
1352  qv_comp = mf_comp;
1353 #ifdef _OPENMP
1354 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1355 #endif
1356  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1357  const amrex::Box& tbx = mfi.tilebox();
1358  auto const& dfab = mf_cc_data.array(mfi);
1359  auto const& cfab = vars_new[ilev][Vars::cons].array(mfi);
1360 
1361  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1362  {
1363  dfab(i,j,k,mf_comp) = cfab(i,j,k,RhoQ1_comp) / cfab(i,j,k,Rho_comp);
1364  });
1365  }
1366  mf_comp += 1;
1367  }
1368  if (containerHasElement(m_varnames, "qc")) {
1369  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(vars_new[ilev][Vars::cons].nComp() > RhoQ2_comp,
1370  "qc sampling requested but moisture components not present in state");
1371 #ifdef _OPENMP
1372 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1373 #endif
1374  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1375  const amrex::Box& tbx = mfi.tilebox();
1376  auto const& dfab = mf_cc_data.array(mfi);
1377  auto const& cfab = vars_new[ilev][Vars::cons].array(mfi);
1378 
1379  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1380  {
1381  dfab(i,j,k,mf_comp) = cfab(i,j,k,RhoQ2_comp) / cfab(i,j,k,Rho_comp);
1382  });
1383  }
1384  mf_comp += 1;
1385  }
1386 
1387  if (containerHasElement(m_varnames, "pressure")) {
1388  if (vars_new[ilev][Vars::cons].nComp() > RhoQ1_comp) {
1389  // moist pressure: use qv from dfab if already sampled, else compute inline
1390 #ifdef _OPENMP
1391 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1392 #endif
1393  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1394  const amrex::Box& tbx = mfi.tilebox();
1395  auto const& dfab = mf_cc_data.array(mfi);
1396  auto const& cfab = vars_new[ilev][Vars::cons].array(mfi);
1397 
1398  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1399  {
1400  amrex::Real qv_val = (qv_comp >= 0) ? dfab(i,j,k,qv_comp)
1401  : cfab(i,j,k,RhoQ1_comp) / cfab(i,j,k,Rho_comp);
1402  dfab(i,j,k,mf_comp) = getPgivenRTh(cfab(i,j,k,RhoTheta_comp), qv_val);
1403  });
1404  }
1405  } else {
1406  // dry pressure
1407 #ifdef _OPENMP
1408 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1409 #endif
1410  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1411  const amrex::Box& tbx = mfi.tilebox();
1412  auto const& dfab = mf_cc_data.array(mfi);
1413  auto const& cfab = vars_new[ilev][Vars::cons].array(mfi);
1414 
1415  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1416  {
1417  dfab(i,j,k,mf_comp) = getPgivenRTh(cfab(i,j,k,RhoTheta_comp));
1418  });
1419  }
1420  }
1421  mf_comp += 1;
1422  }
1423 
1424  if (containerHasElement(m_varnames, "sgs_tke")) {
1425  const bool tke_available =
1426  ilev < static_cast<int>(prognostic_tke_available.size()) &&
1427  prognostic_tke_available[ilev] != 0;
1428  if (!tke_available) {
1429  mf_cc_data.setVal(amrex::Real(0.0), mf_comp, 1, 0);
1430  } else {
1431 #ifdef _OPENMP
1432 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1433 #endif
1434  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1435  const amrex::Box& tbx = mfi.tilebox();
1436  const auto& out = mf_cc_data.array(mfi);
1437  const auto& state = vars_new[ilev][Vars::cons].const_array(mfi);
1438  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
1439  out(i,j,k,mf_comp) = state(i,j,k,RhoKE_comp) / state(i,j,k,Rho_comp);
1440  });
1441  }
1442  }
1443  mf_comp += 1;
1444  }
1445 
1446  // The stresses at cell centers: tau11, tau22 and tau33 are stored there, and the
1447  // others are averaged from the four edges around the cell
1448  auto sample_tau = [&] (const char* name, int tau_type,
1449  amrex::IntVect const& e1, amrex::IntVect const& e2) {
1450  if (!containerHasElement(m_varnames, std::string(name))) { return; }
1451  amrex::MultiFab* tau = get_tau(ilev, tau_type);
1452  if (tau != nullptr) {
1453  const bool at_centre = (e1 == amrex::IntVect(0));
1454  const int comp = mf_comp;
1455  const int ax = e1[0], ay = e1[1], az = e1[2];
1456  const int bx = e2[0], by = e2[1], bz = e2[2];
1457 #ifdef _OPENMP
1458 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1459 #endif
1460  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1461  const amrex::Box& tbx = mfi.tilebox();
1462  const auto& out = mf_cc_data.array(mfi);
1463  const auto& t = tau->const_array(mfi);
1464  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
1465  out(i,j,k,comp) = at_centre ? t(i,j,k) : amrex::Real(0.25) *
1466  (t(i,j,k) + t(i+ax,j+ay,k+az) +
1467  t(i+bx,j+by,k+bz) + t(i+ax+bx,j+ay+by,k+az+bz));
1468  });
1469  }
1470  } else {
1471  mf_cc_data.setVal(0.0, mf_comp, 1, 0);
1472  }
1473  mf_comp += 1;
1474  };
1475  const amrex::IntVect ex(1,0,0), ey(0,1,0), ez(0,0,1), e0(0);
1476  sample_tau("sgs_tau11", TauType::tau11, e0, e0);
1477  sample_tau("sgs_tau12", TauType::tau12, ex, ey);
1478  sample_tau("sgs_tau13", TauType::tau13, ex, ez);
1479  sample_tau("sgs_tau22", TauType::tau22, e0, e0);
1480  sample_tau("sgs_tau23", TauType::tau23, ey, ez);
1481  sample_tau("sgs_tau33", TauType::tau33, e0, e0);
1482 
1483  if (containerHasElement(m_varnames, "sgs_hfx3")) {
1484  amrex::MultiFab* hfx3 = ilev < static_cast<int>(hfx3_lev.size())
1485  ? hfx3_lev[ilev] : nullptr;
1486  if (hfx3 != nullptr) {
1487 #ifdef _OPENMP
1488 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1489 #endif
1490  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1491  const amrex::Box& tbx = mfi.tilebox();
1492  const auto& out = mf_cc_data.array(mfi);
1493  const auto& hfx = hfx3->const_array(mfi);
1494  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
1495  out(i,j,k,mf_comp) = amrex::Real(0.5) * (hfx(i,j,k) + hfx(i,j,k+1));
1496  });
1497  }
1498  } else {
1499  mf_cc_data.setVal(0.0, mf_comp, 1, 0);
1500  }
1501  mf_comp += 1;
1502  }
1503 
1504  // A cell covered by immersed terrain holds no fluid, so every variable but its
1505  // height and volume fraction is written there as erf.sampling_covered_value
1506  if (volfrac != nullptr) {
1507  const amrex::Real covered_value = m_covered_value;
1508 #ifdef _OPENMP
1509 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1510 #endif
1511  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1512  const amrex::Box& tbx = mfi.tilebox();
1513  const auto& out = mf_cc_data.array(mfi);
1514  const auto& vf = volfrac->const_array(mfi);
1515  amrex::ParallelFor(tbx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept {
1516  if (vf(i,j,k) == amrex::Real(0.0) && n != z_comp && n != vf_comp) {
1517  out(i,j,k,n) = covered_value;
1518  }
1519  });
1520  }
1521  }
1522 
1523  for (int n(0); n<static_cast<int>(lines.size()); ++n) {
1524  const int iline = lines[n];
1525  const amrex::Box& bnd_bx = boxes[n];
1526  m_lev[iline] = ilev;
1527  if (m_interp) {
1528  m_ls_mf[iline] = interp_line_data(iline, interp_plan(iline, ilev), mf_cc_data, z_comp, vf_comp);
1529  done[iline] = 1;
1530  continue;
1531  }
1532  m_ls_mf[iline] = get_line_data(mf_cc_data, m_dir[iline], bnd_bx.smallEnd(), bnd_bx);
1533 
1534  // A line is done once a level holds all of it
1535  if (bnd_bx == m_ls_mf[iline].boxArray().minimalBox()) { done[iline] = 1; }
1536  }
1537  } // ilev
1538 
1539  // Fill bnd_bx if use_rbx
1540  if (m_use_real_bx) {
1541  for (int iline(0); iline<nline; ++iline) {
1542  m_bnd_bx[iline] = m_ls_mf[iline].boxArray().minimalBox();
1543  }
1544  }
1545  }
@ tau12
Definition: ERF_DataStruct.H:51
@ tau23
Definition: ERF_DataStruct.H:51
@ tau33
Definition: ERF_DataStruct.H:51
@ tau22
Definition: ERF_DataStruct.H:51
@ tau11
Definition: ERF_DataStruct.H:51
@ tau13
Definition: ERF_DataStruct.H:51
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:79
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:78
#define RhoKE_comp
Definition: ERF_IndexDefines.H:63
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
int sampling_num_levels(const amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_new)
Definition: ERF_SampleData.H:44
@ xvel
Definition: ERF_IndexDefines.H:232
@ cons
Definition: ERF_IndexDefines.H:231
@ zvel
Definition: ERF_IndexDefines.H:234
@ yvel
Definition: ERF_IndexDefines.H:233
@ t
Definition: ERF_WSM6.H:295
Definition: ERF_ConsoleIO.cpp:17
void expand_conserved(int ncons)
Replace "conserved" by one name per component of the conserved state, cons_0, cons_1,...
Definition: ERF_SampleData.H:436
amrex::MultiFab interp_line_data(int iline, const InterpPlan &plan, const amrex::MultiFab &data, int z_comp, int vf_comp) const
Definition: ERF_SampleData.H:855
amrex::Real line_ground(int iline, const amrex::Geometry &geom0, const amrex::MultiFab *ground_nd)
The ground under line iline, found once: level 0 and the terrain do not change.
Definition: ERF_SampleData.H:965
const InterpPlan & cachedInterpPlan(int iline, int lev, const amrex::Geometry &geom, const amrex::Geometry &geom0, const amrex::MultiFab &z_cc, const amrex::MultiFab *z_nd, const amrex::MultiFab *volfrac, const amrex::MultiFab *ground, const amrex::MultiFab *ground0)
make_interp_plan, kept until the grids of the level change
Definition: ERF_SampleData.H:833
const amrex::Box & cachedLineIndexBox(int iline, int lev, const amrex::Geometry &geom, const amrex::MultiFab &z_nd, amrex::Real ground)
Definition: ERF_SampleData.H:986
static const amrex::MultiFab * level_ptr(const amrex::Vector< const amrex::MultiFab * > &v, int lev)
The entry of level lev, or nullptr past the end.
Definition: ERF_SampleData.H:826
amrex::Real m_covered_value
Definition: ERF_SampleData.H:1707
amrex::Box getIndexBox(const amrex::RealBox &real_box, const amrex::Geometry &geom)
Definition: ERF_SampleData.H:1066

Referenced by ERF::run_line_sampler().

Here is the caller graph for this function:

◆ getIndexBox()

amrex::Box LineSampler::getIndexBox ( const amrex::RealBox &  real_box,
const amrex::Geometry &  geom 
)
inline
1067  {
1068  amrex::IntVect slice_lo, slice_hi;
1069 
1070  AMREX_D_TERM(slice_lo[0]=static_cast<int>(std::floor((real_box.lo(0) - geom.ProbLo(0))/geom.CellSize(0)));,
1071  slice_lo[1]=static_cast<int>(std::floor((real_box.lo(1) - geom.ProbLo(1))/geom.CellSize(1)));,
1072  slice_lo[2]=static_cast<int>(std::floor((real_box.lo(2) - geom.ProbLo(2))/geom.CellSize(2))););
1073 
1074  AMREX_D_TERM(slice_hi[0]=static_cast<int>(std::floor((real_box.hi(0) - geom.ProbLo(0))/geom.CellSize(0)));,
1075  slice_hi[1]=static_cast<int>(std::floor((real_box.hi(1) - geom.ProbLo(1))/geom.CellSize(1)));,
1076  slice_hi[2]=static_cast<int>(std::floor((real_box.hi(2) - geom.ProbLo(2))/geom.CellSize(2))););
1077 
1078  return amrex::Box(slice_lo, slice_hi) & geom.Domain();
1079  }

◆ interp_heights()

amrex::Vector<amrex::Real> LineSampler::interp_heights ( int  iline) const
inline

The requested heights of line iline (erf.sample_line_interp): erf.sample_line_npts evenly spaced from lo z to hi z for a vertical line, its one z for a horizontal line

580  {
581  const amrex::RealBox& rb = m_bnd_rbx[iline];
582  if (m_dir[iline] != 2) { return {rb.lo(2)}; }
583  const int n = m_npts[iline];
584  amrex::Vector<amrex::Real> h(n, rb.lo(2));
585  for (int m(1); m<n; ++m) {
586  h[m] = rb.lo(2) + (rb.hi(2) - rb.lo(2)) * amrex::Real(m) / amrex::Real(n - 1);
587  }
588  return h;
589  }

Referenced by make_interp_plan(), and write_line_plotfile().

Here is the caller graph for this function:

◆ interp_line_data()

amrex::MultiFab LineSampler::interp_line_data ( int  iline,
const InterpPlan &  plan,
const amrex::MultiFab &  data,
int  z_comp,
int  vf_comp 
) const
inline

The samples of an interpolated line from the variables data of its level, as a MultiFab of one box (interp_sample_box) on the I/O rank. z is the height of each sample above sea level; a missing sample has volume fraction 0 and erf.sampling_covered_value elsewhere. Collective.

856  {
857  const int ncomp = data.nComp();
858  const int nsamp = static_cast<int>(plan.zt.size());
859  amrex::Vector<amrex::Real> d;
860  if (plan.cells.ok()) { d = gather_box(data, 0, ncomp, plan.cells, false); }
861 
862  const amrex::Box sbx = interp_sample_box(iline, plan.cols);
863  const int io = amrex::ParallelDescriptor::IOProcessorNumber();
864  amrex::MultiFab out(amrex::BoxArray(sbx), amrex::DistributionMapping(amrex::Vector<int>{io}), ncomp, 0);
865  if (amrex::ParallelDescriptor::IOProcessor()) {
866  const int ncol = static_cast<int>(plan.cols.numPts());
867  const auto ncell = static_cast<std::size_t>(plan.cells.ok() ? plan.cells.numPts() : 0);
868  const int kc0 = plan.cells.ok() ? plan.cells.smallEnd(2) - plan.cols.smallEnd(2) : 0;
869  auto cell = [&] (int icol, int k, int n) {
870  return d[static_cast<std::size_t>(icol) + static_cast<std::size_t>(ncol) * (k - kc0) + ncell * n];
871  };
872  // in the order of the box's FArrayBox, whose samples run along its one long direction
873  amrex::Vector<amrex::Real> v(static_cast<std::size_t>(nsamp) * ncomp);
874  for (int n(0); n<ncomp; ++n) {
875  for (int s(0); s<nsamp; ++s) {
876  amrex::Real val;
877  if (n == z_comp) {
878  val = plan.zt[s];
879  } else if (plan.missing[s] != 0) {
880  val = (n == vf_comp) ? amrex::Real(0.0) : m_covered_value;
881  } else {
882  const amrex::Real w = plan.w[s];
883  val = (amrex::Real(1.0) - w) * cell(plan.col[s], plan.k0[s], n);
884  if (w > amrex::Real(0.0)) { val += w * cell(plan.col[s], plan.k1[s], n); }
885  }
886  v[static_cast<std::size_t>(s) + static_cast<std::size_t>(nsamp) * n] = val;
887  }
888  }
889  amrex::Gpu::copy(amrex::Gpu::hostToDevice, v.begin(), v.end(), out[0].dataPtr());
890  }
891  return out;
892  }
static amrex::Vector< amrex::Real > gather_box(const amrex::MultiFab &src, int scomp, int ncomp, const amrex::Box &bx, bool to_all)
Definition: ERF_SampleData.H:606
amrex::Box interp_sample_box(int iline, const amrex::Box &cols) const
The samples of line iline, along its direction: its heights (vertical) or its columns (horizontal)
Definition: ERF_SampleData.H:593
Here is the call graph for this function:

◆ interp_sample_box()

amrex::Box LineSampler::interp_sample_box ( int  iline,
const amrex::Box &  cols 
) const
inline

The samples of line iline, along its direction: its heights (vertical) or its columns (horizontal)

594  {
595  if (m_dir[iline] != 2) { return cols; }
596  amrex::IntVect lo(cols.smallEnd()); lo[2] = 0;
597  amrex::IntVect hi(cols.smallEnd()); hi[2] = m_npts[iline] - 1;
598  return amrex::Box(lo, hi);
599  }

Referenced by interp_line_data().

Here is the caller graph for this function:

◆ level_ptr()

static const amrex::MultiFab* LineSampler::level_ptr ( const amrex::Vector< const amrex::MultiFab * > &  v,
int  lev 
)
inlinestatic

The entry of level lev, or nullptr past the end.

827  {
828  return lev < static_cast<int>(v.size()) ? v[lev] : nullptr;
829  }

◆ line_ground()

amrex::Real LineSampler::line_ground ( int  iline,
const amrex::Geometry &  geom0,
const amrex::MultiFab *  ground_nd 
)
inline

The ground under line iline, found once: level 0 and the terrain do not change.

966  {
967  if (!m_z_agl) { return amrex::Real(0.0); }
968  if (m_ground.empty()) {
969  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ground_nd != nullptr,
970  "erf.sample_line_z_agl needs the height of the ground on level 0");
971  const int nline = static_cast<int>(m_bnd_rbx.size());
972  m_ground.resize(nline);
973  for (int l(0); l<nline; ++l) {
974  const amrex::Box ibx = lineIndexBoxXY(m_bnd_rbx[l], geom0);
975  m_ground[l] = column_ground(*ground_nd, geom0, ibx.smallEnd());
976  }
977  }
978  return m_ground[iline];
979  }
amrex::Vector< amrex::Real > m_ground
Definition: ERF_SampleData.H:1716
static amrex::Real column_ground(const amrex::MultiFab &ground_nd, const amrex::Geometry &geom, const amrex::IntVect &cell)
Definition: ERF_SampleData.H:940
static amrex::Box lineIndexBoxXY(const amrex::RealBox &rb, const amrex::Geometry &geom)
The cells of a real box in x and y on a level, with k = 0: its k comes from heights.
Definition: ERF_SampleData.H:1052
Here is the call graph for this function:

◆ line_sampling_var_order()

static const amrex::Vector<std::string>& LineSampler::line_sampling_var_order ( )
inlinestatic

The variables that may be sampled, in the order they are stored and written.

426  {
427  static const amrex::Vector<std::string> order = {
428  "conserved", "z", "volfrac", "density", "x_velocity", "y_velocity", "z_velocity", "magvel", "theta",
429  "qv", "qc", "pressure", "sgs_tke",
430  "sgs_tau11", "sgs_tau12", "sgs_tau13", "sgs_tau22", "sgs_tau23", "sgs_tau33", "sgs_hfx3"};
431  return order;
432  }

Referenced by LineSampler().

Here is the caller graph for this function:

◆ lineIndexBox()

amrex::Box LineSampler::lineIndexBox ( int  iline,
const amrex::Geometry &  geom,
const amrex::MultiFab &  z_nd,
amrex::Real  ground 
)
inline

The cells of a line given by real coordinates on a level, from the face heights of the column through its first point. A vertical line runs from the cell that holds the lower z to the cell that holds the upper z (each clamped to the column); a horizontal line is the row of cells at the level of cells that holds z in that column, so it follows the terrain-fitted mesh. With erf.sample_line_z_agl, ground is added to z. The box is empty if the level does not hold these cells of the column.

1018  {
1019  const amrex::RealBox& rb = m_bnd_rbx[iline];
1020  const amrex::Box ibx = lineIndexBoxXY(rb, geom);
1021  const amrex::IntVect cell = ibx.smallEnd();
1022  const auto h = column_face_heights(z_nd, geom, cell);
1023  const auto& zl = h[0];
1024  const auto& zu = h[1];
1025  const auto& held = h[2];
1026  const int n = static_cast<int>(zl.size());
1027  const int kdlo = geom.Domain().smallEnd(2);
1028  const amrex::Real offset = m_z_agl ? ground : amrex::Real(0.0);
1029 
1030  // The cell (from the bottom) that holds height z, or -1 where the level does not hold it
1031  auto find_cell = [&] (amrex::Real z) -> int {
1032  if (held[0] > amrex::Real(0.5) && z < zl[0]) { return 0; }
1033  if (held[n-1] > amrex::Real(0.5) && z >= zu[n-1]) { return n-1; }
1034  for (int m = 0; m < n; ++m) {
1035  if (held[m] > amrex::Real(0.5) && zl[m] <= z && z < zu[m]) { return m; }
1036  }
1037  return -1;
1038  };
1039  const int mlo = find_cell(rb.lo(2) + offset);
1040  const int mhi = (m_dir[iline] == 2) ? find_cell(rb.hi(2) + offset) : mlo;
1041  if (mlo < 0 || mhi < 0 || mhi < mlo) { return amrex::Box(); }
1042  for (int m = mlo; m <= mhi; ++m) {
1043  if (held[m] < amrex::Real(0.5)) { return amrex::Box(); }
1044  }
1045  amrex::IntVect lo(ibx.smallEnd()); lo[2] = kdlo + mlo;
1046  amrex::IntVect hi(ibx.bigEnd()); hi[2] = kdlo + mhi;
1047  return amrex::Box(lo, hi);
1048  }
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:36
static amrex::Vector< amrex::Gpu::HostVector< amrex::Real > > column_face_heights(const amrex::MultiFab &z_nd, const amrex::Geometry &geom, const amrex::IntVect &cell)
Definition: ERF_SampleData.H:908

Referenced by cachedLineIndexBox().

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

◆ lineIndexBoxXY()

static amrex::Box LineSampler::lineIndexBoxXY ( const amrex::RealBox &  rb,
const amrex::Geometry &  geom 
)
inlinestatic

The cells of a real box in x and y on a level, with k = 0: its k comes from heights.

1053  {
1054  amrex::IntVect lo, hi;
1055  for (int d(0); d<2; ++d) {
1056  lo[d] = static_cast<int>(std::floor((rb.lo(d) - geom.ProbLo(d))/geom.CellSize(d)));
1057  hi[d] = static_cast<int>(std::floor((rb.hi(d) - geom.ProbLo(d))/geom.CellSize(d)));
1058  lo[d] = std::max(lo[d], geom.Domain().smallEnd(d));
1059  hi[d] = std::min(hi[d], geom.Domain().bigEnd(d));
1060  }
1061  lo[2] = hi[2] = geom.Domain().smallEnd(2);
1062  return amrex::Box(lo, hi);
1063  }

Referenced by line_ground(), lineIndexBox(), and make_interp_plan().

Here is the caller graph for this function:

◆ make_interp_plan()

InterpPlan LineSampler::make_interp_plan ( int  iline,
int  lev,
const amrex::Geometry &  geom,
const amrex::Geometry &  geom0,
const amrex::MultiFab &  z_cc,
const amrex::MultiFab *  z_nd,
const amrex::MultiFab *  volfrac,
const amrex::MultiFab *  ground,
const amrex::MultiFab *  ground0 
) const
inline

The samples of line iline on a level (erf.sample_line_interp). Each sample is in a column of cells of the level: the one that holds the line (vertical), or each one it crosses (horizontal). Its height is the requested one, above sea level or, with erf.sample_line_z_agl, above the ground under the column. The ground and the top of a column are those of the level, the means of the four nodes under and over it, where the level holds the column's bottom or top cell; elsewhere the ground is the level-0 ground, bilinear at the column's center (a level that stops above the ground). Its value is linear in height between the two cell centers of the column that bracket it; between the ground and the lowest cell center with fluid it is that cell's, and between the top cell center and the top the top cell's. A sample below the ground or above the top is missing. The level holds the line if it holds every cell the samples read; level 0 always does. Collective: every rank gets the same plan.

Parameters
[in]z_ndthe nodal heights of the level, or nullptr (the top is then prob_hi)
[in]volfracthe volume fraction of the level with immersed terrain, or nullptr
[in]groundthe ground of the level (z_nd, or the immersed terrain surface), or nullptr
[in]ground0the ground of level 0, or nullptr (the ground is then prob_lo)
663  {
664  InterpPlan plan;
665  plan.ba = z_cc.boxArray();
666  plan.cols = lineIndexBoxXY(m_bnd_rbx[iline], geom);
667  const amrex::Box& dom = geom.Domain();
668  const int kdlo = dom.smallEnd(2);
669  const int nz = dom.length(2);
670  const int ncol = static_cast<int>(plan.cols.numPts());
671  const int dir = m_dir[iline];
672  const int along = (dir == 2) ? 0 : dir;
673  const amrex::IntVect clo = plan.cols.smallEnd();
674 
675  // The heights of the cell centers of the columns, which cells the level holds, and their
676  // volume fractions, from the bottom of the domain to its top
677  amrex::Box colbox(plan.cols);
678  colbox.setSmall(2, kdlo);
679  colbox.setBig(2, dom.bigEnd(2));
680  amrex::MultiFab t(z_cc.boxArray(), z_cc.DistributionMap(), 3, 0);
681  amrex::MultiFab::Copy(t, z_cc, 0, 0, 1, 0);
682  t.setVal(amrex::Real(1.0), 1, 1, 0);
683  if (volfrac != nullptr) {
684  amrex::MultiFab::Copy(t, *volfrac, 0, 2, 1, 0);
685  } else {
686  t.setVal(amrex::Real(1.0), 2, 1, 0);
687  }
688  const amrex::Vector<amrex::Real> c = gather_box(t, 0, 3, colbox, true);
689  const auto ccol = static_cast<std::size_t>(colbox.numPts());
690  auto at = [&] (int icol, int k, int n) {
691  return c[static_cast<std::size_t>(icol) + static_cast<std::size_t>(ncol) * k + ccol * n];
692  };
693  auto held_at = [&] (int icol, int k) { return at(icol, k, 1) > amrex::Real(0.5); };
694 
695  // The mean of the four nodes at node level k of mf under or over each column of the level
696  auto column_node_mean = [&] (const amrex::MultiFab& mf, int k) {
697  amrex::IntVect nlo(clo); nlo[2] = k;
698  amrex::IntVect nhi(plan.cols.bigEnd() + amrex::IntVect(1,1,0)); nhi[2] = k;
699  const amrex::Box nbx(nlo, nhi, amrex::IntVect::TheNodeVector());
700  const amrex::Vector<amrex::Real> g = gather_box(mf, 0, 1, nbx, true);
701  const int nnx = nbx.length(0);
702  amrex::Vector<amrex::Real> mean(ncol);
703  for (int icol(0); icol<ncol; ++icol) {
704  amrex::IntVect cell(clo);
705  cell[along] += icol;
706  const int i = cell[0] - nlo[0], j = cell[1] - nlo[1];
707  mean[icol] = amrex::Real(0.25) * (g[i + nnx*j] + g[i+1 + nnx*j] + g[i + nnx*(j+1)] + g[i+1 + nnx*(j+1)]);
708  }
709  return mean;
710  };
711 
712  // The ground under the center of each column, bilinear between the level-0 nodes around
713  // it: for the columns whose bottom the level does not hold
714  amrex::Vector<amrex::Real> ground_col(ncol, geom0.ProbLo(2));
715  if (ground0 != nullptr) {
716  const amrex::Box& dom0 = geom0.Domain();
717  amrex::Vector<int> i0(ncol), j0(ncol);
718  amrex::Vector<amrex::Real> fx(ncol), fy(ncol);
719  for (int icol(0); icol<ncol; ++icol) {
720  amrex::IntVect cell(clo);
721  cell[along] += icol;
722  int* idx[2] = {&i0[icol], &j0[icol]};
723  amrex::Real* f[2] = {&fx[icol], &fy[icol]};
724  for (int d(0); d<2; ++d) {
725  const amrex::Real xc = geom.ProbLo(d) + (cell[d] + amrex::Real(0.5)) * geom.CellSize(d);
726  const amrex::Real s = (xc - geom0.ProbLo(d)) / geom0.CellSize(d);
727  *idx[d] = std::min(std::max(static_cast<int>(std::floor(s)), dom0.smallEnd(d)), dom0.bigEnd(d));
728  *f[d] = std::min(std::max(s - *idx[d], amrex::Real(0.0)), amrex::Real(1.0));
729  }
730  }
731  const amrex::IntVect nlo(*std::min_element(i0.begin(), i0.end()), *std::min_element(j0.begin(), j0.end()),
732  dom0.smallEnd(2));
733  const amrex::IntVect nhi(*std::max_element(i0.begin(), i0.end()) + 1,
734  *std::max_element(j0.begin(), j0.end()) + 1, dom0.smallEnd(2));
735  const amrex::Box nbx(nlo, nhi, amrex::IntVect::TheNodeVector());
736  const amrex::Vector<amrex::Real> g = gather_box(*ground0, 0, 1, nbx, true);
737  const int nnx = nbx.length(0);
738  auto node = [&] (int i, int j) { return g[(i - nlo[0]) + nnx * (j - nlo[1])]; };
739  for (int icol(0); icol<ncol; ++icol) {
740  const int i = i0[icol], j = j0[icol];
741  const amrex::Real wx = fx[icol], wy = fy[icol];
742  ground_col[icol] = (amrex::Real(1.0) - wy) * ((amrex::Real(1.0) - wx) * node(i,j) + wx * node(i+1,j))
743  + wy * ((amrex::Real(1.0) - wx) * node(i,j+1) + wx * node(i+1,j+1));
744  }
745  }
746  // the level's own ground where it holds the column's bottom cell
747  if (ground != nullptr) {
748  const amrex::Vector<amrex::Real> own = column_node_mean(*ground, kdlo);
749  for (int icol(0); icol<ncol; ++icol) {
750  if (held_at(icol, 0)) { ground_col[icol] = own[icol]; }
751  }
752  }
753  // The top of each column, where the level holds its top cell; elsewhere no sample above
754  // the level's highest cell is bracketed, so the level does not hold it
755  amrex::Vector<amrex::Real> top_col(ncol, geom.ProbHi(2));
756  if (z_nd != nullptr) {
757  const amrex::Vector<amrex::Real> own = column_node_mean(*z_nd, dom.bigEnd(2) + 1);
758  for (int icol(0); icol<ncol; ++icol) {
759  if (held_at(icol, nz-1)) { top_col[icol] = own[icol]; }
760  }
761  }
762 
763  // The samples: the heights of a vertical line in its column, or one height in each column
764  const amrex::Vector<amrex::Real> h = interp_heights(iline);
765  const int nsamp = (dir == 2) ? static_cast<int>(h.size()) : ncol;
766  plan.zt.resize(nsamp);
767  plan.col.resize(nsamp);
768  plan.k0.assign(nsamp, 0);
769  plan.k1.assign(nsamp, 0);
770  plan.w.assign(nsamp, amrex::Real(0.0));
771  plan.missing.assign(nsamp, 0);
772  plan.holds = true;
773  int kmin = nz, kmax = -1;
774  for (int s(0); s<nsamp; ++s) {
775  const int icol = (dir == 2) ? 0 : s;
776  const amrex::Real hs = (dir == 2) ? h[s] : h[0];
777  plan.col[s] = icol;
778  plan.zt[s] = hs + (m_z_agl ? ground_col[icol] : amrex::Real(0.0));
779  const amrex::Real z = plan.zt[s];
780  if (z < ground_col[icol] || z > top_col[icol]) { plan.missing[s] = 1; continue; }
781 
782  auto held = [&] (int k) { return held_at(icol, k); };
783  auto fluid = [&] (int k) { return held(k) && at(icol, k, 2) > amrex::Real(0.0); };
784  auto zc = [&] (int k) { return at(icol, k, 0); };
785  int k0 = -1, k1 = -1;
786  amrex::Real w = amrex::Real(0.0);
787  // between two cell centers with fluid
788  for (int k(0); k<nz-1 && k0 < 0; ++k) {
789  if (fluid(k) && fluid(k+1) && zc(k) <= z && z < zc(k+1)) {
790  k0 = k; k1 = k+1; w = (z - zc(k)) / (zc(k+1) - zc(k));
791  }
792  }
793  // between the top cell center and the top
794  if (k0 < 0 && fluid(nz-1) && z >= zc(nz-1)) { k0 = k1 = nz-1; }
795  // between the ground and the lowest cell center with fluid, if the level holds the
796  // column up to it
797  if (k0 < 0) {
798  int kf = 0;
799  while (kf < nz && held(kf) && !fluid(kf)) { ++kf; }
800  if (kf < nz && fluid(kf) && z < zc(kf)) { k0 = k1 = kf; }
801  }
802  if (k0 < 0) {
803  // Level 0 holds every cell, so there no cells with fluid bracket the height (a
804  // column without fluid, or a height under an overhang of immersed terrain); a
805  // finer level does not hold the cells around it
806  if (lev == 0) { plan.missing[s] = 1; continue; }
807  plan.holds = false;
808  return plan;
809  }
810  plan.k0[s] = k0;
811  plan.k1[s] = k1;
812  plan.w[s] = w;
813  kmin = std::min(kmin, k0);
814  kmax = std::max(kmax, k1);
815  }
816  if (kmax >= kmin) {
817  plan.cells = plan.cols;
818  plan.cells.setSmall(2, kdlo + kmin);
819  plan.cells.setBig(2, kdlo + kmax);
820  }
821  return plan;
822  }
const Real zc
Definition: ERF_InitCustomPert_ABL.H:112
const Real xc
Definition: ERF_InitCustomPert_ABL.H:110
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:404
real(c_double), parameter g
Definition: ERF_module_model_constants.F90:19
real(c_double), private k1
Definition: ERF_module_mp_morr_two_moment.F90:213
amrex::Vector< amrex::Real > interp_heights(int iline) const
Definition: ERF_SampleData.H:579

Referenced by cachedInterpPlan().

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

◆ needs_ground()

bool LineSampler::needs_ground ( ) const
inline

Whether the sampler needs the ground under its lines (erf.sample_line_z_agl, or erf.sample_line_interp, which writes the samples below the ground as missing)

550  {
551  return m_use_real_bx && (m_z_agl || m_interp);
552  }

Referenced by ERF::run_line_sampler(), and ERF::sampling_ground().

Here is the caller graph for this function:

◆ open_ascii_streams()

void LineSampler::open_ascii_streams ( )
inline
449  {
450  if (!m_datastream.empty() || !amrex::ParallelDescriptor::IOProcessor()) { return; }
451  int nline = static_cast<int>(m_name.size());
452  int nvar = static_cast<int>(m_varnames.size());
453  m_datastream.resize(nline * nvar);
454  int i = 0;
455  for (int iline(0); iline<nline; ++iline) {
456  for (int ivar(0); ivar<nvar; ++ivar) {
457  std::string filename = m_name[iline] + "." + m_varnames[ivar];
458  m_datastream[i] = std::make_unique<std::fstream>();
459  m_datastream[i]->open(filename.c_str(),std::ios::out|std::ios::app);
460  if (!m_datastream[i]->good()) {
461  amrex::FileOpenFailed(filename);
462  }
463  i++;
464  }
465  }
466  }
amrex::Vector< std::unique_ptr< std::fstream > > m_datastream
Definition: ERF_SampleData.H:1711

Referenced by write_line_ascii().

Here is the caller graph for this function:

◆ open_logs()

void LineSampler::open_logs ( const amrex::Vector< std::string > &  log_names)
inline

Open one log per line, appended to, on the I/O rank.

407  {
408  m_write_log = true;
409  if (amrex::ParallelDescriptor::IOProcessor()) {
410  const int nline = static_cast<int>(log_names.size());
411  m_logstream.resize(nline);
412  for (int iline(0); iline<nline; ++iline) {
413  m_logstream[iline] = std::make_unique<std::fstream>();
414  m_logstream[iline]->open(log_names[iline].c_str(),std::ios::out|std::ios::app);
415  if (!m_logstream[iline]->good()) {
416  amrex::FileOpenFailed(log_names[iline]);
417  }
418  }
419  }
420  amrex::ParallelDescriptor::Barrier("LineSampler::open_logs");
421  }
amrex::Vector< std::unique_ptr< std::fstream > > m_logstream
Definition: ERF_SampleData.H:1712
bool m_write_log
Definition: ERF_SampleData.H:1703

Referenced by LineSampler().

Here is the caller graph for this function:

◆ resolve_latlon()

void LineSampler::resolve_latlon ( const LatLonMap &  latlon_map,
const amrex::Geometry &  geom0 
)
inline

Turn the ends of the lines given by latitude and longitude into domain coordinates, with the level-0 latitude/longitude map of the run, and check them. A vertical line gives one lat/lon at both ends. The two ends of a horizontal line are in general not on one row of cells: they must lie within one cell of each other across the line, which is then sampled along the line of cells through its lo end. Collective.

484  {
485  const int nline = static_cast<int>(m_bnd_rbx.size());
486  for (int iline(0); iline<nline; ++iline) {
487  const int dir = m_dir[iline];
488  const std::string line = "Line " + std::to_string(iline) + " of erf.sample_line_lo/hi_latlon";
489  const amrex::Real* req[2] = {&m_latlon_lo[3*iline], &m_latlon_hi[3*iline]};
490 
491  if (dir == 2) {
492  if (req[0][0] != req[1][0] || req[0][1] != req[1][1]) {
493  amrex::Abort(line + " is vertical (erf.sample_line_dir = 2), so its two ends"
494  " must give the same latitude and longitude");
495  }
496  if (req[0][2] > req[1][2]) {
497  amrex::Abort(line + " has its lo end above its hi end");
498  }
499  } else if (req[0][2] != req[1][2]) {
500  amrex::Abort(line + " is horizontal, so its two ends must give the same z");
501  }
502 
503  // A vertical line has one lat/lon
504  const int nend = (dir == 2) ? 1 : 2;
505  LatLonLocation where[2];
506  for (int e(0); e<nend; ++e) {
507  where[e] = latlon_map.locate_or_abort(req[e][0], req[e][1],
508  line + (e == 0 ? ", lo end," : ", hi end,"));
509  }
510  if (dir == 2) { where[1] = where[0]; }
511 
512  amrex::Real lo[AMREX_SPACEDIM] = {where[0].x, where[0].y, req[0][2]};
513  amrex::Real hi[AMREX_SPACEDIM] = {where[1].x, where[1].y, req[1][2]};
514  amrex::Real snap = amrex::Real(0.0);
515  if (dir != 2) {
516  const int across = 1 - dir;
517  snap = hi[across] - lo[across];
518  const amrex::Real gap = std::abs(snap) / geom0.CellSize(across);
519  if (gap > amrex::Real(1.0)) {
520  amrex::Abort(line + " is not along erf.sample_line_dir: its ends are " +
521  std::to_string(gap) + " cells apart in direction " +
522  std::to_string(across) + ", and a line between two lat/lon"
523  " points is sampled along one grid direction, so its ends may"
524  " be at most one cell apart across it");
525  }
526  if (hi[dir] < lo[dir]) {
527  amrex::Abort(line + " has its lo end beyond its hi end in direction " +
528  std::to_string(dir) + "; swap the two ends");
529  }
530  hi[across] = lo[across];
531  }
532  m_bnd_rbx[iline] = amrex::RealBox(lo, hi);
533  if (m_interp) { check_interp_heights(iline); }
534 
535  amrex::Print() << line << ": lo end at lat=" << where[0].lat << " long=" << where[0].lon
536  << " (x=" << lo[0] << " y=" << lo[1] << ")";
537  if (dir != 2) {
538  amrex::Print() << ", hi end at lat=" << where[1].lat << " long=" << where[1].lon
539  << " (x=" << hi[0] << " y=" << hi[1] << "), sampled along the line of cells"
540  << " through the lo end, " << std::abs(snap) << " m from the hi end";
541  }
542  amrex::Print() << std::endl;
543  }
544  }
LatLonLocation locate_or_abort(amrex::Real req_lat, amrex::Real req_lon, const std::string &what) const
Definition: ERF_LatLonMap.cpp:233
Definition: ERF_LatLonMap.H:87
amrex::Real lat
Definition: ERF_LatLonMap.H:94
amrex::Real x
Definition: ERF_LatLonMap.H:89
amrex::Real y
Definition: ERF_LatLonMap.H:90
amrex::Real lon
Definition: ERF_LatLonMap.H:95
Here is the call graph for this function:

◆ use_column_heights()

bool LineSampler::use_column_heights ( ) const
inline

Whether the z of a line given by real coordinates is found from the heights of a column: on a stretched or terrain-fitted mesh, or for a height above ground

898  {
899  return m_z_agl || SolverChoice::mesh_type != MeshType::ConstantDz;
900  }

Referenced by LineSampler().

Here is the caller graph for this function:

◆ uses_latlon()

bool LineSampler::uses_latlon ( ) const
inline

Whether the lines are given by latitude and longitude (erf.sample_line_lo/hi_latlon)

471  {
472  return m_use_latlon;
473  }

◆ write_coords()

void LineSampler::write_coords ( amrex::Vector< std::unique_ptr< amrex::MultiFab > > &  z_phys_cc,
amrex::Vector< std::unique_ptr< amrex::MultiFab > > &  z_phys_nd,
amrex::Vector< amrex::Geometry > &  geom,
const amrex::MultiFab *  ground_nd = nullptr,
const amrex::Vector< const amrex::MultiFab * > &  ground_lev = {},
const amrex::Vector< const amrex::MultiFab * > &  volfrac_lev = {} 
)
inline
1086  {},
1087  const amrex::Vector<const amrex::MultiFab*>& volfrac_lev = {})
1088  {
1089  if (!m_write_ascii) return;
1090 
1091  // Only the levels that are sampled
1092  int nlev = static_cast<int>(z_phys_cc.size());
1093  if (m_max_level >= 0) { nlev = std::min(nlev, m_max_level + 1); }
1094  for (int lev(0); lev < nlev; ++lev) {
1095  // A level allowed by amr.max_level that has not been made has no heights, and
1096  // neither does any level above it
1097  if (!z_phys_cc[lev] || lev >= static_cast<int>(z_phys_nd.size()) || !z_phys_nd[lev]) { break; }
1098 
1099  // Written for each set of grids of the level: when the level is made, and again
1100  // when a regrid changes its grids
1101  if (lev >= static_cast<int>(m_zcc_ba.size())) { m_zcc_ba.resize(lev+1); }
1102  if (m_zcc_ba[lev] == z_phys_cc[lev]->boxArray()) { continue; }
1103  m_zcc_ba[lev] = z_phys_cc[lev]->boxArray();
1104 
1105  amrex::Print() << "Writing out line coordinates of level " << lev << " to text" << std::endl;
1106 
1107  // Write one text file per level
1108  std::ofstream outfile;
1109  if (amrex::ParallelDescriptor::IOProcessor()) {
1110  std::string fname = amrex::Concatenate("plt_line_lev", lev, 1);
1111  fname += ".zcc";
1112  outfile.open(fname);
1113 
1114  if (!outfile.is_open()) {
1115  amrex::AllPrint() << "Could not open " << fname << std::endl;
1116  }
1117  }
1118 
1119  // Loop over each line
1120  int nline = static_cast<int>(m_ls_mf.size());
1121  for (int iline(0); iline<nline; ++iline) {
1122  int dir = m_dir[iline];
1123  if (m_interp) {
1124  // The height of each sample above sea level, where the level holds the line
1125  // (the plan the samples are then taken with)
1126  const InterpPlan& plan = cachedInterpPlan(iline, lev, geom[lev], geom[0], *z_phys_cc[lev],
1127  z_phys_nd[lev].get(), level_ptr(volfrac_lev, lev),
1128  level_ptr(ground_lev, lev), ground_nd);
1129  if (amrex::ParallelDescriptor::IOProcessor()) {
1130  if (plan.holds) {
1131  for (const auto& zval : plan.zt) { outfile << " " << zval; }
1132  }
1133  outfile << std::endl;
1134  }
1135  continue;
1136  }
1137  amrex::Box bnd_bx;
1138  if (m_use_real_bx && use_column_heights()) {
1139  // As in get_sample_data: the cells of the line come from the heights
1140  const amrex::Real ground = line_ground(iline, geom[0], ground_nd);
1141  bnd_bx = cachedLineIndexBox(iline, lev, geom[lev], *z_phys_nd[lev], ground);
1142  if (bnd_bx.isEmpty()) {
1143  // This level does not hold the line
1144  if (amrex::ParallelDescriptor::IOProcessor()) { outfile << std::endl; }
1145  continue;
1146  }
1147  } else {
1148  bnd_bx = (m_use_real_bx) ? getIndexBox(m_bnd_rbx[iline], geom[lev])
1149  : m_bnd_bx[iline];
1150  }
1151  amrex::IntVect first_cell = bnd_bx.smallEnd();
1152 
1153  // Create multifab with "sampled" z_phys values
1154  amrex::MultiFab line_coords_mf = get_line_data(
1155  *z_phys_cc[lev], dir, first_cell, bnd_bx
1156  );
1157 
1158  // Convert multifab to vector
1159  amrex::Gpu::HostVector<amrex::Real> vec = sumToLine(
1160  line_coords_mf, 0, 1, bnd_bx, dir
1161  );
1162 
1163  // Append to file
1164  if (amrex::ParallelDescriptor::IOProcessor()) {
1165  for (const auto& zval : vec) {
1166  outfile << " " << zval;
1167  }
1168  outfile << std::endl;
1169  }
1170  } // line loop
1171 
1172  outfile.close();
1173  } // level loop
1174  }
pp_for_pert_vels get("prob_type", prob_type)
amrex::Vector< amrex::BoxArray > m_zcc_ba
Definition: ERF_SampleData.H:1721

Referenced by ERF::run_line_sampler().

Here is the caller graph for this function:

◆ write_line_ascii()

void LineSampler::write_line_ascii ( amrex::Vector< double > &  time)
inline
1599  {
1600  // same as definitions in ERF.H
1601  constexpr int datwidth = 14;
1602  constexpr int datprecision = 6;
1603  constexpr int timeprecision = 13;
1604 
1606 
1607  int nline = static_cast<int>(m_ls_mf.size());
1608  int nvar = static_cast<int>(m_varnames.size());
1609  for (int iline(0); iline<nline; ++iline) {
1610  int dir = m_dir[iline];
1611  int lev = m_lev[iline];
1612  double m_time = time[lev];
1613  amrex::Box m_dom = m_bnd_bx[iline];
1614 
1615  for (int ivar(0); ivar<nvar; ++ivar) {
1616  // Convert multifab to vector
1617  amrex::Gpu::HostVector<amrex::Real> vec = sumToLine(m_ls_mf[iline], ivar, 1, m_dom, dir);
1618 
1619  if (amrex::ParallelDescriptor::IOProcessor()) {
1620  int ifile = iline*nvar + ivar;
1621  std::ostream& fs = *m_datastream[ifile];
1622  fs << std::setw(datwidth) << std::setprecision(timeprecision) << m_time
1623  << std::setw(datwidth) << std::setprecision(datprecision);
1624  for (const auto& val : vec) {
1625  fs << " " << val;
1626  }
1627  fs << std::endl;
1628  }
1629  }
1630  }
1631  }
@ fs
Definition: ERF_AdvanceMorrison.cpp:124
void open_ascii_streams()
Definition: ERF_SampleData.H:448

Referenced by write_sample_data().

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

◆ write_line_log()

void LineSampler::write_line_log ( amrex::Vector< double > &  time)
inline

One row per line in its log: the time, then each variable along the line.

1565  {
1566  // same as definitions in ERF.H
1567  constexpr int datwidth = 14;
1568  constexpr int datprecision = 6;
1569 
1570  int nline = static_cast<int>(m_ls_mf.size());
1571  int nvar = static_cast<int>(m_varnames.size());
1572  for (int iline(0); iline<nline; ++iline) {
1573  int dir = m_dir[iline];
1574  double m_time = time[m_lev[iline]];
1575  amrex::Box m_dom = m_bnd_bx[iline];
1576 
1577  amrex::Vector<amrex::Gpu::HostVector<amrex::Real>> vecs(nvar);
1578  for (int ivar(0); ivar<nvar; ++ivar) {
1579  vecs[ivar] = sumToLine(m_ls_mf[iline], ivar, 1, m_dom, dir);
1580  }
1581 
1582  if (amrex::ParallelDescriptor::IOProcessor()) {
1583  std::ostream& fs = *m_logstream[iline];
1584  if (fs.good()) {
1585  fs << std::setw(datwidth) << std::setprecision(datprecision) << m_time;
1586  for (const auto& vec : vecs) {
1587  for (const auto& val : vec) {
1588  fs << std::setw(datwidth) << std::setprecision(datprecision) << val;
1589  }
1590  }
1591  fs << std::endl;
1592  }
1593  }
1594  }
1595  }

Referenced by write_sample_data().

Here is the caller graph for this function:

◆ write_line_plotfile()

void LineSampler::write_line_plotfile ( amrex::Vector< double > &  time,
amrex::Vector< int > &  level_steps,
amrex::Vector< amrex::IntVect > &  ref_ratio,
amrex::Vector< amrex::Geometry > &  geom 
)
inline
1638  {
1639  int nline = static_cast<int>(m_ls_mf.size());
1640  for (int iline(0); iline<nline; ++iline) {
1641  // Data members that can be used as-is
1642  int dir = m_dir[iline];
1643  int lev = m_lev[iline];
1644  double m_time = time[lev];
1645  amrex::Vector<int> m_level_steps = {level_steps[lev]};
1646  amrex::Vector<amrex::IntVect> m_ref_ratio = {ref_ratio[lev]};
1647 
1648  // Create modified geometry object corresponding to the line
1649  auto plo = geom[lev].ProbLo();
1650  auto dx = geom[lev].CellSize();
1651  amrex::Vector<amrex::Geometry> m_geom; m_geom.resize(1);
1652  amrex::Vector<int> is_per(AMREX_SPACEDIM,0);
1653  amrex::Box m_dom = m_bnd_bx[iline];
1654  amrex::RealBox m_rb;
1655  for (int d(0); d<AMREX_SPACEDIM; ++d) {
1656  amrex::Real offset = (d==dir) ? 0 : myhalf;
1657  amrex::Real lo = plo[d] + ( m_dom.smallEnd(d) - offset ) * dx[d];
1658  amrex::Real hi = plo[d] + ( m_dom.bigEnd(d) + offset ) * dx[d];
1659 
1660  m_rb.setLo(d,lo);
1661  m_rb.setHi(d,hi);
1662 
1663  is_per[d] = geom[lev].isPeriodic(d);
1664  }
1665  // An interpolated line is at its requested heights (above the ground with
1666  // erf.sample_line_z_agl): its z cells are centered on them
1667  if (m_interp) {
1668  const amrex::Vector<amrex::Real> h = interp_heights(iline);
1669  const int nh = static_cast<int>(h.size());
1670  const amrex::Real dh = (nh > 1) ? (h[nh-1] - h[0]) / amrex::Real(nh - 1) : dx[2];
1671  m_rb.setLo(2, h[0] - myhalf * dh);
1672  m_rb.setHi(2, h[nh-1] + myhalf * dh);
1673  is_per[2] = 0;
1674  }
1675  m_geom[0].define(m_dom, &m_rb, geom[lev].Coord(), is_per.data());
1676 
1677  // Create plotfile name
1678  std::string name_line = m_name[iline];
1679  name_line += "_step_";
1680  std::string plotfilename = amrex::Concatenate(name_line, m_level_steps[0], 5);
1681 
1682  // Get the data
1683  amrex::Vector<const amrex::MultiFab*> mf = {&(m_ls_mf[iline])};
1684 
1685  // Write each line
1686  WriteMultiLevelPlotfile(plotfilename, 1, mf,
1687  m_varnames, m_geom, static_cast<amrex::Real>(m_time),
1688  m_level_steps, m_ref_ratio);
1689  }
1690  }
GpuArray< Real, AMREX_SPACEDIM > plo
Definition: ERF_ActuatorSpreading.cpp:131
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
Coord
Coordinate-axis selector.
Definition: ERF_DataStruct.H:226
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41

Referenced by write_sample_data().

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

◆ write_sample_data()

void LineSampler::write_sample_data ( amrex::Vector< double > &  time,
amrex::Vector< int > &  level_steps,
amrex::Vector< amrex::IntVect > &  ref_ratio,
amrex::Vector< amrex::Geometry > &  geom 
)
inline
1552  {
1553  if (m_write_log) {
1554  write_line_log(time);
1555  } else if (m_write_ascii) {
1556  write_line_ascii(time);
1557  } else {
1558  write_line_plotfile(time, level_steps, ref_ratio, geom);
1559  }
1560  }
void write_line_plotfile(amrex::Vector< double > &time, amrex::Vector< int > &level_steps, amrex::Vector< amrex::IntVect > &ref_ratio, amrex::Vector< amrex::Geometry > &geom)
Definition: ERF_SampleData.H:1634
void write_line_log(amrex::Vector< double > &time)
One row per line in its log: the time, then each variable along the line.
Definition: ERF_SampleData.H:1564
void write_line_ascii(amrex::Vector< double > &time)
Definition: ERF_SampleData.H:1598

Referenced by ERF::run_line_sampler().

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

Member Data Documentation

◆ m_bnd_bx

amrex::Vector<amrex::Box> LineSampler::m_bnd_bx

◆ m_bnd_rbx

◆ m_box_cache

amrex::Vector<amrex::Vector<amrex::Box> > LineSampler::m_box_cache

Referenced by cachedLineIndexBox().

◆ m_box_cache_ba

amrex::Vector<amrex::BoxArray> LineSampler::m_box_cache_ba

Referenced by cachedLineIndexBox().

◆ m_box_cache_found

amrex::Vector<amrex::Vector<int> > LineSampler::m_box_cache_found

Referenced by cachedLineIndexBox().

◆ m_covered_value

amrex::Real LineSampler::m_covered_value {sampling_covered_value()}

Referenced by interp_line_data().

◆ m_datastream

amrex::Vector<std::unique_ptr<std::fstream> > LineSampler::m_datastream

◆ m_dir

◆ m_ground

amrex::Vector<amrex::Real> LineSampler::m_ground

Referenced by line_ground().

◆ m_interp

bool LineSampler::m_interp {false}

◆ m_interp_plan

amrex::Vector<amrex::Vector<InterpPlan> > LineSampler::m_interp_plan

Referenced by cachedInterpPlan().

◆ m_latlon_hi

amrex::Vector<amrex::Real> LineSampler::m_latlon_hi

Referenced by LineSampler(), and resolve_latlon().

◆ m_latlon_lo

amrex::Vector<amrex::Real> LineSampler::m_latlon_lo

Referenced by LineSampler(), and resolve_latlon().

◆ m_lev

amrex::Vector<int> LineSampler::m_lev

◆ m_logstream

amrex::Vector<std::unique_ptr<std::fstream> > LineSampler::m_logstream

Referenced by open_logs(), and write_line_log().

◆ m_ls_mf

amrex::Vector<amrex::MultiFab> LineSampler::m_ls_mf

◆ m_max_level

int LineSampler::m_max_level {-1}

Referenced by LineSampler().

◆ m_name

amrex::Vector<std::string> LineSampler::m_name

◆ m_ncons

int LineSampler::m_ncons {-1}

Referenced by expand_conserved().

◆ m_npts

amrex::Vector<int> LineSampler::m_npts

◆ m_use_latlon

bool LineSampler::m_use_latlon {false}

Referenced by LineSampler(), and uses_latlon().

◆ m_use_real_bx

bool LineSampler::m_use_real_bx {false}

Referenced by LineSampler(), and needs_ground().

◆ m_varnames

amrex::Vector<std::string> LineSampler::m_varnames {"magvel","theta"}

◆ m_write_ascii

bool LineSampler::m_write_ascii {false}

Referenced by LineSampler(), and write_sample_data().

◆ m_write_log

bool LineSampler::m_write_log {false}

Referenced by open_logs(), and write_sample_data().

◆ m_z_agl

bool LineSampler::m_z_agl {false}

◆ m_zcc_ba

amrex::Vector<amrex::BoxArray> LineSampler::m_zcc_ba

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