Exemplo n.º 1
0
void
EBMGAverage::averageFAB(EBCellFAB&       a_coar,
                        const Box&       a_boxCoar,
                        const EBCellFAB& a_refCoar,
                        const DataIndex& a_datInd,
                        const Interval&  a_variables) const
{
  CH_TIMERS("EBMGAverage::average");
  CH_TIMER("regular_average", t1);
  CH_TIMER("irregular_average", t2);
  CH_assert(isDefined());

  const Box& coarBox = a_boxCoar;

  //do all cells as if they were regular
  Box refBox(IntVect::Zero, IntVect::Zero);
  refBox.refine(m_refRat);
  int numFinePerCoar = refBox.numPts();

  BaseFab<Real>& coarRegFAB =             a_coar.getSingleValuedFAB();
  const BaseFab<Real>& refCoarRegFAB = a_refCoar.getSingleValuedFAB();

  //set to zero because the fortran is a bit simpleminded
  //and does stuff additively
  a_coar.setVal(0.);
  CH_START(t1);
  for (int comp = a_variables.begin();  comp <= a_variables.end(); comp++)
    {
      FORT_REGAVERAGE(CHF_FRA1(coarRegFAB,comp),
                      CHF_CONST_FRA1(refCoarRegFAB,comp),
                      CHF_BOX(coarBox),
                      CHF_BOX(refBox),
                      CHF_CONST_INT(numFinePerCoar),
                      CHF_CONST_INT(m_refRat));
    }
  CH_STOP(t1);

  //this is really volume-weighted averaging even though it does
  //not look that way.

  //so (in the traditional sense) we want to preserve
  //rhoc * volc = sum(rhof * volf)
  //this translates to
  //volfrac_C * rhoC = (1/numFinePerCoar)(sum(volFrac_F * rhoF))
  //but the data input to this routine is all kappa weigthed so
  //the volumefractions have already been multiplied
  //which means
  // rhoC = (1/numFinePerCoar)(sum(rhoF))
  //which is what this does

  CH_START(t2);
  for (int comp = a_variables.begin();  comp <= a_variables.end(); comp++)
    {
      m_averageEBStencil[a_datInd]->apply(a_coar, a_refCoar, false, comp);
    }
  CH_STOP(t2);

}
Exemplo n.º 2
0
void
EBMGInterp::pwcInterpFAB(EBCellFAB&       a_refCoar,
                         const Box&       a_coarBox,
                         const EBCellFAB& a_coar,
                         const DataIndex& a_datInd,
                         const Interval&  a_variables) const
{
  CH_TIMERS("EBMGInterp::interp");
  CH_TIMER("regular_interp", t1);
  CH_TIMER("irregular_interp", t2);
  CH_assert(isDefined());

  const Box& coarBox = a_coarBox;

  for (int ivar = a_variables.begin();  ivar <= a_variables.end(); ivar++)
    {
      m_interpEBStencil[a_datInd]->cache(a_refCoar, ivar);

      //do all cells as if they were regular
      Box refBox(IntVect::Zero, IntVect::Zero);
      refBox.refine(m_refRat);

      const BaseFab<Real>& coarRegFAB =    a_coar.getSingleValuedFAB();
      BaseFab<Real>& refCoarRegFAB    = a_refCoar.getSingleValuedFAB();

      CH_START(t1);

      FORT_REGPROLONG(CHF_FRA1(refCoarRegFAB,ivar),
                      CHF_CONST_FRA1(coarRegFAB,ivar),
                      CHF_BOX(coarBox),
                      CHF_BOX(refBox),
                      CHF_CONST_INT(m_refRat));

      CH_STOP(t1);

      m_interpEBStencil[a_datInd]->uncache(a_refCoar, ivar);

      CH_START(t2);
      m_interpEBStencil[a_datInd]->apply(a_refCoar, a_coar, true, ivar);
      CH_STOP(t2);
    }
}
Exemplo n.º 3
0
void LargeMatrix::TxtMult(colVect& output, const colVect& arg) const
	{

		CH_TIMERS("Multiplication");
		CH_TIMER("mult_file", t1);

		std::ifstream mtx_file;
		CH_START(t1);
		mtx_file.open(m_filename.c_str());
		//std::cout << "MATRIX LOADING: " << std::endl;
		std::stringstream ss;
		for (int i = 0 ; i < m_num_rows ; i++)
			{
				rowVect row(m_num_rows,0);
				std::string line;

				if (mtx_file.is_open())
					{
						getline(mtx_file,line);
					}
				ss.str(line);

				std::string remain;
				for (int j = 0 ; j < m_num_rows ; j++)
					{
						ss >> row[j];
						//std::cout << row[j] << "  \t";
						ss.ignore(256,',');
					}
				//std::cout << std::endl;
				
				output[i] = row*arg;
			}
		CH_STOP(t1);
		mtx_file.close();
	}
void ebamriTransport(const AMRParameters& a_params,
                     const ProblemDomain& a_coarsestDomain)
{

  // begin define INS solver
  CH_TIMERS("ebamriTransport_driver");
  CH_TIMER("define_ebamrnosubcycle_solver", t3);
  CH_TIMER("init_ebamrnosubcycle_solver",   t4);
  CH_TIMER("run ebamrnosubcycle_solver",   t5);

  // read inputs
  ParmParse pp;

  int flowDir;
  pp.get("flow_dir", flowDir);
  Vector<int> nCells;
  pp.getarr("n_cell",  nCells,0,SpaceDim);

  Real jet1inflowVel;
  pp.get("jet1_inflow_vel", jet1inflowVel);

  int idoJet2;
  pp.get("do_jet2", idoJet2);
  bool doJet2 = idoJet2==1;

  Real jet2inflowVel;
  pp.get("jet2_inflow_vel", jet2inflowVel);

  Real viscosity = 0.0;
  pp.get("viscosity", viscosity);

  int idoSlipWalls;
  pp.get("do_slip_walls", idoSlipWalls);
  bool doSlip = idoSlipWalls==1;
  IntVect doSlipWallsLo = idoSlipWalls*IntVect::Unit;
  IntVect doSlipWallsHi = idoSlipWalls*IntVect::Unit;
  Vector<int> slipWallsLo,slipWallsHi;
  if(doSlip)
    {
      pp.getarr("do_slip_walls_hi",slipWallsHi,0,SpaceDim);
      pp.getarr("do_slip_walls_lo",slipWallsLo,0,SpaceDim);
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          doSlipWallsHi[idir] = slipWallsHi[idir];
          doSlipWallsLo[idir] = slipWallsLo[idir];
        }
    }

  int orderEBBC = 1;
  pp.query("order_ebbc", orderEBBC);

  bool doJet1PoiseInflow = false;
  pp.query("jet1_poiseuille_inflow", doJet1PoiseInflow);

  bool doJet2PoiseInflow = false;
  pp.query("jet2_poiseuille_inflow", doJet2PoiseInflow);

  bool initPoiseData = false;
  pp.query("poiseuille_init", initPoiseData);
  if(initPoiseData)  
  pout() << "Doing Poiseuille initialization" << endl;

  RefCountedPtr<PoiseuilleInflowBCValue> jet1PoiseBCValue;//make this BaseBCValue if also doing constant values
  RefCountedPtr<PoiseuilleInflowBCValue> jet2PoiseBCValue;

