00001
00002
00003
00004
00005
00006 #ifndef LBM_FILE_EXACTSOLUTION_H
00007 #define LBM_FILE_EXACTSOLUTION_H
00008
00016 #include "LBMExactSolution.h"
00017 #include "Interfaces/SchemeFileInput.h"
00018 #include "LBMLevelTransfer.h"
00019
00030 template <class LBMType, int dim>
00031 class LBMF77FileExactSolution : public LBMExactSolution<LBMType,dim> {
00032 typedef LBMExactSolution<LBMType,dim> base;
00033 typedef typename LBMType::MicroType MicroType;
00034 typedef typename MicroType::InternalDataType DataType;
00035 public:
00036 typedef SchemeFileInput<LBMType,dim> file_input_type;
00037 typedef F77LevelTransfer<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 level_transfer_type::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 LBMF77FileExactSolution(LBMType &lbm) :
00045 base(lbm), _ReadInFirst(0), _PhysicalTime(0.0), _TimeDelta(0.0) {
00046 _FileInput = new file_input_type(lbm);
00047 _LevelTransfer = (level_transfer_type*) 0;
00048 }
00049
00050 LBMF77FileExactSolution(LBMType &lbm, generic_func_type prolong) :
00051 base(lbm), _ReadInFirst(0), _PhysicalTime(0.0), _TimeDelta(0.0) {
00052 _FileInput = new file_input_type(lbm);
00053 _LevelTransfer = (level_transfer_type*) 0;
00054 if (prolong)
00055 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00056 (new level_transfer_type(prolong, (generic_func_type) 0,
00057 (generic_func_type) 0)));
00058 }
00059
00060 LBMF77FileExactSolution(LBMType &lbm, generic_func_type prolong, generic_func_type restrct) :
00061 base(lbm), _ReadInFirst(0), _PhysicalTime(0.0), _TimeDelta(0.0) {
00062 _FileInput = new file_input_type(lbm);
00063 _LevelTransfer = (level_transfer_type*) 0;
00064 if (prolong) {
00065 if (!restrct)
00066 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00067 (new level_transfer_type(prolong, (generic_func_type) 0)));
00068 else
00069 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00070 (new level_transfer_type(prolong, restrct)));
00071 }
00072 }
00073
00074 virtual ~LBMF77FileExactSolution() {
00075 if (_FileInput) delete _FileInput;
00076 if (_LevelTransfer) delete _LevelTransfer;
00077 }
00078
00079 virtual void register_at(ControlDevice& Ctrl) { base::register_at(Ctrl); }
00080 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00081 base::register_at(Ctrl,prefix);
00082 if (_FileInput) _FileInput->register_at(base::LocCtrl, "");
00083 RegisterAt(base::LocCtrl,"ReadInFirst",_ReadInFirst);
00084 RegisterAt(base::LocCtrl,"Time",_PhysicalTime);
00085 RegisterAt(base::LocCtrl,"TimeDelta",_TimeDelta);
00086 }
00087
00088 virtual void init() { if (_FileInput) _FileInput->init(); }
00089 virtual void update() { if (_FileInput) _FileInput->update(); }
00090 virtual void finish() { if (_FileInput) _FileInput->finish(); }
00091
00092 virtual void SetupData(GridHierarchy* gh, const int& ghosts) {
00093 base::SetupData(gh,ghosts);
00094 if (_FileInput) _FileInput->SetupData(gh,ghosts);
00095 }
00096
00097 virtual bool Set(vec_grid_fct_type& u, grid_fct_type& work, const double& t) {
00098
00099
00100 if (_PhysicalTime<=0.)
00101 return base::Set(u,work,t);
00102 else if (t<_PhysicalTime-_TimeDelta || t>_PhysicalTime+_TimeDelta)
00103 return false;
00104
00105 for (int lev=0; lev<=FineLevel(base::GH()); lev++) {
00106 int Time = CurrentTime(base::GH(),lev);
00107 int TStep = TimeStep(u,lev);
00108 SwapTimeLevels(u,lev,Time,Time+TStep);
00109 SwapTimeLevels(work,lev,Time,Time+TStep);
00110 }
00111
00112 if (_FileInput && _ReadInFirst>0)
00113 _FileInput->ReadIn(u,work);
00114
00115 for (int lev=0; lev<=FineLevel(base::GH()); lev++) {
00116 int Time = CurrentTime(base::GH(),lev);
00117
00118 forall (u,Time,lev,c)
00119 base::SetGrid(u(Time,lev,c),work(Time,lev,c),lev,t);
00120 end_forall
00121
00122 BoundaryUpdate(u,Time,lev);
00123 }
00124
00125 if (_FileInput && _ReadInFirst==0) {
00126 _FileInput->ReadIn(u,work);
00127 for (int lev=0; lev<=FineLevel(base::GH()); lev++) {
00128 int Time = CurrentTime(base::GH(),lev);
00129 BoundaryUpdate(u,Time,lev);
00130 }
00131 }
00132
00133 for (int lev=0; lev<=FineLevel(base::GH()); lev++) {
00134 int Time = CurrentTime(base::GH(),lev);
00135 int TStep = TimeStep(u,lev);
00136 SwapTimeLevels(u,lev,Time,Time+TStep);
00137 SwapTimeLevels(work,lev,Time,Time+TStep);
00138 }
00139 return true;
00140 }
00141
00142 protected:
00143 int _ReadInFirst;
00144 double _PhysicalTime, _TimeDelta;
00145 file_input_type* _FileInput;
00146 level_transfer_type* _LevelTransfer;
00147 };
00148
00149 #endif
00150