📄 box.h
字号:
// This software is copyright (C) by the Lawrence Berkeley
// National Laboratory. Permission is granted to reproduce
// this software for non-commercial purposes provided that
// this notice is left intact.
//
// It is acknowledged that the U.S. Government has rights to
// this software under Contract DE-AC03-765F00098 between
// the U.S. Department of Energy and the University of
// California.
//
// This software is provided as a professional and academic
// contribution for joint exchange. Thus it is experimental,
// is provided ``as is'', with no warranties of any kind
// whatsoever, no support, no promise of updates, or printed
// documentation. By using this software, you acknowledge
// that the Lawrence Berkeley National Laboratory and
// Regents of the University of California shall have no
// liability with respect to the infringement of other
// copyrights by any part of this software.
//
#ifndef CH_BOX_H
#define CH_BOX_H
#ifdef NODEV
#undef NODEV
#endif
#include "SPACE.H"
#ifndef WRAPPER
#include <iostream>
#include "IntVect.H"
#include "Misc.H"
#include "LoHiSide.H"
class IndexType
{
public:
enum CellIndex { CELL = 0, NODE = 1 };
IndexType ();
IndexType (const IndexType& rhs);
explicit IndexType (const IntVect& iv);
IndexType& operator= (const IndexType& rhs);
IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k));
void set (int dir);
void unset (int dir);
bool test (int dir) const;
void setall ();
void clear ();
bool any () const;
bool ok () const;
void flip (int i);
bool operator== (const IndexType& t) const;
bool operator!= (const IndexType& t) const;
bool cellCentered () const;
bool nodeCentered () const;
void setType (int dir,
CellIndex t);
CellIndex ixType (int dir) const;
int operator[] (int dir) const;
IntVect ixType () const;
static IndexType TheCellType ();
static IndexType TheNodeType ();
friend std::ostream& operator<< (std::ostream& os,
const IndexType& itype);
friend std::istream& operator>> (std::istream& is,
IndexType& itype);
private:
//
// Returns 1<<k.
//
static int mask (int k);
//
// An integer holding the CellIndex in bits 0 - BL\_SPACEDIM-1.
//
unsigned int itype;
};
//
// Inlines.
//
inline
int
IndexType::mask (int k)
{
return 1<<k;
}
inline
IndexType::IndexType ()
: itype(0)
{}
inline
IndexType::IndexType (const IndexType& bt)
: itype(bt.itype)
{}
inline
IndexType& IndexType::operator= (const IndexType& bt)
{
itype = bt.itype;
return *this;
}
inline
IndexType::IndexType (const IntVect& iv)
{
itype = D_TERM((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2));
}
inline
IndexType::IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k))
{
itype = D_TERM(i, | (j<<1), | (k<<2));
}
inline
void
IndexType::set (int dir)
{
itype |= mask(dir);
}
inline
void
IndexType::unset (int dir)
{
itype &= ~mask(dir);
}
inline
bool
IndexType::test (int dir) const
{
return (itype & mask(dir)) != 0;
}
inline
void
IndexType::setall ()
{
itype = (1 << SpaceDim) - 1;
}
inline
void
IndexType::clear ()
{
itype = 0;
}
inline
bool
IndexType::any () const
{
return itype != 0;
}
inline
bool
IndexType::ok () const
{
return itype < (1 << SpaceDim);
}
inline
void
IndexType::flip (int i)
{
itype ^= mask(i);
}
inline
bool
IndexType::operator== (const IndexType& t) const
{
return t.itype == itype;
}
inline
bool
IndexType::operator!= (const IndexType& t) const
{
return t.itype != itype;
}
inline
bool
IndexType::cellCentered () const
{
return itype == 0;
}
inline
bool
IndexType::nodeCentered () const
{
return itype == (1<<SpaceDim)-1;
}
inline
void
IndexType::setType (int dir,
CellIndex t)
{
t == CELL ? unset(dir) : set(dir);
}
inline
IndexType::CellIndex
IndexType::ixType (int dir) const
{
return (CellIndex) ((itype & (1<<dir)) >> dir);
}
inline
int
IndexType::operator[] (int dir) const
{
return test(dir);
}
inline
IntVect
IndexType::ixType () const
{
return IntVect(D_DECL(itype&1, (itype>>1)&1, (itype>>2)&1));
}
#endif /* WRAPPER */
//
class Box
{
public:
Box ();
~Box () {;}
Box (const IntVect& small,
const IntVect& big);
void define(const IntVect& small, const IntVect& big);
Box (const IntVect& small,
const int* vec_len);
Box (const IntVect& small,
const IntVect& big,
const IntVect& typ);
Box (const IntVect& small,
const IntVect& big,
const IndexType& t);
Box (const Box& b);
void define(const Box& b);
Box copy() const {return *this;}
const IntVect& smallEnd () const;
IntVect sideEnd(Side::LoHiSide a_side) const;
int smallEnd (int dir) const;
const IntVect& bigEnd () const;
int bigEnd (int dir) const;
const int* loVect () const;
const int* hiVect () const;
const int* getVect () const;
long index (const IntVect& v) const;
IndexType ixType () const;
IntVect type () const;
IndexType::CellIndex type (int dir) const;
const IntVect& size () const;
int size (int dir) const;
bool numPtsOK () const;
long numPts () const;
bool volumeOK () const;
long volume () const;
int longside (int& dir) const;
int longside () const;
int shortside (int& dir) const;
int shortside () const;
bool isEmpty () const;
bool contains (const IntVect& p) const;
bool contains (const Box& b) const;
bool intersects (const Box& b) const;
bool intersectsNotEmpty (const Box& b) const;
bool sameSize (const Box& b) const;
bool sameType (const Box &b) const;
bool operator== (const Box& b) const;
bool eq(const Box& b) const;
bool operator!= (const Box& b) const;
bool neq(const Box& b) const;
bool cellCentered () const;
// following operators added Sept. 14, 1999. bvs
bool operator < (const Box& rhs) const;
bool lt(const Box& rhs) const;
Box& operator= (const Box& b);
Box& setSmall (const IntVect& sm);
Box& setSmall (int dir,
int sm_index);
Box& setBig (const IntVect& bg);
Box& setBig (int dir,
int bg_index);
Box& setRange (int dir,
int sm_index,
int n_cells = 1);
Box& convert (IndexType typ);
Box& convert (const IntVect& typ);
Box& convert (int dir,
IndexType::CellIndex typ);
Box& surroundingNodes ();
Box& surroundingNodes (int dir);
Box& surroundingNodes_int(int dir);
friend Box surroundingNodes (const Box& b,
int dir);
friend Box surroundingNodes (const Box& b);
Box& enclosedCells ();
Box& enclosedCells (int dir);
Box& enclosedCells_int (int dir);
friend Box enclosedCells (const Box& b,
int dir);
friend Box enclosedCells (const Box& b);
Box& shift (int dir,
int nzones);
Box& shift (const IntVect& iv);
Box& shift_intvect (const IntVect& iv);
Box& shiftHalf (int dir,
int num_halfs);
Box& shiftHalf (const IntVect& iv);
Box& shiftHalf_intvect (const IntVect& iv);
Box& operator+= (const IntVect& v);
Box operator+ (const IntVect& v) const;
Box& operator-= (const IntVect& v);
Box operator- (const IntVect& v) const;
friend Box bdryBox(const Box& b,
int dir,
Side::LoHiSide a_sd,
int len);
friend Box bdryLo (const Box& b,
int dir,
int len);
friend Box bdryHi (const Box& b,
int dir,
int len);
friend Box adjCellLo (const Box& b,
int dir,
int len);
friend Box adjCellHi (const Box& b,
int dir,
int len);
Box operator& (const Box&) const;
Box& operator&= (const Box&);
friend Box adjCellBox (const Box& b,
int dir,
Side::LoHiSide a_side,
int len);
Box& minBox (const Box& b);
friend Box minBox (const Box& b1,
const Box& b2);
Box& grow (int i);
friend Box grow (const Box& b,
int i);
Box& grow (const IntVect& v);
friend Box grow (const Box& b,
const IntVect& v);
Box& grow (int idir,
int n_cell);
Box& growLo (int idir,
int n_cell=1);
Box& growDir (int a_idir,
const Side::LoHiSide& a_sd,
int a_cell);
Box& growHi (int idir,
int n_cell=1);
Box& refine (int refinement_ratio);
friend Box refine (const Box& b,
int refinement_ratio);
Box& refine (const IntVect& refinement_ratio);
friend Box refine (const Box& b,
const IntVect& refinement_ratio);
Box& coarsen (int refinement_ratio);
friend Box coarsen (const Box& b,
int refinement_ratio);
Box& coarsen (const IntVect& refinement_ratio);
friend Box coarsen (const Box& b,
const IntVect& refinement_ratio);
// next(...) is out of favor. use BoxIterator.
/*
Step through the rectangle. It is a runtime error to give
a point not inside rectangle. Iteration may not be efficient.
*/
void next (IntVect &) const;
/*
Scan argument IntVect over object second arg is
increment vector. Runtime error if IntVect is not
contained in object Box. Iteration may not be efficient.
*/
void next (IntVect& p,
const int* shv) const;
Box chop (int dir,
int chop_pnt);
friend std::ostream& operator<< (std::ostream& os,
const Box& bx);
friend std::istream& operator>> (std::istream& os,
Box& bx);
void p() const;
void dumpOn (std::ostream& strm) const;
//static const Box Empty;
// TheUnitBox is out of favor.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -