⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 box.h

📁 自适应网格划分通用程序包
💻 H
📖 第 1 页 / 共 2 页
字号:
  /*
    This static member function returns a constant reference to 
    an object of type Box representing the unit box in
    BL\_SPACEDIM-dimensional space.
  */

  //static const Box& TheUnitBox ();

  //
  // Sets the 'len' element of the Box.  Aborts on integer overflow.
  //
  void computeBoxLen ();
  void computeBoxLenNotEmpty();

protected:
  friend class HDF5Handle;
  //
  // A helper function for numPtsOK() and numPts().
  //
  bool numPtsOK (long& N) const;
  //
  // A helper function for volumeOK() and volume().
  //
  bool volumeOK (long& N) const;

  IntVect   smallend;
  IntVect   bigend;
  IntVect   len;
  IndexType btype;

};

// global function prototypes
Box surroundingNodes (const Box& b,
                      int        dir);
Box surroundingNodes (const Box& b);
Box enclosedCells (const Box& b,
                   int        dir);
Box enclosedCells (const Box& b);
Box bdryBox(const Box& b,
            int        dir,
            Side::LoHiSide a_sd,
            int        len=1);
Box bdryLo (const Box& b,
            int        dir,
            int        len=1);
Box bdryHi (const Box& b,
            int        dir,
            int        len=1);
Box adjCellLo (const Box& b,
               int        dir,
               int        len=1);
Box adjCellHi (const Box& b,
               int        dir,
               int        len=1);
Box minBox (const Box& b1,
            const Box& b2);
//
// Inlines. 
//

#ifndef WRAPPER

inline
Box::Box (const Box& b)
  : smallend(b.smallend),
    bigend(b.bigend),
    btype(b.btype)
{
  D_EXPR(len[0] = b.len[0],
         len[1] = b.len[1],
         len[2] = b.len[2]);
}

inline
Box&
Box::operator= (const Box& b)
{
  smallend = b.smallend;
  bigend = b.bigend;
  btype = b.btype;
  D_EXPR(len[0] = b.len[0],
         len[1] = b.len[1],
         len[2] = b.len[2]);
  return *this;
}

inline
IntVect
Box::sideEnd(Side::LoHiSide a_side) const
{
  IntVect retval;
  if(a_side == Side::Lo)
    retval = smallEnd();
  else
    retval = bigEnd();
  return retval;
}

inline
const IntVect&
Box::smallEnd () const
{
  return smallend;
}

inline
int
Box::smallEnd (int dir) const
{
  return smallend[dir];
}

inline
const IntVect&
Box::bigEnd () const
{
  return bigend;
}

inline
int
Box::bigEnd (int dir) const
{
  return bigend[dir];
}

inline
IndexType
Box::ixType () const
{
  return btype;
}

inline
IntVect
Box::type () const
{
  return btype.ixType();
}

inline
IndexType::CellIndex
Box::type (int dir) const
{
  return btype.ixType(dir);
}

inline
const IntVect&
Box::size () const
{
  return len;
}

inline
int
Box::size (int dir) const
{
  return len[dir];
}

inline
const int*
Box::loVect () const
{
  return smallend.getVect();
}

inline
const int*
Box::hiVect () const
{
  return bigend.getVect();
}

inline
const int*
Box::getVect () const
{
  return smallend.getVect();
}


inline
bool
Box::numPtsOK () const
{
  long ignore;
  return numPtsOK(ignore);
}

inline
bool
Box::isEmpty () const
{
  //    return numPts() == 0;
  return (!(bigend >= smallend));
}

inline
bool
Box::contains (const IntVect& p) const
{

  return ( !isEmpty() && (p >= smallend && p <= bigend) );
}

inline
bool
Box::sameType (const Box &b) const
{
  return btype == b.btype;
}

inline
bool
Box::contains (const Box& b) const
{
  assert(sameType(b));
  return ( !isEmpty() && !b.isEmpty() && 
           (b.smallend >= smallend && b.bigend <= bigend) );
}

inline
bool
Box::sameSize (const Box& b) const
{
  assert(sameType(b));
  return D_TERM(len[0] == b.len[0],
                && len[1]==b.len[1],
                && len[2]==b.len[2]);
}

