Skip to content

Commit

Permalink
Merge pull request #180 from AMReX-FHD/structfact_fixes
Browse files Browse the repository at this point in the history
Structure Factor Fixes
  • Loading branch information
ajnonaka authored Jan 29, 2025
2 parents 3a7d8a6 + 05e6a23 commit 95a94eb
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 161 deletions.
2 changes: 1 addition & 1 deletion exec/DSMC/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ void main_driver(const char* argv)
writePlotFile(cuInst,cuMeans,cuVars,primInst,primMeans,primVars,
coVars,spatialCross1D,particles,geom,time,ncross,istep);

structFactPrim.WritePlotFile(istep,time,geom,"plt_SF_prim");
structFactPrim.WritePlotFile(istep,time,"plt_SF_prim");
}

if ((n_steps_skip > 0 && istep == n_steps_skip) || (n_steps_skip < 0 && istep%n_steps_skip == 0) ) {
Expand Down
2 changes: 1 addition & 1 deletion exec/DSMC_granular/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ void main_driver(const char* argv)
struct_fact_int > 0 && plot_int > 0 &&
istep%plot_int == 0)
{
structFactPrim.WritePlotFile(istep,time,geom,"plt_SF_prim");
structFactPrim.WritePlotFile(istep,time,"plt_SF_prim");
}

//////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions exec/cellbdytest_new/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,8 +1819,8 @@ void main_driver(const char* argv)

// plot structure factor on plot_int
if (istep%plot_int == 0) {
structFact_charge.WritePlotFile(istep,time,geomP,"plt_SF_charge");
structFact_vel .WritePlotFile(istep,time,geom ,"plt_SF_vel");
structFact_charge.WritePlotFile(istep,time,"plt_SF_charge");
structFact_vel .WritePlotFile(istep,time,"plt_SF_vel");
}
}

Expand Down
33 changes: 5 additions & 28 deletions exec/hydro/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ void main_driver(const char* argv)

StructFact structFactFlattened;

Geometry geom_flat;

if(project_dir >= 0){
MultiFab Flattened; // flattened multifab defined below

Expand All @@ -364,30 +362,9 @@ void main_driver(const char* argv)
} else {
ExtractSlice(structFactMF, Flattened, project_dir, slicepoint, 0, 1);
}

BoxArray ba_flat = Flattened.boxArray();
const DistributionMapping& dmap_flat = Flattened.DistributionMap();
{
Box domain_flat = ba_flat.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());
}

structFactFlattened.define(ba_flat,dmap_flat,var_names,var_scaling);
}
Expand Down Expand Up @@ -445,9 +422,9 @@ void main_driver(const char* argv)
if (plot_int > 0) {
WritePlotFile(0,time,geom,umac,pres);
if (n_steps_skip == 0 && struct_fact_int > 0) {
structFact.WritePlotFile(0,0.,geom,"plt_SF");
structFact.WritePlotFile(0,0.,"plt_SF");
if(project_dir >= 0) {
structFactFlattened.WritePlotFile(0,time,geom_flat,"plt_SF_Flattened");
structFactFlattened.WritePlotFile(0,time,"plt_SF_Flattened");
}
}
}
Expand Down Expand Up @@ -547,9 +524,9 @@ void main_driver(const char* argv)

// write out structure factor to plotfile
if (step > n_steps_skip && struct_fact_int > 0) {
structFact.WritePlotFile(step,time,geom,"plt_SF");
structFact.WritePlotFile(step,time,"plt_SF");
if(project_dir >= 0) {
structFactFlattened.WritePlotFile(step,time,geom_flat,"plt_SF_Flattened");
structFactFlattened.WritePlotFile(step,time,"plt_SF_Flattened");
}
}

Expand Down
4 changes: 2 additions & 2 deletions exec/immersedIons/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1589,8 +1589,8 @@ void main_driver(const char* argv)

// plot structure factor on plot_int
if (istep%plot_int == 0) {
structFact_charge.WritePlotFile(istep,time,geomP,"plt_SF_charge");
structFact_vel .WritePlotFile(istep,time,geom ,"plt_SF_vel");
structFact_charge.WritePlotFile(istep,time,"plt_SF_charge");
structFact_vel .WritePlotFile(istep,time,"plt_SF_vel");
}
}

