Example #1
0
void
EBCellFAB::setInvalidData(const Real& a_val,
                          const int& a_comp)
{
  CH_assert(a_comp >= 0);
  CH_assert(a_comp < m_nComp);

  if (m_ebisBox.isAllRegular())
    {
      return;
    }
  else if (m_ebisBox.isAllCovered())
    {
      m_regFAB.setVal(a_val, a_comp);
    }
  else
    {
      for (BoxIterator bit(m_region); bit.ok(); ++bit)
        {
          const IntVect& iv = bit();
          if (m_ebisBox.isCovered(iv))
            {
              m_regFAB(iv, a_comp) = a_val;
            }
        }
      //also set the multivalued cells
      for (IVSIterator ivsit(getMultiCells());
          ivsit.ok(); ++ivsit)
        {
          const IntVect& iv = ivsit();
          m_regFAB(iv, a_comp) = a_val;
        }
      //also set the multivalued cells
    }
}
Example #2
0
EBCellFAB&
EBCellFAB::divide(const EBCellFAB& a_src,
                  int a_srccomp,
                  int a_destcomp,
                  int a_numcomp)
{

  CH_assert(isDefined());
  CH_assert(a_src.isDefined());
  // Dan G. feels strongly that the assert below should NOT be commented out
  // Brian feels that a weaker version of the CH_assert (if possible) is needed
  // Terry is just trying to get his code to work
  //CH_assert(m_ebisBox == a_src.m_ebisBox);

  CH_assert(a_srccomp + a_numcomp <= a_src.m_nComp);
  CH_assert(a_destcomp + a_numcomp <= m_nComp);
  bool sameRegBox = (a_src.m_regFAB.box() == m_regFAB.box());

  Box locRegion = a_src.m_region & m_region;
  if (!locRegion.isEmpty())
    {
      FORT_DIVIDETWOFAB(CHF_FRA(m_regFAB),
                        CHF_CONST_FRA(a_src.m_regFAB),
                        CHF_BOX(locRegion),
                        CHF_INT(a_srccomp),
                        CHF_INT(a_destcomp),
                        CHF_INT(a_numcomp));
      if (sameRegBox && (locRegion == m_region && locRegion == a_src.m_region))
        {
          Real* l = m_irrFAB.dataPtr(a_destcomp);
          const Real* r = a_src.m_irrFAB.dataPtr(a_srccomp);
          int nvof = m_irrFAB.numVoFs();
          CH_assert(nvof == a_src.m_irrFAB.numVoFs());
          for (int i=0; i<a_numcomp*nvof; i++)
            l[i]/=r[i];
        }
      else
        {
          IntVectSet ivsMulti = a_src.getMultiCells();
          ivsMulti &= getMultiCells();
          ivsMulti &= locRegion;
          IVSIterator ivsit(ivsMulti);
          for (ivsit.reset(); ivsit.ok(); ++ivsit)
            {
              const IntVect& iv = ivsit();
              Vector<VolIndex> vofs = m_ebisBox.getVoFs(iv);
              for (int ivof = 0; ivof < vofs.size(); ivof++)
                {
                  const VolIndex& vof = vofs[ivof];
                  for (int icomp = 0; icomp < a_numcomp; ++icomp)
                    {
                      m_irrFAB(vof, a_destcomp+icomp) /=
                        a_src.m_irrFAB(vof, a_srccomp+icomp);
                    }
                }
            }
        }
    }
  return *this;
}
Example #3
0
EBCellFAB& EBCellFAB::plus(const EBCellFAB& a_src,
                           const Box& a_region,
                           int a_srccomp,
                           int a_destcomp,
                           int a_numcomp)
{
  CH_assert(isDefined());
  CH_assert(a_src.isDefined());
  CH_assert(a_srccomp + a_numcomp <= a_src.m_nComp);
  CH_assert(a_destcomp + a_numcomp <= m_nComp);
  const Box& locRegion = a_region;
  bool sameRegBox = (a_src.m_regFAB.box() == m_regFAB.box());

  if (!locRegion.isEmpty())
    {
      FORT_ADDTWOFAB(CHF_FRA(m_regFAB),
                     CHF_CONST_FRA(a_src.m_regFAB),
                     CHF_BOX(locRegion),
                     CHF_INT(a_srccomp),
                     CHF_INT(a_destcomp),
                     CHF_INT(a_numcomp));

      if (sameRegBox && (locRegion == m_region && locRegion == a_src.m_region))
        {
          Real* l = m_irrFAB.dataPtr(a_destcomp);
          const Real* r = a_src.m_irrFAB.dataPtr(a_srccomp);
          int nvof = m_irrFAB.numVoFs();
          CH_assert(nvof == a_src.m_irrFAB.numVoFs());
          for (int i=0; i<a_numcomp*nvof; i++)
            l[i]+=r[i];
        }
      else
        {
          IntVectSet ivsMulti = a_src.getMultiCells();
          ivsMulti &= getMultiCells();
          ivsMulti &= locRegion;
          IVSIterator ivsit(ivsMulti);
          for (ivsit.reset(); ivsit.ok(); ++ivsit)
            {
              const IntVect& iv = ivsit();
              Vector<VolIndex> vofs = m_ebisBox.getVoFs(iv);
              for (int ivof = 0; ivof < vofs.size(); ivof++)
                {
                  const VolIndex& vof = vofs[ivof];
                  for (int icomp = 0; icomp < a_numcomp; ++icomp)
                    {
                      m_irrFAB(vof, a_destcomp+icomp) +=
                        a_src.m_irrFAB(vof, a_srccomp+icomp);
                    }
                }
            }
        }
    }
  return *this;
}
Example #4
0
bool IntVectSet::contains(const IntVectSet& ivs) const
{
  if (&ivs == this) return true;
  for (IVSIterator ivsit(ivs); ivsit.ok(); ++ivsit)
    {
      if (!contains(ivsit()))
        return false;
    }
  //return true for empty input
  return true;
}
void FourthOrderPatchInterp::interpToFine(/// interpolated solution on this level
                                          FArrayBox&                a_fine,
                                          /// coarse solution
                                          const FArrayBox&          a_coarse,
                                          /// stencils
                                          const BaseFab<IntVect>&   a_stencils,
                                          /// we fill in fine cells within these coarse cells
                                          const IntVectSet&         a_ivs)
{
  CH_assert(m_defined);
  // CH_assert(m_isCoarseBoxSet);
  for (IVSIterator ivsit(a_ivs); ivsit.ok(); ++ivsit)
    {
      const IntVect& ivc = ivsit();
      const IntVect& stencilIndex = a_stencils(ivc, 0);
      const FourthOrderInterpStencil& stencil =
        *m_stencils(stencilIndex, 0);
      // Using coarseFab, fill fine cells of fineFab within ivc.
      stencil.fillFine(a_fine, a_coarse, ivc);
    }
}
Example #6
0
void
SlabService::fillGraph(BaseFab<int>&      a_regIrregCovered,
                       Vector<IrregNode>& a_nodes,
                       const Box&         a_validRegion,
                       const Box&         a_ghostRegion,
                       const ProblemDomain&         a_domain,
                       const RealVect&    a_origin,
                       const Real&        a_dx) const
{
  Box grownCovBox = grow(m_coveredRegion, 1);
  grownCovBox &= a_ghostRegion;
  IntVectSet ivsIrreg(grownCovBox);
  ivsIrreg -= m_coveredRegion;
  ivsIrreg &= a_domain;

  //set regirregcoverred flags
  CH_assert(a_regIrregCovered.box().contains(a_ghostRegion));

  //set every cell to regular
  a_regIrregCovered.setVal(1);
  for (BoxIterator bit(a_ghostRegion); bit.ok(); ++bit)
    {
      if (m_coveredRegion.contains(bit()))
        {
          //set covered cells to -1
          a_regIrregCovered(bit(), 0) = -1;
        }
      else if (ivsIrreg.contains(bit()))
        {
          //set irreg cells to 0
          a_regIrregCovered(bit(), 0) = 0;
        }
    }

  //now loop through irreg cells and make Nodes for them
  a_nodes.resize(0);
  for (IVSIterator ivsit(ivsIrreg); ivsit.ok(); ++ivsit)
    {
      const IntVect& iv = ivsit();
      if (a_validRegion.contains(iv))
        {
          IrregNode node;
          //first the obvious
          node.m_cell = iv;
          node.m_volFrac = 1.0;
          node.m_cellIndex = 0;
          node.m_volCentroid    = RealVect::Zero;
          //any time the next cell over is in the covered
          //region, there is no face.  If there is a cell
          //but it is outside the domain, the arc=-1 to signify
          //a boundary face.  Otherwise, the arc is -2 if it
          //is to a regular cell and 0 if it is to an irregular cell
          for (int idir = 0; idir < SpaceDim; idir++)
            {
              for (SideIterator sit; sit.ok(); ++sit)
                {
                  int arcIndex = node.index(idir, sit());
                  Vector<int>&      arcs     = node.m_arc[arcIndex];
                  Vector<Real>&     areaFracs= node.m_areaFrac[arcIndex];
                  Vector<RealVect>& faceCents= node.m_faceCentroid[arcIndex];
                  IntVect otherIV = iv + sign(sit())*BASISV(idir);
                  if (m_coveredRegion.contains(otherIV))
                    {
                      //do nothing, covered face. leave the vector empty
                    }
                  else
                    {
                      int otherCellIndex;
                      if (ivsIrreg.contains(otherIV))
                        {
                          //arc irregular cell inside the domain
                          otherCellIndex = 0;
                        }
                      else if (!a_domain.contains(otherIV))
                        {
                          //boundary face
                          otherCellIndex = -1;
                        }
                      else
                        {
                          //arc to regular cell
                          otherCellIndex = -2;
                        }
                      arcs.push_back(otherCellIndex);
                      Real     areaFrac = 1.0;
                      RealVect faceCent = RealVect::Zero;

                      areaFracs.push_back(areaFrac);
                      faceCents.push_back(faceCent);
                    } //end otherIV not covered
                }
            }
          //the boundary centroid and normal
          //depend on which side is covered

          for (int idir = 0; idir < SpaceDim; idir++)
            {
              for (SideIterator sit; sit.ok(); ++sit)
                {
                  int arcIndex = node.index(idir, sit());
                  Vector<int>& arcs = node.m_arc[arcIndex];
                  if (arcs.size() == 0)
                    {
                      int isign = sign(sit());
                      node.m_bndryCentroid[idir] = Real(isign)*0.5;
                    }
                }
            }
          a_nodes.push_back(node);
        }
    }
}
Example #7
0
EBCellFAB&
EBCellFAB::axby(const EBCellFAB& a_X, const EBCellFAB& a_Y,
                const Real& a_A, const Real& a_B,
                const int& a_destComp,const int& a_xComp,const int& a_yComp)
{
  CH_assert(isDefined());
  CH_assert(a_X.isDefined());
  CH_assert(a_Y.isDefined());
  // Dan G. feels strongly that the assert below should NOT be commented out
  // Brian feels that a weaker version of the CH_assert (if possible) is needed
  // Terry is just trying to get his code to work
  //CH_assert(m_ebisBox == a_X.m_ebisBox);
  CH_assert(m_nComp     > a_destComp);
  CH_assert(a_X.m_nComp > a_xComp);
  CH_assert(a_Y.m_nComp > a_yComp);

  Box locRegion = a_X.m_region & m_region & a_Y.m_region;
  bool sameRegBox = (a_X.m_regFAB.box() == a_Y.m_regFAB.box()) && (a_X.m_regFAB.box() ==  m_regFAB.box());

  if (!locRegion.isEmpty())
    {
      FORT_AXBYFABCOMP(CHF_FRA(m_regFAB),
                       CHF_CONST_FRA(a_X.m_regFAB),
                       CHF_CONST_FRA(a_Y.m_regFAB),
                       CHF_CONST_REAL(a_A),
                       CHF_CONST_REAL(a_B),
                       CHF_CONST_INT(a_destComp),
                       CHF_CONST_INT(a_xComp),
                       CHF_CONST_INT(a_yComp),
                       CHF_BOX(locRegion));

      bool nvofTest   = false;
      bool regionTest = false;
      //CP: we do a thorough test here to see if all VoFs are the same, just being cautious
      const Vector<VolIndex>& vofs   = m_irrFAB.getVoFs();
      const Vector<VolIndex>& vofs_x = a_X.m_irrFAB.getVoFs();
      const Vector<VolIndex>& vofs_y = a_Y.m_irrFAB.getVoFs();
      if (vofs.size() == vofs_x.size() && vofs.size()==vofs_y.size())
        {
          nvofTest = true;
          for (int i=0; i<vofs.size(); i++)
            {
              if (vofs[i] != vofs_x[i] || vofs[i] != vofs_y[i])
                {
                  nvofTest = false;
                  break;
                }
            }

        }
      if (locRegion == a_X.m_region && locRegion == a_Y.m_region && locRegion == m_region)
        regionTest = true;

      if (sameRegBox && regionTest && nvofTest)
        {
          const Real* l = a_X.m_irrFAB.dataPtr(a_xComp);
          const Real* r = a_Y.m_irrFAB.dataPtr(a_yComp);
          Real* c = m_irrFAB.dataPtr(a_destComp);
          int nvof = a_X.m_irrFAB.numVoFs();
          int numComp = 1;
          for (int i=0; i< numComp*nvof; i++)
            c[i] = l[i] * a_A + r[i] * a_B;
        }
      else
        {
          IntVectSet ivsMulti = a_X.getMultiCells();
          ivsMulti &= a_Y.getMultiCells();
          ivsMulti &= getMultiCells();  // opt might be to take this out
          ivsMulti &= locRegion;
          IVSIterator ivsit(ivsMulti);
          for (ivsit.reset(); ivsit.ok(); ++ivsit)
            {
              const IntVect& iv = ivsit();
              Vector<VolIndex> vofs = m_ebisBox.getVoFs(iv);
              for (int ivof = 0; ivof < vofs.size(); ivof++)
                {
                  const VolIndex& vof = vofs[ivof];
                  if (locRegion.contains(vof.gridIndex()))
                    {
                      m_irrFAB(vof, a_destComp) = a_X.m_irrFAB(vof, a_xComp) * a_A
                        + a_Y.m_irrFAB(vof, a_yComp) * a_B;
                    }
                }
            }
        }
    }
  return *this;
}
Example #8
0
EBCellFAB&
EBCellFAB::mult(const EBCellFAB& a_src,
                int a_srccomp,
                int a_destcomp,
                int a_numcomp)
{
  CH_assert(isDefined());
  CH_assert(a_src.isDefined());
  // Dan G. feels strongly that the assert below should NOT be commented out
  // Brian feels that a weaker version of the CH_assert (if possible) is needed
  // Terry is just trying to get his code to work
  //CH_assert(m_ebisBox == a_src.m_ebisBox);

  CH_assert(a_srccomp + a_numcomp <= a_src.m_nComp);
  CH_assert(a_destcomp + a_numcomp <= m_nComp);
  if (s_verbose)
    {
      IntVect ivdebug(D_DECL(964,736,0));
      VolIndex vof(ivdebug, 0);
      pout() << "EBCellFAB phi(vof) = " << (*this)(vof, 0);
      pout() << ",  a(vof) = " << a_src(vof, 0);
      Real aphi = (*this)(vof, 0) * a_src(vof, 0);
      pout() << ",  aphi(calc) = " <<  aphi << endl;
    }
  Box locRegion = a_src.m_region & m_region;
  bool sameRegBox = (a_src.m_regFAB.box() == m_regFAB.box());

  if (!locRegion.isEmpty())
    {
      FORT_MULTIPLYTWOFAB(CHF_FRA(m_regFAB),
                          CHF_CONST_FRA(a_src.m_regFAB),
                          CHF_BOX(locRegion),
                          CHF_INT(a_srccomp),
                          CHF_INT(a_destcomp),
                          CHF_INT(a_numcomp));
      if (sameRegBox && (locRegion == m_region && locRegion == a_src.m_region))
        {
          Real* l = m_irrFAB.dataPtr(a_destcomp);
          const Real* r = a_src.m_irrFAB.dataPtr(a_srccomp);
          int nvof = m_irrFAB.numVoFs();
          CH_assert(nvof == a_src.m_irrFAB.numVoFs());
          for (int i=0; i<a_numcomp*nvof; i++)
            l[i]*=r[i];
        }
      else
        {
          IntVectSet ivsMulti = a_src.getMultiCells();
          ivsMulti &= getMultiCells();
          ivsMulti &= locRegion;
          IVSIterator ivsit(ivsMulti);
          for (ivsit.reset(); ivsit.ok(); ++ivsit)
            {
              const IntVect& iv = ivsit();
              Vector<VolIndex> vofs = m_ebisBox.getVoFs(iv);
              for (int ivof = 0; ivof < vofs.size(); ivof++)
                {
                  const VolIndex& vof = vofs[ivof];
                  for (int icomp = 0; icomp < a_numcomp; ++icomp)
                    {
                      m_irrFAB(vof, a_destcomp+icomp) *=
                        a_src.m_irrFAB(vof, a_srccomp+icomp);
                    }
                }
            }
        }
    }
  if (s_verbose)
    {
      IntVect ivdebug(D_DECL(964,736,0));
      VolIndex vof(ivdebug, 0);
      pout() << ",  aphi(aft) = " <<  (*this)(vof, 0) << endl;
    }
  return *this;
}
Example #9
0
void EBPoissonOp::
getOpFaceStencil(VoFStencil&             a_stencil,
                 const Vector<VolIndex>& a_allMonotoneVoFs,
                 const EBISBox&          a_ebisbox,
                 const VolIndex&         a_VoF,
                 int                     a_dir,
                 const Side::LoHiSide&   a_side,
                 const FaceIndex&        a_face,
                 const bool&             a_lowOrder)
{
  a_stencil.clear();

  const RealVect& faceCentroid = a_ebisbox.centroid(a_face);
  const IntVect& origin = a_VoF.gridIndex();

  IntVect dirs = IntVect::Zero;

  for (int idir = 0; idir < SpaceDim; idir++)
    {
      if (idir != a_dir)
        {
          IntVect ivPlus = origin;
          ivPlus[idir] += 1;
          if (faceCentroid[idir] < 0.0)
            {
              dirs[idir] = -1;
            }
          else if (faceCentroid[idir] > 0.0)
            {
              dirs[idir] = 1;
            }
          else if (m_eblg.getDomain().contains(ivPlus))
            {
              dirs[idir] = 1;
            }
          else
            {
              dirs[idir] = -1;
            }
        }
    }

  bool orderOne = true;

  if (m_orderEB == 0 || a_lowOrder)
    {
      orderOne = false;
    }
  else
    {
      IntVect loVect = dirs;
      loVect.min(IntVect::Zero);

      IntVect hiVect = dirs;
      hiVect.max(IntVect::Zero);

      Box fluxBox(loVect,hiVect);
      IntVectSet fluxIVS(fluxBox);

      IVSIterator ivsit(fluxIVS);
      for (ivsit.begin(); ivsit.ok(); ++ivsit)
        {
          bool curOkay;

          IntVect ivDelta = ivsit();

          IntVect iv1 = ivDelta;
          iv1 += origin;

          VolIndex VoF1;

          curOkay = EBArith::isVoFHere(VoF1,a_allMonotoneVoFs,iv1);

          IntVect iv2 = iv1;
          iv2[a_dir] += sign(a_side);

          VolIndex VoF2;

          curOkay = curOkay && EBArith::isVoFHere(VoF2,a_allMonotoneVoFs,iv2);

          orderOne = orderOne && curOkay;

          if (curOkay)
            {
              VoFStencil curPair;
              curPair.add(VoF1,-m_invDx2[a_dir]);
              curPair.add(VoF2, m_invDx2[a_dir]);

              for (int idir = 0; idir < SpaceDim; idir++)
                {
                  if (idir != a_dir)
                    {
                      if (ivDelta[idir] == 0)
                        {
                          curPair *= 1 - abs(faceCentroid[idir]);
                        }
                      else
                        {
                          curPair *= abs(faceCentroid[idir]);
                        }
                    }
                }
              a_stencil += curPair;
            }
        }
    }

  if (!orderOne)
    {
      VolIndex VoF1 = a_VoF;
      VolIndex VoF2 = a_face.getVoF(a_side);

      if (a_ebisbox.getRegion().contains(VoF2.gridIndex()))
        {
          a_stencil.clear();

          a_stencil.add(VoF1,-m_invDx2[a_dir]);
          a_stencil.add(VoF2, m_invDx2[a_dir]);
        }
    }
  if (!a_lowOrder)
    {
      a_stencil *= a_ebisbox.areaFrac(a_face);
    }
}