00001 /* 00002 ** (c) 1996-2000 The Regents of the University of California (through 00003 ** E.O. Lawrence Berkeley National Laboratory), subject to approval by 00004 ** the U.S. Department of Energy. Your use of this software is under 00005 ** license -- the license agreement is attached and included in the 00006 ** directory as license.txt or you may contact Berkeley Lab's Technology 00007 ** Transfer Department at TTD@lbl.gov. NOTICE OF U.S. GOVERNMENT RIGHTS. 00008 ** The Software was developed under funding from the U.S. Government 00009 ** which consequently retains certain rights as follows: the 00010 ** U.S. Government has been granted for itself and others acting on its 00011 ** behalf a paid-up, nonexclusive, irrevocable, worldwide license in the 00012 ** Software to reproduce, prepare derivative works, and perform publicly 00013 ** and display publicly. Beginning five (5) years after the date 00014 ** permission to assert copyright is obtained from the U.S. Department of 00015 ** Energy, and subject to any subsequent five (5) year renewals, the 00016 ** U.S. Government is granted for itself and others acting on its behalf 00017 ** a paid-up, nonexclusive, irrevocable, worldwide license in the 00018 ** Software to reproduce, prepare derivative works, distribute copies to 00019 ** the public, perform publicly and display publicly, and to permit 00020 ** others to do so. 00021 */ 00022 00023 #ifndef BL_INDEXTYPE_H 00024 #define BL_INDEXTYPE_H 00025 // 00026 // $Id: IndexType.H,v 1.14 2001/10/10 20:12:44 car Exp $ 00027 // 00028 #include <iosfwd> 00029 00030 #include <ccse-mpi.H> 00031 #include <IntVect.H> 00032 #include <SPACE.H> 00033 00034 // 00035 // : 00037 00045 class IndexType 00046 { 00047 friend MPI_Datatype ParallelDescriptor::Mpi_typemap<IndexType>::type(); 00048 public: 00049 // 00051 // 00052 enum CellIndex { CELL = 0, NODE = 1 }; 00053 // 00055 // 00056 IndexType (); 00057 // 00059 // 00060 IndexType (const IndexType& rhs); 00061 // 00063 // 00064 explicit IndexType (const IntVect& iv); 00065 // 00067 // 00068 IndexType& operator= (const IndexType& rhs); 00069 00074 IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k)); 00075 // 00077 // 00078 void set (int dir); 00079 // 00081 // 00082 void unset (int dir); 00083 // 00085 // 00086 bool test (int dir) const; 00087 // 00089 // 00090 void setall (); 00091 // 00093 // 00094 void clear (); 00095 // 00097 // 00098 bool any () const; 00099 // 00101 // 00102 bool ok () const; 00103 // 00105 // 00106 void flip (int i); 00107 // 00109 // 00110 bool operator== (const IndexType& t) const; 00111 // 00113 // 00114 bool operator!= (const IndexType& t) const; 00115 // 00117 // 00118 bool cellCentered () const; 00119 // 00121 // 00122 bool nodeCentered () const; 00123 // 00125 // 00126 void setType (int dir, 00127 CellIndex t); 00128 // 00130 // 00131 CellIndex ixType (int dir) const; 00132 // 00134 // 00135 int operator[] (int dir) const; 00136 // 00138 // 00139 IntVect ixType () const; 00140 00146 static IndexType TheCellType (); 00147 00153 static IndexType TheNodeType (); 00154 static IndexType TheUMACType (); 00155 static IndexType TheVMACType (); 00156 static IndexType TheWMACType (); 00157 00158 private: 00159 // 00160 // Returns 1<<k. 00161 // 00162 static int mask (int k); 00163 // 00164 // An integer holding the CellIndex in bits 0 - BL\_SPACEDIM-1. 00165 // 00166 unsigned int itype; 00167 }; 00168 00169 // 00171 // 00172 std::ostream& operator<< (std::ostream& os, const IndexType& itype); 00173 // 00175 // 00176 std::istream& operator>> (std::istream& is, IndexType& itype); 00177 00178 inline 00179 int 00180 IndexType::mask (int k) 00181 { 00182 return 1<<k; 00183 } 00184 00185 inline 00186 IndexType::IndexType () 00187 : 00188 itype(0) 00189 {} 00190 00191 inline 00192 IndexType::IndexType (const IndexType& bt) 00193 : 00194 itype(bt.itype) 00195 {} 00196 00197 inline 00198 IndexType& 00199 IndexType::operator= (const IndexType& bt) 00200 { 00201 itype = bt.itype; 00202 return *this; 00203 } 00204 00205 inline 00206 void 00207 IndexType::set (int dir) 00208 { 00209 itype |= mask(dir); 00210 } 00211 00212 inline 00213 void 00214 IndexType::unset (int dir) 00215 { 00216 itype &= ~mask(dir); 00217 } 00218 00219 inline 00220 bool 00221 IndexType::test (int dir) const 00222 { 00223 return (itype & mask(dir)) != 0; 00224 } 00225 00226 inline 00227 void 00228 IndexType::setall () 00229 { 00230 itype = (1 << BL_SPACEDIM) - 1; 00231 } 00232 00233 inline 00234 void 00235 IndexType::clear () 00236 { 00237 itype = 0; 00238 } 00239 00240 inline 00241 bool 00242 IndexType::any () const 00243 { 00244 return itype != 0; 00245 } 00246 00247 inline 00248 bool 00249 IndexType::ok () const 00250 { 00251 return itype < (1 << BL_SPACEDIM); 00252 } 00253 00254 inline 00255 void 00256 IndexType::flip (int i) 00257 { 00258 itype ^= mask(i); 00259 } 00260 00261 inline 00262 bool 00263 IndexType::operator== (const IndexType& t) const 00264 { 00265 return t.itype == itype; 00266 } 00267 00268 inline 00269 bool 00270 IndexType::operator!= (const IndexType& t) const 00271 { 00272 return t.itype != itype; 00273 } 00274 00275 inline 00276 bool 00277 IndexType::cellCentered () const 00278 { 00279 return itype == 0; 00280 } 00281 00282 inline 00283 bool 00284 IndexType::nodeCentered () const 00285 { 00286 return itype == (1<<BL_SPACEDIM)-1; 00287 } 00288 00289 inline 00290 int 00291 IndexType::operator[] (int dir) const 00292 { 00293 return test(dir); 00294 } 00295 00296 #endif /*BL_INDEXTYPE_H*/