00001
00002
00003
00004
00005
00006 #ifndef AMROC_F77_FILE_INITIALCONDITION_H
00007 #define AMROC_F77_FILE_INITIALCONDITION_H
00008
00016 #include "F77Interfaces/F77InitialCondition.h"
00017 #include "F77Interfaces/F77FileInput.h"
00018 #include "F77Interfaces/F77UpdateLevelTransfer.h"
00019
00032 template <class VectorType, int dim>
00033 class F77FileInitialCondition : public F77InitialCondition<VectorType,dim> {
00034 typedef F77InitialCondition<VectorType,dim> base;
00035 typedef typename VectorType::InternalDataType DataType;
00036 public:
00037 typedef F77FileInput<VectorType,dim> file_input_type;
00038 typedef F77UpdateLevelTransfer<Vector<DataType,1>, dim> level_transfer_type;
00039 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00040 typedef typename base::grid_fct_type grid_fct_type;
00041 typedef typename base::generic_func_type generic_func_type;
00042
00043 F77FileInitialCondition(generic_func_type initial) : base(initial), _ReadInFirst(0) {
00044 _FileInput = (file_input_type*) 0;
00045 _LevelTransfer = (level_transfer_type*) 0;
00046 }
00047
00048 F77FileInitialCondition(generic_func_type initial, generic_func_type in,
00049 generic_func_type prolong) : base(initial), _ReadInFirst(0) {
00050 _FileInput = (file_input_type*) 0;
00051 _LevelTransfer = (level_transfer_type*) 0;
00052 if (!in) return;
00053 _FileInput = new file_input_type(in);
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 F77FileInitialCondition(generic_func_type initial, generic_func_type out,
00061 generic_func_type in, generic_func_type prolong) :
00062 base(initial), _ReadInFirst(0) {
00063 _FileInput = (file_input_type*) 0;
00064 _LevelTransfer = (level_transfer_type*) 0;
00065 if (!out || !in) return;
00066 _FileInput = new file_input_type(out,in);
00067 if (prolong)
00068 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00069 (new level_transfer_type(prolong, (generic_func_type) 0,
00070 (generic_func_type) 0)));
00071 }
00072
00073 F77FileInitialCondition(generic_func_type initial, generic_func_type out,
00074 generic_func_type in, generic_func_type prolong, generic_func_type update) :
00075 base(initial), _ReadInFirst(0) {
00076 _FileInput = (file_input_type*) 0;
00077 _LevelTransfer = (level_transfer_type*) 0;
00078 if (!out || !in) return;
00079 _FileInput = new file_input_type(out,in);
00080 if (prolong)
00081 if (!update)
00082 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00083 (new level_transfer_type(prolong, (generic_func_type) 0,
00084 (generic_func_type) 0)));
00085 else
00086 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00087 (new level_transfer_type(prolong, (generic_func_type) 0, update)));
00088 }
00089
00090 virtual ~F77FileInitialCondition() {
00091 if (_FileInput) delete _FileInput;
00092 if (_LevelTransfer) delete _LevelTransfer;
00093 }
00094
00095 virtual void register_at(ControlDevice& Ctrl) { base::register_at(Ctrl); }
00096 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00097 base::register_at(Ctrl,prefix);
00098 if (_FileInput) _FileInput->register_at(base::LocCtrl, "");
00099 RegisterAt(base::LocCtrl,"ReadInFirst",_ReadInFirst);
00100 }
00101
00102 virtual void init() { if (_FileInput) _FileInput->init(); }
00103 virtual void update() { if (_FileInput) _FileInput->update(); }
00104 virtual void finish() { if (_FileInput) _FileInput->finish(); }
00105
00106 virtual void SetupData(GridHierarchy* gh, const int& ghosts) {
00107 base::SetupData(gh,ghosts);
00108 if (_FileInput) _FileInput->SetupData(gh,ghosts);
00109 if (_ReadInFirst!=0 && _FileInput)
00110 _FileInput->SetOutFunc((generic_func_type) 0);
00111 }
00112
00113 virtual void Set(vec_grid_fct_type& u, grid_fct_type& work, const int Level) {
00114 SetPhysicalTime(u,0,Level,0.0);
00115
00116 if (_FileInput && _ReadInFirst>0 && !_FileInput->GetOutFunc())
00117 _FileInput->ReadIn(u,work);
00118
00119 forall (u,0,Level,c)
00120 SetGrid(u(0,Level,c),Level);
00121 end_forall
00122
00123 if (_FileInput && _ReadInFirst==0) {
00124 BoundaryUpdate(u,0,Level);
00125 _FileInput->ReadIn(u,work);
00126 }
00127
00128 BoundaryUpdate(u,0,Level);
00129 }
00130
00131 protected:
00132 int _ReadInFirst;
00133 file_input_type* _FileInput;
00134 level_transfer_type* _LevelTransfer;
00135 };
00136
00137 #endif
00138