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

#include <ERF_SampleData.H>

Collaboration diagram for LineSampler:

Public Member Functions

 LineSampler ()
 
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< amrex::Geometry > &geom)
 
void get_sample_data (amrex::Vector< amrex::Geometry > &geom, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_new)
 
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_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)
 

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_write_ascii {false}
 
amrex::Vector< std::string > m_varnames {"magvel","theta"}
 
amrex::Vector< std::unique_ptr< std::fstream > > m_datastream
 

Constructor & Destructor Documentation

◆ LineSampler()

LineSampler::LineSampler ( )
inline
23  {
24  amrex::ParmParse pp("erf");
25 
26  bool has_line_idx = pp.contains("sample_line_lo") || pp.contains("sample_line_hi");
27  bool has_line_real = pp.contains("sample_line_lo_real") || pp.contains("sample_line_hi_real");
28  if (has_line_idx && has_line_real) {
29  amrex::Abort("Specify only one of erf.sample_line_lo/hi or erf.sample_line_lo_real/hi_real");
30  }
31 
32  // Count number of lo and hi points define the line
33  int n_line_lo = pp.countval("sample_line_lo") / AMREX_SPACEDIM;
34  int n_line_hi = pp.countval("sample_line_hi") / AMREX_SPACEDIM;
35  int n_line_lo_real = pp.countval("sample_line_lo_real") / AMREX_SPACEDIM;
36  int n_line_hi_real = pp.countval("sample_line_hi_real") / AMREX_SPACEDIM;
37  int n_line_dir = pp.countval("sample_line_dir");
38  if (has_line_idx) {
39  AMREX_ALWAYS_ASSERT( (n_line_lo==n_line_hi ) &&
40  (n_line_lo==n_line_dir) );
41  } else if (has_line_real) {
42  AMREX_ALWAYS_ASSERT( (n_line_lo_real==n_line_hi_real ) &&
43  (n_line_lo_real==n_line_dir) );
44  }
45 
46  // Parse the data
47  int nline = 0;
48  if (has_line_idx) {
49  nline = n_line_lo;
50  if (nline > 0) {
51  // Parse lo
52  amrex::Vector<int> idx_lo; idx_lo.resize(nline*AMREX_SPACEDIM);
53  amrex::Vector<amrex::IntVect> iv_lo; iv_lo.resize(nline);
54  pp.queryarr("sample_line_lo",idx_lo,0,nline*AMREX_SPACEDIM);
55  for (int i(0); i < nline; i++) {
56  amrex::IntVect iv(idx_lo[AMREX_SPACEDIM*i+0],
57  idx_lo[AMREX_SPACEDIM*i+1],
58  idx_lo[AMREX_SPACEDIM*i+2]);
59  iv_lo[i] = iv;
60  }
61 
62  // Parse hi
63  amrex::Vector<int> idx_hi; idx_hi.resize(nline*AMREX_SPACEDIM);
64  amrex::Vector<amrex::IntVect> iv_hi; iv_hi.resize(nline);
65  pp.queryarr("sample_line_hi",idx_hi,0,nline*AMREX_SPACEDIM);
66  for (int i(0); i < nline; i++) {
67  amrex::IntVect iv(idx_hi[AMREX_SPACEDIM*i+0],
68  idx_hi[AMREX_SPACEDIM*i+1],
69  idx_hi[AMREX_SPACEDIM*i+2]);
70  iv_hi[i] = iv;
71  }
72 
73  // Construct vector of bounding boxes
74  m_bnd_bx.resize(nline);
75  for (int i = 0; i < nline; i++){
76  amrex::Box lbx(iv_lo[i],iv_hi[i]);
77  m_bnd_bx[i] = lbx;
78  }
79  }
80  } else if (has_line_real) {
81  m_use_real_bx = true;
82  nline = n_line_lo_real;
83  if (nline > 0) {
84  // Parse lo
85  amrex::Vector<amrex::Real> real_lo; real_lo.resize(nline*AMREX_SPACEDIM);
86  amrex::Vector<amrex::Vector<amrex::Real>> rv_lo;
87  pp.queryarr("sample_line_lo_real",real_lo,0,nline*AMREX_SPACEDIM);
88  for (int i(0); i < nline; i++) {
89  amrex::Vector<amrex::Real> rv = {real_lo[AMREX_SPACEDIM*i+0],
90  real_lo[AMREX_SPACEDIM*i+1],
91  real_lo[AMREX_SPACEDIM*i+2]};
92  rv_lo.push_back(rv);
93  }
94 
95  // Parse hi
96  amrex::Vector<amrex::Real> real_hi; real_hi.resize(nline*AMREX_SPACEDIM);
97  amrex::Vector<amrex::Vector<amrex::Real>> rv_hi;
98  pp.queryarr("sample_line_hi_real",real_hi,0,nline*AMREX_SPACEDIM);
99  for (int i(0); i < nline; i++) {
100  amrex::Vector<amrex::Real> rv = {real_hi[AMREX_SPACEDIM*i+0],
101  real_hi[AMREX_SPACEDIM*i+1],
102  real_hi[AMREX_SPACEDIM*i+2]};
103  rv_hi.push_back(rv);
104  }
105 
106  // Construct vector of bounding real boxes
107  m_bnd_rbx.resize(nline);
108  for (int i = 0; i < nline; i++){
109  amrex::RealBox rbx(rv_lo[i].data(),rv_hi[i].data());
110  m_bnd_rbx[i] = rbx;
111  }
112 
113  // Construct vector of bounding boxes
114  m_bnd_bx.resize(nline);
115  }
116  }
117 
118  if (nline > 0) {
119  // Parse directionality
120  m_dir.resize(n_line_dir);
121  pp.queryarr("sample_line_dir",m_dir,0,n_line_dir);
122 
123  // Parse names
124  std::string name_base = "plt_line_";
125  m_name.resize(nline);
126  int n_names = pp.countval("sample_line_name");
127  if (n_names > 0) {
128  AMREX_ALWAYS_ASSERT( n_names==nline );
129  pp.queryarr("sample_line_name",m_name,0,n_names);
130  } else {
131  for (int iline(0); iline<nline; ++iline) {
132  m_name[iline] = amrex::Concatenate(name_base, iline , 5);
133  }
134  }
135 
136  // Allocate space for level indicator
137  m_lev.resize(n_line_dir,0);
138 
139  // Allocate space for MF pointers
140  m_ls_mf.resize(nline);
141 
142  // Get requested vars
143  if (pp.countval("line_sampling_vars") > 0) {
144  m_varnames.clear();
145  amrex::Vector<std::string> requested_vars;
146  pp.queryarr("line_sampling_vars",requested_vars);
147  amrex::Print() << "Selected line sampling vars :";
148  if (containerHasElement(requested_vars, "density")) {
149  m_varnames.push_back("density");
150  amrex::Print() << " " << "density";
151  }
152  if (containerHasElement(requested_vars, "x_velocity")) {
153  m_varnames.push_back("x_velocity");
154  amrex::Print() << " " << "x_velocity";
155  }
156  if (containerHasElement(requested_vars, "y_velocity")) {
157  m_varnames.push_back("y_velocity");
158  amrex::Print() << " " << "y_velocity";
159  }
160  if (containerHasElement(requested_vars, "z_velocity")) {
161  m_varnames.push_back("z_velocity");
162  amrex::Print() << " " << "z_velocity";
163  }
164  if (containerHasElement(requested_vars, "magvel")) {
165  m_varnames.push_back("magvel");
166  amrex::Print() << " " << "magvel";
167  }
168  if (containerHasElement(requested_vars, "theta")) {
169  m_varnames.push_back("theta");
170  amrex::Print() << " " << "theta";
171  }
172  if (containerHasElement(requested_vars, "qv")) {
173  m_varnames.push_back("qv");
174  amrex::Print() << " " << "qv";
175  }
176  if (containerHasElement(requested_vars, "qc")) {
177  m_varnames.push_back("qc");
178  amrex::Print() << " " << "qc";
179  }
180  if (containerHasElement(requested_vars, "pressure")) {
181  m_varnames.push_back("pressure");
182  amrex::Print() << " " << "pressure";
183  }
184  amrex::Print() << std::endl;
185  }
186 
187  // Write outputs to text files, one file per variable, with all
188  // times appended to the same file
189  pp.query("line_sampling_text_output",m_write_ascii);
190  if (m_write_ascii && amrex::ParallelDescriptor::IOProcessor()) {
191  int nvar = static_cast<int>(m_varnames.size());
192  m_datastream.resize(nline * nvar);
193  int i = 0;
194  for (int iline(0); iline<nline; ++iline) {
195  for (int ivar(0); ivar<nvar; ++ivar) {
196  std::string filename = m_name[iline] + "." + m_varnames[ivar];
197  m_datastream[i] = std::make_unique<std::fstream>();
198  m_datastream[i]->open(filename.c_str(),std::ios::out|std::ios::app);
199  if (!m_datastream[i]->good()) {
200  amrex::FileOpenFailed(filename);
201  }
202  i++;
203  }
204  }
205  }
206  }
207  }
bool containerHasElement(const V &iterable, const T &query)
Definition: ERF_Container.H:5
struct @28 out
ParmParse pp("prob")
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
amrex::Vector< std::string > m_varnames
Definition: ERF_SampleData.H:567
amrex::Vector< amrex::MultiFab > m_ls_mf
Definition: ERF_SampleData.H:562
amrex::Vector< std::unique_ptr< std::fstream > > m_datastream
Definition: ERF_SampleData.H:568
bool m_use_real_bx
Definition: ERF_SampleData.H:565
amrex::Vector< int > m_dir
Definition: ERF_SampleData.H:558
amrex::Vector< std::string > m_name
Definition: ERF_SampleData.H:563
amrex::Vector< amrex::Box > m_bnd_bx
Definition: ERF_SampleData.H:560
bool m_write_ascii
Definition: ERF_SampleData.H:566
amrex::Vector< amrex::RealBox > m_bnd_rbx
Definition: ERF_SampleData.H:561
amrex::Vector< int > m_lev
Definition: ERF_SampleData.H:559
Here is the call graph for this function:

