📄 copier.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 COPIER_H
#define COPIER_H
#include "DisjointBoxLayout.H"
#include "Pool.H"
#include "Vector.H"
#include "ProblemDomain.H"
class MotionItem;
class CopyIterator;
class Copier
{
public:
Copier(){;}
Copier(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
bool a_exchange = false);
Copier(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
const ProblemDomain& a_domain,
bool a_exchange = false);
Copier(const DisjointBoxLayout& a_level,
const BoxLayout& a_dest,
const IntVect& a_destGhost,
bool a_exchange = false);
Copier(const DisjointBoxLayout& a_level,
const BoxLayout& a_dest,
const ProblemDomain& a_domain,
const IntVect& a_destGhost,
bool a_exchange = false);
virtual ~Copier();
virtual void define(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
bool a_exchange = false);
virtual void define(const DisjointBoxLayout& a_level,
const BoxLayout& a_dest,
const ProblemDomain& a_domain,
bool a_exchange = false);
virtual void define(const DisjointBoxLayout& a_level,
const BoxLayout& a_dest,
const IntVect& a_destGhost,
bool a_exchange = false);
virtual void define(const DisjointBoxLayout& a_level,
const BoxLayout& a_dest,
const ProblemDomain& a_domain,
const IntVect& a_destGhost,
bool a_exchange = false);
void ghostDefine(const DisjointBoxLayout& a_src,
const DisjointBoxLayout& a_dest,
const ProblemDomain& a_domain,
const IntVect& a_srcGhost);
virtual void clear();
bool check(const DisjointBoxLayout& from, const BoxLayout& to) const;
int print() const;
bool bufferAllocated() const;
void setBufferAllocated(bool arg) const;
protected:
friend class CopyIterator;
Vector<MotionItem*> m_localMotionPlan;
Vector<MotionItem*> m_fromMotionPlan;
Vector<MotionItem*> m_toMotionPlan;
friend void dumpmemoryatexit();
static Pool s_motionItemPool;
mutable bool buffersAllocated;
private:
// keep a refcounted reference around for debugging purposes, we can
// decide afterwards if we want to eliminate it.
DisjointBoxLayout m_originPlan;
BoxLayout m_dest;
};
std::ostream& operator<<(std::ostream& os, const Copier& copier);
//===========================================================================
// end of public interface for Copier.
//===========================================================================
// These classes are public because I can't find a nice
// way to make a class a friend of all the instantiations
// of a template class. These classes are not part of
// the public interface for the Array API.
//
// Later, if MotionItem shows up in the profiler, we
// can start using a pool allocation scheme and placement new
class MotionItem{
public:
DataIndex fromIndex, toIndex;
Box fromRegion;
Box toRegion;
int procID;
// this constructor will probably eventually go away
MotionItem(const DataIndex& a_from,
const DataIndex& a_to,
const Box& a_region);
MotionItem(const DataIndex& a_from,
const DataIndex& a_to,
const Box& a_fromRegion,
const Box& a_toRegion);
void reverse();
};
inline MotionItem::MotionItem(const DataIndex& a_from,
const DataIndex& a_to,
const Box& a_region)
:fromIndex(a_from), toIndex(a_to), fromRegion(a_region),
toRegion(a_region), procID(-1)
{;}
inline MotionItem::MotionItem(const DataIndex& a_from,
const DataIndex& a_to,
const Box& a_fromRegion,
const Box& a_toRegion)
:fromIndex(a_from), toIndex(a_to), fromRegion(a_fromRegion),
toRegion(a_toRegion), procID(-1)
{;}
inline
void MotionItem::reverse()
{
Box tmp(fromRegion);
fromRegion=toRegion;
toRegion=tmp;
DataIndex tmpIndex(fromIndex);
fromIndex = toIndex;
toIndex = tmpIndex;
}
class CopyIterator
{
public:
enum local_from_to {LOCAL, FROM, TO};
inline CopyIterator(const Copier& a_copier, local_from_to);
inline const MotionItem& operator()() const;
inline void operator++();
inline bool ok() const;
inline void reset();
private:
const Vector<MotionItem*>* m_motionplanPtr;
unsigned int m_current;
};
//====== inlined functions====================================
inline CopyIterator::CopyIterator(const Copier& a_copier, local_from_to type)
:m_current(0)
{
switch(type){
case LOCAL:
m_motionplanPtr = &(a_copier.m_localMotionPlan);
break;
case FROM:
m_motionplanPtr = &(a_copier.m_fromMotionPlan);
break;
case TO:
m_motionplanPtr = &(a_copier.m_toMotionPlan);
break;
default:
MayDay::Error("illegal local_from_to option for CopyIterator");
}
}
inline const MotionItem& CopyIterator::operator()() const
{
assert(m_current < m_motionplanPtr->size());
return *(m_motionplanPtr->operator[](m_current));
}
inline void CopyIterator::operator++() {++m_current;}
inline bool CopyIterator::ok() const
{
return m_current < m_motionplanPtr->size();
}
inline void CopyIterator::reset()
{
m_current = 0;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -