Пример #1
0
/** Initializes the DisjointBoxLayouts, each step. */
void
EBRestart::makeHierarchy(Vector<DisjointBoxLayout>& a_dbl,
                         const ProblemDomain&       a_baseDomain,
                         const IntVectSet&          a_baseTags,
                         const Vector<int>&         a_refRatios,
                         const InputParams&         a_inputs)
{
  a_dbl.resize(a_inputs.nlevs);
  Real fillRatio     = 0.85;
  BRMeshRefine regridder(a_baseDomain, a_refRatios, fillRatio,
                         a_inputs.blocking_factor,
                         a_inputs.buffer_size, a_inputs.max_size);

  Vector<Vector<Box> > oldGrids(a_inputs.nlevs,1), newGrids(a_inputs.nlevs);
  oldGrids[0][0]=a_baseDomain.domainBox();
  for ( int l=1; l<a_inputs.nlevs; ++l )
  {
    oldGrids[l][0]=coarsen(oldGrids[l-1][0], a_refRatios[l-1]);
    // FIXME: is a_refRatios[l-1] correct??
  }

  regridder.regrid(newGrids, a_baseTags, 0, 1, oldGrids);
  // 0 is baselevel, 1 is toplevel.

  Vector<int> procs;
  for (int l=0; l<a_inputs.nlevs; l++)
  {
    newGrids[l].sort();
    LoadBalance(procs, newGrids[l]);
    a_dbl[l] = DisjointBoxLayout(newGrids[l], procs);
  }
}
Пример #2
0
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;
}
Пример #3
0
void do_geo(DisjointBoxLayout&              a_dbl,
            EBISLayout       &              a_ebisl,
            Box              &              a_domain,
            Real             &              a_dx )
{

  //define grids
  int len = 32;
  int mid = len/2;
  Real xdom = 1.0;
  a_dx = xdom/len;
  const IntVect hi = (len-1)*IntVect::Unit;
  a_domain=  Box(IntVect::Zero, hi);
  Vector<Box> boxes(4);
  Vector<int> procs(4);
  boxes[0] = Box(IntVect(D_DECL(0  ,  0,   0)), IntVect(D_DECL(mid-1, mid-1, len-1)));
  boxes[1] = Box(IntVect(D_DECL(0  ,mid,   0)), IntVect(D_DECL(mid-1, len-1, len-1)));
  boxes[2] = Box(IntVect(D_DECL(mid,  0,   0)), IntVect(D_DECL(len-1, mid-1, len-1)));
  boxes[3] = Box(IntVect(D_DECL(mid,mid,   0)), IntVect(D_DECL(len-1, len-1, len-1)));

  LoadBalance(procs, boxes);
  /**
  int loProc = 0;
  int hiProc = numProc() -1;
  procs[0] = loProc;
  procs[1] = hiProc;
  procs[2] = loProc;
  procs[3] = hiProc;
  **/

  a_dbl = DisjointBoxLayout(boxes, procs);

  //define geometry
  RealVect rampNormal = RealVect::Zero;
  rampNormal[0] = -0.5;
  rampNormal[1] = 0.866025404;

  Real rampAlpha = -0.0625;

  RealVect rampPoint = RealVect::Zero;
  rampPoint[0] = rampAlpha / rampNormal[0];

  bool inside = true;

  PlaneIF ramp(rampNormal,rampPoint,inside);

  RealVect vectDx = RealVect::Unit;
  vectDx *= a_dx;

  GeometryShop mygeom( ramp, 0, vectDx );
  RealVect origin = RealVect::Zero;

  EBIndexSpace *ebisPtr = Chombo_EBIS::instance();
  ebisPtr->define(a_domain, origin, a_dx, mygeom);

  //fill layout
  ebisPtr->fillEBISLayout(a_ebisl, a_dbl, a_domain, 4 );
}
Пример #4
0
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;
}
Пример #5
0
void
makeLevelData(const Vector<Box>& boxes,
              LevelData<FArrayBox>& levelFab)
{
  Vector<int> procIDs(boxes.size());
  LoadBalance(procIDs, boxes);

  DisjointBoxLayout dbl1(boxes, procIDs);
  levelFab.define(dbl1, 1);
}
Пример #6
0
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 _tmain(int argc, _TCHAR* argv[])
{
	int								nRank, nTotalRank;
	double							fStartTime, fEndTime;

	MPI_Init(NULL, NULL);
	MPI_Comm_size(MPI_COMM_WORLD, &nTotalRank);
	MPI_Comm_rank(MPI_COMM_WORLD, &nRank);

	initVariables();
	LoadBalance(nTotalRank, nRank, atoi(argv[1]));
	
	if( 0 == nRank )
		fStartTime = MPI_Wtime();

	if(LoadMatrixNVectorData(g_nSize, atoi(argv[2])))
	{
		if( 0 == nRank )
		{
			fEndTime = MPI_Wtime();
			printf("File Read Time: %lf\n", fEndTime - fStartTime);
		}

		MVMul();
		
		if( 0 == nRank )
		{
			fStartTime = MPI_Wtime();
			printf("MVMul Time: %lf\n", fStartTime - fEndTime);
		}

		SaveResult(nRank, nTotalRank);

		if( 0 == nRank )
		{
			fEndTime = MPI_Wtime();
			printf("File Writing Time: %lf\n", fEndTime - fStartTime);
		}
	}
	else
	{
		if( 0 == nRank )
			printf("Can't allocate memeory!\n");
	}

	FinalVariables();

	MPI_Finalize();
	return 0;
}
Пример #8
0
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;
}
Пример #9
0
int
testComputeSum()
{
  int status = 0;


  int numCells = 32;
  Real domainSize = 2.0;
  IntVect loVect = IntVect::Zero;
  IntVect hiVect = (numCells-1)*IntVect::Unit;
  Box domainBox(loVect, hiVect);
  ProblemDomain baseDomain(domainBox);

  int maxBoxSize = numCells/2;

  Vector<Box> vectBoxes;
  domainSplit(baseDomain, vectBoxes, maxBoxSize, 1);
  Vector<int> procAssign(vectBoxes.size(), 0);
  LoadBalance(procAssign, vectBoxes);
  DisjointBoxLayout level0Grids(vectBoxes, procAssign, baseDomain);
  Real dx0 = domainSize/numCells;


  // first test -- single level
  {
    int numLevels = 1;
    Vector<LevelData<FArrayBox>* > phi(numLevels, NULL);
    IntVect ghostVect = IntVect::Unit;
    phi[0] = new LevelData<FArrayBox>(level0Grids, 1, ghostVect);

    initData(*phi[0], dx0);

    Vector<int> nRef(numLevels, 4);
    Real sum = computeSum(phi, nRef, dx0);

    Real exactVal = D_TERM6(domainSize, *domainSize, *domainSize,
                            *domainSize, *domainSize, *domainSize);

    if (abs(sum - exactVal) > tolerance)
      {
        if (verbose)
          {
            pout() << "Single-level computeSum: expected" << exactVal
                   << ", computed sum = " << sum << endl;
          }
        status += 1;
      }

    // clean up storage
    delete phi[0];
    phi[0] = NULL;

  }



  // second test -- single level with maxLevel > 0
  {
    int numLevels = 3;
    Vector<LevelData<FArrayBox>* > phi(numLevels, NULL);
    IntVect ghostVect = IntVect::Unit;
    // levels 1 and 2 are undefined
    phi[0] = new LevelData<FArrayBox>(level0Grids, 1, ghostVect);

    initData(*phi[0], dx0);

    Vector<int> nRef(numLevels, 4);
    Real sum = computeSum(phi, nRef, dx0);

    Real exactVal = D_TERM6(domainSize, *domainSize, *domainSize,
                            *domainSize, *domainSize, *domainSize);

    if (abs(sum - exactVal) > tolerance)
      {
        if (verbose)
          {
            pout() << "single level, maxLevel > 0 computeSum: expected"
                   << exactVal
                   << ", computed sum = " << sum << endl;
          }
        status += 10;
      }

    // clean up storage
    delete phi[0];
    phi[0] = NULL;

  }


  // third test -- multiple levels
  {
    int numLevels = 3;
    Vector<int> nRef(numLevels, 4);

    Vector<LevelData<FArrayBox>* > phi(numLevels, NULL);
    IntVect ghostVect = IntVect::Unit;
    // level 0
    phi[0] = new LevelData<FArrayBox>(level0Grids, 1, ghostVect);

    initData(*phi[0], dx0);

    // level 1:
    {
      Vector<Box> level1Boxes;

      // do this in a bit of a silly way
      int quarterDomain = numCells / 4;
      int threeQuarterDomain = 3*numCells/4;
      IntVect loVect(quarterDomain);
      IntVect hiVect(IntVect::Unit*threeQuarterDomain);
      hiVect -= IntVect::Unit;
      Box spanBox(loVect, hiVect);
      int maxBox1 = quarterDomain;

      ProblemDomain level1Domain(baseDomain);
      level1Domain.refine(nRef[0]);

      ProblemDomain spanDomain(spanBox);
      domainSplit(spanDomain, level1Boxes, maxBox1, 1);
      Vector<int> level1ProcAssign(level1Boxes.size(), 0);
      LoadBalance(level1ProcAssign, level1Boxes);
      DisjointBoxLayout level1Grids(level1Boxes, level1ProcAssign,
                                    level1Domain);

      phi[1] = new LevelData<FArrayBox>(level1Grids, 1, IntVect::Unit);

      Real dx1 = dx0/nRef[0];

      initData(*phi[1], dx1);

    }

    Real sum = computeSum(phi, nRef, dx0);

    Real exactVal = D_TERM6(domainSize, *domainSize, *domainSize,
                            *domainSize, *domainSize, *domainSize);

    if (abs(sum - exactVal) > tolerance)
      {
        if (verbose)
          {
            pout() << "single level, maxLevel > 0 computeSum: expected"
                   << exactVal
                   << ", computed sum = " << sum << endl;
          }
        status += 10;
      }

    // clean up storage
    delete phi[0];
    phi[0] = NULL;

    delete phi[1];
    phi[1] = NULL;

  }

  return status;
}
Пример #10
0
int getError(LevelData<EBCellFAB>& a_errorFine,
             const EBISLayout& a_ebislFine,
             const DisjointBoxLayout& a_gridsFine,
             const Box& a_domainFine,
             const RealVect& a_dxFine)
{
  ParmParse pp;
  int eekflag = 0;
  int nvar = 1;
  int nghost = 1;
  int nref = 2;
  pp.get("ref_ratio",nref);
  int maxsize;
  pp.get("maxboxsize",maxsize);
  //generate coarse dx, domain
  Box domainCoar = coarsen(a_domainFine, nref);

  RealVect dxCoar = nref*a_dxFine;
  //make the coarse grids completely cover the domain
  Vector<Box> vbox;
  domainSplit(domainCoar, vbox,  maxsize);
  Vector<int>  procAssign;
  eekflag = LoadBalance(procAssign,vbox);
  DisjointBoxLayout gridsCoar(vbox, procAssign);
  //make coarse ebisl
  EBISLayout ebislCoar;
  eekflag = makeEBISL(ebislCoar, gridsCoar, domainCoar, nghost);
  if (eekflag != 0) return eekflag;
  // pout() << "getError dom coar = " << domainCoar << endl;;
  // pout() << "getError grids coar = " << gridsCoar << endl;;
  // pout() << "getError dom fine = " << a_domainFine << endl;;
  // pout() << "getError grids fine = " << a_gridsFine << endl;;

  //create data at both refinemenets
  EBCellFactory ebcellfactFine(a_ebislFine);
  EBCellFactory ebcellfactCoar(ebislCoar);
  LevelData<EBCellFAB> phiFine(a_gridsFine, nvar,
                               IntVect::Unit,ebcellfactFine);
  LevelData<EBCellFAB> phiCoar(gridsCoar, nvar,
                               IntVect::Unit,ebcellfactCoar);

  //fill phi fine and phiCExact
  //put phiFexact into a_errorFine and phiFine
  //this should make the error at the interior = 0
  for (DataIterator dit = a_gridsFine.dataIterator();
      dit.ok(); ++dit)
    {
      Box grownBox = grow(a_gridsFine.get(dit()), 1);
      grownBox &= a_domainFine;
      IntVectSet ivsBox(grownBox);
      phiFine[dit()].setVal(0.0);
      a_errorFine[dit()].setVal(0.0);
      EBCellFAB& phiFineFAB = phiFine[dit()];
      EBCellFAB& errFineFAB = a_errorFine[dit()];
      phiFineFAB.setCoveredCellVal(0.0,0);
      for (VoFIterator vofit(ivsBox, a_ebislFine[dit()].getEBGraph());
          vofit.ok(); ++vofit)
        {
          const VolIndex& vof = vofit();
          Real rightAns = exactFunc(vof.gridIndex(), a_dxFine);
          phiFineFAB(vof, 0) = rightAns;
          errFineFAB(vof, 0) = rightAns;
        }
    }

  for (DataIterator dit = gridsCoar.dataIterator();
      dit.ok(); ++dit)
    {
      Box grownBox = grow(gridsCoar.get(dit()), 1);
      grownBox &= domainCoar;
      IntVectSet ivsBox(grownBox);
      EBCellFAB& phiCoarFAB = phiCoar[dit()];
      phiCoarFAB.setCoveredCellVal(0.0,0);
      for (VoFIterator vofit(ivsBox, ebislCoar[dit()].getEBGraph());
          vofit.ok(); ++vofit)
        {
          const VolIndex& vof = vofit();
          Real rightAns = exactFunc(vof.gridIndex(), dxCoar);
          phiCoarFAB(vof, 0) = rightAns;
        }
    }


  LayoutData<IntVectSet> cfivs;
  EBArith::defineCFIVS(cfivs, a_gridsFine, a_domainFine);
  EBQuadCFInterp interpOp(a_gridsFine,  gridsCoar,
                          a_ebislFine,  ebislCoar,
                          domainCoar, nref, nvar,
                          cfivs, Chombo_EBIS::instance(), true);

  Interval interv(0,0);
  interpOp.interpolate(phiFine, phiCoar, interv);

  //error = phiF - phiFExact
  for (DataIterator dit = a_gridsFine.dataIterator();
      dit.ok(); ++dit)
    {
      EBCellFAB& errorFAB = a_errorFine[dit()];
      EBCellFAB& phiFineFAB = phiFine[dit()];

      errorFAB -= phiFineFAB;
    }

  return eekflag;
}
Пример #11
0
void
EBCoarseAverage::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)
{
  CH_TIME("EBCoarseAverage::define");
  CH_assert(ebisPtr->isDefined());

  ProblemDomain domainFine = a_domainCoar;
  domainFine.refine(a_nref);
  EBLevelGrid eblgFine;
  EBLevelGrid eblgCoar = EBLevelGrid(a_dblCoar, a_ebislCoar, a_domainCoar);
  EBLevelGrid eblgCoFi;

  //check to see if the input layout is coarsenable.
  //if so, proceed with ordinary drill
  //otherwise, see if the layout covers the domain.
  //if it does, we can use domainsplit
  if (a_dblFine.coarsenable(a_nref))
    {
      eblgFine = EBLevelGrid(a_dblFine, a_ebislFine,   domainFine);
      m_useFineBuffer = false;
    }
  else
    {
      Box fineDomBox = refine(a_domainCoar.domainBox(), a_nref);
      int numPtsDom = fineDomBox.numPts();
      //no need for gathers here because the meta data is global
      int numPtsLayout = 0;
      for (LayoutIterator lit = a_dblFine.layoutIterator(); lit.ok(); ++lit)
        {
          numPtsLayout += a_dblFine.get(lit()).numPts();
        }
      bool coveringDomain = (numPtsDom == numPtsLayout);
      if (coveringDomain)
        {
          m_useFineBuffer = true;
          int maxBoxSize = 4*a_nref;
          Vector<Box> boxes;
          Vector<int> procs;
          domainSplit(fineDomBox, boxes, maxBoxSize);
          mortonOrdering(boxes);
          LoadBalance(procs, boxes);
          DisjointBoxLayout dblBufFine(boxes, procs);

          eblgFine = EBLevelGrid(dblBufFine, domainFine, 2, eblgCoar.getEBIS());
        }
      else
        {
          pout() << "EBCoarseAverage::input layout is not coarsenable and does not cover the domain--bailing out" << endl;
          MayDay::Error();
        }
    }

  coarsen(eblgCoFi, eblgFine, a_nref);
  define(eblgFine, eblgCoar, eblgCoFi, a_nref, a_nvar);
}
Пример #12
0
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;
}
Пример #13
0
int fluxRegTest()
{
#ifdef CH_USE_HDF5
  writeLevel(NULL);
#endif
  int retflag = 0;

  int nref;
  Vector<Box> fineboxes;
  Vector<Box> coarboxes;
  Box domf, domc;

  //set coarse and fine grid boxes
  setDefaults(nref, coarboxes,  fineboxes, domc, domf);

  {
    // first do nonperiodic test

    Interval interv(0,0);

    //set up coarse and fine grids
    DisjointBoxLayout dblFineCell,dblCoarCell;
    Vector<int> procAssignCoar(coarboxes.size(), 0);
    Vector<int> procAssignFine(fineboxes.size(), 0);
    LoadBalance(procAssignCoar, coarboxes);
    LoadBalance(procAssignFine, fineboxes);

    dblCoarCell.define(coarboxes, procAssignCoar);
    dblFineCell.define(fineboxes, procAssignFine);

    dblCoarCell.close();
    dblFineCell.close();

    LevelData<FArrayBox> coarData(dblCoarCell, 1);
    LevelData<FArrayBox> fineData(dblFineCell, 1);

    DataIterator coarIt = coarData.dataIterator();
    DataIterator fineIt = fineData.dataIterator();

    LevelFluxRegister fluxReg(dblFineCell,
                              dblCoarCell,
                              domf, nref,
                              1);

    //set data and flux registers to zero
    for (coarIt.reset(); coarIt.ok(); ++coarIt)
      coarData[coarIt()].setVal(0.);

    fluxReg.setToZero();

    //increment and decrement
    //flux registers with equal size fluxes
    Real scale = 1.0;
    Real fluxVal = 4.77;
    for (coarIt.reset(); coarIt.ok(); ++coarIt)
      {
        const Box&  cellBoxCoar = dblCoarCell.get(coarIt());
        for (int idir = 0; idir < SpaceDim; idir++)
          {
            Box edgeBoxCoar = surroundingNodes(cellBoxCoar, idir);
            FArrayBox edgeFlux(edgeBoxCoar,1);
            edgeFlux.setVal(fluxVal);
            DataIndex dataIndGlo = coarIt();
            fluxReg.incrementCoarse(edgeFlux, scale,
                                    dataIndGlo, interv, interv, idir);
          }
      }

    for (fineIt.reset(); fineIt.ok(); ++fineIt)
      {
        const Box&  cellBoxFine = dblFineCell.get(fineIt());
        for (int idir = 0; idir < SpaceDim; idir++)
          {
            Box edgeBoxFine = surroundingNodes(cellBoxFine, idir);
            FArrayBox edgeFlux(edgeBoxFine,1);
            edgeFlux.setVal(fluxVal);
            SideIterator sit;
            DataIndex dataIndGlo = fineIt();
            for (sit.reset(); sit.ok(); ++sit)
              {
                fluxReg.incrementFine(edgeFlux, scale,
                                      dataIndGlo,  interv, interv, idir, sit());
              }
          }
      }

    //reflux what ought to be zero into zero and the result should be zero
    fluxReg.reflux(coarData, scale);

    DataIterator datIt = coarData.dataIterator();
    for (datIt.reset(); datIt.ok(); ++datIt)
      {
        const FArrayBox& data = coarData[datIt()];
        Real rmax = Abs(data.max());
        Real rmin = Abs(data.min());
        if ((rmax > 1.0e-10)||(rmin > 1.0e-10))
          {
            pout() << indent << pgmname
                 << ": fluxRegister failed the nonperiodic conservation test = " << endl;
            retflag = 1;
          }
      }
  }
  // end non-periodic test

  // now do the same thing all over again, this time with a periodic domain
  {
    ProblemDomain coarseDomain(domc);
    ProblemDomain fineDomain(domf);
    for (int dir=0; dir<SpaceDim; dir++)
      {
        coarseDomain.setPeriodic(dir, true);
        fineDomain.setPeriodic(dir, true);
      }

    Interval interv(0,0);

    //set up coarse and fine grids
    DisjointBoxLayout dblFineCell,dblCoarCell;
    Vector<int> procAssignCoar(coarboxes.size(), 0);
    Vector<int> procAssignFine(fineboxes.size(), 0);
    LoadBalance(procAssignCoar, coarboxes);
    LoadBalance(procAssignFine, fineboxes);

    dblCoarCell.define(coarboxes, procAssignCoar, coarseDomain);
    dblFineCell.define(fineboxes, procAssignFine, fineDomain);

    dblCoarCell.close();
    dblFineCell.close();

    LevelData<FArrayBox> coarData(dblCoarCell, 1);
    LevelData<FArrayBox> fineData(dblFineCell, 1);

    DataIterator coarIt = coarData.dataIterator();
    DataIterator fineIt = fineData.dataIterator();

    LevelFluxRegister fluxReg(dblFineCell,
                              dblCoarCell,
                              fineDomain, nref,
                              1);

    //set data and flux registers to zero
    for (coarIt.reset(); coarIt.ok(); ++coarIt)
      coarData[coarIt()].setVal(0.);

    fluxReg.setToZero();

    //increment and decrement
    //flux registers with equal size fluxes
    Real scale = 1.0;
    Real fluxVal = 4.77;
    for (coarIt.reset(); coarIt.ok(); ++coarIt)
      {
        const Box&  cellBoxCoar = dblCoarCell.get(coarIt());
        for (int idir = 0; idir < SpaceDim; idir++)
          {
            Box edgeBoxCoar = surroundingNodes(cellBoxCoar, idir);
            FArrayBox edgeFlux(edgeBoxCoar,1);
            edgeFlux.setVal(fluxVal);
            DataIndex dataIndGlo = coarIt();
            fluxReg.incrementCoarse(edgeFlux, scale,
                                    dataIndGlo, interv, interv, idir);
          }
      }

    for (fineIt.reset(); fineIt.ok(); ++fineIt)
      {
        const Box&  cellBoxFine = dblFineCell.get(fineIt());
        for (int idir = 0; idir < SpaceDim; idir++)
          {
            Box edgeBoxFine = surroundingNodes(cellBoxFine, idir);
            FArrayBox edgeFlux(edgeBoxFine,1);
            edgeFlux.setVal(fluxVal);
            SideIterator sit;
            DataIndex dataIndGlo = fineIt();
            for (sit.reset(); sit.ok(); ++sit)
              {
                fluxReg.incrementFine(edgeFlux, scale,
                                      dataIndGlo,  interv, interv, idir, sit());
              }
          }
      }

    //reflux what ought to be zero into zero and the result should be zero
    fluxReg.reflux(coarData, scale);

    DataIterator datIt = coarData.dataIterator();
    for (datIt.reset(); datIt.ok(); ++datIt)
      {
        const FArrayBox& data = coarData[datIt()];
        Real rmax = Abs(data.max());
        Real rmin = Abs(data.min());
        if ((rmax > 1.0e-10)||(rmin > 1.0e-10))
          {
            pout() << indent << pgmname
                 << ": fluxRegister failed the periodic conservation test " << endl;
            retflag += 2;
          }
      }
  } // end periodic test

  return retflag;
}
Пример #14
0
int test()
{
#ifdef CH_USE_HDF5

  int error;
  HDF5Handle testFile;

  CH_assert(!testFile.isOpen());

  error = testFile.open("data.h5", HDF5Handle::CREATE);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "File creation failed "<<error<<endl;
      return error;
    }

  CH_assert(testFile.isOpen());

  Box domain(IntVect::Zero, 20*IntVect::Unit);

  DisjointBoxLayout plan1, plan2;
  {
    IntVectSet tags;

    IntVect center = 10*IntVect::Unit;

    setCircleTags(tags, 6, 1, center); //circle/sphere

    buildDisjointBoxLayout(plan1, tags, domain);

    tags.makeEmpty();

    setCircleTags(tags, 5, 2, center);

    buildDisjointBoxLayout(plan2, tags, domain);
  }
  if ( verbose )
  {
    pout() << "plan1: " << procID() << "...." << plan1 << endl;
    pout() << "plan2: " << procID() << "...." << plan2 << endl;
  }

  //test LayoutData<Real> specialization
  LayoutData<Real>  specialReal(plan1);


  LayoutData<Moment>   vlPlan(plan1);


  LevelData<BaseFab<int> > level1(plan1, 3, IntVect::Unit);

  LevelData<BaseFab<int> > level2;

  level2.define(level1);

  level2.define(plan2, 1);

  for (DataIterator i(level2.dataIterator()); i.ok(); ++i)
  {
    level2[i()].setVal(2);
  }

  level1.apply(values::setVal1);

  level2.apply(values::setVal2);

  HDF5HeaderData set1;
  Real dx=0.004;
  Box b1(IntVect(D_DECL6(1,2,1,1,2,1)), IntVect(D_DECL6(4,4,4,4,4,4)));
  Box b2(IntVect(D_DECL6(5,2,1,5,2,1)), IntVect(D_DECL6(12,4,4,12,4,4)));
  int currentStep = 2332;

  set1.m_string["name"] = "set1";
  set1.m_real["dx"] = dx;
  set1.m_int["currentStep"] = currentStep;
  set1.m_intvect["some intvect or other"] = b1.smallEnd();
  set1.m_box["b1"] = b1;
  set1.m_box["b2"] = b2;

  testFile.setGroupToLevel(1);

  error = write(testFile, plan1);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box write failed "<<error<<endl;
      return error;
    }

  error = write(testFile, level1, "level1 state vector");
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayoutData 1 write failed "<<error<<endl;
      return error;
    }

  testFile.setGroupToLevel(2);

  error = write(testFile, plan2);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box2 write failed "<<error<<endl;
      return error;
    }

  error = write(testFile, level2, "level2 state vector");
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl;
      return error;
    }

  LevelData<FArrayBox> state(plan2, 3);

  state.apply(values::setVal3);
  testFile.setGroupToLevel(0);
  set1.writeToFile(testFile);

  error = write(testFile, plan2);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box2 write failed "<<error<<endl;
      return error;
    }

  testFile.setGroup("/");

  error = writeLevel(testFile, 0, state, 2, 1, 0.001, b2, 2);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl;
      return error;
    }

  set1.writeToFile(testFile);
  set1.writeToFile(testFile);

  testFile.close();

 CH_assert(!testFile.isOpen());

  // test the utility functions ReadUGHDF5 and WriteUGHDF5

  WriteUGHDF5("UGIO.hdf5", plan2, state, domain);

  ReadUGHDF5("UGIO.hdf5", plan2, state, domain);
  //========================================================================
  //
  //  now, read this data back in
  //
  //========================================================================

  BoxLayoutData<BaseFab<int> > readlevel1, readlevel2;

  error = testFile.open("data.h5", HDF5Handle::OPEN_RDONLY);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "File open failed "<<error<<endl;
      return error;
    }

  testFile.setGroupToLevel(2);
  Vector<Box> boxes;
  error = read(testFile, boxes);

  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box read failed "<<error<<endl;
      return error;
    }
  boxes.sort();
  Vector<int> assign;
  error = LoadBalance(assign, boxes);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl;
      return error;
    }
  BoxLayout readplan2(boxes, assign);
  readplan2.close();
  error = read(testFile, readlevel2, "level2 state vector", readplan2);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl;
      return error;
    }

  testFile.setGroupToLevel(1);
  error = read(testFile, boxes);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "box read failed "<<error<<endl;
      return error;
    }

  error = LoadBalance(assign, boxes);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl;
      return error;
    }
  BoxLayout readplan1(boxes, assign);
  readplan1.close();
  if ( verbose )
  {
    pout() << "readplan1: " << procID() << "...." << readplan1 << endl;
    pout() << "readplan2: " << procID() << "...." << readplan2 << endl;
  }
  error = read(testFile, readlevel1, "level1 state vector", readplan1);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl;
      return error;
    }

  if ( verbose )
    pout() << plan1<<readplan1<<endl;

  // real test of IO, make sure the data is the same coming and going

  DataIterator l1  = level1.dataIterator();
  DataIterator rl1 = readlevel1.dataIterator();
  DataIterator l2  = level2.dataIterator();
  DataIterator rl2 = readlevel2.dataIterator();

  if (level1.boxLayout().size() != readlevel1.boxLayout().size())
    {
      if ( verbose )
        pout() << indent2 << "level1.size() != readl1.size() read failed "<<error<<endl;
      return 1;
    }
  if (level2.boxLayout().size() != readlevel2.boxLayout().size())
    {
      if ( verbose )
        pout() << indent2 << "level2.size() != readl2.size() read failed "<<error<<endl;
      return 1;
    }

  // we can assume that BoxLayout IO is tested in HDF5boxIO
  BaseFab<int>* before, *after;
  for (; l1.ok(); ++l1, ++rl1)
    {

      before = &(level1[l1()]); after = &(readlevel1[rl1()]);
      for (int c=0; c<before->nComp(); ++c)
        {
          for (BoxIterator it(level1.box(l1())); it.ok(); ++it)
            {
              if ((*before)(it(), c) != (*after)(it(), c))
                {
                  if ( verbose )
                    pout() << indent2 << "l1 != readl1 read failed "<<error<<endl;
                  return 2;
                }
            }
        }
    }

  for (; l2.ok(); ++l2, ++rl2)
    {

      before = &(level2[l2()]); after = &(readlevel2[rl2()]);
      for (int c=0; c<before->nComp(); ++c)
        {
          for (BoxIterator it(level2.box(l2())); it.ok(); ++it)
            {
              if ((*before)(it(), c) != (*after)(it(), c))
                {
                  if ( verbose )
                    pout() << indent2 << "level2 != readlevel2 read failed "<<error<<endl;
                  return 3;
                }
            }
        }
    }

  LevelData<FArrayBox> readState;
  Real dt, time;
  int refRatio;

  testFile.setGroup("/");

  error = readLevel(testFile, 0, readState, dx, dt, time, b2, refRatio);
  if (error != 0)
    {
      if ( verbose )
        pout() << indent2 << "readLevel failed "<<error<<endl;
      return error;
    }

