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,
00075 generic_func_type restrct) :
00076 base(initial), _ReadInFirst(0) {
00077 _FileInput = (file_input_type*) 0;
00078 _LevelTransfer = (level_transfer_type*) 0;
00079 if (!out || !in) return;
00080 _FileInput = new file_input_type(out,in);
00081 if (prolong) {
00082 if (!restrct)
00083 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00084 (new level_transfer_type(prolong, (generic_func_type) 0,
00085 (generic_func_type) 0)));
00086 else
00087 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00088 (new level_transfer_type(prolong, restrct, (generic_func_type) 0)));
00089 }
00090 }
00091
00092 F77FileInitialCondition(generic_func_type initial, generic_func_type out,
00093 generic_func_type in, generic_func_type prolong,
00094 generic_func_type restrct, generic_func_type update) :
00095 base(initial), _ReadInFirst(0) {
00096 _FileInput = (file_input_type*) 0;
00097 _LevelTransfer = (level_transfer_type*) 0;
00098 if (!out || !in) return;
00099 _FileInput = new file_input_type(out,in);
00100 if (prolong) {
00101 if (!restrct) {
00102 if (!update)
00103 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00104 (new level_transfer_type(prolong, (generic_func_type) 0,
00105 (generic_func_type) 0)));
00106 else
00107 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00108 (new level_transfer_type(prolong, (generic_func_type) 0, update)));
00109 }
00110 else {
00111 if (!update)
00112 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00113 (new level_transfer_type(prolong, restrct, (generic_func_type) 0)));
00114 else
00115 _FileInput->SetLevelTransfer((typename file_input_type::leveltransfer_type*)
00116 (new level_transfer_type(prolong, restrct, update)));
00117 }
00118 }
00119 }
00120
00121 virtual ~F77FileInitialCondition() {
00122 if (_FileInput) delete _FileInput;
00123 if (_LevelTransfer) delete _LevelTransfer;
00124 }
00125
00126 virtual void register_at(ControlDevice& Ctrl) { base::register_at(Ctrl); }
00127 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00128 base::register_at(Ctrl,prefix);
00129 if (_FileInput) _FileInput->register_at(base::LocCtrl, "");
00130 RegisterAt(base::LocCtrl,"ReadInFirst",_ReadInFirst);
00131 }
00132
00133 virtual void init() { if (_FileInput) _FileInput->init(); }
00134 virtual void update() { if (_FileInput) _FileInput->update(); }
00135 virtual void finish() { if (_FileInput) _FileInput->finish(); }
00136
00137 virtual void SetupData(GridHierarchy* gh, const int& ghosts) {
00138 base::SetupData(gh,ghosts);
00139 if (_FileInput) _FileInput->SetupData(gh,ghosts);
00140 if (_ReadInFirst!=0 && _FileInput)
00141 _FileInput->SetOutFunc((generic_func_type) 0);
00142 }
00143
00144 virtual void Set(vec_grid_fct_type& u, grid_fct_type& work, const int Level) {
00145 SetPhysicalTime(u,0,Level,0.0);
00146
00147 if (_FileInput && _ReadInFirst>0 && !_FileInput->GetOutFunc())
00148 _FileInput->ReadIn(u,work);
00149
00150 forall (u,0,Level,c)
00151 base::SetGrid(u(0,Level,c),work(0,Level,c),Level);
00152 end_forall
00153
00154 if (_FileInput && _ReadInFirst==0) {
00155 BoundaryUpdate(u,0,Level);
00156 _FileInput->ReadIn(u,work);
00157 }
00158
00159 BoundaryUpdate(u,0,Level);
00160 }
00161
00162 protected:
00163 int _ReadInFirst;
00164 file_input_type* _FileInput;
00165 level_transfer_type* _LevelTransfer;
00166 };
00167
00168 #endif
00169