|
7 | 7 | /// \brief AMReX I/O for 2D projections |
8 | 8 |
|
9 | 9 | #include "AMReX_Array.H" |
| 10 | +#include "AMReX_BoxList.H" |
10 | 11 | #include "AMReX_DistributionMapping.H" |
11 | 12 | #include "AMReX_FPC.H" |
12 | 13 | #include "AMReX_Geometry.H" |
@@ -542,7 +543,36 @@ void WriteProjection(amrex::Direction dir, std::unordered_map<std::string, amrex |
542 | 543 | for (int lev = 0; lev < nlevels; ++lev) { |
543 | 544 | // Use the BoxArray and DM from the first component's MultiFab on this level |
544 | 545 | 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 | + } |
546 | 576 |
|
547 | 577 | int icomp = 0; |
548 | 578 | // Iterate in the same order as varnames |
|
0 commit comments