//  if(doPoiseInflow)
//    {
//      pout() << "Doing Poiseuille inflow" << endl;
      RealVect jet1centerPt, tubeAxis;
      Real jet1tubeRadius;
      Vector<Real> jet1centerPtVect, tubeAxisVect;
      pp.get("jet1_poise_profile_radius", jet1tubeRadius);
      pp.getarr("jet1_poise_profile_center_pt",  jet1centerPtVect,0,SpaceDim);
      pp.getarr("poise_profile_axis",       tubeAxisVect,0,SpaceDim);
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          jet1centerPt[idir] = jet1centerPtVect[idir];
          tubeAxis[idir] = tubeAxisVect[idir];
        }

      Real maxVelFactor;//= 1.5 for planar geometry, = 2.0 for cylindrical
      pp.get("poise_maxvel_factor", maxVelFactor);
      Real jet1maxVel = maxVelFactor*jet1inflowVel;

      jet1PoiseBCValue = RefCountedPtr<PoiseuilleInflowBCValue>(new PoiseuilleInflowBCValue(jet1centerPt,tubeAxis,jet1tubeRadius,jet1maxVel,flowDir));
//    }

      RealVect jet2centerPt;
      Real jet2tubeRadius;
      Vector<Real> jet2centerPtVect;
      pp.get("jet2_poise_profile_radius", jet2tubeRadius);
      pp.getarr("jet2_poise_profile_center_pt",  jet2centerPtVect,0,SpaceDim);
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          jet2centerPt[idir] = jet2centerPtVect[idir];
        }

      Real jet2maxVel = maxVelFactor*jet2inflowVel;

      jet2PoiseBCValue = RefCountedPtr<PoiseuilleInflowBCValue>(new PoiseuilleInflowBCValue(jet2centerPt,tubeAxis,jet2tubeRadius,jet2maxVel,flowDir));

  InflowOutflowIBCFactory ibc(flowDir,
                              doJet2,
                              jet1inflowVel,
                              jet2inflowVel,
                              orderEBBC,
                              doSlipWallsHi,
                              doSlipWallsLo,
                              doJet1PoiseInflow,
                              doJet2PoiseInflow,
                              initPoiseData,
                              jet1PoiseBCValue,
                              jet2PoiseBCValue);

  CH_START(t3);

  EBAMRNoSubcycle kahuna(a_params, ibc, a_coarsestDomain, viscosity);

  CH_STOP(t3);
  
  // end define INS solver

  // begin define transport solver
  
  // 1. setup the ibc  
  Real scalarInflowValue = 0.0;
  pp.get("scalar_inflow_value", scalarInflowValue);
  RefCountedPtr<EBScalarAdvectBCFactory> advectBCFact = 
    RefCountedPtr<EBScalarAdvectBCFactory>
    (new EBScalarAdvectBCFactory(flowDir, scalarInflowValue, jet2PoiseBCValue));

  EBAMRTransportParams transParams;
  // fillTransParams(transParams);

  bool scalSlopeLimiting = true;
  int ilimit;
  pp.get("limit_scal_slope", ilimit);
  scalSlopeLimiting = (ilimit==1);

  Real maxScalVal = 1.0;
  pp.get("max_scal_value", maxScalVal);

  Real minScalVal = 0.0;
  pp.get("min_scal_value", minScalVal);

  bool setScalMaxMin = true;
  int ilimit2;
  pp.get("set_scal_maxmin", ilimit2);
  setScalMaxMin = (ilimit2==1);

  int ifourth, iflatten, iartvisc;
  pp.get("scal_use_fourth_order_slopes", ifourth);
  pp.get("scal_use_flatten", iflatten);
  pp.get("scal_use_art_visc", iartvisc);

  bool useFourthOrderSlopes = (ifourth  == 1);
  bool useFlattening        = (iflatten == 1);
  bool useArtificialVisc    = (iartvisc == 1);

  RefCountedPtr<EBPhysIBCFactory> ibcFact = static_cast<RefCountedPtr<EBPhysIBCFactory> >(advectBCFact);

  RefCountedPtr<EBPatchTransportFactory> patchTransport = 
   RefCountedPtr<EBPatchTransportFactory>
   (new EBPatchTransportFactory(ibcFact, scalSlopeLimiting, maxScalVal, minScalVal, setScalMaxMin, useFourthOrderSlopes, useFlattening, useArtificialVisc));

  // 2. setup transport solver
  EBAMRTransportFactory transSolverFact(transParams, patchTransport, true);  
  // end define transport solver

  kahuna.defineExtraSolver(&transSolverFact);
  

  CH_START(t4);
  if (!pp.contains("restart_file"))
    {
      pout() << "starting fresh AMR run" << endl;
      kahuna.setupForAMRRun();
    }
  else
    {
      std::string restart_file;
      pp.get("restart_file",restart_file);
      pout() << " restarting from file " << restart_file << endl;
      kahuna.setupForRestart(restart_file);
    }
  CH_STOP(t4);

  int maxStep;
  pp.get("max_step", maxStep);

  Real stopTime = 0.0;
  pp.get("max_time",stopTime);

  CH_START(t5);

  Real fixedDt = 0.;
  pp.query("fixed_dt", fixedDt);
  if(fixedDt > 1.e-12)
    {
      kahuna.useFixedDt(fixedDt);
    }

  kahuna.run(stopTime, maxStep);

  CH_STOP(t5);

}
int
main(int a_argc, char* a_argv[])
{
#ifdef CH_MPI
  MPI_Init(&a_argc,&a_argv);
#endif
  //Scoping trick
  {
    CH_TIMERS("uber_timers");
    CH_TIMER("define_geometry", t1);
    CH_TIMER("run", t2);

#ifdef CH_MPI
    MPI_Barrier(Chombo_MPI::comm);
#endif

    //Check for an input file
    char* inFile = NULL;
    if (a_argc > 1)
      {
        inFile = a_argv[1];
      }
    else
      {
        pout() << "Usage: <executable name> <inputfile>" << endl;
        pout() << "No input file specified" << endl;
        return -1;
      }

    //Parse the command line and the input file (if any)
    ParmParse pp(a_argc-2,a_argv+2,NULL,inFile);

    ProblemDomain coarsestDomain;
    RealVect coarsestDx;
    AMRParameters params;
    getAMRINSParameters(params, coarsestDomain);
    int numFilt;
    pp.get("num_filter_iterations", numFilt);
    params.m_numFilterIterations = numFilt;

    int gphiIterations;
    pp.get("num_gphi_iterations", gphiIterations);
    params.m_gphiIterations = gphiIterations;

    int initIterations;
    pp.get("num_init_iterations", initIterations);
    params.m_initIterations = initIterations;

    bool doRegridSmoothing;
    pp.get("do_regrid_smoothing", doRegridSmoothing);
    params.m_doRegridSmoothing = doRegridSmoothing;

    CH_START(t1);

    //define geometry
    AMRINSGeometry(params, coarsestDomain);

    CH_STOP(t1);

    CH_START(t2);
    ebamriTransport(params, coarsestDomain);
    CH_STOP(t2);

    EBIndexSpace* ebisPtr = Chombo_EBIS::instance();
    ebisPtr->clear();

  }//end scoping trick
#ifdef CH_MPI
  CH_TIMER_REPORT();
  dumpmemoryatexit();
  MPI_Finalize();
#endif
}
Exemplo n.º 6
0
void
EBMGInterp::define(const DisjointBoxLayout&    a_dblFine,
                   const DisjointBoxLayout&    a_dblCoar,
                   const EBISLayout&           a_ebislFine,
                   const EBISLayout&           a_ebislCoar,
                   const ProblemDomain&        a_domainCoar,
                   const int&                  a_nref,
                   const int&                  a_nvar,
                   const EBIndexSpace*         ebisPtr,
                   const IntVect&              a_ghostCellsPhi,
                   const bool&                 a_layoutChanged,
                   const bool&                 a_doLinear)
{
  CH_TIMERS("EBMGInterp::define");
  CH_TIMER("fillEBISLayout", t1);
  m_isDefined = true;
  m_doLinear = a_doLinear;
  m_ghost = a_ghostCellsPhi;
  m_nComp = a_nvar;
  m_coarGrids = a_dblCoar;
  m_fineGrids = a_dblFine;
  m_coarEBISL = a_ebislCoar;
  m_fineEBISL = a_ebislFine;
  m_coarDomain = a_domainCoar;
  m_refRat = a_nref;
  m_fineDomain = refine(m_coarDomain, m_refRat);
  m_layoutChanged = a_layoutChanged;
  m_coarsenable   = a_dblFine.coarsenable(m_refRat);

  //only define ebislbuf and gridbuf if we are changing layouts
  if (m_layoutChanged)
    {
      ProblemDomain domebisl;
      if (m_coarsenable)
        {
          coarsen(m_buffGrids, m_fineGrids, m_refRat);
          domebisl = m_coarDomain;
        }
      else
        {
          refine(m_buffGrids,  m_coarGrids, m_refRat);
          m_copierRCtoF.define(m_buffGrids, m_fineGrids, a_ghostCellsPhi);
          m_copierFtoRC.define(m_fineGrids, m_buffGrids, a_ghostCellsPhi);
          domebisl = m_fineDomain;
        }

      CH_START(t1);
      int nghost = 4;
      ebisPtr->fillEBISLayout(m_buffEBISL,
                              m_buffGrids,
                              domebisl, nghost);
      if (m_refRat > 2)
        {
          if (m_coarsenable)
            {
              m_buffEBISL.setMaxRefinementRatio(m_refRat, ebisPtr);
            }
          else
            {
              m_buffEBISL.setMaxCoarseningRatio(m_refRat, ebisPtr);
            }
        }
      CH_STOP(t1);
    }
  defineStencils();
}
Exemplo n.º 7
0
void
EBMGInterp::pwlInterpFAB(EBCellFAB&       a_refCoar,
                         const Box&       a_coarBox,
                         const EBCellFAB& a_coar,
                         const DataIndex& a_datInd,
                         const Interval&  a_variables) const
{
  CH_TIMERS("EBMGInterp::pwlinterpfab");
  CH_TIMER("regular_interp", t1);
  CH_TIMER("irregular_interp", t2);
  CH_assert(isDefined());


  //first interpolate piecewise constant.
  pwcInterpFAB(a_refCoar,
               a_coarBox,
               a_coar,
               a_datInd,
               a_variables);

  //then add in slope*distance.
  const Box& coarBox = a_coarBox;

  for (int ivar = a_variables.begin();  ivar <= a_variables.end(); ivar++)
    {
      //save stuff at irreg cells because fortran result will be garbage
      //and this is an incremental process
      m_linearEBStencil[a_datInd]->cache(a_refCoar, ivar);

      //do all cells as if they were regular
      Box refBox(IntVect::Zero, IntVect::Zero);
      refBox.refine(m_refRat);

      const BaseFab<Real>& coarRegFAB =    a_coar.getSingleValuedFAB();
      BaseFab<Real>& refCoarRegFAB    = a_refCoar.getSingleValuedFAB();

      CH_START(t1);

      Real dxf = 1.0/m_coarDomain.size(0);
      Real dxc = 2.0*dxf;

      //do every cell as regular
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          FORT_PROLONGADDSLOPE(CHF_FRA1(refCoarRegFAB,ivar),
                               CHF_CONST_FRA1(coarRegFAB,ivar),
                               CHF_BOX(coarBox),
                               CHF_BOX(refBox),
                               CHF_INT(idir),
                               CHF_REAL(dxf),
                               CHF_REAL(dxc),
                               CHF_CONST_INT(m_refRat));
        }
      CH_STOP(t1);

      //replace garbage fortran put in with original values (at irregular cells)
      m_linearEBStencil[a_datInd]->uncache(a_refCoar, ivar);

      CH_START(t2);
      //do what fortran should have done at irregular cells.
      m_linearEBStencil[a_datInd]->apply(a_refCoar, a_coar, true, ivar);
      CH_STOP(t2);
    }
}
Exemplo n.º 8
0
//
// VCAMRPoissonOp2::reflux()
//   There are currently the new version (first) and the old version (second)
//   in this file.  Brian asked to preserve the old version in this way for
//   now. - TJL (12/10/2007)
//
void VCAMRPoissonOp2::reflux(const LevelData<FArrayBox>&        a_phiFine,
                            const LevelData<FArrayBox>&        a_phi,
                            LevelData<FArrayBox>&              a_residual,
                            AMRLevelOp<LevelData<FArrayBox> >* a_finerOp)
{
  CH_TIMERS("VCAMRPoissonOp2::reflux");

  m_levfluxreg.setToZero();
  Interval interv(0,a_phi.nComp()-1);

  CH_TIMER("VCAMRPoissonOp2::reflux::incrementCoarse", t2);
  CH_START(t2);

  DataIterator dit = a_phi.dataIterator();
  for (dit.reset(); dit.ok(); ++dit)
  {
    const FArrayBox& coarfab   = a_phi[dit];
    const FluxBox&   coarBCoef = (*m_bCoef)[dit];
    const Box&       gridBox   = a_phi.getBoxes()[dit];

    if (m_levfluxreg.hasCF(dit()))
    {
      for (int idir = 0; idir < SpaceDim; idir++)
      {
        FArrayBox coarflux;
        Box faceBox = surroundingNodes(gridBox, idir);

        getFlux(coarflux, coarfab, coarBCoef, faceBox, idir);

        Real scale = 1.0;
        m_levfluxreg.incrementCoarse(coarflux, scale,dit(),
            interv, interv, idir);
      }
    }
  }

  CH_STOP(t2);

  // const cast:  OK because we're changing ghost cells only
  LevelData<FArrayBox>& phiFineRef = ( LevelData<FArrayBox>&)a_phiFine;

  VCAMRPoissonOp2* finerAMRPOp = (VCAMRPoissonOp2*) a_finerOp;
  QuadCFInterp& quadCFI = finerAMRPOp->m_interpWithCoarser;

  quadCFI.coarseFineInterp(phiFineRef, a_phi);
  // I'm pretty sure this is not necessary. bvs -- flux calculations use
  // outer ghost cells, but not inner ones
  // phiFineRef.exchange(a_phiFine.interval());
  IntVect phiGhost = phiFineRef.ghostVect();
  int ncomps = a_phiFine.nComp();

  CH_TIMER("VCAMRPoissonOp2::reflux::incrementFine", t3);
  CH_START(t3);

  DataIterator ditf = a_phiFine.dataIterator();
  const DisjointBoxLayout& dblFine = a_phiFine.disjointBoxLayout();
  for (ditf.reset(); ditf.ok(); ++ditf)
    {
      const FArrayBox& phifFab   = a_phiFine[ditf];
      const FluxBox&   fineBCoef = (*(finerAMRPOp->m_bCoef))[ditf];
      const Box&       gridbox   = dblFine.get(ditf());

      for (int idir = 0; idir < SpaceDim; idir++)
        {
          //int normalGhost = phiGhost[idir];
          SideIterator sit;
          for (sit.begin(); sit.ok(); sit.next())
            {
              if (m_levfluxreg.hasCF(ditf(), sit()))
                {
                  Side::LoHiSide hiorlo = sit();
                  Box fluxBox = bdryBox(gridbox,idir,hiorlo,1);

                  FArrayBox fineflux(fluxBox,ncomps);
                  getFlux(fineflux, phifFab, fineBCoef, fluxBox, idir,
                          m_refToFiner);

                  Real scale = 1.0;
                  m_levfluxreg.incrementFine(fineflux, scale, ditf(),
                                             interv, interv, idir, hiorlo);
                }
            }
        }
    }

  CH_STOP(t3);

  Real scale = 1.0/m_dx;
  m_levfluxreg.reflux(a_residual, scale);
}
Exemplo n.º 9
0
// Advance the solution by "a_dt" by using an unsplit method.
// "a_finerFluxRegister" is the flux register with the next finer level.
// "a_coarseFluxRegister" is flux register with the next coarser level.
// If source terms do not exist, "a_S" should be null constructed and not
// defined (i.e. its define() should not be called).
Real LevelPluto::step(LevelData<FArrayBox>&       a_U,
                      LevelData<FArrayBox>        a_flux[CH_SPACEDIM],
                      LevelFluxRegister&          a_finerFluxRegister,
                      LevelFluxRegister&          a_coarserFluxRegister,
                      LevelData<FArrayBox>&       a_split_tags,
                      const LevelData<FArrayBox>& a_UCoarseOld,
                      const Real&                 a_TCoarseOld,
                      const LevelData<FArrayBox>& a_UCoarseNew,
                      const Real&                 a_TCoarseNew,
                      const Real&                 a_time,
                      const Real&                 a_dt,
                      const Real&                 a_cfl)
{
  CH_TIMERS("LevelPluto::step");

  CH_TIMER("LevelPluto::step::setup"   ,timeSetup);
  CH_TIMER("LevelPluto::step::update"  ,timeUpdate);
  CH_TIMER("LevelPluto::step::reflux"  ,timeReflux);
  CH_TIMER("LevelPluto::step::conclude",timeConclude);

  // Make sure everything is defined
  CH_assert(m_isDefined);

  CH_START(timeSetup);

  // Clear flux registers with next finer level
  if (m_hasFiner && (g_intStage == 1))
    {
      a_finerFluxRegister.setToZero();
    }

  // Setup an interval corresponding to the conserved variables
  Interval UInterval(0,m_numCons-1);

  {
    CH_TIME("setup::localU");
    for (DataIterator dit = m_U.dataIterator(); dit.ok(); ++dit)
    {
      m_U[dit].setVal(0.0); // Gets rid of denormalized crap.
      m_U[dit].copy(a_U[dit]);
    }

    m_U.exchange(m_exchangeCopier);
  }

  // Fill m_U's ghost cells using fillInterp
  if (m_hasCoarser)
    {
      // Fraction "a_time" falls between the old and the new coarse times
      Real alpha = (a_time - a_TCoarseOld) / (a_TCoarseNew - a_TCoarseOld);

    // Truncate the fraction to the range [0,1] to remove floating-point
    // subtraction roundoff effects
      Real eps = 0.04 * a_dt / m_refineCoarse;

      if (Abs(alpha) < eps)     alpha = 0.0;
      if (Abs(1.0-alpha) < eps) alpha = 1.0;

      // Current time before old coarse time
      if (alpha < 0.0)
        {
          MayDay::Error( "LevelPluto::step: alpha < 0.0");
        }

      // Current time after new coarse time
      if (alpha > 1.0)
        {
          MayDay::Error( "LevelPluto::step: alpha > 1.0");
        }

      // Interpolate ghost cells from next coarser level using both space
      // and time interpolation
      m_patcher.fillInterp(m_U,
                           a_UCoarseOld,
                           a_UCoarseNew,
                           alpha,
                           0,0,m_numCons);
    }

  // Potentially used in boundary conditions
  m_patchPluto->setCurrentTime(a_time);

  // Use to restrict maximum wave speed away from zero
  Real maxWaveSpeed = 1.e-12;
  Real minDtCool    = 1.e38;

  // The grid structure
  Grid *grid;
  static Time_Step Dts;
  Real inv_dt;
  
  #ifdef GLM_MHD
   glm_ch = g_coeff_dl_min*m_dx/(a_dt + 1.e-16)*a_cfl;
//   glm_ch = g_coeff_dl_min/(a_dt + 1.e-16)*a_cfl; /* If subcycling is turned off */
   glm_ch = MIN(glm_ch,glm_ch_max*g_coeff_dl_min);
  #endif

  CH_STOP(timeSetup);
  g_level_dx = m_dx;

  // Beginning of loop through patches/grids.
  for (DataIterator dit = m_grids.dataIterator(); dit.ok(); ++dit){
    CH_START(timeUpdate);

    // The current box
    Box curBox = m_grids.get(dit());

    // The current grid of conserved variables
    FArrayBox& curU = m_U[dit];

    // The current grid of volumes
    #if GEOMETRY != CARTESIAN
     const FArrayBox& curdV = m_dV[dit()];
    #else
     const FArrayBox  curdV;
    #endif
 
   #ifdef SKIP_SPLIT_CELLS
    // The current grid of split/unsplit tags
    FArrayBox& split_tags = a_split_tags[dit];
   #else
    FArrayBox split_tags;
   #endif

   #if (TIME_STEPPING == RK2)
    // The current storage for flags (RK2 only)
    BaseFab<unsigned char>& flags = m_Flags[dit];
    // Local temporary storage for conserved variables
    FArrayBox& curUtmp = m_Utmp[dit];
   #else
    BaseFab<unsigned char> flags;
    FArrayBox curUtmp;
   #endif

    // The fluxes computed for this grid - used for refluxing and returning
    // other face centered quantities
    FluxBox flux;

    // Set the current box for the patch integrator
    m_patchPluto->setCurrentBox(curBox);

    Real minDtCoolGrid;
    
    grid = m_structs_grid[dit].getGrid();
 
    IBEG = grid[IDIR].lbeg; IEND = grid[IDIR].lend;
    JBEG = grid[JDIR].lbeg; JEND = grid[JDIR].lend;
    KBEG = grid[KDIR].lbeg; KEND = grid[KDIR].lend;

    NX1 = grid[IDIR].np_int;
    NX2 = grid[JDIR].np_int;
    NX3 = grid[KDIR].np_int;

    NX1_TOT = grid[IDIR].np_tot;
    NX2_TOT = grid[JDIR].np_tot;
    NX3_TOT = grid[KDIR].np_tot;
 
    SetRBox();  /* RBox structures must be redefined for each patch */

    g_dt   = a_dt;
    g_time = a_time;
    g_maxRiemannIter = 0;
    PLM_CoefficientsSet (grid);  /* -- these may be needed by
                                       shock flattening algorithms */
    #if RECONSTRUCTION == PARABOLIC
     PPM_CoefficientsSet (grid);  
    #endif
    
    // reset time step coefficients 
    if (Dts.cmax == NULL) Dts.cmax = ARRAY_1D(NMAX_POINT, double);
    int id;
    Dts.inv_dta = 1.e-18;
    Dts.inv_dtp = 1.e-18;
    Dts.dt_cool = 1.e18;
    Dts.cfl     = a_cfl;
    Where(-1, grid); /* -- store grid for subsequent calls -- */

    // Take one step
    m_patchPluto->advanceStep (curU, curUtmp, curdV, split_tags, flags, flux,
                               &Dts, curBox, grid);
 
    inv_dt = Dts.inv_dta + 2.0*Dts.inv_dtp;
    maxWaveSpeed = Max(maxWaveSpeed, inv_dt); // Now the inverse of the timestep

    minDtCool = Min(minDtCool, Dts.dt_cool/a_cfl);

    CH_STOP(timeUpdate);

    CH_START(timeReflux);

    // Do flux register updates
    for (int idir = 0; idir < SpaceDim; idir++) {
    // Increment coarse flux register between this level and the next
    // finer level - this level is the next coarser level with respect
    // to the next finer level
      if (m_hasFiner) {
        a_finerFluxRegister.incrementCoarse(flux[idir],a_dt,dit(),
                                            UInterval, UInterval,idir);
      }

      // Increment fine flux registers between this level and the next
      // coarser level - this level is the next finer level with respect
      // to the next coarser level
       if (m_hasCoarser) {
         a_coarserFluxRegister.incrementFine(flux[idir],a_dt,dit(),
                                             UInterval, UInterval,idir);
       }
    }

    CH_STOP(timeReflux);
  }

  CH_START(timeConclude);

  {
    CH_TIME("conclude::copyU");
    // Now that we have completed the updates of all the patches, we copy the
    // contents of temporary storage, U, into the permanent storage, a_U.
    for(DataIterator dit = m_U.dataIterator(); dit.ok(); ++dit){
      a_U[dit].copy(m_U[dit]);
    }
   }

  // Find the minimum of dt's over this level
  Real local_dtNew = 1. / maxWaveSpeed;
  local_dtNew = Min(local_dtNew,minDtCool);
  Real dtNew;

  {
    CH_TIME("conclude::getDt");
 #ifdef CH_MPI
  #if (TIME_STEPPING == RK2) && (COOLING == NO)
  if (g_intStage == 1) {
  #endif
   int result = MPI_Allreduce(&local_dtNew, &dtNew, 1, MPI_CH_REAL,
                                  MPI_MIN, Chombo_MPI::comm);
   if(result != MPI_SUCCESS){ //bark!!!
      MayDay::Error("sorry, but I had a communcation error on new dt");
   }
  #if (TIME_STEPPING == RK2) && (COOLING == NO)
  } else {
   dtNew = local_dtNew;
  }
  #endif
 #else
   dtNew = local_dtNew;
 #endif
  }

  CH_STOP(timeConclude);

  // Return the maximum stable time step
  return dtNew;
}
Exemplo n.º 10
0
void LargeMatrix::OptMult(colVect& output, const colVect& arg) const
	{
		CH_TIMERS("Multiplication");
		CH_TIMER("trivial", t0);
		CH_TIMER("file_read", t1);
		CH_TIMER("line_splice", t2);
		CH_TIMER("vec_multiply", t3);
		//std::cout << "PERFORMING MULTIPLICATION!" << std::endl;


		std::ifstream mtx_file;
		mtx_file.open(m_filename.c_str(), std::ifstream::binary);
		//std::cout << "MATRIX LOADING: " << std::endl;
	
		char header_buffer[18];
		mtx_file.read(header_buffer, 18);
		if (!mtx_file)
			{
				mtx_file.close();
				std::cout << "FATAL ERROR: could not read line from file" << std::endl;
				abort();
			}
		//std::cout << "HEADER:: " << header_buffer << std::endl;
		unsigned int dat_size = *(int*) (header_buffer + 9);
		unsigned int num_row = *(int*) (header_buffer + 13);

		//std::cout << "Dat Size:: " << dat_size << std::endl;
		//std::cout << "Num rows:: " << num_row << std::endl;

		assert(m_num_rows == num_row);
		int Nchar_double = 8;
		assert(Nchar_double == dat_size);
		assert(sizeof(Real) == dat_size);



		int max_lines_read = m_nums_in_memory / m_num_rows;
		//std::cout << "Max nums in memory: " << m_nums_in_memory << std::endl;
		//std::cout << "Max lines to read: " << max_lines_read << std::endl;

		int line_size_char = m_num_rows * Nchar_double;


		char buffer[ line_size_char * max_lines_read];
		for (int i = 0 ; i < m_num_rows ; i+=max_lines_read)
			{
				CH_START(t0);
				assert(mtx_file.is_open());
				CH_STOP(t0);
				
				CH_START(t1);
				int num_lines_to_read = std::min(max_lines_read, m_num_rows - i);
				int num_bytes_to_read = line_size_char * num_lines_to_read;

				//std::cout << "Reading " << num_lines_to_read << " lines.\n Buffer call to read " << num_bytes_to_read << " Bytes." << std::endl;
	
				rowVect row(m_num_rows,0);
				mtx_file.read(buffer,  num_bytes_to_read);
				if (!mtx_file)
					{
						mtx_file.close();
						std::cout << "FATAL ERROR: could not read line from file" << std::endl;
						abort();
					}
				CH_STOP(t1);
	
				for (int n_line = 0 ; n_line < num_lines_to_read ; n_line++)
					{
						CH_START(t2);
						int line_displace = n_line * line_size_char;
						Real* row_vect = (Real*) (buffer + line_displace);
						//for (int j = 0 ; j < m_num_rows ; j++)
						//	{
						//		int float_displace = (j * Nchar_double) + line_displace;
	
						//		//assert(displace + Nchar_double  < line_size_char);
						//		row[j] = *(Real*) (buffer + float_displace);
						//		if (n_line == num_lines_to_read-1 and j == m_num_rows-1)
						//		{
						//			std::cout << row[j] << std::endl;
						//			std::cout << float_displace << std::endl;
						//		}
						//	}
						CH_STOP(t2);
						
						CH_START(t3);
						output[i+n_line] = cblas_ddot(m_num_rows, row_vect, 1, &*arg.begin(), 1);
						CH_STOP(t3);
					}
			}
		mtx_file.close();
	}
