Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

BoxLayout.H

Go to the documentation of this file.
00001 /* _______              __
00002   / ___/ /  ___  __ _  / /  ___
00003  / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004  \___/_//_/\___/_/_/_/_.__/\___/ 
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 // 
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 #ifndef BOXLAYOUT_H
00029 #define BOXLAYOUT_H
00030 
00031 #ifndef WRAPPER
00032 #include "Box.H"
00033 #include "Vector.H"
00034 class DataIterator;
00035 class LayoutIterator;
00036 #include "RefCountedPtr.H"
00037 #include "DataIndex.H"
00038 #include "SPMD.H"
00039 #endif /*WRAPPER*/
00040 
00041 #ifndef DOXYGEN
00042 
00043 struct Entry
00044 {
00045   Entry(): m_procID(procID()){;}
00046   Entry(const Box& a_box)
00047         :box(a_box), m_procID(procID()){}
00048   Entry(const Box& a_box, const unsigned int a_index)
00049         :box(a_box), index(a_index), m_procID(procID()){}
00050   bool operator < (const Entry& rhs) const
00051   { return box < rhs.box;}
00052   
00053   Box box;
00054   unsigned int index;
00055   unsigned int m_procID;// not used in serial code.
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 
00139 
00144   virtual
00145   ~BoxLayout();
00146 
00148 
00151   BoxLayout& operator=(const BoxLayout& a_rhs);
00152 
00154 
00160   virtual void
00161   define(const Vector<Box>& a_boxes,
00162          const Vector<int>& a_procIDs);
00163 
00164 
00171 
00173 
00175   const Box&
00176   operator[](const LayoutIndex& it) const;
00177 
00179 
00181   Box&
00182   operator[](const LayoutIndex& it);
00183 
00185 
00192   Box get(const LayoutIndex& it) const;
00193 
00195 
00197   Box get(const LayoutIterator& it) const;
00198 
00200 
00202   Box get(const DataIterator& it) const;
00203  
00205 
00213   unsigned int
00214   procID(const LayoutIndex& a_index) const ;
00215 
00217 
00219   int numBoxes(const int procID) const;
00220 
00222 
00224   inline unsigned int
00225   size() const ;
00226 
00229   unsigned int index(const LayoutIndex& index) const;
00230 
00237 
00239 
00242   inline bool
00243   operator==(const BoxLayout& rhs) const ;
00244 
00246 
00249   bool eq(const BoxLayout& rhs) const { return *this == rhs;}
00250 
00251 
00255   bool
00256   isClosed() const;
00257 
00259 
00261   bool
00262   isSorted() const {return isClosed();}
00263 
00266   bool check(const LayoutIndex& index) const
00267     { return index.m_layoutIntPtr == m_layout;}
00268 
00269 
00276 
00278 
00282   DataIndex
00283   addBox(const Box& box, int procID);
00284 
00286 
00288   virtual void
00289   close();
00290 
00292 
00317   virtual void
00318   deepCopy(const BoxLayout& a_source);
00319 
00321 
00327   bool coarsenable(int refRatio) const;
00328   
00330 
00345   friend void coarsen(BoxLayout& output,
00346                       const BoxLayout& input,
00347                       int refinement);
00348 
00350 
00365   friend void refine(BoxLayout& output,
00366                      const BoxLayout& input,
00367                      int refinement);
00368 
00370 
00373   void
00374   setProcID(const LayoutIndex& a_index, unsigned int a_procID);
00375 
00376   //const or non-const operation ?.....I can think of usages either way...bvs
00378 
00382   void
00383   sort();
00384 
00387   void aliasAddBox(const Box& box);
00388 
00391   void aliasClose();
00392 
00399 
00401 
00405   DataIterator
00406   dataIterator() const;
00407 
00409 
00413   LayoutIterator
00414   layoutIterator() const;
00415 
00422 
00423 #ifndef WRAPPER
00424 
00425 
00428   void
00429   print() const;
00430 #endif
00431 
00432 
00435   void p() const { print();}
00436 
00439 protected:
00440 
00441   void setIndexVector();
00442   friend class LayoutIterator;
00443   friend class DataIterator;
00444 
00445   RefCountedPtr<Vector<Entry> >        m_boxes;
00446   RefCountedPtr<Vector<unsigned int> > m_index;
00447   RefCountedPtr<int>                   m_layout;
00448   RefCountedPtr<bool>                  m_closed;
00449   RefCountedPtr<DataIterator>          m_dataIterator;
00450 
00451 private:
00452 
00453 };
00454 
00455 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00456 
00457 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00458 
00459 #ifndef WRAPPER
00460 
00461 inline
00462 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00463 { coarsen(output, input, refinement);}
00464 
00465 inline
00466 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00467 { refine(output, input, refinement);}
00468 
00469 //========================================================
00470 
00471 
00472 // inlined functions
00473 // =================
00474 
00475 
00476 // constructors
00477 // ============
00478 
00479 
00480 
00481 /*
00482 inline
00483 BoxLayout::BoxLayout(int a_boxes)
00484   :m_boxes(new std::vector<Entry>(a_boxes)),
00485    m_index(new std::vector<unsigned int>(a_boxes)),
00486    m_layout(new int),
00487    m_closed(new bool(false))
00488 {
00489   std::vector<Entry>& boxes = *m_boxes;
00490   std::vector<unsigned int>& index = *m_index;
00491   for(unsigned int i=0; i<boxes.size(); ++i)
00492     {
00493       boxes[i].index = i;
00494       index[i] = i;
00495     }
00496 }
00497 */
00498 
00499 // operators
00500 // =========
00501 
00502 inline const Box&
00503 BoxLayout::operator[](const LayoutIndex& index) const
00504 {
00505   assert(check(index));// make sure this LayoutIndex came from my own iterator
00506   return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00507 }
00508 
00509 inline Box&
00510 BoxLayout::operator[](const LayoutIndex& index)
00511 {
00512   if(*m_closed)
00513     {
00514       MayDay::Error("attempt to modify closed BoxLayout");
00515     }
00516   assert(check(index)); // make sure this LayoutIndex came from my own iterator
00517   return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00518 }
00519 
00520 inline bool
00521 BoxLayout::operator==(const BoxLayout& rhs) const
00522 {
00523   return m_boxes == rhs.m_boxes;
00524 }
00525 
00526 
00527 // member functions
00528 // ================
00529 
00530 
00531 inline  Box
00532 BoxLayout::get(const LayoutIndex& index) const
00533 {
00534   assert(check(index)); // make sure this LayoutIndex came from my own iterator
00535   return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00536 }
00537 
00538 inline unsigned int
00539 BoxLayout::index(const LayoutIndex& a_index) const
00540 {
00541   return m_index->operator[](a_index.m_index);
00542 }
00543 
00544 inline bool
00545 BoxLayout::isClosed() const
00546 {
00547   return *m_closed;
00548 }
00549 
00550 inline unsigned int
00551 BoxLayout::procID(const LayoutIndex& a_index) const
00552 {
00553   assert(check(a_index));
00554   return m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID;
00555 }
00556 
00557 inline void
00558 BoxLayout::setProcID(const LayoutIndex& a_index, unsigned int a_procID)
00559 {
00560   assert(check(a_index));
00561   m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID = a_procID;
00562 }
00563 
00564 inline unsigned int
00565 BoxLayout::size() const 
00566 {
00567   return m_boxes->size();
00568 }
00569 
00570 
00571 // global functions
00572 // ================
00573 
00574 std::ostream& operator<<(std::ostream& os, const BoxLayout& a_layout);
00575 
00576 #endif /*WRAPPER*/
00577 
00578 #endif // DATAPLAN_H

Generated on Wed Jun 2 13:53:32 2004 for Chombo&INSwithParticles by doxygen 1.3.2