Skip to content

Commit a7f6a0b

Browse files
committed
fix
1 parent 232a1cd commit a7f6a0b

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

src/io/projection.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/// \brief AMReX I/O for 2D projections
88

99
#include "AMReX_Array.H"
10+
#include "AMReX_BoxList.H"
1011
#include "AMReX_DistributionMapping.H"
1112
#include "AMReX_FPC.H"
1213
#include "AMReX_Geometry.H"
@@ -542,7 +543,36 @@ void WriteProjection(amrex::Direction dir, std::unordered_map<std::string, amrex
542543
for (int lev = 0; lev < nlevels; ++lev) {
543544
// Use the BoxArray and DM from the first component's MultiFab on this level
544545
const amrex::MultiFab &example_mf = firstVec[lev];
545-
mf_all[lev].define(example_mf.boxArray(), example_mf.DistributionMap(), ncomp, 0);
546+
bool needs_union = false;
547+
for (const auto &varname : varnames) {
548+
const amrex::MultiFab &comp_mf = proj.at(varname)[lev];
549+
const auto &example_ba = example_mf.boxArray();
550+
const auto &comp_ba = comp_mf.boxArray();
551+
const bool cover_match = example_ba.contains(comp_ba) && comp_ba.contains(example_ba);
552+
if (!cover_match) {
553+
needs_union = true;
554+
break;
555+
}
556+
}
557+
558+
if (needs_union) {
559+
amrex::BoxList bl_union(example_mf.boxArray());
560+
for (const auto &varname : varnames) {
561+
const amrex::MultiFab &comp_mf = proj.at(varname)[lev];
562+
bl_union.join(comp_mf.boxArray().boxList());
563+
}
564+
bl_union.simplify();
565+
amrex::BoxArray ba_union(amrex::removeOverlap(bl_union));
566+
amrex::DistributionMapping dm_union(ba_union);
567+
mf_all[lev].define(ba_union, dm_union, ncomp, 0);
568+
mf_all[lev].setVal(0.0);
569+
if (amrex::ParallelDescriptor::IOProcessor()) {
570+
amrex::Print() << "Warning: projection components use different BoxArrays at level " << lev
571+
<< "; using a union BoxArray for output.\n";
572+
}
573+
} else {
574+
mf_all[lev].define(example_mf.boxArray(), example_mf.DistributionMap(), ncomp, 0);
575+
}
546576

547577
int icomp = 0;
548578
// Iterate in the same order as varnames

0 commit comments

Comments
 (0)