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

LevelData.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 _LEVELDATA_H_
00029 #define _LEVELDATA_H_
00030 
00031 #include "IntVect.H"
00032 #include "BoxLayoutData.H"
00033 #include "DisjointBoxLayout.H"
00034 #include "Copier.H"
00035 #include "SPMD.H"
00036 
00037 template <class T>
00038 class LDOperator
00039 {
00040 public:
00041   virtual int size(const T& arg, const Box& b, const Interval& comps) const
00042   {
00043         return arg.size(b, comps);
00044   }
00045   virtual void linearOut(const T& arg, void* buf, const Box& R, 
00046                          const Interval& comps) const
00047   {
00048         arg.linearOut(buf, R, comps);
00049   }
00050   virtual void linearIn(T& arg,  void* buf, const Box& R, 
00051                         const Interval& comps)const
00052   {
00053         arg.linearIn(buf, R, comps);
00054   }
00055   virtual void op(T& dest, 
00056                   const Box& RegionFrom, 
00057                   const Interval& Cdest, 
00058                   const Box& RegionTo,
00059                   const T& src, 
00060                   const Interval& Csrc) const
00061   {
00062         dest.copy(RegionFrom, Cdest,RegionTo, src, Csrc);
00063   }
00064 }; 
00065 
00067 
00080 template<class T> class LevelData : public BoxLayoutData<T>
00081 {
00082 public:
00083 
00085   LevelData();
00086 
00088   LevelData(const DisjointBoxLayout& dp, int comps,
00089             const IntVect& ghost = IntVect::TheZeroVector(),
00090             const DataFactory<T>& a_factory = DefaultDataFactory<T>());
00091 
00093   virtual ~LevelData();
00094 
00095 
00097   virtual void define(const DisjointBoxLayout& dp, int comps,
00098                       const IntVect& ghost = IntVect::TheZeroVector(),
00099                       const DataFactory<T>& a_factory = DefaultDataFactory<T>());
00100 
00101 
00103 
00106   virtual void define(const LevelData<T>& da,
00107                       const DataFactory<T>& a_factory = DefaultDataFactory<T>());
00108 
00110 
00115   virtual void define(const LevelData<T>& da, const Interval& comps,
00116                       const DataFactory<T>& a_factory = DefaultDataFactory<T>());
00117 
00119   virtual void copyTo(const Interval& srcComps,
00120                       BoxLayoutData<T>& dest,
00121                       const Interval& destComps) const;
00122 
00124   virtual void copyTo(const Interval& srcComps,
00125                       BoxLayoutData<T>& dest,
00126                       const Interval& destComps,
00127                       const Copier& copier) const;
00129 
00131   virtual void copyTo(const Interval& srcComps,
00132                       LevelData<T>& dest,
00133                       const Interval& destComps) const;
00134 
00136 
00139   virtual void copyTo(const Interval& srcComps,
00140                       LevelData<T>& dest,
00141                       const Interval& destComps,
00142                       const Copier& copier,
00143                       const LDOperator<T>& a_op = LDOperator<T>()) const;
00144 
00146   virtual void exchange(const Interval& comps);
00147 
00149   virtual void exchange(const Interval& comps,
00150                         const Copier& copier);
00151 
00153   const IntVect& ghostVect() const { return m_ghost;}
00154 
00168   virtual void define(const BoxLayout& dp, int comps,
00169                       const DataFactory<T>& factory);
00170 
00172   virtual void define(const BoxLayoutData<T>& da,
00173                       const DataFactory<T>& factory = DefaultDataFactory<T>());
00174 
00176   virtual void define(const BoxLayoutData<T>& da, const Interval& comps,
00177                       const DataFactory<T>& factory = DefaultDataFactory<T>());
00178 
00179   virtual void define(const BoxLayout& deadFunction);
00182 
00183   const DisjointBoxLayout& getBoxes() const
00184   {
00185     return m_disjointBoxLayout;
00186   }
00187 
00189   const DisjointBoxLayout& disjointBoxLayout() const
00190   {
00191     return m_disjointBoxLayout;
00192   }
00193 
00195 
00219   virtual void apply(void (*a_Function)(const Box& box, int comps, T& t));
00220 
00221 protected:
00222 
00223   void makeItSo(const Interval&     a_srcComps,
00224                 const LevelData<T>& a_src,
00225                 BoxLayoutData<T>&   a_dest,
00226                 const Interval&     a_destComps,
00227                 const Copier&       a_copier,
00228                 const LDOperator<T>& a_op = LDOperator<T>()) const;
00229 
00230   DisjointBoxLayout m_disjointBoxLayout;
00231 
00232   IntVect   m_ghost;
00233 
00234   // attempt to speed up the periodic code
00235   //Copier m_exchangeCopier;
00236 
00237   //========================================================================
00238   //
00239   // data structures used by makeItSo when we have some
00240   // data that needs to be moved (ie. there are entries
00241   // in the 'FROM' or 'TO' CopyIterators)
00242   //
00243   void completePendingSends() const;
00244 
00245   void allocateBuffers(const LevelData<T>& a_src,
00246                        const Interval& a_srcComps,
00247                        const BoxLayoutData<T>& a_dest,
00248                        const Interval& a_destComps,
00249                        const Copier&   a_copier,
00250                        const LDOperator<T>& a_op) const;
00251 
00252   void writeSendDataFromMeIntoBuffers(const LevelData<T>& a_src,
00253                                       const Interval& a_srcComps,
00254                                       const LDOperator<T>& a_op) const;
00255 
00256   void postSendsFromMe() const ;
00257 
00258   void postReceivesToMe() const ;
00259 
00260   void unpackReceivesToMe(BoxLayoutData<T>& a_dest,
00261                           const Interval&   a_destComps,
00262                           const LDOperator<T>& a_op) const ;
00263 
00266   mutable void*  m_sendbuffer; // pointer member OK here,
00267                                // since LevelData<T> has no copy
00268   mutable size_t m_sendcapacity;
00269   mutable void*  m_recbuffer;  // pointer member OK here,
00270                                // since LevelData<T> has no copy
00271   mutable size_t m_reccapacity;
00272 
00273 #ifdef MPI
00274 
00275 #ifndef DOXYGEN
00276 
00277   struct bufEntry
00278   {
00279     void* bufPtr; // pointer into contiguous m_buffer
00280     size_t size;
00281     const MotionItem* item;
00282     unsigned int procID;
00283     bool operator < (const bufEntry& rhs) const
00284       {
00285         if(procID == rhs.procID)
00286           {
00287             const Box& left = item->toRegion;
00288             const Box& right= rhs.item->toRegion;
00289             if(left.smallEnd() == right.smallEnd())
00290               {
00291                 return left.bigEnd().lexLT(right.bigEnd());
00292               }
00293             else
00294               {
00295                 return item->toRegion < rhs.item->toRegion;
00296               }
00297           }
00298         //else
00299         return procID < rhs.procID;
00300       }
00301   };
00302 
00303 #endif
00304   mutable std::vector<bufEntry> m_fromMe;
00305   mutable std::vector<bufEntry> m_toMe;
00306 
00307   mutable MPI_Request  *m_sendRequests, *m_receiveRequests;
00308   mutable MPI_Status   *m_sendStatus,   *m_receiveStatus;
00309   mutable int numSends, numReceives;
00310 
00311 #endif
00312 
00314 #ifdef DOXYGEN
00315   friend void aliasLevelData<T>(LevelData<T>& a_alias,
00316                                 LevelData<T>* a_original,
00317                                 const Interval& a_interval);
00318 #endif
00319 
00320 };
00321 
00323 
00350 template <class T>
00351 void aliasLevelData(LevelData<T>& a_alias, LevelData<T>* a_original,
00352                     const Interval& a_interval)
00353 {
00354   AliasDataFactory<T> factory(a_original, a_interval);
00355   a_alias.define(a_original->disjointBoxLayout(), a_interval.size(), a_original->ghostVect(), factory);
00356 }
00357 
00358 
00359 // ====== inlined function definitions ================
00360 
00361 // As with the BoxLayoutData implementation file.  This file
00362 // just gives the interface and the inline implmentations
00363 // are given in LevelDataI.H
00364 
00365 #include "LevelDataI.H"
00366 
00367 
00368 
00369 #endif

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