vtf-logo

Fixup3.h

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

Generated on Fri Aug 24 13:00:50 2007 for AMROC Fluid-solver Framework - by  doxygen 1.4.7