Expand Down
4 changes: 2 additions & 2 deletions exec/multispec/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ void main_driver(const char* argv)
if (plot_int > 0) {
WritePlotFile(0,0.,geom,umac,rhotot_old,rho_old,pi,charge_old,Epot);
if (n_steps_skip == 0 && struct_fact_int > 0) {
structFact.WritePlotFile(0,0.,geom,"plt_SF");
structFact.WritePlotFile(0,0.,"plt_SF");
}
}

Expand Down Expand Up @@ -593,7 +593,7 @@ void main_driver(const char* argv)
if (plot_int > 0 && istep%plot_int == 0) {
WritePlotFile(istep,time,geom,umac,rhotot_new,rho_new,pi,charge_new,Epot);
if (istep > n_steps_skip && struct_fact_int > 0) {
structFact.WritePlotFile(istep,time,geom,"plt_SF");
structFact.WritePlotFile(istep,time,"plt_SF");
}
}

Expand Down
2 changes: 1 addition & 1 deletion exec/structFactTest/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void main_driver(const char* argv)

structFact.FortStructure(struct_cc);

structFact.WritePlotFile(0,0.,geom,"plt_SF");
structFact.WritePlotFile(0,0.,"plt_SF");

// Call the timer again and compute the maximum difference between the start time
// and stop time over all processors
Expand Down
6 changes: 3 additions & 3 deletions src_MFsurfchem/MFsurfchem_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void init_surfcov(MultiFab& surfcov, const amrex::Geometry& geom)