Member Function Documentation

◆ get_sample_data()

void LineSampler::get_sample_data ( amrex::Vector< amrex::Geometry > &  geom,
amrex::Vector< amrex::Vector< amrex::MultiFab >> &  vars_new 
)
inline
281  {
282  int nlev = static_cast<int>(vars_new.size());
283  int nline = static_cast<int>(m_bnd_bx.size());
284  int ncomp = static_cast<int>(m_varnames.size());
285 
286  int qv_comp = -1;
287 
288  // Loop over each line
289  for (int iline(0); iline<nline; ++iline) {
290  int dir = m_dir[iline];
291 
292  // Search each level to get the finest data possible
293  for (int ilev(nlev-1); ilev>=0; --ilev) {
294  amrex::Box bnd_bx = (m_use_real_bx)
295  ? getIndexBox(m_bnd_rbx[iline], geom[ilev])
296  : m_bnd_bx[iline];
297  amrex::IntVect cell = bnd_bx.smallEnd();
298 
299  // Construct CC velocities
300  amrex::MultiFab mf_cc_vel;
301  auto ba = vars_new[ilev][Vars::cons].boxArray();
302  auto dm = vars_new[ilev][Vars::cons].DistributionMap();
303  mf_cc_vel.define(ba, dm, AMREX_SPACEDIM, amrex::IntVect(1,1,1));
304  average_face_to_cellcenter(mf_cc_vel,0,
305  amrex::Array<const amrex::MultiFab*,3>{&vars_new[ilev][Vars::xvel],
306  &vars_new[ilev][Vars::yvel],
307  &vars_new[ilev][Vars::zvel]});
308 
309  // Construct MultiFab holding requested variables
310  amrex::MultiFab mf_cc_data;
311  mf_cc_data.define(ba, dm, ncomp, 1);
312 
313  int mf_comp = 0;
314 
315  if (containerHasElement(m_varnames, "density")) {
316  amrex::MultiFab::Copy(mf_cc_data, vars_new[ilev][Vars::cons], Rho_comp, mf_comp, 1, 0);
317  mf_comp += 1;
318  }
319 
320  if (containerHasElement(m_varnames, "x_velocity")) {
321  amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 0, mf_comp, 1, 0);
322  mf_comp += 1;
323  }
324  if (containerHasElement(m_varnames, "y_velocity")) {
325  amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 1, mf_comp, 1, 0);
326  mf_comp += 1;
327  }
328  if (containerHasElement(m_varnames, "z_velocity")) {
329  amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 2, mf_comp, 1, 0);
330  mf_comp += 1;
331  }
332 
333  if (containerHasElement(m_varnames, "magvel")) {
334 #ifdef _OPENMP
335 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
336 #endif
337  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
338  const amrex::Box& tbx = mfi.tilebox();
339  auto const& dfab = mf_cc_data.array(mfi);
340  auto const& vfab = mf_cc_vel.array(mfi);
341 
342  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
343  {
344  dfab(i,j,k,mf_comp) = std::sqrt(vfab(i,j,k,0)*vfab(i,j,k,0)
345  + vfab(i,j,k,1)*vfab(i,j,k,1)
346  + vfab(i,j,k,2)*vfab(i,j,k,2)) ;
347  });
348  }
349  mf_comp += 1;
350  }
351 
352  if (containerHasElement(m_varnames, "theta")) {
353 #ifdef _OPENMP
354 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
355 #endif
356  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
357  const amrex::Box& tbx = mfi.tilebox();
358  auto const& dfab = mf_cc_data.array(mfi);
359  auto const& cfab = vars_new[ilev][Vars::cons].array(mfi);
360 
361  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
362  {
363  dfab(i,j,k,mf_comp) = cfab(i,j,k,RhoTheta_comp) / cfab(i,j,k,Rho_comp);
364  });
365  }
366  mf_comp += 1;
367  }
368 
369  if (containerHasElement(m_varnames, "qv")) {
370  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(vars_new[ilev][Vars::cons].nComp() > RhoQ1_comp,
371  "qv sampling requested but moisture components not present in state");
372  if (qv_comp >= 0) AMREX_ALWAYS_ASSERT(qv_comp == mf_comp);
373  qv_comp = mf_comp;
374 #ifdef _OPENMP
375 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
376 #endif
377  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
378  const amrex::Box& tbx = mfi.tilebox();
379  auto const& dfab = mf_cc_data.array(mfi);
380  auto const& cfab = vars_new[ilev][Vars::cons].array(mfi);
381 
382  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
383  {
384  dfab(i,j,k,mf_comp) = cfab(i,j,k,RhoQ1_comp) / cfab(i,j,k,Rho_comp);
385  });
386  }
387  mf_comp += 1;
388  }
389  if (containerHasElement(m_varnames, "qc")) {
390  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(vars_new[ilev][Vars::cons].nComp() > RhoQ2_comp,
391  "qc sampling requested but moisture components not present in state");
392 #ifdef _OPENMP
393 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
394 #endif
395  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
396  const amrex::Box& tbx = mfi.tilebox();
397  auto const& dfab = mf_cc_data.array(mfi);
398  auto const& cfab = vars_new[ilev][Vars::cons].array(mfi);
399 
400  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
401  {
402  dfab(i,j,k,mf_comp) = cfab(i,j,k,RhoQ2_comp) / cfab(i,j,k,Rho_comp);
403  });
404  }
405  mf_comp += 1;
406  }
407 
408  if (containerHasElement(m_varnames, "pressure")) {
409  if (vars_new[ilev][Vars::cons].nComp() > RhoQ1_comp) {
410  // moist pressure: use qv from dfab if already sampled, else compute inline
411 #ifdef _OPENMP
412 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
413 #endif
414  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
415  const amrex::Box& tbx = mfi.tilebox();
416  auto const& dfab = mf_cc_data.array(mfi);
417  auto const& cfab = vars_new[ilev][Vars::cons].array(mfi);
418 
419  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
420  {
421  amrex::Real qv_val = (qv_comp >= 0) ? dfab(i,j,k,qv_comp)
422  : cfab(i,j,k,RhoQ1_comp) / cfab(i,j,k,Rho_comp);
423  dfab(i,j,k,mf_comp) = getPgivenRTh(cfab(i,j,k,RhoTheta_comp), qv_val);
424  });
425  }
426  } else {
427  // dry pressure
428 #ifdef _OPENMP
429 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
430 #endif
431  for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
432  const amrex::Box& tbx = mfi.tilebox();
433  auto const& dfab = mf_cc_data.array(mfi);
434  auto const& cfab = vars_new[ilev][Vars::cons].array(mfi);
435 
436  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
437  {
438  dfab(i,j,k,mf_comp) = getPgivenRTh(cfab(i,j,k,RhoTheta_comp));
439  });
440  }
441  }
442  mf_comp += 1;
443  }
444 
445  m_lev[iline] = ilev;
446  m_ls_mf[iline] = get_line_data(mf_cc_data, dir, cell, bnd_bx);
447 
448  // We can stop if we got the entire line
449  auto min_bnd_bx = m_ls_mf[iline].boxArray().minimalBox();
450  if (bnd_bx == min_bnd_bx) { break; }
451 
452  } // ilev
453 
454  // Fill bnd_bx if use_rbx
455  if (m_use_real_bx) {
456  m_bnd_bx[iline] = m_ls_mf[iline].boxArray().minimalBox();
457  }
458 
459  }// iline
460  }
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:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:43
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:42
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_cloud_chamber_config.active, "Cloud Chamber: initializer reached without a parsed configuration")
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);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ xvel
Definition: ERF_IndexDefines.H:177
@ cons
Definition: ERF_IndexDefines.H:176
@ zvel
Definition: ERF_IndexDefines.H:179
@ yvel
Definition: ERF_IndexDefines.H:178
amrex::Box getIndexBox(const amrex::RealBox &real_box, const amrex::Geometry &geom)
Definition: ERF_SampleData.H:210
Here is the call graph for this function:

