vtf-logo

GhostFluidMethod.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_GHOSTFLUIDMETHOD_H
00010 #define AMROC_GHOSTFLUIDMETHOD_H
00011 
00019 #include "GFMBoundary.h"
00020 #include "GFMLevelSet.h"
00021 #include "AMRBase.h"
00022 
00030 template <class VectorType, int dim>
00031 class GhostFluidMethod : public AMRBase<VectorType,dim> {
00032   typedef typename VectorType::InternalDataType DataType;
00033   typedef AMRBase<VectorType,dim> base;
00034 public:
00035   typedef typename base::vec_grid_fct_type vec_grid_fct_type;  
00036   typedef GridFunction<DataType,dim> grid_fct_type;   
00037   typedef GridFunction<bool,dim> bool_grid_fct_type;  
00038 
00039   typedef GFMBoundary<VectorType,dim> boundary_type;
00040   typedef GFMLevelSet<DataType,dim> levelset_type;
00041   typedef BoundaryConditions<DataType,dim> boundary_conditions_type;
00042 
00043   typedef GFBndryUpdateSpecificFunc<boundary_conditions_type,DataType,dim> boundary_functor_type;
00044 
00045   GhostFluidMethod(boundary_type* boundary, levelset_type* levelset) : 
00046     _Boundary(boundary), _LevelSet(levelset), _EstimateError(false), _Ignore(0) {      
00047     _BoundaryConditions = (boundary_conditions_type*) 0; 
00048     _phi = (grid_fct_type *) 0; 
00049     _phi_sh = (grid_fct_type *) 0; 
00050     _BoundaryFunc = (boundary_functor_type *) 0;
00051     _myprefix = "";
00052   }
00053 
00054   GhostFluidMethod(boundary_type* boundary, levelset_type* levelset, 
00055                    boundary_conditions_type* boundary_conditions) : 
00056     _Boundary(boundary), _LevelSet(levelset), 
00057     _BoundaryConditions(boundary_conditions),
00058     _EstimateError(false), _Ignore(0)  {      
00059     _phi = (grid_fct_type *) 0; 
00060     _phi_sh = (grid_fct_type *) 0; 
00061     _BoundaryFunc = (boundary_functor_type *) 0;
00062     _myprefix = "";
00063   }
00064 
00065   virtual ~GhostFluidMethod() {
00066     if (_phi) delete _phi;
00067     if (_phi_sh) delete _phi_sh;
00068     if (_BoundaryFunc) delete _BoundaryFunc;
00069   }
00070 
00071   virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00072     _myprefix = prefix;
00073     base::LocCtrl = Ctrl.getSubDevice(prefix+"GFM");    
00074     RegisterAt(base::LocCtrl,"Ignore",_Ignore);
00075     LevelSet().register_at(base::LocCtrl,"");
00076     Boundary().register_at(base::LocCtrl,"");
00077   } 
00078   virtual void register_at(ControlDevice& Ctrl) {
00079     register_at(Ctrl, "");
00080   }
00081 
00082   virtual void init() {
00083     LevelSet().init();
00084     Boundary().init(); 
00085   }
00086   virtual void update() {
00087     LevelSet().update();
00088     Boundary().update(); 
00089   }
00090   virtual void finish() {
00091     if (_phi) {
00092       delete _phi;
00093       _phi = (grid_fct_type *) 0; 
00094     }
00095     if (_phi_sh) {
00096       delete _phi_sh;
00097       _phi_sh = (grid_fct_type *) 0; 
00098     }
00099     LevelSet().finish();
00100     Boundary().finish(); 
00101   } 
00102 
00103   virtual void SetupData(GridHierarchy* gh, const int& ghosts) {
00104     base::SetupData(gh, ghosts);
00105     LevelSet().SetupData(gh, ghosts);
00106     Boundary().SetupData(gh, ghosts);
00107     int t_sten = 1;            
00108     int s_sten = base::NGhosts(); 
00109     std::sprintf(phiName,"%sphi",_myprefix.c_str());
00110     _phi = new grid_fct_type(phiName, t_sten, s_sten, base::GH(), DAGHCellCentered,
00111                              DAGHCommSimple, DAGHNoBoundary, DAGHNoAdaptBoundary,
00112                              DAGHNoExternalGhost);
00113     if (Stationary()) { SetTimeAlias(*_phi, 1, 0); SetTimeAlias(*_phi, -1, 0); }
00114     else SetTimeAlias(*_phi, -1, 1);
00115     SetCheckpointFlag(*_phi, DAGHTrue);
00116     if (_BoundaryConditions) 
00117       _BoundaryFunc = new boundary_functor_type(_BoundaryConditions, 
00118                                                 &boundary_conditions_type::SetBndry);
00119     SetProlongFlag(*_phi, DAGHFalse);   
00120     if (_BoundaryFunc) {
00121       _phi->GF_SetBndryUpdateFlag(DAGHTrue);
00122       _phi->GF_SetBoundaryType(DAGHBoundaryUserDef);
00123       _phi->GF_SetBndryUpdateFunc(_BoundaryFunc);
00124     }
00125 
00126     if (ErrorEstimation()) {
00127       std::sprintf(phiNamesh,"%sphish",_myprefix.c_str()); 
00128       _phi_sh = new grid_fct_type(phiNamesh, t_sten, s_sten, base::GH(), DAGHCellCentered, 0, 
00129                                   DAGHShadowFactor, DAGH_All, DAGHCommSimple, 
00130                                   DAGHNoBoundary, DAGHNoAdaptBoundary, DAGHNoExternalGhost);
00131       if (Stationary()) { SetTimeAlias(*_phi_sh, 1, 0); SetTimeAlias(*_phi_sh, -1, 0); }
00132       else SetTimeAlias(*_phi_sh, -1, 1);
00133       SetCheckpointFlag(*_phi_sh, DAGHTrue);
00134       SetProlongFlag(*_phi_sh, DAGHFalse);   
00135       if (_BoundaryFunc) {
00136         _phi_sh->GF_SetBndryUpdateFlag(DAGHTrue);
00137         _phi_sh->GF_SetBoundaryType(DAGHBoundaryUserDef);
00138         _phi_sh->GF_SetBndryUpdateFunc(_BoundaryFunc);
00139       }
00140     }   
00141   }
00142 
00143   virtual void SetLevelSet(vec_grid_fct_type& u, const int Time, 
00144                            const int Level, double t) {
00145     START_WATCH
00146       forall (Phi(u),Time,Level,c)  
00147         Phi(u)(Time,Level,c) = DataType(0.0);
00148       end_forall    
00149     END_WATCH(LS_SET_WHOLE)
00150     if (_Ignore) {
00151       START_WATCH
00152         forall (Phi(u),Time,Level,c)  
00153           Phi(u)(Time,Level,c) = Boundary().FarAway();
00154         end_forall    
00155       END_WATCH(LS_SET_WHOLE)
00156       return;
00157     }
00158 #ifdef DEBUG_PRINT_AMRSOLVER
00159       ( comm_service::log() <<  "  *** Setting level set: Level " << Level << 
00160         "  Time = " << Time << "  t = " << t << "\n" ).flush();
00161 #endif
00162     START_WATCH
00163       LevelSet().SetPhi(Phi(u),Time,Level,t);
00164     END_WATCH(LS_SET_WHOLE)
00165   }   
00166 
00167   virtual void SetBndry(vec_grid_fct_type& u, bool_grid_fct_type& bf, 
00168                         const int Time, const int Level, 
00169                         double t, bool extrapolate=false) {
00170     if (_Ignore) return;
00171 #ifdef DEBUG_PRINT_AMRSOLVER
00172     ( comm_service::log() <<  "  *** Setting GFM bndry: Level " << Level << 
00173       "  Time = " << Time << "  t = " << t << "\n" ).flush();
00174 #endif
00175     Boundary().SetPhysbd(u,Phi(u),bf,Time,Level,t,extrapolate); 
00176   }   
00177 
00178   void SetMaxRecomposeLevel(const int l) {
00179     Phi().GF_SetMaxRecomposeLevel(l);
00180     if (ErrorEstimation()) 
00181       Phish().GF_SetMaxRecomposeLevel(l);
00182   }
00183 
00184   inline bool IsUsed() const { return (_Ignore==0); }
00185   inline const int& Stationary() const { return LevelSet().Stationary(); }
00186   inline grid_fct_type& Phi() { return *_phi; }
00187   inline const grid_fct_type& Phi() const { return *_phi; }
00188   inline grid_fct_type& Phish() { return *_phi_sh; }
00189   inline const grid_fct_type& Phish() const { return *_phi_sh; }
00190   inline grid_fct_type& Phi(vec_grid_fct_type& u) 
00191   { return (&u==_u_sh ? *_phi_sh : *_phi); }
00192   inline const grid_fct_type& Phi(vec_grid_fct_type& u) const
00193   { return (&u==_u_sh ? *_phi_sh : *_phi); }
00194   inline const bool& ErrorEstimation() const { return _EstimateError;}
00195   void SetErrorEstimation(const bool est) { _EstimateError = est; }
00196 
00197   inline void SetBoundaryP(boundary_type* _boundary) { _Boundary = _boundary; }
00198   inline boundary_type* GetBoundaryP() { return _Boundary; }
00199   inline boundary_type& Boundary() { assert (_Boundary!=0); return *_Boundary; }
00200   inline const boundary_type& Boundary() const { assert (_Boundary!=0); return *_Boundary; }
00201 
00202   inline void SetLevelSetP(levelset_type* _levelset) { _LevelSet = _levelset; }
00203   inline levelset_type* GetLevelSetP() { return _LevelSet; }
00204   inline levelset_type& LevelSet() { assert (_LevelSet!=0); return *_LevelSet; }
00205   inline const levelset_type& LevelSet() const { assert (_LevelSet!=0); return *_LevelSet; }
00206 
00207   inline void SetBoundaryConditionsP(boundary_conditions_type* boundary_conditions) 
00208   { _BoundaryConditions = boundary_conditions; }
00209   inline boundary_conditions_type* GetBoundaryConditionsP() { return _BoundaryConditions; }
00210   inline boundary_conditions_type& BoundaryConditions_() 
00211   { assert (_BoundaryConditions!=0); return *_BoundaryConditions; }
00212   inline const boundary_conditions_type& BoundaryConditions_() const 
00213   { assert (_BoundaryConditions!=0); return *_BoundaryConditions; }
00214 
00215   inline void SetGridFunctions(vec_grid_fct_type* u, vec_grid_fct_type* ush) {
00216     _u = u; _u_sh = ush;
00217   }
00218   inline vec_grid_fct_type& U() { return *_u; }
00219   inline const vec_grid_fct_type& U() const { return *_u; }
00220   inline vec_grid_fct_type& Ush() { return *_u_sh; }
00221   inline const vec_grid_fct_type& Ush() const { return *_u_sh; }
00222 
00223 protected:
00224   boundary_type* _Boundary;
00225   levelset_type* _LevelSet;
00226   grid_fct_type *_phi, *_phi_sh;
00227   boundary_conditions_type* _BoundaryConditions;
00228   boundary_functor_type* _BoundaryFunc;
00229   vec_grid_fct_type *_u, *_u_sh;
00230   char phiName[DAGHBktGFNameWidth], phiNamesh[DAGHBktGFNameWidth];
00231   bool _EstimateError;
00232   int _Ignore;
00233   std::string _myprefix;
00234 };
00235 
00236 
00237 #endif

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