void AmrAdv::RemakeLevel (int lev, Real time, const BoxArray& new_grids, const DistributionMapping& new_dmap) { const int ncomp = phi_new[lev]->nComp(); const int nghost = phi_new[lev]->nGrow(); auto new_state = std::unique_ptr<MultiFab>(new MultiFab(new_grids, ncomp, nghost, new_dmap)); auto old_state = std::unique_ptr<MultiFab>(new MultiFab(new_grids, ncomp, nghost, new_dmap)); FillPatch(lev, time, *new_state, 0, ncomp); SetBoxArray(lev, new_grids); SetDistributionMap(lev, new_dmap); std::swap(new_state, phi_new[lev]); std::swap(old_state, phi_old[lev]); t_new[lev] = time; t_old[lev] = time - 1.e200; if (lev > 0 && do_reflux) { flux_reg[lev] = std::unique_ptr<FluxRegister> (new FluxRegister(grids[lev], refRatio(lev-1), lev, ncomp, dmap[lev])); } }
void AmrAdv::FillPatch (int lev, Real time, MultiFab& mf, int icomp, int ncomp) { if (lev == 0) { PArray<MultiFab> smf; std::vector<Real> stime; GetData(0, time, smf, stime); AmrAdvPhysBC physbc; BoxLib::FillPatchSingleLevel(mf, time, smf, stime, 0, icomp, ncomp, geom[lev], physbc); } else { PArray<MultiFab> cmf, fmf; std::vector<Real> ctime, ftime; GetData(lev-1, time, cmf, ctime); GetData(lev , time, fmf, ftime); AmrAdvPhysBC cphysbc, fphysbc; Interpolater* mapper = &cell_cons_interp; int lo_bc[] = {INT_DIR, INT_DIR, INT_DIR}; // periodic boundaryies int hi_bc[] = {INT_DIR, INT_DIR, INT_DIR}; Array<BCRec> bcs(1, BCRec(lo_bc, hi_bc)); BoxLib::FillPatchTwoLevels(mf, time, cmf, ctime, fmf, ftime, 0, icomp, ncomp, geom[lev-1], geom[lev], cphysbc, fphysbc, refRatio(lev-1), mapper, bcs); } }
void AmrAdv::AverageDownTo (int crse_lev) { BoxLib::average_down(*phi_new[crse_lev+1], *phi_new[crse_lev], geom[crse_lev+1], geom[crse_lev], 0, phi_new[crse_lev]->nComp(), refRatio(crse_lev)); }
void AmrAdv::WritePlotFile () const { const std::string& plotfilename = PlotFileName(istep[0]); const auto& mf = PlotFileMF(); const auto& varnames = PlotFileVarNames(); BoxLib::WriteMultiLevelPlotfile(plotfilename, finest_level+1, mf, varnames, Geom(), t_new[0], istep, refRatio()); }
void AmrAdv::AverageDown () { for (int lev = finest_level-1; lev >= 0; --lev) { BoxLib::average_down(*phi_new[lev+1], *phi_new[lev], geom[lev+1], geom[lev], 0, phi_new[lev]->nComp(), refRatio(lev)); } }
void AmrAdv::MakeNewLevel (int lev, Real time, const BoxArray& new_grids, const DistributionMapping& new_dmap) { const int ncomp = 1; const int nghost = 0; SetBoxArray(lev, new_grids); SetDistributionMap(lev, new_dmap); phi_new[lev] = std::unique_ptr<MultiFab>(new MultiFab(grids[lev], ncomp, nghost, dmap[lev])); phi_old[lev] = std::unique_ptr<MultiFab>(new MultiFab(grids[lev], ncomp, nghost, dmap[lev])); t_new[lev] = time; t_old[lev] = time - 1.e200; if (lev > 0 && do_reflux) { flux_reg[lev] = std::unique_ptr<FluxRegister> (new FluxRegister(grids[lev], refRatio(lev-1), lev, ncomp, dmap[lev])); } }
// --------------------------------------------------------------- // create tags at initial time void AMRNavierStokes::tagCellsInit(IntVectSet& a_tags) { if (s_verbosity >= 3) { pout () << "AMRNavierStokes::tagCellsInit " << m_level << endl; } if (s_specifyInitialGrids) { Vector<Vector<Box> > amrGrids; #ifdef CH_MPI MPI_Barrier(Chombo_MPI::comm); if (procID() == 0) { #endif // read in predefined grids ifstream is(s_initialGridFile.c_str(), ios::in); if (is.fail()) { pout() << "cannot open grids file " << s_initialGridFile << endl; MayDay::Error(); } // format of file -- same as other grid files -- number of // levels, then for each level starting with level 1, // number of grids on level, list of boxes. int in_numLevels; is >> in_numLevels; CH_assert (in_numLevels >= m_level+1); if (s_verbosity >= 3) { pout() << "numLevels = " << in_numLevels << endl; } while (is.get() != '\n'); amrGrids.resize(in_numLevels); // now loop over levels, starting with level 1 int ngrid; for (int lev=1; lev< in_numLevels; lev++) { is >> ngrid; if (s_verbosity > 3) { pout() << "level " << lev << " numGrids = " << ngrid << endl; pout() << "Grids: "; } while (is.get() != '\n'); amrGrids[lev].resize(ngrid); for (int i=0; i<ngrid; i++) { Box bx; is >> bx; while (is.get() != '\n'); if (s_verbosity >= 3) { pout() << bx << endl; } amrGrids[lev][i] = bx; } // end loop over boxes on this level } // end loop over levels #ifdef CH_MPI } // end if procID = 0 MPI_Barrier(Chombo_MPI::comm); broadcast(amrGrids, 0); MPI_Barrier(Chombo_MPI::comm); #endif // now coarsen next levels boxes down to this level and add them // to the tagged IntvectSet int nRefFine = refRatio(); for (int n=0; n<amrGrids.size(); n++) { Box coarseFineBox(amrGrids[m_level+1][n]); coarseFineBox.coarsen(nRefFine); a_tags |= coarseFineBox; } }
int main(int argc,char **argv) { #ifdef CH_MPI MPI_Init(&argc, &argv); #endif // registerDebugger(); // begin forever present scoping trick { pout()<<std::endl; Vector<std::string> names0(1, "phi"); Vector<int> refRatio(3,2); Vector<Real> coveredVal(1,3.0); const char* in_file = "sphere.inputs"; // read in an input file or use default file // if (argc > 1) // { // in_file = argv[1]; // } //parse input file ParmParse pp(0,NULL,NULL,in_file); RealVect center; Real radius; RealVect origin; RealVect dx; Box domain; ProblemDomain pDomain(domain); int eekflag = 0; LevelData<EBCellFAB> fine, med, coarse; LevelData<EBCellFAB> fineRHS, medRHS, coarseRHS; LevelData<EBCellFAB> fineResidual, mediumResidual, coarseResidual; Vector<LevelData<EBCellFAB>* > ebvector(3,NULL); Vector<LevelData<EBCellFAB>* > vresidual(3,NULL); Vector<LevelData<EBCellFAB>* > rhsvector(3,NULL); ebvector[0]=&coarse; ebvector[1]=&med; ebvector[2]=&fine; vresidual[0]=&coarseResidual; vresidual[1]=&mediumResidual; vresidual[2]=&fineResidual; rhsvector[0] = &coarseRHS; rhsvector[1] = &medRHS; rhsvector[2] = &fineRHS; readGeometryInfo(domain, dx, origin, center, radius); Box domainFine(domain), domainMedi, domainCoar; ProblemDomain pFine(domain); RealVect dxFine(dx), dxMedi, dxCoar; CH_assert(eekflag == 0); domainMedi = coarsen(domainFine, 2); domainCoar = coarsen(domainMedi, 2); dxMedi = 2.0*dxFine; dxCoar = 2.0*dxMedi; Vector<RealVect> xVec(3, IntVect::Unit); xVec[0]*= dxCoar; xVec[1]*= dxMedi; xVec[2]*= dxFine; Vector<DisjointBoxLayout> grids(3); ProblemDomain baseDomain(domainCoar); ProblemDomain pMed(domainMedi); Vector<ProblemDomain> pd(3); pd[0] = baseDomain; pd[1] = pMed; pd[2] = ProblemDomain(domainFine); RefCountedPtr<BaseBCValue>value(new DirichletBC()); DirichletPoissonDomainBC* domainBC = new DirichletPoissonDomainBC(); domainBC->setFunction(value); RefCountedPtr<BaseDomainBC> bc(domainBC); //make data holders Vector<int> comps(2,1); int steps= 5; int step = 0; while (step < steps) { eekflag = makeGeometry( domain, dx, origin, center, radius); //make grids //IntVectSet tags = mfIndexSpace->interfaceRegion(2); IntVectSet tags(domainCoar); tags.grow(1); makeHierarchy(grids, baseDomain, tags); const CH_XD::EBIndexSpace* ebisPtr = Chombo_EBIS::instance(); Vector<EBISLayout> layouts(3); EBISLayout& fineLayout = layouts[2]; ebisPtr->fillEBISLayout(fineLayout, grids[2], domainFine, 2); EBCellFactory fineFactory(fineLayout); ebvector[2]->define(grids[2], 1, IntVect::Unit, fineFactory); rhsvector[2]->define(grids[2], 1, IntVect::Zero, fineFactory); EBISLayout& medLayout = layouts[1]; ebisPtr->fillEBISLayout(medLayout, grids[1], domainMedi, 2); EBCellFactory medFactory(medLayout); ebvector[1]->define(grids[1], 1, IntVect::Unit, medFactory); rhsvector[1]->define(grids[1], 1, IntVect::Zero, medFactory); EBISLayout& coarseLayout = layouts[0]; ebisPtr->fillEBISLayout(coarseLayout, grids[0], domainCoar, 2); EBCellFactory coarseFactory(coarseLayout); ebvector[0]->define(grids[0], 1, IntVect::Unit, coarseFactory); rhsvector[0]->define(grids[0], 1, IntVect::Zero, coarseFactory); for (int lev=0; lev<3; lev++) { setValue(*rhsvector[lev], RHS(), pd[lev].domainBox(), xVec[lev], origin, true); } Vector<int> refRatio(3,2); int max_iter = 40; pp.get("max_iter", max_iter); Real eps = 1.e-6; pp.get("eps", eps); int relaxType; pp.get("relaxType",relaxType); DirichletPoissonDomainBCFactory* domDirBC = new DirichletPoissonDomainBCFactory(); domDirBC->setFunction(value); RefCountedPtr<BaseDomainBCFactory> domBC( domDirBC ); DirichletPoissonEBBCFactory* ebDirBC = new DirichletPoissonEBBCFactory(); ebDirBC->setFunction(value); RefCountedPtr<BaseEBBCFactory> ebBC( ebDirBC ); Vector<EBLevelGrid> eblgs(3); Vector<RefCountedPtr<EBQuadCFInterp> > quadCFI(3, RefCountedPtr<EBQuadCFInterp>()); for (int i=0; i<3; i++) { eblgs[i] = EBLevelGrid(grids[i], layouts[i], pd[i]); if (i > 0) { quadCFI[i] = RefCountedPtr<EBQuadCFInterp>( new EBQuadCFInterp(grids[i], grids[i-1], layouts[i], layouts[i-1], pd[i-1], refRatio[i-1], 1, *eblgs[i].getCFIVS())); } } EBAMRPoissonOpFactory opFact(eblgs, refRatio, quadCFI, xVec[0], RealVect::Zero, 4, relaxType, domBC, ebBC, 0.0, 1.0, 0.0, IntVect::Unit, IntVect::Zero); for (int i=0; i<3; i++) { LevelData<EBCellFAB> &phi=*ebvector[i], &rhs=*rhsvector[i], &residual=*vresidual[i]; LevelData<EBCellFAB> correction; DisjointBoxLayout dblMGCoar; EBISLayout ebislMGCoar; EBAMRPoissonOp* opPtr = opFact.AMRnewOp(pd[i]); EBAMRPoissonOp& op = *opPtr; RelaxSolver<LevelData<EBCellFAB> > solver; solver.define(&op, false); solver.m_imax = max_iter; solver.m_eps = eps; op.create(residual, rhs); op.create(correction, phi); op.setToZero(residual); op.setToZero(phi); op.residual(residual, phi, rhs); Real r2norm = op.norm(residual, 2); Real r0norm = op.norm(residual, 0); pout()<<indent<<"Residual L2 norm "<<r2norm<<"Residual max norm = " <<r0norm<<std::endl; solver.solve(phi, rhs); op.residual(residual, phi, rhs); r2norm = op.norm(residual, 2); r0norm = op.norm(residual, 0); pout()<<indent2<<"Residual L2 norm "<<r2norm<<" Residual max norm = " <<r0norm<<std::endl; delete opPtr; } #ifdef CH_USE_HDF5 sprintf(iter_str, "residual.%03d.%dd.hdf5",step, SpaceDim); Vector<std::string> names(1); names[0]="residual"; writeEBHDF5(iter_str, grids, vresidual, names, domainCoar, dxCoar[0], 1, step, refRatio, 3, true, coveredVal); sprintf(iter_str, "phi.%03d.%dd.hdf5",step, SpaceDim); names[0]="phi"; writeEBHDF5(iter_str, grids, ebvector ,names, domainCoar, dxCoar[0], 1, step, refRatio, 3, true, coveredVal); #endif step++; center[0]-= dx[0]/3.0; center[1]-= dx[1]/2.0; radius += dx[0]/6.0; Chombo_EBIS::instance()->clear(); pout()<<step<<std::endl; } pout() <<"\n "<<indent2<<pgmname<<" test passed " << endl; } // end scoping trick #ifdef CH_MPI MPI_Finalize(); #endif return 0; }
int main(int argc, char** argv) { #ifdef CH_MPI MPI_Init(&argc, &argv); #endif int eekflag = 0; {//begin forever present scoping trick const char* in_file = "pwlinterp.inputs"; //parse input file ParmParse pp(0,NULL,NULL,in_file); //define the geometry object. //need the new and delete because of //strong construction //make the gometry. this makes the first Chombo_EBIS Box domainFineFull, domainCoarFull; Box domainFinePart, domainCoarPart; Real dxFineFull, dxCoarFull; Real dxFinePart, dxCoarPart; //and defines it using a geometryservice eekflag = makeGeometry(domainFinePart, dxFinePart); CH_assert(eekflag == 0); int nlevels = 2; Vector<int> refRatio(nlevels); pp.getarr("ref_ratio", refRatio,0,nlevels); domainCoarPart = coarsen(domainFinePart, 2); domainFineFull = coarsen(domainFinePart, refRatio[0]); domainCoarFull = coarsen(domainFineFull, 2); dxCoarPart = 2.0*dxFinePart; dxFineFull = refRatio[0]*dxFinePart; dxCoarFull = 2.0*dxFineFull; //make grids DisjointBoxLayout gridsFinePart, gridsCoarPart; DisjointBoxLayout gridsFineFull, gridsCoarFull; eekflag = makeLayoutPart(gridsCoarPart, domainCoarFull); eekflag = makeLayoutFull(gridsCoarFull, domainCoarFull); CH_assert(eekflag == 0); refine(gridsFinePart, gridsCoarPart, 2); refine(gridsFineFull, gridsCoarFull, 2); ///create ebislayout int nghost = 0; EBISLayout ebislFinePart, ebislCoarPart; EBISLayout ebislFineFull, ebislCoarFull; eekflag = makeEBISL(ebislFinePart, gridsFinePart, domainFinePart, nghost); if (eekflag != 0) return eekflag; eekflag = makeEBISL(ebislCoarPart, gridsCoarPart, domainCoarPart, nghost); if (eekflag != 0) return eekflag; eekflag = makeEBISL(ebislFineFull, gridsFineFull, domainFineFull, nghost); if (eekflag != 0) return eekflag; eekflag = makeEBISL(ebislCoarFull, gridsCoarFull, domainCoarFull, nghost); if (eekflag != 0) return eekflag; int nvar = 1; EBCellFactory ebcellfactFinePart(ebislFinePart); EBCellFactory ebcellfactCoarPart(ebislCoarPart); LevelData<EBCellFAB> errorFinePart(gridsFinePart, nvar, IntVect::Zero,ebcellfactFinePart); LevelData<EBCellFAB> errorCoarPart(gridsCoarPart, nvar, IntVect::Zero,ebcellfactCoarPart); eekflag = getError(errorFinePart, ebislFinePart, gridsFinePart, domainFinePart, dxFinePart, ebislFineFull, gridsFineFull, domainFineFull, dxFineFull, refRatio[0]); if (eekflag != 0) return eekflag; eekflag = getError(errorCoarPart, ebislCoarPart, gridsCoarPart, domainCoarPart, dxCoarPart, ebislCoarFull, gridsCoarFull, domainCoarFull, dxCoarFull, refRatio[0]); if (eekflag != 0) return eekflag; eekflag = compareError(errorFinePart, ebislFinePart, gridsFinePart, domainFinePart, errorCoarPart, ebislCoarPart, gridsCoarPart, domainCoarPart); if (eekflag != 0) return eekflag; #if CH_SPACEDIM==2 string fileFine("pltFineError.2d.hdf5"); string fileCoar("pltCoarError.2d.hdf5"); #else string fileFine("pltFineError.3d.hdf5"); string fileCoar("pltCoarError.3d.hdf5"); #endif outputError(errorFinePart, errorCoarPart, gridsFinePart, gridsCoarPart, domainFinePart, domainCoarPart, fileFine, fileCoar); }//end omnipresent scoping trick CH_XD::EBIndexSpace* ebisPtr = Chombo_EBIS::instance(); ebisPtr->clear(); #ifdef CH_MPI MPI_Finalize(); #endif return eekflag; }
int makeGeometry(Box& a_domain, Real& a_dx) { int eekflag = 0; //parse input file ParmParse pp; RealVect origin = RealVect::Zero; Vector<int> n_cell(SpaceDim); pp.getarr("n_cell",n_cell,0,SpaceDim); int nlevels = 2; Vector<int> refRatio(nlevels); pp.getarr("ref_ratio", refRatio,0,nlevels); IntVect lo = IntVect::Zero; IntVect hi; for (int ivec = 0; ivec < SpaceDim; ivec++) { if (n_cell[ivec] <= 0) { pout() << " bogus number of cells input = " << n_cell[ivec]; return(-1); } hi[ivec] = n_cell[ivec] - 1; } a_domain.setSmall(lo); a_domain.setBig(hi); //now coarsen a_domain so it's the finest domain (level 1, fine hierarchy) a_domain.refine(refRatio[0]*2); Vector<Real> prob_lo(SpaceDim, 1.0); Real prob_hi; pp.getarr("prob_lo",prob_lo,0,SpaceDim); pp.get("prob_hi",prob_hi); a_dx = (prob_hi-prob_lo[0])/n_cell[0]; a_dx /= 2*refRatio[0];//so it's dx on the finest domain (level 1, fine hierarchy) for (int idir = 0; idir < SpaceDim; idir++) { origin[idir] = prob_lo[idir]; } int whichgeom; pp.get("which_geom",whichgeom); if (whichgeom == 0) { //allregular pout() << "all regular geometry" << endl; AllRegularService regserv; CH_XD::EBIndexSpace* ebisPtr = Chombo_EBIS::instance(); ebisPtr->define(a_domain, origin, a_dx, regserv); } else if (whichgeom == 1) { pout() << "ramp geometry" << endl; int upDir; int indepVar; Real startPt; Real slope; pp.get("up_dir",upDir); pp.get("indep_var",indepVar); pp.get("start_pt", startPt); pp.get("ramp_slope", slope); RealVect normal = RealVect::Zero; normal[upDir] = 1.0; normal[indepVar] = -slope; RealVect point = RealVect::Zero; point[upDir] = -slope*startPt; bool normalInside = true; PlaneIF ramp(normal,point,normalInside); RealVect vectDx = RealVect::Unit; vectDx *= a_dx; GeometryShop workshop(ramp,0,vectDx); //this generates the new EBIS CH_XD::EBIndexSpace* ebisPtr = Chombo_EBIS::instance(); ebisPtr->define(a_domain, origin, a_dx, workshop); } else if (whichgeom == 2) { pout() << "slab geometry" << endl; vector<int> slab_lo(SpaceDim); pp.getarr("slab_lo",slab_lo,0,SpaceDim); vector<int> slab_hi(SpaceDim); pp.getarr("slab_hi",slab_hi,0,SpaceDim); IntVect lo, hi; for (int idir = 0; idir < SpaceDim; idir++) { lo[idir] = slab_lo[idir]; hi[idir] = slab_hi[idir]; } Box coveredBox(lo,hi); SlabService slab(coveredBox); //this generates the new EBIS CH_XD::EBIndexSpace* ebisPtr = Chombo_EBIS::instance(); RealVect origin = RealVect::Zero; ebisPtr->define(a_domain, origin, a_dx, slab); } else { //bogus which_geom pout() << " bogus which_geom input = " << whichgeom; eekflag = 33; } return eekflag; }