4 #ifndef ERF_SAMPLEDATA_H
5 #define ERF_SAMPLEDATA_H
12 #include <AMReX_ParmParse.H>
13 #include <AMReX_MultiFab.H>
14 #include <AMReX_MultiFabUtil.H>
15 #include <AMReX_PlotFileUtil.H>
16 #include <AMReX_RealVect.H>
33 amrex::Real value = amrex::Real(-9999.0);
34 amrex::ParmParse
pp(
"erf");
35 pp.queryAdd(
"sampling_covered_value", value);
47 while (nlev <
static_cast<int>(vars_new.size()) &&
48 static_cast<int>(vars_new[nlev].size()) >
Vars::cons &&
59 amrex::ParmParse
pp(
"erf");
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");
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");
79 (n_line_lo==n_line_dir) );
80 }
else if (has_line_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");
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]);
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]);
121 for (
int i = 0; i < nline; i++){
122 amrex::Box lbx(iv_lo[i],iv_hi[i]);
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;
138 }
else if (has_line_real) {
140 nline = n_line_lo_real;
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]};
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]};
166 for (
int i = 0; i < nline; i++){
167 amrex::RealBox rbx(rv_lo[i].data(),rv_hi[i].data());
174 }
else if (has_line_latlon) {
180 nline = n_line_lo_latlon;
191 m_dir.resize(n_line_dir);
192 pp.queryarr(
"sample_line_dir",
m_dir,0,n_line_dir);
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");
202 for (
int d(0); d<AMREX_SPACEDIM; ++d) {
203 const bool differ = has_line_idx
206 const bool reversed = has_line_idx
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));
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");
224 std::string name_base =
"plt_line_";
226 int n_names =
pp.countval(
"sample_line_name");
229 pp.queryarr(
"sample_line_name",
m_name,0,n_names);
231 for (
int iline(0); iline<nline; ++iline) {
232 m_name[iline] = amrex::Concatenate(name_base, iline , 5);
237 m_lev.resize(n_line_dir,0);
244 if (
pp.countval(
"line_sampling_vars") > 0) {
246 amrex::Vector<std::string> requested_vars;
247 pp.queryarr(
"line_sampling_vars",requested_vars);
248 amrex::Print() <<
"Selected line sampling vars :";
252 amrex::Print() <<
" " <<
name;
255 amrex::Print() << std::endl;
265 pp.queryAdd(
"sample_line_z_agl",
m_z_agl);
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");
278 const int n_npts =
pp.countval(
"sample_line_npts");
280 if (n_npts != nline) {
281 amrex::Abort(
"erf.sample_line_npts must give one value per line (0 for a horizontal line)");
283 pp.getarr(
"sample_line_npts",
m_npts, 0, nline);
286 for (
int iline(0); iline<nline; ++iline) {
294 }
else if (
pp.contains(
"sample_line_npts")) {
295 amrex::Abort(
"erf.sample_line_npts is used only with erf.sample_line_interp = true");
302 amrex::Abort(
"Line sampling with erf.sample_line_lo_real/hi_real is not supported "
303 "with erf.terrain_type = MovingFittedMesh");
328 const amrex::Vector<std::string>& log_names,
329 const amrex::Box& domain)
332 const int nline =
static_cast<int>(cells.size());
333 constexpr
int dir = 2;
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);
341 m_dir.assign(nline, dir);
342 m_lev.assign(nline, 0);
346 m_varnames = {
"conserved",
"x_velocity",
"y_velocity",
"z_velocity",
347 "sgs_tau11",
"sgs_tau12",
"sgs_tau13",
"sgs_tau22",
"sgs_tau23",
"sgs_tau33"};
367 const amrex::Vector<amrex::RealVect>& points,
368 const amrex::Vector<std::string>& log_names,
372 const int nline =
static_cast<int>(log_names.size());
376 if (!cells.empty()) {
377 for (
int iline(0); iline<nline; ++iline) {
378 m_bnd_bx[iline] = amrex::Box(cells[iline], cells[iline]);
385 for (
int iline(0); iline<nline; ++iline) {
386 m_bnd_rbx[iline] = amrex::RealBox(points[iline].dataPtr(), points[iline].dataPtr());
390 amrex::Abort(
"erf.sample_point_real and erf.sample_point_latlon are not supported "
391 "with erf.terrain_type = MovingFittedMesh");
395 m_dir.assign(nline, 2);
396 m_lev.assign(nline, 0);
409 if (amrex::ParallelDescriptor::IOProcessor()) {
410 const int nline =
static_cast<int>(log_names.size());
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);
416 amrex::FileOpenFailed(log_names[iline]);
420 amrex::ParallelDescriptor::Barrier(
"LineSampler::open_logs");
424 static const amrex::Vector<std::string>&
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"};
440 amrex::Vector<std::string> names;
441 for (
int n(0); n<ncons; ++n) { names.push_back(amrex::Concatenate(
"cons_", n, 1)); }
443 m_varnames.insert(it, names.begin(), names.end());
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());
455 for (
int iline(0); iline<nline; ++iline) {
456 for (
int ivar(0); ivar<nvar; ++ivar) {
459 m_datastream[i]->open(filename.c_str(),std::ios::out|std::ios::app);
461 amrex::FileOpenFailed(filename);
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";
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");
496 if (req[0][2] > req[1][2]) {
497 amrex::Abort(line +
" has its lo end above its hi end");
499 }
else if (req[0][2] != req[1][2]) {
500 amrex::Abort(line +
" is horizontal, so its two ends must give the same z");
504 const int nend = (dir == 2) ? 1 : 2;
506 for (
int e(0); e<nend; ++e) {
508 line + (e == 0 ?
", lo end," :
", hi end,"));
510 if (dir == 2) { where[1] = where[0]; }
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);
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");
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");
530 hi[across] =
lo[across];
535 amrex::Print() << line <<
": lo end at lat=" << where[0].
lat <<
" long=" << where[0].
lon
536 <<
" (x=" <<
lo[0] <<
" y=" <<
lo[1] <<
")";
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";
542 amrex::Print() << std::endl;
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) {
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");
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");
578 [[nodiscard]] amrex::Vector<amrex::Real>
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);
592 [[nodiscard]] amrex::Box
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);
605 static amrex::Vector<amrex::Real>
606 gather_box (
const amrex::MultiFab& src,
int scomp,
int ncomp,
const amrex::Box& bx,
bool to_all)
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());
619 if (to_all) { amrex::ParallelDescriptor::Bcast(v.data(), v.size(), io); }
633 amrex::Vector<amrex::Real>
zt;
635 amrex::Vector<amrex::Real>
w;
659 make_interp_plan (
int iline,
int lev,
const amrex::Geometry& geom,
const amrex::Geometry& geom0,
660 const amrex::MultiFab& z_cc,
const amrex::MultiFab* z_nd,
661 const amrex::MultiFab* volfrac,
const amrex::MultiFab* ground,
662 const amrex::MultiFab* ground0)
const
665 plan.
ba = z_cc.boxArray();
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();
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);
686 t.setVal(amrex::Real(1.0), 2, 1, 0);
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];
693 auto held_at = [&] (
int icol,
int k) {
return at(icol, k, 1) > amrex::Real(0.5); };
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);
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)]);
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);
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));
731 const amrex::IntVect nlo(*std::min_element(i0.begin(), i0.end()), *std::min_element(j0.begin(), j0.end()),
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));
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]; }
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]; }
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));
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];
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; }
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);
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));
794 if (k0 < 0 && fluid(nz-1) &&
z >=
zc(nz-1)) { k0 =
k1 = nz-1; }
799 while (kf < nz && held(kf) && !fluid(kf)) { ++kf; }
800 if (kf < nz && fluid(kf) &&
z <
zc(kf)) { k0 =
k1 = kf; }
806 if (lev == 0) { plan.
missing[s] = 1;
continue; }
813 kmin = std::min(kmin, k0);
814 kmax = std::max(kmax,
k1);
818 plan.
cells.setSmall(2, kdlo + kmin);
819 plan.
cells.setBig(2, kdlo + kmax);
825 static const amrex::MultiFab*
826 level_ptr (
const amrex::Vector<const amrex::MultiFab*>& v,
int lev)
828 return lev < static_cast<int>(v.size()) ? v[lev] :
nullptr;
833 cachedInterpPlan (
int iline,
int lev,
const amrex::Geometry& geom,
const amrex::Geometry& geom0,
834 const amrex::MultiFab& z_cc,
const amrex::MultiFab* z_nd,
835 const amrex::MultiFab* volfrac,
const amrex::MultiFab* ground,
836 const amrex::MultiFab* ground0)
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);
857 const int ncomp = data.nComp();
858 const int nsamp =
static_cast<int>(plan.
zt.size());
859 amrex::Vector<amrex::Real> d;
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];
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) {
879 }
else if (plan.
missing[s] != 0) {
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); }
886 v[
static_cast<std::size_t
>(s) +
static_cast<std::size_t
>(nsamp) * n] = val;
889 amrex::Gpu::copy(amrex::Gpu::hostToDevice, v.begin(), v.end(), out[0].dataPtr());
907 static amrex::Vector<amrex::Gpu::HostVector<amrex::Real>>
909 const amrex::IntVect& cell)
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);
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);
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);
930 return {amrex::sumToLine(f, 0, 1, col, 2), amrex::sumToLine(f, 1, 1, col, 2),
931 amrex::sumToLine(f, 2, 1, col, 2)};
940 column_ground (
const amrex::MultiFab& ground_nd,
const amrex::Geometry& geom,
941 const amrex::IntVect& cell)
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) {
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)) };
958 amrex::Real ground = amrex::get<0>(reduce_data.value(reduce_op));
959 amrex::ParallelAllReduce::Sum(ground, amrex::ParallelContext::CommunicatorSub());
965 line_ground (
int iline,
const amrex::Geometry& geom0,
const amrex::MultiFab* ground_nd)
967 if (!
m_z_agl) {
return amrex::Real(0.0); }
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());
973 for (
int l(0); l<nline; ++l) {
987 const amrex::MultiFab& z_nd, amrex::Real ground)
994 const int nline =
static_cast<int>(
m_bnd_rbx.size());
1016 lineIndexBox (
int iline,
const amrex::Geometry& geom,
const amrex::MultiFab& z_nd,
1019 const amrex::RealBox& rb =
m_bnd_rbx[iline];
1021 const amrex::IntVect cell = ibx.smallEnd();
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);
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; }
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(); }
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);
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));
1061 lo[2] =
hi[2] = geom.Domain().smallEnd(2);
1062 return amrex::Box(
lo,
hi);
1067 const amrex::Geometry& geom) {
1068 amrex::IntVect slice_lo, slice_hi;
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))););
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))););
1078 return amrex::Box(slice_lo, slice_hi) & geom.Domain();
1083 amrex::Vector<std::unique_ptr<amrex::MultiFab> >& z_phys_nd,
1084 amrex::Vector<amrex::Geometry>& geom,
1085 const amrex::MultiFab* ground_nd =
nullptr,
1086 const amrex::Vector<const amrex::MultiFab*>& ground_lev = {},
1087 const amrex::Vector<const amrex::MultiFab*>& volfrac_lev = {})
1092 int nlev =
static_cast<int>(z_phys_cc.size());
1094 for (
int lev(0); lev < nlev; ++lev) {
1097 if (!z_phys_cc[lev] || lev >=
static_cast<int>(z_phys_nd.size()) || !z_phys_nd[lev]) {
break; }
1102 if (
m_zcc_ba[lev] == z_phys_cc[lev]->boxArray()) {
continue; }
1103 m_zcc_ba[lev] = z_phys_cc[lev]->boxArray();
1105 amrex::Print() <<
"Writing out line coordinates of level " << lev <<
" to text" << std::endl;
1108 std::ofstream outfile;
1109 if (amrex::ParallelDescriptor::IOProcessor()) {
1110 std::string fname = amrex::Concatenate(
"plt_line_lev", lev, 1);
1112 outfile.open(fname);
1114 if (!outfile.is_open()) {
1115 amrex::AllPrint() <<
"Could not open " << fname << std::endl;
1120 int nline =
static_cast<int>(
m_ls_mf.size());
1121 for (
int iline(0); iline<nline; ++iline) {
1122 int dir =
m_dir[iline];
1126 const InterpPlan& plan =
cachedInterpPlan(iline, lev, geom[lev], geom[0], *z_phys_cc[lev],
1129 if (amrex::ParallelDescriptor::IOProcessor()) {
1131 for (
const auto& zval : plan.zt) { outfile <<
" " << zval; }
1133 outfile << std::endl;
1140 const amrex::Real ground =
line_ground(iline, geom[0], ground_nd);
1142 if (bnd_bx.isEmpty()) {
1144 if (amrex::ParallelDescriptor::IOProcessor()) { outfile << std::endl; }
1151 amrex::IntVect first_cell = bnd_bx.smallEnd();
1154 amrex::MultiFab line_coords_mf = get_line_data(
1155 *z_phys_cc[lev], dir, first_cell, bnd_bx
1159 amrex::Gpu::HostVector<amrex::Real> vec = sumToLine(
1160 line_coords_mf, 0, 1, bnd_bx, dir
1164 if (amrex::ParallelDescriptor::IOProcessor()) {
1165 for (
const auto& zval : vec) {
1166 outfile <<
" " << zval;
1168 outfile << std::endl;
1178 amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars_new,
1179 const amrex::Vector<amrex::Vector<amrex::MultiFab*>>& tau_lev = {},
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 = {})
1192 int nline =
static_cast<int>(
m_bnd_bx.size());
1193 int ncomp =
static_cast<int>(
m_varnames.size());
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];
1209 "Line sampling by height needs the nodal heights of each level");
1212 auto interp_plan = [&] (
int iline,
int ilev) ->
const InterpPlan& {
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,
1219 auto line_box = [&] (
int iline,
int ilev) -> amrex::Box {
1221 const InterpPlan& plan = interp_plan(iline, ilev);
1222 return plan.holds ? plan.cols : amrex::Box();
1225 if (ilev >=
static_cast<int>(z_nd_lev.size()) || z_nd_lev[ilev] ==
nullptr) {
return amrex::Box(); }
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);
1245 if (lines.empty()) {
continue; }
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],
1258 amrex::MultiFab mf_cc_data;
1259 mf_cc_data.define(ba, dm, ncomp, 1);
1267 amrex::MultiFab::Copy(mf_cc_data, vars_new[ilev][
Vars::cons], 0, mf_comp,
m_ncons, 0);
1273 amrex::MultiFab* z_cc = ilev < static_cast<int>(z_cc_lev.size()) ? z_cc_lev[ilev] :
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);
1282 const amrex::MultiFab* volfrac = ilev < static_cast<int>(volfrac_lev.size())
1283 ? volfrac_lev[ilev] :
nullptr;
1285 if (volfrac !=
nullptr) {
1286 amrex::MultiFab::Copy(mf_cc_data, *volfrac, 0, mf_comp, 1, 0);
1288 mf_cc_data.setVal(1.0, mf_comp, 1, 0);
1295 amrex::MultiFab::Copy(mf_cc_data, vars_new[ilev][
Vars::cons],
Rho_comp, mf_comp, 1, 0);
1300 amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 0, mf_comp, 1, 0);
1304 amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 1, mf_comp, 1, 0);
1308 amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 2, mf_comp, 1, 0);
1314 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
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);
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)) ;
1333 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
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);
1350 "qv sampling requested but moisture components not present in state");
1354 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
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);
1370 "qc sampling requested but moisture components not present in state");
1372 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
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);
1391 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
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);
1400 amrex::Real qv_val = (qv_comp >= 0) ? dfab(i,j,k,qv_comp)
1408 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
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);
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);
1432 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
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);
1448 auto sample_tau = [&] (
const char*
name,
int tau_type,
1449 amrex::IntVect
const& e1, amrex::IntVect
const& e2) {
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];
1458 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
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);
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));
1471 mf_cc_data.setVal(0.0, mf_comp, 1, 0);
1475 const amrex::IntVect ex(1,0,0), ey(0,1,0), ez(0,0,1), e0(0);
1484 amrex::MultiFab* hfx3 = ilev < static_cast<int>(hfx3_lev.size())
1485 ? hfx3_lev[ilev] :
nullptr;
1486 if (hfx3 !=
nullptr) {
1488 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
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);
1495 out(i,j,k,mf_comp) = amrex::Real(0.5) * (hfx(i,j,k) + hfx(i,j,k+1));
1499 mf_cc_data.setVal(0.0, mf_comp, 1, 0);
1506 if (volfrac !=
nullptr) {
1509 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
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;
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;
1532 m_ls_mf[iline] = get_line_data(mf_cc_data,
m_dir[iline], bnd_bx.smallEnd(), bnd_bx);
1535 if (bnd_bx ==
m_ls_mf[iline].boxArray().minimalBox()) { done[iline] = 1; }
1541 for (
int iline(0); iline<nline; ++iline) {
1549 amrex::Vector<int>& level_steps,
1550 amrex::Vector<amrex::IntVect>& ref_ratio,
1551 amrex::Vector<amrex::Geometry>& geom)
1567 constexpr
int datwidth = 14;
1568 constexpr
int datprecision = 6;
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];
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);
1582 if (amrex::ParallelDescriptor::IOProcessor()) {
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;
1601 constexpr
int datwidth = 14;
1602 constexpr
int datprecision = 6;
1603 constexpr
int timeprecision = 13;
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];
1615 for (
int ivar(0); ivar<nvar; ++ivar) {
1617 amrex::Gpu::HostVector<amrex::Real> vec = sumToLine(
m_ls_mf[iline], ivar, 1, m_dom, dir);
1619 if (amrex::ParallelDescriptor::IOProcessor()) {
1620 int ifile = iline*nvar + ivar;
1622 fs << std::setw(datwidth) << std::setprecision(timeprecision) << m_time
1623 << std::setw(datwidth) << std::setprecision(datprecision);
1624 for (
const auto& val : vec) {
1635 amrex::Vector<int>& level_steps,
1636 amrex::Vector<amrex::IntVect>& ref_ratio,
1637 amrex::Vector<amrex::Geometry>& geom)
1639 int nline =
static_cast<int>(
m_ls_mf.size());
1640 for (
int iline(0); iline<nline; ++iline) {
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]};
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) {
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];
1663 is_per[d] = geom[lev].isPeriodic(d);
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);
1675 m_geom[0].define(m_dom, &m_rb, geom[lev].
Coord(), is_per.data());
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);
1683 amrex::Vector<const amrex::MultiFab*> mf = {&(
m_ls_mf[iline])};
1686 WriteMultiLevelPlotfile(plotfilename, 1, mf,
1687 m_varnames, m_geom,
static_cast<amrex::Real
>(m_time),
1688 m_level_steps, m_ref_ratio);
1731 amrex::ParmParse
pp(
"erf");
1734 int n_plane_lo =
pp.countval(
"sample_plane_lo") / AMREX_SPACEDIM;
1735 int n_plane_hi =
pp.countval(
"sample_plane_hi") / AMREX_SPACEDIM;
1736 int n_plane_dir =
pp.countval(
"sample_plane_dir");
1738 (n_plane_lo==n_plane_dir) );
1741 if (n_plane_lo > 0) {
1743 amrex::Vector<amrex::Real> r_lo; r_lo.resize(n_plane_lo*AMREX_SPACEDIM);
1744 amrex::Vector<amrex::Vector<amrex::Real>> rv_lo;
1745 pp.queryarr(
"sample_plane_lo",r_lo,0,n_plane_lo*AMREX_SPACEDIM);
1746 for (
int i(0); i < n_plane_lo; i++) {
1747 amrex::Vector<amrex::Real> rv = {r_lo[AMREX_SPACEDIM*i+0],
1748 r_lo[AMREX_SPACEDIM*i+1],
1749 r_lo[AMREX_SPACEDIM*i+2]};
1750 rv_lo.push_back(rv);
1754 amrex::Vector<amrex::Real> r_hi; r_hi.resize(n_plane_hi*AMREX_SPACEDIM);
1755 amrex::Vector<amrex::Vector<amrex::Real>> rv_hi;
1756 pp.queryarr(
"sample_plane_hi",r_hi,0,n_plane_hi*AMREX_SPACEDIM);
1757 for (
int i(0); i < n_plane_hi; i++) {
1758 amrex::Vector<amrex::Real> rv = {r_hi[AMREX_SPACEDIM*i+0],
1759 r_hi[AMREX_SPACEDIM*i+1],
1760 r_hi[AMREX_SPACEDIM*i+2]};
1761 rv_hi.push_back(rv);
1766 for (
int i(0); i < n_plane_hi; i++){
1767 amrex::RealBox rbx(rv_lo[i].data(),rv_hi[i].data());
1772 m_dir.resize(n_plane_dir);
1773 pp.queryarr(
"sample_plane_dir",
m_dir,0,n_plane_dir);
1776 std::string name_base =
"plt_plane_";
1777 m_name.resize(n_plane_lo);
1778 int n_names =
pp.countval(
"sample_plane_name");
1781 pp.queryarr(
"sample_plane_name",
m_name,0,n_names);
1783 for (
int iplane(0); iplane<n_plane_lo; ++iplane) {
1784 m_name[iplane] = amrex::Concatenate(name_base, iplane , 5);
1795 if (
pp.countval(
"plane_sampling_vars") > 0) {
1797 amrex::Vector<std::string> requested_vars;
1798 pp.queryarr(
"plane_sampling_vars",requested_vars);
1799 amrex::Print() <<
"Selected plane sampling vars :";
1802 amrex::Print() <<
" " <<
"density";
1806 amrex::Print() <<
" " <<
"x_velocity";
1810 amrex::Print() <<
" " <<
"y_velocity";
1814 amrex::Print() <<
" " <<
"z_velocity";
1818 amrex::Print() <<
" " <<
"magvel";
1822 amrex::Print() <<
" " <<
"theta";
1826 amrex::Print() <<
" " <<
"qv";
1830 amrex::Print() <<
" " <<
"qc";
1834 amrex::Print() <<
" " <<
"pressure";
1840 amrex::Print() <<
" " <<
"z_phys";
1844 amrex::Print() <<
" " <<
"volfrac";
1846 amrex::Print() << std::endl;
1863 const amrex::Geometry& geom) {
1864 amrex::IntVect slice_lo, slice_hi;
1866 AMREX_D_TERM(slice_lo[0]=
static_cast<int>(std::floor((real_box.lo(0) - geom.ProbLo(0))/geom.CellSize(0)));,
1867 slice_lo[1]=
static_cast<int>(std::floor((real_box.lo(1) - geom.ProbLo(1))/geom.CellSize(1)));,
1868 slice_lo[2]=
static_cast<int>(std::floor((real_box.lo(2) - geom.ProbLo(2))/geom.CellSize(2))););
1870 AMREX_D_TERM(slice_hi[0]=
static_cast<int>(std::floor((real_box.hi(0) - geom.ProbLo(0))/geom.CellSize(0)));,
1871 slice_hi[1]=
static_cast<int>(std::floor((real_box.hi(1) - geom.ProbLo(1))/geom.CellSize(1)));,
1872 slice_hi[2]=
static_cast<int>(std::floor((real_box.hi(2) - geom.ProbLo(2))/geom.CellSize(2))););
1874 return amrex::Box(slice_lo, slice_hi) & geom.Domain();
1879 amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars_new,
1880 const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& z_phys_cc,
1881 const amrex::Vector<const amrex::MultiFab*>& volfrac_lev = {})
1884 int nplane =
static_cast<int>(
m_bnd_rbx.size());
1885 int ncomp =
static_cast<int>(
m_varnames.size());
1886 bool interpolate =
true;
1891 for (
int iplane(0); iplane<nplane; ++iplane) {
1892 int dir =
m_dir[iplane];
1893 amrex::RealBox bnd_rbx =
m_bnd_rbx[iplane];
1894 amrex::Real
point = bnd_rbx.lo(dir);
1900 for (
int ilev(0); ilev<=lev_cap; ++ilev) {
1904 amrex::Box plane_bx =
getIndexBox(bnd_rbx, geom[ilev]);
1905 int k_l =
static_cast<int>(std::floor((
point - geom[ilev].ProbLo(dir))
1906 / geom[ilev].CellSize(dir)));
1907 plane_bx.setSmall(dir, k_l); plane_bx.setBig(dir, k_l);
1908 if (!vars_new[ilev][
Vars::cons].boxArray().intersects(plane_bx)) {
break; }
1912 amrex::MultiFab mf_cc_vel;
1913 auto ba = vars_new[ilev][
Vars::cons].boxArray();
1914 auto dm = vars_new[ilev][
Vars::cons].DistributionMap();
1915 mf_cc_vel.define(ba, dm, AMREX_SPACEDIM, amrex::IntVect(1,1,1));
1916 average_face_to_cellcenter(mf_cc_vel,0,
1917 amrex::Array<const amrex::MultiFab*,3>{&vars_new[ilev][
Vars::xvel],
1923 amrex::MultiFab mf_cc_data;
1924 mf_cc_data.define(ba, dm, ncomp+1, 1);
1929 amrex::MultiFab::Copy(mf_cc_data, vars_new[ilev][
Vars::cons],
Rho_comp, mf_comp, 1, 0);
1934 amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 0, mf_comp, 1, 0);
1938 amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 1, mf_comp, 1, 0);
1942 amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 2, mf_comp, 1, 0);
1948 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1950 for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1951 const amrex::Box& tbx = mfi.tilebox();
1952 auto const& dfab = mf_cc_data.array(mfi);
1953 auto const& vfab = mf_cc_vel.array(mfi);
1957 dfab(i,j,k,mf_comp) = std::sqrt(vfab(i,j,k,0)*vfab(i,j,k,0)
1958 + vfab(i,j,k,1)*vfab(i,j,k,1)
1959 + vfab(i,j,k,2)*vfab(i,j,k,2));
1967 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1969 for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1970 const amrex::Box& tbx = mfi.tilebox();
1971 auto const& dfab = mf_cc_data.array(mfi);
1972 auto const& cfab = vars_new[ilev][
Vars::cons].array(mfi);
1984 "qv sampling requested but moisture components not present in state");
1988 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1990 for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1991 const amrex::Box& tbx = mfi.tilebox();
1992 auto const& dfab = mf_cc_data.array(mfi);
1993 auto const& cfab = vars_new[ilev][
Vars::cons].array(mfi);
2004 "qc sampling requested but moisture components not present in state");
2006 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2008 for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
2009 const amrex::Box& tbx = mfi.tilebox();
2010 auto const& dfab = mf_cc_data.array(mfi);
2011 auto const& cfab = vars_new[ilev][
Vars::cons].array(mfi);
2025 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2027 for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
2028 const amrex::Box& tbx = mfi.tilebox();
2029 auto const& dfab = mf_cc_data.array(mfi);
2030 auto const& cfab = vars_new[ilev][
Vars::cons].array(mfi);
2034 amrex::Real qv_val = (qv_comp >= 0) ? dfab(i,j,k,qv_comp)
2042 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2044 for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
2045 const amrex::Box& tbx = mfi.tilebox();
2046 auto const& dfab = mf_cc_data.array(mfi);
2047 auto const& cfab = vars_new[ilev][
Vars::cons].array(mfi);
2061 amrex::MultiFab::Copy(mf_cc_data, *z_phys_cc[ilev], 0, mf_comp, 1, 0);
2068 const amrex::MultiFab* volfrac = ilev < static_cast<int>(volfrac_lev.size())
2069 ? volfrac_lev[ilev] :
nullptr;
2072 if (volfrac !=
nullptr) {
2073 amrex::MultiFab::Copy(mf_cc_data, *volfrac, 0, mf_comp, 1, 1);
2075 mf_cc_data.setVal(1.0, mf_comp, 1, 1);
2080 if (volfrac !=
nullptr) {
2081 const int cov_comp = ncomp;
2083 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2085 for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
2086 const amrex::Box& gbx = mfi.growntilebox(1);
2087 const auto& out = mf_cc_data.array(mfi);
2088 const auto& vf = volfrac->const_array(mfi);
2090 out(i,j,k,cov_comp) = (vf(i,j,k) == amrex::Real(0.0)) ? amrex::Real(1.0)
2095 mf_cc_data.setVal(0.0, ncomp, 1, 1);
2103 const int fdir = dir;
2104 for (amrex::MFIter mfi(mf_cc_data); mfi.isValid(); ++mfi) {
2105 const amrex::Box& vbx = mfi.validbox();
2106 const int vlo = vbx.smallEnd(fdir);
2107 const int vhi = vbx.bigEnd(fdir);
2108 auto const& dfab = mf_cc_data.array(mfi);
2110 [=] AMREX_GPU_DEVICE(
int i,
int j,
int k,
int n) noexcept
2112 amrex::IntVect iv(i,j,k);
2113 if (iv[fdir] < vlo || iv[fdir] > vhi) {
2114 iv[fdir] = amrex::min(amrex::max(iv[fdir], vlo), vhi);
2115 dfab(i,j,k,n) = dfab(iv,n);
2119 mf_cc_data.FillBoundary(geom[ilev].periodicity());
2122 auto slice = get_slice_data(dir,
point, mf_cc_data, geom[ilev],
2123 0, ncomp+1, interpolate, bnd_rbx);
2126 if (!slice || slice->boxArray().size() == 0) {
break; }
2132 const int rr_l = 1 << ilev;
2133 const int k_slice = slice->boxArray().minimalBox().smallEnd(dir);
2134 const int l_dir = dir;
2138 const amrex::BoxArray& slice_ba = slice->boxArray();
2139 for (
int ib(0); ib<static_cast<int>(slice_ba.size()); ++ib) {
2140 amrex::Box b = slice_ba[ib];
2142 b.setBig(dir, rr_l - 1);
2145 amrex::BoxArray out_ba(std::move(bl));
2146 auto out_mf = std::make_unique<amrex::MultiFab>(out_ba, slice->DistributionMap(),
2149 for (amrex::MFIter mfi(*out_mf); mfi.isValid(); ++mfi) {
2150 const amrex::Box& obx = mfi.validbox();
2151 auto const& ofab = out_mf->array(mfi);
2152 auto const& sfab = slice->array(mfi);
2153 amrex::ParallelFor(obx, ncomp, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k,
int n) noexcept
2155 int si = i, sj = j, sk = k;
2156 if (l_dir == 0) { si = k_slice; }
2157 else if (l_dir == 1) { sj = k_slice; }
2158 else { sk = k_slice; }
2161 ofab(i,j,k,n) = (sfab(si,sj,sk,ncomp) > amrex::Real(0.0) &&
2162 n != vf_comp && n != z_comp)
2163 ? covered_value : sfab(si,sj,sk,n);
2167 m_ps_mf[iplane].push_back(std::move(out_mf));
2175 amrex::Vector<int>& level_steps,
2176 amrex::Vector<amrex::IntVect>& ref_ratio,
2177 amrex::Vector<amrex::Geometry>& geom)
2179 amrex::ignore_unused(ref_ratio);
2181 for (
int iplane(0); iplane<nplane; ++iplane) {
2182 int nlev_c =
static_cast<int>(
m_ps_mf[iplane].size());
2183 if (nlev_c == 0) {
continue; }
2185 int dir =
m_dir[iplane];
2186 amrex::RealBox bnd_rbx =
m_bnd_rbx[iplane];
2187 amrex::Real
point = bnd_rbx.lo(dir);
2192 amrex::Real dx0 = geom[0].CellSize(dir);
2193 amrex::RealBox shared_rbx = bnd_rbx;
2197 amrex::Vector<int> is_per(AMREX_SPACEDIM,0);
2198 for (
int d(0); d<AMREX_SPACEDIM; ++d) { is_per[d] = geom[0].isPeriodic(d); }
2204 amrex::Vector<const amrex::MultiFab*> mf(nlev_c);
2205 amrex::Vector<amrex::Geometry> m_geom(nlev_c);
2206 amrex::Vector<int> m_level_steps(nlev_c);
2207 amrex::Vector<amrex::IntVect> m_ref_ratio(nlev_c-1, amrex::IntVect(2));
2209 for (
int l(0); l<nlev_c; ++l) {
2210 const int rr_l = 1 << l;
2215 for (
int d(0); d<AMREX_SPACEDIM; ++d) {
2216 amrex::Real ratio = geom[0].CellSize(d) / geom[l].CellSize(d);
2218 std::abs(ratio -
static_cast<amrex::Real
>(rr_l)) < amrex::Real(1.e-6) * rr_l,
2219 "PlaneSampler multi-level output requires factor-2 isotropic refinement (amr.ref_ratio = 2 2 2)");
2222 amrex::Box domain_l = amrex::refine(B0, rr_l);
2223 domain_l.setSmall(dir, 0);
2224 domain_l.setBig(dir, rr_l - 1);
2226 mf[l] =
m_ps_mf[iplane][l].get();
2227 m_geom[l].define(domain_l, &shared_rbx, geom[l].
Coord(), is_per.data());
2228 m_level_steps[l] = level_steps[l];
2229 AMREX_ASSERT(domain_l.contains(mf[l]->boxArray().minimalBox()));
2233 std::string name_plane =
m_name[iplane];
2234 name_plane +=
"_step_";
2235 std::string plotfilename = amrex::Concatenate(name_plane, m_level_steps[0], 5);
2238 WriteMultiLevelPlotfile(plotfilename, nlev_c, mf,
2239 m_varnames, m_geom,
static_cast<amrex::Real
>(time[0]),
2240 m_level_steps, m_ref_ratio);
2247 amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab>>>
m_ps_mf;
std::vector< int > point
Definition: ERF_ActuatorSpreading.cpp:221
GpuArray< Real, AMREX_SPACEDIM > plo
Definition: ERF_ActuatorSpreading.cpp:131
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
bool containerHasElement(const V &iterable, const T &query)
Definition: ERF_Container.H:5
@ 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
Coord
Coordinate-axis selector.
Definition: ERF_DataStruct.H:226
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
pp_for_pert_vels get("prob_type", prob_type)
const Real zc
Definition: ERF_InitCustomPert_ABL.H:112
const Real xc
Definition: ERF_InitCustomPert_ABL.H:110
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:404
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);})
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:36
amrex::Real sampling_covered_value()
Definition: ERF_SampleData.H:31
int sampling_num_levels(const amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_new)
Definition: ERF_SampleData.H:44
Definition: ERF_LatLonMap.H:152
LatLonLocation locate_or_abort(amrex::Real req_lat, amrex::Real req_lon, const std::string &what) const
Definition: ERF_LatLonMap.cpp:233
@ fs
Definition: ERF_AdvanceMorrison.cpp:124
@ 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
@ p
Definition: ERF_WSM6.H:303
Definition: ERF_ConsoleIO.cpp:17
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
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
Definition: ERF_SampleData.H:628
amrex::Box cols
the columns of the line on the level (k = the domain's bottom)
Definition: ERF_SampleData.H:631
amrex::Vector< amrex::Real > zt
the height of each sample above sea level
Definition: ERF_SampleData.H:633
amrex::Vector< int > k1
per sample: its column along the line, the cells it reads
Definition: ERF_SampleData.H:634
amrex::Vector< int > k0
Definition: ERF_SampleData.H:634
amrex::Vector< int > col
Definition: ERF_SampleData.H:634
amrex::BoxArray ba
the grids of the level
Definition: ERF_SampleData.H:629
amrex::Vector< amrex::Real > w
the weight of k1
Definition: ERF_SampleData.H:635
amrex::Vector< char > missing
the sample is below the ground or above the top, or no fluid brackets it
Definition: ERF_SampleData.H:636
amrex::Box cells
the cells the samples read (empty if none)
Definition: ERF_SampleData.H:632
bool holds
the level holds every cell the samples read
Definition: ERF_SampleData.H:630
Definition: ERF_SampleData.H:56
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
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
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::Vector< std::string > m_varnames
Definition: ERF_SampleData.H:1710
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::Vector< std::unique_ptr< std::fstream > > m_logstream
Definition: ERF_SampleData.H:1712
amrex::Vector< amrex::Real > interp_heights(int iline) const
Definition: ERF_SampleData.H:579
amrex::Vector< amrex::Real > m_ground
Definition: ERF_SampleData.H:1716
void open_ascii_streams()
Definition: ERF_SampleData.H:448
amrex::Vector< amrex::MultiFab > m_ls_mf
Definition: ERF_SampleData.H:1696
void resolve_latlon(const LatLonMap &latlon_map, const amrex::Geometry &geom0)
Definition: ERF_SampleData.H:483
LineSampler(const amrex::Vector< amrex::IntVect > &cells, const amrex::Vector< std::string > &log_names, const amrex::Box &domain)
Definition: ERF_SampleData.H:327
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
amrex::Vector< amrex::Real > m_latlon_lo
Definition: ERF_SampleData.H:1701
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
amrex::Vector< amrex::Vector< int > > m_box_cache_found
Definition: ERF_SampleData.H:1718
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={})
Definition: ERF_SampleData.H:1082
bool needs_ground() const
Definition: ERF_SampleData.H:549
int m_max_level
Definition: ERF_SampleData.H:1708
LineSampler(const amrex::Vector< amrex::IntVect > &cells, const amrex::Vector< amrex::RealVect > &points, const amrex::Vector< std::string > &log_names, bool z_agl)
Definition: ERF_SampleData.H:366
bool m_interp
Definition: ERF_SampleData.H:1705
void write_sample_data(amrex::Vector< double > &time, amrex::Vector< int > &level_steps, amrex::Vector< amrex::IntVect > &ref_ratio, amrex::Vector< amrex::Geometry > &geom)
Definition: ERF_SampleData.H:1548
amrex::Vector< std::unique_ptr< std::fstream > > m_datastream
Definition: ERF_SampleData.H:1711
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
static amrex::Real column_ground(const amrex::MultiFab &ground_nd, const amrex::Geometry &geom, const amrex::IntVect &cell)
Definition: ERF_SampleData.H:940
bool uses_latlon() const
Whether the lines are given by latitude and longitude (erf.sample_line_lo/hi_latlon)
Definition: ERF_SampleData.H:470
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={})
Definition: ERF_SampleData.H:1177
bool m_use_real_bx
Definition: ERF_SampleData.H:1699
amrex::Vector< amrex::Vector< InterpPlan > > m_interp_plan
Definition: ERF_SampleData.H:1723
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
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
amrex::Vector< amrex::BoxArray > m_zcc_ba
Definition: ERF_SampleData.H:1721
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
amrex::Vector< int > m_dir
Definition: ERF_SampleData.H:1692
bool use_column_heights() const
Definition: ERF_SampleData.H:897
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
bool m_z_agl
Definition: ERF_SampleData.H:1704
amrex::Vector< int > m_npts
Definition: ERF_SampleData.H:1706
int m_ncons
Definition: ERF_SampleData.H:1709
amrex::Vector< amrex::BoxArray > m_box_cache_ba
Definition: ERF_SampleData.H:1719
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
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
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
amrex::Vector< amrex::Real > m_latlon_hi
Definition: ERF_SampleData.H:1701
LineSampler()
Definition: ERF_SampleData.H:57
bool m_write_log
Definition: ERF_SampleData.H:1703
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::Real m_covered_value
Definition: ERF_SampleData.H:1707
amrex::Vector< amrex::Box > m_bnd_bx
Definition: ERF_SampleData.H:1694
bool m_use_latlon
Definition: ERF_SampleData.H:1700
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
amrex::Box getIndexBox(const amrex::RealBox &real_box, const amrex::Geometry &geom)
Definition: ERF_SampleData.H:1066
amrex::Vector< amrex::Vector< amrex::Box > > m_box_cache
Definition: ERF_SampleData.H:1717
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
amrex::Box lineIndexBox(int iline, const amrex::Geometry &geom, const amrex::MultiFab &z_nd, amrex::Real ground)
Definition: ERF_SampleData.H:1016
Definition: ERF_SampleData.H:1728
amrex::Vector< int > m_dir
Definition: ERF_SampleData.H:2245
amrex::Box getIndexBox(const amrex::RealBox &real_box, const amrex::Geometry &geom)
Definition: ERF_SampleData.H:1862
amrex::Real m_covered_value
Definition: ERF_SampleData.H:2251
void write_sample_data(amrex::Vector< double > &time, amrex::Vector< int > &level_steps, amrex::Vector< amrex::IntVect > &ref_ratio, amrex::Vector< amrex::Geometry > &geom)
Definition: ERF_SampleData.H:2174
int m_max_level
Definition: ERF_SampleData.H:2244
amrex::Vector< std::string > m_name
Definition: ERF_SampleData.H:2248
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > m_ps_mf
Definition: ERF_SampleData.H:2247
amrex::Vector< amrex::RealBox > m_bnd_rbx
Definition: ERF_SampleData.H:2246
PlaneSampler()
Definition: ERF_SampleData.H:1729
amrex::Vector< std::string > m_varnames
Definition: ERF_SampleData.H:2250
void get_sample_data(amrex::Vector< amrex::Geometry > &geom, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_new, const amrex::Vector< std::unique_ptr< amrex::MultiFab >> &z_phys_cc, const amrex::Vector< const amrex::MultiFab * > &volfrac_lev={})
Definition: ERF_SampleData.H:1878
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