Skip to content

Commit

Permalink
cleanup flattened code, simplify a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnonaka committed Jan 3, 2025
1 parent 8c94f93 commit 45b79e3
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 378 deletions.
93 changes: 21 additions & 72 deletions exec/hydro/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ void main_driver(const char* argv)
///////////////////////////////////////////

StructFact structFactFlattened;
MultiFab FlattenedRotMaster;
MultiFab FlattenedMaster;

Geometry geom_flat;

Expand All @@ -365,76 +365,30 @@ void main_driver(const char* argv)
} else {
ExtractSlice(structFactMF, Flattened, geom, project_dir, slicepoint, 0, 1);
}
// we rotate this flattened MultiFab to have normal in the z-direction since
// our structure factor class assumes this for flattened
MultiFab FlattenedRot = RotateFlattenedMF(Flattened);
BoxArray ba_flat = FlattenedRot.boxArray();
const DistributionMapping& dmap_flat = FlattenedRot.DistributionMap();
FlattenedRotMaster.define(ba_flat,dmap_flat,structVars,0);
BoxArray ba_flat = Flattened.boxArray();
const DistributionMapping& dmap_flat = Flattened.DistributionMap();
FlattenedMaster.define(ba_flat,dmap_flat,structVars,0);
{
IntVect dom_lo(AMREX_D_DECL(0,0,0));
IntVect dom_hi;

// yes you could simplify this code but for now
// these are written out fully to better understand what is happening
// we wanted dom_hi[AMREX_SPACEDIM-1] to be equal to 0
// and need to transmute the other indices depending on project_dir
#if (AMREX_SPACEDIM == 2)
if (project_dir == 0) {
dom_hi[0] = n_cells[1]-1;
}
else if (project_dir == 1) {
dom_hi[0] = n_cells[0]-1;
}
dom_hi[1] = 0;
#elif (AMREX_SPACEDIM == 3)
if (project_dir == 0) {
dom_hi[0] = n_cells[1]-1;
dom_hi[1] = n_cells[2]-1;
} else if (project_dir == 1) {
dom_hi[0] = n_cells[0]-1;
dom_hi[1] = n_cells[2]-1;
} else if (project_dir == 2) {
dom_hi[0] = n_cells[0]-1;
dom_hi[1] = n_cells[1]-1;
}
dom_hi[2] = 0;
#endif
Box domain(dom_lo, dom_hi);

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

// This defines the physical box
// we retain prob_lo and prob_hi in all directions except project_dir,
// where the physical size is 0 to dx[project_dir]
Vector<Real> projected_lo(AMREX_SPACEDIM);
Vector<Real> projected_hi(AMREX_SPACEDIM);

// yes you could simplify this code but for now
// these are written out fully to better understand what is happening
// we wanted projected_hi[AMREX_SPACEDIM-1] to be equal to dx[projected_dir]
// and need to transmute the other indices depending on project_dir
#if (AMREX_SPACEDIM == 2)
if (project_dir == 0) {
projected_hi[0] = prob_hi[1];
} else if (project_dir == 1) {
projected_hi[0] = prob_hi[0];
for (int d=0; d<AMREX_SPACEDIM; ++d) {
projected_lo[d] = prob_lo[d];
projected_hi[d] = prob_hi[d];
}
projected_hi[1] = prob_hi[project_dir] / n_cells[project_dir];
#elif (AMREX_SPACEDIM == 3)
if (project_dir == 0) {
projected_hi[0] = prob_hi[1];
projected_hi[1] = prob_hi[2];
} else if (project_dir == 1) {
projected_hi[0] = prob_hi[0];
projected_hi[1] = prob_hi[2];
} else if (project_dir == 2) {
projected_hi[0] = prob_hi[0];
projected_hi[1] = prob_hi[1];
}
projected_hi[2] = prob_hi[project_dir] / n_cells[project_dir];
#endif
projected_lo[project_dir] = 0.;
projected_hi[project_dir] = (prob_hi[project_dir] - prob_lo[project_dir]) / n_cells[project_dir];

RealBox real_box({AMREX_D_DECL( prob_lo[0], prob_lo[1], prob_lo[2])},
{AMREX_D_DECL(projected_hi[0],projected_hi[1],projected_hi[2])});
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])});

// This defines a Geometry object
geom_flat.define(domain,&real_box,CoordSys::cartesian,is_periodic.data());
geom_flat.define(domain_flat,&real_box_flat,CoordSys::cartesian,is_periodic.data());
}

