Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef _included_GridDataOps_2_h 00002 #define _included_GridDataOps_2_h 00003 00009 template <class Type> 00010 void GridData(2)<Type>::lin_interp (GridData(2)<Type> const &gd1, double const frac1, 00011 GridData(2)<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 //int 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(2)<Type> &dst = *this; 00024 00025 BeginFastIndex2(src1, gd1._bbox, gd1._data, const Type); 00026 BeginFastIndex2(src2, gd2._bbox, gd2._data, const Type); 00027 BeginFastIndex2(dst, dst._bbox, dst._data, Type); 00028 00029 for_2(i, j, intersection, max_step) 00030 FastIndex2(dst,i,j) = (Type) ((FastIndex2(src1,i,j) * frac1) 00031 + (FastIndex2(src2,i,j) * frac2)); 00032 end_for 00033 00034 EndFastIndex2(dst); 00035 EndFastIndex2(src1); 00036 EndFastIndex2(src2); 00037 } 00038 } 00039 00040 /**************************************************************************/ 00041 00042 template <class Type> 00043 void GridData(2)<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(2)<Type>::equals (GridData(2)<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(2)<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(2)<Type>::plus (GridData(2)<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(2)<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(2)<Type>::minus (GridData(2)<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(2)<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(2)<Type>::multiply (GridData(2)<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(2)<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(2)<Type>::divide (GridData(2)<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(2)<Type>::gd_OperateRegion(equal) (Type const &val, 00191 BBox const &to, BBox const &from, Coords const &step) 00192 { 00193 GridData(2)<Type> &dst = *this; 00194 00195 BeginFastIndex2(dst, dst._bbox, dst._data, Type); 00196 00197 for_2(i, j, to, step) 00198 FastIndex2(dst,i,j) = val; 00199 end_for 00200 00201 EndFastIndex2(dst); 00202 } 00203 00204 template <class Type> 00205 void GridData(2)<Type>::gd_OperateRegion(equal) (GridData(2)<Type> const &src, 00206 BBox const &to, BBox const &from, Coords const &step) 00207 { 00208 GridData(2)<Type> &dst = *this; 00209 const int di = from.lower(0)-to.lower(0); 00210 const int dj = from.lower(1)-to.lower(1); 00211 00212 BeginFastIndex2(src, src._bbox, src._data, const Type); 00213 BeginFastIndex2(dst, dst._bbox, dst._data, Type); 00214 00215 for_2(i, j, to, step) 00216 FastIndex2(dst,i,j) = FastIndex2(src,i+di,j+dj); 00217 end_for 00218 00219 EndFastIndex2(dst); 00220 EndFastIndex2(src); 00221 } 00222 00223 /************************************************************************/ 00224 00225 /****************************** + ***************************************/ 00226 00227 template <class Type> 00228 void GridData(2)<Type>::gd_OperateRegion(plus)(Type const &val, 00229 BBox const &to, BBox const &from, Coords const &step) 00230 { 00231 GridData(2)<Type> &dst = *this; 00232 00233 BeginFastIndex2(dst, dst._bbox, dst._data, Type); 00234 00235 for_2(i, j, to, step) 00236 FastIndex2(dst,i,j) += val; 00237 end_for 00238 00239 EndFastIndex2(dst); 00240 } 00241 00242 template <class Type> 00243 void GridData(2)<Type>::gd_OperateRegion(plus)(GridData(2)<Type> const &src, 00244 BBox const &to, BBox const &from, Coords const &step) 00245 { 00246 GridData(2)<Type> &dst = *this; 00247 const int di = from.lower(0)-to.lower(0); 00248 const int dj = from.lower(1)-to.lower(1); 00249 00250 BeginFastIndex2(src, src._bbox, src._data, const Type); 00251 BeginFastIndex2(dst, dst._bbox, dst._data, Type); 00252 00253 for_2(i, j, to, step) 00254 FastIndex2(dst,i,j) += FastIndex2(src,i+di,j+dj); 00255 end_for 00256 00257 EndFastIndex2(dst); 00258 EndFastIndex2(src); 00259 } 00260 00261 /************************************************************************/ 00262 00263 /****************************** - ***************************************/ 00264 00265 template <class Type> 00266 void GridData(2)<Type>::gd_OperateRegion(minus)(Type const &val, 00267 BBox const &to, BBox const &from, Coords const &step) 00268 { 00269 GridData(2)<Type> &dst = *this; 00270 00271 BeginFastIndex2(dst, dst._bbox, dst._data, Type); 00272 00273 for_2(i, j, to, step) 00274 FastIndex2(dst,i,j) -= val; 00275 end_for 00276 00277 EndFastIndex2(dst); 00278 } 00279 00280 template <class Type> 00281 void GridData(2)<Type>::gd_OperateRegion(minus)(GridData(2)<Type> const &src, 00282 BBox const &to, BBox const &from, Coords const &step) 00283 { 00284 GridData(2)<Type> &dst = *this; 00285 const int di = from.lower(0)-to.lower(0); 00286 const int dj = from.lower(1)-to.lower(1); 00287 00288 BeginFastIndex2(src, src._bbox, src._data, const Type); 00289 BeginFastIndex2(dst, dst._bbox, dst._data, Type); 00290 00291 for_2(i, j, to, step) 00292 FastIndex2(dst,i,j) -= FastIndex2(src,i+di,j+dj); 00293 end_for 00294 00295 EndFastIndex2(dst); 00296 EndFastIndex2(src); 00297 } 00298 00299 /************************************************************************/ 00300 00301 /****************************** * ***************************************/ 00302 00303 template <class Type> 00304 void GridData(2)<Type>::gd_OperateRegion(mult)(Type const &val, 00305 BBox const &to, BBox const &from, Coords const &step) 00306 { 00307 GridData(2)<Type> &dst = *this; 00308 00309 BeginFastIndex2(dst, dst._bbox, dst._data, Type); 00310 00311 for_2(i, j, to, step) 00312 FastIndex2(dst,i,j) *= val; 00313 end_for 00314 00315 EndFastIndex2(dst); 00316 } 00317 00318 template <class Type> 00319 void GridData(2)<Type>::gd_OperateRegion(mult)(GridData(2)<Type> const &src, 00320 BBox const &to, BBox const &from, Coords const &step) 00321 { 00322 GridData(2)<Type> &dst = *this; 00323 const int di = from.lower(0)-to.lower(0); 00324 const int dj = from.lower(1)-to.lower(1); 00325 00326 BeginFastIndex2(src, src._bbox, src._data, const Type); 00327 BeginFastIndex2(dst, dst._bbox, dst._data, Type); 00328 00329 for_2(i, j, to, step) 00330 FastIndex2(dst,i,j) *= FastIndex2(src,i+di,j+dj); 00331 end_for 00332 00333 EndFastIndex2(dst); 00334 EndFastIndex2(src); 00335 } 00336 00337 /************************************************************************/ 00338 00339 /****************************** / ***************************************/ 00340 00341 template <class Type> 00342 void GridData(2)<Type>::gd_OperateRegion(div)(Type const &val, 00343 BBox const &to, BBox const &from, Coords const &step) 00344 { 00345 assert (val != (Type)0); 00346 GridData(2)<Type> &dst = *this; 00347 00348 BeginFastIndex2(dst, dst._bbox, dst._data, Type); 00349 00350 for_2(i, j, to, step) 00351 FastIndex2(dst,i,j) /= val; 00352 end_for 00353 00354 EndFastIndex2(dst); 00355 } 00356 00357 template <class Type> 00358 void GridData(2)<Type>::gd_OperateRegion(div)(GridData(2)<Type> const &src, 00359 BBox const &to, BBox const &from, Coords const &step) 00360 { 00361 GridData(2)<Type> &dst = *this; 00362 const int di = from.lower(0)-to.lower(0); 00363 const int dj = from.lower(1)-to.lower(1); 00364 00365 BeginFastIndex2(src, src._bbox, src._data, const Type); 00366 BeginFastIndex2(dst, dst._bbox, dst._data, Type); 00367 00368 for_2(i, j, to, step) 00369 FastIndex2(dst,i,j) /= FastIndex2(src,i+di,j+dj); 00370 end_for 00371 00372 EndFastIndex2(dst); 00373 EndFastIndex2(src); 00374 } 00375 /************************************************************************/ 00376 00377 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04