AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

AMRDQFlagging.h

Go to the documentation of this file.
00001 #ifndef AMROC_AMRDQ_FLAGGING_H
00002 #define AMROC_AMRDQ_FLAGGING_H
00003 
00011 #ifndef AMRDQFlaggingName
00012 #define AMRDQFlagging(dim)      name2(AMRDQFlagging,dim)
00013 #define AMRDQFlaggingName
00014 #endif
00015 
00026 template <class VectorType, class FixupType, class FlagType>
00027 class AMRDQFlagging(DIM) : 
00028   public AMRFlaggingRel(DIM)<VectorType,FixupType,FlagType> {
00029   typedef typename VectorType::InternalDataType DataType;
00030   typedef GridData(DIM)<VectorType>   vec_grid_data_type;
00031  
00032   typedef AMRFlaggingRel(DIM)<VectorType,FixupType,FlagType> flagging_type;    
00033   typedef Solver(DIM)<VectorType,FixupType,FlagType> solver_type;    
00034 
00035 public:
00036   AMRDQFlagging(DIM)(solver_type& solver, const int quan) :
00037     flagging_type(solver), _Quantities(quan) {
00038     DQTolerance   = new DataType[NQuantities()];
00039     DQToleranceSp = new DataType[NQuantities()];
00040     for (int k=0; k<NQuantities(); k++) {
00041       DQTolerance[k]   = 0.0;
00042       DQToleranceSp[k] = 0.0;
00043     }
00044     _DQNFlags = 2*NQuantities(); 
00045     SetDQBaseFlag(flagging_type::NFlags());
00046   }
00047 
00048   ~AMRDQFlagging(DIM)() {
00049     delete [] DQTolerance;
00050     delete [] DQToleranceSp;
00051   }
00052 
00053   virtual void register_at(ControlDevice& Ctrl) {}
00054   virtual void register_at(ControlDevice& Ctrl,const string& prefix) {
00055     flagging_type::register_at(Ctrl,prefix);
00056     int d;
00057     char ToleranceName[16];
00058     for (d=0; d<NQuantities(); d++) {
00059       sprintf(ToleranceName,"DQTolGrad(%d)",d+1);
00060       RegisterAt(LocCtrl,ToleranceName,DQToleranceSp[d]);
00061       sprintf(ToleranceName,"DQTolErrEst(%d)",d+1);
00062       RegisterAt(LocCtrl,ToleranceName,DQTolerance[d]);
00063     }    
00064   }
00065   virtual void update() {
00066     flagging_type::update();
00067     bool est = ErrorEstimation();
00068     for (int k=0; k<NQuantities(); k++) 
00069       est = est || (DQTolerance[k] > 0.0);
00070     SetErrorEstimation(est);
00071   }
00072 
00073   virtual void SetFlags(const int Time, const int Level, double t, double dt) {
00074     FlagCellsByDifference(Time, Level);
00075     FlagCellsByDifferenceRel(Time, Level);
00076     FlagCellsDQByDifference(Time, Level, dt);
00077     if (ErrorEstimation() && Time>0) {
00078       //---------------------------------------------------------------
00079       // Take a step on the U(). U()(Time,Level) has to remain 
00080       // unchanged in a fractional step method!
00081       //---------------------------------------------------------------
00082       END_WATCH_FLAGGING
00083         Solver_().IntegrateLevel(U(), Time, Level, t, dt, false, 0.0, 1); 
00084       START_WATCH
00085       FlagCellsByError(Time, Level);
00086       FlagCellsByErrorRel(Time, Level);
00087       FlagCellsDQByError(Time, Level, dt);
00088     }
00089   }   
00090 
00091   virtual int NFlags() const { return (flagging_type::NFlags()+_DQNFlags); }
00092 protected:  
00093   void FlagCellsDQByDifference(const int Time, const int Level, double dt) { 
00094     
00095     if (Time < 0) return;
00096     int me = MY_PROC(GH); 
00097     int TStep = TimeStep(U(),Level);
00098     for (int k=1; k<=NQuantities(); k++) {
00099       if (DQToleranceSp[k-1] <= 0.0) continue;
00100       forall (U(),Time,Level,c)    
00101         //------------------------------------------------------------------------
00102         // Compute derived quantities from vector of state
00103         //------------------------------------------------------------------------
00104         f_dq_flag(FA(DIM,U()(Time,Level,c)), 
00105                   FA(DIM,Work()(Time,Level,c)),
00106                   FBA(Work()(Time,Level,c)),NEquations(),k,dt);
00107         Work()(Time+TStep,Level,c) = 0.0;       
00108       end_forall
00109       FlagByDifference(Time, Level, Work(), DQToleranceSp[k-1], k+DQBaseFlag());
00110 
00111       if (PlotGrad() && Solver_().LastOutputTime()==Time) {
00112         char name[DAGHBktGFNameWidth+16];
00113         sprintf(name,"dqgrad_%d_%d",k,Time); 
00114         if (Level==0 && me==VizServer) 
00115           cout << " *** Writing " << name << endl;   
00116         Write(Work(),Time+TStep,Level,DAGH_Double,name); 
00117 #ifndef DAGH_NO_MPI
00118         MPI_Barrier(comm_service::comm()); 
00119 #endif
00120       }
00121     } 
00122   }
00123 
00124   void FlagCellsDQByError(const int Time, const int Level, double dt) { 
00125     
00126     if (Time <= 0) return;
00127     int me = MY_PROC(GH); 
00128     int TStep = TimeStep(U(),Level);
00129     int ShTStep = TimeStep(Ush(),Level);
00130     int myargc = sizeof(int); int myargs = 1;
00131     DataType Order = pow(2.0, 
00132        ((flagging_type::integrator_type&)Integrator_()).NMethodOrder()+1.0) - 2.0;
00133     for (int k=1; k<=NQuantities(); k++) {
00134       if (DQTolerance[k-1] <= 0.0) continue;
00135       forall (U(),Time,Level,c)    
00136         //------------------------------------------------------------------------
00137         // Compute derived quantities from vector of state
00138         //------------------------------------------------------------------------
00139         f_dq_flag(FA(DIM,U()(Time+TStep,Level,c)), 
00140                   FA(DIM,Work()(Time+TStep,Level,c)),
00141                   FBA(Work().interiorbbox(Time+TStep,Level,c)),
00142                   NEquations(),k,dt);
00143         f_dq_flag(FA(DIM,Ush()(Time,Level,c)), 
00144                   FA(DIM,Worksh()(Time,Level,c)),
00145                   FBA(Worksh().interiorbbox(Time,Level,c)),
00146                   NEquations(),k,dt);
00147         //------------------------------------------------------------------------
00148         //       // First update Worksh() from Work()
00149         //------------------------------------------------------------------------
00150         f_restrict_amr(FA(DIM,(vec_grid_data_type &)Work()(Time+TStep,Level,c)),
00151                        FA(DIM,(vec_grid_data_type &)Worksh()(Time+ShTStep,Level,c)),
00152                        FBA(Work().interiorbbox(Time+TStep,Level,c)), 
00153                        (char *)&myargs, &myargc); 
00154         //------------------------------------------------------------------------
00155         // Estimate error by Richardson-Extrapolation
00156         //------------------------------------------------------------------------
00157         Worksh()(Time+ShTStep,Level,c).minus(Worksh()(Time,Level,c));
00158         Worksh()(Time+ShTStep,Level,c).divide(Order);
00159       end_forall
00160       FlagByErrorEstimation(Time, Level, Worksh(), DQTolerance[k-1], 
00161                             k+NQuantities()+DQBaseFlag());
00162 
00163       if (PlotErrEst() && Solver_().LastOutputTime()==Time) {
00164         char name[DAGHBktGFNameWidth+16];
00165         sprintf(name,"dqerrest_%d_%d",k,Time); 
00166         if (Level==0 && me==VizServer) 
00167           cout << " *** Writing " << name << endl;   
00168         Write(Worksh(),Time+ShTStep,Level,DAGH_Double,name); 
00169 #ifndef DAGH_NO_MPI
00170         MPI_Barrier(comm_service::comm()); 
00171 #endif
00172       }
00173     } 
00174   }
00175 
00176   inline const int& NQuantities() const { return _Quantities; }
00177   inline const int& DQBaseFlag() const { return _DQBaseFlag; }
00178   void SetDQBaseFlag(const int bf) { _DQBaseFlag = bf; }
00179 
00180 protected:
00181   DataType *DQTolerance, *DQToleranceSp;
00182   int _Quantities;
00183   int _DQBaseFlag;
00184   int _DQNFlags;
00185 };
00186 
00187 
00188 
00189 #endif


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04