Skip to content

Commit

Permalink
cleanup of flattened SF data structures
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnonaka committed Jan 29, 2025
1 parent 95a94eb commit 474d4ad
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src_compressible_stag/compressible_functions_stag.H
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void WriteSpatialCross3D(const Vector<Real>& spatialCross, int step, const Geome

void WriteSpatialCross1D(const MultiFab& spatialCross , int step, const Geometry& geom, const int ncross);

void WritePlotFilesSF_2D(const amrex::MultiFab& mag, const amrex::MultiFab& realimag, const amrex::Geometry& geom,
void WritePlotFilesSF_2D(const amrex::MultiFab& mag, const amrex::MultiFab& realimag,
const int step, const Real time, const amrex::Vector< std::string >& names, std::string plotfile_base);

void EvaluateWritePlotFileVelGrad(int step,
Expand Down
65 changes: 30 additions & 35 deletions src_compressible_stag/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,20 @@ void main_driver(const char* argv)
}
}

if (((do_1D) or (do_2D)) and (amrex::Math::abs(visc_type) == 3)) {
if ((do_1D || do_2D) && amrex::Math::abs(visc_type) == 3) {
Abort("1D and 2D version only work for zero bulk viscosity currently. Use visc_type 1 or 2");
}
if ((do_1D) and (do_2D)) {
Abort("Can not have both 1D and 2D mode on at the same time");
}

// cannot run a 1x1x1 simulation
if (n_cells[0] == 1 && n_cells[1] == 1 && n_cells[2] == 1) {
Abort("Simulation must have more than 1 total cell");
}

//**********************************************************************
// Error checking to make sure a 2D planar simulation is configured correctly
if (do_1D && do_2D) {
Abort("Can not have both 1D and 2D mode on at the same time");
}
if (n_cells[0] == 1 && n_cells[1] > 1 && n_cells[2] > 1) {
Abort("Cannot run a 2D simulation with only 1 cell in x - use n_cells[2]=1");
}
Expand All @@ -122,6 +125,20 @@ void main_driver(const char* argv)
if (n_cells[0] > 1 && n_cells[1] > 1 && n_cells[2] == 1 && do_2D == 0) {
Abort("2D simulations with only 1 cell in z requires do_2D=1");
}
//**********************************************************************

//**********************************************************************
// Error checking to make sure a 1D pencil simulation is configured correctly
if (n_cells[0] == 1 && n_cells[1] == 1 && n_cells[2] > 1) {
Abort("Cannot run a 1D simulation in the z-direcion; use n_cells[0]>1");
}
if (n_cells[0] == 1 && n_cells[1] > 1 && n_cells[2] == 1) {
Abort("Cannot run a 1D simulation in the y-direcion; use n_cells[0]>1");
}
if (n_cells[0] > 1 && n_cells[1] == 1 && n_cells[2] == 1) {
Abort("1D simulations in the x-direction requires do_1D=1");
}
//**********************************************************************

// for each direction, if bc_vel_lo/hi is periodic, then
// set the corresponding bc_mass_lo/hi and bc_therm_lo/hi to periodic
Expand Down Expand Up @@ -228,15 +245,15 @@ void main_driver(const char* argv)
Abort("Cross cell needs to be within the domain: 0 <= cross_cell <= n_cells[0] - 1");
}
if (struct_fact_int > 0) {
if (do_1D) {
Abort("Projected structure factors (project_dir) does not work for do_1D case");
}
if (do_2D and project_dir != 2) {
Abort("Structure factors with do_2D requires project_dir == 2");
}
if (do_2D and slicepoint >= 0) {
Abort("Cannot use do_2D and slicepoint");
}
if (do_1D) {
Abort("Projected structure factors (project_dir) does not work for do_1D case");
}
if (project_dir >= 0) {
if (do_slab_sf and ((membrane_cell <= 0) or (membrane_cell >= n_cells[project_dir]-1))) {
Abort("Slab structure factor needs a membrane cell within the domain: 0 < membrane_cell < n_cells[project_dir] - 1");
Expand Down Expand Up @@ -330,7 +347,8 @@ void main_driver(const char* argv)
Vector < StructFact > structFactPrimArray;
Vector < StructFact > structFactConsArray;

Geometry geom_sf_flat; // for SF plotfiles for use_2D case - needs to be cleaned up
// for structure factor analysis of flattened MultiFabs
// (slices, vertical averages, arrays of flattened MFs, surface coverage)
BoxArray ba_flat;
DistributionMapping dmap_flat;

Expand Down Expand Up @@ -801,29 +819,6 @@ void main_driver(const char* argv)
ba_flat = Flattened.boxArray();
dmap_flat = Flattened.DistributionMap();

if (do_2D) {
///////////////////////////////////////////////////
// for SF plotfiles for do_2D case - needs to be cleaned up
// create a Geometry object for SF plotfile so wavenumber appears in physical coordinates
Box domain_flat = ba_flat.minimalBox();

Vector<Real> projected_lo(AMREX_SPACEDIM);
Vector<Real> projected_hi(AMREX_SPACEDIM);

for (int d=0; d<AMREX_SPACEDIM; ++d) {
projected_lo[d] = -domain_flat.length(d)/2 - 0.5;
projected_hi[d] = domain_flat.length(d)/2 - 1 + 0.5;
}
projected_lo[project_dir] = -0.5;
projected_hi[project_dir] = 0.5;

RealBox real_box_flat({AMREX_D_DECL(projected_lo[0],projected_lo[1],projected_lo[2])},
{AMREX_D_DECL(projected_hi[0],projected_hi[1],projected_hi[2])});

geom_sf_flat.define(domain_flat,&real_box_flat,CoordSys::cartesian,is_periodic.data());
///////////////////////////////////////////////////
}

if (do_2D) {

structFactPrimArray.resize(n_cells[project_dir]);
Expand Down Expand Up @@ -1441,9 +1436,9 @@ void main_driver(const char* argv)

MultiFab prim_mag, prim_realimag, cons_mag, cons_realimag;

prim_mag.define(ba_flat,dmap_flat,structFactPrimArray[0].get_ncov(),0);
prim_mag .define(ba_flat,dmap_flat, structFactPrimArray[0].get_ncov(),0);
prim_realimag.define(ba_flat,dmap_flat,2*structFactPrimArray[0].get_ncov(),0);
cons_mag.define(ba_flat,dmap_flat,structFactConsArray[0].get_ncov(),0);
cons_mag .define(ba_flat,dmap_flat, structFactConsArray[0].get_ncov(),0);
cons_realimag.define(ba_flat,dmap_flat,2*structFactConsArray[0].get_ncov(),0);

prim_mag.setVal(0.0);
Expand All @@ -1463,9 +1458,9 @@ void main_driver(const char* argv)
prim_realimag.mult(ncellsinv);
cons_realimag.mult(ncellsinv);

WritePlotFilesSF_2D(prim_mag,prim_realimag,geom_sf_flat,step,time,
WritePlotFilesSF_2D(prim_mag,prim_realimag,step,time,
structFactPrimArray[0].get_names(),"plt_SF_prim_2D");
WritePlotFilesSF_2D(cons_mag,cons_realimag,geom_sf_flat,step,time,
WritePlotFilesSF_2D(cons_mag,cons_realimag,step,time,
structFactConsArray[0].get_names(),"plt_SF_cons_2D");

}
Expand Down
40 changes: 24 additions & 16 deletions src_compressible_stag/writePlotFileStag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,35 +517,43 @@ void WriteSpatialCross1D(const amrex::MultiFab& spatialCross, int step, const Ge
}
}

void WritePlotFilesSF_2D(const amrex::MultiFab& mag, const amrex::MultiFab& realimag, const amrex::Geometry& geom,
void WritePlotFilesSF_2D(const amrex::MultiFab& mag, const amrex::MultiFab& realimag,
const int step, const Real time, const amrex::Vector< std::string >& names, std::string plotfile_base) {

// Magnitude of the Structure Factor
std::string name = plotfile_base;
name += "_mag";
const std::string plotfilename1 = amrex::Concatenate(name,step,9);

Real dx0 = geom.CellSize(0);
Real dx1 = geom.CellSize(1);
Real dx2 = geom.CellSize(2);
Real pi = 3.1415926535897932;
Box domain = geom.Domain();
RealBox real_box({AMREX_D_DECL(-pi/dx0,-pi/dx1,-pi/dx2)},
{AMREX_D_DECL( pi/dx0, pi/dx1, pi/dx2)});
Vector<int> is_periodic(AMREX_SPACEDIM,0); // set to 0 (not periodic) by default
for (int i=0; i<AMREX_SPACEDIM; ++i) {
is_periodic[i] = geom.isPeriodic(i);

Vector<int> is_periodic(AMREX_SPACEDIM,1); // only needed to make a plotfile

Geometry geom;

Box domain_flat = mag.boxArray().minimalBox();

Vector<Real> projected_lo(AMREX_SPACEDIM);
Vector<Real> projected_hi(AMREX_SPACEDIM);

for (int d=0; d<AMREX_SPACEDIM; ++d) {
projected_lo[d] = -domain_flat.length(d)/2 - 0.5;
projected_hi[d] = domain_flat.length(d)/2 - 1 + 0.5;
}
Geometry geom2;
geom2.define(domain,&real_box,CoordSys::cartesian,is_periodic.data());
projected_lo[project_dir] = -0.5;
projected_hi[project_dir] = 0.5;

RealBox real_box_flat({AMREX_D_DECL(projected_lo[0],projected_lo[1],projected_lo[2])},
{AMREX_D_DECL(projected_hi[0],projected_hi[1],projected_hi[2])});

geom.define(domain_flat,&real_box_flat,CoordSys::cartesian,is_periodic.data());


Vector<std::string> varNames;
varNames.resize(names.size());
for (int n=0; n<names.size(); n++) {
varNames[n] = names[n];
}

WriteSingleLevelPlotfile(plotfilename1,mag,varNames,geom2,time,step);
WriteSingleLevelPlotfile(plotfilename1,mag,varNames,geom,time,step);

// Components of the Structure Factor
name = plotfile_base;
Expand All @@ -568,7 +576,7 @@ void WritePlotFilesSF_2D(const amrex::MultiFab& mag, const amrex::MultiFab& real
cnt++;
}

WriteSingleLevelPlotfile(plotfilename2,realimag,varNames,geom2,time,step);
WriteSingleLevelPlotfile(plotfilename2,realimag,varNames,geom,time,step);
}


0 comments on commit 474d4ad

Please sign in to comment.