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

📄 denseintvectset.h

📁 自适应网格划分通用程序包
💻 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 DENSEINTVECTSET_H
#define DENSEINTVECTSET_H

#include "BitSet.H"
#include "IntVect.H"
#include "Box.H"
#include "Vector.H"
#include "ProblemDomain.H"

class ProblemDomain;
class DenseIntVectSetIterator;

class DenseIntVectSet
{
public:
  DenseIntVectSet(){;}


  DenseIntVectSet(const Box& a_domain, bool init = true);
  // copy, and operator= should be fine


  DenseIntVectSet& operator-=(const Box& box);


  DenseIntVectSet& operator-=(const IntVect& intvect);


  DenseIntVectSet& operator-=(const DenseIntVectSet& ivs);


  DenseIntVectSet& operator&=(const Box& box);
 

  DenseIntVectSet& operator&=(const ProblemDomain& domain);


  DenseIntVectSet& operator|=(const IntVect& intvect);


  DenseIntVectSet& operator|=(const Box& b);


  DenseIntVectSet& operator|=(const DenseIntVectSet& b);


  DenseIntVectSet& operator&=(const DenseIntVectSet& ivs);


  void shift(const IntVect& iv);

  /* slower, constant time pointwise access.
     You should not build a BoxIterator, then access this
     method if you intend to iterate over the objects true
     or false terms.  you should build a DenseIntVectSetIterator */
  bool operator[](const IntVect& index) const;


  bool contains(const Box& box) const;


  void coarsen(int iref);


  void refine(int iref);


  void grow(int igrow);


  void grow(int idir, int igrow);


  DenseIntVectSet chop(int dir, int chop_pnt);

  inline const Box& box() const;


  void nestingRegion(int a_radius, const Box& a_domain);

 
  void nestingRegion(int a_radius, const ProblemDomain& a_domain);


  bool isEmpty() const; //cheaper than numPts by wide margin


  bool isFull() const;  // cheaper than numPts, bu significant margin


  int  numPts() const;

  bool operator==(const DenseIntVectSet& a_lhs) const;


  Vector<Box> createBoxes() const;

  void compact() const ; 

  void recalcMinBox() const;

  const Box& mBox() const {return m_minBox;}


  int linearSize() const;

  void linearIn(const void* const inBuf);

  void linearOut(void* const a_outBuf) const;

private:

  void grow(const IntVect& iv);
  // version without checking intersect or empty
  DenseIntVectSet& intersect(const DenseIntVectSet& rhs);
  Box m_domain;
  BitSet m_bits;
  friend class DenseIntVectSetIterator;
  Box m_minBox;
};


class DenseIntVectSetIterator
{
public:

  DenseIntVectSetIterator();

  DenseIntVectSetIterator(const DenseIntVectSet& ivs);

  void define(const DenseIntVectSet& ivs);
  //default null, assignment, copy and destructor should work fine.

  const IntVect& operator()() const ;

  bool ok() const;

  void operator++();

  void begin();

  void end();

  static DenseIntVectSet    emptyDenseIntVectSet;

private:
  BitSetIterator m_iterator;
  IntVect        m_current;
  const DenseIntVectSet*    m_ivsPtr;
  int isize, ijsize, bigi, bigj;

  void nextIntVect();
  void nextIntVect(int skip);

};

//===================================================================

// inline functions


inline
const Box& DenseIntVectSet::box() const { return m_domain;}



inline
DenseIntVectSet& DenseIntVectSet::operator-=(const IntVect& intvect)
{
  if(m_domain.contains(intvect))
    m_bits.setFalse(m_domain.index(intvect));
  return *this;
}

inline void DenseIntVectSet::shift(const IntVect& iv)
{
  m_domain.shift(iv);
  m_minBox.shift(iv);
}

inline
DenseIntVectSetIterator::DenseIntVectSetIterator()
  : m_ivsPtr(&emptyDenseIntVectSet)
{
  ;
}

inline
void DenseIntVectSetIterator::define(const DenseIntVectSet& ivs)
{
  m_ivsPtr = &ivs;
  begin();
}

inline
DenseIntVectSetIterator::DenseIntVectSetIterator(const DenseIntVectSet& ivs)
  : m_ivsPtr(&ivs)
{
  begin();
}

inline
const IntVect& DenseIntVectSetIterator::operator()() const
{
  return m_current;
}

inline
bool DenseIntVectSetIterator::ok() const
{
  return m_iterator.ok();
}


inline 
void DenseIntVectSetIterator::end()
{
  m_iterator.end();
}

//  inline 
//  void DenseIntVectSetIterator::operator++()
//  {
//    ++m_iterator;
//    nextIntVect();
//    while(!m_iterator() && m_iterator.ok())
//      {
//        ++m_iterator; // next bit please
//        nextIntVect();
//      }
//  }
inline 
void DenseIntVectSetIterator::operator++()
{
  ++m_iterator;
  int i=1;
  while(m_iterator.ok() && !m_iterator())
    {
      ++m_iterator; // next bit please
      ++i;
    }
  nextIntVect(i);
}

#endif

⌨️ 快捷键说明

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