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

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

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