vtf-logo

StdCriterion.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2002 Ralf Deiterding
00004 // Brandenburgische Universitaet Cottbus
00005 //
00006 // Copyright (C) 2003-2007 California Institute of Technology
00007 // Ralf Deiterding, ralf@amroc.net
00008 
00009 #ifndef AMROC_STDCRITERION_H
00010 #define AMROC_STDCRITERION_H
00011 
00018 #include "Criterion.h"
00019 
00020 template <class VectorType, class FlagType, int dim> class StdCriterion; 
00021 
00028 template <class VectorType, class FlagType>
00029 class StdCriterion<VectorType,FlagType,1> : 
00030   public Criterion<VectorType,FlagType,1> {
00031   typedef typename VectorType::InternalDataType DataType;
00032   typedef Criterion<VectorType,FlagType,1> base;
00033 public:
00034   typedef typename base::grid_fct_type grid_fct_type;
00035   typedef typename base::flag_fct_type flag_fct_type;
00036   typedef typename base::grid_data_type grid_data_type;
00037 
00038   StdCriterion() : base() {}
00039 
00040   virtual ~StdCriterion() {}
00041 
00042   virtual void FlagByValue(grid_fct_type& work, flag_fct_type& flags,
00043                            const int& Time, const int& Level, 
00044                            const DataType& Tol, const FlagType& FlagValue,
00045                            const int comparison = 0, const int growby = 0) {
00046 
00047     int TStep = TimeStep(work,Level);
00048     forall(flags, Time, Level, c)
00049       BeginFastIndex1(work, work(Time+TStep,Level,c).bbox(), 
00050                       work(Time+TStep,Level,c).data(), DataType);        
00051       BeginFastIndex1(flags, flags(Time,Level,c).bbox(), 
00052                       flags(Time,Level,c).data(), FlagType);
00053 
00054       BBox OpBox = flags.interiorbbox(Time,Level,c);
00055       Coords& Os = OpBox.stepsize();
00056       BBox OpwBox = work(Time+TStep,Level,c).bbox();
00057       Coords& Ows = OpwBox.stepsize();
00058 
00059       for_1 (n, OpBox, Os)
00060         if ((comparison==0 && FastIndex1(work,n-n%Ows(0))>=Tol) ||
00061             (comparison==1 && FastIndex1(work,n-n%Ows(0))< Tol)) {
00062           if (growby<=0) 
00063             FastIndex1(flags,n) = FlagValue;
00064           else {
00065             BBox bbflag(1,n,n,Os(0)); bbflag.grow(growby);
00066             flags(Time,Level,c).equals(FlagValue,bbflag);
00067           }
00068         }
00069       end_for
00070 
00071       EndFastIndex1(work);
00072       EndFastIndex1(flags);
00073     end_forall
00074   } 
00075 
00076   virtual void Difference(grid_fct_type& work, const int& Time, const int& Level, 
00077                           int* Offset1, int* Offset2) {
00078 
00079     int TStep = TimeStep(work,Level);
00080     forall(work, Time, Level, c)
00081       BBox OpBox = work.interiorbbox(Time,Level,c);
00082       Coords& OpBox_stepsize = OpBox.stepsize();
00083       BeginFastIndex1(work, work(Time,Level,c).bbox(), 
00084                       work(Time,Level,c).data(), DataType);
00085       BeginFastIndex1(workout, work(Time+TStep,Level,c).bbox(), 
00086                       work(Time+TStep,Level,c).data(), DataType);
00087 
00088       Coords o1 = Coords(1,Offset1)*OpBox_stepsize;
00089       Coords o2 = Coords(1,Offset2)*OpBox_stepsize;
00090       for_1 (n, OpBox, OpBox_stepsize)
00091         FastIndex1(workout,n) = std::max(FastIndex1(workout,n),
00092            std::fabs(FastIndex1(work,n+o1(0))-FastIndex1(work,n+o2(0))));
00093       end_for
00094 
00095       EndFastIndex1(work);
00096       EndFastIndex1(workout);
00097     end_forall
00098   }
00099 
00100   virtual void Abs(grid_data_type& work) {
00101     BBox OpBox = work.bbox();
00102     Coords& OpBox_stepsize = OpBox.stepsize();
00103     BeginFastIndex1(work, OpBox, work.data(), DataType);
00104     for_1 (n, OpBox, OpBox_stepsize)
00105       FastIndex1(work,n) = std::fabs(FastIndex1(work,n));
00106     end_for
00107     EndFastIndex1(work);
00108   }
00109 
00110   virtual void Max(grid_data_type& work, const DataType& val) {
00111     BBox OpBox = work.bbox();
00112     Coords& OpBox_stepsize = OpBox.stepsize();
00113     BeginFastIndex1(work, OpBox, work.data(), DataType);
00114     for_1 (n, OpBox, OpBox_stepsize)
00115       FastIndex1(work,n) = std::max(FastIndex1(work,n), val);
00116     end_for
00117     EndFastIndex1(work);
00118   }
00119 
00120   virtual void Min(grid_data_type& work, const DataType& val) {
00121     BBox OpBox = work.bbox();
00122     Coords& OpBox_stepsize = OpBox.stepsize();
00123     BeginFastIndex1(work, OpBox, work.data(), DataType);
00124     for_1 (n, OpBox, OpBox_stepsize)
00125       FastIndex1(work,n) = std::min(FastIndex1(work,n), val);
00126     end_for
00127     EndFastIndex1(work);
00128   }
00129 };
00130 
00131 
00138 template <class VectorType, class FlagType>
00139 class StdCriterion<VectorType,FlagType,2> : 
00140   public Criterion<VectorType,FlagType,2> {
00141   typedef typename VectorType::InternalDataType DataType;
00142   typedef Criterion<VectorType,FlagType,2> base;
00143 public:
00144   typedef typename base::grid_fct_type grid_fct_type;
00145   typedef typename base::flag_fct_type flag_fct_type;
00146   typedef typename base::grid_data_type grid_data_type;
00147 
00148   StdCriterion() : base() {}
00149 
00150   virtual ~StdCriterion() {}
00151 
00152   virtual void FlagByValue(grid_fct_type& work, flag_fct_type& flags,
00153                            const int& Time, const int& Level, 
00154                            const DataType& Tol, const FlagType& FlagValue,
00155                            const int comparison = 0, const int growby = 0) {
00156 
00157     int TStep = TimeStep(work,Level);
00158     forall(flags, Time, Level, c)
00159       BeginFastIndex2(work, work(Time+TStep,Level,c).bbox(), 
00160                       work(Time+TStep,Level,c).data(), DataType);        
00161       BeginFastIndex2(flags, flags(Time,Level,c).bbox(), 
00162                       flags(Time,Level,c).data(), FlagType);
00163 
00164       BBox OpBox = flags.interiorbbox(Time,Level,c);
00165       Coords& Os = OpBox.stepsize();
00166       BBox OpwBox = work(Time+TStep,Level,c).bbox();
00167       Coords& Ows = OpwBox.stepsize();
00168 
00169       for_2 (n, m, OpBox, Os)
00170         if ((comparison==0 && FastIndex2(work,n-n%Ows(0),m-m%Ows(1))>=Tol) ||
00171             (comparison==1 && FastIndex2(work,n-n%Ows(0),m-m%Ows(1))< Tol)) {
00172           if (growby<=0) 
00173             FastIndex2(flags,n,m) = FlagValue;
00174           else {
00175             BBox bbflag(2,n,m,n,m,Os(0),Os(1)); bbflag.grow(growby);
00176             flags(Time,Level,c).equals(FlagValue,bbflag);
00177           }
00178         }
00179       end_for
00180 
00181       EndFastIndex2(work);
00182       EndFastIndex2(flags);
00183     end_forall
00184   } 
00185 
00186   virtual void Difference(grid_fct_type& work, const int& Time, const int& Level, 
00187                           int* Offset1, int* Offset2) {
00188 
00189     int TStep = TimeStep(work,Level);
00190     forall(work, Time, Level, c)
00191       BBox OpBox = work.interiorbbox(Time,Level,c);
00192       Coords& OpBox_stepsize = OpBox.stepsize();
00193       BeginFastIndex2(work, work(Time,Level,c).bbox(), 
00194                       work(Time,Level,c).data(), DataType);
00195       BeginFastIndex2(workout, work(Time+TStep,Level,c).bbox(), 
00196                       work(Time+TStep,Level,c).data(), DataType);
00197 
00198       Coords o1 = Coords(2,Offset1)*OpBox_stepsize;
00199       Coords o2 = Coords(2,Offset2)*OpBox_stepsize;
00200       for_2 (n, m, OpBox, OpBox_stepsize)
00201         FastIndex2(workout,n,m) = std::max(FastIndex2(workout,n,m),
00202            std::fabs(FastIndex2(work,n+o1(0),m+o1(1))-FastIndex2(work,n+o2(0),m+o2(1))));
00203       end_for
00204 
00205       EndFastIndex2(work);
00206       EndFastIndex2(workout);
00207     end_forall
00208   }
00209 
00210   virtual void Abs(grid_data_type& work) {
00211     BBox OpBox = work.bbox();
00212     Coords& OpBox_stepsize = OpBox.stepsize();
00213     BeginFastIndex2(work, OpBox, work.data(), DataType);
00214     for_2 (n, m, OpBox, OpBox_stepsize)
00215       FastIndex2(work,n,m) = std::fabs(FastIndex2(work,n,m));
00216     end_for
00217     EndFastIndex2(work);
00218   }
00219 
00220   virtual void Max(grid_data_type& work, const DataType& val) {
00221     BBox OpBox = work.bbox();
00222     Coords& OpBox_stepsize = OpBox.stepsize();
00223     BeginFastIndex2(work, OpBox, work.data(), DataType);
00224     for_2 (n, m, OpBox, OpBox_stepsize)
00225       FastIndex2(work,n,m) = std::max(FastIndex2(work,n,m), val);
00226     end_for
00227     EndFastIndex2(work);
00228   }
00229 
00230   virtual void Min(grid_data_type& work, const DataType& val) {
00231     BBox OpBox = work.bbox();
00232     Coords& OpBox_stepsize = OpBox.stepsize();
00233     BeginFastIndex2(work, OpBox, work.data(), DataType);
00234     for_2 (n, m, OpBox, OpBox_stepsize)
00235       FastIndex2(work,n,m) = std::min(FastIndex2(work,n,m), val);
00236     end_for
00237     EndFastIndex2(work);
00238   }
00239 };
00240 
00241 
00248 template <class VectorType, class FlagType>
00249 class StdCriterion<VectorType,FlagType,3> : 
00250   public Criterion<VectorType,FlagType,3> {
00251   typedef typename VectorType::InternalDataType DataType;
00252   typedef Criterion<VectorType,FlagType,3> base;
00253 public:
00254   typedef typename base::grid_fct_type grid_fct_type;
00255   typedef typename base::flag_fct_type flag_fct_type;
00256   typedef typename base::grid_data_type grid_data_type;
00257 
00258   StdCriterion() : base() {}
00259 
00260   virtual ~StdCriterion() {}
00261 
00262   virtual void FlagByValue(grid_fct_type& work, flag_fct_type& flags,
00263                            const int& Time, const int& Level, 
00264                            const DataType& Tol, const FlagType& FlagValue,
00265                            const int comparison = 0, const int growby = 0) {
00266 
00267     int TStep = TimeStep(work,Level);
00268     forall(flags, Time, Level, c)
00269       BeginFastIndex3(work, work(Time+TStep,Level,c).bbox(), 
00270                       work(Time+TStep,Level,c).data(), DataType);        
00271       BeginFastIndex3(flags, flags(Time,Level,c).bbox(), 
00272                       flags(Time,Level,c).data(), FlagType);
00273 
00274       BBox OpBox = flags.interiorbbox(Time,Level,c);
00275       Coords& Os = OpBox.stepsize();
00276       BBox OpwBox = work(Time+TStep,Level,c).bbox();
00277       Coords& Ows = OpwBox.stepsize();
00278 
00279       for_3 (n, m, l, OpBox, Os)
00280         if ((comparison==0 && FastIndex3(work,n-n%Ows(0),m-m%Ows(1),l-l%Ows(2))>=Tol) ||
00281             (comparison==1 && FastIndex3(work,n-n%Ows(0),m-m%Ows(1),l-l%Ows(2))< Tol)) {
00282           if (growby<=0) 
00283             FastIndex3(flags,n,m,l) = FlagValue;
00284           else {
00285             BBox bbflag(3,n,m,l,n,m,l,Os(0),Os(1),Os(2)); bbflag.grow(growby);
00286             flags(Time,Level,c).equals(FlagValue,bbflag);
00287           }
00288         }
00289       end_for
00290 
00291       EndFastIndex3(work);
00292       EndFastIndex3(flags);
00293     end_forall
00294   } 
00295 
00296   virtual void Difference(grid_fct_type& work, const int& Time, const int& Level, 
00297                           int* Offset1, int* Offset2) {
00298 
00299     int TStep = TimeStep(work,Level);
00300     forall(work, Time, Level, c)
00301       BBox OpBox = work.interiorbbox(Time,Level,c);
00302       Coords& OpBox_stepsize = OpBox.stepsize();
00303       BeginFastIndex3(work, work(Time,Level,c).bbox(), 
00304                       work(Time,Level,c).data(), DataType);
00305       BeginFastIndex3(workout, work(Time+TStep,Level,c).bbox(), 
00306                       work(Time+TStep,Level,c).data(), DataType);
00307 
00308       Coords o1 = Coords(3,Offset1)*OpBox_stepsize;
00309       Coords o2 = Coords(3,Offset2)*OpBox_stepsize;
00310       for_3 (n, m, l, OpBox, OpBox_stepsize)
00311         FastIndex3(workout,n,m,l) = std::max(FastIndex3(workout,n,m,l),
00312            std::fabs(FastIndex3(work,n+o1(0),m+o1(1),l+o1(2))-FastIndex3(work,n+o2(0),m+o2(1),l+o2(2))));
00313       end_for
00314 
00315       EndFastIndex3(work);
00316       EndFastIndex3(workout);
00317     end_forall
00318   }
00319 
00320   virtual void Abs(grid_data_type& work) {
00321     BBox OpBox = work.bbox();
00322     Coords& OpBox_stepsize = OpBox.stepsize();
00323     BeginFastIndex3(work, OpBox, work.data(), DataType);
00324     for_3 (n, m, l, OpBox, OpBox_stepsize)
00325       FastIndex3(work,n,m,l) = std::fabs(FastIndex3(work,n,m,l));
00326     end_for
00327     EndFastIndex3(work);
00328   }
00329 
00330   virtual void Max(grid_data_type& work, const DataType& val) {
00331     BBox OpBox = work.bbox();
00332     Coords& OpBox_stepsize = OpBox.stepsize();
00333     BeginFastIndex3(work, OpBox, work.data(), DataType);
00334     for_3 (n, m, l, OpBox, OpBox_stepsize)
00335       FastIndex3(work,n,m,l) = std::max(FastIndex3(work,n,m,l), val);
00336     end_for
00337     EndFastIndex3(work);
00338   }
00339 
00340   virtual void Min(grid_data_type& work, const DataType& val) {
00341     BBox OpBox = work.bbox();
00342     Coords& OpBox_stepsize = OpBox.stepsize();
00343     BeginFastIndex3(work, OpBox, work.data(), DataType);
00344     for_3 (n, m, l, OpBox, OpBox_stepsize)
00345       FastIndex3(work,n,m,l) = std::min(FastIndex3(work,n,m,l), val);
00346     end_for
00347     EndFastIndex3(work);
00348   }
00349 };
00350 
00351 
00352 #endif

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