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

#include <ERF_SampleData.H>

Collaboration diagram for PlaneSampler:

Public Member Functions

 PlaneSampler ()
 
amrex::Box getIndexBox (const amrex::RealBox &real_box, const amrex::Geometry &geom)
 
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={})
 
void write_sample_data (amrex::Vector< double > &time, amrex::Vector< int > &level_steps, amrex::Vector< amrex::IntVect > &ref_ratio, amrex::Vector< amrex::Geometry > &geom)
 

Public Attributes

int m_max_level = -1
 
amrex::Vector< int > m_dir
 
amrex::Vector< amrex::RealBox > m_bnd_rbx
 
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > m_ps_mf
 
amrex::Vector< std::string > m_name
 
amrex::Vector< std::string > m_varnames {"magvel","theta"}
 
amrex::Real m_covered_value {sampling_covered_value()}
 

Constructor & Destructor Documentation

◆ PlaneSampler()

PlaneSampler::PlaneSampler ( )
inline
1730  {
1731  amrex::ParmParse pp("erf");
1732 
1733  // Count number of lo and hi points define the plane
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");
1737  AMREX_ALWAYS_ASSERT( (n_plane_lo==n_plane_hi ) &&
1738  (n_plane_lo==n_plane_dir) );
1739 
1740  // Parse the data
1741  if (n_plane_lo > 0) {
1742  // Parse lo
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);
1751  }
1752 
1753  // Parse hi
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);
1762  }
1763 
1764  // Construct vector of bounding real boxes
1765  m_bnd_rbx.resize(n_plane_lo);
1766  for (int i(0); i < n_plane_hi; i++){
1767  amrex::RealBox rbx(rv_lo[i].data(),rv_hi[i].data());
1768  m_bnd_rbx[i] = rbx;
1769  }
1770 
1771  // Parse directionality
1772  m_dir.resize(n_plane_dir);
1773  pp.queryarr("sample_plane_dir",m_dir,0,n_plane_dir);
1774 
1775  // Parse names
1776  std::string name_base = "plt_plane_";
1777  m_name.resize(n_plane_lo);
1778  int n_names = pp.countval("sample_plane_name");
1779  if (n_names > 0) {
1780  AMREX_ALWAYS_ASSERT( n_names==n_plane_lo );
1781  pp.queryarr("sample_plane_name",m_name,0,n_names);
1782  } else {
1783  for (int iplane(0); iplane<n_plane_lo; ++iplane) {
1784  m_name[iplane] = amrex::Concatenate(name_base, iplane , 5);
1785  }
1786  }
1787 
1788  // Optional cap on the finest level written (-1 => all intersecting levels)
1789  pp.queryAdd("plane_sampling_max_level", m_max_level);
1790 
1791  // Allocate per-plane vectors of per-level MF pointers
1792  m_ps_mf.resize(n_plane_lo);
1793 
1794  // Get requested vars
1795  if (pp.countval("plane_sampling_vars") > 0) {
1796  m_varnames.clear();
1797  amrex::Vector<std::string> requested_vars;
1798  pp.queryarr("plane_sampling_vars",requested_vars);
1799  amrex::Print() << "Selected plane sampling vars :";
1800  if (containerHasElement(requested_vars, "density")) {
1801  m_varnames.push_back("density");
1802  amrex::Print() << " " << "density";
1803  }
1804  if (containerHasElement(requested_vars, "x_velocity")) {
1805  m_varnames.push_back("x_velocity");
1806  amrex::Print() << " " << "x_velocity";
1807  }
1808  if (containerHasElement(requested_vars, "y_velocity")) {
1809  m_varnames.push_back("y_velocity");
1810  amrex::Print() << " " << "y_velocity";
1811  }
1812  if (containerHasElement(requested_vars, "z_velocity")) {
1813  m_varnames.push_back("z_velocity");
1814  amrex::Print() << " " << "z_velocity";
1815  }
1816  if (containerHasElement(requested_vars, "magvel")) {
1817  m_varnames.push_back("magvel");
1818  amrex::Print() << " " << "magvel";
1819  }
1820  if (containerHasElement(requested_vars, "theta")) {
1821  m_varnames.push_back("theta");
1822  amrex::Print() << " " << "theta";
1823  }
1824  if (containerHasElement(requested_vars, "qv")) {
1825  m_varnames.push_back("qv");
1826  amrex::Print() << " " << "qv";
1827  }
1828  if (containerHasElement(requested_vars, "qc")) {
1829  m_varnames.push_back("qc");
1830  amrex::Print() << " " << "qc";
1831  }
1832  if (containerHasElement(requested_vars, "pressure")) {
1833  m_varnames.push_back("pressure");
1834  amrex::Print() << " " << "pressure";
1835  }
1836  // "z", as for line sampling, is the same variable
1837  if (containerHasElement(requested_vars, "z_phys") ||
1838  containerHasElement(requested_vars, "z")) {
1839  m_varnames.push_back("z_phys");
1840  amrex::Print() << " " << "z_phys";
1841  }
1842  if (containerHasElement(requested_vars, "volfrac")) {
1843  m_varnames.push_back("volfrac");
1844  amrex::Print() << " " << "volfrac";
1845  }
1846  amrex::Print() << std::endl;
1847  }
1848 
1849  // The plane is placed, and its plotfile written, in the computational coordinates,
1850  // which are not the physical height on a stretched or terrain-fitted mesh, so there
1851  // the height is always written (before volfrac, as when it is requested)
1852  if (SolverChoice::mesh_type != MeshType::ConstantDz &&
1853  !containerHasElement(m_varnames, "z_phys")) {
1854  auto it = std::find(m_varnames.begin(), m_varnames.end(), "volfrac");
1855  m_varnames.insert(it, "z_phys");
1856  }
1857  }
1858  }
bool containerHasElement(const V &iterable, const T &query)
Definition: ERF_Container.H:5
ParmParse pp("prob")
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
amrex::Vector< int > m_dir
Definition: ERF_SampleData.H:2245
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
amrex::Vector< std::string > m_varnames
Definition: ERF_SampleData.H:2250
static MeshType mesh_type
Vertical mesh representation.
Definition: ERF_DataStruct.H:3004
Here is the call graph for this function:

Member Function Documentation

◆ get_sample_data()

void PlaneSampler::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 = {} 
)
inline
1881  {})
1882  {
1883  int nlev = sampling_num_levels(vars_new);
1884  int nplane = static_cast<int>(m_bnd_rbx.size());
1885  int ncomp = static_cast<int>(m_varnames.size());
1886  bool interpolate = true;
1887 
1888  int qv_comp = -1;
1889 
1890  // Loop over each plane
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);
1895 
1896  // Collect every level 0..lev_cap whose grids intersect the plane.
1897  int lev_cap = (m_max_level >= 0 && m_max_level < nlev-1) ? m_max_level : nlev-1;
1898  m_ps_mf[iplane].clear();
1899 
1900  for (int ilev(0); ilev<=lev_cap; ++ilev) {
1901 
1902  // Stop ascending once a level's grids no longer touch the flattened plane
1903  {
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; }
1909  }
1910 
1911  // Construct CC velocities
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],
1918  &vars_new[ilev][Vars::yvel],
1919  &vars_new[ilev][Vars::zvel]});
1920 
1921  // Construct MultiFab holding requested variables, and after them whether
1922  // each cell is covered by immersed terrain
1923  amrex::MultiFab mf_cc_data;
1924  mf_cc_data.define(ba, dm, ncomp+1, 1);
1925 
1926  int mf_comp = 0;
1927 
1928  if (containerHasElement(m_varnames, "density")) {
1929  amrex::MultiFab::Copy(mf_cc_data, vars_new[ilev][Vars::cons], Rho_comp, mf_comp, 1, 0);
1930  mf_comp += 1;
1931  }
1932 
1933  if (containerHasElement(m_varnames, "x_velocity")) {
1934  amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 0, mf_comp, 1, 0);
1935  mf_comp += 1;
1936  }
1937  if (containerHasElement(m_varnames, "y_velocity")) {
1938  amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 1, mf_comp, 1, 0);
1939  mf_comp += 1;
1940  }
1941  if (containerHasElement(m_varnames, "z_velocity")) {
1942  amrex::MultiFab::Copy(mf_cc_data, mf_cc_vel, 2, mf_comp, 1, 0);
1943  mf_comp += 1;
1944  }
1945 
1946  if (containerHasElement(m_varnames, "magvel")) {
1947 #ifdef _OPENMP
1948 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1949 #endif
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);
1954 
1955  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1956  {
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));
1960  });
1961  }
1962  mf_comp += 1;
1963  }
1964 
1965  if (containerHasElement(m_varnames, "theta")) {
1966 #ifdef _OPENMP
1967 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1968 #endif
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);
1973 
1974  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1975  {
1976  dfab(i,j,k,mf_comp) = cfab(i,j,k,RhoTheta_comp) / cfab(i,j,k,Rho_comp);
1977  });
1978  }
1979  mf_comp += 1;
1980  }
1981 
1982  if (containerHasElement(m_varnames, "qv")) {
1983  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(vars_new[ilev][Vars::cons].nComp() > RhoQ1_comp,
1984  "qv sampling requested but moisture components not present in state");
1985  if (qv_comp >= 0) AMREX_ALWAYS_ASSERT(qv_comp == mf_comp);
1986  qv_comp = mf_comp;
1987 #ifdef _OPENMP
1988 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1989 #endif
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);
1994 
1995  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1996  {
1997  dfab(i,j,k,mf_comp) = cfab(i,j,k,RhoQ1_comp) / cfab(i,j,k,Rho_comp);
1998  });
1999  }
2000  mf_comp += 1;
2001  }
2002  if (containerHasElement(m_varnames, "qc")) {
2003  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(vars_new[ilev][Vars::cons].nComp() > RhoQ2_comp,
2004  "qc sampling requested but moisture components not present in state");
2005 #ifdef _OPENMP
2006 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2007 #endif
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);
2012 
2013  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
2014  {
2015  dfab(i,j,k,mf_comp) = cfab(i,j,k,RhoQ2_comp) / cfab(i,j,k,Rho_comp);
2016  });
2017  }
2018  mf_comp += 1;
2019  }
2020 
2021  if (containerHasElement(m_varnames, "pressure")) {
2022  if (vars_new[ilev][Vars::cons].nComp() > RhoQ1_comp) {
2023  // moist pressure: use qv from dfab if already sampled, else compute inline
2024 #ifdef _OPENMP
2025 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2026 #endif
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);
2031 
2032  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
2033  {
2034  amrex::Real qv_val = (qv_comp >= 0) ? dfab(i,j,k,qv_comp)
2035  : cfab(i,j,k,RhoQ1_comp) / cfab(i,j,k,Rho_comp);
2036  dfab(i,j,k,mf_comp) = getPgivenRTh(cfab(i,j,k,RhoTheta_comp), qv_val);
2037  });
2038  }
2039  } else {
2040  // dry pressure
2041 #ifdef _OPENMP
2042 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2043 #endif
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);
2048 
2049  amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
2050  {
2051  dfab(i,j,k,mf_comp) = getPgivenRTh(cfab(i,j,k,RhoTheta_comp));
2052  });
2053  }
2054  }
2055  mf_comp += 1;
2056  }
2057 
2058  // The physical height of each cell center
2059  int z_comp = -1;
2060  if (containerHasElement(m_varnames, "z_phys")) {
2061  amrex::MultiFab::Copy(mf_cc_data, *z_phys_cc[ilev], 0, mf_comp, 1, 0);
2062  z_comp = mf_comp;
2063  mf_comp += 1;
2064  }
2065 
2066  // The volume fraction, 1 without immersed terrain, and 1 where a cell is
2067  // covered (0 elsewhere)
2068  const amrex::MultiFab* volfrac = ilev < static_cast<int>(volfrac_lev.size())
2069  ? volfrac_lev[ilev] : nullptr;
2070  int vf_comp = -1;
2071  if (containerHasElement(m_varnames, "volfrac")) {
2072  if (volfrac != nullptr) {
2073  amrex::MultiFab::Copy(mf_cc_data, *volfrac, 0, mf_comp, 1, 1);
2074  } else {
2075  mf_cc_data.setVal(1.0, mf_comp, 1, 1);
2076  }
2077  vf_comp = mf_comp;
2078  mf_comp += 1;
2079  }
2080  if (volfrac != nullptr) {
2081  const int cov_comp = ncomp;
2082 #ifdef _OPENMP
2083 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2084 #endif
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);
2089  amrex::ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
2090  out(i,j,k,cov_comp) = (vf(i,j,k) == amrex::Real(0.0)) ? amrex::Real(1.0)
2091  : amrex::Real(0.0);
2092  });
2093  }
2094  } else {
2095  mf_cc_data.setVal(0.0, ncomp, 1, 1);
2096  }
2097 
2098  // The interpolation reads the cell on the other side of the plane, which may be
2099  // a ghost cell. It is taken from the neighboring grid, or periodic image, where
2100  // there is one; at the domain boundary or the edge of the level it is the cell
2101  // itself, so the plane there takes the value of the cell it lies in
2102  {
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);
2109  amrex::ParallelFor(amrex::grow(vbx, fdir, 1), ncomp+1,
2110  [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept
2111  {
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);
2116  }
2117  });
2118  }
2119  mf_cc_data.FillBoundary(geom[ilev].periodicity());
2120  }
2121 
2122  auto slice = get_slice_data(dir, point, mf_cc_data, geom[ilev],
2123  0, ncomp+1, interpolate, bnd_rbx);
2124 
2125  // Defensive: an empty return means nothing was actually sampled.
2126  if (!slice || slice->boxArray().size() == 0) { break; }
2127 
2128  // Broadcast the single sampled plane across 2^ilev cells in dir so
2129  // every level shares an isotropic refinement ratio. The dir extent
2130  // becomes [0, 2^ilev-1]; each cell holds the interpolated plane value
2131  // replicated across the shared level-0 slab thickness.
2132  const int rr_l = 1 << ilev;
2133  const int k_slice = slice->boxArray().minimalBox().smallEnd(dir);
2134  const int l_dir = dir;
2135  const amrex::Real covered_value = m_covered_value;
2136 
2137  amrex::BoxList bl;
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];
2141  b.setSmall(dir, 0);
2142  b.setBig(dir, rr_l - 1);
2143  bl.push_back(b);
2144  }
2145  amrex::BoxArray out_ba(std::move(bl));
2146  auto out_mf = std::make_unique<amrex::MultiFab>(out_ba, slice->DistributionMap(),
2147  ncomp, 0);
2148 
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
2154  {
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; }
2159  // A sample interpolated from a covered cell is written as
2160  // erf.sampling_covered_value, except for the height and volume fraction
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);
2164  });
2165  }
2166 
2167  m_ps_mf[iplane].push_back(std::move(out_mf));
2168 
2169  } // ilev
2170  }// iplane
2171  }
std::vector< int > point
Definition: ERF_ActuatorSpreading.cpp:221
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
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
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);})
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
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

