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

📄 dataiterator.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 _DATAITERATOR_H_
#define _DATAITERATOR_H_


#include "DataIndex.H"
#include "BoxLayout.H"
#include "SPMD.H"


#ifdef CH_MPI


class DataIterator
{
  //Note: parallel version doesn't inherit LayoutIterator, serial version does
public:

  DataIterator();

  DataIterator(const BoxLayout& a_layout){*this = a_layout.dataIterator();}

  ~DataIterator() {;}


  inline const DataIndex& operator()() const ;

  DataIndex i() const { return this->operator()();}

  inline void operator++();
  void incr() { ++(*this);}

  bool ok() const;

  void begin();

  void reset();


  void end();

private:

  friend class BoxLayout;
  friend class DisjointBoxLayout;

  DataIterator(const BoxLayout& boxlayout, const int* layoutID);

  BoxLayout m_layout;

  unsigned int m_index;

  DataIndex m_current;

  unsigned int m_procID;

};


inline DataIterator::DataIterator()
  : m_index(0), m_procID(0)
{}


inline const DataIndex& DataIterator::operator()() const
{
  assert(ok());
  return m_current;
}

inline void DataIterator::operator++()
{
  const Entry* box;
  while(++m_index < m_layout.size())
    {
      box = &(*(m_layout.m_boxes))[m_index];
      if(box->m_procID == m_procID)
        {
          m_current.m_index = box->index;
          return;
        }
    }

}

inline bool DataIterator::ok() const
{
  return m_index < m_layout.size();
}



inline void DataIterator::reset()
{
  begin();
}

inline void DataIterator::begin()
{
  m_index = 0;
  const Entry* box;
  while(m_index < m_layout.size())
    {
      box = &(*(m_layout.m_boxes))[m_index];
      if(box->m_procID == m_procID)
        {
          m_current.m_index = box->index;
          return;
        }
      ++m_index;
    }
}

#else

// serial version
#include "LayoutIterator.H"

class DataIterator : public LayoutIterator
{
public:
  DataIterator(){;}
  DataIterator(const BoxLayout& a_layout){*this = a_layout.dataIterator();}


  const DataIndex& operator()() const
  {
    return (const DataIndex&)(LayoutIterator::operator()());
  };


  DataIndex i() const {return this->operator()();}

private:
  friend class BoxLayout;
  friend class DisjointBoxLayout;

  DataIterator(const BoxLayout& boxlayout, const int* layoutID)
        : LayoutIterator(boxlayout, layoutID) {;}
};

#endif  /*CH_MPI*/


#define DATAITERATOR(CLASS, BOXLAYOUT) \
        DataIterator dit = BOXLAYOUT .dataIterator(); \
        for(dit.begin(); dit.ok(); ++dit) {     \
        DataIndex di = dit();                   \
        MT_BEGIN1(CLASS, DataIndex, di)

#define ENDITERATOR(CLASS)  \
        MT_END1(CLASS, DataIndex, di) \
        }

#define DATAITERATOR1(CLASS, BOXLAYOUT, TYPE1, VAL1) \
        DataIterator dit = BOXLAYOUT .dataIterator(); \
        for(dit.begin(); dit.ok(); ++dit) {     \
        DataIndex di = dit();                   \
        MT_BEGIN2(CLASS, TYPE1, VAL1, DataIndex, di)

#define ENDITERATOR1(CLASS, TYPE1, VAL1)  \
        MT_END2(CLASS, TYPE1, VAL1, DataIndex, di) \
        }

#define DATAITERATOR2(CLASS, BOXLAYOUT, TYPE1, VAL1, TYPE2, VAL2) \
        DataIterator dit = BOXLAYOUT .dataIterator(); \
        for(dit.begin(); dit.ok(); ++dit) {     \
        DataIndex di = dit();                   \
        MT_BEGIN3(CLASS, TYPE1, VAL1, TYPE2, VAL2, DataIndex, di)

#define ENDITERATOR2(CLASS, TYPE1, VAL1, TYPE2, VAL2)  \
        MT_END3(CLASS, TYPE1, VAL1, TYPE2, VAL2, DataIndex, di) \
        }

#endif

⌨️ 快捷键说明

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