00001
00002
00003
00004
00005
00006 #ifndef AMROC_F77_FILE_EXACTSOLUTION_H
00007 #define AMROC_F77_FILE_EXACTSOLUTION_H
00008
00016 #include "F77Interfaces/F77ExactSolution.h"
00017 #include "F77Interfaces/F77FileInput.h"
00018 #include "F77Interfaces/F77UpdateLevelTransfer.h"
00019
00031 template <class VectorType, int dim>
00032 class F77FileExactSolution : public F77ExactSolution<VectorType,dim> {
00033 typedef F77ExactSolution<VectorType,dim> base;
00034 typedef typename VectorType::InternalDataType DataType;
00035 public:
00036 typedef F77FileInput<VectorType,dim> file_input_type;
00037 typedef F77UpdateLevelTransfer<Vector<DataType,1>, dim> level_transfer_type;
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::generic_func_type generic_func_type;
00041 typedef typename base::vec_grid_data_type vec_grid_data_type;
00042 typedef typename base::grid_data_type grid_data_type;
00043
00044 F77FileExactSolution(generic_func_type initial) :
00045 base(initial), _ReadInFirst(0), _PhysicalTime(0.0), _TimeDelta(0.0) {
00046 _FileInput = (file_input_type*) 0;
00047 _LevelTransfer = (level_transfer_type*) 0;
00048 }
00049
00050 F77FileExactSolution(generic_func_type exact, generic_func_type in,
00051 generic_func_type prolong) :
00052 base(exact), _ReadInFirst(0), _PhysicalTime(0.0), _TimeDelta(0.0) {
00053 _FileInput = (file_input_type*) 0;
00054 _LevelTransfer = (level_transfer_type*) 0;
00055 if (!in) return;
00056 _FileInput = new file_input_type(in);
00057 if (prolong)
00058 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00059 (new level_transfer_type(prolong, (generic_func_type) 0,
00060 (generic_func_type) 0)));
00061 }
00062
00063 F77FileExactSolution(generic_func_type exact, generic_func_type out,
00064 generic_func_type in, generic_func_type prolong) :
00065 base(exact), _ReadInFirst(0), _PhysicalTime(0.0), _TimeDelta(0.0) {
00066 _FileInput = (file_input_type*) 0;
00067 _LevelTransfer = (level_transfer_type*) 0;
00068 if (!out || !in) return;
00069 _FileInput = new file_input_type(out,in);
00070 if (prolong)
00071 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00072 (new level_transfer_type(prolong, (generic_func_type) 0,
00073 (generic_func_type) 0)));
00074 }
00075
00076 F77FileExactSolution(generic_func_type exact, generic_func_type out,
00077 generic_func_type in, generic_func_type prolong,
00078 generic_func_type restrct) :
00079 base(exact), _ReadInFirst(0), _PhysicalTime(0.0), _TimeDelta(0.0) {
00080 _FileInput = (file_input_type*) 0;
00081 _LevelTransfer = (level_transfer_type*) 0;
00082 if (!out || !in) return;
00083 _FileInput = new file_input_type(out,in);
00084 if (prolong) {
00085 if (!restrct)
00086 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00087 (new level_transfer_type(prolong, (generic_func_type) 0,
00088 (generic_func_type) 0)));
00089 else
00090 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00091 (new level_transfer_type(prolong, restrct, (generic_func_type) 0)));
00092 }
00093 }
00094
00095 F77FileExactSolution(generic_func_type exact, generic_func_type out,
00096 generic_func_type in, generic_func_type prolong,
00097 generic_func_type restrct, generic_func_type update) :
00098 base(exact), _ReadInFirst(0), _PhysicalTime(0.0, _TimeDelta(0.0)) {
00099 _FileInput = (file_input_type*) 0;
00100 _LevelTransfer = (level_transfer_type*) 0;
00101 if (!out || !in) return;
00102 _FileInput = new file_input_type(out,in);
00103 if (prolong) {
00104 if (!restrct) {
00105 if (!update)
00106 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00107 (new level_transfer_type(prolong, (generic_func_type) 0,
00108 (generic_func_type) 0)));
00109 else
00110 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00111 (new level_transfer_type(prolong, (generic_func_type) 0, update)));
00112 }
00113 else {
00114 if (!update)
00115 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00116 (new level_transfer_type(prolong, restrct, (generic_func_type) 0)));
00117 else
00118 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00119 (new level_transfer_type(prolong, restrct, update)));
00120 }
00121 }
00122 }
00123
00124 virtual ~F77FileExactSolution() {
00125 if (_FileInput) delete _FileInput;
00126 if (_LevelTransfer) delete _LevelTransfer;
00127 }
00128
00129 virtual void register_at(ControlDevice& Ctrl) { base::register_at(Ctrl); }
00130 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00131 base::register_at(Ctrl,prefix);
00132 if (_FileInput) _FileInput->register_at(base::LocCtrl, "");
00133 RegisterAt(base::LocCtrl,"ReadInFirst",_ReadInFirst);
00134 RegisterAt(base::LocCtrl,"Time",_PhysicalTime);
00135 RegisterAt(base::LocCtrl,"TimeDelta",_TimeDelta);
00136 }
00137
00138 virtual void init() { if (_FileInput) _FileInput->init(); }
00139 virtual void update() { if (_FileInput) _FileInput->update(); }
00140 virtual void finish() { if (_FileInput) _FileInput->finish(); }
00141
00142 virtual void SetupData(GridHierarchy* gh, const int& ghosts) {
00143 base::SetupData(gh,ghosts);
00144 if (_FileInput) _FileInput->SetupData(gh,ghosts);
00145 if (_ReadInFirst!=0 && _FileInput)
00146 _FileInput->SetOutFunc((generic_func_type) 0);
00147 }
00148
00149 virtual bool Set(vec_grid_fct_type& u, grid_fct_type& work, const double& t) {
00150 if (_PhysicalTime<=0.)
00151 return base::Set(u,work,t);
00152 else if (t<_PhysicalTime-_TimeDelta || t>_PhysicalTime+_TimeDelta)
00153 return false;
00154
00155 for (int lev=0; lev<=FineLevel(base::GH()); lev++) {
00156 int Time = CurrentTime(base::GH(),lev);
00157 int TStep = TimeStep(u,lev);
00158 SwapTimeLevels(u,lev,Time,Time+TStep);
00159 SwapTimeLevels(work,lev,Time,Time+TStep);
00160 }
00161
00162 if (_FileInput && _ReadInFirst>0 && !_FileInput->GetOutFunc())
00163 _FileInput->ReadIn(u,work);
00164
00165 for (int lev=0; lev<=FineLevel(base::GH()); lev++) {
00166 int Time = CurrentTime(base::GH(),lev);
00167
00168 forall (u,Time,lev,c)
00169 base::SetGrid(u(Time,lev,c),work(Time,lev,c),lev,t);
00170 end_forall
00171
00172 BoundaryUpdate(u,Time,lev);
00173 }
00174
00175 if (_FileInput && _ReadInFirst==0) {
00176 _FileInput->ReadIn(u,work);
00177 for (int lev=0; lev<=FineLevel(base::GH()); lev++) {
00178 int Time = CurrentTime(base::GH(),lev);
00179 BoundaryUpdate(u,Time,lev);
00180 }
00181 }
00182
00183 for (int lev=0; lev<=FineLevel(base::GH()); lev++) {
00184 int Time = CurrentTime(base::GH(),lev);
00185 int TStep = TimeStep(u,lev);
00186 SwapTimeLevels(u,lev,Time,Time+TStep);
00187 SwapTimeLevels(work,lev,Time,Time+TStep);
00188 }
00189 return true;
00190 }
00191
00192 protected:
00193 int _ReadInFirst;
00194 double _PhysicalTime, _TimeDelta;
00195 file_input_type* _FileInput;
00196 level_transfer_type* _LevelTransfer;
00197 };
00198
00199 #endif
00200