Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef _included_GridDataOps_1_h 00002 #define _included_GridDataOps_1_h 00003 00009 template <class Type> 00010 void GridData(1)<Type>::lin_interp (GridData(1)<Type> const &gd1, double const frac1, 00011 GridData(1)<Type> const &gd2, double const frac2, 00012 BBox const &where) 00013 { 00014 BBox intersection = _bbox * gd1._bbox * gd2._bbox * where; 00015 if (!intersection.empty()) 00016 { 00017 //Coords max_step = (_step > gd1._step) ? _step : 00018 // (gd1._step > gd2._step) ? gd1._step : gd2._step; 00019 00020 Coords max_step = _step.getmax(gd1._step); 00021 max_step.max(gd2._step); 00022 00023 GridData(1)<Type> &dst = *this; 00024 00025 BeginFastIndex1(src1, gd1._bbox, gd1._data, const Type); 00026 BeginFastIndex1(src2, gd2._bbox, gd2._data, const Type); 00027 BeginFastIndex1(dst, dst._bbox, dst._data, Type); 00028 00029 for_1(i, intersection, max_step) 00030 FastIndex1(dst,i) = (Type) ((FastIndex1(src1,i) * frac1) 00031 + (FastIndex1(src2,i) * frac2)); 00032 end_for 00033 00034 EndFastIndex1(dst); 00035 EndFastIndex1(src1); 00036 EndFastIndex1(src2); 00037 } 00038 } 00039 00040 /**************************************************************************/ 00041 00042 template <class Type> 00043 void GridData(1)<Type>::equals (Type const &val, BBox const &where) 00044 { 00045 BBox intersection = _bbox * where; 00046 if (!intersection.empty()) 00047 { 00048 Coords max_step = _step.getmax(where.stepsize()); 00049 BBox to(intersection); to.setstepsize(_step); 00050 BBox from(intersection); from.setstepsize(where.stepsize()); 00051 gd_OperateRegion(equal)(val, to, from, max_step); 00052 } 00053 } 00054 00055 template <class Type> 00056 void GridData(1)<Type>::equals (GridData(1)<Type> const &gd, BBox const &to, 00057 BBox const &from) 00058 { 00059 const Coords toshift = from.lower() - to.lower(); 00060 BBox newfrom = gd._bbox * from * shiftabs(_bbox * to, toshift); 00061 if (!newfrom.empty()) 00062 { 00063 BBox newto = shiftabs(newfrom, -toshift); 00064 Coords max_step = _step.getmax(gd._step); 00065 newto.setstepsize(_step); 00066 newfrom.setstepsize(gd._step); 00067 gd_OperateRegion(equal)(gd, newto, newfrom, max_step); 00068 } 00069 } 00070 00071 template <class Type> 00072 void GridData(1)<Type>::plus (Type const &val, BBox const &where) 00073 { 00074 BBox intersection = _bbox * where; 00075 if (!intersection.empty()) 00076 { 00077 Coords max_step = _step.getmax(where.stepsize()); 00078 BBox to(intersection); to.setstepsize(_step); 00079 BBox from(intersection); from.setstepsize(where.stepsize()); 00080 gd_OperateRegion(plus)(val, to, from, max_step); 00081 } 00082 } 00083 00084 template <class Type> 00085 void GridData(1)<Type>::plus (GridData(1)<Type> const &gd, BBox const &to, 00086 BBox const &from) 00087 { 00088 const Coords toshift = from.lower() - to.lower(); 00089 BBox newfrom = gd._bbox * from * shiftabs(_bbox * to, toshift); 00090 if (!newfrom.empty()) 00091 { 00092 BBox newto = shiftabs(newfrom, -toshift); 00093 Coords max_step = _step.getmax(gd._step); 00094 newto.setstepsize(_step); 00095 newfrom.setstepsize(gd._step); 00096 gd_OperateRegion(plus)(gd, newto, newfrom, max_step); 00097 } 00098 } 00099 00100 template <class Type> 00101 void GridData(1)<Type>::minus (Type const &val, BBox const &where) 00102 { 00103 BBox intersection = _bbox * where; 00104 if (!intersection.empty()) 00105 { 00106 Coords max_step = _step.getmax(where.stepsize()); 00107 BBox to(intersection); to.setstepsize(_step); 00108 BBox from(intersection); from.setstepsize(where.stepsize()); 00109 gd_OperateRegion(minus)(val, to, from, max_step); 00110 } 00111 } 00112 00113 template <class Type> 00114 void GridData(1)<Type>::minus (GridData(1)<Type> const &gd, BBox const &to, 00115 BBox const &from) 00116 { 00117 const Coords toshift = from.lower() - to.lower(); 00118 BBox newfrom = gd._bbox * from * shiftabs(_bbox * to, toshift); 00119 if (!newfrom.empty()) 00120 { 00121 BBox newto = shiftabs(newfrom, -toshift); 00122 Coords max_step = _step.getmax(gd._step); 00123 newto.setstepsize(_step); 00124 newfrom.setstepsize(gd._step); 00125 gd_OperateRegion(minus)(gd, newto, newfrom, max_step); 00126 } 00127 } 00128 00129 template <class Type> 00130 void GridData(1)<Type>::multiply (Type const &val, BBox const &where) 00131 { 00132 BBox intersection = _bbox * where; 00133 if (!intersection.empty()) 00134 { 00135 Coords max_step = _step.getmax(where.stepsize()); 00136 BBox to(intersection); to.setstepsize(_step); 00137 BBox from(intersection); from.setstepsize(where.stepsize()); 00138 gd_OperateRegion(mult)(val, to, from, max_step); 00139 } 00140 } 00141 00142 template <class Type> 00143 void GridData(1)<Type>::multiply (GridData(1)<Type> const &gd, BBox const &to, 00144 BBox const &from) 00145 { 00146 const Coords toshift = from.lower() - to.lower(); 00147 BBox newfrom = gd._bbox * from * shiftabs(_bbox * to, toshift); 00148 if (!newfrom.empty()) 00149 { 00150 BBox newto = shiftabs(newfrom, -toshift); 00151 Coords max_step = _step.getmax(gd._step); 00152 newto.setstepsize(_step); 00153 newfrom.setstepsize(gd._step); 00154 gd_OperateRegion(mult)(gd, newto, newfrom, max_step); 00155 } 00156 } 00157 00158 template <class Type> 00159 void GridData(1)<Type>::divide (Type const &val, BBox const &where) 00160 { 00161 BBox intersection = _bbox * where; 00162 if (!intersection.empty()) 00163 { 00164 Coords max_step = _step.getmax(where.stepsize()); 00165 BBox to(intersection); to.setstepsize(_step); 00166 BBox from(intersection); from.setstepsize(where.stepsize()); 00167 gd_OperateRegion(div)(val, to, from, max_step); 00168 } 00169 } 00170 00171 template <class Type> 00172 void GridData(1)<Type>::divide (GridData(1)<Type> const &gd, BBox const &to, 00173 BBox const &from) 00174 { 00175 const Coords toshift = from.lower() - to.lower(); 00176 BBox newfrom = gd._bbox * from * shiftabs(_bbox * to, toshift); 00177 if (!newfrom.empty()) 00178 { 00179 BBox newto = shiftabs(newfrom, -toshift); 00180 Coords max_step = _step.getmax(gd._step); 00181 newto.setstepsize(_step); 00182 newfrom.setstepsize(gd._step); 00183 gd_OperateRegion(div)(gd, newto, newfrom, max_step); 00184 } 00185 } 00186 00187 /****************************** = ***************************************/ 00188 00189 template <class Type> 00190 void GridData(1)<Type>::gd_OperateRegion(equal) (Type const &val, 00191 BBox const &to, BBox const &from, Coords const &step) 00192 { 00193 GridData(1)<Type> &dst = *this; 00194 00195 BeginFastIndex1(dst, dst._bbox, dst._data, Type); 00196 00197 for_1(i, to, step) 00198 FastIndex1(dst,i) = val; 00199 end_for 00200 00201 EndFastIndex1(dst); 00202 } 00203 00204 template <class Type> 00205 void GridData(1)<Type>::gd_OperateRegion(equal) (GridData(1)<Type> const &src, 00206 BBox const &to, BBox const &from, Coords const &step) 00207 { 00208 GridData(1)<Type> &dst = *this; 00209 const int di = from.lower(0)-to.lower(0); 00210 00211 BeginFastIndex1(src, src._bbox, src._data, const Type); 00212 BeginFastIndex1(dst, dst._bbox, dst._data, Type); 00213 00214 for_1(i, to, step) 00215 FastIndex1(dst,i) = FastIndex1(src,i+di); 00216 end_for 00217 00218 EndFastIndex1(dst); 00219 EndFastIndex1(src); 00220 } 00221 00222 /************************************************************************/ 00223 00224 /****************************** + ***************************************/ 00225 00226 template <class Type> 00227 void GridData(1)<Type>::gd_OperateRegion(plus)(Type const &val, 00228 BBox const &to, BBox const &from, Coords const &step) 00229 { 00230 GridData(1)<Type> &dst = *this; 00231 00232 BeginFastIndex1(dst, dst._bbox, dst._data, Type); 00233 00234 for_1(i, to, step) 00235 FastIndex1(dst,i) += val; 00236 end_for 00237 00238 EndFastIndex1(dst); 00239 } 00240 00241 template <class Type> 00242 void GridData(1)<Type>::gd_OperateRegion(plus)(GridData(1)<Type> const &src, 00243 BBox const &to, BBox const &from, Coords const &step) 00244 { 00245 GridData(1)<Type> &dst = *this; 00246 const int di = from.lower(0)-to.lower(0); 00247 00248 BeginFastIndex1(src, src._bbox, src._data, const Type); 00249 BeginFastIndex1(dst, dst._bbox, dst._data, Type); 00250 00251 for_1(i, to, step) 00252 FastIndex1(dst,i) += FastIndex1(src,i+di); 00253 end_for 00254 00255 EndFastIndex1(dst); 00256 EndFastIndex1(src); 00257 } 00258 00259 /************************************************************************/ 00260 00261 /****************************** - ***************************************/ 00262 00263 template <class Type> 00264 void GridData(1)<Type>::gd_OperateRegion(minus)(Type const &val, 00265 BBox const &to, BBox const &from, Coords const &step) 00266 { 00267 GridData(1)<Type> &dst = *this; 00268 00269 BeginFastIndex1(dst, dst._bbox, dst._data, Type); 00270 00271 for_1(i, to, step) 00272 FastIndex1(dst,i) -= val; 00273 end_for 00274 00275 EndFastIndex1(dst); 00276 } 00277 00278 template <class Type> 00279 void GridData(1)<Type>::gd_OperateRegion(minus)(GridData(1)<Type> const &src, 00280 BBox const &to, BBox const &from, Coords const &step) 00281 { 00282 GridData(1)<Type> &dst = *this; 00283 const int di = from.lower(0)-to.lower(0); 00284 00285 BeginFastIndex1(src, src._bbox, src._data, const Type); 00286 BeginFastIndex1(dst, dst._bbox, dst._data, Type); 00287 00288 for_1(i, to, step) 00289 FastIndex1(dst,i) -= FastIndex1(src,i+di); 00290 end_for 00291 00292 EndFastIndex1(dst); 00293 EndFastIndex1(src); 00294 } 00295 00296 /************************************************************************/ 00297 00298 /****************************** * ***************************************/ 00299 00300 template <class Type> 00301 void GridData(1)<Type>::gd_OperateRegion(mult)(Type const &val, 00302 BBox const &to, BBox const &from, Coords const &step) 00303 { 00304 GridData(1)<Type> &dst = *this; 00305 00306 BeginFastIndex1(dst, dst._bbox, dst._data, Type); 00307 00308 for_1(i, to, step) 00309 FastIndex1(dst,i) *= val; 00310 end_for 00311 00312 EndFastIndex1(dst); 00313 } 00314 00315 template <class Type> 00316 void GridData(1)<Type>::gd_OperateRegion(mult)(GridData(1)<Type> const &src, 00317 BBox const &to, BBox const &from, Coords const &step) 00318 { 00319 GridData(1)<Type> &dst = *this; 00320 const int di = from.lower(0)-to.lower(0); 00321 00322 BeginFastIndex1(src, src._bbox, src._data, const Type); 00323 BeginFastIndex1(dst, dst._bbox, dst._data, Type); 00324 00325 for_1(i, to, step) 00326 FastIndex1(dst,i) *= FastIndex1(src,i+di); 00327 end_for 00328 00329 EndFastIndex1(dst); 00330 EndFastIndex1(src); 00331 } 00332 00333 /************************************************************************/ 00334 00335 /****************************** / ***************************************/ 00336 00337 template <class Type> 00338 void GridData(1)<Type>::gd_OperateRegion(div)(Type const &val, 00339 BBox const &to, BBox const &from, Coords const &step) 00340 { 00341 assert (val != (Type)0); 00342 GridData(1)<Type> &dst = *this; 00343 00344 BeginFastIndex1(dst, dst._bbox, dst._data, Type); 00345 00346 for_1(i, to, step) 00347 FastIndex1(dst,i) /= val; 00348 end_for 00349 00350 EndFastIndex1(dst); 00351 } 00352 00353 template <class Type> 00354 void GridData(1)<Type>::gd_OperateRegion(div)(GridData(1)<Type> const &src, 00355 BBox const &to, BBox const &from, Coords const &step) 00356 { 00357 GridData(1)<Type> &dst = *this; 00358 const int di = from.lower(0)-to.lower(0); 00359 00360 BeginFastIndex1(src, src._bbox, src._data, const Type); 00361 BeginFastIndex1(dst, dst._bbox, dst._data, Type); 00362 00363 for_1(i, to, step) 00364 FastIndex1(dst,i) /= FastIndex1(src,i+di); 00365 end_for 00366 00367 EndFastIndex1(dst); 00368 EndFastIndex1(src); 00369 } 00370 /************************************************************************/ 00371 00372 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04