00001
00002
00003
00004
00005
00006 #ifndef SCHEME_CRITERIA_H
00007 #define SCHEME_CRITERIA_H
00008
00015 #include "Criteria/ByValue.h"
00016 #include "Criteria/ScaledGradient.h"
00017 #include "Criteria/AbsoluteError.h"
00018 #include "Criteria/LimiterType.h"
00019 #include "Criteria/RelativeError.h"
00020 #include "Criteria/Regions.h"
00021 #include "Interfaces/SchemeFileOutput.h"
00022
00030 template <class SchemeType, class FlagType, int dim>
00031 class SchemeByValue : public SchemeOutBase<SchemeType,dim>,
00032 public ByValue<typename SchemeType::VectorType,FlagType,dim> {
00033 typedef typename SchemeType::VectorType VectorType;
00034 typedef typename VectorType::InternalDataType DataType;
00035 typedef ByValue<VectorType,FlagType,dim> base;
00036 typedef SchemeOutBase<SchemeType,dim> out_base;
00037 public:
00038 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00039 typedef typename base::grid_fct_type grid_fct_type;
00040 typedef typename base::flag_fct_type flag_fct_type;
00041
00042 SchemeByValue(SchemeType &scheme) : out_base(scheme), base() {}
00043
00044 virtual ~SchemeByValue() {}
00045
00046 virtual void register_at(ControlDevice& Ctrl) { base::register_at(Ctrl, "Output"); }
00047 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix)
00048 { base::register_at(Ctrl, "Output"); }
00049
00050 virtual bool SetFlags(vec_grid_fct_type& u, grid_fct_type& work, flag_fct_type& flags,
00051 const int& cnt, const int& Time, const int& Level, const double& t,
00052 const FlagType& FlagValue) {
00053 if (base::Tol(cnt) <= 0.0 ||
00054 (base::MaxLevel(cnt)<Level && base::MaxLevel(cnt)>=0)) return false;
00055 this->Transform(u,work,Time,Level,cnt+1,t);
00056 int TStep = TimeStep(work,Level);
00057 forall(work,Time+TStep,Level,c)
00058 work(Time+TStep,Level,c).equals(work(Time,Level,c));
00059 end_forall
00060 base::FlagByValue(work, flags, Time, Level, base::Tol(cnt), FlagValue,
00061 base::_Comparison[cnt]);
00062 return true;
00063 }
00064
00065 virtual void OutputName(char* name, int cnt) { std::sprintf(name,"ovalue_%d",cnt+1); }
00066 };
00067
00068
00075 template <class SchemeType, class FlagType, int dim>
00076 class SchemeScaledGradient : public SchemeOutBase<SchemeType,dim>,
00077 public ScaledGradient<typename SchemeType::VectorType,FlagType,dim> {
00078 typedef typename SchemeType::VectorType VectorType;
00079 typedef typename VectorType::InternalDataType DataType;
00080 typedef ScaledGradient<VectorType,FlagType,dim> base;
00081 typedef SchemeOutBase<SchemeType,dim> out_base;
00082 public:
00083 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00084 typedef typename base::grid_fct_type grid_fct_type;
00085 typedef typename base::flag_fct_type flag_fct_type;
00086
00087 SchemeScaledGradient(SchemeType &scheme) : out_base(scheme), base() {}
00088
00089 virtual ~SchemeScaledGradient() {}
00090
00091 virtual void register_at(ControlDevice& Ctrl) { base::register_at(Ctrl, "Output"); }
00092 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix)
00093 { base::register_at(Ctrl, "Output"); }
00094
00095 virtual bool SetFlags(vec_grid_fct_type& u, grid_fct_type& work, flag_fct_type& flags,
00096 const int& cnt, const int& Time, const int& Level, const double& t,
00097 const FlagType& FlagValue) {
00098 if (base::Tol(cnt) <= 0.0 ||
00099 (base::MaxLevel(cnt)<Level && base::MaxLevel(cnt)>=0)) return false;
00100 this->Transform(u,work,Time,Level,cnt+1,t);
00101 return base::FlagByScaledGradient(work, flags, Time, Level, base::Tol(cnt), FlagValue);
00102 }
00103
00104 virtual void OutputName(char* name, int cnt) { std::sprintf(name,"ograd_%d",cnt+1); }
00105 };
00106
00107
00114 template <class SchemeType, class Fixup, class FlagType, int dim>
00115 class SchemeAbsoluteError : public SchemeOutBase<SchemeType,dim>,
00116 public AbsoluteError<typename SchemeType::VectorType,Fixup,FlagType,dim> {
00117 typedef typename SchemeType::VectorType VectorType;
00118 typedef typename VectorType::InternalDataType DataType;
00119 typedef AbsoluteError<VectorType,Fixup,FlagType,dim> base;
00120 typedef SchemeOutBase<SchemeType,dim> out_base;
00121 public:
00122 typedef typename base::solver_type solver_type;
00123 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00124 typedef typename base::grid_fct_type grid_fct_type;
00125 typedef typename base::flag_fct_type flag_fct_type;
00126
00127 SchemeAbsoluteError(solver_type& solver, SchemeType &scheme) : out_base(scheme), base(solver) {}
00128
00129 virtual ~SchemeAbsoluteError() {}
00130
00131 virtual void register_at(ControlDevice& Ctrl) { base::register_at(Ctrl, "Output"); }
00132 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix)
00133 { base::register_at(Ctrl, "Output"); }
00134
00135 virtual bool SetFlags(vec_grid_fct_type& u, grid_fct_type& work, flag_fct_type& flags,
00136 const int& cnt, const int& Time, const int& Level, const double& t,
00137 const FlagType& FlagValue) {
00138 if (base::Tol(cnt) <= 0.0 || Time==0 ||
00139 (base::MaxLevel(cnt)<Level && base::MaxLevel(cnt)>=0)) return false;
00140 int TStep = TimeStep(work,Level);
00141 this->Transform(u,work,Time,Level,cnt+1,t);
00142 this->Transform(u,work,Time+TStep,Level,cnt+1,t);
00143 forall(work,Time,Level,c)
00144 work(Time+TStep,Level,c).minus(work(Time,Level,c));
00145 base::Abs(work(Time+TStep,Level,c));
00146 work(Time+TStep,Level,c).divide(base::Order);
00147 end_forall
00148 base::FlagByValue(work, flags, Time, Level, base::Tol(cnt), FlagValue);
00149 return true;
00150 }
00151
00152 virtual void OutputName(char* name, int cnt) { std::sprintf(name,"oabserr_%d",cnt+1); }
00153 };
00154
00155
00163 template <class SchemeType, class FlagType, int dim>
00164 class SchemeLimiterType : public SchemeOutBase<SchemeType,dim>,
00165 public LimiterType<typename SchemeType::VectorType,FlagType,dim> {
00166 typedef typename SchemeType::VectorType VectorType;
00167 typedef typename VectorType::InternalDataType DataType;
00168 typedef LimiterType<VectorType,FlagType,dim> base;
00169 typedef SchemeOutBase<SchemeType,dim> out_base;
00170 public:
00171 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00172 typedef typename base::grid_fct_type grid_fct_type;
00173 typedef typename base::flag_fct_type flag_fct_type;
00174
00175 SchemeLimiterType(SchemeType &scheme) : out_base(scheme), base() {}
00176
00177 virtual ~SchemeLimiterType() {}
00178
00179 virtual void register_at(ControlDevice& Ctrl) { base::register_at(Ctrl, "Output"); }
00180 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix)
00181 { base::register_at(Ctrl, "Output"); }
00182
00183 virtual bool SetFlags(vec_grid_fct_type& u, grid_fct_type& work, flag_fct_type& flags,
00184 const int& cnt, const int& Time, const int& Level, const double& t,
00185 const FlagType& FlagValue) {
00186 if (base::Tol(cnt) <= 0.0 || base::Sc(cnt)<=0.0 ||
00187 (base::MaxLevel(cnt)<Level && base::MaxLevel(cnt)>=0)) return false;
00188 this->Transform(u,work,Time,Level,cnt+1,t);
00189 return base::FlagByLimiter(work, flags, Time, Level, base::Tol(cnt), base::Sc(cnt), FlagValue);
00190 }
00191
00192 virtual void OutputName(char* name, int cnt) { std::sprintf(name,"olimtype_%d",cnt+1); }
00193 };
00194
00195
00202 template <class SchemeType, class Fixup, class FlagType, int dim>
00203 class SchemeRelativeError : public SchemeOutBase<SchemeType,dim>,
00204 public RelativeError<typename SchemeType::VectorType,Fixup,FlagType,dim> {
00205 typedef typename SchemeType::VectorType VectorType;
00206 typedef typename VectorType::InternalDataType DataType;
00207 typedef RelativeError<VectorType,Fixup,FlagType,dim> base;
00208 typedef SchemeOutBase<SchemeType,dim> out_base;
00209 public:
00210 typedef typename base::solver_type solver_type;
00211 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00212 typedef typename base::grid_fct_type grid_fct_type;
00213 typedef typename base::flag_fct_type flag_fct_type;
00214
00215 SchemeRelativeError(solver_type& solver, SchemeType &scheme) : out_base(scheme), base(solver) {}
00216
00217 virtual ~SchemeRelativeError() {}
00218
00219 virtual void register_at(ControlDevice& Ctrl) { base::register_at(Ctrl, "Output"); }
00220 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix)
00221 { base::register_at(Ctrl, "Output"); }
00222
00223 virtual bool SetFlags(vec_grid_fct_type& u, grid_fct_type& work, flag_fct_type& flags,
00224 const int& cnt, const int& Time, const int& Level, const double& t,
00225 const FlagType& FlagValue) {
00226 if (base::Tol(cnt) <= 0.0 || base::Sc(cnt)<=0.0 || Time==0 ||
00227 (base::MaxLevel(cnt)<Level && base::MaxLevel(cnt)>=0)) return false;
00228 int TStep = TimeStep(work,Level);
00229 this->Transform(u,work,Time,Level,cnt+1,t);
00230 this->Transform(u,work,Time+TStep,Level,cnt+1,t);
00231 forall(u,Time,Level,c)
00232 work(Time+TStep,Level,c).minus(work(Time,Level,c));
00233 base::Abs(work(Time+TStep,Level,c));
00234 end_forall
00235
00236 if (base::OutputFlags() && base::Solver_().LastOutputTime()==Time && Level==0) {
00237 DataType Maxv = MaxVal(work, Time, 0);
00238 if (MY_PROC == VizServer)
00239 std::cout << " OutputMax(" << cnt+1 << ") on L0=" << Maxv << " ";
00240 }
00241
00242 forall(u,Time,Level,c)
00243 base::Abs(work(Time,Level,c));
00244 base::Max(work(Time,Level,c),base::Sc(cnt));
00245 work(Time+TStep,Level,c).divide(work(Time,Level,c));
00246 work(Time+TStep,Level,c).divide(base::Order);
00247 end_forall
00248
00249 base::FlagByValue(work, flags, Time, Level, base::Tol(cnt), FlagValue);
00250 return true;
00251 }
00252
00253 virtual void OutputName(char* name, int cnt) { std::sprintf(name,"orelerr_%d",cnt+1); }
00254 };
00255
00256 #endif