Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef _included_GridData_1_h 00002 #define _included_GridData_1_h 00003 00009 #include "DAGHParams.h" 00010 #include "GridDataParams.h" 00011 00012 #ifdef DEBUG_PRINT_GD_MEMORY 00013 #include "DAGHMemoryTrace.h" 00014 #endif 00015 00016 #include "BBox.h" 00017 #include "Coords.h" 00018 #include "PackedGridDataBucket.h" 00019 00020 #ifdef DEBUG_PRINT 00021 #include "CommServer.h" 00022 #endif 00023 00024 #include "IndexGridData1.h" 00025 00026 #ifndef GridData 00027 #define GridData(dim) name2(GridData,dim) 00028 #endif 00029 00030 #ifndef gd_OperateRegion 00031 #define gd_OperateRegion(op) name2(gd_OperateRegion,op) 00032 #endif 00033 00034 #include "GDIterator.h" 00035 00045 template <class Type> class GridData(1) 00046 { 00047 BBox _bbox; 00048 Coords _extents; 00049 Coords _step; 00050 int _size; 00051 int _bottom; 00052 Type *_data; 00053 00054 public: 00055 GridData(1)(void); 00056 GridData(1)(BBox const &bbox); 00057 GridData(1)(int const i, int const ii); 00058 GridData(1)(int const i, int const ii, int const s); 00059 GridData(1)(BBox const &bbox, Type *databuf); 00060 GridData(1)(GridDataBucket<Type> &gdbkt); 00061 GridData(1)(GridDataBucket<Type> &gdbkt, int const n); 00062 /* A "psuedo" copy-constructor */ 00063 GridData(1) (GridData(1)<Type> const &other); 00064 00065 inline ~GridData(1)(void) 00066 { 00067 if (_data) { 00068 delete [] _data; 00069 #ifdef DEBUG_PRINT_GD_MEMORY 00070 DAGHMemoryTrace::free(sizeof(Type)*_size); 00071 #endif 00072 } 00073 } 00074 00075 void allocate(BBox const &bbox); 00076 void allocate(BBox const &bbox, Type *databuf); 00077 00078 inline void allocate(Type *databuf) 00079 { 00080 if (_data) { 00081 delete [] _data; _data = (Type*)0; 00082 #ifdef DEBUG_PRINT_GD_MEMORY 00083 DAGHMemoryTrace::free(sizeof(Type)*_size); 00084 #endif 00085 } 00086 _data = databuf; 00087 } 00088 00089 inline void deallocate() 00090 { 00091 if (_data) { 00092 delete [] _data; _data = (Type*)0; 00093 #ifdef DEBUG_PRINT_GD_MEMORY 00094 DAGHMemoryTrace::free(sizeof(Type)*_size); 00095 #endif 00096 } 00097 } 00098 inline void deallocate(Type*& databuf) 00099 { databuf = _data; _data = (Type*) 0; } 00100 00101 void* databuffer() { return ((void*) _data); } 00102 00103 /* Query funtions */ 00104 /* Define some inline functions for getting at region extents */ 00105 00106 inline const Coords& lower() const { return(_bbox.lower()); } 00107 inline const Coords& upper() const { return(_bbox.upper()); } 00108 inline const Coords& extents() const { return(_extents); } 00109 inline const Coords& stepsize() const { return(_step); } 00110 inline Coords lower() { return(_bbox.lower()); } 00111 inline Coords upper() { return(_bbox.upper()); } 00112 inline Coords extents() { return(_extents); } 00113 inline Coords stepsize() { return(_step); } 00114 inline int bottom() const { return(_bottom); } 00115 inline int lower(const int i) const { return(_bbox.lower(i)); } 00116 inline int upper(const int i) const { return(_bbox.upper(i)); } 00117 inline int extents(const int i) const { return(_extents(i)); } 00118 inline int stepsize(int const i) const { return(_step(i)); } 00119 inline const BBox& bbox() const { return(_bbox); } 00120 00121 /* Define the inline functions for indexing the GridData object */ 00122 00123 inline int ok_to_index() { return(_data != (Type *) NULL); } 00124 inline int size() const { return(_size); } 00125 00126 inline int idx(const int i) const 00127 { return( _bottom+(i/_step(0)) ); } 00128 00129 inline const Type& operator () (const int i) const 00130 { assert(idx(i) >= 0 && idx(i) < _size); return(_data[idx(i)]); } 00131 inline Type& operator () (const int i) 00132 { assert(idx(i) >= 0 && idx(i) < _size); return(_data[idx(i)]); } 00133 00134 inline const Type& operator () (const Coords& c) const 00135 { assert(idx(c(0)) >= 0 && idx(c(0)) < _size); return(_data[idx(c(0))]); } 00136 inline Type& operator () (const Coords& c) 00137 { assert(idx(c(0)) >= 0 && idx(c(0)) < _size); return(_data[idx(c(0))]); } 00138 00139 inline const Type *ptr(const int i) const 00140 { assert(idx(i) >= 0 && idx(i) < _size); return(_data + idx(i)); } 00141 inline Type *ptr(const int i) 00142 { assert(idx(i) >= 0 && idx(i) < _size); return(_data + idx(i)); } 00143 00144 inline const Type *ptr(const Coords& c) const 00145 { assert(idx(c(0)) >= 0 && idx(c(0)) < _size); return(_data + idx(c(0))); } 00146 inline Type *ptr(const Coords& c) 00147 { assert(idx(c(0)) >= 0 && idx(c(0)) < _size); return(_data + idx(c(0))); } 00148 00149 inline const Type *data() const { return(_data); } 00150 inline Type *data() { return(_data); } 00151 00152 void fill(Type const &val); 00153 00154 /* Define the copy functions for communication between objects */ 00155 void copy(GridData(1)<Type> const &gd); 00156 void copy(GridData(1)<Type> const &gd, BBox const &where); 00157 void copy(GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00158 00159 void copy(GridDataBucket<Type> const &gdbkt); 00160 void copy(GridDataBucket<Type> const &gdbkt, BBox const &where); 00161 void copy(GridDataBucket<Type> const &gdbkt, BBox const &to, 00162 BBox const &from); 00163 00164 void copy(GridDataBucket<Type> const &gdbkt, int const n); 00165 void copy(GridDataBucket<Type> const &gdbkt, int const n, BBox const &where); 00166 void copy(GridDataBucket<Type> const &gdbkt, int const n, BBox const &to, 00167 BBox const &from); 00168 00169 /* Linear interpolation */ 00170 void lin_interp(GridData(1)<Type> const &gd1, double const frac1, 00171 GridData(1)<Type> const &gd2, double const frac2, 00172 BBox const &where); 00173 inline void lin_interp(GridData(1)<Type> const &gd1, double const frac1, 00174 GridData(1)<Type> const &gd2, double const frac2) 00175 { GridData(1)<Type>::lin_interp(gd1,frac1,gd2,frac2,_bbox); } 00176 00177 /* first moment (i think) sum(q(i)*i) */ 00178 Type moment1(int const axis, BBox const &where); 00179 inline Type moment1(int const axis) 00180 { return (GridData(1)<Type>::moment1(axis,_bbox)); } 00181 00182 /* sum of squares - for calculating L2-norm */ 00183 double sumsqrd(BBox const &where); 00184 inline double sumsqrd() 00185 { return (GridData(1)<Type>::sumsqrd(_bbox)); } 00186 00187 /* sum of absolute values - for calculating L1-norm */ 00188 double sumabs(BBox const &where); 00189 inline double sumabs() 00190 { return (GridData(1)<Type>::sumabs(_bbox)); } 00191 00192 /* Maximum of absolute values - for calculating Loo-norm */ 00193 double maxabs(BBox const &where); 00194 inline double maxabs() 00195 { return (GridData(1)<Type>::maxabs(_bbox)); } 00196 00197 /* operator == */ 00198 BBox is_eq(Type const &val, BBox const &where); 00199 inline BBox is_eq(Type const &val) 00200 { return (GridData(1)<Type>::is_eq(val, _bbox)); } 00201 00202 BBox is_eq(GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00203 inline BBox is_eq(GridData(1)<Type> const &gd) 00204 { return (GridData(1)<Type>::is_eq(gd, gd._bbox, gd._bbox)); } 00205 inline BBox is_eq(GridData(1)<Type> const &gd, BBox const &where) 00206 { return (GridData(1)<Type>::is_eq(gd, where, where)); } 00207 00208 /* operator != */ 00209 BBox is_neq(Type const &val, BBox const &where); 00210 inline BBox is_neq(Type const &val) 00211 { return (GridData(1)<Type>::is_neq(val, _bbox)); } 00212 00213 BBox is_neq(GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00214 inline BBox is_neq(GridData(1)<Type> const &gd) 00215 { return (GridData(1)<Type>::is_neq(gd, gd._bbox, gd._bbox)); } 00216 inline BBox is_neq(GridData(1)<Type> const &gd, BBox const &where) 00217 { return (GridData(1)<Type>::is_neq(gd, where, where)); } 00218 00219 /* operator > */ 00220 BBox is_gt(Type const &val, BBox const &where); 00221 inline BBox is_gt(Type const &val) 00222 { return (GridData(1)<Type>::is_gt(val, _bbox)); } 00223 00224 BBox is_gt(GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00225 inline BBox is_gt(GridData(1)<Type> const &gd) 00226 { return (GridData(1)<Type>::is_gt(gd, gd._bbox, gd._bbox)); } 00227 inline BBox is_gt(GridData(1)<Type> const &gd, BBox const &where) 00228 { return (GridData(1)<Type>::is_gt(gd, where, where)); } 00229 00230 /* operator >= */ 00231 BBox is_ge(Type const &val, BBox const &where); 00232 inline BBox is_ge(Type const &val) 00233 { return (GridData(1)<Type>::is_ge(val, _bbox)); } 00234 00235 BBox is_ge(GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00236 inline BBox is_ge(GridData(1)<Type> const &gd) 00237 { return (GridData(1)<Type>::is_ge(gd, gd._bbox, gd._bbox)); } 00238 inline BBox is_ge(GridData(1)<Type> const &gd, BBox const &where) 00239 { return (GridData(1)<Type>::is_ge(gd, where, where)); } 00240 00241 /* operator < */ 00242 BBox is_lt(Type const &val, BBox const &where); 00243 inline BBox is_lt(Type const &val) 00244 { return (GridData(1)<Type>::is_lt(val, _bbox)); } 00245 00246 BBox is_lt(GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00247 inline BBox is_lt(GridData(1)<Type> const &gd) 00248 { return (GridData(1)<Type>::is_lt(gd, gd._bbox, gd._bbox)); } 00249 inline BBox is_lt(GridData(1)<Type> const &gd, BBox const &where) 00250 { return (GridData(1)<Type>::is_lt(gd, where, where)); } 00251 00252 /* operator <= */ 00253 BBox is_le(Type const &val, BBox const &where); 00254 inline BBox is_le(Type const &val) 00255 { return (GridData(1)<Type>::is_le(val, _bbox)); } 00256 00257 BBox is_le(GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00258 inline BBox is_le(GridData(1)<Type> const &gd) 00259 { return (GridData(1)<Type>::is_le(gd, gd._bbox, gd._bbox)); } 00260 inline BBox is_le(GridData(1)<Type> const &gd, BBox const &where) 00261 { return (GridData(1)<Type>::is_le(gd, where, where)); } 00262 00263 /* operator = */ 00264 void equals(Type const &val, BBox const &where); 00265 inline void equals(Type const &val) 00266 { GridData(1)<Type>::equals(val, _bbox); } 00267 00268 void equals(GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00269 inline void equals(GridData(1)<Type> const &gd) 00270 { GridData(1)<Type>::equals(gd, gd._bbox, gd._bbox); } 00271 inline void equals(GridData(1)<Type> const &gd, BBox const &where) 00272 { GridData(1)<Type>::equals(gd, where, where); } 00273 00274 /* operator += */ 00275 void plus (Type const &val, BBox const &where); 00276 inline void plus (Type const &val) 00277 { GridData(1)<Type>::plus(val, _bbox); } 00278 00279 void plus (GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00280 inline void plus (GridData(1)<Type> const &gd) 00281 { GridData(1)<Type>::plus(gd, gd._bbox, gd._bbox); } 00282 inline void plus (GridData(1)<Type> const &gd, BBox const &where) 00283 { GridData(1)<Type>::plus(gd, where, where); } 00284 00285 /* operator -= */ 00286 void minus (Type const &val, BBox const &where); 00287 inline void minus (Type const &val) 00288 { GridData(1)<Type>::minus(val, _bbox); } 00289 00290 void minus (GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00291 inline void minus (GridData(1)<Type> const &gd) 00292 { GridData(1)<Type>::minus(gd, gd._bbox, gd._bbox); } 00293 inline void minus (GridData(1)<Type> const &gd, BBox const &where) 00294 { GridData(1)<Type>::minus(gd, where, where); } 00295 00296 /* operator *= */ 00297 void multiply(Type const &val, BBox const &where); 00298 inline void multiply(Type const &val) 00299 { GridData(1)<Type>::multiply(val, _bbox); } 00300 00301 void multiply (GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00302 inline void multiply (GridData(1)<Type> const &gd) 00303 { GridData(1)<Type>::multiply(gd, gd._bbox, gd._bbox); } 00304 inline void multiply (GridData(1)<Type> const &gd, BBox const &where) 00305 { GridData(1)<Type>::multiply(gd, where, where); } 00306 00307 /* operator /= */ 00308 void divide (Type const &val, BBox const &where); 00309 inline void divide (Type const &val) 00310 { GridData(1)<Type>::divide(val, _bbox); } 00311 00312 void divide (GridData(1)<Type> const &gd, BBox const &to, BBox const &from); 00313 inline void divide (GridData(1)<Type> const &gd) 00314 { GridData(1)<Type>::divide(gd, gd._bbox, gd._bbox); } 00315 inline void divide (GridData(1)<Type> const &gd, BBox const &where) 00316 { GridData(1)<Type>::divide(gd, where, where); } 00317 00318 /**********************************************************************/ 00319 inline BBox operator == (Type const &val) 00320 { return (GridData(1)<Type>::is_eq(val, _bbox)); } 00321 inline BBox operator == (GridData(1)<Type> const &gd) 00322 { return (GridData(1)<Type>::is_eq(gd, gd._bbox, gd._bbox)); } 00323 00324 inline BBox operator != (Type const &val) 00325 { return (GridData(1)<Type>::is_neq(val, _bbox)); } 00326 inline BBox operator != (GridData(1)<Type> const &gd) 00327 { return (GridData(1)<Type>::is_neq(gd, gd._bbox, gd._bbox)); } 00328 00329 inline BBox operator > (Type const &val) 00330 { return (GridData(1)<Type>::is_gt(val, _bbox)); } 00331 inline BBox operator > (GridData(1)<Type> const &gd) 00332 { return (GridData(1)<Type>::is_gt(gd, gd._bbox, gd._bbox)); } 00333 00334 inline BBox operator >= (Type const &val) 00335 { return (GridData(1)<Type>::is_ge(val, _bbox)); } 00336 inline BBox operator >= (GridData(1)<Type> const &gd) 00337 { return (GridData(1)<Type>::is_ge(gd, gd._bbox, gd._bbox)); } 00338 00339 inline BBox operator < (Type const &val) 00340 { return (GridData(1)<Type>::is_lt(val, _bbox)); } 00341 inline BBox operator < (GridData(1)<Type> const &gd) 00342 { return (GridData(1)<Type>::is_lt(gd, gd._bbox, gd._bbox)); } 00343 00344 inline BBox operator <= (Type const &val) 00345 { return (GridData(1)<Type>::is_le(val, _bbox)); } 00346 inline BBox operator <= (GridData(1)<Type> const &gd) 00347 { return (GridData(1)<Type>::is_le(gd, gd._bbox, gd._bbox)); } 00348 00349 inline void operator = (Type const &val) 00350 { GridData(1)<Type>::equals(val, _bbox); } 00351 inline void operator = (GridData(1)<Type> const &gd) 00352 { GridData(1)<Type>::equals(gd, gd._bbox, gd._bbox); } 00353 00354 inline void operator += (Type const &val) 00355 { GridData(1)<Type>::plus(val, _bbox); } 00356 inline void operator += (GridData(1)<Type> const &gd) 00357 { GridData(1)<Type>::plus(gd, gd._bbox, gd._bbox); } 00358 00359 inline void operator -= (Type const &val) 00360 { GridData(1)<Type>::minus(val, _bbox); } 00361 inline void operator -= (GridData(1)<Type> const &gd) 00362 { GridData(1)<Type>::minus(gd, gd._bbox, gd._bbox); } 00363 00364 inline void operator *= (Type const &val) 00365 { GridData(1)<Type>::multiply(val, _bbox); } 00366 inline void operator *= (GridData(1)<Type> const &gd) 00367 { GridData(1)<Type>::multiply(gd, gd._bbox, gd._bbox); } 00368 00369 inline void operator /= (Type const &val) 00370 { GridData(1)<Type>::divide(val, _bbox); } 00371 inline void operator /= (GridData(1)<Type> const &gd) 00372 { GridData(1)<Type>::divide(gd, gd._bbox, gd._bbox); } 00373 /**********************************************************************/ 00374 00375 /**********************************************************************/ 00376 // Reduction Operations 00377 /**********************************************************************/ 00378 Type maxval (BBox const &where); 00379 inline Type maxval (void) 00380 { return (GridData(1)<Type>::maxval(_bbox)); } 00381 00382 Type minval (BBox const &where); 00383 inline Type minval (void) 00384 { return (GridData(1)<Type>::minval(_bbox)); } 00385 00386 Type sum (BBox const &where); 00387 inline Type sum (void) 00388 { return (GridData(1)<Type>::sum(_bbox)); } 00389 00390 Type product (BBox const &where); 00391 inline Type product (void) 00392 { return (GridData(1)<Type>::product(_bbox)); } 00393 /**********************************************************************/ 00394 00395 private: 00396 void gd_CopyRegion(GridData(1)<Type> const &gd, BBox const &to, 00397 BBox const &from, Coords const &step); 00398 void gdb_CopyRegion(GridDataBucket<Type> const &gdbkt, BBox const &to, 00399 BBox const &from, Coords const &step); 00400 void gdb_CopyRegion(GridDataBucket<Type> const &gdbkt, int const n, BBox const &to, 00401 BBox const &from, Coords const &step); 00402 00403 void gd_OperateRegion(is_eq)(Type const &val, BBox const &to, 00404 BBox const &from, Coords const &step, BBox &bb); 00405 void gd_OperateRegion(is_eq)(GridData(1)<Type> const &gd, BBox const &to, 00406 BBox const &from, Coords const &step, BBox &bb); 00407 00408 void gd_OperateRegion(is_neq)(Type const &val, BBox const &to, 00409 BBox const &from, Coords const &step, BBox &bb); 00410 void gd_OperateRegion(is_neq)(GridData(1)<Type> const &gd, BBox const &to, 00411 BBox const &from, Coords const &step, BBox &bb); 00412 00413 void gd_OperateRegion(is_gt)(Type const &val, BBox const &to, 00414 BBox const &from, Coords const &step, BBox &bb); 00415 void gd_OperateRegion(is_gt)(GridData(1)<Type> const &gd, BBox const &to, 00416 BBox const &from, Coords const &step, BBox &bb); 00417 00418 void gd_OperateRegion(is_ge)(Type const &val, BBox const &to, 00419 BBox const &from, Coords const &step, BBox &bb); 00420 void gd_OperateRegion(is_ge)(GridData(1)<Type> const &gd, BBox const &to, 00421 BBox const &from, Coords const &step, BBox &bb); 00422 00423 void gd_OperateRegion(is_lt)(Type const &val, BBox const &to, 00424 BBox const &from, Coords const &step, BBox &bb); 00425 void gd_OperateRegion(is_lt)(GridData(1)<Type> const &gd, BBox const &to, 00426 BBox const &from, Coords const &step, BBox &bb); 00427 00428 void gd_OperateRegion(is_le)(Type const &val, BBox const &to, 00429 BBox const &from, Coords const &step, BBox &bb); 00430 void gd_OperateRegion(is_le)(GridData(1)<Type> const &gd, BBox const &to, 00431 BBox const &from, Coords const &step, BBox &bb); 00432 00433 void gd_OperateRegion(equal)(Type const &val, BBox const &to, 00434 BBox const &from, Coords const &step); 00435 void gd_OperateRegion(equal)(GridData(1)<Type> const &gd, BBox const &to, 00436 BBox const &from, Coords const &step); 00437 00438 void gd_OperateRegion(plus)(Type const &val, BBox const &to, 00439 BBox const &from, Coords const &step); 00440 void gd_OperateRegion(plus)(GridData(1)<Type> const &gd, BBox const &to, 00441 BBox const &from, Coords const &step); 00442 00443 void gd_OperateRegion(minus)(Type const &val, BBox const &to, 00444 BBox const &from, Coords const &step); 00445 void gd_OperateRegion(minus)(GridData(1)<Type> const &gd, BBox const &to, 00446 BBox const &from, Coords const &step); 00447 00448 void gd_OperateRegion(mult)(Type const &val, BBox const &to, 00449 BBox const &from, Coords const &step); 00450 void gd_OperateRegion(mult)(GridData(1)<Type> const &gd, BBox const &to, 00451 BBox const &from, Coords const &step); 00452 00453 void gd_OperateRegion(div)(Type const &val, BBox const &to, 00454 BBox const &from, Coords const &step); 00455 void gd_OperateRegion(div)(GridData(1)<Type> const &gd, BBox const &to, 00456 BBox const &from, Coords const &step); 00457 00458 public: 00459 /* Perform efficient buffer packing/unpacking and data movement */ 00460 void PackRegion(Type *sendbuf, BBox const &from) const; 00461 void UnPackRegion(Type const *recvbuf, BBox const &to); 00462 00463 #if (!defined(Want_c_files) && (defined(RS6000) || defined(SPX))) 00464 friend ostream& operator << (ostream&, const GridData(1)<Type>&); 00465 friend ofstream& operator << (ofstream&, const GridData(1)<Type>&); 00466 friend ifstream& operator >> (ifstream&, GridData(1)<Type>&); 00467 friend strstream& operator << (strstream&, const GridData(1)<Type>&); 00468 friend strstream& operator >> (strstream&, GridData(1)<Type>&); 00469 #endif 00470 00471 }; 00472 00473 #if defined(Want_c_files) || (!defined(RS6000) && !defined(SPX)) 00474 #include "GridData1.c" 00475 #endif 00476 00477 /*********************************************************************/ 00478 template <class Type> 00479 inline Coords lower(GridData(1)<Type> &gd) { return(gd.lower()); } 00480 template <class Type> 00481 inline Coords upper(GridData(1)<Type> &gd) { return(gd.upper()); } 00482 template <class Type> 00483 inline Coords extents(GridData(1)<Type> &gd) { return(gd.extents()); } 00484 template <class Type> 00485 inline int lower(GridData(1)<Type> &gd, const int i) { return(gd.lower(i)); } 00486 template <class Type> 00487 inline int upper(GridData(1)<Type> &gd, const int i) { return(gd.upper(i)); } 00488 template <class Type> 00489 inline int extents(GridData(1)<Type> &gd, const int i) { return(gd.extents(i)); } 00490 template <class Type> 00491 inline BBox bbox(GridData(1)<Type> &gd) { return(gd.bbox()); } 00492 template <class Type> 00493 inline int size(GridData(1)<Type> &gd) { return(gd.size()); } 00494 template <class Type> 00495 inline Coords stepsize(GridData(1)<Type> &gd) { return(gd.stepsize()); } 00496 00497 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04