int makeLayout(DisjointBoxLayout& a_dbl, const Box& a_domain) { ParmParse pp; int eekflag= 0; int ipieces; ipieces = Max(ipieces, 1); int maxsize; pp.get("maxboxsize",maxsize); Vector<Box> vbox(1, a_domain); domainSplit(a_domain, vbox, maxsize); if (eekflag != 0) { pout() << "problem in domainsplit" << endl; return eekflag; } Vector<int> procAssign; eekflag = LoadBalance(procAssign,vbox); if (eekflag != 0) { pout() << "problem in loadbalance" << endl; return eekflag; } a_dbl.define(vbox, procAssign); return eekflag; }
int makeLayout(DisjointBoxLayout& a_dbl, const Box& a_domainFine) { //set up mesh refine object ParmParse pp; int eekflag= 0; int maxsize; pp.get("maxboxsize",maxsize); int bufferSize = 1; int blockFactor = 2; Real fillrat = 0.75; Box domainCoar = coarsen(a_domainFine, 2); Vector<int> refRat(2,2); BRMeshRefine meshRefObj(domainCoar, refRat, fillrat, blockFactor, bufferSize, maxsize); Vector<Vector<Box> > oldMeshes(2); oldMeshes[0] = Vector<Box>(1, domainCoar); oldMeshes[1] = Vector<Box>(1, a_domainFine); //set up coarse tags int nc = domainCoar.size(0); int nmi = nc/2;//16 int nqu = nc/4;//8 int ntf = (nc*3)/4; //24 int nte = (nc*3)/8; //12 int nfe = (nc*5)/8; //20 #if (CH_SPACEDIM ==2) Box boxf1(IntVect(0, nqu), IntVect(nmi-1,ntf-1)); Box boxf2(IntVect(nmi,nte), IntVect(ntf-1,nfe-1)); Box boxf3(IntVect(nqu,0 ), IntVect(nfe-1,nqu-1)); Box boxf4(IntVect(nfe,nqu), IntVect(nc -1,nte-1)); #else Box boxf1(IntVect(0, nqu,nqu), IntVect(nmi-1,ntf-1,ntf-1)); Box boxf2(IntVect(nmi,nte,nte), IntVect(ntf-1,nfe-1,nfe-1)); Box boxf3(IntVect(nqu,0,0 ), IntVect(nfe-1,nqu-1,nqu-1)); Box boxf4(IntVect(nfe,nqu,nqu), IntVect(nc -1,nte-1,nte-1)); #endif IntVectSet tags; tags |= boxf1; tags |= boxf2; tags |= boxf3; tags |= boxf4; int baseLevel = 0; int topLevel = 0; Vector<Vector<Box> > newMeshes; meshRefObj.regrid(newMeshes, tags, baseLevel, topLevel, oldMeshes); const Vector<Box>& vbox = newMeshes[1]; Vector<int> procAssign; eekflag = LoadBalance(procAssign,vbox); if (eekflag != 0) return eekflag; a_dbl.define(vbox, procAssign); return eekflag; }
int makeLayoutPart(DisjointBoxLayout& a_dbl, const Box& a_domainCoarsest) { // Vector<int> vecRefRat(2, 2); ParmParse pp; int eekflag= 0; int blockFactor, bufferSize, maxSize; Real fillRat; pp.get("block_factor", blockFactor); pp.get("buffer_size", bufferSize); pp.get("maxboxsize", maxSize); pp.get("fill_ratio", fillRat); int nlevels = 2; Vector<int> vecRefRat(nlevels); pp.getarr("ref_ratio", vecRefRat,0,nlevels); BRMeshRefine mesher(a_domainCoarsest, vecRefRat, fillRat, blockFactor, bufferSize, maxSize); int topLevel = 0; int baseLevel = 0; //tags at base level IntVectSet tags; eekflag = makeTags(tags, a_domainCoarsest); if (eekflag < 0) return eekflag; Vector<Vector<Box> > oldMeshes(nlevels); oldMeshes[0] = Vector<Box>(1, a_domainCoarsest); Box finerDomain = a_domainCoarsest; for (int ilev = 1; ilev < nlevels; ilev++) { finerDomain.refine(vecRefRat[ilev]); oldMeshes[ilev] = Vector<Box>(1, finerDomain); } Vector<Vector<Box> > newMeshes; mesher.regrid(newMeshes, tags, baseLevel, topLevel, oldMeshes); Vector<int> procAssign; eekflag = LoadBalance(procAssign, newMeshes[1]); if (eekflag != 0) return eekflag; a_dbl.define(newMeshes[1], procAssign); int iverbose; pp.get("verbose", iverbose); if (iverbose == 1) { pout() << "the grids coarser domain= " << a_domainCoarsest << " = " << a_dbl << endl; } return eekflag; }
int makeLayout(DisjointBoxLayout& a_dbl, const Box& a_domainFine) { //set up mesh refine object ParmParse pp; int eekflag= 0; int maxsize; pp.get("maxboxsize",maxsize); int bufferSize = 2; int blockFactor = 8; Real fillrat = 0.7; Box domainCoar = coarsen(a_domainFine, 2); Vector<int> refRat(2,2); BRMeshRefine meshRefObj(domainCoar, refRat, fillrat, blockFactor, bufferSize, maxsize); Vector<Vector<Box> > oldMeshes(2); oldMeshes[0] = Vector<Box>(1, domainCoar); oldMeshes[1] = Vector<Box>(1, a_domainFine); //set up coarse tags int nc = domainCoar.size(0); Box halfBox = domainCoar; halfBox.growHi(0, -nc/2); IntVectSet tags(halfBox); int baseLevel = 0; int topLevel = 0; Vector<Vector<Box> > newMeshes; meshRefObj.regrid(newMeshes, tags, baseLevel, topLevel, oldMeshes); const Vector<Box>& vbox = newMeshes[1]; Vector<int> procAssign; eekflag = LoadBalance(procAssign,vbox); if (eekflag != 0) return eekflag; a_dbl.define(vbox, procAssign); return eekflag; }
int main(int argc ,char *argv[] ) { #ifdef CH_MPI MPI_Init(&argc, &argv); #endif int status = 0; // Make this test pass automatically if DIM > 3, to avoid FAIL message. if (SpaceDim <= 3) { parseTestOptions(argc, argv); // establish periodic domain -- first multiply periodic in all directions int baseDomainSize = 8; int numGhost = 2; IntVect ghostVect(numGhost*IntVect::Unit); Box baseDomBox(IntVect::Zero, (baseDomainSize-1)*IntVect::Unit); ProblemDomain baseDomain(baseDomBox); // set periodic in all directions for (int dir=0; dir<SpaceDim; dir++) { baseDomain.setPeriodic(dir, true); } { // QuadCFInterp test int nRef = 2; ProblemDomain fineDomain(baseDomain); fineDomain.refine(nRef); const Box domainBox = baseDomain.domainBox(); Vector<Box> crseBoxes(1, domainBox); Vector<int> crseProcAssign(1,0); DisjointBoxLayout crseGrids(crseBoxes, crseProcAssign, baseDomain); // note the lack of ghost cells on the base level LevelData<FArrayBox> crseData(crseGrids, 1, IntVect::Zero); Real dxCrse = 1.0/(baseDomainSize); Real dxFine = dxCrse/nRef; initData(crseData, dxCrse); #if (CH_SPACEDIM == 1) Vector<Box> fineBoxes(2); Vector<int> fineProcAssign(2); fineBoxes[0] = Box(IntVect::Zero, 5*IntVect::Unit); fineBoxes[1] = Box(IntVect(D_DECL6(6,10,10,6,10,0)), IntVect(D_DECL6(11,15,15,11,15,15))); #else // try multiple boxes for fine level Vector<Box> fineBoxes(4); Vector<int> fineProcAssign(4); fineBoxes[0] = Box(IntVect::Zero, 9*IntVect::Unit); fineBoxes[1] = Box(IntVect(D_DECL6(6,10,10,6,10,0)), IntVect(D_DECL6(11,15,15,11,15,15))); // this box should fail the disjointness test //fineBoxes[1] = Box(IntVect(D_DECL(7,10,10)), 17*IntVect::Unit); fineBoxes[2] = Box(IntVect(D_DECL6(12,2,0,12,2,0)), IntVect(D_DECL6(15,7,7,15,7,7))); fineBoxes[3] = Box(IntVect(D_DECL6(12,12,0,12,12,0)), 15*IntVect::Unit); #endif int loadbalancestatus = LoadBalance(fineProcAssign, fineBoxes); CH_assert (loadbalancestatus == 0); DisjointBoxLayout fineGrids; fineGrids.define(fineBoxes, fineProcAssign, fineDomain); LevelData<FArrayBox> fineData(fineGrids, 1, ghostVect); // set these to a bogus value to start with DataIterator fineDit = fineData.dataIterator(); for (fineDit.begin(); fineDit.ok(); ++fineDit) { fineData[fineDit()].setVal(1.0e9); } FineInterp interpolator(fineGrids, 1, nRef, fineDomain); // turn on fine-data averaging even though it's unnecessary // since this is a test (so we'd like to know if it's broken) bool averageFineData = true; interpolator.interpToFine(fineData, crseData, averageFineData); // now fill in ghost cells QuadCFInterp filler(fineGrids, &crseGrids, dxFine, nRef, 1, fineDomain); filler.coarseFineInterp(fineData, crseData); } { // fineInterp near boundary test int numLev = 3; Vector<int> nRefVect(numLev); nRefVect[0] = 4; nRefVect[1] = 2; nRefVect[2] = -1; Vector<Real> dxVect(numLev); Vector<ProblemDomain> levelDomains(numLev); levelDomains[0] = Box(IntVect::Zero, 15*IntVect::Unit); dxVect[0] = 1.0/(levelDomains[0].domainBox().size(0)); for (int lev=1; lev<numLev; lev++) { levelDomains[lev] = levelDomains[lev-1]; levelDomains[lev].refine(nRefVect[lev-1]); dxVect[lev] = dxVect[lev-1]/nRefVect[lev-1]; } Vector<DisjointBoxLayout> levelGrids(numLev); Vector<LevelData<FArrayBox>* > levelData(numLev, NULL); const Box domainBox = levelDomains[0].domainBox(); Vector<Box> crseBoxes(1, domainBox); Vector<int> crseProcAssign(1,0); DisjointBoxLayout level0Grids(crseBoxes, crseProcAssign, levelDomains[0]); levelGrids[0] = level0Grids; // note the lack of ghost cells on the base level levelData[0] = new LevelData<FArrayBox>(level0Grids, 1, IntVect::Zero); initData(*levelData[0], dxVect[0]); Vector<Box> level1Boxes(1, levelDomains[1].domainBox()); int loadbalancestatus = LoadBalance(crseProcAssign, level1Boxes); CH_assert (loadbalancestatus == 0); IntVect newGhostVect(4*IntVect::Unit); DisjointBoxLayout fineGrids; fineGrids.define(level1Boxes, crseProcAssign, levelDomains[1]); levelGrids[1] = fineGrids; levelData[1] = new LevelData<FArrayBox>(fineGrids, 1, newGhostVect); Vector<Box> level2Boxes(1); //level2Boxes[0] = Box(20*IntVect::Unit, 119*IntVect::Unit); level2Boxes[0] = Box(100*IntVect::Unit, 127*IntVect::Unit); DisjointBoxLayout finestGrids(level2Boxes, crseProcAssign, levelDomains[2]); levelGrids[2] = finestGrids; levelData[2] = new LevelData<FArrayBox>(finestGrids, 1, newGhostVect); for (int lev=1; lev<numLev; lev++) { LevelData<FArrayBox>& fineData = *levelData[lev]; LevelData<FArrayBox>& crseData = *levelData[lev-1]; // set these to a bogus value to start with DataIterator fineDit = fineData.dataIterator(); for (fineDit.begin(); fineDit.ok(); ++fineDit) { fineData[fineDit()].setVal(1.0e9); } FineInterp interpolator(levelGrids[lev], 1, nRefVect[lev-1], levelDomains[lev]); // turn on fine-data averaging even though it's unnecessary // since this is a test (so we'd like to know if it's broken) bool averageFineData = true; interpolator.interpToFine(fineData, crseData, averageFineData); pout() << "grids at level = " << lev << endl; dumpDBL(&levelGrids[lev]); pout() << "grids at level = " << lev-1 << endl; dumpDBL(&levelGrids[lev-1]); // now fill in ghost cells QuadCFInterp filler(levelGrids[lev], &levelGrids[lev-1], dxVect[lev], nRefVect[lev-1], 1, levelDomains[lev]); filler.coarseFineInterp(fineData, crseData); } #ifdef CH_USE_HDF5 // dump data if (writePlots) { string fname = "interp.hdf5"; Vector<string> varNames(1,"phi"); Real dt = 0.0; Real time= 0.0; WriteAMRHierarchyHDF5(fname, levelGrids, levelData, varNames, levelDomains[0].domainBox(), dxVect[0], dt, time, nRefVect, numLev); } #endif // clean up memory for (int lev=0; lev<levelData.size(); lev++) { if (levelData[lev] != NULL) { delete levelData[lev]; levelData[lev] = NULL; } } } // now test partially periodic case (also coarsen back to original domain // no such thing as "partially periodic" for 1D; for 1D, test moving // fine-grid boxes from low-end of domain to high-end of domain { baseDomain.setPeriodic(0,false); // try similar tests to the previous case int nRef = 2; ProblemDomain fineDomain(baseDomain); fineDomain.refine(nRef); const Box domainBox = baseDomain.domainBox(); Vector<Box> crseBoxes(1, domainBox); Vector<int> crseProcAssign(1,0); DisjointBoxLayout crseGrids(crseBoxes, crseProcAssign, baseDomain); // note the lack of ghost cells on the base level LevelData<FArrayBox> crseData(crseGrids, 1, IntVect::Zero); Real dxCrse = 1.0/(baseDomainSize); Real dxFine = dxCrse/nRef; initData(crseData, dxCrse); #if (CH_SPACEDIM == 1) Vector<Box> fineBoxes(2); Vector<int> fineProcAssign(2); fineBoxes[0] = Box(12*IntVect::Unit, 15*IntVect::Unit); fineBoxes[1] = Box(IntVect(D_DECL6(6,10,10,6,10,10)), IntVect(D_DECL6(11,15,15,11,15,15))); #else // try multiple boxes for fine level // note grids are different in this case to allow for all periodic checking Vector<Box> fineBoxes(3); Vector<int> fineProcAssign(3); fineBoxes[0] = Box(IntVect::Zero, 9*IntVect::Unit); fineBoxes[1] = Box(IntVect(D_DECL6(6,10,10,6,10,10)), IntVect(D_DECL6(11,15,15,11,15,15))); // this box should fail the disjointness test //fineBoxes[1] = Box(IntVect(D_DECL(7,10,10)), 17*IntVect::Unit); fineBoxes[2] = Box(IntVect(D_DECL6(12,2,0,12,2,0)), IntVect(D_DECL6(15,7,7,15,7,7))); //fineBoxes[3] = Box(IntVect(D_DECL(12,12,0)), 15*IntVect::Unit); #endif int loadbalancestatus = LoadBalance(fineProcAssign, fineBoxes); CH_assert (loadbalancestatus == 0); DisjointBoxLayout fineGrids; fineGrids.define(fineBoxes, fineProcAssign, fineDomain); LevelData<FArrayBox> fineData(fineGrids, 1, ghostVect); // set these to a bogus value to start with DataIterator fineDit = fineData.dataIterator(); for (fineDit.begin(); fineDit.ok(); ++fineDit) { fineData[fineDit()].setVal(1.0e9); } FineInterp interpolator(fineGrids, 1, nRef, fineDomain); // turn on fine-data averaging even though it's unnecessary // since this is a test (so we'd like to know if it's broken) bool averageFineData = true; interpolator.interpToFine(fineData, crseData, averageFineData); // now fill in first layer of ghost cells QuadCFInterp filler(fineGrids, &crseGrids, dxFine, nRef, 1, fineDomain); filler.coarseFineInterp(fineData, crseData); // now fill in remaining ghost cell with extrapolation Interval extrapInterval(1,1); ExtrapFillPatch extrapFiller(fineGrids, fineDomain, extrapInterval); for (int dir=0; dir<SpaceDim; dir++) { extrapFiller.fillExtrap(fineData,dir,0,1); } fineData.exchange(fineData.interval()); } } // if (SpaceDim <= 3) pout() << indent << pgmname << ": " << ( (status == 0) ? "passed all tests" : "failed at least one test,") << endl; #ifdef CH_MPI MPI_Finalize(); #endif return status ; }
int makeLayouts(DisjointBoxLayout& a_dblCoar, DisjointBoxLayout& a_dblFine, const Box& a_domainCoar, const Box& a_domainFine) { //set up mesh refine object int eekflag= 0; Vector<Box> vboxCoar; Vector<Box> vboxFine; #if 1 ParmParse pp; int maxsize; pp.get("maxboxsize",maxsize); int bufferSize = 1; int blockFactor = 2; Real fillrat = 0.75; Vector<int> refRat(2,2); BRMeshRefine meshRefObj(a_domainCoar, refRat, fillrat, blockFactor, bufferSize, maxsize); Vector<Vector<Box> > oldMeshes(2); oldMeshes[0] = Vector<Box>(1, a_domainCoar); oldMeshes[1] = Vector<Box>(1, a_domainFine); //set up coarse tags int nc = a_domainCoar.size(0); int nmi = nc/2;//16 int nqu = nc/4;//8 int ntf = (nc*3)/4; //24 int nte = (nc*3)/8; //12 int nfe = (nc*5)/8; //20 #if (CH_SPACEDIM ==2) Box boxf1(IntVect(0, nqu), IntVect(nmi-1,ntf-1)); Box boxf2(IntVect(nmi,nte), IntVect(ntf-1,nfe-1)); Box boxf3(IntVect(nqu,0 ), IntVect(nfe-1,nqu-1)); Box boxf4(IntVect(nfe,nqu), IntVect(nc -1,nte-1)); // Box boxf5(IntVect(nqu,nqu), IntVect(ntf-1,ntf-1)); #else Box boxf1(IntVect(0, nqu,nqu), IntVect(nmi-1,ntf-1,ntf-1)); Box boxf2(IntVect(nmi,nte,nte), IntVect(ntf-1,nfe-1,nfe-1)); Box boxf3(IntVect(nqu,0,0 ), IntVect(nfe-1,nqu-1,nqu-1)); Box boxf4(IntVect(nfe,nqu,nqu), IntVect(nc -1,nte-1,nte-1)); // Box boxf5(IntVect(nqu,nqu), IntVect(ntf-1,ntf-1)) #endif IntVectSet tags; tags |= boxf1; tags |= boxf2; tags |= boxf3; tags |= boxf4; // tags |= boxf5; int baseLevel = 0; int topLevel = 0; Vector<Vector<Box> > newMeshes; meshRefObj.regrid(newMeshes, tags, baseLevel, topLevel, oldMeshes); vboxCoar = newMeshes[0]; vboxFine = newMeshes[1]; #else vboxCoar = Vector<Box>(1, a_domainCoar); Box shrunkFine = a_domainFine; int nc = Max(a_domainCoar.size(0)/4, 2); shrunkFine.grow(-nc); vboxFine = Vector<Box>(1, shrunkFine); #endif Vector<int> procAssignFine, procAssignCoar; eekflag = LoadBalance(procAssignFine,vboxFine); if (eekflag != 0) return eekflag; eekflag = LoadBalance(procAssignCoar,vboxCoar); if (eekflag != 0) return eekflag; a_dblFine.define(vboxFine, procAssignFine); a_dblCoar.define(vboxCoar, procAssignCoar); return eekflag; }
int EBAMRTestCommon:: makeHalfLayouts(DisjointBoxLayout& a_gridsFine, EBISLayout& a_ebislFine, DisjointBoxLayout& a_gridsCoar, EBISLayout& a_ebislCoar, const Box& a_domainFine, const Box& a_domainCoar, int a_refrat, int a_halfDir ) { //set up mesh refine object ParmParse pp; int eekflag= 0; int maxsize; pp.get("maxboxsize",maxsize); int bufferSize = 2; int blockFactor = 8; Real fillrat = 0.7; Vector<int> refRat(2,2); BRMeshRefine meshRefObj(a_domainCoar, refRat, fillrat, blockFactor, bufferSize, maxsize); Vector<Vector<Box> > oldMeshes(2); oldMeshes[0] = Vector<Box>(1, a_domainCoar); oldMeshes[1] = Vector<Box>(1, a_domainFine); //set up coarse tags int nc = a_domainCoar.size(a_halfDir); Box halfBox = a_domainCoar; halfBox.growHi(a_halfDir, -nc/2); IntVectSet tags(halfBox); int baseLevel = 0; int topLevel = 0; Vector<Vector<Box> > newMeshes; meshRefObj.regrid(newMeshes, tags, baseLevel, topLevel, oldMeshes); const Vector<Box>& vboxFine = newMeshes[1]; Vector<int> procAssign; eekflag = LoadBalance(procAssign,vboxFine); if (eekflag != 0) return eekflag; a_gridsFine.define(vboxFine, procAssign); //make the coarse grids completely cover the domain Vector<Box> vboxCoar; domainSplit(a_domainCoar, vboxCoar, maxsize); eekflag = LoadBalance(procAssign,vboxCoar); a_gridsCoar.define(vboxCoar, procAssign); ///create ebislayout int nghost = 4; eekflag = makeEBISL(a_ebislFine, a_gridsFine, a_domainFine, nghost); if (eekflag != 0) return eekflag; eekflag = makeEBISL(a_ebislCoar, a_gridsCoar, a_domainCoar, nghost); if (eekflag != 0) return eekflag; return eekflag; }