Exemplo n.º 11
0
void LargeMatrix::BinMult(colVect& output, const colVect& arg) const
	{
		CH_TIMERS("Multiplication");
		CH_TIMER("file_read", t1);
		CH_TIMER("line_splice", t2);
		CH_TIMER("vec_multiply", t3);
		//std::cout << "PERFORMING MULTIPLICATION!" << std::endl;
	
		std::ifstream mtx_file;
		mtx_file.open(m_filename.c_str(), std::ifstream::binary);
		//std::cout << "MATRIX LOADING: " << std::endl;
	
		int Nchar_double = 8;
		assert(m_num_rows == 25*25);
		int line_size = m_num_rows * Nchar_double;
		char buffer[line_size + 1];
		for (int i = 0 ; i < m_num_rows ; i++)
			{
				assert(mtx_file.is_open());
				CH_START(t1);
	
				rowVect row(m_num_rows,0);
				mtx_file.read(buffer, line_size + 1);
				if (!mtx_file)
					{
						mtx_file.close();
						std::cout << "FATAL ERROR: could not read line from file" << std::endl;
						abort();
					}
				assert(buffer[line_size] == '\n');
				CH_STOP(t1);
	
				CH_START(t2);
				Real * row_vect = (Real*) buffer;
				for (int j = 0 ; j < m_num_rows ; j++)
					{
						int displace = Nchar_double * j;
	
						//assert(displace + Nchar_double  < line_size);
						
						row[j] = *(Real*) (buffer + Nchar_double * j);
						//if (i == m_num_rows-1 and j == m_num_rows-1)
						//{
						//	std::cout << row[j] << std::endl;
						//	std::cout << Nchar_double * j << std::endl;
						//}
					}
				CH_STOP(t2);
				
				CH_START(t3);
				for (int q = 0 ; q < arg.size() ; q++)
					{
						//std::cout << "row["<<q<<"] vs row_vect["<<q<<"]:" <<row[q] << " VS "<<row_vect[q] << std::endl;
						assert(row[q] == row_vect[q]);
					}
				output[i] = cblas_ddot(m_num_rows, row_vect, 1, &*arg.begin(), 1);
				//output[i] = row*arg;
				CH_STOP(t3);
			}
		mtx_file.close();
	}
Exemplo n.º 12
0
void EBPoissonOp::
applyOp(LevelData<EBCellFAB>&             a_opPhi,
        const LevelData<EBCellFAB>&       a_phi,
        bool                              a_homogeneousPhysBC,
        DataIterator& dit,
        bool a_do_exchange)
{
  CH_TIMERS("EBPoissonOp::applyOp");
  CH_TIMER("regular_apply", t1);
  CH_TIMER("irregular_apply", t2);
  CH_TIMER("eb_bcs_apply", t3);
  CH_TIMER("dom_bcs_apply", t4);
  CH_TIMER("alpha_apply", t5);
  CH_assert(a_opPhi.ghostVect() == m_ghostCellsRHS);
  CH_assert(a_phi.ghostVect() == m_ghostCellsPhi);


  CH_assert(a_phi.nComp() == a_opPhi.nComp());

  LevelData<EBCellFAB>& phi = const_cast<LevelData<EBCellFAB>&>(a_phi);
  if (a_do_exchange)
    {
      phi.exchange(phi.interval());
    }

  int nComps = a_phi.nComp();

  for (dit.reset(); dit.ok(); ++dit)
    {

      Box dblBox( m_eblg.getDBL().get(dit()) );
      const EBCellFAB& phifab = phi[dit()];
      Box curPhiBox = phifab.box();
      const BaseFab<Real>& curPhiFAB = phifab.getSingleValuedFAB();

      EBCellFAB& opphifab = a_opPhi[dit()];
      BaseFab<Real>& curOpPhiFAB = opphifab.getSingleValuedFAB();

      //       Interval interv(0, nComps-1);
      CH_START(t5);
      if (m_alpha == 0)
        {
          opphifab.setVal(0.0);
        }
      else
        {
          opphifab.copy(phifab);
          opphifab.mult(m_alpha);
        }
      CH_STOP(t5);

      Box loBox[SpaceDim],hiBox[SpaceDim];
      int hasLo[SpaceDim],hasHi[SpaceDim];
      CH_START(t1);
      applyOpRegularAllDirs( loBox, hiBox, hasLo, hasHi,
                             dblBox, curPhiBox, nComps,
                             curOpPhiFAB,
                             curPhiFAB,
                             a_homogeneousPhysBC,
                             dit(),
                             m_beta);

      CH_STOP(t1);

      CH_START(t2);
      //apply stencil
      m_opEBStencil[dit()]->apply(opphifab, phifab, false);
      CH_STOP(t2);
      //apply inhom boundary conditions
      CH_START(t3);
      if (!a_homogeneousPhysBC)
        {
          const Real factor = m_dxScale*m_beta;
          m_ebBC->applyEBFlux(opphifab, phifab, m_vofItIrreg[dit()], (*m_eblg.getCFIVS()),
                              dit(), m_origin, m_dx, factor,
                              a_homogeneousPhysBC, m_time);
        }
      CH_STOP(t3);

      CH_START(t4);
      int comp = 0;
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          for (m_vofItIrregDomLo[idir][dit()].reset(); m_vofItIrregDomLo[idir][dit()].ok();  ++m_vofItIrregDomLo[idir][dit()])
            {
              Real flux;
              const VolIndex& vof = m_vofItIrregDomLo[idir][dit()]();
              m_domainBC->getFaceFlux(flux,vof,comp,a_phi[dit()],
                                      m_origin,m_dx,idir,Side::Lo, dit(), m_time,
                                      a_homogeneousPhysBC);

              opphifab(vof,comp) -= flux * m_beta*m_invDx[idir];
            }
          for (m_vofItIrregDomHi[idir][dit()].reset(); m_vofItIrregDomHi[idir][dit()].ok();  ++m_vofItIrregDomHi[idir][dit()])
            {
              Real flux;
              const VolIndex& vof = m_vofItIrregDomHi[idir][dit()]();
              m_domainBC->getFaceFlux(flux,vof,comp,a_phi[dit()],
                                      m_origin,m_dx,idir,Side::Hi,dit(), m_time,
                                      a_homogeneousPhysBC);

              opphifab(vof,comp) += flux * m_beta*m_invDx[idir];
            }

        }
      CH_STOP(t4);
    }
}
Exemplo n.º 13
0
void
EBPoissonOp::
defineStencils()
{
  CH_TIMERS("EBPoissonOp::defineStencils");
  CH_TIMER("opStencil_define", t1);
  CH_TIMER("colorStencil_define", t2);

  // define ebstencil for irregular applyOp
  m_opEBStencil.define(m_eblg.getDBL());
  // create vofstencils for applyOp
  LayoutData<BaseIVFAB<VoFStencil> > opStencil;
  opStencil.define(m_eblg.getDBL());
  //define bc stencils and create flux stencil
  m_ebBC->define((*m_eblg.getCFIVS()), m_dxScale*m_beta);
  LayoutData<BaseIVFAB<VoFStencil> >* fluxStencil = m_ebBC->getFluxStencil(0);
  //create and define colored stencils (2 parts)
  LayoutData<BaseIVFAB<VoFStencil> > colorStencil;
  colorStencil.define(m_eblg.getDBL());
  LayoutData<BaseIVFAB<VoFStencil> > rhsColorStencil;
  rhsColorStencil.define(m_eblg.getDBL());

  m_alphaDiagWeight.define(   m_eblg.getDBL());
  m_betaDiagWeight.define(   m_eblg.getDBL());
  m_vofItIrreg.define( m_eblg.getDBL()); // vofiterator cache

  Box domainBox = m_eblg.getDomain().domainBox();
  Box sideBoxLo[SpaceDim];
  Box sideBoxHi[SpaceDim];
  for (int idir = 0; idir < SpaceDim; idir++)
    {
      sideBoxLo[idir] = adjCellLo(domainBox, idir, 1);
      sideBoxLo[idir].shift(idir,  1);
      sideBoxHi[idir] = adjCellHi(domainBox, idir, 1);
      sideBoxHi[idir].shift(idir, -1);
      m_vofItIrregDomLo[idir].define( m_eblg.getDBL()); // vofiterator cache for domain lo
      m_vofItIrregDomHi[idir].define( m_eblg.getDBL()); // vofiterator cache for domain hi
    }

  CH_START(t1);
  for (DataIterator dit = m_eblg.getDBL().dataIterator(); dit.ok(); ++dit)
    {
      const Box& curBox = m_eblg.getDBL().get(dit());
      const EBISBox& curEBISBox = m_eblg.getEBISL()[dit()];
      const EBGraph& curEBGraph = curEBISBox.getEBGraph();

      IntVectSet notRegular = curEBISBox.getIrregIVS  (curBox);

      BaseIVFAB<VoFStencil>& curStencilBaseIVFAB = opStencil[dit()];
      BaseIVFAB<Real>&       alphaWeight  = m_alphaDiagWeight[dit()];
      BaseIVFAB<Real>&        betaWeight  = m_betaDiagWeight[dit()];
      curStencilBaseIVFAB.define(notRegular,curEBGraph, 1);
      alphaWeight.define(        notRegular,curEBGraph, 1);
      betaWeight.define(         notRegular,curEBGraph, 1);

      //cache the vofIterators
      m_vofItIrreg[dit()].define(notRegular,curEBISBox.getEBGraph());
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          IntVectSet loIrreg = notRegular;
          IntVectSet hiIrreg = notRegular;
          loIrreg &= sideBoxLo[idir];
          hiIrreg &= sideBoxHi[idir];
          m_vofItIrregDomLo[idir][dit()].define(loIrreg,curEBISBox.getEBGraph());
          m_vofItIrregDomHi[idir][dit()].define(hiIrreg,curEBISBox.getEBGraph());
        }

      //Operator vofstencil
      VoFIterator& vofit = m_vofItIrreg[dit()];
      for (vofit.reset(); vofit.ok(); ++vofit)
        {
          const VolIndex& VoF = vofit();

          VoFStencil& curStencil = curStencilBaseIVFAB(VoF,0);
          getOpVoFStencil(curStencil,curEBISBox,VoF);

          Real& curAlphaWeight  = alphaWeight(VoF,0);
          Real& curBetaWeight  =   betaWeight(VoF,0);

          const Real kappa = curEBISBox.volFrac(VoF);

          curAlphaWeight = kappa;
          curBetaWeight = 0.0;
          for (int i = 0; i < curStencil.size(); i++)
            {
              if (curStencil.vof(i) == VoF)
                {
                  curBetaWeight += curStencil.weight(i);
                  break;
                }
            }

          curStencil *= m_beta;
          if (m_alpha != 0)
            {
              curStencil.add(VoF, kappa*m_alpha);
            }

          const IntVect& iv = VoF.gridIndex();

          for (int idir = 0; idir < SpaceDim; idir++)
            {
              Box loSide = bdryLo(m_eblg.getDomain(),idir);
              loSide.shiftHalf(idir,1);
              if (loSide.contains(iv))
                {
                  Real faceAreaFrac = 0.0;
                  Vector<FaceIndex> faces = curEBISBox.getFaces(VoF,idir,Side::Lo);
                  for (int i = 0; i < faces.size(); i++)
                    {
                      faceAreaFrac += curEBISBox.areaFrac(faces[i]);
                    }
                  curBetaWeight += -faceAreaFrac * m_invDx2[idir];
                }

              Box hiSide = bdryHi(m_eblg.getDomain(),idir);
              hiSide.shiftHalf(idir,-1);
              if (hiSide.contains(iv))
                {
                  Real faceAreaFrac = 0.0;
                  Vector<FaceIndex> faces = curEBISBox.getFaces(VoF,idir,Side::Hi);
                  for (int i = 0; i < faces.size(); i++)
                    {
                      faceAreaFrac += curEBISBox.areaFrac(faces[i]);
                    }
                  curBetaWeight += -faceAreaFrac * m_invDx2[idir];
                }
            }

          if (curBetaWeight == 0.0)
            {
              curBetaWeight = -1.0;
            }
          if (fluxStencil != NULL)
            {
              BaseIVFAB<VoFStencil>& fluxStencilBaseIVFAB = (*fluxStencil)[dit()];
              VoFStencil& fluxStencilPt = fluxStencilBaseIVFAB(VoF,0);
              curStencil += fluxStencilPt;
            }
        }//vofit

      //Operator ebstencil
      m_opEBStencil[dit()] = RefCountedPtr<EBStencil>(new EBStencil(m_vofItIrreg[dit()].getVector(), opStencil[dit()], m_eblg.getDBL().get(dit()), m_eblg.getEBISL()[dit()], m_ghostCellsPhi, m_ghostCellsRHS));

    }//dit
  CH_STOP(t1);

  //color vofstencils and ebstencils
  IntVect color = IntVect::Zero;
  IntVect limit = IntVect::Unit;
  color[0]=-1;
  // Loop over all possibilities (in all dimensions)
  CH_START(t2);
  for (int icolor = 0; icolor < m_colors.size(); icolor++)
    {
      m_colorEBStencil[icolor].define(m_eblg.getDBL());
      m_rhsColorEBStencil[icolor].define(m_eblg.getDBL());
      m_vofItIrregColor[icolor].define( m_eblg.getDBL());
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          m_vofItIrregColorDomLo[icolor][idir].define( m_eblg.getDBL());
          m_vofItIrregColorDomHi[icolor][idir].define( m_eblg.getDBL());
        }
      for (DataIterator dit = m_eblg.getDBL().dataIterator(); dit.ok(); ++dit)
        {
          IntVectSet ivsColor;
          const EBISBox& curEBISBox = m_eblg.getEBISL()[dit()];
          const EBGraph& curEBGraph = curEBISBox.getEBGraph();
          Box dblBox( m_eblg.getDBL().get(dit()) );

          BaseIVFAB<VoFStencil>& curStencilBaseIVFAB = opStencil[dit()];
          BaseIVFAB<VoFStencil>& colorStencilBaseIVFAB = colorStencil[dit()];
          BaseIVFAB<VoFStencil>& rhsColorStencilBaseIVFAB = rhsColorStencil[dit()];

          const BaseIVFAB<Real>& curAlphaWeight = m_alphaDiagWeight[dit()];
          const BaseIVFAB<Real>& curBetaWeight  = m_betaDiagWeight[dit()];

          VoFIterator& vofit = m_vofItIrreg[dit()];

          int vofOrdinal = 0;
          for (vofit.reset(); vofit.ok(); ++vofit, ++vofOrdinal)
            {
              const VolIndex& vof = vofit();
              const IntVect& iv = vof.gridIndex();

              bool doThisVoF = true;
              for (int idir = 0; idir < SpaceDim; idir++)
                {
                  if (iv[idir] % 2 != color[idir])
                    {
                      doThisVoF = false;
                      break;
                    }
                }

              if (doThisVoF)
                {
                  ivsColor |= iv;
                }
            }

          m_vofItIrregColor[icolor][dit()].define(ivsColor, curEBGraph);
          colorStencilBaseIVFAB.define(ivsColor, curEBGraph, 1);
          rhsColorStencilBaseIVFAB.define(ivsColor, curEBGraph, 1);

          for (int idir = 0; idir < SpaceDim; idir++)
            {
              IntVectSet loIrregColor = ivsColor;
              IntVectSet hiIrregColor = ivsColor;
              loIrregColor &= sideBoxLo[idir];
              hiIrregColor &= sideBoxHi[idir];
              m_vofItIrregColorDomLo[icolor][idir][dit()].define(loIrregColor,curEBISBox.getEBGraph());
              m_vofItIrregColorDomHi[icolor][idir][dit()].define(hiIrregColor,curEBISBox.getEBGraph());
            }

          VoFIterator& vofitcolor = m_vofItIrregColor[icolor][dit()];
          for (vofitcolor.reset(); vofitcolor.ok(); ++vofitcolor)
            {
              const VolIndex& vof = vofitcolor();

              VoFStencil& curStencil = curStencilBaseIVFAB(vof,0);
              VoFStencil& colorStencil = colorStencilBaseIVFAB(vof,0);
              VoFStencil& rhsColorStencil = rhsColorStencilBaseIVFAB(vof,0);
              Real weightIrreg = m_alpha*curAlphaWeight(vof,0) + m_beta*curBetaWeight(vof,0);
              colorStencil = curStencil;
              colorStencil *= (-1.0/weightIrreg);
              colorStencil.add(vof, 1.0);
              rhsColorStencil.add(vof, 1.0/weightIrreg);
            }

          Vector<VolIndex> srcVofs = m_vofItIrregColor[icolor][dit()].getVector();

          //color ebstencils
          m_colorEBStencil[icolor][dit()]    = RefCountedPtr<EBStencil>(new EBStencil(srcVofs, colorStencil[dit()]   ,  m_eblg.getDBL().get(dit()), m_eblg.getEBISL()[dit()], m_ghostCellsPhi, m_ghostCellsPhi));
          m_rhsColorEBStencil[icolor][dit()] = RefCountedPtr<EBStencil>(new EBStencil(srcVofs, rhsColorStencil[dit()]     , m_eblg.getDBL().get(dit()) , m_eblg.getEBISL()[dit()], m_ghostCellsRHS, m_ghostCellsPhi));

        }//dit
    }//color
  CH_STOP(t2);
}
Exemplo n.º 14
0
void ebamrieuler(const AMRParameters& a_params,
                 const ProblemDomain& a_coarsestDomain)
{

  CH_TIMERS("ebamrins_driver");
  CH_TIMER("define_ebamrnosubcycle_solver", t3);
  CH_TIMER("init_ebamrnosubcycle_solver",   t4);
  CH_TIMER("run ebamrnosubcycle_solver",   t5);

  // read inputs
  ParmParse pp;

  int flowDir;
  pp.get("flow_dir", flowDir);
  Vector<int> nCells;
  pp.getarr("n_cell",  nCells,0,SpaceDim);

  Real inflowVel;
  pp.get("inflow_vel", inflowVel);

  Real viscosity = 0.0;
  pp.get("viscosity", viscosity);

  int idoSlipWalls;
  pp.get("do_slip_walls", idoSlipWalls);
  bool doSlip = idoSlipWalls==1;
  IntVect doSlipWallsLo = idoSlipWalls*IntVect::Unit;
  IntVect doSlipWallsHi = idoSlipWalls*IntVect::Unit;
  Vector<int> slipWallsLo,slipWallsHi;
  if (doSlip)
    {
      pp.getarr("do_slip_walls_hi",slipWallsHi,0,SpaceDim);
      pp.getarr("do_slip_walls_lo",slipWallsLo,0,SpaceDim);
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          doSlipWallsHi[idir] = slipWallsHi[idir];
          doSlipWallsLo[idir] = slipWallsLo[idir];
        }
    }

  int orderEBBC = 1;
  pp.query("order_ebbc", orderEBBC);

  bool doPoiseInflow = false;
  pp.query("poiseuille_inflow", doPoiseInflow);

  bool initPoiseData = false;
  pp.query("poiseuille_init", initPoiseData);
  if (initPoiseData)  
  pout() << "Doing Poiseuille initialization" << endl;

  RefCountedPtr<PoiseuilleInflowBCValue> poiseBCValue;//make this BaseBCValue if also doing constant values
  if (doPoiseInflow)
    {
      pout() << "Doing Poiseuille inflow" << endl;
      RealVect centerPt, tubeAxis;
      Real tubeRadius;
      Vector<Real> centerPtVect, tubeAxisVect;
      pp.get("poise_profile_radius", tubeRadius);
      pp.getarr("poise_profile_center_pt",  centerPtVect,0,SpaceDim);
      pp.getarr("poise_profile_axis",       tubeAxisVect,0,SpaceDim);
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          centerPt[idir] = centerPtVect[idir];
          tubeAxis[idir] = tubeAxisVect[idir];
        }

      Real maxVelFactor;//= 1.5 for planar geometry, = 2.0 for cylindrical
      pp.get("poise_maxvel_factor", maxVelFactor);
      Real maxVel = maxVelFactor*inflowVel;

      poiseBCValue = RefCountedPtr<PoiseuilleInflowBCValue>(new PoiseuilleInflowBCValue(centerPt,tubeAxis,tubeRadius,maxVel,flowDir));
    }

  bool doWomersleyInflow = false;
  pp.query("womersley_inflow", doWomersleyInflow);

  InflowOutflowIBCFactory ibc(flowDir,
                              inflowVel,
                              orderEBBC,
                              doSlipWallsHi,
                              doSlipWallsLo,
                              doPoiseInflow,
                              initPoiseData,
                              poiseBCValue,
                              doWomersleyInflow);

  CH_START(t3);

  EBAMRNoSubcycle kahuna(a_params, ibc, a_coarsestDomain, viscosity);

  CH_STOP(t3);

  CH_START(t4);
  if (!pp.contains("restart_file"))
    {
      pout() << "starting fresh AMR run" << endl;
      kahuna.setupForAMRRun();
    }
  else
    {
      std::string restart_file;
      pp.get("restart_file",restart_file);
      pout() << " restarting from file " << restart_file << endl;
      kahuna.setupForRestart(restart_file);
    }
  CH_STOP(t4);

  int maxStep;
  pp.get("max_step", maxStep);

  Real stopTime = 0.0;
  pp.get("max_time",stopTime);

  CH_START(t5);

  Real fixedDt = 0.;
  pp.query("fixed_dt", fixedDt);
  if (fixedDt > 1.e-12)
    {
      kahuna.useFixedDt(fixedDt);
    }

  kahuna.run(stopTime, maxStep);

  CH_STOP(t5);

}
Exemplo n.º 15
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);
    }
}