Skip to content

Commit

Permalink
multilevel version of writeplotfiletoascii (#2742)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnonaka authored May 12, 2022
1 parent 5bbb63f commit 0b48551
Showing 1 changed file with 56 additions and 57 deletions.
113 changes: 56 additions & 57 deletions Tools/Postprocessing/C_Src/WritePlotfileToASCII.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,27 @@ main (int argc,
PrintUsage(argv[0]);
}

// plotfile names for the coarse, fine, and subtracted output
// plotfile name
std::string iFile;

// read in parameters from inputs file
ParmParse pp;

// coarse MultiFab
// read in plotfile name
pp.query("infile", iFile);
if (iFile.empty())
amrex::Abort("You must specify `infile'");

int comp_in_line = 0;
pp.query("comp_in_line", comp_in_line);

// single-level for now
// AMR comes later, where we iterate over each level in isolation

// for the Header
std::string iFile2 = iFile;
iFile2 += "/Header";
std::string Header = iFile;
Header += "/Header";

// open header
ifstream x;
x.open(iFile2.c_str(), ios::in);
x.open(Header.c_str(), ios::in);

// read in first line of header
string str;
Expand All @@ -85,70 +82,72 @@ main (int argc,
Abort();
}

// now read in the plotfile data
// check to see whether the user pointed to the plotfile base directory
// or the data itself
if (amrex::FileExists(iFile+"/Level_0/Cell_H")) {
iFile += "/Level_0/Cell";
}
if (amrex::FileExists(iFile+"/Level_00/Cell_H")) {
iFile += "/Level_00/Cell";
}
int lev = 0;

// storage for the input coarse and fine MultiFabs
MultiFab mf;
do {

// read in plotfiles, 'coarse' and 'fine' to MultiFabs
// note: fine could be the same resolution as coarse
VisMF::Read(mf, iFile);
if (lev > 9) {
Abort("Utility only works for 10 levels of refinement or less");
}

ncomp = mf.nComp();
Print() << "ncomp = " << ncomp << std::endl;
// storage for the MultiFab
MultiFab mf;

// check nodality
IntVect c_nodality = mf.ixType().toIntVect();
Print() << "nodality " << c_nodality << std::endl;
std::string iFile_lev = iFile;

// get boxArray
BoxArray ba = mf.boxArray();
std::string levX = "/Level_"+to_string(lev)+"/Cell";
std::string levXX = "/Level_0"+to_string(lev)+"/Cell";

// minimalBox() computes a single box to enclose all the boxes
// enclosedCells() converts it to a cell-centered Box
Box bx_onegrid = ba.minimalBox().enclosedCells();
// now read in the plotfile data
// check to see whether the user pointed to the plotfile base directory
// or the data itself
if (amrex::FileExists(iFile+levX+"_H")) {
iFile_lev += levX;
} else if (amrex::FileExists(iFile+levXX+"_H")) {
iFile_lev += levXX;
} else {
break; // terminate while loop
}

// number of cells in the coarse domain
Print() << "npts in coarse domain = " << bx_onegrid.numPts() << std::endl;
long npts_coarsedomain = bx_onegrid.numPts();
// read in plotfile to MultiFab
VisMF::Read(mf, iFile_lev);

// BoxArray, DistributionMapping, and MultiFab with one grid
BoxArray ba_onegrid(bx_onegrid);
DistributionMapping dmap_onegrid(ba_onegrid);
MultiFab mf_onegrid(ba_onegrid,dmap_onegrid,ncomp,0);
if (lev == 0) {
ncomp = mf.nComp();
Print() << "Number of components in the plotfile = " << ncomp << std::endl;
Print() << "Nodality of plotfile = " << mf.ixType().toIntVect() << std::endl;
}

// copy data into MultiFab with one grid
mf_onegrid.ParallelCopy(mf,0,0,ncomp,0,0);
// get boxArray to compute number of grid points at the level
BoxArray ba = mf.boxArray();
Print() << "Number of grid points at level " << lev << " = " << ba.numPts() << std::endl;

for ( MFIter mfi(mf_onegrid,false); mfi.isValid(); ++mfi ) {
for ( MFIter mfi(mf,false); mfi.isValid(); ++mfi ) {

const Box& bx = mfi.validbox();
const auto lo = amrex::lbound(bx);
const auto hi = amrex::ubound(bx);
const Box& bx = mfi.validbox();
const auto lo = amrex::lbound(bx);
const auto hi = amrex::ubound(bx);

const Array4<Real>& mfdata = mf_onegrid.array(mfi);
const Array4<Real>& mfdata = mf.array(mfi);

if (comp_in_line == 1){
std::cout << mf_onegrid[mfi];
}else{
for (auto n=0; n<ncomp; ++n) {
for (auto k = lo.z; k <= hi.z; ++k) {
for (auto j = lo.y; j <= hi.y; ++j) {
if (comp_in_line == 1) {
std::cout << mf[mfi];
} else {
for (auto n=0; n<ncomp; ++n) {
for (auto k = lo.z; k <= hi.z; ++k) {
for (auto j = lo.y; j <= hi.y; ++j) {
for (auto i = lo.x; i <= hi.x; ++i) {
std::cout << i << " " << j << " " << k << " " << n << " " << mfdata(i,j,k,n) << "\n";
std::cout << i << " " << j << " " << k << " " << n << " " << mfdata(i,j,k,n) << "\n";
}
}
}
}
}
}
}
}
} // end MFIter
} // end MFIter

// proceed to next level of refinement
++lev;

} while(true);

}

0 comments on commit 0b48551

Please sign in to comment.