◆ getIndexBox()

amrex::Box PlaneSampler::getIndexBox ( const amrex::RealBox &  real_box,
const amrex::Geometry &  geom 
)
inline
1863  {
1864  amrex::IntVect slice_lo, slice_hi;
1865 
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))););
1869 
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))););
1873 
1874  return amrex::Box(slice_lo, slice_hi) & geom.Domain();
1875  }

Referenced by write_sample_data().

Here is the caller graph for this function:

◆ write_sample_data()

void PlaneSampler::write_sample_data ( amrex::Vector< double > &  time,
amrex::Vector< int > &  level_steps,
amrex::Vector< amrex::IntVect > &  ref_ratio,
amrex::Vector< amrex::Geometry > &  geom 
)
inline
2178  {
2179  amrex::ignore_unused(ref_ratio);
2180  int nplane = m_ps_mf.size();
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; }
2184 
2185  int dir = m_dir[iplane];
2186  amrex::RealBox bnd_rbx = m_bnd_rbx[iplane];
2187  amrex::Real point = bnd_rbx.lo(dir);
2188 
2189  // One shared physical RealBox for every level: full in-plane extent of the
2190  // requested plane, and a dir-slab of level-0 thickness centered on the plane.
2191  // Level 0 supplies prob_lo/hi to the writer, so this object must be shared.
2192  amrex::Real dx0 = geom[0].CellSize(dir);
2193  amrex::RealBox shared_rbx = bnd_rbx;
2194  shared_rbx.setLo(dir, point - myhalf*dx0);
2195  shared_rbx.setHi(dir, point + myhalf*dx0);
2196 
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); }
2199 
2200  // Build the index chain by refining the level-0 plane box so that
2201  // Domain_l == refine(Domain_{l-1},2) holds exactly in every axis.
2202  amrex::Box B0 = getIndexBox(bnd_rbx, geom[0]);
2203 
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));
2208 
2209  for (int l(0); l<nlev_c; ++l) {
2210  const int rr_l = 1 << l;
2211 
2212  // The nested plane plotfile stores a single scalar refinement
2213  // ratio per level, so multi-level output requires factor-2
2214  // isotropic refinement.
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)");
2220  }
2221 
2222  amrex::Box domain_l = amrex::refine(B0, rr_l);
2223  domain_l.setSmall(dir, 0);
2224  domain_l.setBig(dir, rr_l - 1);
2225 
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()));
2230  }
2231 
2232  // Create plotfile name
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);
2236 
2237  // Write the nested multi-level plane plotfile
2238  WriteMultiLevelPlotfile(plotfilename, nlev_c, mf,
2239  m_varnames, m_geom, static_cast<amrex::Real>(time[0]),
2240  m_level_steps, m_ref_ratio);
2241  } // iplane
2242  }
Coord
Coordinate-axis selector.
Definition: ERF_DataStruct.H:226
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
Here is the call graph for this function:

Member Data Documentation

◆ m_bnd_rbx

amrex::Vector<amrex::RealBox> PlaneSampler::m_bnd_rbx

Referenced by PlaneSampler(), and write_sample_data().

◆ m_covered_value

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

◆ m_dir

amrex::Vector<int> PlaneSampler::m_dir

Referenced by PlaneSampler(), and write_sample_data().

◆ m_max_level

int PlaneSampler::m_max_level = -1

Referenced by PlaneSampler().

◆ m_name

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

Referenced by PlaneSampler(), and write_sample_data().

◆ m_ps_mf

amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab> > > PlaneSampler::m_ps_mf

Referenced by PlaneSampler(), and write_sample_data().

◆ m_varnames

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

Referenced by PlaneSampler(), and write_sample_data().


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