00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef AMROC_FIXUP_BASE_H
00010 #define AMROC_FIXUP_BASE_H
00011
00019 #include "GridFunction.h"
00020 #include <string>
00021 #include "AMRBase.h"
00022
00023 template <int dim> class minus_1;
00024
00025 template <> class minus_1<1> {
00026 public:
00027 static const int dim = 1;
00028 };
00029
00030 template <> class minus_1<2> {
00031 public:
00032 static const int dim = 1;
00033 };
00034
00035 template <> class minus_1<3> {
00036 public:
00037 static const int dim = 2;
00038 };
00039
00040
00049 template <class VectorType, class FixupType, int dim>
00050 class FixupBase : public AMRBase<VectorType,dim> {
00051 typedef AMRBase<VectorType,dim> base;
00052 public:
00053 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00054 typedef typename base::vec_grid_data_type vec_grid_data_type;
00055
00056 typedef GridData<VectorType,minus_1<dim>::dim> ld_vec_grid_data_type;
00057 typedef GridData<FixupType,minus_1<dim>::dim> ld_fixup_grid_data_type;
00058 typedef GridFunction<FixupType,minus_1<dim>::dim> ld_fixup_grid_fct_type;
00059
00060 FixupBase() : base(), _FixupEquations(FixupType::Length()) {
00061 for (int d=0; d<dim; d++) {
00062 _f[2*d] = (ld_fixup_grid_fct_type *) 0;
00063 _f[2*d+1] = (ld_fixup_grid_fct_type *) 0;
00064 _f_name[2*d] = (char *) 0;
00065 _f_name[2*d+1] = (char *) 0;
00066 }
00067 }
00068
00069 virtual ~FixupBase() {
00070 for (int d=0; d<dim; d++) {
00071 if (_f[2*d]) delete _f[2*d];
00072 if (_f_name[2*d]) delete [] _f_name[2*d];
00073 if (_f[2*d+1]) delete _f[2*d+1];
00074 if (_f_name[2*d+1]) delete [] _f_name[2*d+1];
00075 }
00076 }
00077
00078
00079
00080
00081 virtual void SaveFluxes(const int Time, const int Level, const int c,
00082 vec_grid_data_type* flux[], const double dt,
00083 const int& mdim) = 0;
00084 virtual void AddFluxes(const int Time, const int Level, const int c,
00085 vec_grid_data_type* flux[], const double tc,
00086 const double tf, const double dt, const int& mdim) = 0;
00087 virtual void Correction(const int Time, const int WTime, const int Level) = 0;
00088
00089
00090 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00091 base::LocCtrl = Ctrl.getSubDevice(prefix+"FixupBase");
00092 }
00093 virtual void register_at(ControlDevice& Ctrl) { register_at(Ctrl,""); }
00094 virtual void finish() {
00095 for (int d=0; d<dim; d++) {
00096 if (_f[2*d]) {
00097 delete _f[2*d];
00098 _f[2*d] = (ld_fixup_grid_fct_type *) 0;
00099 }
00100 if (_f_name[2*d]) {
00101 delete [] _f_name[2*d];
00102 _f_name[2*d] = (char *) 0;
00103 }
00104 if (_f[2*d+1]) {
00105 delete _f[2*d+1];
00106 _f[2*d+1] = (ld_fixup_grid_fct_type *) 0;
00107 }
00108 if (_f_name[2*d+1]) {
00109 delete [] _f_name[2*d+1];
00110 _f_name[2*d+1] = (char *) 0;
00111 }
00112 }
00113 }
00114
00115 virtual void SetupData(GridHierarchy* gh, const int& ghosts) {
00116 base::SetupData(gh, ghosts);
00117 int t_sten = 0;
00118 int s_sten = 0;
00119 AllocError::SetTexts("FixupBase","allocation of GridFunctions");
00120 int DAGH_Base = DAGH_X;
00121 if (dim == 2) DAGH_Base = DAGH_Y;
00122 if (dim == 3) DAGH_Base = DAGH_YZ;
00123
00124 for (int d=0; d<dim; d++) {
00125 _f_name[2*d] = new char[DAGHBktGFNameWidth];
00126 sprintf(_f_name[2*d],"f_lower");
00127 _f[2*d] = new ld_fixup_grid_fct_type(_f_name[2*d], t_sten, s_sten, base::GH(),
00128 DAGHCellCentered, 1, 1, DAGH_Base-d,
00129 DAGHNoComm, DAGHNoBoundary,
00130 DAGHNoAdaptBoundary, DAGHNoExternalGhost);
00131 SetProlongFlag(F(2*d), DAGHFalse);
00132 SetCheckpointFlag(F(2*d), DAGHFalse);
00133
00134 _f_name[2*d+1] = new char[DAGHBktGFNameWidth];
00135 sprintf(_f_name[2*d+1],"f_upper");
00136 _f[2*d+1] = new ld_fixup_grid_fct_type(_f_name[2*d+1], t_sten, s_sten, base::GH(),
00137 DAGHCellCentered, 1, 1, (DAGH_Base-d) | DAGH_Dim1ToTop,
00138 DAGHNoComm, DAGHNoBoundary,
00139 DAGHNoAdaptBoundary, DAGHNoExternalGhost);
00140 SetProlongFlag(F(2*d+1), DAGHFalse);
00141 SetCheckpointFlag(F(2*d+1), DAGHFalse);
00142 }
00143
00144 SetMaxRecomposeLevel(DAGHNull);
00145 }
00146
00147 void SetMaxRecomposeLevel(const int l) {
00148 for (int d=0; d<dim; d++) {
00149 F(2*d).GF_SetMaxRecomposeLevel(l);
00150 F(2*d+1).GF_SetMaxRecomposeLevel(l);
00151 }
00152 }
00153
00154 inline ld_fixup_grid_fct_type& F(int d) {
00155 #ifdef DEBUG_PRINT
00156 assert(d>=0 && d<2*dim);
00157 #endif
00158 return *_f[d];
00159 }
00160
00161 inline const ld_fixup_grid_fct_type& F(int d) const {
00162 #ifdef DEBUG_PRINT
00163 assert(d>=0 && d<2*dim);
00164 #endif
00165 return *_f[d];
00166 }
00167
00168 inline const int& NFixupEquations() { return _FixupEquations; }
00169
00170 protected:
00171 int _FixupEquations;
00172 ld_fixup_grid_fct_type* _f[2*dim];
00173 char *_f_name[2*dim];
00174 };
00175
00176 template <class VectorType, class FixupType, int dim> class FixupOps;
00177 template <class VectorType, class FixupType, int dim> class Fixup;
00178
00179 #endif