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 _DENSEINTVECTSET_H_
00053 #define _DENSEINTVECTSET_H_
00054
00055 #include "BitSet.H"
00056 #include "IntVect.H"
00057 #include "Box.H"
00058 #include "Vector.H"
00059 #include "ProblemDomain.H"
00060
00061 class ProblemDomain;
00062 class DenseIntVectSetIterator;
00064
00078 class DenseIntVectSet
00079 {
00080 public:
00082 DenseIntVectSet()
00083 {}
00084
00086
00087 DenseIntVectSet(const Box& a_domain, bool init = true);
00088 // copy, and operator= should be fine
00089
00091
00094 DenseIntVectSet& operator-=(const Box& box);
00095
00097
00100 DenseIntVectSet& operator-=(const IntVect& intvect);
00101
00103
00106 DenseIntVectSet& operator-=(const DenseIntVectSet& ivs);
00107
00109
00112 DenseIntVectSet& operator&=(const Box& box);
00113
00115
00118 DenseIntVectSet& operator&=(const ProblemDomain& domain);
00119
00121
00126 DenseIntVectSet& operator|=(const IntVect& intvect);
00127
00129
00134 DenseIntVectSet& operator|=(const Box& b);
00135
00137
00142 DenseIntVectSet& operator|=(const DenseIntVectSet& b);
00143
00145
00148 DenseIntVectSet& operator&=(const DenseIntVectSet& ivs);
00149
00151
00154 void shift(const IntVect& iv);
00155
00157 /* slower, constant time pointwise access.
00158 You should not build a BoxIterator, then access this
00159 method if you intend to iterate over the objects true
00160 or false terms. you should build a DenseIntVectSetIterator */
00161 bool operator[](const IntVect& index) const;
00162
00164
00166 bool contains(const Box& box) const;
00167
00169
00172 void coarsen(int iref);
00173
00175
00178 void refine(int iref);
00179
00181
00184 void grow(int igrow);
00185
00187
00190 void grow(int idir, int igrow);
00191
00193
00198 DenseIntVectSet chop(int dir, int chop_pnt);
00199
00200 inline const Box& box() const;
00201
00203
00205 void nestingRegion(int a_radius, const Box& a_domain);
00206
00208
00209 void nestingRegion(int a_radius, const ProblemDomain& a_domain);
00210
00212
00215 bool isEmpty() const; //cheaper than numPts by wide margin
00216
00218
00221 bool isFull() const; // cheaper than numPts, bu significant margin
00222
00224
00227 int numPts() const;
00228
00230 bool operator==(const DenseIntVectSet& a_lhs) const;
00231
00233
00236 Vector<Box> createBoxes() const;
00238
00242 void compact() const ;
00243
00244 void recalcMinBox() const;
00245
00246 const Box& mBox() const {return m_minBox;}
00247
00250 int linearSize() const;
00251
00252 void linearIn(const void* const inBuf);
00253
00254 void linearOut(void* const a_outBuf) const;
00255
00257 private:
00258
00259 void grow(const IntVect& iv);
00260 // version without checking intersect or empty
00261 DenseIntVectSet& intersect(const DenseIntVectSet& rhs);
00262 Box m_domain;
00263 BitSet m_bits;
00264 friend class DenseIntVectSetIterator;
00265 Box m_minBox;
00266 };
00267
00269
00271 class DenseIntVectSetIterator
00272 {
00273 public:
00274
00276 DenseIntVectSetIterator();
00277
00279 DenseIntVectSetIterator(const DenseIntVectSet& ivs);
00280
00282 void define(const DenseIntVectSet& ivs);
00283 //default null, assignment, copy and destructor should work fine.
00284
00286 const IntVect& operator()() const ;
00287
00289 bool ok() const;
00290
00292 void operator++();
00293
00295 void begin();
00296
00298 void end();
00299
00300 static DenseIntVectSet emptyDenseIntVectSet;
00301
00302 private:
00303 BitSetIterator m_iterator;
00304 IntVect m_current;
00305 const DenseIntVectSet* m_ivsPtr;
00306 int isize, ijsize, bigi, bigj;
00307
00308 void nextIntVect();
00309 void nextIntVect(int skip);
00310
00311 };
00312
00313 //===================================================================
00314
00315 // inline functions
00316
00317 inline
00318 const Box& DenseIntVectSet::box() const { return m_domain;}
00319
00320 inline
00321 DenseIntVectSet& DenseIntVectSet::operator-=(const IntVect& intvect)
00322 {
00323 if(m_domain.contains(intvect))
00324 m_bits.setFalse(m_domain.index(intvect));
00325 return *this;
00326 }
00327
00328 inline void DenseIntVectSet::shift(const IntVect& iv)
00329 {
00330 m_domain.shift(iv);
00331 m_minBox.shift(iv);
00332 }
00333
00334 inline
00335 DenseIntVectSetIterator::DenseIntVectSetIterator()
00336 : m_ivsPtr(&emptyDenseIntVectSet)
00337 {
00338 ;
00339 }
00340
00341 inline
00342 void DenseIntVectSetIterator::define(const DenseIntVectSet& ivs)
00343 {
00344 m_ivsPtr = &ivs;
00345 begin();
00346 }
00347
00348 inline
00349 DenseIntVectSetIterator::DenseIntVectSetIterator(const DenseIntVectSet& ivs)
00350 : m_ivsPtr(&ivs)
00351 {
00352 begin();
00353 }
00354
00355 inline
00356 const IntVect& DenseIntVectSetIterator::operator()() const
00357 {
00358 return m_current;
00359 }
00360
00361 inline
00362 bool DenseIntVectSetIterator::ok() const
00363 {
00364 return m_iterator.ok();
00365 }
00366
00367 inline
00368 void DenseIntVectSetIterator::end()
00369 {
00370 m_iterator.end();
00371 }
00372
00373 // inline
00374 // void DenseIntVectSetIterator::operator++()
00375 // {
00376 // ++m_iterator;
00377 // nextIntVect();
00378 // while(!m_iterator() && m_iterator.ok())
00379 // {
00380 // ++m_iterator; // next bit please
00381 // nextIntVect();
00382 // }
00383 // }
00384 inline
00385 void DenseIntVectSetIterator::operator++()
00386 {
00387 ++m_iterator;
00388 int i=1;
00389 while(m_iterator.ok() && !m_iterator())
00390 {
00391 ++m_iterator; // next bit please
00392 ++i;
00393 }
00394 nextIntVect(i);
00395 }
00396
00397 #endif
1.2.16