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 // This header file defines the BoxLayout oject.
00042 
00044 
00092 class BoxLayout
00093 {
00094 public:
00096   BoxLayout();
00097 
00099 
00102   BoxLayout(const Vector<Box>& a_boxes,
00103             const Vector<int>& a_procIDs);
00104 
00106 
00111   virtual
00112   ~BoxLayout();
00113 
00115 
00117   BoxLayout& operator=(const BoxLayout& a_rhs);
00118 
00120 
00126   virtual void
00127   define(const Vector<Box>& a_boxes,
00128          const Vector<int>& a_procIDs);
00129 
00130 
00132 
00134   const Box&
00135   operator[](const LayoutIndex& it) const;
00136 
00138   Box&
00139   operator[](const LayoutIndex& it);
00140 
00142 
00145   inline bool
00146   operator==(const BoxLayout& rhs) const ;
00147   bool eq(const BoxLayout& rhs) const { return *this == rhs;}
00148 
00149 
00150   // not a user function
00151   bool check(const LayoutIndex& index) const
00152     { return index.m_layoutIntPtr == m_layout;}
00153 
00154 
00156 
00160   DataIndex
00161   addBox(const Box& box, int procID);
00162 
00164 
00166   virtual void
00167   close();
00168 
00170 
00195   virtual void
00196   deepCopy(const BoxLayout& a_source);
00197 
00199 
00203   Box get(const LayoutIndex& it) const;
00204 
00205 
00208   bool
00209   isClosed() const;
00210 
00211 
00213 
00215   bool
00216   isSorted() const {return isClosed();}
00217 
00219   /* parallel iterator.  Returns DataIndex objects that that only correspond to boxes
00220      on the local processor */
00221   DataIterator
00222   dataIterator() const;
00223 
00225 
00227   LayoutIterator
00228   layoutIterator() const;
00229 
00231 #ifndef WRAPPER
00232   void
00233   print() const;
00234 #endif
00235   void p() const { print();}
00236 
00238 
00245   unsigned int
00246   procID(const LayoutIndex& a_index) const ;
00247 
00249   /* returns the number of boxes assigned to a given procID
00250    */
00251   int numBoxes(const int procID) const;
00252 
00254 
00257   void
00258   setProcID(const LayoutIndex& a_index, unsigned int a_procID);
00259 
00261   inline unsigned int
00262   size() const ;
00263 
00264 
00265   //const or non-const operation ?.....I can think of usages either way...bvs
00267 
00270   void
00271   sort();
00272 
00274 
00280   friend void coarsen(BoxLayout& output, const BoxLayout& input, int refinement);
00281 
00283 
00285   friend void refine(BoxLayout& output, const BoxLayout& input, int refinement);
00286 
00287   struct Entry
00288   {
00289     Entry(): m_procID(::procID()){;}
00290     Entry(const Box& a_box)
00291       :box(a_box), m_procID(::procID()){}
00292     Entry(const Box& a_box, const unsigned int a_index)
00293       :box(a_box), index(a_index), m_procID(::procID()){}
00294     bool operator < (const Entry& rhs) const
00295       { return box < rhs.box;}
00296 
00297     Box box;
00298     unsigned int index;
00299     unsigned int m_procID;// not used in serial code.
00300   };
00301 
00302   // not a user function.  used in IO routine.
00303   unsigned int index(const LayoutIndex& index) const;
00304 
00305 protected:
00306 
00307   void setIndexVector();
00308   friend class LayoutIterator;
00309   friend class DataIterator;
00310 
00311   RefCountedPtr<Vector<Entry> >        m_boxes;
00312   RefCountedPtr<Vector<unsigned int> > m_index;
00313   RefCountedPtr<int>                   m_layout;
00314   RefCountedPtr<bool>                  m_closed;
00315   RefCountedPtr<DataIterator>          m_dataIterator;
00316 
00317 private:
00318 
00319 };
00320 
00321 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00322 
00323 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00324 
00325 #ifndef WRAPPER
00326 
00327 inline
00328 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00329 { coarsen(output, input, refinement);}
00330 
00331 inline
00332 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00333 { refine(output, input, refinement);}
00334 
00335 //========================================================
00336 
00337 
00338 // inlined functions
00339 // =================
00340 
00341 
00342 // constructors
00343 // ============
00344 
00345 
00346 
00347 /*
00348 inline
00349 BoxLayout::BoxLayout(int a_boxes)
00350   :m_boxes(new std::vector<Entry>(a_boxes)),
00351    m_index(new std::vector<unsigned int>(a_boxes)),
00352    m_layout(new int),
00353    m_closed(new bool(false))
00354 {
00355   std::vector<Entry>& boxes = *m_boxes;
00356   std::vector<unsigned int>& index = *m_index;
00357   for(unsigned int i=0; i<boxes.size(); ++i)
00358     {
00359       boxes[i].index = i;
00360       index[i] = i;
00361     }
00362 }
00363 */
00364 
00365 // operators
00366 // =========
00367 
00368 inline const Box&
00369 BoxLayout::operator[](const LayoutIndex& index) const
00370 {
00371   assert(check(index));// make sure this LayoutIndex came from my own iterator
00372   return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00373 }
00374 
00375 inline Box&
00376 BoxLayout::operator[](const LayoutIndex& index)
00377 {
00378   if(*m_closed)
00379     {
00380       MayDay::Error("attempt to modify closed BoxLayout");
00381     }
00382   assert(check(index)); // make sure this LayoutIndex came from my own iterator
00383   return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00384 }
00385 
00386 inline bool
00387 BoxLayout::operator==(const BoxLayout& rhs) const
00388 {
00389   return m_boxes == rhs.m_boxes;
00390 }
00391 
00392 
00393 // member functions
00394 // ================
00395 
00396 
00397 inline  Box
00398 BoxLayout::get(const LayoutIndex& index) const
00399 {
00400   assert(check(index)); // make sure this LayoutIndex came from my own iterator
00401   return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00402 }
00403 
00404 inline unsigned int
00405 BoxLayout::index(const LayoutIndex& a_index) const
00406 {
00407   return m_index->operator[](a_index.m_index);
00408 }
00409 
00410 inline bool
00411 BoxLayout::isClosed() const
00412 {
00413   return *m_closed;
00414 }
00415 
00416 inline unsigned int
00417 BoxLayout::procID(const LayoutIndex& a_index) const
00418 {
00419   assert(check(a_index));
00420   return m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID;
00421 }
00422 
00423 inline void
00424 BoxLayout::setProcID(const LayoutIndex& a_index, unsigned int a_procID)
00425 {
00426   assert(check(a_index));
00427   m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID = a_procID;
00428 }
00429 
00430 inline unsigned int
00431 BoxLayout::size() const 
00432 {
00433   return m_boxes->size();
00434 }
00435 
00436 
00437 // global functions
00438 // ================
00439 
00440 std::ostream& operator<<(std::ostream& os, const BoxLayout& a_layout);
00441 
00442 #endif /*WRAPPER*/
00443 
00444 
00445 #endif // DATAPLAN_H
00446 

Generated on Thu Aug 29 11:05:44 2002 for Chombo&INS by doxygen1.2.16