#ifndef CH_MPI
  // OK, now try to read one FArrayBox at a time
  // problem with DataIterator and running the out-of-core in parallel, so
  // have to think about that for now  BVS.
  FArrayBox readFAB;
  Interval  interval(1,2);
  testFile.setGroup("/");
  int index=0;
  for (DataIterator dit(state.dataIterator()); dit.ok(); ++index,++dit)
        {
          FArrayBox& fab = state[dit()];
          readFArrayBox(testFile, readFAB, 0, index, interval);
          for (BoxIterator it(state.box(dit())) ; it.ok() ; ++it)
                {
                  if (readFAB(it(), 0) != fab(it(), 1))
                        {
                          if ( verbose )
                                pout() << indent2 << "state != after for out-of-core "<<error<<endl;
                          return 3;
                        }
                }
        }

#endif

  testFile.close();

 CH_assert(!testFile.isOpen());

#endif // CH_USE_HDF5

  return 0;
}
Пример #15
0
int getError(LevelData<EBCellFAB>& a_errorFine,
             const EBISLayout& a_ebislFine,
             const DisjointBoxLayout& a_gridsFine,
             const Box& a_domainFine,
             const Real& a_dxFine)
{
  ParmParse pp;
  int eekflag = 0;
  int nvar = 1;
  int nghost = 2;
  int nref = 2;
  int maxsize;
  pp.get("maxboxsize",maxsize);

  //generate coarse dx, domain
  Box domainCoar = coarsen(a_domainFine, nref);

  Real dxCoar = nref*a_dxFine;
  //make the coarse grids completely cover the domain
  Vector<Box> vbox;
  domainSplit(domainCoar, vbox,  maxsize);
  Vector<int>  procAssign;
  eekflag = LoadBalance(procAssign,vbox);
  DisjointBoxLayout gridsCoar(vbox, procAssign);
  //make coarse ebisl
  EBISLayout ebislCoar;
  eekflag = makeEBISL(ebislCoar, gridsCoar, domainCoar, nghost);
  if (eekflag != 0) return eekflag;
  // pout() << "getError dom coar = " << domainCoar << endl;;
  // pout() << "getError grids coar = " << gridsCoar << endl;;
  // pout() << "getError dom fine = " << a_domainFine << endl;;
  // pout() << "getError grids fine = " << a_gridsFine << endl;;

  //create data at both refinemenets
  IntVect ghost = IntVect::Unit;
  EBCellFactory ebcellfactFine(a_ebislFine);
  EBCellFactory ebcellfactCoar(ebislCoar);
  LevelData<EBCellFAB> phiFine(a_gridsFine,  nvar, ghost, ebcellfactFine);
  LevelData<EBCellFAB> oldFine(a_gridsFine,  nvar, ghost, ebcellfactFine);
  LevelData<EBCellFAB> phiCoarOld(gridsCoar, nvar, ghost, ebcellfactCoar);
  LevelData<EBCellFAB> phiCoarNew(gridsCoar, nvar, ghost, ebcellfactCoar);

  //fill phi fine and phiCExact
  //put phiFexact into a_errorFine and phiFine
  //this should make the error at the interior = 0
  for (DataIterator dit = a_gridsFine.dataIterator();
      dit.ok(); ++dit)
    {
      Box grownBox = grow(a_gridsFine.get(dit()), 1);
      grownBox &= a_domainFine;
      IntVectSet ivsBox(grownBox);
      phiFine[dit()].setVal(0.0);
      oldFine[dit()].setVal(0.0);
      a_errorFine[dit()].setVal(0.0);
      EBCellFAB& phiFineFAB = phiFine[dit()];
      EBCellFAB& oldFineFAB = oldFine[dit()];
      EBCellFAB& errFineFAB = a_errorFine[dit()];
      phiFineFAB.setCoveredCellVal(0.0,0);
      oldFineFAB.setCoveredCellVal(0.0,0);
      for (VoFIterator vofit(ivsBox, a_ebislFine[dit()].getEBGraph());
          vofit.ok(); ++vofit)
        {
          const VolIndex& vof = vofit();
          Real rightAns = exactFunc(vof.gridIndex(), a_dxFine, g_fineTime);
          phiFineFAB(vof, 0) = rightAns;
          oldFineFAB(vof, 0) = rightAns;
          errFineFAB(vof, 0) = rightAns;
        }
    }

  for (DataIterator dit = gridsCoar.dataIterator();
      dit.ok(); ++dit)
    {
      Box grownBox = grow(gridsCoar.get(dit()), 1);
      grownBox &= domainCoar;
      IntVectSet ivsBox(grownBox);
      EBCellFAB& phiCoarOldFAB = phiCoarOld[dit()];
      EBCellFAB& phiCoarNewFAB = phiCoarNew[dit()];
      phiCoarOldFAB.setCoveredCellVal(0.0,0);
      phiCoarNewFAB.setCoveredCellVal(0.0,0);
      for (VoFIterator vofit(ivsBox, ebislCoar[dit()].getEBGraph());
          vofit.ok(); ++vofit)
        {
          const VolIndex& vof = vofit();
          Real rightAnsOld = exactFunc(vof.gridIndex(), dxCoar,g_coarTimeOld);
          Real rightAnsNew = exactFunc(vof.gridIndex(), dxCoar,g_coarTimeNew);
          phiCoarOldFAB(vof, 0) = rightAnsOld;
          phiCoarNewFAB(vof, 0) = rightAnsNew;
        }
    }

  //interpolate phiC onto phiF
  AggEBPWLFillPatch interpOp(a_gridsFine, gridsCoar,
                             a_ebislFine, ebislCoar,
                             domainCoar, nref, nvar,
                             1, ghost);

  //interpolate phiC onto phiF
  EBPWLFillPatch oldinterpOp(a_gridsFine, gridsCoar,
                             a_ebislFine, ebislCoar,
                             domainCoar, nref, nvar, 1);


  Interval zeroiv(0,0);
  interpOp.interpolate(phiFine, phiCoarOld, phiCoarNew,
                       g_coarTimeOld, g_coarTimeNew,
                       g_fineTime, zeroiv);

  oldinterpOp.interpolate(oldFine, phiCoarOld, phiCoarNew,
                          g_coarTimeOld, g_coarTimeNew,
                          g_fineTime, zeroiv);
  //error = phiF - phiFExact
  int ibox = 0;
  for (DataIterator dit = a_gridsFine.dataIterator();
      dit.ok(); ++dit, ++ibox)
    {
      Box grownBox = grow(a_gridsFine.get(dit()), 1);
      grownBox &= a_domainFine;
      IntVectSet ivsBox(grownBox);

      EBCellFAB& phiFineFAB = phiFine[dit()];
      EBCellFAB& oldFineFAB = oldFine[dit()];
      Real     maxDiff = 0;
      VolIndex vofDiff;
      bool found = false;
      for (VoFIterator vofit(ivsBox, a_ebislFine[dit()].getEBGraph());
          vofit.ok(); ++vofit)
        {
          const VolIndex& vof = vofit();
          Real diff = Abs(phiFineFAB(vof,0)-oldFineFAB(vof,0));
          if (diff > maxDiff)
            {
              found = true;
              vofDiff  = vof;
              maxDiff = diff;
            }
        }
      if (found)
        {
          pout() << "max diff   = " << maxDiff << endl;
          pout() << "at intvect = " << vofDiff.gridIndex() << endl;
          pout() << "at box num = " << ibox << endl;
        }

      EBCellFAB& errorFAB = a_errorFine[dit()];
      errorFAB -= phiFineFAB;
    }

  return eekflag;
}
Пример #16
0
PetscErrorCode setupGrids( Vector<int> &a_refratios,  // out
                           Vector<ProblemDomain> &a_domains, // out
                           Vector<DisjointBoxLayout> &a_grids, // in/out
                           int a_nLevs,
                           Real &a_cdx, // out
                           Vector<RefCountedPtr<LevelData<FArrayBox> > > a_exact,
                           Vector<RefCountedPtr<LevelData<FArrayBox> > > a_phi,
                           Real a_max_norm_error,
                           Vector<IntVectSet> &a_tagVects,
                           bool &a_same // out
                           )
{
  CH_TIME("setupGrids");
  const int new_level=a_nLevs-1;
  bool isperiodic[3] = {false,false,false};
  PetscFunctionBeginUser;

  a_cdx = 1./s_nCells0; // out

  a_refratios.resize(a_nLevs-1);
  a_domains.resize(a_nLevs);
  a_grids.resize(a_nLevs);

  if (a_nLevs==1)
    {
      Vector<int> procAssign;
      Vector<Box> boxvector;
      Box levbox(IntVect::Zero,(s_nCells0-1)*IntVect::Unit), dombox=levbox;
      pout() << "setupGrids for level " << new_level+1 << "/" << a_nLevs << ". level domain " << levbox << endl;
      domainSplit(levbox, boxvector, s_maxboxsz, s_blockingfactor); // need blocking factor of 4 for C-F
      LoadBalance( procAssign, boxvector );
      a_grids[new_level].define(boxvector,procAssign);
      a_domains[new_level].define(dombox,isperiodic);
      a_same = false;
    }
  else
    {
      Vector<Vector<Box> > old_grids(a_nLevs-1);
      int new_finest_level;
      Real fillRatio = .8;
      BRMeshRefine refiner;
      Box curr_dom_box;
      static double thresh;

      // refratio
      a_refratios[new_level-1] = s_refRatio;
      // make new domain
      {
        Box dombox = a_domains[new_level-1].domainBox();
        dombox.refine(s_refRatio);
        a_domains[new_level].define(dombox,isperiodic);
      }

      refiner.define(a_domains[0],a_refratios,fillRatio,s_blockingfactor,s_nesting,s_maxboxsz);

      Real dx = a_cdx;
      if (a_nLevs==2)
        {
          // get max_grad on coarsest level - has the whole domain
          double max_ = 0.;
          const DisjointBoxLayout& dbl = a_grids[0];
          for (DataIterator dit = dbl.dataIterator(); dit.ok(); ++dit)
            {
              FArrayBox& exactFAB = (*a_exact[0])[dit];
              FArrayBox& phiFAB = (*a_phi[0])[dit];
              Box region = dbl[dit];
              for (BoxIterator bit(region); bit.ok(); ++bit)
                {
                  const IntVect& iv = bit();
                  Real grad = 0., tt;
                  if (s_amr_type_iserror)
                    {
                      tt = fabs(phiFAB(iv,0)-exactFAB(iv,0));
                      if (tt>max_) max_ = tt;
                    }
                  else
                    {
                      for (int dir=0; dir<SpaceDim; ++dir)
                        {
                          IntVect liv(iv), riv(iv); liv.shift(dir,-1); riv.shift(dir,1); 
                          tt = (exactFAB(riv,0)-exactFAB(liv,0))/(2.*dx);
                          grad += tt*tt;
                        }
                      grad = sqrt(grad);
                      if (grad>max_) max_ = grad;
                    }
                }
            }
#ifdef CH_MPI
          MPI_Allreduce( &max_, &thresh, 1, MPI_DOUBLE, MPI_MAX, PETSC_COMM_WORLD );
#else
	  thresh = max_;
#endif
          // set thresh
          thresh /= 2.; 
        }
      
      // make tags
      curr_dom_box = a_domains[0].domainBox(); // used for hard wired refinement
      for (int ilev=0;ilev<new_level;ilev++)
        {
          const DisjointBoxLayout& dbl = a_grids[ilev];
          for (DataIterator dit = dbl.dataIterator(); dit.ok(); ++dit)
            {
              FArrayBox& exactFAB = (*a_exact[ilev])[dit];
              FArrayBox& phiFAB = (*a_phi[ilev])[dit];
              Box region = dbl[dit];
              for (BoxIterator bit(region); bit.ok(); ++bit)
                {
                  const IntVect& iv = bit();
                  if (s_amr_type_iserror)
                    {
                      Real error = fabs(phiFAB(iv,0)-exactFAB(iv,0));
                      if (error > thresh) a_tagVects[ilev] |= iv; // real AMR
                    }
                  else // grad
                    {
                      Real grad = 0., tt;
                      for (int dir=0; dir<SpaceDim; ++dir)
                        {
                          IntVect liv(iv), riv(iv); liv.shift(dir,-1); riv.shift(dir,1); 
                          tt = (exactFAB(riv,0)-exactFAB(liv,0))/(2.*dx);
                          grad += tt*tt;
                        }
                      grad = sqrt(grad);
                      if (grad > thresh) a_tagVects[ilev] |= iv; // real AMR
                    }
                }
            } // grid

          // hardwire refinement in fake place
          IntVect se = a_domains[ilev].domainBox().smallEnd();
          //se.shift(1,curr_dom_box.size(1)-1);
          a_tagVects[ilev] |= se; 

          curr_dom_box.refine(s_refRatio);
          dx /= s_refRatio;
          thresh *= s_error_thresh; 
        }
  
      // make old_grids, need to make all because coarse grids can change after refinement
      for (int ilev=0;ilev<new_level;ilev++)
        {
          const DisjointBoxLayout& dbl = a_grids[ilev];
          old_grids[ilev].resize(dbl.size());
          LayoutIterator lit = dbl.layoutIterator();
          int boxIndex = 0;
          for (lit.begin(); lit.ok(); ++lit, ++boxIndex) 
            {
              old_grids[ilev][boxIndex] = dbl[lit()];
            }
        }
      
      pout() << "setupGrids for level " << new_level+1 << "/" << a_nLevs << ". level domain " << a_domains[new_level].domainBox() << endl;

      // want to keep these
      Vector<IntVectSet> tagVects_copy(a_nLevs-1);
      for (int ilev=0;ilev<new_level;ilev++)
        {
          tagVects_copy[ilev] = a_tagVects[ilev];
        }
      Vector<Vector<Box> > new_grids;
      new_finest_level = refiner.regrid( new_grids, tagVects_copy, 
                                         0, new_level-1, 
                                         old_grids );

      if (new_finest_level == new_level-1) 
        {
          a_same = true;
        }
      else
        {
          // test to see if grids have changed, create new DBLs
          a_same = true;
          for (int ilev=1; ilev<=new_finest_level; ++ilev)
            {
              int numGridsNew = new_grids[ilev].size();
              Vector<int> procIDs(numGridsNew);
              LoadBalance(procIDs, new_grids[ilev]);
              const DisjointBoxLayout newDBL( new_grids[ilev], procIDs,
                                              a_domains[ilev] );
              const DisjointBoxLayout oldDBL = a_grids[ilev];
              a_same &= oldDBL.sameBoxes(newDBL);
              a_grids[ilev] = newDBL;
            }
        }
      if (a_same)
        {
          pout() << "setupGrids -- grids unchanged" << endl;
        }
    }

  PetscFunctionReturn(0);
}
Пример #17
0
int checkCorrection(const Box& a_domain)
{
  int eekflag = 0;
  const EBIndexSpace* const ebisPtr = Chombo_EBIS::instance();
  CH_assert(ebisPtr->isDefined());
  //create a dbl of split up into 2^D boxes
  Vector<Box> vbox;
  Vector<int> proc;
  domainSplit(a_domain, vbox, a_domain.size(0)/2);
  LoadBalance(proc, vbox);
  DisjointBoxLayout dbl(vbox, proc);
  LayoutData<bool>  map1d(dbl);
  int ibox = 0;

  //make every other map 1d
  for (DataIterator dit = dbl.dataIterator(); dit.ok(); ++dit)
    {
      map1d[dit()] = (ibox%2 == 0);
      ibox++;
    }

  LevelData< BaseFab<int> > intmap(dbl, 1 , IntVect::Unit);
  Correct1D2D::makeIntMap(intmap, map1d, dbl);

  //this defines an ebisl with 2 ghost cells
  EBLevelGrid eblg(dbl, ProblemDomain(a_domain), 2, Chombo_EBIS::instance()) ;

  RealVect fluxVal = RealVect::Unit;
  Real dx = 1.0/a_domain.size(0);

  EBCellFactory fact(eblg.getEBISL());
  LevelData<EBCellFAB> divU(dbl, 1, IntVect::Zero, fact);
  Correct1D2D correctinator(eblg, map1d, 1);
  correctinator.setToZero(); //this is important
  for (DataIterator dit = dbl.dataIterator(); dit.ok(); ++dit)
    {
      //make a flux that is borked on the 1d side of box boundaries
      EBFluxFAB fluxFunc(     eblg.getEBISL()[dit()], dbl[dit()], 1);
      setBorkedFlux(fluxFunc, eblg.getEBISL()[dit()], dbl[dit()], fluxVal, intmap[dit()]);
      //increment 1d buffers in corrector
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          correctinator.increment1D(fluxFunc[idir], 1./dx, dit());
          correctinator.increment2D(fluxFunc[idir], 1./dx, dit());
        }

      //now take the divergence of the flux.   it should be zero except
      //at box boundaries on the 1d side
      divergence(divU[dit()], fluxFunc, eblg.getEBISL()[dit()], dbl[dit()], fluxVal, dx);
    }
  //find max value of divergence before corrections

  Real max, min;
  EBLevelDataOps::getMaxMin(max, min, divU, 0);
  pout() << "before correction max divU = " << max << ", min divU = " << min << endl;

  //correct solution due to mismatch at 1d-2d boundaries
  correctinator.correctSolution(divU);

  //recalc max min
  EBLevelDataOps::getMaxMin(max, min, divU, 0);
  pout() << "after  correction max divU = " << max << ", min divU = " << min << endl;
  if (Abs(max-min) > 1.0e-3)
    {
      pout() << "corrector did not seem to correct" << endl;
      return -7;
    }
  return eekflag;
}