structFactFlattened.define(ba_flat,dmap_flat,var_names,var_scaling);
Expand Down Expand Up @@ -484,11 +438,8 @@ void main_driver(const char* argv)
} else {
ExtractSlice(structFactMF, Flattened, geom, project_dir, slicepoint, 0, structVars);
}
// we rotate this flattened MultiFab to have normal in the z-direction since
// our structure factor class assumes this for flattened
MultiFab FlattenedRot = RotateFlattenedMF(Flattened);
FlattenedRotMaster.ParallelCopy(FlattenedRot,0,0,structVars);
structFactFlattened.FortStructure(FlattenedRotMaster);
FlattenedMaster.ParallelCopy(Flattened,0,0,structVars);
structFactFlattened.FortStructure(FlattenedMaster);
}
}

Expand Down Expand Up @@ -582,10 +533,8 @@ void main_driver(const char* argv)
} else {
ExtractSlice(structFactMF, Flattened, geom, project_dir, slicepoint, 0, structVars);
}
// we rotate this flattened MultiFab to have normal in the z-direction since
// our structure factor class assumes this for flattened
MultiFab FlattenedRot = RotateFlattenedMF(Flattened);
structFactFlattened.FortStructure(FlattenedRot);
FlattenedMaster.ParallelCopy(Flattened,0,0,structVars);
structFactFlattened.FortStructure(FlattenedMaster);
}
}

Expand Down
1 change: 0 additions & 1 deletion src_common/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ CEXE_sources += ComputeDivAndGrad.cpp
CEXE_sources += Debug.cpp
CEXE_sources += MultiFabPhysBC.cpp
CEXE_sources += NormInnerProduct.cpp
CEXE_sources += RotateFlattenedMF.cpp
CEXE_sources += SqrtMF.cpp
#CEXE_sources += InterpCoarsen.cpp

51 changes: 0 additions & 51 deletions src_common/RotateFlattenedMF.cpp

This file was deleted.

5 changes: 0 additions & 5 deletions src_common/common_functions.H
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@ void CCL2Norm(const MultiFab & m1,
amrex::MultiFab& mscr,
Real & norm_l2);

///////////////////////////
// in RotateFlattenedMF.cpp

MultiFab RotateFlattenedMF(MultiFab const& mf);

///////////////////////////
// in InterpCoarsen.cpp
void FaceFillCoarse(Vector<std::array< MultiFab, AMREX_SPACEDIM >>& mf, int map);
Expand Down
112 changes: 31 additions & 81 deletions src_compressible/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void main_driver(const char* argv)

// structure factor class for flattened dataset
StructFact structFactPrimFlattened;
MultiFab primFlattenedRotMaster;
MultiFab primFlattenedMaster;

//////////////////////////////////////////////

Expand Down Expand Up @@ -465,7 +465,7 @@ void main_driver(const char* argv)

// structure factor class for flattened dataset
StructFact structFactConsFlattened;
MultiFab consFlattenedRotMaster;
MultiFab consFlattenedMaster;

//////////////////////////////////////////////