inline
bool
Box::operator== (const Box& b) const
{
  return smallend == b.smallend && bigend == b.bigend && b.btype == btype;
}

inline
bool
Box::operator!= (const Box& b) const
{
  return !operator==(b);
}

inline
bool
Box::cellCentered () const
{
  return !btype.any();
}

inline
bool
Box::volumeOK () const
{
  return numPtsOK();
}

inline
long
Box::index (const IntVect& v) const
{
  long result = v.vect[0]-smallend.vect[0];
#if   CH_SPACEDIM==2
  result += len[0]*(v.vect[1]-smallend.vect[1]);
#elif CH_SPACEDIM==3
  result += len[0]*(v.vect[1]-smallend.vect[1]
                    +(v.vect[2]-smallend.vect[2])*len[1]);
#endif
  return result;
}

inline
void
Box::computeBoxLen ()
{
  if (isEmpty())
    {
      len = IntVect::Zero;
    }
  else
    {
      D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
             len[1] = bigend[1]-smallend[1] + 1,
             len[2] = bigend[2]-smallend[2] + 1);
    }
}

inline
void
Box::computeBoxLenNotEmpty()
{
  D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
         len[1] = bigend[1]-smallend[1] + 1,
         len[2] = bigend[2]-smallend[2] + 1);
}

inline
Box&
Box::setSmall (const IntVect& sm)
{
  assert (sm <= bigend);

  smallend = sm;
  computeBoxLen();
  return *this;
}

inline
Box&
Box::setSmall (int dir,
               int sm_index)
{
  assert (sm_index <= bigend[dir]);

  smallend.setVal(dir,sm_index);
  computeBoxLen();
  return *this;
}

inline
Box&
Box::setBig (const IntVect& bg)
{
  assert (bg >= smallend);

  bigend = bg;
  computeBoxLen();
  return *this;
}

inline
Box&
Box::setBig (int dir,
             int bg_index)
{
  assert (bg_index >= smallend[dir]);

  bigend.setVal(dir,bg_index);
  computeBoxLen();
  return *this;
}

inline
Box&
Box::setRange (int dir,
               int sm_index,
               int n_cells)
{
  assert (n_cells > 0);

  smallend.setVal(dir,sm_index);
  bigend.setVal(dir,sm_index+n_cells-1);
  computeBoxLen();
  return *this;
}

inline
Box&
Box::shift (int dir,
            int nzones)
{
  if (!isEmpty())
    {
      smallend.shift(dir,nzones);
      bigend.shift(dir,nzones);
    }
  return *this;
}

inline
Box&
Box::shift (const IntVect& iv)
{
  if (!isEmpty())
    {
      smallend.shift(iv);
      bigend.shift(iv);
    }
  return *this;
}

inline
Box&
Box::convert (const IntVect& typ)
{
  assert(typ >= IntVect::TheZeroVector() && typ <= IntVect::TheUnitVector());
  if (!isEmpty())
    {
      IntVect shft(typ - btype.ixType());
      bigend += shft;
    }
  btype = IndexType(typ);
  computeBoxLen();
  return *this;
}

inline
Box&
Box::surroundingNodes (int dir)
{
  if (!(btype[dir]))
    {
      if (!isEmpty())
        {
          bigend.shift(dir,1);
        }
      //
      // Set dir'th bit to 1 = IndexType::NODE.
      //
      btype.set(dir);
      computeBoxLen();
    }
  return *this;
}

inline
Box&
Box::enclosedCells (int dir)
{
  if (btype[dir])
    {
      if (!isEmpty())
        {
          bigend.shift(dir,-1);
        }
      //
      // Set dir'th bit to 0 = IndexType::CELL.
      //
      btype.unset(dir);
      computeBoxLen();
    }
  return *this;
}

inline
Box
surroundingNodes (const Box& b,
                  int        dir)
{
  Box bx(b);
  return bx.surroundingNodes(dir);
}

inline
Box
surroundingNodes (const Box& b)
{
  Box bx(b);
  return bx.surroundingNodes();
}

