Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

BoxLayout.H

Go to the documentation of this file.
00001 /*   _______              __
00002     / ___/ /  ___  __ _  / /  ___
00003    / /__/ _ \/ _ \/  V \/ _ \/ _ \
00004    \___/_//_/\___/_/_/_/_.__/\___/
00005 */
00006 // CHOMBO Copyright (c) 2000-2004, The Regents of the University of
00007 // California, through Lawrence Berkeley National Laboratory (subject to
00008 // receipt of any required approvals from U.S. Dept. of Energy).  All
00009 // rights reserved.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are met:
00013 //
00014 // (1) Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 // (2) Redistributions in binary form must reproduce the above copyright
00017 // notice, this list of conditions and the following disclaimer in the
00018 // documentation and/or other materials provided with the distribution.
00019 // (3) Neither the name of Lawrence Berkeley National Laboratory, U.S.
00020 // Dept. of Energy nor the names of its contributors may be used to endorse
00021 // or promote products derived from this software without specific prior
00022 // written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035 //
00036 // You are under no obligation whatsoever to provide any bug fixes,
00037 // patches, or upgrades to the features, functionality or performance of
00038 // the source code ("Enhancements") to anyone; however, if you choose to
00039 // make your Enhancements available either publicly, or directly to
00040 // Lawrence Berkeley National Laboratory, without imposing a separate
00041 // written license agreement for such Enhancements, then you hereby grant
00042 // the following license: a non-exclusive, royalty-free perpetual license
00043 // to install, use, modify, prepare derivative works, incorporate into
00044 // other computer software, distribute, and sublicense such Enhancements or
00045 // derivative works thereof, in binary and source code form.
00046 //
00047 // TRADEMARKS. Product and company names mentioned herein may be the
00048 // trademarks of their respective owners.  Any rights not expressly granted
00049 // herein are reserved.
00050 //
00051 
00052 #ifndef _BOXLAYOUT_H_
00053 #define _BOXLAYOUT_H_
00054 
00055 #ifndef WRAPPER
00056 #include "Box.H"
00057 #include "Vector.H"
00058 class DataIterator;
00059 class LayoutIterator;
00060 #include "RefCountedPtr.H"
00061 #include "DataIndex.H"
00062 #include "SPMD.H"
00063 #endif /*WRAPPER*/
00064 
00065 #ifndef DOXYGEN
00066 
00067 struct Entry
00068 {
00069   Entry()
00070     :
00071     m_procID(procID())
00072   {}
00073 
00074   Entry(const Box& a_box)
00075     :
00076     box(a_box),
00077     m_procID(procID())
00078   {}
00079 
00080   Entry(const Box& a_box, const unsigned int a_index)
00081     :
00082     box(a_box),
00083     index(a_index),
00084     m_procID(procID())
00085   {}
00086 
00087   bool operator < (const Entry& rhs) const
00088   { return box < rhs.box;}
00089 
00090   Box box;
00091   unsigned int index;
00092   unsigned int m_procID;// not used in serial code.
00093 };
00094 
00095 #endif
00096 
00098 
00153 class BoxLayout
00154 {
00155 public:
00156 
00161 
00163 
00166   BoxLayout();
00167 
00169 
00172   BoxLayout(const Vector<Box>& a_boxes,
00173             const Vector<int>& a_procIDs);
00174 
00176 
00181   virtual
00182   ~BoxLayout();
00183 
00185 
00188   BoxLayout& operator=(const BoxLayout& a_rhs);
00189 
00191 
00197   virtual void
00198   define(const Vector<Box>& a_boxes,
00199          const Vector<int>& a_procIDs);
00200 
00207 
00209 
00211   const Box&
00212   operator[](const LayoutIndex& it) const;
00213 
00215 
00217   Box&
00218   operator[](const LayoutIndex& it);
00219 
00221 
00228   Box get(const LayoutIndex& it) const;
00229 
00231 
00233   Box get(const LayoutIterator& it) const;
00234 
00236 
00238   Box get(const DataIterator& it) const;
00239 
00241 
00249   unsigned int
00250   procID(const LayoutIndex& a_index) const ;
00251 
00253 
00255   int numBoxes(const int procID) const;
00256 
00258 
00260   inline unsigned int
00261   size() const ;
00262 
00265   unsigned int index(const LayoutIndex& index) const;
00266 
00273 
00275 
00278   inline bool
00279   operator==(const BoxLayout& rhs) const ;
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 
00310 
00312 
00316   DataIndex
00317   addBox(const Box& box, int procID);
00318 
00320 
00322   virtual void
00323   close();
00324 
00326 
00351   virtual void
00352   deepCopy(const BoxLayout& a_source);
00353 
00355 
00361   bool coarsenable(int refRatio) const;
00362 
00364 
00379   friend void coarsen(BoxLayout& output,
00380                       const BoxLayout& input,
00381                       int refinement);
00382 
00384 
00399   friend void refine(BoxLayout& output,
00400                      const BoxLayout& input,
00401                      int refinement);
00402 
00404 
00407   void
00408   setProcID(const LayoutIndex& a_index, unsigned int a_procID);
00409 
00410   //const or non-const operation ?.....I can think of usages either way...bvs
00412 
00416   void
00417   sort();
00418 
00421   void aliasAddBox(const Box& box);
00422 
00425   void aliasClose();
00426 
00433 
00435 
00439   DataIterator
00440   dataIterator() const;
00441 
00443 
00447   LayoutIterator
00448   layoutIterator() const;
00449 
00456 
00457 #ifndef WRAPPER
00458 
00459 
00462   void
00463   print() const;
00464 #endif
00465 
00466 
00469   void p() const { print();}
00470 
00473 protected:
00474 
00475   void setIndexVector();
00476   friend class LayoutIterator;
00477   friend class DataIterator;
00478 
00479   RefCountedPtr<Vector<Entry> >        m_boxes;
00480   RefCountedPtr<Vector<unsigned int> > m_index;
00481   RefCountedPtr<int>                   m_layout;
00482   RefCountedPtr<bool>                  m_closed;
00483   RefCountedPtr<DataIterator>          m_dataIterator;
00484 
00485 private:
00486 
00487 };
00488 
00489 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00490 
00491 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00492 
00493 #ifndef WRAPPER
00494 
00495 inline
00496 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00497 { coarsen(output, input, refinement);}
00498 
00499 inline
00500 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00501 { refine(output, input, refinement);}
00502 
00503 //========================================================
00504 
00505 // inlined functions
00506 // =================
00507 
00508 // constructors
00509 // ============
00510 
00511 /*
00512 inline
00513 BoxLayout::BoxLayout(int a_boxes)
00514   :m_boxes(new std::vector<Entry>(a_boxes)),
00515    m_index(new std::vector<unsigned int>(a_boxes)),
00516    m_layout(new int),
00517    m_closed(new bool(false))
00518 {
00519   std::vector<Entry>& boxes = *m_boxes;
00520   std::vector<unsigned int>& index = *m_index;
00521   for(unsigned int i=0; i<boxes.size(); ++i)
00522     {
00523       boxes[i].index = i;
00524       index[i] = i;
00525     }
00526 }
00527 */
00528 
00529 // operators
00530 // =========
00531 
00532 inline const Box&
00533 BoxLayout::operator[](const LayoutIndex& index) const
00534 {
00535  CH_assert(check(index));// make sure this LayoutIndex came from my own iterator
00536   return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00537 }
00538 
00539 inline Box&
00540 BoxLayout::operator[](const LayoutIndex& index)
00541 {
00542   if(*m_closed)
00543     {
00544       MayDay::Error("attempt to modify closed BoxLayout");
00545     }
00546  CH_assert(check(index)); // make sure this LayoutIndex came from my own iterator
00547   return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00548 }
00549 
00550 inline bool
00551 BoxLayout::operator==(const BoxLayout& rhs) const
00552 {
00553   return m_boxes == rhs.m_boxes;
00554 }
00555 
00556 // member functions
00557 // ================
00558 
00559 inline  Box
00560 BoxLayout::get(const LayoutIndex& index) const
00561 {
00562  CH_assert(check(index)); // make sure this LayoutIndex came from my own iterator
00563   return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00564 }
00565 
00566 inline unsigned int
00567 BoxLayout::index(const LayoutIndex& a_index) const
00568 {
00569   return m_index->operator[](a_index.m_index);
00570 }
00571 
00572 inline bool
00573 BoxLayout::isClosed() const
00574 {
00575   return *m_closed;
00576 }
00577 
00578 inline unsigned int
00579 BoxLayout::procID(const LayoutIndex& a_index) const
00580 {
00581  CH_assert(check(a_index));
00582   return m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID;
00583 }
00584 
00585 inline void
00586 BoxLayout::setProcID(const LayoutIndex& a_index, unsigned int a_procID)
00587 {
00588  CH_assert(check(a_index));
00589   m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID = a_procID;
00590 }
00591 
00592 inline unsigned int
00593 BoxLayout::size() const
00594 {
00595   return m_boxes->size();
00596 }
00597 
00598 // global functions
00599 // ================
00600 
00601 std::ostream& operator<<(std::ostream& os, const BoxLayout& a_layout);
00602 
00603 #endif /*WRAPPER*/
00604 
00605 #endif // DATAPLAN_H

Generated on Wed Oct 5 13:52:08 2005 for Chombo&AMRSelfGravity by  doxygen 1.4.1