00001
00002
00003
00004
00005
00006 #ifndef SCHEME_INTEGRATOR_H
00007 #define SCHEME_INTEGRATOR_H
00008
00016 #include "Integrator.h"
00017
00024 template <class SchemeType, int dim>
00025 class SchemeIntegrator : public Integrator<typename SchemeType::VectorType,dim> {
00026 typedef Integrator<typename SchemeType::VectorType,dim> base;
00027 public:
00028 typedef typename SchemeType::VectorType VectorType;
00029 typedef typename VectorType::InternalDataType DataType;
00030 typedef typename base::vec_grid_data_type vec_grid_data_type;
00031
00032 SchemeIntegrator(SchemeType &scheme) : base(), _scheme(scheme), _check(0) {
00033 FluxData = (VectorType*) 0;
00034 }
00035
00036 virtual ~SchemeIntegrator() {
00037 if (FluxData) {
00038 delete [] FluxData;
00039 FluxData = (VectorType*) 0;
00040 }
00041 }
00042
00043 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00044 ControlDevice LocCtrl = Ctrl.getSubDevice(prefix+"Integrator");
00045 RegisterAt(LocCtrl,"Check",_check);
00046 Scheme().register_at(LocCtrl,prefix);
00047 }
00048 virtual void register_at(ControlDevice& Ctrl) {
00049 register_at(Ctrl, "");
00050 }
00051 virtual void init() {
00052 base::init();
00053 Scheme().init();
00054 }
00055 virtual void update() {
00056 base::update();
00057 Scheme().update();
00058 }
00059 virtual void finish() {
00060 base::finish();
00061 Scheme().finish();
00062 }
00063
00064 virtual void SetupData(GridHierarchy* gh, const int& ghosts) {
00065 base::SetupData(gh,ghosts);
00066 base::SetMaxIntegratorPasses(NMaxPass());
00067 base::_abort = (NCheck()>=10 ? DAGHTrue : DAGHFalse);
00068 Scheme().SetupData(gh,ghosts);
00069 }
00070
00071 virtual double CalculateGrid(vec_grid_data_type& NewStateVec,
00072 vec_grid_data_type& OldStateVec,
00073 vec_grid_data_type* Flux[],
00074 const int& level, const double& t,
00075 const double& dt, const int& mpass) {
00076 if (NCheck()>0)
00077 base::CheckGrid(OldStateVec, level, OldStateVec.bbox(), t, "CalculateGrid::before Step");
00078
00079 if (NMaxPass()==0 || mpass==1)
00080 NewStateVec.copy(OldStateVec);
00081
00082 double cfl = Scheme().Step(NewStateVec,OldStateVec,Flux,t,dt,mpass);
00083
00084 if (NCheck()%10>1)
00085 base::CheckGrid(NewStateVec, level, NewStateVec.bbox(), t, "CalculateGrid::after Step");
00086
00087 return cfl;
00088 }
00089
00090 virtual void AllocGridFluxes(const BBox &bb, vec_grid_data_type**& Flux) {
00091
00092
00093 FluxData = new VectorType[base::Dim()*bb.size()];
00094 Flux = new vec_grid_data_type* [2*base::Dim()];
00095 for (register int d=0; d<base::Dim(); d++) {
00096 Flux[2*d] = new vec_grid_data_type(bb,&(FluxData[d*bb.size()]));
00097 Flux[2*d+1] = Flux[2*d];
00098 }
00099 }
00100
00101 virtual void DeAllocGridFluxes(vec_grid_data_type**& Flux) {
00102 if (Flux) {
00103 VectorType* dummy;
00104 for (register int d=0; d<base::Dim(); d++)
00105 if (Flux[2*d]) {
00106
00107 Flux[2*d]->deallocate(dummy);
00108 delete Flux[2*d];
00109 }
00110 delete [] Flux;
00111 }
00112 if (FluxData) {
00113 delete [] FluxData;
00114 FluxData = (VectorType*) 0;
00115 }
00116 }
00117
00118 virtual void ResetGridFluxes(vec_grid_data_type**& Flux) {
00119 if (Flux) {
00120 VectorType zero(0.0);
00121 for (register int d=0; d<base::Dim(); d++)
00122 if (Flux[2*d])
00123 Flux[2*d]->equals(zero);
00124 }
00125 }
00126
00127 virtual int ControlGrid(vec_grid_data_type& StateVec, const int& level,
00128 const BBox& where, const double& time, const int verbose)
00129 { return Scheme().Check(StateVec,where,time,verbose); }
00130
00131 inline const int& NCheck() const { return _check; }
00132 virtual int NMethodOrder() const { return Scheme().NMethodOrder(); }
00133 inline int NMaxPass() const { return Scheme().NMaxPass(); }
00134
00135 inline SchemeType& Scheme() { return _scheme; }
00136 inline const SchemeType& Scheme() const { return _scheme; }
00137
00138 protected:
00139 SchemeType &_scheme;
00140 int _check;
00141 VectorType* FluxData;
00142 };
00143
00144
00145 #endif
00146