AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

Fixup3.h

Go to the documentation of this file.
00001 #ifndef AMROC_FIXUP3_H
00002 #define AMROC_FIXUP3_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(3) {
00031 public:
00032   FixupOps(3)() {}
00033 
00034   void copy_to(GridData(2)<FixupType> &target, const BBox &to, 
00035                const GridData(3)<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     const int dl = frombb.lower(1)-tobb.lower(1);
00042     
00043     BeginFastIndex3(src, source.bbox(), source.data(), const VectorType);
00044     BeginFastIndex2(tgt, target.bbox(), target.data(), FixupType);
00045     switch(s) {
00046     case 0: 
00047     case 1: 
00048       for_2 (k, l, tobb, tobb.stepsize()) 
00049         equals_to(FastIndex2(tgt, k-k%tobb.stepsize(0), l-l%tobb.stepsize(1)),
00050                   FastIndex3(src, from.lower(0), k+dk-(k+dk)%frombb.stepsize(0),
00051                              l+dl-(l+dl)%frombb.stepsize(1)));
00052       end_for
00053       break;
00054     case 2:
00055     case 3: 
00056       for_2 (k, l, tobb, tobb.stepsize()) 
00057         equals_to(FastIndex2(tgt, k-k%tobb.stepsize(0), l-l%tobb.stepsize(1)), 
00058                   FastIndex3(src, k+dk-(k+dk)%frombb.stepsize(0), from.lower(1), 
00059                              l+dl-(l+dl)%frombb.stepsize(1)));
00060       end_for
00061       break;
00062     case 4:
00063     case 5: 
00064       for_2 (k, l, tobb, tobb.stepsize()) 
00065         equals_to(FastIndex2(tgt, k-k%tobb.stepsize(0), l-l%tobb.stepsize(1)), 
00066                   FastIndex3(src, k+dk-(k+dk)%frombb.stepsize(0), 
00067                              l+dl-(l+dl)%frombb.stepsize(1),from.lower(2)));
00068       end_for
00069       break;
00070     default:
00071       assert(0);
00072     }
00073     EndFastIndex3(src);
00074     EndFastIndex2(tgt);
00075   }
00076   void copy_to(GridData(2)<FixupType> &target, 
00077                const GridData(3)<VectorType> &source, const BBox &fromwhere, const int s) {
00078     
00079     BBox tobb(target.bbox()); 
00080     BBox from(fromwhere * source.bbox()); BBox frombb(from); AlignBBox(frombb, s);
00081     tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);   
00082     tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize());
00083     
00084     BeginFastIndex3(src, source.bbox(), source.data(), const VectorType);
00085     BeginFastIndex2(tgt, target.bbox(), target.data(), FixupType);
00086     switch(s) {
00087     case 0: 
00088     case 1: 
00089       for_2 (k, l, tobb, tobb.stepsize()) 
00090         equals_to(FastIndex2(tgt, k-k%tobb.stepsize(0), l-l%tobb.stepsize(1)),
00091                   FastIndex3(src, from.lower(0), k-k%frombb.stepsize(0),
00092                              l-l%frombb.stepsize(1)));
00093       end_for
00094       break;
00095     case 2:
00096     case 3: 
00097       for_2 (k, l, tobb, tobb.stepsize()) 
00098         equals_to(FastIndex2(tgt, k-k%tobb.stepsize(0), l-l%tobb.stepsize(1)), 
00099                   FastIndex3(src, k-k%frombb.stepsize(0), from.lower(1), 
00100                              l-l%frombb.stepsize(1)));
00101       end_for
00102       break;
00103     case 4:
00104     case 5: 
00105       for_2 (k, l, tobb, tobb.stepsize()) 
00106         equals_to(FastIndex2(tgt, k-k%tobb.stepsize(0), l-l%tobb.stepsize(1)), 
00107                   FastIndex3(src, k-k%frombb.stepsize(0), 
00108                              l-l%frombb.stepsize(1),from.lower(2)));
00109       end_for
00110       break;
00111     default:
00112       assert(0);
00113     }
00114     EndFastIndex3(src);
00115     EndFastIndex2(tgt);
00116   }
00117 
00118   void copy_from(GridData(3)<VectorType> &target, const BBox &towhere, 
00119                  const GridData(2)<FixupType> &source, const BBox &from, const int s) {
00120     
00121     BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s);
00122     BBox frombb(from * source.bbox()); 
00123     tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);     
00124     const int dk = frombb.lower(0)-tobb.lower(0);
00125     const int dl = frombb.lower(1)-tobb.lower(1);
00126     
00127     BeginFastIndex2(src, source.bbox(), source.data(), const FixupType);
00128     BeginFastIndex3(tgt, target.bbox(), target.data(), VectorType);
00129     switch(s) {
00130     case 0: 
00131     case 1: 
00132       for_2 (k, l, tobb, tobb.stepsize()) 
00133         equals_from(FastIndex3(tgt,to.lower(0),k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00134                     FastIndex2(src, k+dk-(k+dk)%frombb.stepsize(0),
00135                                l+dl-(l+dl)%frombb.stepsize(1)));
00136       end_for
00137       break;
00138     case 2:
00139     case 3: 
00140       for_2 (k, l, tobb, tobb.stepsize()) 
00141         equals_from(FastIndex3(tgt,k-k%tobb.stepsize(0),to.lower(1),l-l%tobb.stepsize(1)), 
00142                     FastIndex2(src, k+dk-(k+dk)%frombb.stepsize(0),
00143                                l+dl-(l+dl)%frombb.stepsize(1)));
00144       end_for
00145       break;
00146     case 4:
00147     case 5: 
00148       for_2 (k, l, tobb, tobb.stepsize()) 
00149         equals_from(FastIndex3(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1),to.lower(2)), 
00150                     FastIndex2(src,k+dk-(k+dk)%frombb.stepsize(0),
00151                                l+dl-(l+dl)%frombb.stepsize(1)));
00152       end_for
00153       break;
00154     default:
00155       assert(0);
00156     }
00157     EndFastIndex2(src);
00158     EndFastIndex3(tgt);
00159   }
00160   void copy_from(GridData(3)<VectorType> &target, const BBox &towhere, 
00161                  const GridData(2)<FixupType> &source, const int s) {
00162     
00163     BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s);
00164     BBox frombb(source.bbox()); 
00165     tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);     
00166     tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize());
00167     
00168     BeginFastIndex2(src, source.bbox(), source.data(), const FixupType);
00169     BeginFastIndex3(tgt, target.bbox(), target.data(), VectorType);
00170     switch(s) {
00171     case 0: 
00172     case 1: 
00173       for_2 (k, l, tobb, tobb.stepsize()) 
00174         equals_from(FastIndex3(tgt,to.lower(0),k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00175                     FastIndex2(src, k-k%frombb.stepsize(0),
00176                                l-l%frombb.stepsize(1)));
00177       end_for
00178       break;
00179     case 2:
00180     case 3: 
00181       for_2 (k, l, tobb, tobb.stepsize()) 
00182         equals_from(FastIndex3(tgt,k-k%tobb.stepsize(0),to.lower(1),l-l%tobb.stepsize(1)), 
00183                     FastIndex2(src, k-k%frombb.stepsize(0),
00184                                l-l%frombb.stepsize(1)));
00185       end_for
00186       break;
00187     case 4:
00188     case 5: 
00189       for_2 (k, l, tobb, tobb.stepsize()) 
00190         equals_from(FastIndex3(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1),to.lower(2)), 
00191                     FastIndex2(src,k-k%frombb.stepsize(0),
00192                                l-l%frombb.stepsize(1)));
00193       end_for
00194       break;
00195     default:
00196       assert(0);
00197     }
00198     EndFastIndex2(src);
00199     EndFastIndex3(tgt);
00200   }
00201    
00202   void add_to(GridData(2)<FixupType> &target, const BBox &to, 
00203               const GridData(3)<VectorType> &source, const BBox &fromwhere, const int s) {
00204     
00205     BBox tobb(to * target.bbox()); 
00206     BBox from(fromwhere * source.bbox()); BBox frombb(from); AlignBBox(frombb, s);
00207     tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 
00208     const int dk = frombb.lower(0)-tobb.lower(0);
00209     const int dl = frombb.lower(1)-tobb.lower(1);
00210     
00211     BeginFastIndex3(src, source.bbox(), source.data(), const VectorType);
00212     BeginFastIndex2(tgt, target.bbox(), target.data(), FixupType);
00213     switch(s) {
00214     case 0: 
00215     case 1: 
00216       for_2 (k, l, tobb, tobb.stepsize()) 
00217         plus_to(FastIndex2(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00218                 FastIndex3(src, from.lower(0), k+dk-(k+dk)%frombb.stepsize(0),
00219                            l+dl-(l+dl)%frombb.stepsize(1)));
00220       end_for
00221       break;
00222     case 2:
00223     case 3: 
00224       for_2 (k, l, tobb, tobb.stepsize()) 
00225         plus_to(FastIndex2(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00226                 FastIndex3(src, k+dk-(k+dk)%frombb.stepsize(0), from.lower(1), 
00227                            l+dl-(l+dl)%frombb.stepsize(1)));
00228       end_for
00229       break;
00230     case 4:
00231     case 5: 
00232       for_2 (k, l, tobb, tobb.stepsize()) 
00233         plus_to(FastIndex2(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00234                 FastIndex3(src, k+dk-(k+dk)%frombb.stepsize(0), 
00235                            l+dl-(l+dl)%frombb.stepsize(1), from.lower(2)));
00236       end_for
00237       break;
00238     default:
00239       assert(0);
00240     }
00241     EndFastIndex3(src);
00242     EndFastIndex2(tgt);
00243   }
00244   void add_to(GridData(2)<FixupType> &target,
00245               const GridData(3)<VectorType> &source, const BBox &fromwhere, const int s) {
00246     
00247     BBox tobb(target.bbox()); 
00248     BBox from(fromwhere * source.bbox()); BBox frombb(from); AlignBBox(frombb, s);
00249     tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1); 
00250     tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize());
00251     
00252     BeginFastIndex3(src, source.bbox(), source.data(), const VectorType);
00253     BeginFastIndex2(tgt, target.bbox(), target.data(), FixupType);
00254     switch(s) {
00255     case 0: 
00256     case 1: 
00257       for_2 (k, l, tobb, tobb.stepsize()) 
00258         plus_to(FastIndex2(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00259                 FastIndex3(src, from.lower(0), k-k%frombb.stepsize(0),
00260                            l-l%frombb.stepsize(1)));
00261       end_for
00262       break;
00263     case 2:
00264     case 3: 
00265       for_2 (k, l, tobb, tobb.stepsize()) 
00266         plus_to(FastIndex2(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00267                 FastIndex3(src, k-k%frombb.stepsize(0), from.lower(1), 
00268                            l-l%frombb.stepsize(1)));
00269       end_for
00270       break;
00271     case 4:
00272     case 5: 
00273       for_2 (k, l, tobb, tobb.stepsize()) 
00274         plus_to(FastIndex2(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00275                 FastIndex3(src, k-k%frombb.stepsize(0), 
00276                            l-l%frombb.stepsize(1), from.lower(2)));
00277       end_for
00278       break;
00279     default:
00280       assert(0);
00281     }
00282     EndFastIndex3(src);
00283     EndFastIndex2(tgt);
00284   }
00285   
00286   void add_from(GridData(3)<VectorType> &target, const BBox &towhere, 
00287                 const GridData(2)<FixupType> &source, const BBox &from, const int s) {
00288     
00289     BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s);
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     const int dl = frombb.lower(1)-tobb.lower(1);
00294     
00295     BeginFastIndex2(src, source.bbox(), source.data(), const FixupType);
00296     BeginFastIndex3(tgt, target.bbox(), target.data(), VectorType);
00297     switch(s) {
00298     case 0: 
00299     case 1: 
00300       for_2 (k, l, tobb, tobb.stepsize()) 
00301         plus_from(FastIndex3(tgt,to.lower(0),k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00302                   FastIndex2(src, k+dk-(k+dk)%frombb.stepsize(0),
00303                              l+dl-(l+dl)%frombb.stepsize(1)));               
00304       end_for
00305       break;
00306     case 2:
00307     case 3: 
00308       for_2 (k, l, tobb, tobb.stepsize()) 
00309         plus_from(FastIndex3(tgt,k-k%tobb.stepsize(0),to.lower(1),l-l%tobb.stepsize(1)), 
00310                   FastIndex2(src, k+dk-(k+dk)%frombb.stepsize(0),
00311                              l+dl-(l+dl)%frombb.stepsize(1)));
00312       end_for
00313       break;
00314     case 4:
00315     case 5: 
00316       for_2 (k, l, tobb, tobb.stepsize()) 
00317         plus_from(FastIndex3(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1),to.lower(2)), 
00318                   FastIndex2(src, k+dk-(k+dk)%frombb.stepsize(0),
00319                              l+dl-(l+dl)%frombb.stepsize(1)));
00320       end_for
00321       break;
00322     default:
00323       assert(0);
00324     }
00325     EndFastIndex2(src);
00326     EndFastIndex3(tgt);
00327   }
00328   void add_from(GridData(3)<VectorType> &target, const BBox &towhere, 
00329                 const GridData(2)<FixupType> &source, const int s) {
00330     
00331     BBox to(towhere * target.bbox()); BBox tobb(to); AlignBBox(tobb, s);
00332     BBox frombb(source.bbox()); 
00333     tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);     
00334     tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize());
00335     
00336     BeginFastIndex2(src, source.bbox(), source.data(), const FixupType);
00337     BeginFastIndex3(tgt, target.bbox(), target.data(), VectorType);
00338     switch(s) {
00339     case 0: 
00340     case 1: 
00341       for_2 (k, l, tobb, tobb.stepsize()) 
00342         plus_from(FastIndex3(tgt,to.lower(0),k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00343                   FastIndex2(src, k-k%frombb.stepsize(0),
00344                              l-l%frombb.stepsize(1)));               
00345       end_for
00346       break;
00347     case 2:
00348     case 3: 
00349       for_2 (k, l, tobb, tobb.stepsize()) 
00350         plus_from(FastIndex3(tgt,k-k%tobb.stepsize(0),to.lower(1),l-l%tobb.stepsize(1)), 
00351                   FastIndex2(src, k-k%frombb.stepsize(0),
00352                              l-l%frombb.stepsize(1)));
00353       end_for
00354       break;
00355     case 4:
00356     case 5: 
00357       for_2 (k, l, tobb, tobb.stepsize()) 
00358         plus_from(FastIndex3(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1),to.lower(2)), 
00359                   FastIndex2(src, k-k%frombb.stepsize(0),
00360                              l-l%frombb.stepsize(1)));
00361       end_for
00362       break;
00363     default:
00364       assert(0);
00365     }
00366     EndFastIndex2(src);
00367     EndFastIndex3(tgt);
00368   }
00369   
00370   void add_to(GridData(2)<FixupType> &target, const BBox &to, 
00371               const GridData(2)<VectorType> &source, const BBox &from) {
00372     
00373     BBox tobb(to * target.bbox()); 
00374     BBox frombb(from * source.bbox()); 
00375     tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);   
00376     const int dk = frombb.lower(0)-tobb.lower(0);
00377     const int dl = frombb.lower(1)-tobb.lower(1);
00378     
00379     BeginFastIndex2(src, source.bbox(), source.data(), const VectorType);
00380     BeginFastIndex2(tgt, target.bbox(), target.data(), FixupType);
00381     for_2 (k, l, tobb, tobb.stepsize()) 
00382       plus_to(FastIndex2(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00383               FastIndex2(src, k+dk-(k+dk)%frombb.stepsize(0),
00384                          l+dl-(l+dl)%frombb.stepsize(1)));
00385     end_for
00386     EndFastIndex2(src);
00387     EndFastIndex2(tgt);
00388   }
00389   void add_to(GridData(2)<FixupType> &target, 
00390               const GridData(2)<VectorType> &source, const BBox &where) {
00391     
00392     BBox tobb(target.bbox()); 
00393     BBox frombb(where * source.bbox()); 
00394     tobb.growupper(1); tobb.stepsize().min(frombb.stepsize()); tobb.growupper(-1);   
00395     tobb *= refine(frombb,frombb.stepsize()/tobb.stepsize());
00396     
00397     BeginFastIndex2(src, source.bbox(), source.data(), const VectorType);
00398     BeginFastIndex2(tgt, target.bbox(), target.data(), FixupType);
00399     for_2 (k, l, tobb, tobb.stepsize()) 
00400       plus_to(FastIndex2(tgt,k-k%tobb.stepsize(0),l-l%tobb.stepsize(1)), 
00401               FastIndex2(src, k-k%frombb.stepsize(0),
00402                          l-l%frombb.stepsize(1)));
00403     end_for
00404     EndFastIndex2(src);
00405     EndFastIndex2(tgt);
00406   }
00407 };
00408   
00415 template <class VectorType, class FixupType>
00416 class Fixup(3) : public FixupBase(3)<VectorType,FixupType> {
00417   typedef Integrator(3)<VectorType> integrator_type;
00418   typedef GridData(3)<VectorType>  vec_grid_data_type;
00419   typedef GridData(DIM_1)<VectorType> ld_vec_grid_data_type;
00420   typedef GridData(DIM_1)<FixupType>  ld_fixup_grid_data_type;
00421 
00422 public:
00423   Fixup(3)(integrator_type& integ) : FixupBase(3)<VectorType,FixupType>(integ) {}  
00424 
00425 protected:
00426   void debug_print(vec_grid_data_type &gd, const BBox &where) {
00427 #ifdef DEBUG_PRINT
00428     for (register int k=where.lower(2); k<=where.upper(2); k+=where.stepsize(2)) 
00429       for (register int j=where.lower(1); j<=where.upper(1); j+=where.stepsize(1)) {
00430         for (register int i=where.lower(0); i<=where.upper(0); i+=where.stepsize(0)) 
00431           ( comm_service::log() << "[" << i << "," << j << "," << k << "]=" 
00432             << gd(i,j,k)(0) << " " ).flush();
00433       } 
00434 #endif
00435   }    
00436 
00437   void debug_print_ldv(ld_vec_grid_data_type &gd, const BBox &where) {
00438 #ifdef DEBUG_PRINT
00439     for (register int j=where.lower(1); j<=where.upper(1); j+=where.stepsize(1)) {
00440       for (register int i=where.lower(0); i<=where.upper(0); i+=where.stepsize(0)) 
00441         ( comm_service::log() << "[" << i << "," << j << "]=" 
00442           << gd(i,j)(0) << " " ).flush();
00443       ( comm_service::log() << "\n" ).flush();
00444     }   
00445 #endif
00446   }    
00447   void debug_print_ldv(ld_vec_grid_data_type &gd) {
00448     debug_print_ldv(gd, gd.bbox());
00449   }
00450 
00451   void debug_print_ld(ld_fixup_grid_data_type &gd, const BBox &where) {
00452 #ifdef DEBUG_PRINT
00453     for (register int j=where.lower(1); j<=where.upper(1); j+=where.stepsize(1)) {
00454       for (register int i=where.lower(0); i<=where.upper(0); i+=where.stepsize(0)) 
00455         ( comm_service::log() << "[" << i << "," << j << "]=" 
00456           << gd(i,j)(0) << " " ).flush();
00457       ( comm_service::log() << "\n" ).flush();
00458     }   
00459 #endif
00460   }    
00461   void debug_print_ld(ld_fixup_grid_data_type &gd) {
00462     debug_print_ld(gd, gd.bbox());
00463   }
00464 };
00465 
00466 #endif


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04