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 dtc, const double dtf,
00087 const int& mdim) = 0;
00088 virtual void Correction(const int Time, const int WTime, const int Level,
00089 const double t, const double d) = 0;
00090
00091
00092 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00093 base::LocCtrl = Ctrl.getSubDevice(prefix+"FixupBase");
00094 }
00095 virtual void register_at(ControlDevice& Ctrl) { register_at(Ctrl,""); }
00096 virtual void finish() {
00097 for (int d=0; d<dim; d++) {
00098 if (_f[2*d]) {
00099 delete _f[2*d];
00100 _f[2*d] = (ld_fixup_grid_fct_type *) 0;
00101 }
00102 if (_f_name[2*d]) {
00103 delete [] _f_name[2*d];
00104 _f_name[2*d] = (char *) 0;
00105 }
00106 if (_f[2*d+1]) {
00107 delete _f[2*d+1];
00108 _f[2*d+1] = (ld_fixup_grid_fct_type *) 0;
00109 }
00110 if (_f_name[2*d+1]) {
00111 delete [] _f_name[2*d+1];
00112 _f_name[2*d+1] = (char *) 0;
00113 }
00114 }
00115 }
00116
00117 virtual void SetupData(GridHierarchy* gh, const int& ghosts) {
00118 base::SetupData(gh, ghosts);
00119 int t_sten = 0;
00120 int s_sten = 0;
00121 AllocError::SetTexts("FixupBase","allocation of GridFunctions");
00122 int DAGH_Base = DAGH_X;
00123 if (dim == 2) DAGH_Base = DAGH_Y;
00124 if (dim == 3) DAGH_Base = DAGH_YZ;
00125
00126 for (int d=0; d<dim; d++) {
00127 _f_name[2*d] = new char[DAGHBktGFNameWidth];
00128 sprintf(_f_name[2*d],"f_lower");
00129 _f[2*d] = new ld_fixup_grid_fct_type(_f_name[2*d], t_sten, s_sten, base::GH(),
00130 DAGHCellCentered, 1, 1, DAGH_Base-d,
00131 DAGHNoComm, DAGHNoBoundary,
00132 DAGHNoAdaptBoundary, DAGHNoExternalGhost);
00133 SetProlongFlag(F(2*d), DAGHFalse);
00134 SetCheckpointFlag(F(2*d), DAGHFalse);
00135
00136 _f_name[2*d+1] = new char[DAGHBktGFNameWidth];
00137 sprintf(_f_name[2*d+1],"f_upper");
00138 _f[2*d+1] = new ld_fixup_grid_fct_type(_f_name[2*d+1], t_sten, s_sten, base::GH(),
00139 DAGHCellCentered, 1, 1, (DAGH_Base-d) | DAGH_Dim1ToTop,
00140 DAGHNoComm, DAGHNoBoundary,
00141 DAGHNoAdaptBoundary, DAGHNoExternalGhost);
00142 SetProlongFlag(F(2*d+1), DAGHFalse);
00143 SetCheckpointFlag(F(2*d+1), DAGHFalse);
00144 }
00145
00146 SetMaxRecomposeLevel(DAGHNull);
00147 }
00148
00149 void SetMaxRecomposeLevel(const int l) {
00150 for (int d=0; d<dim; d++) {
00151 if (_f[2*d]) F(2*d).GF_SetMaxRecomposeLevel(l);
00152 if (_f[2*d+1]) F(2*d+1).GF_SetMaxRecomposeLevel(l);
00153 }
00154 }
00155
00156 inline ld_fixup_grid_fct_type& F(int d) {
00157 #ifdef DEBUG_PRINT
00158 assert(d>=0 && d<2*dim);
00159 #endif
00160 return *_f[d];
00161 }
00162
00163 inline const ld_fixup_grid_fct_type& F(int d) const {
00164 #ifdef DEBUG_PRINT
00165 assert(d>=0 && d<2*dim);
00166 #endif
00167 return *_f[d];
00168 }
00169
00170 inline const int& NFixupEquations() { return _FixupEquations; }
00171
00172 protected:
00173 int _FixupEquations;
00174 ld_fixup_grid_fct_type* _f[2*dim];
00175 char *_f_name[2*dim];
00176 };
00177
00178 template <class VectorType, class FixupType, int dim> class FixupOps;
00179 template <class VectorType, class FixupType, int dim> class Fixup;
00180
00181 #endif