inline
Box
enclosedCells (const Box& b,
               int        dir)
{
  Box bx(b);
  return bx.enclosedCells(dir);
}

inline
Box
enclosedCells (const Box& b)
{
  Box bx(b);
  return bx.enclosedCells();
}

inline
Box&
Box::operator+= (const IntVect& v)
{
  if (!isEmpty())
    {
      smallend += v;
      bigend += v;
    }
  return *this;
}

inline
Box
Box::operator+  (const IntVect& v) const
{
  if (isEmpty())
    {
      return(Box().convert(btype));
    }
  else
    {
      IntVect small(smallend);
      small += v;
      IntVect big(bigend);
      big += v;
      return Box(small,big,btype);
    }
}

inline
Box&
Box::operator-= (const IntVect& v)
{
  if (!isEmpty())
    {
      smallend -= v;
      bigend -= v;
    }
  return *this;
}

inline
bool 
Box::operator < (const Box& rhs) const
{
  return(!isEmpty() && (rhs.isEmpty() || smallend.lexLT(rhs.smallend)));
}

inline
Box
Box::operator-  (const IntVect& v) const
{
  if (isEmpty())
    {
      return(Box().convert(btype));
    }
  else
    {
      IntVect small = smallend;
      small -= v;
      IntVect big = bigend;
      big -= v;
      return Box(small,big,btype);
    }
}

inline
Box&
Box::grow (int i)
{
  if (!isEmpty())
    {
      smallend.diagShift(-i);
      bigend.diagShift(i);
      if (!(bigend >= smallend)) *this = Box().convert(btype);
      computeBoxLen();
    }
  return *this;
}

inline
Box
grow (const Box& b,
      int        i)
{
  if (b.isEmpty())
    {
      return (Box().convert(b.btype));
    }
  else
    {
      IntVect small = diagShift(b.smallend,-i);
      IntVect big   = diagShift(b.bigend,i);
      if (!(big >= small))
        {
          return(Box().convert(b.btype));
        }
      else
        {
          return Box(small,big,b.btype);
        }
    }
}

inline
Box&
Box::grow (const IntVect& v)
{
  if (!isEmpty())
    {
      smallend -= v;
      bigend   += v;
      if (!(bigend >= smallend)) *this = Box().convert(btype);
      computeBoxLen();
    }
  return *this;
}

inline
Box
grow (const Box&     b,
      const IntVect& v)
{
  if (b.isEmpty())
    {
      return(Box().convert(b.btype));
    }
  else
    {
      IntVect small = b.smallend - v;
      IntVect big   = b.bigend   + v;
      if (!(big >= small))
        {
          return(Box().convert(b.btype));
        }
      else
        {
          return Box(small,big,b.btype);
        }
    }
}

inline
Box&
Box::grow (int idir,
           int n_cell)
{
  if (!isEmpty())
    {
      smallend.shift(idir, -n_cell);
      bigend.shift(idir, n_cell);
      if (!(bigend >= smallend)) *this = Box().convert(btype);
      computeBoxLen();
    }
  return *this;
}

inline
Box&
Box::growLo (int idir,
             int n_cell)
{
  if (!isEmpty())
    {
      smallend.shift(idir, -n_cell);
      if (!(bigend >= smallend)) *this = Box().convert(btype);
      computeBoxLen();
    }
  return *this;
}

inline
Box&
Box::growDir (int idir,
              const Side::LoHiSide& a_sd,
              int n_cell)
{
  if(a_sd == Side::Lo)
    {
      growLo(idir, n_cell);
    }
  else
    {
      growHi(idir, n_cell);
    }
  return *this;
}

inline
Box&
Box::growHi (int idir,
             int n_cell)
{
  if (!isEmpty())
    {
      bigend.shift(idir,n_cell);
      if (!(bigend >= smallend)) *this = Box().convert(btype);
      computeBoxLen();
    }
  return *this;
}


inline
Box
Box::operator& (const Box& rhs) const
{
  Box lhs(*this);
  return lhs &= rhs;
}

#endif /* WRAPPER */

#endif /*CH_BOX_H*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -