00001
00002
00003
00004
00005
00006 #ifndef SCHEME_EXACT_SOLUTION_H
00007 #define SCHEME_EXACT_SOLUTION_H
00008
00016 #include "ExactSolution.h"
00017
00024 template <class SchemeType, int dim>
00025 class SchemeExactSolution : public ExactSolution<typename SchemeType::VectorType,dim> {
00026 typedef ExactSolution<typename SchemeType::VectorType,dim> base;
00027 public:
00028 typedef typename SchemeType::VectorType VectorType;
00029 typedef typename VectorType::InternalDataType DataType;
00030 typedef typename base::vec_grid_data_type vec_grid_data_type;
00031 typedef typename base::grid_data_type grid_data_type;
00032 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00033 typedef typename base::grid_fct_type grid_fct_type;
00034
00035 SchemeExactSolution(SchemeType &scheme) : base(), _scheme(scheme) {
00036 OutputFileName = "-";
00037 OutputIndices = "-";
00038 }
00039 virtual ~SchemeExactSolution() {}
00040
00041 virtual void SetGrid(vec_grid_data_type& fvec, grid_data_type& workvec,
00042 const int& level, const double& t) {}
00043
00044 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00045 base::register_at(Ctrl,prefix);
00046 RegisterAt(base::LocCtrl,"OutputFileName",OutputFileName);
00047 RegisterAt(base::LocCtrl,"OutputIndices",OutputIndices);
00048 }
00049 virtual void register_at(ControlDevice& Ctrl) { register_at(Ctrl, ""); }
00050
00051 virtual void ErrorNorm(vec_grid_fct_type& u, grid_fct_type& work,
00052 const double& t) {
00053
00054 if (base::ENorm<1 || base::ENorm>3)
00055 return;
00056 if (!(this->Set(u,work,t)))
00057 return;
00058
00059 if (OutputIndices.c_str()[0] != '-') {
00060 int me = MY_PROC;
00061 std::ofstream outfile;
00062 std::ostream* out = 0;
00063 if (me==VizServer && OutputFileName.c_str()[0] != '-') {
00064 outfile.open(OutputFileName.c_str(), std::ios::out | std::ios::app);
00065 out = new std::ostream(outfile.rdbuf());
00066 }
00067 if (me == VizServer) {
00068 std::cout << " Output Error:";
00069 if (out) *out << t;
00070 }
00071
00072 DataType *Error = (DataType *) 0;
00073 std::string delimiter = ",";
00074 std::string s = OutputIndices+delimiter;
00075 size_t pos = 0;
00076 std::string token;
00077 while ((pos = s.find(delimiter)) != std::string::npos) {
00078 token = s.substr(0, pos);
00079 int cnt = std::atoi( token.c_str() );
00080 s.erase(0, pos + delimiter.length());
00081
00082 for (int lev=0; lev<=FineLevel(base::GH()); lev++) {
00083 int Time = CurrentTime(base::GH(),lev);
00084 int TStep = TimeStep(u,lev);
00085 forall (u,Time,lev,c)
00086 Scheme().Output(u(Time,lev,c), work(Time,lev,c), cnt);
00087 Scheme().Output(u(Time+TStep,lev,c), work(Time+TStep,lev,c), cnt);
00088 work(Time+TStep,lev,c).minus(work(Time,lev,c));
00089 end_forall
00090 }
00091
00092 this->CalculateNorm(work, Error);
00093
00094 if (base::ENormAll) {
00095 std::cout << " " << Error[0];
00096 if (out) *out << " " << Error[0];
00097 }
00098 else
00099 for (int lev=0; lev<=FineLevel(base::GH()); lev++) {
00100 std::cout << " L(" << lev << ")=" << Error[lev];
00101 if (out) *out << " " << Error[lev];
00102 }
00103 }
00104 if (me == VizServer) {
00105 std::cout << std::endl;
00106 if (out) *out << std::endl;
00107 outfile.close();
00108 delete out;
00109 }
00110 if (Error) delete [] Error;
00111 }
00112 base::ErrorNorm(u,work,t);
00113 }
00114
00115 inline SchemeType& Scheme() { return _scheme; }
00116 inline const SchemeType& Scheme() const { return _scheme; }
00117
00118 protected:
00119 SchemeType &_scheme;
00120 std::string OutputFileName, OutputIndices;
00121 };
00122
00123
00124 #endif