◆ getIndexBox()

amrex::Box LineSampler::getIndexBox ( const amrex::RealBox &  real_box,
const amrex::Geometry &  geom 
)
inline
211  {
212  amrex::IntVect slice_lo, slice_hi;
213 
214  AMREX_D_TERM(slice_lo[0]=static_cast<int>(std::floor((real_box.lo(0) - geom.ProbLo(0))/geom.CellSize(0)));,
215  slice_lo[1]=static_cast<int>(std::floor((real_box.lo(1) - geom.ProbLo(1))/geom.CellSize(1)));,
216  slice_lo[2]=static_cast<int>(std::floor((real_box.lo(2) - geom.ProbLo(2))/geom.CellSize(2))););
217 
218  AMREX_D_TERM(slice_hi[0]=static_cast<int>(std::floor((real_box.hi(0) - geom.ProbLo(0))/geom.CellSize(0)));,
219  slice_hi[1]=static_cast<int>(std::floor((real_box.hi(1) - geom.ProbLo(1))/geom.CellSize(1)));,
220  slice_hi[2]=static_cast<int>(std::floor((real_box.hi(2) - geom.ProbLo(2))/geom.CellSize(2))););
221 
222  return amrex::Box(slice_lo, slice_hi) & geom.Domain();
223  }

Referenced by get_sample_data(), and write_coords().

Here is the caller graph for this function:

◆ write_coords()

void LineSampler::write_coords ( amrex::Vector< std::unique_ptr< amrex::MultiFab > > &  z_phys_cc,
amrex::Vector< amrex::Geometry > &  geom 
)
inline
228  {
229  if (!m_write_ascii) return;
230 
231  amrex::Print() << "Writing out line coordinates to text" << std::endl;
232 
233  for (int lev(0); lev < z_phys_cc.size(); ++lev) {
234  // Write one text file per level
235  std::ofstream outfile;
236  if (amrex::ParallelDescriptor::IOProcessor()) {
237  std::string fname = amrex::Concatenate("plt_line_lev", lev, 1);
238  fname += ".zcc";
239  outfile.open(fname);
240 
241  if (!outfile.is_open()) {
242  amrex::AllPrint() << "Could not open " << fname << std::endl;
243  }
244  }
245 
246  // Loop over each line
247  int nline = static_cast<int>(m_ls_mf.size());
248  for (int iline(0); iline<nline; ++iline) {
249  int dir = m_dir[iline];
250  amrex::Box bnd_bx = (m_use_real_bx)
251  ? getIndexBox(m_bnd_rbx[iline], geom[lev])
252  : m_bnd_bx[iline];
253  amrex::IntVect first_cell = bnd_bx.smallEnd();
254 
255  // Create multifab with "sampled" z_phys values
256  amrex::MultiFab line_coords_mf = get_line_data(
257  *z_phys_cc[lev], dir, first_cell, bnd_bx
258  );
259 
260  // Convert multifab to vector
261  amrex::Gpu::HostVector<amrex::Real> vec = sumToLine(
262  line_coords_mf, 0, 1, bnd_bx, dir
263  );
264 
265  // Append to file
266  if (amrex::ParallelDescriptor::IOProcessor()) {
267  for (const auto& zval : vec) {
268  outfile << " " << zval;
269  }
270  outfile << std::endl;
271  }
272  } // line loop
273 
274  outfile.close();
275  } // level loop
276  }
Here is the call graph for this function:

