void EBMGInterp::pwlInterp(LevelData<EBCellFAB>& a_fineData, const LevelData<EBCellFAB>& a_coarData, const Interval& a_variables) { CH_TIME("EBMGInterp::pwlInterp"); CH_assert(a_fineData.ghostVect() == m_ghost); CH_assert(a_coarData.ghostVect() == m_ghost); CH_assert(m_doLinear); //otherwise stencils have not been defined if (m_layoutChanged) { if (m_coarsenable) { CH_TIME("EBMGInterp::pwlInterp::coarsenable"); EBCellFactory ebcellfact(m_buffEBISL); LevelData<EBCellFAB> coarsenedFineData(m_buffGrids, m_nComp, m_ghost, ebcellfact); a_coarData.copyTo(a_variables, coarsenedFineData, a_variables); fillGhostCellsPWC(coarsenedFineData, m_buffEBISL, m_coarDomain); for (DataIterator dit = m_fineGrids.dataIterator(); dit.ok(); ++dit) { //does incrementonly = true pwlInterpFAB(a_fineData[dit()], m_buffGrids[dit()], coarsenedFineData[dit()], dit(), a_variables); } } else { CH_TIME("EBMGInterp::pwlInterp::uncoarsenable"); EBCellFactory ebcellfact(m_buffEBISL); fillGhostCellsPWC((LevelData<EBCellFAB>&)a_coarData, m_coarEBISL, m_coarDomain); LevelData<EBCellFAB> refinedCoarseData(m_buffGrids, m_nComp, m_ghost, ebcellfact); for (DataIterator dit = m_coarGrids.dataIterator(); dit.ok(); ++dit) { refinedCoarseData[dit()].setVal(0.); pwlInterpFAB(refinedCoarseData[dit()], m_coarGrids[dit()], a_coarData[dit()], dit(), a_variables); } EBAddOp op; refinedCoarseData.copyTo(a_variables, a_fineData, a_variables, m_copierRCtoF, op); } } else { pwcInterpMG(a_fineData, a_coarData, a_variables); } }
void EBCoarToFineRedist:: defineDataHolders() { CH_TIME("EBCoarToFineRedist::defineDataHolders"); //make mass buffers BaseIVFactory<Real> factCoar(m_ebislCoar, m_setsCoar); IntVect noghost = IntVect::Zero; m_regsCoar.define(m_gridsCoar, m_nComp, noghost, factCoar); BaseIVFactory<Real> factCedFine(m_ebislCedFine, m_setsCedFine); m_regsCedFine.define(m_gridsCedFine, m_nComp, m_redistRad*IntVect::Unit, factCedFine); EBCellFactory ebcellfact(m_ebislCedFine); m_densityCedFine.define(m_gridsCedFine, 1, 2*m_redistRad*IntVect::Unit, ebcellfact); //define the stencils with volume weights. //if you want mass weights or whatever, use reset weights m_stenCedFine.define(m_gridsCedFine); m_volumeStenc.define(m_gridsCedFine); m_standardStenc.define(m_gridsCedFine); RedistStencil stenCedFine(m_gridsCedFine, m_ebislCedFine, m_domainCoar, m_redistRad); for (DataIterator ditCedF = m_gridsCedFine.dataIterator(); ditCedF.ok(); ++ditCedF) { BaseIVFAB<VoFStencil>& stenFAB = m_stenCedFine[ditCedF()]; BaseIVFAB<VoFStencil>& volStenFAB = m_volumeStenc[ditCedF()]; BaseIVFAB<VoFStencil>& stanStenFAB = m_standardStenc[ditCedF()]; const EBISBox& ebisBox = m_ebislCedFine[ditCedF()]; const IntVectSet& ivs = m_setsCedFine[ditCedF()]; const BaseIVFAB<VoFStencil>& rdStenFAB = stenCedFine[ditCedF()]; const Box& gridCedFine = m_gridsCedFine.get(ditCedF()); stenFAB.define(ivs, ebisBox.getEBGraph(), 1); volStenFAB.define(ivs, ebisBox.getEBGraph(), 1); stanStenFAB.define(ivs, ebisBox.getEBGraph(), 1); for (VoFIterator vofit(ivs, ebisBox.getEBGraph()); vofit.ok(); ++vofit) { const VolIndex& srcVoF = vofit(); VoFStencil newStencil; const VoFStencil& stanSten = rdStenFAB(srcVoF, 0); for (int istan = 0; istan < stanSten.size(); istan++) { const VolIndex& dstVoF = stanSten.vof(istan); const Real& weight = stanSten.weight(istan); if (gridCedFine.contains(dstVoF.gridIndex())) { newStencil.add(dstVoF, weight); } } stenFAB(srcVoF, 0) = newStencil; //need to keep these around to get mass redist right volStenFAB(srcVoF, 0) = newStencil; stanStenFAB(srcVoF,0) = stanSten; } } }
void EBPoissonOp:: create(LevelData<EBCellFAB>& a_lhs, const LevelData<EBCellFAB>& a_rhs) { int ncomp = a_rhs.nComp(); EBCellFactory ebcellfact(m_eblg.getEBISL()); a_lhs.define(m_eblg.getDBL(), ncomp, a_rhs.ghostVect(), ebcellfact); }
void EBPoissonOp:: createCoarser(LevelData<EBCellFAB>& a_coar, const LevelData<EBCellFAB>& a_fine, bool a_ghosted) { CH_assert(a_fine.nComp() == 1); const DisjointBoxLayout& dbl = m_eblgCoarMG.getDBL(); ProblemDomain coarDom = coarsen(m_eblg.getDomain(), 2); int nghost = a_fine.ghostVect()[0]; EBISLayout coarEBISL; const EBIndexSpace* const ebisPtr = Chombo_EBIS::instance(); ebisPtr->fillEBISLayout(coarEBISL, dbl, coarDom, nghost); EBCellFactory ebcellfact(coarEBISL); a_coar.define(dbl, 1,a_fine.ghostVect(),ebcellfact); }
void EBCoarsen::define(const EBLevelGrid& a_eblgFine, const EBLevelGrid& a_eblgCoar, const int& a_nref, const int& a_nvar) { CH_TIME("EBCoarsen:define"); CH_assert(a_nref > 0); CH_assert(a_nvar > 0); CH_assert(a_eblgFine.getDBL().coarsenable(a_nref)); CH_assert(a_eblgFine.getEBIS()->isDefined()); CH_assert(a_eblgCoar.getEBIS()->isDefined()); m_cfivsPtr = a_eblgFine.getCFIVS(); m_isDefined = true; m_refRat = a_nref; m_nComp = a_nvar; m_gridsCoar = a_eblgCoar.getDBL(); m_gridsFine = a_eblgFine.getDBL(); m_ebislCoar = a_eblgCoar.getEBISL(); m_ebislFine = a_eblgFine.getEBISL(); m_domainCoar = a_eblgCoar.getDomain(); m_domainFine = a_eblgFine.getDomain(); IntVect ghost = 4*IntVect::Unit; int nghost = 4; m_coarsenedFineGrids = DisjointBoxLayout(); coarsen(m_coarsenedFineGrids, m_gridsFine, m_refRat); a_eblgFine.getEBIS()->fillEBISLayout(m_coarsenedFineEBISL, m_coarsenedFineGrids, m_domainCoar, nghost); m_coarsenedFineEBISL.setMaxRefinementRatio(m_refRat, a_eblgFine.getEBIS()); EBCellFactory ebcellfact(m_coarsenedFineEBISL); m_coarsenedFineData.define(m_coarsenedFineGrids, m_nComp, ghost, ebcellfact); //define the coarsening stencil for irreg vofs and // for coarse vofs next to the cf interface if refRat<4 defineStencil(*a_eblgFine.getCFIVS()); }
void getError(LevelData<EBCellFAB>& a_error, const EBISLayout& a_ebisl, const DisjointBoxLayout& a_dbl, const Real& a_dx) { EBCellFactory ebcellfact(a_ebisl); EBFluxFactory ebfluxfact(a_ebisl); a_error.define(a_dbl, 1, IntVect::Zero, ebcellfact); LevelData<EBCellFAB> divFCalc(a_dbl, 1, IntVect::Zero, ebcellfact); LevelData<EBCellFAB> divFExac(a_dbl, 1, IntVect::Zero, ebcellfact); LevelData<EBFluxFAB> faceFlux(a_dbl, 1, IntVect::Zero, ebfluxfact); for (DataIterator dit = a_dbl.dataIterator(); dit.ok(); ++dit) { a_error[dit()].setVal(0.); divFCalc[dit()].setVal(0.); divFExac[dit()].setVal(0.); } setToExactDivFLD(divFExac, a_ebisl, a_dbl, a_dx); setToExactFluxLD(faceFlux, a_ebisl, a_dbl, a_dx); Interval interv(0, 0); faceFlux.exchange(interv); kappaDivergenceLD(divFCalc, faceFlux, a_ebisl, a_dbl, a_dx); for (DataIterator dit = a_dbl.dataIterator(); dit.ok(); ++dit) { EBCellFAB& errorFAB = a_error[dit()]; EBCellFAB& exactFAB = divFExac[dit()]; EBCellFAB& calcuFAB = divFCalc[dit()]; errorFAB += calcuFAB; errorFAB -= exactFAB; } }
EBCompositeMACProjector:: EBCompositeMACProjector(const Vector<EBLevelGrid>& a_eblg, const Vector<int>& a_refRat, const Vector<RefCountedPtr<EBQuadCFInterp> >& a_quadCFI, const RealVect& a_coarsestDx, const RealVect& a_origin, const RefCountedPtr<BaseDomainBCFactory>& a_baseDomainBCVel, const RefCountedPtr<BaseDomainBCFactory>& a_baseDomainBCPhi, const RefCountedPtr<BaseEBBCFactory>& a_baseEBBCPhi, const bool& a_subtractOffMean, const int& a_numLevels, const int& a_verbosity, const int& a_numPreCondIters, const Real& a_time, const int& a_relaxType, const int& a_bottomSolverType) { CH_TIME("EBCompositeMACProjector::EBCompositeMACProjector"); m_eblg = a_eblg; m_quadCFI = a_quadCFI; if (a_numLevels < 0) { m_numLevels = a_eblg.size(); } else { CH_assert(a_numLevels <= a_eblg.size()); m_numLevels = a_numLevels; } //a few consistency checks CH_assert(a_eblg.size() >= m_numLevels); CH_assert(a_refRat.size() >= m_numLevels); m_baseDomainBCFactVel = a_baseDomainBCVel; m_baseDomainBCFactPhi = a_baseDomainBCPhi; m_refRat = a_refRat; m_dx.resize(m_numLevels); m_dx[0] = a_coarsestDx; m_origin = a_origin; m_time = a_time; for (int ilev = 1; ilev < m_numLevels; ilev++) { m_dx[ilev] = m_dx[ilev-1]/m_refRat[ilev-1]; } const EBIndexSpace* ebisPtr = a_eblg[0].getEBIS(); m_divu.resize(m_numLevels, NULL); m_phi.resize(m_numLevels, NULL); m_fluxReg.resize(m_numLevels, NULL); for (int ilev = 0; ilev < m_numLevels; ilev++) { EBCellFactory ebcellfact(m_eblg[ilev].getEBISL()); m_divu[ilev] = new LevelData<EBCellFAB>(m_eblg[ilev].getDBL(), 1, IntVect::Zero, ebcellfact); m_phi[ilev] = new LevelData<EBCellFAB>(m_eblg[ilev].getDBL(), 1, IntVect::Unit, ebcellfact); m_fluxReg[ilev] = new EBFluxRegister(); if (ilev < (m_numLevels-1)) { //flux register lives with coarser level m_fluxReg[ilev]->define(m_eblg[ilev+1].getDBL(), m_eblg[ilev].getDBL(), m_eblg[ilev+1].getEBISL(), m_eblg[ilev].getEBISL(), m_eblg[ilev].getDomain(), m_refRat[ilev], 1, ebisPtr); } } //default values int numSmooth = 4; int itermax = 100; int mgCycle = 1; Real hang = 1.0e-20; Real tolerance = 1.0e-12; Real normThresh= 1.0e-12; m_useInitialGuess = false; m_subtractOffMean = a_subtractOffMean; m_bottomSolverType = a_bottomSolverType; ProblemDomain coarsestDomain(m_eblg[0].getDomain()); Real alpha = 0.0; Real beta = 1.0; m_opFactory = new EBAMRPoissonOpFactory(m_eblg, m_refRat, m_quadCFI, m_dx[0], m_origin, a_numPreCondIters,a_relaxType, a_baseDomainBCPhi, a_baseEBBCPhi, alpha, beta, m_time, IntVect::Unit, IntVect::Zero, m_numLevels); if (m_bottomSolverType==0) {//BiCGStab bottom solver m_solver.define(coarsestDomain, *m_opFactory, &m_bottomSolverBiCG, m_numLevels); } else if (m_bottomSolverType==1) {//EBSimpleSolver bottom solver m_solver.define(coarsestDomain, *m_opFactory, &m_bottomSolverSimp, m_numLevels); } else if (m_bottomSolverType==2) {//GMRES bottom solver m_solver.define(coarsestDomain, *m_opFactory, &m_bottomSolverGMRes, m_numLevels); } else { MayDay::Error("EBCompositeMACProjector::bad m_bottomSolverType type"); } setSolverParams(numSmooth, itermax, mgCycle, hang, tolerance, a_verbosity, normThresh); m_solver.init(m_phi, m_divu, m_numLevels-1, 0); }
void EBMGAverage::average(LevelData<EBCellFAB>& a_coarData, const LevelData<EBCellFAB>& a_fineData, const Interval& a_variables) { CH_TIMERS("EBMGAverage::average"); CH_TIMER("layout_changed_coarsenable", t1); CH_TIMER("layout_changed_not_coarsenable", t2); CH_TIMER("not_layout_changed", t3); CH_assert(a_fineData.ghostVect() == m_ghost); //CH_assert(a_coarData.ghostVect() == m_ghost); CH_assert(isDefined()); if (m_layoutChanged) { if (m_coarsenable) { CH_START(t1); EBCellFactory ebcellfact(m_buffEBISL); LevelData<EBCellFAB> coarsenedFineData(m_buffGrids, m_nComp, m_ghost, ebcellfact); EBLevelDataOps::setVal(coarsenedFineData, 0.0); for (DataIterator dit = m_fineGrids.dataIterator(); dit.ok(); ++dit) { averageFAB(coarsenedFineData[dit()], m_buffGrids[dit()], a_fineData[dit()], dit(), a_variables); } coarsenedFineData.copyTo(a_variables, a_coarData, a_variables, m_copier); CH_STOP(t1); } else { CH_START(t2); EBCellFactory ebcellfact(m_buffEBISL); LevelData<EBCellFAB> refinedCoarseData(m_buffGrids, m_nComp, m_ghost, ebcellfact); EBLevelDataOps::setVal(refinedCoarseData, 0.0); a_fineData.copyTo(a_variables, refinedCoarseData, a_variables, m_copier); for (DataIterator dit = m_coarGrids.dataIterator(); dit.ok(); ++dit) { averageFAB(a_coarData[dit()], m_coarGrids[dit()], refinedCoarseData[dit()], dit(), a_variables); } CH_STOP(t2); } } else { CH_START(t3); averageMG(a_coarData, a_fineData, a_variables); CH_STOP(t3); } }
EBGradDivFilter:: EBGradDivFilter(const DisjointBoxLayout& a_gridsFine, const DisjointBoxLayout* a_gridsCoarPtr, const EBISLayout& a_ebislFine, const EBISLayout* a_ebislCoarPtr, const ProblemDomain& a_domainFine, const RealVect& a_dxFine, const int& a_refRat, const Real& a_lambdaScale, const EBIndexSpace* const a_ebisPtr) { CH_TIME("EBGradDivFilter::EBGradDivFilter"); m_gridsFine = a_gridsFine ; m_gridsCoarPtr= a_gridsCoarPtr ; m_ebislFine = a_ebislFine ; m_eblgFine.define(m_gridsFine, m_ebislFine, m_domainFine); m_ebislCoarPtr= a_ebislCoarPtr ; m_domainFine = a_domainFine ; m_refRat = a_refRat ; m_dxFine = a_dxFine; m_hasCoarser = (m_gridsCoarPtr != NULL); EBCellFactory ebcellfact(m_ebislFine); EBFluxFactory ebfluxfact(m_ebislFine); m_gradVel.define(m_gridsFine, SpaceDim*SpaceDim, IntVect::Unit, ebcellfact); m_lambda.define( m_gridsFine, 1, IntVect::Zero, ebcellfact); m_faceDivCell.define(m_gridsFine, 1,4*IntVect::Unit, ebfluxfact); m_dropOrder.define( m_gridsFine); m_johanStencil.define(m_gridsFine); m_distanceAlongLine.define(m_gridsFine); for (DataIterator dit = m_gridsFine.dataIterator(); dit.ok(); ++dit) { BaseIVFAB<VoFStencil>& curJohanStencil = m_johanStencil[dit()]; BaseIVFAB<char>& curDropOrder = m_dropOrder[dit()]; BaseIVFAB<Real>& curDistanceAlongLine = m_distanceAlongLine[dit()]; EBGraph ebgraph = m_ebislFine[dit()].getEBGraph(); IntVectSet ivsIrreg = m_ebislFine[dit()].getIrregIVS(m_gridsFine.get(dit())); curJohanStencil.define( ivsIrreg,ebgraph, 2); curDistanceAlongLine.define(ivsIrreg,ebgraph, 2); curDropOrder.define( ivsIrreg,ebgraph, 1); for (VoFIterator vofit(ivsIrreg, ebgraph); vofit.ok(); ++vofit) { Vector<VoFStencil> pointStencils; Vector<Real> distanceAlongLine; bool dropOrder = false; EBArith::johanStencil(dropOrder, pointStencils, distanceAlongLine, vofit(), m_ebislFine[dit()], m_dxFine, (*m_eblgFine.getCFIVS())[dit()]); curDropOrder(vofit(), 0) = dropOrder; if (!dropOrder) { for (int ipoint = 0; ipoint < 2; ipoint++) { curJohanStencil(vofit(), ipoint) = pointStencils[ipoint]; curDistanceAlongLine(vofit(), ipoint) = distanceAlongLine[ipoint]; } } } } m_tensorCFI = NULL; if (m_hasCoarser) { Real dx = a_dxFine[0]; m_domainCoar = coarsen(m_domainFine, m_refRat); m_tensorCFI= new EBTensorCFInterp(m_gridsFine, *m_gridsCoarPtr, m_ebislFine, *m_ebislCoarPtr, m_domainCoar, m_refRat, SpaceDim, dx, *m_eblgFine.getCFIVS(), a_ebisPtr); } m_lambdaScale = a_lambdaScale; fillLambda(); }