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

Copier.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 _COPIER_H_
00053 #define _COPIER_H_
00054 
00055 #include "DisjointBoxLayout.H"
00056 #include "Pool.H"
00057 #include "Vector.H"
00058 #include "ProblemDomain.H"
00059 
00060 class MotionItem;
00061 class CopyIterator;
00062 
00064 
00085 class Copier
00086 {
00087 public:
00088 
00090   Copier()
00091   {}
00092 
00094   Copier(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
00095          bool a_exchange = false);
00096 
00098   Copier(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
00099          const ProblemDomain& a_domain,
00100          bool  a_exchange  = false);
00101 
00103   Copier(const DisjointBoxLayout& a_level,
00104          const BoxLayout& a_dest,
00105          const IntVect& a_destGhost,
00106          bool  a_exchange = false);
00107 
00109   Copier(const DisjointBoxLayout& a_level,
00110          const BoxLayout& a_dest,
00111          const ProblemDomain& a_domain,
00112          const IntVect& a_destGhost,
00113          bool  a_exchange = false);
00114 
00116   virtual ~Copier();
00117 
00119   virtual void define(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
00120                       bool  a_exchange = false);
00121 
00123   virtual void define(const DisjointBoxLayout& a_level,
00124                       const BoxLayout& a_dest,
00125                       const ProblemDomain& a_domain,
00126                       bool  a_exchange = false);
00127 
00129   virtual void define(const DisjointBoxLayout& a_level,
00130                       const BoxLayout& a_dest,
00131                       const IntVect& a_destGhost,
00132                       bool  a_exchange = false);
00133 
00135   virtual void define(const BoxLayout& a_level,
00136                       const BoxLayout& a_dest,
00137                       const ProblemDomain& a_domain,
00138                       const IntVect& a_destGhost,
00139                       bool  a_exchange = false);
00140 
00142 
00146   void ghostDefine(const DisjointBoxLayout& a_src,
00147                    const DisjointBoxLayout& a_dest,
00148                    const ProblemDomain& a_domain,
00149                    const IntVect& a_srcGhost);
00151   virtual void clear();
00152 
00154   bool check(const DisjointBoxLayout& from, const BoxLayout& to) const;
00155 
00156   int print() const;
00157 
00158   bool bufferAllocated() const;
00159   void setBufferAllocated(bool arg) const;
00160 
00161   int numLocalCellsToCopy() const;
00162   int numFromCellsToCopy() const;
00163   int numToCellsToCopy() const;
00164 
00165 
00166 protected:
00167 
00168   friend class CopyIterator;
00169 
00170   Vector<MotionItem*> m_localMotionPlan;
00171   Vector<MotionItem*> m_fromMotionPlan;
00172   Vector<MotionItem*> m_toMotionPlan;
00173 
00174   friend void dumpmemoryatexit();
00175   static Pool s_motionItemPool;
00176   mutable bool buffersAllocated;
00177 private:
00178 
00179   // keep a refcounted reference around for debugging purposes, we can
00180   // decide afterwards if we want to eliminate it.
00181   DisjointBoxLayout m_originPlan;
00182   BoxLayout  m_dest;
00183 
00184 };
00185 
00186 std::ostream& operator<<(std::ostream& os, const Copier& copier);
00187 
00188 //===========================================================================
00189 // end of public interface for Copier.
00190 //===========================================================================
00191 
00192 //  These classes are public because I can't find a nice
00193 //  way to make a class a friend of all the instantiations
00194 //  of a template class.  These classes are not part of
00195 //  the public interface for the Array API.
00196 //
00197 //  Later, if MotionItem shows up in the profiler, we
00198 //  can start using a pool allocation scheme and placement new
00199 
00200 class MotionItem{
00201 public:
00202   DataIndex fromIndex, toIndex;
00203   Box fromRegion;
00204   Box toRegion;
00205   int procID;
00206   // this constructor will probably eventually go away
00207   MotionItem(const DataIndex& a_from,
00208              const DataIndex& a_to,
00209              const Box&       a_region);
00210   MotionItem(const DataIndex& a_from,
00211              const DataIndex& a_to,
00212              const Box&       a_fromRegion,
00213              const Box&       a_toRegion);
00214   void reverse();
00215 
00216 };
00217 
00218 inline MotionItem::MotionItem(const DataIndex& a_from,
00219                               const DataIndex& a_to,
00220                               const Box&       a_region)
00221   :fromIndex(a_from), toIndex(a_to), fromRegion(a_region),
00222   toRegion(a_region), procID(-1)
00223 {}
00224 
00225 inline MotionItem::MotionItem(const DataIndex& a_from,
00226                               const DataIndex& a_to,
00227                               const Box&       a_fromRegion,
00228                               const Box&       a_toRegion)
00229   :fromIndex(a_from), toIndex(a_to), fromRegion(a_fromRegion),
00230   toRegion(a_toRegion), procID(-1)
00231 {}
00232 
00233 inline
00234 void  MotionItem::reverse()
00235 {
00236   Box tmp(fromRegion);
00237   fromRegion=toRegion;
00238   toRegion=tmp;
00239   DataIndex tmpIndex(fromIndex);
00240   fromIndex = toIndex;
00241   toIndex = tmpIndex;
00242 }
00243 
00244 class CopyIterator
00245 {
00246 public:
00247   enum local_from_to {LOCAL, FROM, TO};
00248 
00249   inline CopyIterator(const Copier& a_copier, local_from_to);
00250 
00251   inline const MotionItem& operator()() const;
00252 
00253   inline void operator++();
00254 
00255   inline bool ok() const;
00256 
00257   inline void reset();
00258 private:
00259   const Vector<MotionItem*>* m_motionplanPtr;
00260   unsigned int  m_current;
00261 };
00262 
00263 //====== inlined functions====================================
00264 
00265 inline CopyIterator::CopyIterator(const Copier& a_copier, local_from_to type)
00266   :m_current(0)
00267 {
00268   switch(type){
00269   case LOCAL:
00270     m_motionplanPtr = &(a_copier.m_localMotionPlan);
00271     break;
00272   case FROM:
00273     m_motionplanPtr = &(a_copier.m_fromMotionPlan);
00274     break;
00275   case TO:
00276     m_motionplanPtr = &(a_copier.m_toMotionPlan);
00277     break;
00278   default:
00279     MayDay::Error("illegal local_from_to option for CopyIterator");
00280   }
00281 }
00282 
00283 inline const MotionItem& CopyIterator::operator()() const
00284 {
00285  CH_assert(m_current < m_motionplanPtr->size());
00286   return *(m_motionplanPtr->operator[](m_current));
00287 }
00288 
00289 inline void CopyIterator::operator++() {++m_current;}
00290 
00291 inline bool CopyIterator::ok() const
00292 {
00293   return m_current < m_motionplanPtr->size();
00294 }
00295 
00296 inline void CopyIterator::reset()
00297 {
00298   m_current = 0;
00299 }
00300 
00301 #endif

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