◆ write_line_ascii()

void LineSampler::write_line_ascii ( amrex::Vector< double > &  time)
inline
477  {
478  // same as definitions in ERF.H
479  constexpr int datwidth = 14;
480  constexpr int datprecision = 6;
481  constexpr int timeprecision = 13;
482 
483  int nline = static_cast<int>(m_ls_mf.size());
484  int nvar = static_cast<int>(m_varnames.size());
485  for (int iline(0); iline<nline; ++iline) {
486  int dir = m_dir[iline];
487  int lev = m_lev[iline];
488  double m_time = time[lev];
489  amrex::Box m_dom = m_bnd_bx[iline];
490 
491  for (int ivar(0); ivar<nvar; ++ivar) {
492  // Convert multifab to vector
493  amrex::Gpu::HostVector<amrex::Real> vec = sumToLine(m_ls_mf[iline], ivar, 1, m_dom, dir);
494 
495  if (amrex::ParallelDescriptor::IOProcessor()) {
496  int ifile = iline*nvar + ivar;
497  std::ostream& fs = *m_datastream[ifile];
498  fs << std::setw(datwidth) << std::setprecision(timeprecision) << m_time
499  << std::setw(datwidth) << std::setprecision(datprecision);
500  for (const auto& val : vec) {
501  fs << " " << val;
502  }
503  fs << std::endl;
504  }
505  }
506  }
507  }
@ fs
Definition: ERF_AdvanceMorrison.cpp:122

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
514  {
515  int nline = static_cast<int>(m_ls_mf.size());
516  for (int iline(0); iline<nline; ++iline) {
517  // Data members that can be used as-is
518  int dir = m_dir[iline];
519  int lev = m_lev[iline];
520  double m_time = time[lev];
521  amrex::Vector<int> m_level_steps = {level_steps[lev]};
522  amrex::Vector<amrex::IntVect> m_ref_ratio = {ref_ratio[lev]};
523 
524  // Create modified geometry object corresponding to the line
525  auto plo = geom[lev].ProbLo();
526  auto dx = geom[lev].CellSize();
527  amrex::Vector<amrex::Geometry> m_geom; m_geom.resize(1);
528  amrex::Vector<int> is_per(AMREX_SPACEDIM,0);
529  amrex::Box m_dom = m_bnd_bx[iline];
530  amrex::RealBox m_rb;
531  for (int d(0); d<AMREX_SPACEDIM; ++d) {
532  amrex::Real offset = (d==dir) ? 0 : myhalf;
533  amrex::Real lo = plo[d] + ( m_dom.smallEnd(d) - offset ) * dx[d];
534  amrex::Real hi = plo[d] + ( m_dom.bigEnd(d) + offset ) * dx[d];
535 
536  m_rb.setLo(d,lo);
537  m_rb.setHi(d,hi);
538 
539  is_per[d] = geom[lev].isPeriodic(d);
540  }
541  m_geom[0].define(m_dom, &m_rb, geom[lev].Coord(), is_per.data());
542 
543  // Create plotfile name
544  std::string name_line = m_name[iline];
545  name_line += "_step_";
546  std::string plotfilename = amrex::Concatenate(name_line, m_level_steps[0], 5);
547 
548  // Get the data
549  amrex::Vector<const amrex::MultiFab*> mf = {&(m_ls_mf[iline])};
550 
551  // Write each line
552  WriteMultiLevelPlotfile(plotfilename, 1, mf,
553  m_varnames, m_geom, static_cast<amrex::Real>(m_time),
554  m_level_steps, m_ref_ratio);
555  }
556  }
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
Coord
Coordinate-axis selector.
Definition: ERF_DataStruct.H:143
const Real dx
Definition: ERF_InitCustomPert_ABL.H:23
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:31

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
467  {
468  if (m_write_ascii) {
469  write_line_ascii(time);
470  } else {
471  write_line_plotfile(time, level_steps, ref_ratio, geom);
472  }
473  }
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:510
void write_line_ascii(amrex::Vector< double > &time)
Definition: ERF_SampleData.H:476
Here is the call graph for this function:

Member Data Documentation

◆ m_bnd_bx

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

◆ m_bnd_rbx

amrex::Vector<amrex::RealBox> LineSampler::m_bnd_rbx

◆ m_datastream

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

Referenced by LineSampler(), and write_line_ascii().

◆ m_dir

amrex::Vector<int> LineSampler::m_dir

◆ m_lev

amrex::Vector<int> LineSampler::m_lev

◆ m_ls_mf

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

◆ m_name

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

Referenced by LineSampler(), and write_line_plotfile().

◆ m_use_real_bx

bool LineSampler::m_use_real_bx {false}

◆ m_varnames

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

◆ m_write_ascii

bool LineSampler::m_write_ascii {false}

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