Commit 590057d6 authored by frey_m's avatar frey_m
Browse files

AMR test case: Try to initialize first AmrObject and then Particles.

modified:   ippl/test/AMR/AmrOpal.cpp
modified:   ippl/test/AMR/AmrOpal.h
modified:   ippl/test/AMR/helper_functions.h
modified:   ippl/test/AMR/testGaussian.cpp
parent afc0784e
......@@ -29,6 +29,36 @@ AmrOpal::AmrOpal(const RealBox* rb, int max_level_in, const Array<int>& n_cell_i
// bunch_m->myUpdate();
}
AmrOpal::AmrOpal(const RealBox* rb, int max_level_in, const Array<int>& n_cell_in, int coord)
: AmrCore(rb, max_level_in, n_cell_in, coord)
{
finest_level = 0;
const BoxArray& ba = MakeBaseGrids();
DistributionMapping dm(ba, ParallelDescriptor::NProcs());
nPartPerCell_m.resize(max_level_in + 1);//, PArrayManage);
chargeOnGrid_m.resize(max_level_in + 1);
MakeNewLevel(0, 0.0, ba, dm);
// #ifdef UNIQUE_PTR
// nPartPerCell_m[0] = std::unique_ptr<MultiFab>(new MultiFab(this->boxArray(0), 1, 1, this->DistributionMap(0)));
// nPartPerCell_m[0]->setVal(0.0);
//
// chargeOnGrid_m.resize(max_level_in + 1);
// chargeOnGrid_m[0] = std::unique_ptr<MultiFab>(new MultiFab(this->boxArray(0), 1, 0, this->DistributionMap(0)));
// #else
// nPartPerCell_m.set(0, new MultiFab(this->boxArray(0), 1, 1, this->DistributionMap(0)));
// nPartPerCell_m[0].setVal(0.0);
//
// chargeOnGrid_m.resize(max_level_in + 1);
// chargeOnGrid_m.set(0, new MultiFab(this->boxArray(0), 1, 0, this->DistributionMap(0)));
// #endif
}
AmrOpal::~AmrOpal() { }
......
......@@ -37,10 +37,20 @@ public:
* @param rb is the physical domain
* @param max_level_in is the max. number of allowed AMR levels
* @param n_cell_in is the number of grid cells at the coarsest level
* @param coord is the coordinate system (0: cartesian)
* @param bunch is the particle bunch
*/
AmrOpal(const RealBox* rb, int max_level_in, const Array<int>& n_cell_in, int coord, PartBunchBase* bunch);
/*!
* Create an AMR object.
* @param rb is the physical domain
* @param max_level_in is the max. number of allowed AMR levels
* @param n_cell_in is the number of grid cells at the coarsest level
* @param coord is the coordinate system (0: cartesian)
*/
AmrOpal(const RealBox* rb, int max_level_in, const Array<int>& n_cell_in, int coord);
virtual ~AmrOpal(); ///< does nothing
void initBaseLevel(); ///< defines BoxArray, DistributionMapping of level 0
......@@ -74,6 +84,10 @@ public:
void ClearLevel(int lev);
void setBunch(AmrPartBunch* bunch) {
bunch_m = bunch;
}
/*!
* Print the number of particles per cell (minimum and maximum)
*/
......
......@@ -241,6 +241,39 @@ inline void init(RealBox& domain,
}
}
/*!
* @param domain is the physical domain
* @param nr are the number of grid points in each dimension
* @param lower is the physical lower bound of the domain
* @param upper is the physical upper bound of the domain
*/
inline void init(RealBox& domain,
const Vektor<size_t, 3>& nr,
const std::array<double, BL_SPACEDIM>& lower,
const std::array<double, BL_SPACEDIM>& upper)
{
/*
* nLevels is the number of levels allowed, i.e if nLevels = 1
* we just run single-level
*/
/*
* set up the geometry
*/
IntVect low(0, 0, 0);
IntVect high(nr[0] - 1, nr[1] - 1, nr[2] - 1);
Box bx(low, high);
// box
for (int i = 0; i < BL_SPACEDIM; ++i) {
domain.setLo(i, lower[i]); // m
domain.setHi(i, upper[i]); // m
}
// Dirichlet boundary conditions in all directions
int bc[BL_SPACEDIM] = {0, 0, 0};
}
/*!
* Allocate memory for the solver and initialize
* the grid data to zero.
......
......@@ -140,19 +140,42 @@ void doBoxLib(const Vektor<size_t, 3>& nr, size_t nParticles,
std::array<double, BL_SPACEDIM> upper = {{ 0.5, 0.5, 0.5}}; // m
RealBox domain;
Array<BoxArray> ba;
Array<Geometry> geom;
Array<DistributionMapping> dmap;
Array<int> rr;
// in helper_functions.h
init(domain, ba, dmap, geom, rr, nr, nLevels, maxBoxSize, lower, upper);
init(domain, nr, lower, upper);
/*
* create an Amr object
*/
ParmParse pp("amr");
pp.add("max_grid_size", int(maxBoxSize));
Array<int> error_buf(nLevels, 0);
pp.addarr("n_error_buf", error_buf);
pp.add("grid_eff", 0.95);
Array<int> nCells(3);
for (int i = 0; i < 3; ++i)
nCells[i] = nr[i];
AmrOpal myAmrOpal(&domain, nLevels - 1, nCells, 0 /* cartesian */);
// ========================================================================
// 2. initialize all particles (just single-level)
// ========================================================================
PartBunchBase* bunch = new AmrPartBunch(geom[0], dmap[0], ba[0]);
const Array<BoxArray>& ba = myAmrOpal.boxArray();
const Array<DistributionMapping>& dmap = myAmrOpal.DistributionMap();
const Array<Geometry>& geom = myAmrOpal.Geom();
Array<int> rr(nLevels);
for (int i = 0; i < nLevels; ++i)
rr[i] = 2;
PartBunchBase* bunch = new AmrPartBunch(geom, dmap, ba, rr);
// initialize a particle distribution
......@@ -184,42 +207,28 @@ void doBoxLib(const Vektor<size_t, 3>& nr, size_t nParticles,
<< "Charge per particle: " << bunch->getQM(0) << " C" << endl
<< "Total charge: " << nParticles * bunch->getQM(0) << " C" << endl;
myAmrOpal.setBunch(dynamic_cast<AmrPartBunch*>(bunch));
const Array<Geometry>& geoms = myAmrOpal.Geom();
for (int i = 0; i < nLevels; ++i)
msg << "#Cells per dim of level " << i << " for bunch : "
<< 2.0 * sig / *(geom[i].CellSize()) << endl;
<< 2.0 * sig / *(geoms[i].CellSize()) << endl;
// ========================================================================
// 2. tagging (i.e. create BoxArray's, DistributionMapping's of all
// other levels)
// ========================================================================
/*
* create an Amr object
*/
ParmParse pp("amr");
pp.add("max_grid_size", int(maxBoxSize));
Array<int> error_buf(nLevels, 0);
pp.addarr("n_error_buf", error_buf);
pp.add("grid_eff", 0.95);
Array<int> nCells(3);
for (int i = 0; i < 3; ++i)
nCells[i] = nr[i];
AmrOpal myAmrOpal(&domain, nLevels - 1, nCells, 0 /* cartesian */, bunch);
/*
* do tagging
*/
dynamic_cast<AmrPartBunch*>(bunch)->Define (myAmrOpal.Geom(),
myAmrOpal.DistributionMap(),
myAmrOpal.boxArray(),
rr);
// dynamic_cast<AmrPartBunch*>(bunch)->Define (myAmrOpal.Geom(),
// myAmrOpal.DistributionMap(),
// myAmrOpal.boxArray(),
// rr);
//
//
// ========================================================================
// 3. multi-level redistribute
// ========================================================================
......@@ -236,7 +245,8 @@ void doBoxLib(const Vektor<size_t, 3>& nr, size_t nParticles,
container_t grad_phi;
std::string plotsolve = BoxLib::Concatenate("plt", 0, 4);
doSolve(myAmrOpal, bunch, rhs, phi, grad_phi, geom, rr, nLevels, msg);
doSolve(myAmrOpal, bunch, rhs, phi, grad_phi, geoms, rr, nLevels, msg);
msg << "Total field energy: " << totalFieldEnergy(grad_phi, rr) << endl;
......@@ -255,7 +265,7 @@ void doBoxLib(const Vektor<size_t, 3>& nr, size_t nParticles,
}
writePlotFile(plotsolve, rhs, phi, grad_phi, rr, geom, 0);
writePlotFile(plotsolve, rhs, phi, grad_phi, rr, geoms, 0);
// dynamic_cast<AmrPartBunch*>(bunch)->python_format(0);
}
......@@ -306,8 +316,8 @@ int main(int argc, char *argv[]) {
std::stringstream timefile;
timefile << std::string(argv[0]) << "-timing-cores-"
<< std::setfill('0') << std::setw(6) << Ippl::getNodes()
<< "-threads-1.dat";
<< std::setfill('0') << std::setw(6) << Ippl::getNodes()
<< "-threads-1.dat";
IpplTimings::print(timefile.str());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment