📄 boxlayout.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 BOXLAYOUT_H
#define BOXLAYOUT_H
#ifndef WRAPPER
#include "Box.H"
#include "Vector.H"
class DataIterator;
class LayoutIterator;
#include "RefCountedPtr.H"
#include "DataIndex.H"
#include "SPMD.H"
#endif /*WRAPPER*/
#ifndef DOXYGEN
struct Entry
{
Entry(): m_procID(procID()){;}
Entry(const Box& a_box)
:box(a_box), m_procID(procID()){}
Entry(const Box& a_box, const unsigned int a_index)
:box(a_box), index(a_index), m_procID(procID()){}
bool operator < (const Entry& rhs) const
{ return box < rhs.box;}
Box box;
unsigned int index;
unsigned int m_procID;// not used in serial code.
};
#endif
class BoxLayout
{
public:
BoxLayout();
BoxLayout(const Vector<Box>& a_boxes,
const Vector<int>& a_procIDs);
virtual
~BoxLayout();
BoxLayout& operator=(const BoxLayout& a_rhs);
virtual void
define(const Vector<Box>& a_boxes,
const Vector<int>& a_procIDs);
const Box&
operator[](const LayoutIndex& it) const;
Box&
operator[](const LayoutIndex& it);
Box get(const LayoutIndex& it) const;
Box get(const LayoutIterator& it) const;
Box get(const DataIterator& it) const;
unsigned int
procID(const LayoutIndex& a_index) const ;
int numBoxes(const int procID) const;
inline unsigned int
size() const ;
unsigned int index(const LayoutIndex& index) const;
inline bool
operator==(const BoxLayout& rhs) const ;
bool eq(const BoxLayout& rhs) const { return *this == rhs;}
bool
isClosed() const;
bool
isSorted() const {return isClosed();}
bool check(const LayoutIndex& index) const
/*zhouhc add // */
{ //return index.m_layoutIntPtr==m_layout;
}
DataIndex
addBox(const Box& box, int procID);
virtual void
close();
virtual void
deepCopy(const BoxLayout& a_source);
friend void coarsen(BoxLayout& output,
const BoxLayout& input,
int refinement);
friend void refine(BoxLayout& output,
const BoxLayout& input,
int refinement);
void
setProcID(const LayoutIndex& a_index, unsigned int a_procID);
//const or non-const operation ?.....I can think of usages either way...bvs
void
sort();
void aliasAddBox(const Box& box);
void aliasClose();
DataIterator
dataIterator() const;
LayoutIterator
layoutIterator() const;
#ifndef WRAPPER
void
print() const;
#endif
void p() const { print();}
protected:
void setIndexVector();
friend class LayoutIterator;
friend class DataIterator;
RefCountedPtr<Vector<Entry> > m_boxes;
RefCountedPtr<Vector<unsigned int> > m_index;
RefCountedPtr<int> m_layout;
RefCountedPtr<bool> m_closed;
RefCountedPtr<DataIterator> m_dataIterator;
private:
};
void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement);
void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement);
#ifndef WRAPPER
inline
void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement)
{ coarsen(output, input, refinement);}
inline
void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement)
{ refine(output, input, refinement);}
//========================================================
// inlined functions
// =================
// constructors
// ============
/*
inline
BoxLayout::BoxLayout(int a_boxes)
:m_boxes(new std::vector<Entry>(a_boxes)),
m_index(new std::vector<unsigned int>(a_boxes)),
m_layout(new int),
m_closed(new bool(false))
{
std::vector<Entry>& boxes = *m_boxes;
std::vector<unsigned int>& index = *m_index;
for(unsigned int i=0; i<boxes.size(); ++i)
{
boxes[i].index = i;
index[i] = i;
}
}
*/
// operators
// =========
inline const Box&
BoxLayout::operator[](const LayoutIndex& index) const
{
assert(check(index));// make sure this LayoutIndex came from my own iterator
return m_boxes->operator[](m_index->operator[](index.m_index)).box;
}
inline Box&
BoxLayout::operator[](const LayoutIndex& index)
{
if(*m_closed)
{
MayDay::Error("attempt to modify closed BoxLayout");
}
assert(check(index)); // make sure this LayoutIndex came from my own iterator
return m_boxes->operator[](m_index->operator[](index.m_index)).box;
}
inline bool
BoxLayout::operator==(const BoxLayout& rhs) const
{
return m_boxes == rhs.m_boxes;
}
// member functions
// ================
inline Box
BoxLayout::get(const LayoutIndex& index) const
{
assert(check(index)); // make sure this LayoutIndex came from my own iterator
return m_boxes->operator[](m_index->operator[](index.m_index)).box;
}
inline unsigned int
BoxLayout::index(const LayoutIndex& a_index) const
{
return m_index->operator[](a_index.m_index);
}
inline bool
BoxLayout::isClosed() const
{
return *m_closed;
}
inline unsigned int
BoxLayout::procID(const LayoutIndex& a_index) const
{
assert(check(a_index));
return m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID;
}
inline void
BoxLayout::setProcID(const LayoutIndex& a_index, unsigned int a_procID)
{
assert(check(a_index));
m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID = a_procID;
}
inline unsigned int
BoxLayout::size() const
{
return m_boxes->size();
}
// global functions
// ================
std::ostream& operator<<(std::ostream& os, const BoxLayout& a_layout);
#endif /*WRAPPER*/
#endif // DATAPLAN_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -