00001
00002
00003
00004
00005
00006 #ifndef SCHEME_FILEINPUT_H
00007 #define SCHEME_FILEINPUT_H
00008
00016 #include "FileInput.h"
00017 #include "Interfaces/SchemeFileOutput.h"
00018
00019 template <class SchemeType, int dim>
00020 class SchemeInBase {
00021 typedef typename SchemeType::VectorType VectorType;
00022 typedef typename VectorType::InternalDataType DataType;
00023 typedef GridFunction<VectorType,dim> vec_grid_fct_type;
00024 typedef GridFunction<DataType,dim> grid_fct_type;
00025
00026 public:
00027 SchemeInBase(SchemeType &scheme) : _scheme(scheme) {}
00028
00029 virtual ~SchemeInBase() {}
00030
00031 virtual void Transform(grid_fct_type& work, vec_grid_fct_type& u, const int Time, const int& Level,
00032 const int cnt, const double& t) {
00033 forall(u,Time,Level,c)
00034 Scheme().Input(u(Time,Level,c),work(Time,Level,c),cnt);
00035 end_forall
00036 }
00037
00038 inline SchemeType& Scheme() { return _scheme; }
00039 inline const SchemeType& Scheme() const { return _scheme; }
00040
00041 protected:
00042 SchemeType &_scheme;
00043 };
00044
00045
00057 template <class SchemeType, int dim>
00058 class SchemeFileInput : public SchemeOutBase<SchemeType,dim>, public SchemeInBase<SchemeType,dim>,
00059 public FileInput<typename SchemeType::VectorType,dim> {
00060 typedef typename SchemeType::VectorType VectorType;
00061 typedef typename VectorType::InternalDataType DataType;
00062 typedef FileInput<VectorType,dim> base;
00063 typedef SchemeOutBase<SchemeType,dim> out_base;
00064 typedef SchemeInBase<SchemeType,dim> in_base;
00065 public:
00066 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00067 typedef typename base::grid_fct_type grid_fct_type;
00068 typedef typename base::grid_data_type grid_data_type;
00069
00070 SchemeFileInput(SchemeType &scheme) : out_base(scheme), in_base(scheme), base(), _scheme(scheme) {}
00071
00072 virtual ~SchemeFileInput() {}
00073
00074 virtual void ReadIn(vec_grid_fct_type& u, grid_fct_type& IOfunc) {
00075 for (int cnt=1; cnt<=base::Ncnt(); cnt++) {
00076 if (base::CompName[cnt-1].c_str()[0] == '-')
00077 continue;
00078 int lev;
00079 double t;
00080 for (lev=0; lev<=FineLevel(base::GH()); lev++) {
00081 int Time = CurrentTime(base::GH(),lev);
00082 t = GetPhysicalTime(u,Time,lev);
00083 ((out_base*) this)->Transform(u,IOfunc,Time,lev,cnt,t);
00084 }
00085 ReadIn(IOfunc,base::CompName[cnt-1].c_str());
00086 for (lev=0; lev<=FineLevel(base::GH()); lev++) {
00087 int Time = CurrentTime(base::GH(),lev);
00088 t = GetPhysicalTime(u,Time,lev);
00089 ((in_base*) this)->Transform(IOfunc,u,Time,lev,cnt,t);
00090 }
00091 #ifndef DAGH_NO_MPI
00092 MPI_Barrier(comm_service::comm());
00093 #endif
00094 }
00095 }
00096
00097 virtual void ReadIn(grid_fct_type& IOfunc, const char* name)
00098 { base::ReadIn(IOfunc,name); }
00099
00100 virtual void ReadIn(grid_fct_type& IOfunc, const char* name,
00101 const int& Time, const int& Level)
00102 { base::ReadIn(IOfunc,name,Time,Level); }
00103
00104 virtual void ReadIn(grid_data_type& IOdata, const char* name,
00105 const int& Time, const int& Level) {
00106 base::ReadIn(IOdata,name,Time,Level);
00107 }
00108
00109 inline SchemeType& Scheme() { return _scheme; }
00110 inline const SchemeType& Scheme() const { return _scheme; }
00111
00112 protected:
00113 SchemeType &_scheme;
00114 };
00115
00116 #endif