vtf-logo

Flagging.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2002 Ralf Deiterding
00004 // Brandenburgische Universitaet Cottbus
00005 //
00006 // Copyright (C) 2003-2007 California Institute of Technology
00007 // Ralf Deiterding, ralf@amroc.net
00008 
00009 #ifndef AMROC_FLAGGING_H
00010 #define AMROC_FLAGGING_H
00011 
00019 #include <string>
00020 #include "Criterion.h"
00021 #include "AMRBase.h"
00022 
00023 template <class VectorType, class FixupType, class FlagType, int dim> class AMRSolverBase;
00024 
00025 #define GoodPoint (0)
00026 #define BadPoint  (1)
00027 #define VizServer 0                                               
00028 
00036 template <class VectorType, class FlagType, int dim>
00037 class Flagging : public AMRBase<VectorType,dim> {
00038   typedef AMRBase<VectorType,dim> base;
00039   typedef typename VectorType::InternalDataType DataType;
00040 public:
00041   typedef GridFunction<FlagType,dim> flag_fct_type;
00042   typedef Criterion<VectorType,FlagType,dim> criterion_type;
00043 
00044   Flagging() : base(), _ncrit(0), _Bufferwidth(2) {    
00045     _crit = (criterion_type**) 0;
00046     _flag = (flag_fct_type *) 0; 
00047   }
00048 
00049   virtual ~Flagging() {
00050     if (_flag) delete _flag;
00051     if (_crit) delete [] _crit;
00052   }
00053 
00054   //******************************************************************************
00055   // Abstract class interface
00056   //******************************************************************************
00057   virtual void SetFlags(const int Time, const int Level, double t, double dt) = 0;   
00058   //******************************************************************************
00059 
00060   virtual void register_at(ControlDevice& Ctrl) {}
00061   virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00062     base::LocCtrl = Ctrl.getSubDevice(prefix+"Flagging");
00063     for (register int n=0; n<NCrit(); n++) 
00064       Criterion_(n).register_at(base::LocCtrl,"");
00065   }
00066 
00067   virtual void init() {
00068     base::init();
00069     for (register int n=0; n<NCrit(); n++) 
00070       Criterion_(n).init();
00071   }
00072   virtual void update() {
00073     base::update();
00074     for (register int n=0; n<NCrit(); n++) 
00075       Criterion_(n).update();
00076   }
00077   virtual void finish() {
00078     base::finish();
00079     for (register int n=0; n<NCrit(); n++) 
00080       Criterion_(n).finish();
00081     if (_flag) {
00082       delete _flag;
00083       _flag = (flag_fct_type *) 0; 
00084     }
00085   }
00086 
00087   virtual void SetupData(GridHierarchy* gh, const int& ghosts) {
00088     base::SetupData(gh, ghosts);
00089     for (register int n=0; n<NCrit(); n++)
00090       Criterion_(n).SetupData(gh, ghosts);
00091     int t_sten = 0;            
00092     int s_sten = Bufferwidth(); 
00093     sprintf(flagName,"Flags");
00094     _flag = new flag_fct_type(flagName, t_sten, s_sten, base::GH(), DAGHCellCentered,
00095                               DAGHCommSimple, DAGHNoBoundary, DAGHNoAdaptBoundary,
00096                               DAGHNoExternalGhost);
00097     SetCheckpointFlag(*_flag, DAGHFalse);   
00098     SetProlongFlag(*_flag, DAGHFalse);   
00099     _flag->GF_SetMaxRecomposeLevel(DAGHNull);
00100   }    
00101 
00102   void AddCriterion(criterion_type* crit) {
00103     if (crit) {
00104       criterion_type** _crit_new = new criterion_type*[_ncrit+1];
00105       if (_crit) {
00106         for (register int n=0; n<_ncrit; n++)
00107           _crit_new[n] = _crit[n];
00108         delete [] _crit;
00109       }
00110       _crit = _crit_new;
00111       _crit[_ncrit] = crit;
00112       _ncrit++;
00113     }
00114   }
00115 
00116   void EliminateCriterion(criterion_type* crit) {
00117     if (crit) {
00118       int c=0;
00119       for (register int n=0; n<_ncrit; n++)
00120         if (_crit[n] == crit) c++;
00121       if (c>0) {
00122         criterion_type** _crit_new = (criterion_type**) 0;
00123         if (_ncrit-c>0) {
00124           _crit_new = new criterion_type*[_ncrit-c];
00125           for (register int n=0, m=0; n<_ncrit; n++)
00126             if (_crit[n] != crit) 
00127               _crit_new[m++] = _crit[n];
00128         }
00129         delete [] _crit;
00130         _crit = _crit_new;
00131         _ncrit = _ncrit-c;
00132       }
00133     }
00134   }
00135 
00136   void DeleteCriterion(criterion_type* crit) {
00137     EliminateCriterion(crit);
00138     if (crit) delete crit;
00139   }
00140 
00141   void DeleteAllCriterions() {
00142     while (NCrit()>0)
00143       DeleteCriterion(_crit[0]);
00144   }
00145 
00146   inline criterion_type* CriterionP(const int n) { assert (n>=0 && n<_ncrit); return _crit[n]; }
00147   inline criterion_type& Criterion_(const int n) { assert (n>=0 && n<_ncrit); return *(_crit[n]); }
00148   inline const criterion_type& Criterion_(const int n) const { assert (n>=0 && n<_ncrit); return *(_crit[n]); }
00149   inline const int& NCrit() const { return _ncrit; }
00150 
00151   void SetBufferwidth(const int buffw) { _Bufferwidth = buffw; }
00152   inline const int& Bufferwidth() const { return _Bufferwidth; }
00153   inline int Bufferwidth() { return _Bufferwidth; }
00154 
00155   inline flag_fct_type& Flags() { return *_flag; }
00156   inline const flag_fct_type& Flags() const { return *_flag; }
00157 
00158 protected:
00159   criterion_type** _crit;
00160   int _ncrit;
00161   flag_fct_type* _flag;
00162   char flagName[DAGHBktGFNameWidth];
00163   int _Bufferwidth;
00164 };
00165 
00166 
00167 #endif

Generated on Fri Aug 24 13:00:50 2007 for AMROC Fluid-solver Framework - by  doxygen 1.4.7