amrex::ParallelForRNG(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k, RandomEngine const& engine) noexcept
{
if (k==0) {
if ( (project_dir == 0 && i == 0) || (project_dir == 1 && j == 0) || (project_dir == 2 && k == 0) ) {
if (stoch_surfcov0==1) {
amrex::Real Ntot = rint(surf_site_num_dens*dx[0]*dx[1]); // total number of reactive sites
GpuArray<int,MAX_SPECIES> Nocc;
Expand Down Expand Up @@ -144,7 +144,7 @@ void sample_MFsurfchem(MultiFab& cu, MultiFab& prim, MultiFab& surfcov, MultiFab

amrex::ParallelForRNG(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k, RandomEngine const& engine) noexcept
{
if (k==0) {
if ( (project_dir == 0 && i == 0) || (project_dir == 1 && j == 0) || (project_dir == 2 && k == 0) ) {
amrex::Real sumtheta = 0.;
for (int m=0;m<n_ads_spec;m++) {
sumtheta += surfcov_arr(i,j,k,m);
Expand Down Expand Up @@ -198,7 +198,7 @@ void update_MFsurfchem(MultiFab& cu, MultiFab& prim, MultiFab& surfcov, MultiFab
amrex::Real Ntot = surf_site_num_dens*dx[0]*dx[1]; // total number of reactive sites
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
if (k==0) {
if ( (project_dir == 0 && i == 0) || (project_dir == 1 && j == 0) || (project_dir == 2 && k == 0) ) {

amrex::Real T_inst = prim_arr(i,j,k,4);

Expand Down
5 changes: 3 additions & 2 deletions src_analysis/StructFact.H
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class StructFact {
// Define vector of unique selected variables
amrex::Vector< int > var_u;

Geometry geom_sf;

public:

// Vector containing running sums of real and imaginary components
Expand Down Expand Up @@ -86,8 +88,7 @@ public:
amrex::MultiFab&,
bool unpack=true);

void WritePlotFile(const int, const amrex::Real, const amrex::Geometry&,
std::string, const int& zero_avg=1);
void WritePlotFile(const int, const amrex::Real, std::string, const int& zero_avg=1);

void Finalize(amrex::MultiFab&, amrex::MultiFab&,
const int& zero_avg=1);
Expand Down
36 changes: 33 additions & 3 deletions src_analysis/StructFact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,36 @@ void StructFact::define(const BoxArray& ba_in,
cov_names[cnt] = x;
cnt++;
}


Box domain = ba_in.minimalBox();

Vector<Real> kspace_lo(AMREX_SPACEDIM);
Vector<Real> kspace_hi(AMREX_SPACEDIM);

for (int d=0; d<AMREX_SPACEDIM; ++d) {

if (domain.length(d) % 2 == 0) {
// even number of cells
kspace_lo[d] = -domain.length(d) / 2. - 0.5;
kspace_hi[d] = domain.length(d) / 2. - 0.5;
} else {
// odd number of cells
kspace_lo[d] = -domain.length(d) / 2.;
kspace_hi[d] = domain.length(d) / 2.;
}
}

RealBox kspace({AMREX_D_DECL(kspace_lo[0],kspace_lo[1],kspace_lo[2])},
{AMREX_D_DECL(kspace_hi[0],kspace_hi[1],kspace_hi[2])});

// required only to define geom object
Vector<int> is_periodic(AMREX_SPACEDIM,1);

geom_sf.define(domain,&kspace,CoordSys::cartesian,is_periodic.data());



}

void StructFact::FortStructure(const MultiFab& variables,
Expand Down Expand Up @@ -505,7 +535,7 @@ void StructFact::ComputeFFT(const MultiFab& variables,
}
}

void StructFact::WritePlotFile(const int step, const Real time, const Geometry& geom,
void StructFact::WritePlotFile(const int step, const Real time,
std::string plotfile_base,
const int& zero_avg) {

Expand Down Expand Up @@ -546,7 +576,7 @@ void StructFact::WritePlotFile(const int step, const Real time, const Geometry&
MultiFab::Copy(plotfile, cov_mag, 0, 0, NCOV, 0); // copy structure factor into plotfile

// write a plotfile
WriteSingleLevelPlotfile(plotfilename1,plotfile,varNames,geom,time,step);
WriteSingleLevelPlotfile(plotfilename1,plotfile,varNames,geom_sf,time,step);

//////////////////////////////////////////////////////////////////////////////////
// Write out real and imaginary components of structure factor to plot file
Expand Down Expand Up @@ -579,7 +609,7 @@ void StructFact::WritePlotFile(const int step, const Real time, const Geometry&
MultiFab::Copy(plotfile,cov_imag_temp,0,NCOV,NCOV,0);

// write a plotfile
WriteSingleLevelPlotfile(plotfilename2,plotfile,varNames,geom,time,step);
WriteSingleLevelPlotfile(plotfilename2,plotfile,varNames,geom_sf,time,step);
}

void StructFact::Finalize(MultiFab& cov_real_in, MultiFab& cov_imag_in,
Expand Down
32 changes: 4 additions & 28 deletions src_compressible/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,6 @@ void main_driver(const char* argv)

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

Geometry geom_flat;

if(project_dir >= 0){
MultiFab Flattened; // flattened multifab defined below

Expand All @@ -482,28 +480,6 @@ void main_driver(const char* argv)
}
BoxArray ba_flat = Flattened.boxArray();
const DistributionMapping& dmap_flat = Flattened.DistributionMap();
{
Box domain_flat = ba_flat.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);
structFactConsFlattened.define(ba_flat,dmap_flat,cons_var_names,var_scaling_cons);
Expand Down Expand Up @@ -747,13 +723,13 @@ void main_driver(const char* argv)

Print() << "HERE1\n";

structFactPrim.WritePlotFile(step,time,geom,"plt_SF_prim");
structFactPrim.WritePlotFile(step,time,"plt_SF_prim");

Print() << "HERE2\n";
structFactCons.WritePlotFile(step,time,geom,"plt_SF_cons");
structFactCons.WritePlotFile(step,time,"plt_SF_cons");
if(project_dir >= 0) {
structFactPrimFlattened.WritePlotFile(step,time,geom_flat,"plt_SF_prim_Flattened");
structFactConsFlattened.WritePlotFile(step,time,geom_flat,"plt_SF_cons_Flattened");
structFactPrimFlattened.WritePlotFile(step,time,"plt_SF_prim_Flattened");
structFactConsFlattened.WritePlotFile(step,time,"plt_SF_cons_Flattened");
}

// timer
Expand Down
Loading

0 comments on commit 95a94eb

Please sign in to comment.