Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef AMROC_FIXUP2_H 00002 #define AMROC_FIXUP2_H 00003 00011 #include "FixupBase.h" 00012 00013 #ifndef FixupName 00014 #define Fixup(dim) name2(Fixup,dim) 00015 #define FixupName 00016 #endif 00017 00018 #ifndef FixupOpsName 00019 #define FixupOps(dim) name2(FixupOps,dim) 00020 #define FixupOpsName 00021 #endif 00022 00029 template <class VectorType, class FixupType> 00030 class FixupOps(2) { 00031 public: 00032 FixupOps(2)() {} 00033 00034 void copy_to(GridData(1)<FixupType> &target, const BBox &to, 00035 const GridData(2)<VectorType> &source, const BBox &fromwhere, const int s) { 00036 00037 BBox tobb(to * target.bbox()); 00038 BBox from(fromwhere * source.bbox()); BBox frombb(from); AlignBBox(frombb, s); 00039 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 00040 const int dk = frombb.lower(0)-tobb.lower(0); 00041 00042 BeginFastIndex2(src, source.bbox(), source.data(), const VectorType); 00043 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType); 00044 switch(s) { 00045 case 0: 00046 case 1: 00047 for_1 (k, tobb, tobb.stepsize()) 00048 equals_to(FastIndex1(tgt,k-k%tobb.stepsize(0)), 00049 FastIndex2(src, from.lower(0), k+dk-(k+dk)%frombb.stepsize(0))); 00050 end_for 00051 break; 00052 case 2: 00053 case 3: 00054 for_1 (k, tobb, tobb.stepsize()) 00055 equals_to(FastIndex1(tgt,k-k%tobb.stepsize(0)), 00056 FastIndex2(src, k+dk-(k+dk)%frombb.stepsize(0), from.lower(1))); 00057 end_for 00058 break; 00059 default: 00060 assert(0); 00061 } 00062 EndFastIndex2(src); 00063 EndFastIndex1(tgt); 00064 } 00065 void copy_to(GridData(1)<FixupType> &target, 00066 const GridData(2)<VectorType> &source, const BBox &fromwhere, const int s) { 00067 00068 BBox tobb(target.bbox()); 00069 BBox from(fromwhere * source.bbox()); BBox frombb(from); AlignBBox(frombb, s); 00070 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 00071 tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize()); 00072 00073 BeginFastIndex2(src, source.bbox(), source.data(), const VectorType); 00074 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType); 00075 switch(s) { 00076 case 0: 00077 case 1: 00078 for_1 (k, tobb, tobb.stepsize()) 00079 equals_to(FastIndex1(tgt,k-k%tobb.stepsize(0)), 00080 FastIndex2(src, from.lower(0), k-k%frombb.stepsize(0))); 00081 end_for 00082 break; 00083 case 2: 00084 case 3: 00085 for_1 (k, tobb, tobb.stepsize()) 00086 equals_to(FastIndex1(tgt,k-k%tobb.stepsize(0)), 00087 FastIndex2(src, k-k%frombb.stepsize(0), from.lower(1))); 00088 end_for 00089 break; 00090 default: 00091 assert(0); 00092 } 00093 EndFastIndex2(src); 00094 EndFastIndex1(tgt); 00095 } 00096 00097 void copy_from(GridData(2)<VectorType> &target, const BBox &towhere, 00098 const GridData(1)<FixupType> &source, const BBox &from, const int s) { 00099 00100 BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s); 00101 BBox frombb(from * source.bbox()); 00102 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 00103 const int dk = frombb.lower(0)-tobb.lower(0); 00104 00105 BeginFastIndex1(src, source.bbox(), source.data(), const FixupType); 00106 BeginFastIndex2(tgt, target.bbox(), target.data(), VectorType); 00107 switch(s) { 00108 case 0: 00109 case 1: 00110 for_1 (k, tobb, tobb.stepsize()) 00111 equals_from(FastIndex2(tgt,to.lower(0),k-k%tobb.stepsize(0)), 00112 FastIndex1(src, k+dk-(k+dk)%frombb.stepsize(0))); 00113 end_for 00114 break; 00115 case 2: 00116 case 3: 00117 for_1 (k, tobb, tobb.stepsize()) 00118 equals_from(FastIndex2(tgt,k-k%tobb.stepsize(0),to.lower(1)), 00119 FastIndex1(src, k+dk-(k+dk)%frombb.stepsize(0))); 00120 end_for 00121 break; 00122 default: 00123 assert(0); 00124 } 00125 EndFastIndex1(src); 00126 EndFastIndex2(tgt); 00127 } 00128 void copy_from(GridData(2)<VectorType> &target, const BBox &towhere, 00129 const GridData(1)<FixupType> &source, const int s) { 00130 00131 BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s); 00132 BBox frombb(source.bbox()); 00133 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 00134 tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize()); 00135 00136 BeginFastIndex1(src, source.bbox(), source.data(), const FixupType); 00137 BeginFastIndex2(tgt, target.bbox(), target.data(), VectorType); 00138 switch(s) { 00139 case 0: 00140 case 1: 00141 for_1 (k, tobb, tobb.stepsize()) 00142 equals_from(FastIndex2(tgt,to.lower(0),k-k%tobb.stepsize(0)), 00143 FastIndex1(src, k-k%frombb.stepsize(0))); 00144 end_for 00145 break; 00146 case 2: 00147 case 3: 00148 for_1 (k, tobb, tobb.stepsize()) 00149 equals_from(FastIndex2(tgt,k-k%tobb.stepsize(0),to.lower(1)), 00150 FastIndex1(src, k-k%frombb.stepsize(0))); 00151 end_for 00152 break; 00153 default: 00154 assert(0); 00155 } 00156 EndFastIndex1(src); 00157 EndFastIndex2(tgt); 00158 } 00159 00160 void add_to(GridData(1)<FixupType> &target, const BBox &to, 00161 const GridData(2)<VectorType> &source, const BBox &fromwhere, const int s) { 00162 00163 BBox tobb(to * target.bbox()); 00164 BBox from(fromwhere * source.bbox()); BBox frombb(from); AlignBBox(frombb, s); 00165 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 00166 const int dk = frombb.lower(0)-tobb.lower(0); 00167 00168 BeginFastIndex2(src, source.bbox(), source.data(), const VectorType); 00169 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType); 00170 switch(s) { 00171 case 0: 00172 case 1: 00173 for_1 (k, tobb, tobb.stepsize()) 00174 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)), 00175 FastIndex2(src, from.lower(0), k+dk-(k+dk)%frombb.stepsize(0))); 00176 end_for 00177 break; 00178 case 2: 00179 case 3: 00180 for_1 (k, tobb, tobb.stepsize()) 00181 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)), 00182 FastIndex2(src, k+dk-(k+dk)%frombb.stepsize(0), from.lower(1))); 00183 end_for 00184 break; 00185 default: 00186 assert(0); 00187 } 00188 EndFastIndex2(src); 00189 EndFastIndex1(tgt); 00190 } 00191 void add_to(GridData(1)<FixupType> &target, 00192 const GridData(2)<VectorType> &source, const BBox &fromwhere, const int s) { 00193 00194 BBox tobb(target.bbox()); 00195 BBox from(fromwhere * source.bbox()); BBox frombb(from); AlignBBox(frombb, s); 00196 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 00197 tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize()); 00198 00199 BeginFastIndex2(src, source.bbox(), source.data(), const VectorType); 00200 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType); 00201 switch(s) { 00202 case 0: 00203 case 1: 00204 for_1 (k, tobb, tobb.stepsize()) 00205 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)), 00206 FastIndex2(src, from.lower(0), k-k%frombb.stepsize(0))); 00207 end_for 00208 break; 00209 case 2: 00210 case 3: 00211 for_1 (k, tobb, tobb.stepsize()) 00212 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)), 00213 FastIndex2(src, k-k%frombb.stepsize(0), from.lower(1))); 00214 end_for 00215 break; 00216 default: 00217 assert(0); 00218 } 00219 EndFastIndex2(src); 00220 EndFastIndex1(tgt); 00221 } 00222 00223 void add_from(GridData(2)<VectorType> &target, const BBox &towhere, 00224 const GridData(1)<FixupType> &source, const BBox &from, const int s) { 00225 00226 BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s); 00227 BBox frombb(from * source.bbox()); 00228 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 00229 const int dk = frombb.lower(0)-tobb.lower(0); 00230 00231 BeginFastIndex1(src, source.bbox(), source.data(), const FixupType); 00232 BeginFastIndex2(tgt, target.bbox(), target.data(), VectorType); 00233 switch(s) { 00234 case 0: 00235 case 1: 00236 for_1 (k, tobb, tobb.stepsize()) 00237 plus_from(FastIndex2(tgt,to.lower(0),k-k%tobb.stepsize(0)), 00238 FastIndex1(src, k+dk-(k+dk)%frombb.stepsize(0))); 00239 end_for 00240 break; 00241 case 2: 00242 case 3: 00243 for_1 (k, tobb, tobb.stepsize()) 00244 plus_from(FastIndex2(tgt,k-k%tobb.stepsize(0),to.lower(1)), 00245 FastIndex1(src, k+dk-(k+dk)%frombb.stepsize(0))); 00246 end_for 00247 break; 00248 default: 00249 assert(0); 00250 } 00251 EndFastIndex1(src); 00252 EndFastIndex2(tgt); 00253 } 00254 void add_from(GridData(2)<VectorType> &target, const BBox &towhere, 00255 const GridData(1)<FixupType> &source, const int s) { 00256 00257 BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s); 00258 BBox frombb(source.bbox()); 00259 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 00260 tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize()); 00261 00262 BeginFastIndex1(src, source.bbox(), source.data(), const FixupType); 00263 BeginFastIndex2(tgt, target.bbox(), target.data(), VectorType); 00264 switch(s) { 00265 case 0: 00266 case 1: 00267 for_1 (k, tobb, tobb.stepsize()) 00268 plus_from(FastIndex2(tgt,to.lower(0),k-k%tobb.stepsize(0)), 00269 FastIndex1(src, k-k%frombb.stepsize(0))); 00270 end_for 00271 break; 00272 case 2: 00273 case 3: 00274 for_1 (k, tobb, tobb.stepsize()) 00275 plus_from(FastIndex2(tgt,k-k%tobb.stepsize(0),to.lower(1)), 00276 FastIndex1(src, k-k%frombb.stepsize(0))); 00277 end_for 00278 break; 00279 default: 00280 assert(0); 00281 } 00282 EndFastIndex1(src); 00283 EndFastIndex2(tgt); 00284 } 00285 00286 void add_to(GridData(1)<FixupType> &target, const BBox &to, 00287 const GridData(1)<VectorType> &source, const BBox &from) { 00288 00289 BBox tobb(to * target.bbox()); 00290 BBox frombb(from * source.bbox()); 00291 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 00292 const int dk = frombb.lower(0)-tobb.lower(0); 00293 00294 BeginFastIndex1(src, source.bbox(), source.data(), const VectorType); 00295 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType); 00296 for_1 (k, tobb, tobb.stepsize()) 00297 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)), 00298 FastIndex1(src, k+dk-(k+dk)%frombb.stepsize(0))); 00299 end_for 00300 EndFastIndex1(src); 00301 EndFastIndex1(tgt); 00302 } 00303 void add_to(GridData(1)<FixupType> &target, 00304 const GridData(1)<VectorType> &source, const BBox &where) { 00305 00306 BBox tobb(target.bbox()); 00307 BBox frombb(where * source.bbox()); 00308 tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 00309 tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize()); 00310 00311 BeginFastIndex1(src, source.bbox(), source.data(), const VectorType); 00312 BeginFastIndex1(tgt, target.bbox(), target.data(), FixupType); 00313 for_1 (k, tobb, tobb.stepsize()) 00314 plus_to(FastIndex1(tgt,k-k%tobb.stepsize(0)), 00315 FastIndex1(src, k-k%frombb.stepsize(0))); 00316 end_for 00317 EndFastIndex1(src); 00318 EndFastIndex1(tgt); 00319 } 00320 }; 00321 00328 template <class VectorType, class FixupType> 00329 class Fixup(2) : public FixupBase(2)<VectorType,FixupType> { 00330 typedef Integrator(2)<VectorType> integrator_type; 00331 typedef GridData(2)<VectorType> vec_grid_data_type; 00332 typedef GridData(DIM_1)<VectorType> ld_vec_grid_data_type; 00333 typedef GridData(DIM_1)<FixupType> ld_fixup_grid_data_type; 00334 00335 public: 00336 Fixup(2)(integrator_type& integ) : FixupBase(2)<VectorType,FixupType>(integ) {} 00337 00338 protected: 00339 void debug_print(vec_grid_data_type &gd, const BBox &where) { 00340 #ifdef DEBUG_PRINT 00341 for (register int j=where.lower(1); j<=where.upper(1); j+=where.stepsize(1)) { 00342 for (register int i=where.lower(0); i<=where.upper(0); i+=where.stepsize(0)) 00343 ( comm_service::log() << "[" << i << "," << j << "]=" 00344 << gd(i,j)(0) << " " ).flush(); 00345 } 00346 #endif 00347 } 00348 00349 void debug_print_ldv(ld_vec_grid_data_type &gd, const BBox &where) { 00350 #ifdef DEBUG_PRINT 00351 for (register int i=where.lower(0); i<=where.upper(0); i+=where.stepsize(0)) 00352 ( comm_service::log() << "[" << i << "]=" 00353 << gd(i)(0) << " " ).flush(); 00354 ( comm_service::log() << "\n" ).flush(); 00355 #endif 00356 } 00357 void debug_print_ldv(ld_vec_grid_data_type &gd) { 00358 debug_print_ldv(gd, gd.bbox()); 00359 } 00360 00361 void debug_print_ld(ld_fixup_grid_data_type &gd, const BBox &where) { 00362 #ifdef DEBUG_PRINT 00363 for (register int i=where.lower(0); i<=where.upper(0); i+=where.stepsize(0)) 00364 ( comm_service::log() << "[" << i << "]=" 00365 << gd(i)(0) << " " ).flush(); 00366 ( comm_service::log() << "\n" ).flush(); 00367 #endif 00368 } 00369 void debug_print_ld(ld_fixup_grid_data_type &gd) { 00370 debug_print_ld(gd, gd.bbox()); 00371 } 00372 }; 00373 00374 00375 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04