00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011
00012 #ifndef _BOXLAYOUT_H_
00013 #define _BOXLAYOUT_H_
00014
00015 #include "Box.H"
00016 #include "Vector.H"
00017 #include "RefCountedPtr.H"
00018 #include "DataIndex.H"
00019 #include "SPMD.H"
00020 #include "NamespaceHeader.H"
00021
00022 class DataIterator;
00023 class TimedDataIterator;
00024 class LayoutIterator;
00025
00026 #ifndef DOXYGEN
00027
00028 struct Entry
00029 {
00030 Entry()
00031 :
00032 m_procID(procID())
00033 {}
00034
00035 Entry(const Box& a_box)
00036 :
00037 box(a_box),
00038 m_procID(procID())
00039 {}
00040
00041 Entry(const Box& a_box, const unsigned int a_index)
00042 :
00043 box(a_box),
00044 index(a_index),
00045 m_procID(procID())
00046 {}
00047
00048 bool operator < (const Entry& rhs) const
00049 {
00050 return box < rhs.box;
00051 }
00052
00053 Box box;
00054 unsigned int index;
00055 unsigned int m_procID;
00056 };
00057
00058 #endif
00059
00061
00116 class BoxLayout
00117 {
00118 public:
00119
00124
00126
00129 BoxLayout();
00130
00132
00135 BoxLayout(const Vector<Box>& a_boxes,
00136 const Vector<int>& a_procIDs);
00137
00138
00140
00145 virtual
00146 ~BoxLayout();
00147
00149
00152 BoxLayout& operator=(const BoxLayout& a_rhs);
00153
00155
00161 virtual void
00162 define(const Vector<Box>& a_boxes,
00163 const Vector<int>& a_procIDs);
00164
00165
00166
00173
00175
00177 const Box&
00178 operator[](const LayoutIndex& it) const;
00179
00181
00184 Box& ref(const LayoutIndex& it);
00185
00187
00189 const Box&
00190 operator[](const LayoutIterator& it) const;
00191
00193
00195 const Box&
00196 operator[](const DataIterator& it) const;
00197
00199
00206 Box get(const LayoutIndex& it) const;
00207
00208
00210
00212 Box get(const DataIterator& it) const;
00213
00215
00217 Box get(const LayoutIterator& it) const;
00218
00220
00228 unsigned int
00229 procID(const LayoutIndex& a_index) const ;
00230
00231
00232
00233
00234
00236
00238 int numBoxes(const int procID) const;
00239
00240
00242 long long numCells() const;
00243
00245
00247 unsigned int
00248 size() const ;
00249
00252 unsigned int index(const LayoutIndex& index) const;
00253
00254 unsigned int lindex(const DataIndex& index) const;
00261
00263
00266 inline bool
00267 operator==(const BoxLayout& rhs) const ;
00268
00272 inline bool operator<(const BoxLayout& rhs) const ;
00273
00277 int refCount() const
00278 {
00279 return m_boxes.refCount();
00280 }
00282
00285 bool eq(const BoxLayout& rhs) const { return *this == rhs;}
00286
00290 bool
00291 isClosed() const;
00292
00294
00296 bool
00297 isSorted() const {return isClosed();}
00298
00301 bool check(const LayoutIndex& index) const
00302 { return index.m_layoutIntPtr == m_layout;}
00303
00304
00306
00310 bool compatible(const BoxLayout& a_rhs) const
00311 {
00312 return m_layout == a_rhs.m_layout;
00313 }
00314
00321
00323
00327
00328
00329 void addBox(const Box& box, int procID);
00330
00332
00334 virtual void
00335 close();
00336
00337
00338 virtual void
00339 closeNoSort();
00340
00341
00343
00368 virtual void
00369 deepCopy(const BoxLayout& a_source);
00370
00372
00378 bool coarsenable(int refRatio) const;
00379
00381
00397 friend void coarsen(BoxLayout& output,
00398 const BoxLayout& input,
00399 int refinement);
00400
00402
00418 friend void refine(BoxLayout& output,
00419 const BoxLayout& input,
00420 int refinement);
00421
00423
00426 void
00427 setProcID(const LayoutIndex& a_index, unsigned int a_procID);
00428
00429
00431
00435 void
00436 sort();
00437
00440 void aliasAddBox(const Box& box);
00441
00444 void aliasClose();
00445
00452
00454
00458 DataIterator
00459 dataIterator() const;
00460
00462 TimedDataIterator
00463 timedDataIterator() const;
00464
00466
00470 LayoutIterator
00471 layoutIterator() const;
00472
00479
00480 #ifndef WRAPPER
00482
00485 void
00486 print() const;
00487 #endif
00489
00492 void p() const { print();}
00493
00496
00497 Vector<Box> boxArray() const;
00498
00502 Vector<int> procIDs() const;
00503
00504 inline unsigned int indexI(const LayoutIndex&) const;
00505
00506 protected:
00507
00508 void setIndexVector();
00509 void buildDataIndex();
00510 friend class LayoutIterator;
00511 friend class DataIterator;
00512
00513 RefCountedPtr<Vector<Entry> > m_boxes;
00514 RefCountedPtr<Vector<unsigned int> > m_index;
00515 RefCountedPtr<Vector<unsigned int> > m_localIndex;
00516 RefCountedPtr<int> m_layout;
00517 RefCountedPtr<bool> m_closed;
00518 RefCountedPtr<DataIterator> m_dataIterator;
00519
00520 #ifdef CH_MPI
00521 RefCountedPtr<Vector<DataIndex> > m_dataIndex;
00522 #endif
00523
00524 void checkDefine(const Vector<Box>& a_boxes, const Vector<int>& procIDs);
00525 private:
00526
00527 };
00528
00529 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00530
00531 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00532
00533 #ifndef WRAPPER
00534
00535 inline
00536 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00537 { coarsen(output, input, refinement);}
00538
00539 inline
00540 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00541 { refine(output, input, refinement);}
00542
00543 void mortonOrdering(Vector<Box>& a_boxes);
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574 inline unsigned int BoxLayout::indexI(const LayoutIndex& index) const
00575 {
00576 return m_index->operator[](index.m_index);
00577 }
00578
00579 inline unsigned int BoxLayout::lindex(const DataIndex& index) const
00580 {
00581 return m_localIndex->operator[](index.m_index);
00582 }
00583
00584 inline const Box&
00585 BoxLayout::operator[](const LayoutIndex& index) const
00586 {
00587 CH_assert(check(index));
00588 return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00589 }
00590
00591
00592 inline Box&
00593 BoxLayout::ref(const LayoutIndex& index)
00594 {
00595 if(*m_closed)
00596 {
00597 MayDay::Error("attempt to modify closed BoxLayout");
00598 }
00599 CH_assert(check(index));
00600 return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00601 }
00602
00603 inline bool
00604 BoxLayout::operator==(const BoxLayout& rhs) const
00605 {
00606 return m_boxes == rhs.m_boxes;
00607 }
00608
00609 inline bool
00610 BoxLayout::operator<(const BoxLayout& rhs) const
00611 {
00612 return m_boxes < rhs.m_boxes;
00613 }
00614
00615
00616
00617
00618 inline Box
00619 BoxLayout::get(const LayoutIndex& index) const
00620 {
00621 CH_assert(check(index));
00622 return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00623 }
00624
00625
00626
00627 inline unsigned int
00628 BoxLayout::index(const LayoutIndex& a_index) const
00629 {
00630 return m_index->operator[](a_index.m_index);
00631 }
00632
00633 inline bool
00634 BoxLayout::isClosed() const
00635 {
00636 return *m_closed;
00637 }
00638
00639 inline unsigned int
00640 BoxLayout::procID(const LayoutIndex& a_index) const
00641 {
00642 CH_assert(check(a_index));
00643 return m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID;
00644 }
00645
00646
00647 inline void
00648 BoxLayout::setProcID(const LayoutIndex& a_index, unsigned int a_procID)
00649 {
00650 CH_assert(check(a_index));
00651 m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID = a_procID;
00652 }
00653
00654
00655
00656
00657 std::ostream& operator<<(std::ostream& os, const BoxLayout& a_layout);
00658
00659 #endif
00660
00661 #include "NamespaceFooter.H"
00662 #endif