1 #ifndef ERF_SAMPLEDATA_H
2 #define ERF_SAMPLEDATA_H
6 #include <AMReX_ParmParse.H>
7 #include <AMReX_MultiFab.H>
8 #include <AMReX_MultiFabUtil.H>
9 #include <AMReX_PlotFileUtil.H>
17 amrex::ParmParse
pp(
"erf");
20 int n_line_lo =
pp.countval(
"sample_line_lo") / AMREX_SPACEDIM;
21 int n_line_hi =
pp.countval(
"sample_line_hi") / AMREX_SPACEDIM;
22 int n_line_dir =
pp.countval(
"sample_line_dir");
23 AMREX_ALWAYS_ASSERT( (n_line_lo==n_line_hi ) &&
24 (n_line_lo==n_line_dir) );
29 amrex::Vector<int> idx_lo; idx_lo.resize(n_line_lo*AMREX_SPACEDIM);
30 amrex::Vector<amrex::IntVect> iv_lo; iv_lo.resize(n_line_lo);
31 pp.queryarr(
"sample_line_lo",idx_lo,0,n_line_lo*AMREX_SPACEDIM);
32 for (
int i(0); i < n_line_lo; i++) {
33 amrex::IntVect iv(idx_lo[AMREX_SPACEDIM*i+0],
34 idx_lo[AMREX_SPACEDIM*i+1],
35 idx_lo[AMREX_SPACEDIM*i+2]);
40 amrex::Vector<int> idx_hi; idx_hi.resize(n_line_hi*AMREX_SPACEDIM);
41 amrex::Vector<amrex::IntVect> iv_hi; iv_hi.resize(n_line_hi);
42 pp.queryarr(
"sample_line_hi",idx_hi,0,n_line_hi*AMREX_SPACEDIM);
43 for (
int i(0); i < n_line_hi; i++) {
44 amrex::IntVect iv(idx_hi[AMREX_SPACEDIM*i+0],
45 idx_hi[AMREX_SPACEDIM*i+1],
46 idx_hi[AMREX_SPACEDIM*i+2]);
52 for (
int i = 0; i < n_line_hi; i++){
53 amrex::Box lbx(iv_lo[i],iv_hi[i]);
58 m_dir.resize(n_line_dir);
59 pp.queryarr(
"sample_line_dir",
m_dir,0,n_line_dir);
62 m_lev.resize(n_line_dir,0);
70 get_line_mfs (amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars_new)
72 int nlev = vars_new.size();
77 for (
int iline(0); iline<nline; ++iline) {
78 int dir =
m_dir[iline];
80 amrex::IntVect cell = bnd_bx.smallEnd();
83 for (
int ilev(nlev-1); ilev>=0; --ilev) {
86 amrex::MultiFab mf_cc_vel;
87 auto ba = vars_new[ilev][
Vars::cons].boxArray();
88 auto dm = vars_new[ilev][
Vars::cons].DistributionMap();
89 mf_cc_vel.define(ba, dm, AMREX_SPACEDIM, amrex::IntVect(1,1,1));
90 average_face_to_cellcenter(mf_cc_vel,0,
91 amrex::Array<const amrex::MultiFab*,3>{&vars_new[ilev][
Vars::xvel],
96 amrex::MultiFab mf_cc_data;
97 mf_cc_data.define(ba, dm, ncomp, 1);
99 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
101 for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
102 const amrex::Box& tbx = mfi.tilebox();
103 auto const& dfab = mf_cc_data.array(mfi);
104 auto const& tfab = vars_new[ilev][
Vars::cons].array(mfi);
105 auto const& wfab = mf_cc_vel.array(mfi);
106 amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
108 dfab(i,j,k,0) = tfab(i,j,k,1)/tfab(i,j,k,0);
109 dfab(i,j,k,1) = std::sqrt(wfab(i,j,k,0)*wfab(i,j,k,0)
110 + wfab(i,j,k,1)*wfab(i,j,k,1)
111 + wfab(i,j,k,2)*wfab(i,j,k,2)) ;
117 m_ls_mf[iline] = get_line_data(mf_cc_data, dir, cell, bnd_bx);
120 auto min_bnd_bx =
m_ls_mf[iline].boxArray().minimalBox();
121 if (bnd_bx == min_bnd_bx) {
continue; }
129 amrex::Vector<int>& level_steps,
130 amrex::Vector<amrex::IntVect>& ref_ratio,
131 amrex::Vector<amrex::Geometry>& geom)
133 std::string name_base =
"plt_line_";
134 amrex::Vector<std::string> varnames = {
"T",
"Wsp"};
137 for (
int iline(0); iline<nline; ++iline) {
139 int dir =
m_dir[iline];
140 int lev =
m_lev[iline];
141 amrex::Real m_time = time[lev];
142 amrex::Vector<int> m_level_steps = {level_steps[lev]};
143 amrex::Vector<amrex::IntVect> m_ref_ratio = {ref_ratio[lev]};
146 auto plo = geom[lev].ProbLo();
147 auto dx = geom[lev].CellSize();
148 amrex::Vector<amrex::Geometry> m_geom; m_geom.resize(1);
149 amrex::Vector<int> is_per(AMREX_SPACEDIM,0);
152 for (
int d(0); d<AMREX_SPACEDIM; ++d) {
153 amrex::Real
offset = (d==dir) ? 0 : 0.5;
154 amrex::Real lo = plo[d] + ( m_dom.smallEnd(d) -
offset ) * dx[d];
155 amrex::Real hi = plo[d] + ( m_dom.bigEnd(d) +
offset ) * dx[d];
160 is_per[d] = geom[lev].isPeriodic(d);
162 m_geom[0].define(m_dom, &m_rb, geom[lev].
Coord(), is_per.data());
165 std::string name_line = amrex::Concatenate(name_base, iline , 5);
166 name_line +=
"_step_";
167 std::string plotfilename = amrex::Concatenate(name_line, m_level_steps[0], 5);
170 amrex::Vector<const amrex::MultiFab*> mf = {&(
m_ls_mf[iline])};
173 WriteMultiLevelPlotfile(plotfilename, 1, mf,
174 varnames, m_geom, m_time,
175 m_level_steps, m_ref_ratio);
190 amrex::ParmParse
pp(
"erf");
193 int n_plane_lo =
pp.countval(
"sample_plane_lo") / AMREX_SPACEDIM;
194 int n_plane_hi =
pp.countval(
"sample_plane_hi") / AMREX_SPACEDIM;
195 int n_plane_dir =
pp.countval(
"sample_plane_dir");
196 AMREX_ALWAYS_ASSERT( (n_plane_lo==n_plane_hi ) &&
197 (n_plane_lo==n_plane_dir) );
200 if (n_plane_lo > 0) {
202 amrex::Vector<amrex::Real> r_lo; r_lo.resize(n_plane_lo*AMREX_SPACEDIM);
203 amrex::Vector<amrex::Vector<amrex::Real>> rv_lo;
204 pp.queryarr(
"sample_plane_lo",r_lo,0,n_plane_lo*AMREX_SPACEDIM);
205 for (
int i(0); i < n_plane_lo; i++) {
206 amrex::Vector<amrex::Real> rv = {r_lo[AMREX_SPACEDIM*i+0],
207 r_lo[AMREX_SPACEDIM*i+1],
208 r_lo[AMREX_SPACEDIM*i+2]};
213 amrex::Vector<amrex::Real> r_hi; r_hi.resize(n_plane_hi*AMREX_SPACEDIM);
214 amrex::Vector<amrex::Vector<amrex::Real>> rv_hi;
215 pp.queryarr(
"sample_plane_hi",r_hi,0,n_plane_hi*AMREX_SPACEDIM);
216 for (
int i(0); i < n_plane_hi; i++) {
217 amrex::Vector<amrex::Real> rv = {r_hi[AMREX_SPACEDIM*i+0],
218 r_hi[AMREX_SPACEDIM*i+1],
219 r_hi[AMREX_SPACEDIM*i+2]};
225 for (
int i(0); i < n_plane_hi; i++){
226 amrex::RealBox rbx(rv_lo[i].data(),rv_hi[i].data());
231 m_dir.resize(n_plane_dir);
232 pp.queryarr(
"sample_plane_dir",
m_dir,0,n_plane_dir);
235 m_lev.resize(n_plane_dir,0);
245 const amrex::Geometry& geom) {
246 amrex::IntVect slice_lo, slice_hi;
248 AMREX_D_TERM(slice_lo[0]=
static_cast<int>(std::floor((real_box.lo(0) - geom.ProbLo(0))/geom.CellSize(0)));,
249 slice_lo[1]=
static_cast<int>(std::floor((real_box.lo(1) - geom.ProbLo(1))/geom.CellSize(1)));,
250 slice_lo[2]=
static_cast<int>(std::floor((real_box.lo(2) - geom.ProbLo(2))/geom.CellSize(2))););
252 AMREX_D_TERM(slice_hi[0]=
static_cast<int>(std::floor((real_box.hi(0) - geom.ProbLo(0))/geom.CellSize(0)));,
253 slice_hi[1]=
static_cast<int>(std::floor((real_box.hi(1) - geom.ProbLo(1))/geom.CellSize(1)));,
254 slice_hi[2]=
static_cast<int>(std::floor((real_box.hi(2) - geom.ProbLo(2))/geom.CellSize(2))););
256 return amrex::Box(slice_lo, slice_hi) & geom.Domain();
261 amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars_new)
263 int nlev = vars_new.size();
266 bool interpolate =
true;
269 for (
int iplane(0); iplane<nplane; ++iplane) {
270 int dir =
m_dir[iplane];
271 amrex::RealBox bnd_rbx =
m_bnd_rbx[iplane];
272 amrex::Real point = bnd_rbx.lo(dir);
275 for (
int ilev(nlev-1); ilev>=0; --ilev) {
278 amrex::MultiFab mf_cc_vel;
279 auto ba = vars_new[ilev][
Vars::cons].boxArray();
280 auto dm = vars_new[ilev][
Vars::cons].DistributionMap();
281 mf_cc_vel.define(ba, dm, AMREX_SPACEDIM, amrex::IntVect(1,1,1));
282 average_face_to_cellcenter(mf_cc_vel,0,
283 amrex::Array<const amrex::MultiFab*,3>{&vars_new[ilev][
Vars::xvel],
288 amrex::MultiFab mf_cc_data;
289 mf_cc_data.define(ba, dm, ncomp, 1);
291 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
293 for (amrex::MFIter mfi(mf_cc_data, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) {
294 const amrex::Box& tbx = mfi.tilebox();
295 auto const& dfab = mf_cc_data.array(mfi);
296 auto const& tfab = vars_new[ilev][
Vars::cons].array(mfi);
297 auto const& wfab = mf_cc_vel.array(mfi);
298 amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
300 dfab(i,j,k,0) = tfab(i,j,k,1)/tfab(i,j,k,0);
301 dfab(i,j,k,1) = std::sqrt(wfab(i,j,k,0)*wfab(i,j,k,0)
302 + wfab(i,j,k,1)*wfab(i,j,k,1)
303 + wfab(i,j,k,2)*wfab(i,j,k,2)) ;
308 m_lev[iplane] = ilev;
309 m_ps_mf[iplane] = get_slice_data(dir, point, mf_cc_data, geom[ilev],
310 0, ncomp, interpolate, bnd_rbx);
313 auto min_bnd_bx =
m_ps_mf[iplane]->boxArray().minimalBox();
314 amrex::Box bnd_bx =
getIndexBox(bnd_rbx, geom[ilev]);
315 if (bnd_bx == min_bnd_bx) {
continue; }
323 amrex::Vector<int>& level_steps,
324 amrex::Vector<amrex::IntVect>& ref_ratio,
325 amrex::Vector<amrex::Geometry>& geom)
327 std::string name_base =
"plt_plane_";
328 amrex::Vector<std::string> varnames = {
"T",
"Wsp"};
331 for (
int iplane(0); iplane<nplane; ++iplane) {
333 int dir =
m_dir[iplane];
334 int lev =
m_lev[iplane];
335 amrex::Real m_time = time[lev];
336 amrex::Vector<int> m_level_steps = {level_steps[lev]};
337 amrex::Vector<amrex::IntVect> m_ref_ratio = {ref_ratio[lev]};
342 amrex::Real point = m_rb.hi(dir);
343 amrex::Vector<int> is_per(AMREX_SPACEDIM,0);
344 for (
int d(0); d<AMREX_SPACEDIM; ++d) {
346 m_rb.setLo(d,point-0.5*geom[lev].CellSize(d));
347 m_rb.setHi(d,point+0.5*geom[lev].CellSize(d));
349 is_per[d] = geom[lev].isPeriodic(d);
351 amrex::Vector<amrex::Geometry> m_geom; m_geom.resize(1);
352 m_geom[0].define(m_dom, &m_rb, geom[lev].
Coord(), is_per.data());
355 std::string name_plane = amrex::Concatenate(name_base, iplane , 5);
356 name_plane +=
"_step_";
357 std::string plotfilename = amrex::Concatenate(name_plane, m_level_steps[0], 5);
360 amrex::Vector<const amrex::MultiFab*> mf = {
m_ps_mf[iplane].get()};
363 WriteMultiLevelPlotfile(plotfilename, 1, mf,
364 varnames, m_geom, m_time,
365 m_level_steps, m_ref_ratio);
372 amrex::Vector<std::unique_ptr<amrex::MultiFab>>
m_ps_mf;
382 if(do_line)
m_ls = std::make_unique<LineSampler >();
383 if(do_plane)
m_ps = std::make_unique<PlaneSampler>();
388 amrex::Vector<amrex::Vector<amrex::MultiFab>>& vars_new)
390 if (
m_ls)
m_ls->get_line_mfs(vars_new);
391 if (
m_ps)
m_ps->get_plane_mfs(geom, vars_new);
396 amrex::Vector<int>& level_steps,
397 amrex::Vector<amrex::IntVect>& ref_ratio,
398 amrex::Vector<amrex::Geometry>& geom)
400 if (
m_ls)
m_ls->write_line_mfs(time, level_steps, ref_ratio, geom);
401 if (
m_ls)
m_ps->write_plane_mfs(time, level_steps, ref_ratio, geom);
407 std::unique_ptr<LineSampler>
m_ls =
nullptr;
410 std::unique_ptr<PlaneSampler>
m_ps =
nullptr;
Coord
Definition: ERF_DataStruct.H:64
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:219
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:28
Definition: ERF_SampleData.H:377
std::unique_ptr< LineSampler > m_ls
Definition: ERF_SampleData.H:407
void get_sample_data(amrex::Vector< amrex::Geometry > &geom, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_new)
Definition: ERF_SampleData.H:387
SampleData(bool do_line=false, bool do_plane=false)
Definition: ERF_SampleData.H:379
std::unique_ptr< PlaneSampler > m_ps
Definition: ERF_SampleData.H:410
void write_sample_data(amrex::Vector< amrex::Real > &time, amrex::Vector< int > &level_steps, amrex::Vector< amrex::IntVect > &ref_ratio, amrex::Vector< amrex::Geometry > &geom)
Definition: ERF_SampleData.H:395
@ xvel
Definition: ERF_IndexDefines.H:130
@ cons
Definition: ERF_IndexDefines.H:129
@ zvel
Definition: ERF_IndexDefines.H:132
@ yvel
Definition: ERF_IndexDefines.H:131
Definition: ERF_SampleData.H:14
amrex::Vector< amrex::MultiFab > m_ls_mf
Definition: ERF_SampleData.H:182
void get_line_mfs(amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_new)
Definition: ERF_SampleData.H:70
amrex::Vector< int > m_dir
Definition: ERF_SampleData.H:179
LineSampler()
Definition: ERF_SampleData.H:15
amrex::Vector< amrex::Box > m_bnd_bx
Definition: ERF_SampleData.H:181
void write_line_mfs(amrex::Vector< amrex::Real > &time, amrex::Vector< int > &level_steps, amrex::Vector< amrex::IntVect > &ref_ratio, amrex::Vector< amrex::Geometry > &geom)
Definition: ERF_SampleData.H:128
amrex::Vector< int > m_lev
Definition: ERF_SampleData.H:180
Definition: ERF_SampleData.H:187
amrex::Vector< int > m_dir
Definition: ERF_SampleData.H:369
amrex::Box getIndexBox(const amrex::RealBox &real_box, const amrex::Geometry &geom)
Definition: ERF_SampleData.H:244
amrex::Vector< int > m_lev
Definition: ERF_SampleData.H:370
void get_plane_mfs(amrex::Vector< amrex::Geometry > &geom, amrex::Vector< amrex::Vector< amrex::MultiFab >> &vars_new)
Definition: ERF_SampleData.H:260
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_ps_mf
Definition: ERF_SampleData.H:372
amrex::Vector< amrex::RealBox > m_bnd_rbx
Definition: ERF_SampleData.H:371
PlaneSampler()
Definition: ERF_SampleData.H:188
void write_plane_mfs(amrex::Vector< amrex::Real > &time, amrex::Vector< int > &level_steps, amrex::Vector< amrex::IntVect > &ref_ratio, amrex::Vector< amrex::Geometry > &geom)
Definition: ERF_SampleData.H:322