18#ifndef REMORA_USE_NETCDF
19 amrex::ignore_unused(istep_for_plot);
21 Vector<std::string> varnames_3d;
24 Vector<std::string> varnames_2d;
27 Vector<std::string> varnames_2d_rho;
28 Vector<std::string> varnames_2d_u;
29 Vector<std::string> varnames_2d_v;
31 const int ncomp_mf_3d = varnames_3d.size();
32 const auto ngrow_vars = IntVect(
NGROW-1,
NGROW-1,0);
35 int ncomp_mf_2d_rho = 0;
36 int ncomp_mf_2d_u = 0;
37 int ncomp_mf_2d_v = 0;
40 for (
auto plot_name : varnames_2d) {
42 if (plot_name ==
"zeta" ) {varnames_2d_rho.push_back(plot_name); ncomp_mf_2d_rho++;}
43 if (plot_name ==
"h" ) {varnames_2d_rho.push_back(plot_name); ncomp_mf_2d_rho++;}
44 if (plot_name ==
"f" ) {varnames_2d_rho.push_back(plot_name); ncomp_mf_2d_rho++;}
45 if (plot_name ==
"visc2") {varnames_2d_rho.push_back(plot_name); ncomp_mf_2d_rho++;}
46 for (
int n = 0; n <
ncons; ++n) {
47 const std::string diff2_name = std::string(
"diff2_") +
cons_names[n];
48 if (plot_name == diff2_name) {
49 varnames_2d_rho.push_back(plot_name);
53 for (
int n = 0; n <
ncons; ++n) {
54 const std::string stflux_name = std::string(
"stflux_") +
cons_names[n];
55 if (plot_name == stflux_name) {
56 varnames_2d_rho.push_back(plot_name);
60 if (plot_name ==
"lrflux") {varnames_2d_rho.push_back(plot_name); ncomp_mf_2d_rho++;}
61 if (plot_name ==
"lhflux") {varnames_2d_rho.push_back(plot_name); ncomp_mf_2d_rho++;}
62 if (plot_name ==
"srflux") {varnames_2d_rho.push_back(plot_name); ncomp_mf_2d_rho++;}
63 if (plot_name ==
"shflux") {varnames_2d_rho.push_back(plot_name); ncomp_mf_2d_rho++;}
64 if (plot_name ==
"ubar" ) {varnames_2d_u.push_back(plot_name); ncomp_mf_2d_u++;}
65 if (plot_name ==
"sustr") {varnames_2d_u.push_back(plot_name); ncomp_mf_2d_u++;}
66 if (plot_name ==
"bustr") {varnames_2d_u.push_back(plot_name); ncomp_mf_2d_u++;}
67 if (plot_name ==
"vbar" ) {varnames_2d_v.push_back(plot_name); ncomp_mf_2d_v++;}
68 if (plot_name ==
"svstr") {varnames_2d_v.push_back(plot_name); ncomp_mf_2d_v++;}
69 if (plot_name ==
"bvstr") {varnames_2d_v.push_back(plot_name); ncomp_mf_2d_v++;}
75 for (
int lev = 0; lev <= finest_level; ++lev) {
84 for (
int lev = 0; lev <= finest_level; ++lev) {
89 Vector<MultiFab> plotMF(finest_level+1);
90 for (
int lev = 0; lev <= finest_level; ++lev) {
91 plotMF[lev].define(grids[lev], dmap[lev], ncomp_mf_3d, ngrow_vars);
92 plotMF[lev].setVal(1.234e20);
96 Vector<MultiFab> mf_2d_rho(finest_level+1);
97 Vector<MultiFab> mf_2d_u(finest_level+1);
98 Vector<MultiFab> mf_2d_v(finest_level+1);
99 for (
int lev = 0; lev <= finest_level; ++lev) {
100 BoxArray ba(grids[lev]);
101 BoxList bl2d = ba.boxList();
102 for (
auto& b : bl2d) {
105 BoxArray ba2d(std::move(bl2d));
106 mf_2d_rho[lev].define(ba2d, dmap[lev], ncomp_mf_2d_rho, IntVect(0,0,0));
107 mf_2d_u[lev].define(ba2d, dmap[lev], ncomp_mf_2d_u , IntVect(0,0,0));
108 mf_2d_v[lev].define(ba2d, dmap[lev], ncomp_mf_2d_v , IntVect(0,0,0));
113 Vector<MultiFab> mf_nd(finest_level+1);
115 for (
int lev = 0; lev <= finest_level; ++lev) {
116 BoxArray nodal_grids(grids[lev]); nodal_grids.surroundingNodes();
117 mf_nd[lev].define(nodal_grids, dmap[lev], AMREX_SPACEDIM, 0);
118 mf_nd[lev].setVal(0.);
123 Vector<MultiFab> mf_u(finest_level+1);
124 Vector<MultiFab> mf_v(finest_level+1);
125 Vector<MultiFab> mf_w(finest_level+1);
127 for (
int lev = 0; lev <= finest_level; ++lev) {
128 BoxArray grid_stag_u(grids[lev]); grid_stag_u.surroundingNodes(0);
129 BoxArray grid_stag_v(grids[lev]); grid_stag_v.surroundingNodes(1);
130 BoxArray grid_stag_w(grids[lev]); grid_stag_w.surroundingNodes(2);
131 mf_u[lev].define(grid_stag_u, dmap[lev], 1, 0);
132 mf_v[lev].define(grid_stag_v, dmap[lev], 1, 0);
133 mf_w[lev].define(grid_stag_w, dmap[lev], 1, 0);
134 MultiFab::Copy(mf_u[lev],*
xvel_new[lev],0,0,1,0);
135 MultiFab::Copy(mf_v[lev],*
yvel_new[lev],0,0,1,0);
136 MultiFab::Copy(mf_w[lev],*
zvel_new[lev],0,0,1,0);
141 Vector<MultiFab> mf_cc_vel(finest_level+1);
148 for (
int lev = 0; lev <= finest_level; ++lev) {
149 mf_cc_vel[lev].define(grids[lev], dmap[lev], AMREX_SPACEDIM, IntVect(1,1,0));
150 mf_cc_vel[lev].setVal(0.0_rt);
151 average_face_to_cellcenter(mf_cc_vel[lev],0,
153 mf_cc_vel[lev].FillBoundary(geom[lev].periodicity());
157 amrex::Interpolater* mapper = &cell_cons_interp;
159 for (
int lev = 1; lev <= finest_level; ++lev) {
160 Vector<MultiFab*> fmf = {&(mf_cc_vel[lev]), &(mf_cc_vel[lev])};
161 Vector<Real> ftime = {
t_new[lev],
t_new[lev]};
162 Vector<MultiFab*> cmf = {&mf_cc_vel[lev-1], &mf_cc_vel[lev-1]};
163 Vector<Real> ctime = {
t_new[lev],
t_new[lev]};
166 amrex::FillPatchTwoLevels(mf_cc_vel[lev], mf_cc_vel[lev].nGrowVect(), IntVect(0,0,0),
167 t_new[lev], cmf, ctime, fmf, ftime,
168 0, 0, mf_cc_vel[lev].nComp(), geom[lev-1], geom[lev],
175 for (
auto plot_name : varnames_2d_rho)
177 if (plot_name ==
"zeta" ) {
178 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_rho[lev],*
vec_Zt_avg1[lev],0,icomp_rho,1,0); }
181 if (plot_name ==
"h" ) {
182 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_rho[lev],*
vec_h[lev],0,icomp_rho,1,0); }
185 if (plot_name ==
"f" ) {
186 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_rho[lev],*
vec_fcor[lev],0,icomp_rho,1,0); }
189 if (plot_name ==
"visc2" ) {
190 for (
int lev = 0; lev <= finest_level; ++lev) {
192 amrex::Abort(
"Found while writing output: visc2 contains nan or inf");
194 for (MFIter mfi(mf_2d_rho[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
195 const Box& bx = mfi.validbox();
196 const int K = mfi.index();
197 auto dst = mf_2d_rho[lev].array(mfi, icomp_rho);
199 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (
int i,
int j,
int)
noexcept {
200 dst(i,j,0) = src(i,j,0);
206 for (
int n = 0; n <
ncons; ++n) {
207 const std::string diff2_name = std::string(
"diff2_") +
cons_names[n];
208 if (plot_name == diff2_name) {
209 for (
int lev = 0; lev <= finest_level; ++lev) {
210 for (MFIter mfi(mf_2d_rho[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
211 const Box& bx = mfi.validbox();
212 const int K = mfi.index();
213 auto dst = mf_2d_rho[lev].array(mfi, icomp_rho);
214 auto src =
vec_diff2[lev]->const_array(K);
215 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (
int i,
int j,
int)
noexcept {
216 dst(i,j,0) = src(i,j,0,n);
223 for (
int n = 0; n <
ncons; ++n) {
224 const std::string stflux_name = std::string(
"stflux_") +
cons_names[n];
225 if (plot_name == stflux_name) {
226 for (
int lev = 0; lev <= finest_level; ++lev) {
227 MultiFab::Copy(mf_2d_rho[lev],*
vec_stflux[lev],n,icomp_rho,1,0);
232 if (plot_name ==
"lrflux" ) {
234 amrex::Abort(
"Attempting to write longwave radiation flux to plotfile. Variable not allocated when bulk_fluxes turned off");
236 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_rho[lev],*
vec_lrflx[lev],0,icomp_rho,1,0); }
239 if (plot_name ==
"lhflux" ) {
241 amrex::Abort(
"Attempting to write latent heat flux to plotfile. Variable not allocated when bulk_fluxes turned off");
243 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_rho[lev],*
vec_lhflx[lev],0,icomp_rho,1,0); }
246 if (plot_name ==
"srflux" ) {
248 amrex::Abort(
"Attempting to write shortwave radiation flux to plotfile. Variable not allocated when bulk_fluxes turned off");
250 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_rho[lev],*
vec_srflx[lev],0,icomp_rho,1,0); }
253 if (plot_name ==
"shflux" ) {
255 amrex::Abort(
"Attempting to write sensible heat flux to plotfile. Variable not allocated when bulk_fluxes turned off");
257 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_rho[lev],*
vec_shflx[lev],0,icomp_rho,1,0); }
263 for (
auto plot_name : varnames_2d_u)
265 if (plot_name ==
"ubar" ) {
266 for (
int lev = 0; lev <= finest_level; ++lev) {
267 MultiFab::Copy(mf_2d_u[lev],*
vec_DU_avg1[lev],0,icomp_u,1,0);
271 if (plot_name ==
"sustr" ) {
272 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_u[lev],*
vec_sustr[lev],0,icomp_u,1,0); }
275 if (plot_name ==
"bustr" ) {
276 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_u[lev],*
vec_bustr[lev],0,icomp_u,1,0); }
282 for (
auto plot_name : varnames_2d_v)
284 if (plot_name ==
"vbar" ) {
285 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_v[lev],*
vec_DV_avg1[lev],0,icomp_v,1,0); }
288 if (plot_name ==
"svstr" ) {
289 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_v[lev],*
vec_svstr[lev],0,icomp_v,1,0); }
292 if (plot_name ==
"bvstr" ) {
293 for (
int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(mf_2d_v[lev],*
vec_bvstr[lev],0,icomp_v,1,0); }
298 for (
int lev = 0; lev <= finest_level; ++lev)
304 for (
int i = 0; i <
ncons; ++i) {
307 amrex::Abort(
"Found while writing output: Cons (salt, temp, or tracer, etc) contains nan or inf");
309 MultiFab::Copy(plotMF[lev],*
cons_new[lev],i,mf_comp,1,ngrow_vars);
316 if (mf_cc_vel[lev].contains_nan(0,1) || mf_cc_vel[lev].contains_inf(0,1)) {
317 amrex::Abort(
"Found while writing output: u velocity contains nan or inf");
319 MultiFab::Copy(plotMF[lev], mf_cc_vel[lev], 0, mf_comp, 1, 0);
323 if (mf_cc_vel[lev].contains_nan(1,1) || mf_cc_vel[lev].contains_inf(1,1)) {
324 amrex::Abort(
"Found while writing output: v velocity contains nan or inf");
326 MultiFab::Copy(plotMF[lev], mf_cc_vel[lev], 1, mf_comp, 1, 0);
330 if (mf_cc_vel[lev].contains_nan(2,1) || mf_cc_vel[lev].contains_inf(2,1)) {
331 amrex::Abort(
"Found while writing output: z velocity contains nan or inf");
333 MultiFab::Copy(plotMF[lev], mf_cc_vel[lev], 2, mf_comp, 1, 0);
338 auto calculate_derived = [&](
const std::string& der_name,
342 MultiFab dmf(plotMF[lev], make_alias, mf_comp, 1);
344#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
346 for (MFIter mfi(dmf, TilingIfNotGPU()); mfi.isValid(); ++mfi)
348 const Box& bx = mfi.tilebox();
349 auto& dfab = dmf[mfi];
351 if (der_name ==
"vorticity") {
352 auto const& sfab = mf_cc_vel[lev][mfi];
353 der_function(bx, dfab, 0, 1, sfab,
vec_pm[lev]->const_array(mfi),
vec_pn[lev]->const_array(mfi),
vec_mskr[lev]->const_array(mfi), Geom(lev),
t_new[0],
nullptr, lev);
355 auto const& sfab = (*
cons_new[lev])[mfi];
356 der_function(bx, dfab, 0, 1, sfab,
vec_pm[lev]->const_array(mfi),
vec_pn[lev]->const_array(mfi),
vec_mskr[lev]->const_array(mfi), Geom(lev),
t_new[0],
nullptr, lev);
368 Real
dx = Geom()[lev].CellSizeArray()[0];
369 Real
dy = Geom()[lev].CellSizeArray()[1];
376 MultiFab dmf(plotMF[lev], make_alias, mf_comp, AMREX_SPACEDIM);
378#pragma omp parallel if (Gpu::notInLaunchRegion())
380 for (MFIter mfi(dmf, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
381 const Box& bx = mfi.tilebox();
382 const Array4<Real> loc_arr = dmf.array(mfi);
383 const Array4<Real const> zp_arr =
vec_z_phys_nd[lev]->const_array(mfi);
385 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
386 loc_arr(i,j,k,0) = (i+0.5_rt) *
dx;
387 loc_arr(i,j,k,1) = (j+0.5_rt) *
dy;
388 loc_arr(i,j,k,2) = 0.125_rt * (zp_arr(i,j ,k ) + zp_arr(i+1,j ,k ) +
389 zp_arr(i,j+1,k ) + zp_arr(i+1,j+1,k ) +
390 zp_arr(i,j ,k+1) + zp_arr(i+1,j ,k+1) +
391 zp_arr(i,j+1,k+1) + zp_arr(i+1,j+1,k+1) );
394 mf_comp += AMREX_SPACEDIM;
397#ifdef REMORA_USE_PARTICLES
398 const auto& particles_namelist( particleData.getNames() );
399 for (ParticlesNamesVector::size_type i = 0; i < particles_namelist.size(); i++) {
402 MultiFab temp_dat(plotMF[lev].boxArray(), plotMF[lev].DistributionMap(), 1, 0);
404 particleData[particles_namelist[i]]->Increment(temp_dat, lev);
405 MultiFab::Copy(plotMF[lev], temp_dat, 0, mf_comp, 1, 0);
410 Vector<std::string> particle_mesh_plot_names(0);
411 particleData.GetMeshPlotVarNames( particle_mesh_plot_names );
412 for (
int i = 0; i < particle_mesh_plot_names.size(); i++) {
413 std::string plot_var_name(particle_mesh_plot_names[i]);
415 MultiFab temp_dat(plotMF[lev].boxArray(), plotMF[lev].DistributionMap(), 1, 1);
417 particleData.GetMeshPlotVar(plot_var_name, temp_dat, lev);
418 MultiFab::Copy(plotMF[lev], temp_dat, 0, mf_comp, 1, 0);
426 Real dz = Geom()[lev].CellSizeArray()[2];
427 int N = Geom()[lev].Domain().size()[2];
430#pragma omp parallel if (Gpu::notInLaunchRegion())
432 for (MFIter mfi(mf_nd[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
434 const Box& bx = mfi.tilebox();
435 Array4<Real> mf_arr = mf_nd[lev].array(mfi);
436 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
437 mf_arr(i,j,k,2) = mf_arr(i,j,k,2) + (N-k) * dz;
448 if (finest_level == 0)
451 amrex::Print() <<
"Writing plotfile " << plotfilename <<
"\n";
453 GetVecOfConstPtrs(plotMF),
454 GetVecOfConstPtrs(mf_nd),
455 GetVecOfConstPtrs(mf_u),
456 GetVecOfConstPtrs(mf_v),
457 GetVecOfConstPtrs(mf_w),
458 GetVecOfConstPtrs(mf_2d_rho),
459 GetVecOfConstPtrs(mf_2d_u),
460 GetVecOfConstPtrs(mf_2d_v),
461 varnames_3d, varnames_2d_rho,
462 varnames_2d_u, varnames_2d_v,
467#ifdef REMORA_USE_PARTICLES
468 particleData.Checkpoint(plotfilename);
475 amrex::Print() <<
"Writing plotfile " << plotfilename <<
"\n";
477 [[maybe_unused]]
int desired_ratio = std::max(std::max(ref_ratio[lev0][0],ref_ratio[lev0][1]),ref_ratio[lev0][2]);
478 bool any_ratio_one = ( ( (ref_ratio[lev0][0] == 1) || (ref_ratio[lev0][1] == 1) ) ||
479 (ref_ratio[lev0][2] == 1) );
480 for (
int lev = 1; lev < finest_level; lev++) {
481 any_ratio_one = any_ratio_one ||
482 ( ( (ref_ratio[lev][0] == 1) || (ref_ratio[lev][1] == 1) ) ||
483 (ref_ratio[lev][2] == 1) );
486 Vector<IntVect> r2(finest_level);
487 Vector<Geometry> g2(finest_level+1);
488 Vector<MultiFab> mf2(finest_level+1);
490 mf2[0].define(grids[0], dmap[0], ncomp_mf_3d, 0);
493 MultiFab::Copy(mf2[0],plotMF[0],0,0,plotMF[0].nComp(),0);
496 Array<int,AMREX_SPACEDIM> periodicity =
497 {Geom()[0].isPeriodic(0),Geom()[0].isPeriodic(1),Geom()[0].isPeriodic(2)};
498 g2[0].define(Geom()[0].Domain(),&(Geom()[0].ProbDomain()),0,periodicity.data());
500 r2[0] = IntVect(1,1,ref_ratio[0][0]);
501 for (
int lev = 1; lev <= finest_level; ++lev) {
505 r2[lev-1][2] = r2[lev-2][2] * ref_ratio[lev-1][0];
508 mf2[lev].define(refine(grids[lev],r2[lev-1]), dmap[lev], ncomp_mf_3d, 0);
511 Box d2(Geom()[lev].Domain());
512 d2.refine(r2[lev-1]);
514 g2[lev].define(d2,&(Geom()[lev].ProbDomain()),0,periodicity.data());
519 amrex::Vector<amrex::BCRec> null_dom_bcs;
520 null_dom_bcs.resize(mf2[0].nComp());
521 for (
int n = 0; n < mf2[0].nComp(); n++) {
522 for (
int dir = 0; dir < AMREX_SPACEDIM; dir++) {
529 for (
int lev = 1; lev <= finest_level; ++lev) {
530 Interpolater* mapper_c = &pc_interp;
531 InterpFromCoarseLevel(mf2[lev],
t_new[lev], plotMF[lev],
532 0, 0, mf2[lev].nComp(),
535 r2[lev-1], mapper_c, null_dom_bcs, 0);
539 Vector<IntVect> rr(finest_level);
540 for (
int lev = 0; lev < finest_level; ++lev) {
541 rr[lev] = IntVect(ref_ratio[lev][0],ref_ratio[lev][1],ref_ratio[lev][0]);
545 GetVecOfConstPtrs(mf2),
546 GetVecOfConstPtrs(mf_nd),
547 GetVecOfConstPtrs(mf_u),
548 GetVecOfConstPtrs(mf_v),
549 GetVecOfConstPtrs(mf_w),
550 GetVecOfConstPtrs(mf_2d_rho),
551 GetVecOfConstPtrs(mf_2d_u),
552 GetVecOfConstPtrs(mf_2d_v),
553 varnames_3d, varnames_2d_rho,
554 varnames_2d_u, varnames_2d_v,
559#ifdef REMORA_USE_PARTICLES
560 particleData.Checkpoint(plotfilename);
564 GetVecOfConstPtrs(plotMF),
565 GetVecOfConstPtrs(mf_nd),
566 GetVecOfConstPtrs(mf_u),
567 GetVecOfConstPtrs(mf_v),
568 GetVecOfConstPtrs(mf_w),
569 GetVecOfConstPtrs(mf_2d_rho),
570 GetVecOfConstPtrs(mf_2d_u),
571 GetVecOfConstPtrs(mf_2d_v),
572 varnames_3d, varnames_2d_rho,
573 varnames_2d_u, varnames_2d_v,
577#ifdef REMORA_USE_PARTICLES
578 particleData.Checkpoint(plotfilename);
583 for (
int lev = 0; lev <= finest_level; ++lev) {
588#ifdef REMORA_USE_NETCDF
592 AMREX_ASSERT(finest_level == 0);
594 plotMF[0].FillBoundary(geom[lev].periodicity());
620 const Vector<const MultiFab*>& mf,
621 const Vector<const MultiFab*>& mf_nd,
622 const Vector<const MultiFab*>& mf_u,
623 const Vector<const MultiFab*>& mf_v,
624 const Vector<const MultiFab*>& mf_w,
625 const Vector<const MultiFab*>& mf_2d_rho,
626 const Vector<const MultiFab*>& mf_2d_u,
627 const Vector<const MultiFab*>& mf_2d_v,
628 const Vector<std::string>& varnames_3d,
629 const Vector<std::string>& varnames_2d_rho,
630 const Vector<std::string>& varnames_2d_u,
631 const Vector<std::string>& varnames_2d_v,
632 const Vector<Geometry>& my_geom,
634 const Vector<int>& level_steps,
635 const Vector<IntVect>& rr,
636 const std::string &versionName,
637 const std::string &levelPrefix,
638 const std::string &mfPrefix,
639 const Vector<std::string>& extra_dirs)
const
641 BL_PROFILE(
"WriteMultiLevelPlotfileWithBathymetry()");
643 AMREX_ASSERT(nlevels <= mf.size());
644 AMREX_ASSERT(nlevels <= ref_ratio.size()+1);
645 AMREX_ASSERT(nlevels <= level_steps.size());
647 AMREX_ASSERT(mf[0]->nComp() == varnames_3d.size());
649 bool callBarrier(
false);
650 PreBuildDirectorHierarchy(plotfilename, levelPrefix, nlevels, callBarrier);
651 if (!extra_dirs.empty()) {
652 for (
const auto& d : extra_dirs) {
653 const std::string ed = plotfilename+
"/"+d;
654 PreBuildDirectorHierarchy(ed, levelPrefix, nlevels, callBarrier);
657 ParallelDescriptor::Barrier();
659 if (ParallelDescriptor::MyProc() == ParallelDescriptor::NProcs()-1) {
660 Vector<BoxArray> boxArrays(nlevels);
661 for(
int level(0); level < boxArrays.size(); ++level) {
662 boxArrays[level] = mf[level]->boxArray();
665 auto f = [
this, plotfilename, nlevels, boxArrays, varnames_3d,
666 varnames_2d_rho, varnames_2d_u, varnames_2d_v, my_geom,
667 time, level_steps, rr, versionName, levelPrefix, mfPrefix]() {
668 VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
669 std::string HeaderFileName(plotfilename +
"/Header");
670 std::ofstream HeaderFile;
671 HeaderFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
672 HeaderFile.open(HeaderFileName.c_str(), std::ofstream::out |
673 std::ofstream::trunc |
674 std::ofstream::binary);
675 if( ! HeaderFile.good()) FileOpenFailed(HeaderFileName);
677 varnames_2d_rho, varnames_2d_u, varnames_2d_v,
678 my_geom,
time, level_steps, rr, versionName,
679 levelPrefix, mfPrefix);
682 if (AsyncOut::UseAsyncOut()) {
683 AsyncOut::Submit(std::move(f));
689 std::string mf_nodal_prefix =
"Nu_nd";
690 std::string mf_uface_prefix =
"UFace";
691 std::string mf_vface_prefix =
"VFace";
692 std::string mf_wface_prefix =
"WFace";
693 std::string mf_2d_rho_prefix =
"rho2d";
694 std::string mf_2d_u_prefix =
"u2d";
695 std::string mf_2d_v_prefix =
"v2d";
697 for (
int level = 0; level <= finest_level; ++level)
699 if (AsyncOut::UseAsyncOut()) {
700 VisMF::AsyncWrite(*mf[level],
701 MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mfPrefix),
704 VisMF::AsyncWrite(*mf_nd[level],
705 MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_nodal_prefix),
709 VisMF::AsyncWrite(*mf_u[level],
710 MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_uface_prefix),
712 VisMF::AsyncWrite(*mf_v[level],
713 MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_vface_prefix),
715 VisMF::AsyncWrite(*mf_w[level],
716 MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_wface_prefix),
719 if (mf_2d_rho[level]->nComp() > 0) {
720 VisMF::AsyncWrite(*mf_2d_rho[level],
721 MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_2d_rho_prefix),
724 if (mf_2d_u[level]->nComp() > 0) {
725 VisMF::AsyncWrite(*mf_2d_u[level],
726 MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_2d_u_prefix),
729 if (mf_2d_v[level]->nComp() > 0) {
730 VisMF::AsyncWrite(*mf_2d_v[level],
731 MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_2d_v_prefix),
735 const MultiFab* data;
736 std::unique_ptr<MultiFab> mf_tmp;
737 if (mf[level]->nGrowVect() != 0) {
738 mf_tmp = std::make_unique<MultiFab>(mf[level]->boxArray(),
739 mf[level]->DistributionMap(),
740 mf[level]->nComp(), 0, MFInfo(),
741 mf[level]->Factory());
742 MultiFab::Copy(*mf_tmp, *mf[level], 0, 0, mf[level]->nComp(), 0);
747 VisMF::Write(*data , MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mfPrefix));
749 VisMF::Write(*mf_nd[level], MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_nodal_prefix));
752 VisMF::Write(*mf_u[level], MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_uface_prefix));
753 VisMF::Write(*mf_v[level], MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_vface_prefix));
754 VisMF::Write(*mf_w[level], MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_wface_prefix));
756 if (mf_2d_rho[level]->nComp() > 0) {
757 VisMF::Write(*mf_2d_rho[level], MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_2d_rho_prefix));
759 if (mf_2d_u[level]->nComp() > 0) {
760 VisMF::Write(*mf_2d_u[level], MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_2d_u_prefix));
762 if (mf_2d_v[level]->nComp() > 0) {
763 VisMF::Write(*mf_2d_v[level], MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_2d_v_prefix));
785 [[maybe_unused]]
int nlevels,
786 const Vector<BoxArray> &bArray,
787 const Vector<std::string> &varnames_3d,
788 const Vector<std::string> &varnames_2d_rho,
789 const Vector<std::string> &varnames_2d_u,
790 const Vector<std::string> &varnames_2d_v,
791 const Vector<Geometry>& my_geom,
793 const Vector<int> &level_steps,
794 const Vector<IntVect>& my_ref_ratio,
795 const std::string &versionName,
796 const std::string &levelPrefix,
797 const std::string &mfPrefix)
const
799 AMREX_ASSERT(nlevels <= bArray.size());
800 AMREX_ASSERT(nlevels <= ref_ratio.size()+1);
801 AMREX_ASSERT(nlevels <= level_steps.size());
803 int num_extra_mfs = 1;
808 HeaderFile.precision(17);
811 HeaderFile << versionName <<
'\n';
813 HeaderFile << varnames_3d.size() <<
'\n';
815 for (
int ivar = 0; ivar < varnames_3d.size(); ++ivar) {
816 HeaderFile << varnames_3d[ivar] <<
"\n";
818 HeaderFile << AMREX_SPACEDIM <<
'\n';
819 HeaderFile <<
time <<
'\n';
820 HeaderFile << finest_level <<
'\n';
821 for (
int i = 0; i < AMREX_SPACEDIM; ++i) {
822 HeaderFile << my_geom[0].ProbLo(i) <<
' ';
825 for (
int i = 0; i < AMREX_SPACEDIM; ++i) {
826 HeaderFile << my_geom[0].ProbHi(i) <<
' ';
829 for (
int i = 0; i < finest_level; ++i) {
830 HeaderFile << my_ref_ratio[i][0] <<
' ';
833 for (
int i = 0; i <= finest_level; ++i) {
834 HeaderFile << my_geom[i].Domain() <<
' ';
837 for (
int i = 0; i <= finest_level; ++i) {
838 HeaderFile << level_steps[i] <<
' ';
841 for (
int i = 0; i <= finest_level; ++i) {
842 for (
int k = 0; k < AMREX_SPACEDIM; ++k) {
843 HeaderFile << my_geom[i].CellSize()[k] <<
' ';
847 HeaderFile << (int) my_geom[0].
Coord() <<
'\n';
850 for (
int level = 0; level <= finest_level; ++level) {
851 HeaderFile << level <<
' ' << bArray[level].size() <<
' ' <<
time <<
'\n';
852 HeaderFile << level_steps[level] <<
'\n';
854 const IntVect& domain_lo = my_geom[level].Domain().smallEnd();
855 for (
int i = 0; i < bArray[level].size(); ++i)
860 const Box& b = shift(bArray[level][i], -domain_lo);
861 RealBox loc = RealBox(b, my_geom[level].CellSize(), my_geom[level].ProbLo());
862 for (
int n = 0; n < AMREX_SPACEDIM; ++n) {
863 HeaderFile << loc.lo(n) <<
' ' << loc.hi(n) <<
'\n';
867 HeaderFile << MultiFabHeaderPath(level, levelPrefix, mfPrefix) <<
'\n';
869 HeaderFile << num_extra_mfs <<
"\n";
870 HeaderFile <<
"3" <<
"\n";
871 HeaderFile <<
"amrexvec_nu_x" <<
"\n";
872 HeaderFile <<
"amrexvec_nu_y" <<
"\n";
873 HeaderFile <<
"amrexvec_nu_z" <<
"\n";
874 std::string mf_nodal_prefix =
"Nu_nd";
875 for (
int level = 0; level <= finest_level; ++level) {
876 HeaderFile << MultiFabHeaderPath(level, levelPrefix, mf_nodal_prefix) <<
'\n';
879 HeaderFile <<
"1" <<
"\n";
880 HeaderFile <<
"u_vel" <<
"\n";
881 std::string mf_uface_prefix =
"UFace";
882 for (
int level = 0; level <= finest_level; ++level) {
883 HeaderFile << MultiFabHeaderPath(level, levelPrefix, mf_uface_prefix) <<
'\n';
885 HeaderFile <<
"1" <<
"\n";
886 HeaderFile <<
"v_vel" <<
"\n";
887 std::string mf_vface_prefix =
"VFace";
888 for (
int level = 0; level <= finest_level; ++level) {
889 HeaderFile << MultiFabHeaderPath(level, levelPrefix, mf_vface_prefix) <<
'\n';
891 HeaderFile <<
"1" <<
"\n";
892 HeaderFile <<
"w_vel" <<
"\n";
893 std::string mf_wface_prefix =
"WFace";
894 for (
int level = 0; level <= finest_level; ++level) {
895 HeaderFile << MultiFabHeaderPath(level, levelPrefix, mf_wface_prefix) <<
'\n';
899 if (varnames_2d_rho.size() > 0) {
900 HeaderFile << varnames_2d_rho.size() <<
"\n";
901 for (
int ivar = 0; ivar < varnames_2d_rho.size(); ++ivar) {
902 HeaderFile << varnames_2d_rho[ivar] <<
"\n";
904 std::string mf_2d_rho_prefix =
"rho2d";
905 for (
int level = 0; level <= finest_level; ++level) {
906 HeaderFile << MultiFabHeaderPath(level, levelPrefix, mf_2d_rho_prefix) <<
"\n";
910 if (varnames_2d_u.size() > 0) {
911 HeaderFile << varnames_2d_u.size() <<
"\n";
912 for (
int ivar = 0; ivar < varnames_2d_u.size(); ++ivar) {
913 HeaderFile << varnames_2d_u[ivar] <<
"\n";
915 std::string mf_2d_u_prefix =
"u2d";
916 for (
int level = 0; level <= finest_level; ++level) {
917 HeaderFile << MultiFabHeaderPath(level, levelPrefix, mf_2d_u_prefix) <<
"\n";
921 if (varnames_2d_v.size() > 0) {
922 HeaderFile << varnames_2d_v.size() <<
"\n";
923 for (
int ivar = 0; ivar < varnames_2d_v.size(); ++ivar) {
924 HeaderFile << varnames_2d_v[ivar] <<
"\n";
926 std::string mf_2d_v_prefix =
"v2d";
927 for (
int level = 0; level <= finest_level; ++level) {
928 HeaderFile << MultiFabHeaderPath(level, levelPrefix, mf_2d_v_prefix) <<
"\n";