Main Page   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    / /__/ _ \/ _ \/  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 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   m_ghost = ghost;
00127 
00128 #ifdef 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 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   assert(comps.size()>0);
00165   // this line doesn't make any sense!
00166   //assert(comps.end()<=this->m_comps);
00167   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 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(const Interval& srcComps,
00215                           LevelData<T>& dest,
00216                           const Interval& destComps) const
00217 {
00218   if(this == &dest){
00219     MayDay::Error("src == dest in copyTo function. Perhaps you want exchange ?");
00220   }
00221 
00222   if(this->boxLayout() == dest.boxLayout()  && dest.ghostVect() == IntVect::Zero)
00223     {
00224       // parallel direct copy here, no communication issues
00225       for(DataIterator it(this->dataIterator()); it.ok(); ++it)
00226         {
00227           dest[it()].copy(this->box(it()),
00228                           destComps,
00229                           this->box(it()),
00230                           this->operator[](it()),
00231                           srcComps);
00232         }
00233       return;
00234     }
00235 
00236   Copier copier(m_disjointBoxLayout, dest.getBoxes(), dest.m_ghost);
00237   copyTo(srcComps, dest, destComps, copier);
00238 }
00239 
00240 template<class T>
00241 void LevelData<T>::copyTo(const Interval& srcComps,
00242                           BoxLayoutData<T>& dest,
00243                           const Interval& destComps,
00244                           const Copier& copier) const
00245 {
00246 
00247   makeItSo(srcComps, *this, dest, destComps, copier);
00248 
00249 }
00250 
00251 template<class T>
00252 void LevelData<T>::copyTo(const Interval& srcComps,
00253                           LevelData<T>& dest,
00254                           const Interval& destComps,
00255                           const Copier& copier,
00256                           const LDOperator<T>& a_op) const
00257 {
00258 
00259   makeItSo(srcComps, *this, dest, destComps, copier, a_op);
00260 
00261 }
00262 
00263 template<class T>
00264 void LevelData<T>::exchange(const Interval& comps)
00265 {
00266   // later on we can code this part as a direct algorithm
00267   // by copying and pasting the code from the Copier::define code
00268   // for now, just do the easy to debug approach.
00269   Copier copier(m_disjointBoxLayout, m_disjointBoxLayout, m_ghost, true);
00270   exchange(comps, copier);
00271 
00272   // if there aren't any ghost cells, there isn't really anything
00273   // to do here (also, if m_ghost == Zero, m_exchangeCopier
00274   // wasn't defined!
00275   //if (m_ghost != IntVect::Zero)
00276   //makeItSo(comps, *this, *this, comps, m_exchangeCopier);
00277 }
00278 
00279 template<class T>
00280 void LevelData<T>::exchange(const Interval& comps,
00281                             const Copier& copier)
00282 {
00283   makeItSo(comps, *this, *this, comps, copier);
00284 
00285 }
00286 
00287 template<class T>
00288 void LevelData<T>::define(const BoxLayout& dp, int comps,  const DataFactory<T>& a_factory)
00289 {
00290   MayDay::Error("LevelData<T>::define called with BoxLayout input");
00291 }
00292 
00293 template<class T>
00294 void LevelData<T>::define(const BoxLayout& dp)
00295 {
00296   MayDay::Error("LevelData<T>::define called with BoxLayout input");
00297 }
00298 
00299 template<class T>
00300 void LevelData<T>::define(const BoxLayoutData<T>& da, const DataFactory<T>& a_factory )
00301 {
00302   MayDay::Error("LevelData<T>::define called with BoxLayout input");
00303 }
00304 
00305 template<class T>
00306 void LevelData<T>::define(const BoxLayoutData<T>& da, const Interval& comps,
00307                           const DataFactory<T>& a_factory)
00308 {
00309   MayDay::Error("LevelData<T>::define called with BoxLayout input");
00310 }
00311 
00312 template<class T>
00313 void LevelData<T>::apply(void (*a_func)(const Box& box, int comps, T& t))
00314 {
00315   for(DataIterator it(this->dataIterator()); it.ok(); ++it)
00316     {
00317       unsigned int index = this->m_boxLayout.index(it());
00318       a_func(m_disjointBoxLayout.get(it()), this->m_comps, *(this->m_vector[index]));
00319     }
00320 }
00321 
00322 #endif

Generated on Wed Jan 19 17:51:25 2005 for Chombo&INSwithParticles by doxygen1.2.16