Expand All @@ -482,77 +482,31 @@ void main_driver(const char* argv)
} else {
ExtractSlice(structFactPrimMF, Flattened, geom, project_dir, slicepoint, 0, 1);
}
// we rotate this flattened MultiFab to have normal in the z-direction since
// our structure factor class assumes this for flattened
MultiFab FlattenedRot = RotateFlattenedMF(Flattened);
BoxArray ba_flat = FlattenedRot.boxArray();
const DistributionMapping& dmap_flat = FlattenedRot.DistributionMap();
primFlattenedRotMaster.define(ba_flat,dmap_flat,structVarsPrim,0);
consFlattenedRotMaster.define(ba_flat,dmap_flat,structVarsCons,0);
BoxArray ba_flat = Flattened.boxArray();
const DistributionMapping& dmap_flat = Flattened.DistributionMap();
primFlattenedMaster.define(ba_flat,dmap_flat,structVarsPrim,0);
consFlattenedMaster.define(ba_flat,dmap_flat,structVarsCons,0);
{
IntVect dom_lo(AMREX_D_DECL(0,0,0));
IntVect dom_hi;

// yes you could simplify this code but for now
// these are written out fully to better understand what is happening
// we wanted dom_hi[AMREX_SPACEDIM-1] to be equal to 0
// and need to transmute the other indices depending on project_dir
#if (AMREX_SPACEDIM == 2)
if (project_dir == 0) {
dom_hi[0] = n_cells[1]-1;
}
else if (project_dir == 1) {
dom_hi[0] = n_cells[0]-1;
}
dom_hi[1] = 0;
#elif (AMREX_SPACEDIM == 3)
if (project_dir == 0) {
dom_hi[0] = n_cells[1]-1;
dom_hi[1] = n_cells[2]-1;
} else if (project_dir == 1) {
dom_hi[0] = n_cells[0]-1;
dom_hi[1] = n_cells[2]-1;
} else if (project_dir == 2) {
dom_hi[0] = n_cells[0]-1;
dom_hi[1] = n_cells[1]-1;
}
dom_hi[2] = 0;
#endif
Box domain(dom_lo, dom_hi);

// This defines the physical box
Vector<Real> projected_hi(AMREX_SPACEDIM);

// yes you could simplify this code but for now
// these are written out fully to better understand what is happening
// we wanted projected_hi[AMREX_SPACEDIM-1] to be equal to dx[projected_dir]
// and need to transmute the other indices depending on project_dir
#if (AMREX_SPACEDIM == 2)
if (project_dir == 0) {
projected_hi[0] = prob_hi[1];
} else if (project_dir == 1) {
projected_hi[0] = prob_hi[0];
}
projected_hi[1] = prob_hi[project_dir] / n_cells[project_dir];
#elif (AMREX_SPACEDIM == 3)
if (project_dir == 0) {
projected_hi[0] = prob_hi[1];
projected_hi[1] = prob_hi[2];
} else if (project_dir == 1) {
projected_hi[0] = prob_hi[0];
projected_hi[1] = prob_hi[2];
} else if (project_dir == 2) {
projected_hi[0] = prob_hi[0];
projected_hi[1] = prob_hi[1];
}
projected_hi[2] = prob_hi[project_dir] / n_cells[project_dir];
#endif

RealBox real_box({AMREX_D_DECL( prob_lo[0], prob_lo[1], prob_lo[2])},
{AMREX_D_DECL(projected_hi[0],projected_hi[1],projected_hi[2])});

// This defines a Geometry object
geom_flat.define(domain,&real_box,CoordSys::cartesian,is_periodic.data());
Box domain_flat = primFlattenedMaster.boxArray().minimalBox();

// This defines the physical box
// we retain prob_lo and prob_hi in all directions except project_dir,
// where the physical size is 0 to dx[project_dir]
Vector<Real> projected_lo(AMREX_SPACEDIM);
Vector<Real> projected_hi(AMREX_SPACEDIM);

for (int d=0; d<AMREX_SPACEDIM; ++d) {
projected_lo[d] = prob_lo[d];
projected_hi[d] = prob_hi[d];
}
projected_lo[project_dir] = 0.;
projected_hi[project_dir] = (prob_hi[project_dir] - prob_lo[project_dir]) / n_cells[project_dir];

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])});

// This defines a Geometry object
geom_flat.define(domain_flat,&real_box_flat,CoordSys::cartesian,is_periodic.data());
}

structFactPrimFlattened.define(ba_flat,dmap_flat,prim_var_names,var_scaling_prim);
Expand Down Expand Up @@ -779,15 +733,11 @@ void main_driver(const char* argv)
ExtractSlice(structFactPrimMF, primFlattened, geom, project_dir, slicepoint, 0, structVarsPrim);
ExtractSlice(structFactConsMF, consFlattened, geom, project_dir, slicepoint, 0, structVarsCons);
}
// we rotate this flattened MultiFab to have normal in the z-direction since
// our structure factor class assumes this for flattened
MultiFab primFlattenedRot = RotateFlattenedMF(primFlattened);
primFlattenedRotMaster.ParallelCopy(primFlattenedRot,0,0,structVarsPrim);
structFactPrimFlattened.FortStructure(primFlattenedRotMaster);

MultiFab consFlattenedRot = RotateFlattenedMF(consFlattened);
consFlattenedRotMaster.ParallelCopy(consFlattenedRot,0,0,structVarsCons);
structFactConsFlattened.FortStructure(consFlattenedRotMaster);
primFlattenedMaster.ParallelCopy(primFlattened,0,0,structVarsPrim);
structFactPrimFlattened.FortStructure(primFlattenedMaster);

consFlattenedMaster.ParallelCopy(consFlattened,0,0,structVarsCons);
structFactConsFlattened.FortStructure(consFlattenedMaster);
}

// timer
Expand Down
Loading

0 comments on commit 45b79e3

Please sign in to comment.