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

LevelDataI.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 #include <cstdlib>
00029 #include <algorithm>
00030 #include "parstream.H"
00031 #include "memtrack.H"
00032 
00033 using std::sort;
00034 
00035 template<class T> 
00036 LevelData<T>::LevelData()
00037 
00038 {
00039 
00040 }
00041 
00042 template<class T> 
00043 LevelData<T>::~LevelData()
00044 
00045 {
00046 
00047 }
00048 
00049 
00050 template<class T> 
00051 LevelData<T>::LevelData(const DisjointBoxLayout& dp, int comps, const IntVect& ghost,
00052                         const DataFactory<T>& a_factory)
00053   : m_disjointBoxLayout(dp), m_ghost(ghost)
00054 { 
00055 #ifdef MPI
00056   numSends = 0;
00057   numReceives = 0;
00058 #endif
00059   this->m_boxLayout = dp; 
00060   this->m_comps = comps;
00061   this->m_isdefined = true;
00062 
00063   if(!dp.isClosed())
00064     {
00065       MayDay::Error("non-disjoint DisjointBoxLayout: LevelData<T>::LevelData(const DisjointBoxLayout& dp, int comps)");
00066     }
00067 
00068   Interval interval(0, comps-1);
00069   allocateGhostVector(a_factory, ghost);
00070   setVector(*this, interval, interval);
00071   
00072  
00073 }
00074 
00075 
00076 
00077 // Since I need to thwart the user from invoking the
00078 // 'define' methods that use a general BoxLayout, I cannot
00079 // get at said functions myself now. Ha!  So, I have to recode
00080 // them here.
00081 
00082 template<class T> 
00083 void LevelData<T>::define(const DisjointBoxLayout& dp, int comps, const IntVect& ghost,
00084                           const DataFactory<T> & a_factory)
00085 {
00086   this->m_isdefined = true;
00087   if(!dp.isClosed())
00088     {
00089       MayDay::Error("non-disjoint DisjointBoxLayout: LevelData<T>::define(const DisjointBoxLayout& dp,....)");
00090     }
00091   if(comps<=0)
00092     {
00093       MayDay::Error("LevelData::LevelData(const BoxLayout& dp, int comps)  comps<=0");
00094     }
00095   this->m_comps = comps;
00096   this->m_boxLayout = dp;
00097 
00098   m_disjointBoxLayout = dp;
00099   m_ghost = ghost;
00100 
00101   // Interval interval(0, comps-1);
00102   allocateGhostVector(a_factory, ghost);
00103   //  setVector(*this, interval, interval);
00104   
00105   m_ghost = ghost; 
00106 
00107 #ifdef MPI  
00108   m_fromMe.resize(0);
00109   m_toMe.resize(0);
00110 #endif
00111 
00112 }
00113 
00114 
00115 template<class T> 
00116 void LevelData<T>::define(const LevelData<T>& da,  const DataFactory<T> & a_factory)
00117 {
00118   this->m_isdefined = true;
00119   if(this == &da) return;
00120   m_disjointBoxLayout = da.m_disjointBoxLayout;
00121   this->m_boxLayout  = da.m_disjointBoxLayout;
00122   this->m_comps     = da.m_comps;
00123   m_ghost     = da.m_ghost;
00124 
00125   Interval srcAnddest(0, this->m_comps-1);
00126 
00127   allocateGhostVector(a_factory, m_ghost);
00128   setVector(da, srcAnddest, srcAnddest);
00129 
00130 #ifdef MPI
00131   m_fromMe.resize(0);
00132   m_toMe.resize(0);
00133 #endif
00134 }
00135 
00136 
00137 template<class T> 
00138 void LevelData<T>::define(const LevelData<T>& da, const Interval& comps,
00139                           const DataFactory<T>& a_factory)
00140 {
00141   this->m_isdefined = true;
00142   if(this == &da){
00143     MayDay::Error(" LevelData<T>::define(const LevelData<T>& da, const Interval& comps) called with 'this'");
00144   }
00145   assert(comps.size()>0);
00146   // this line doesn't make any sense!
00147   //assert(comps.end()<=this->m_comps);
00148   assert(comps.begin()>=0);
00149 
00150   m_disjointBoxLayout = da.m_disjointBoxLayout;
00151   this->m_boxLayout  = da.m_disjointBoxLayout;
00152 
00153   this->m_comps = comps.size();
00154 
00155   m_ghost = da.m_ghost;
00156 
00157   Interval dest(0, this->m_comps-1);
00158 
00159   allocateGhostVector(a_factory, m_ghost);
00160 
00161   setVector(da, comps, dest);
00162 
00163 #ifdef MPI
00164   m_fromMe.resize(0);
00165   m_toMe.resize(0);
00166 #endif
00167 }
00168 
00169 template<class T> 
00170 void LevelData<T>::copyTo(const Interval& srcComps, 
00171                           BoxLayoutData<T>& dest,
00172                           const Interval& destComps) const
00173 {
00174   if((BoxLayoutData<T>*)this == &dest) return;
00175 
00176   if(this->boxLayout() == dest.boxLayout())
00177     {
00178       // parallel direct copy here, no communication issues
00179       for(DataIterator it(this->dataIterator()); it.ok(); ++it)
00180         {
00181           dest[it()].copy(this->box(it()), 
00182                           destComps,
00183                           this->box(it()),
00184                           this->operator[](it()),
00185                           srcComps);
00186         }
00187       return;
00188     }
00189 
00190   Copier copier(m_disjointBoxLayout, dest.boxLayout());
00191   copyTo(srcComps, dest, destComps, copier);
00192 }
00193 
00194 template<class T> 
00195 void LevelData<T>::copyTo(const Interval& srcComps, 
00196                           LevelData<T>& dest,
00197                           const Interval& destComps) const
00198 {
00199   if(this == &dest){
00200     MayDay::Error("src == dest in copyTo function. Perhaps you want exchange ?");
00201   }
00202 
00203   if(this->boxLayout() == dest.boxLayout()  && dest.ghostVect() == IntVect::Zero)
00204     {
00205       // parallel direct copy here, no communication issues
00206       for(DataIterator it(this->dataIterator()); it.ok(); ++it)
00207         {
00208           dest[it()].copy(this->box(it()), 
00209                           destComps,
00210                           this->box(it()),
00211                           this->operator[](it()),
00212                           srcComps);
00213         }
00214       return;
00215     }
00216 
00217   Copier copier(m_disjointBoxLayout, dest.getBoxes(), dest.m_ghost);
00218   copyTo(srcComps, dest, destComps, copier);
00219 }
00220 
00221 
00222 template<class T> 
00223 void LevelData<T>::copyTo(const Interval& srcComps, 
00224                           BoxLayoutData<T>& dest,
00225                           const Interval& destComps,
00226                           const Copier& copier) const
00227 {
00228 
00229   makeItSo(srcComps, *this, dest, destComps, copier);
00230 
00231 }
00232 
00233 template<class T> 
00234 void LevelData<T>::copyTo(const Interval& srcComps, 
00235                           LevelData<T>& dest,
00236                           const Interval& destComps,
00237                           const Copier& copier,
00238                           const LDOperator<T>& a_op) const
00239 {
00240 
00241   makeItSo(srcComps, *this, dest, destComps, copier, a_op);
00242 
00243 }
00244 
00245 template<class T>  
00246 void LevelData<T>::exchange(const Interval& comps)
00247 {
00248   // later on we can code this part as a direct algorithm
00249   // by copying and pasting the code from the Copier::define code
00250   // for now, just do the easy to debug approach.
00251   Copier copier(m_disjointBoxLayout, m_disjointBoxLayout, m_ghost, true);
00252   exchange(comps, copier);
00253 
00254   // if there aren't any ghost cells, there isn't really anything
00255   // to do here (also, if m_ghost == Zero, m_exchangeCopier
00256   // wasn't defined!
00257   //if (m_ghost != IntVect::Zero)
00258   //makeItSo(comps, *this, *this, comps, m_exchangeCopier);
00259 }
00260 
00261 template<class T> 
00262 void LevelData<T>::exchange(const Interval& comps,
00263                             const Copier& copier)
00264 {
00265   makeItSo(comps, *this, *this, comps, copier);
00266 
00267 }
00268 
00269 
00270 template<class T> 
00271 void LevelData<T>::define(const BoxLayout& dp, int comps,  const DataFactory<T>& a_factory)
00272 {
00273   MayDay::Error("LevelData<T>::define called with BoxLayout input");
00274 }
00275 
00276 template<class T> 
00277 void LevelData<T>::define(const BoxLayout& dp)
00278 {
00279   MayDay::Error("LevelData<T>::define called with BoxLayout input");
00280 }
00281 
00282 template<class T> 
00283 void LevelData<T>::define(const BoxLayoutData<T>& da, const DataFactory<T>& a_factory )
00284 {
00285   MayDay::Error("LevelData<T>::define called with BoxLayout input");
00286 }
00287 
00288 template<class T> 
00289 void LevelData<T>::define(const BoxLayoutData<T>& da, const Interval& comps,
00290                           const DataFactory<T>& a_factory)
00291 {
00292   MayDay::Error("LevelData<T>::define called with BoxLayout input");
00293 }
00294 
00295 
00296 template<class T>
00297 void LevelData<T>::apply(void (*a_func)(const Box& box, int comps, T& t))
00298 {
00299   for(DataIterator it(this->dataIterator()); it.ok(); ++it)
00300     {
00301       unsigned int index = this->m_boxLayout.index(it());
00302       a_func(m_disjointBoxLayout.get(it()), this->m_comps, *(this->m_vector[index]));
00303     }
00304 }
00305 
00306 
00307 

Generated on Fri Jul 2 17:53:42 2004 for Chombo by doxygen 1.3.2