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

📄 layoutdatai.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.
//

#include "MayDay.H"
#include "DataIterator.H"
#include "SPMD.H"

template<class T>
inline const T& LayoutData<T>::operator[](const DataIndex& index) const
{
  assert(m_boxLayout.check(index));
  assert(m_boxLayout.procID(index) == procID()); // using a DataIndex for data on another processor
                                       //if you are reading this error in a debugger, then
                                       // you haven't used addBox(Box, int) correctly, or
                                       // you are using a LayoutIterator to access a data holder.
  return *(m_vector[m_boxLayout.index(index)]);
}

template<class T>
inline const T& LayoutData<T>::operator[](const DataIterator& index) const
{
  return (*this)[index()];
}

template<class T>
inline T& LayoutData<T>::operator[](const DataIndex& index)
{
  assert(m_boxLayout.check(index));
  assert(m_boxLayout.procID(index) == procID());// using a DataIndex for data on another processor
                                       //if you are reading this error in a debugger, then
                                       // you haven't used addBox(Box, int) correctly, or
                                       // you are using a LayoutIterator to access a data holder.

  return *(m_vector[m_boxLayout.index(index)]);
}

template<class T>
inline T& LayoutData<T>::operator[](const DataIterator& index)
{

  return (*this)[index()];
}

template<class T>
inline Box LayoutData<T>::box(const DataIndex& index) const
{
  return m_boxLayout.get(index);
}

template<class T>
inline Box LayoutData<T>::box(const DataIterator& index) const
{
  return m_boxLayout.get(index());
}
template<class T>
inline DataIterator LayoutData<T>::dataIterator() const
{
  return m_boxLayout.dataIterator();
}

template<class T>
inline LayoutData<T>::LayoutData()
{
  m_boxLayout.close();
}

template<class T>
inline LayoutData<T>::LayoutData(const BoxLayout& dp)
  : m_boxLayout(dp)
{
  assert(dp.isClosed());
  allocate();
}

template<class T>
inline void LayoutData<T>::define(const BoxLayout& dp)
{
  assert(dp.isClosed());
  m_boxLayout = dp;
  allocate();
}

template<class T>
inline LayoutData<T>::~LayoutData()
{
  for(DataIterator it(dataIterator()); it.ok(); ++it)
    {
      delete m_vector[m_boxLayout.index(it())];
    }
}


template<class T>
inline void LayoutData<T>::allocate()
{

  for(unsigned int i=0; i<m_vector.size(); ++i)
    {
      delete m_vector[i];
      m_vector[i] = NULL;
    }

  m_vector.resize(m_boxLayout.size(), NULL);

  for(DataIterator it(dataIterator()); it.ok(); ++it)
    {
      unsigned int index = m_boxLayout.index(it());
      if(m_vector[index] == NULL) 
        {
          m_vector[index] = new T();
          if(m_vector[index] == NULL)
          {
            MayDay::Error("OutOfMemory in boxlayoutdata::setVector");
          }
        }
 
    }
}


⌨️ 快捷键说明

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