Plugins
stabilization.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3  * Author: Andreas Vogel
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__PLUGINS__NAVIER_STOKES__INCOMPRESSIBLE__FV1__STABILIZATION__
34 #define __H__UG__PLUGINS__NAVIER_STOKES__INCOMPRESSIBLE__FV1__STABILIZATION__
35 
36 //#define UG_NSSTAB_ASSERT(cond, exp)
37 // include define below to assert arrays used in stabilization
38 #define UG_NSSTAB_ASSERT(cond, exp) UG_ASSERT((cond), (exp))
39 
40 #include "../../upwind_interface.h"
43 
44 
45 namespace ug{
46 namespace NavierStokes{
47 
60 template <int dim>
62 {
63  protected:
66 
67  public:
69  static const size_t maxNumSCV = traits::maxNumSCV;
70 
72  static const size_t maxNumSCVF = traits::maxNumSCVF;
73 
75  static const size_t maxNumSH = traits::maxNSH;
76 
77  private:
80 
81  public:
84  : m_numScvf(0), m_numSh(0),
85  m_spUpwind(NULL)
86  {
87  m_vUpdateFunc.clear();
88  }
89 
92  {
93  m_spUpwind = spUpwind;
94  m_spConstUpwind = spUpwind;
95  }
96 
99 
101  bool upwind_valid() const {return m_spConstUpwind.valid();}
102 
104  template <typename TFVGeom>
106  {
107  // get unique geometry id
108  size_t id = GetUniqueFVGeomID<TFVGeom>();
109  // check that function exists
110  if(id >= m_vUpdateFunc.size() || m_vUpdateFunc[id] == NULL)
111  UG_THROW("No update function registered for Geometry "<<id);
112  // set current geometry
113  m_id = id;
114 
115  // set sizes
116  TFVGeom& geo = GeomProvider<TFVGeom>::get();
117  m_numScvf = geo.num_scvf();
118  m_numSh = geo.num_sh();
119  // set sizes in upwind
120  if(m_spUpwind.valid()) m_spUpwind->template set_geometry_type<TFVGeom>();
121  }
122 
124  // interface to the upwind
126 
127  protected:
128 
130  template <typename TFVGeom>
131  void compute_upwind(const TFVGeom& geo,
132  const MathVector<dim> vStdVel[])
133  {
134  UG_NSSTAB_ASSERT(m_spUpwind.valid(), "No upwind object");
135  m_spUpwind->update_upwind(geo, vStdVel);
136  };
137 
139  template <typename TFVGeom>
140  void compute_downwind(const TFVGeom& geo,
141  const MathVector<dim> vStdVel[])
142  {
143  UG_NSSTAB_ASSERT(m_spUpwind.valid(), "No upwind object");
144  m_spUpwind->update_downwind(geo, vStdVel);
145  };
146 
148  // the data interface (for the NS discretization)
150 
151  public:
152 
154  size_t num_ip () const {return m_numScvf;}
155 
157  size_t num_sh () const {return m_numSh;}
158 
160  const MathVector<dim>& stab_vel(size_t scvf) const
161  {
162  UG_NSSTAB_ASSERT(scvf < m_numScvf, "Invalid index.");
163  return m_vStabVel[scvf];
164  }
165 
168 
171  number stab_shape_vel(size_t scvf, size_t compOut, size_t compIn, size_t sh) const
172  {
173  UG_NSSTAB_ASSERT(scvf < m_numScvf, "Invalid index.");
174  UG_NSSTAB_ASSERT(compOut < dim, "Invalid index.");
175  UG_NSSTAB_ASSERT(compIn < dim, "Invalid index.");
176  UG_NSSTAB_ASSERT(sh < m_numSh, "Invalid index.");
177  return m_vvvvStabShapeVel[scvf][compOut][compIn][sh];
178  }
179 
181  number stab_shape_p(size_t scvf, size_t compOut, size_t sh) const
182  {
183  UG_NSSTAB_ASSERT(scvf < m_numScvf, "Invalid index.");
184  UG_NSSTAB_ASSERT(compOut < dim, "Invalid index.");
185  UG_NSSTAB_ASSERT(sh < m_numSh, "Invalid index.");
186  return m_vvvStabShapePressure[scvf][compOut][sh];
187  }
188 
189 
191  void update(const FVGeometryBase* geo,
192  const LocalVector& vCornerValue,
193  const MathVector<dim> vStdVel[],
194  const bool bStokes,
195  const DataImport<number, dim>& kinVisco,
196  const DataImport<number, dim>& density,
197  const DataImport<MathVector<dim>, dim>* pSource,
198  const LocalVector* pvCornerValueOldTime, number dt)
199  {(this->*(m_vUpdateFunc[m_id]))(geo, vCornerValue, vStdVel,
200  bStokes, kinVisco, density, pSource,
201  pvCornerValueOldTime, dt);}
202 
204  // the data interface (for the implementation)
206 
207  protected:
208 
210  MathVector<dim>& stab_vel(size_t scvf)
211  {
212  UG_NSSTAB_ASSERT(scvf < m_numScvf, "Invalid index.");
213  return m_vStabVel[scvf];
214  }
215 
217  void set_vel_comp_connected(bool bVelCompConnected) {m_bVelCompConnected = bVelCompConnected;}
218 
221  number& stab_shape_vel(size_t scvf, size_t compOut, size_t compIn, size_t sh)
222  {
223  UG_NSSTAB_ASSERT(scvf < m_numScvf, "Invalid index.");
224  UG_NSSTAB_ASSERT(compOut < dim, "Invalid index.");
225  UG_NSSTAB_ASSERT(compIn < dim, "Invalid index.");
226  UG_NSSTAB_ASSERT(sh < m_numSh, "Invalid index.");
227  return m_vvvvStabShapeVel[scvf][compOut][compIn][sh];
228  }
229 
231  number& stab_shape_p(size_t scvf, size_t compOut, size_t sh)
232  {
233  UG_NSSTAB_ASSERT(scvf < m_numScvf, "Invalid index.");
234  UG_NSSTAB_ASSERT(compOut < dim, "Invalid index.");
235  UG_NSSTAB_ASSERT(sh < m_numSh, "Invalid index.");
236  return m_vvvStabShapePressure[scvf][compOut][sh];
237  }
238 
240  // the data
242 
243  private:
244 
246  size_t m_numScvf;
247 
249  size_t m_numSh;
250 
253 
256 
259 
262 
264  int m_id;
265 
270 
272  // registering mechanism
274 
275  protected:
277  typedef void (this_type::*UpdateFunc)( const FVGeometryBase* geo,
278  const LocalVector& vCornerValue,
279  const MathVector<dim> vStdVel[],
280  const bool bStokes,
281  const DataImport<number, dim>& kinVisco,
282  const DataImport<number, dim>& density,
283  const DataImport<MathVector<dim>, dim>* pSource,
284  const LocalVector* pvCornerValueOldTime, number dt);
285 
286  public:
288  template <typename TFVGeom, typename TAssFunc>
289  void register_update_func(TAssFunc func);
290 
291  protected:
293  std::vector<UpdateFunc> m_vUpdateFunc;
294 };
295 
296 /*-------- Schneider-Raw-type stabilizations --------*/
297 
303 template <int dim>
305  : public INavierStokesFV1Stabilization<dim>
306 {
307  private:
310 
311  protected:
313  {
314  RAW = 0,
316  COR
317  };
318 
319  public:
322  {
323  // default setup
324  set_diffusion_length("RAW");
325  }
326 
328  void set_diffusion_length(std::string diffLength);
329 
330  protected:
331 
333  number diff_length_sq_inv(size_t scvf) const
334  {
335  UG_NSSTAB_ASSERT(scvf < this_type::num_ip(), "Invalid index.");
336  return m_vDiffLengthSqInv[scvf];
337  }
338 
340  // forward methods of Upwind Velocity
342 
344  number upwind_conv_length(size_t scvf) const
345  {
346  UG_NSSTAB_ASSERT(this_type::upwind_valid(), "No upwind object");
347  return this_type::upwind()->upwind_conv_length(scvf);
348  }
349 
351  number downwind_conv_length(size_t scvf) const
352  {
353  UG_NSSTAB_ASSERT(this_type::upwind_valid(), "No upwind object");
354  return this_type::upwind()->downwind_conv_length(scvf);
355  }
356 
358  number upwind_shape_sh(size_t scvf, size_t sh) const
359  {
360  UG_NSSTAB_ASSERT(this_type::upwind_valid(), "No upwind object");
361  return this_type::upwind()->upwind_shape_sh(scvf, sh);
362  }
363 
365  number downwind_shape_sh(size_t scvf, size_t sh) const
366  {
367  UG_NSSTAB_ASSERT(this_type::upwind_valid(), "No upwind object");
368  return this_type::upwind()->downwind_shape_sh(scvf, sh);
369  }
370 
372  bool non_zero_shape_ip() const
373  {
374  UG_NSSTAB_ASSERT(this_type::upwind_valid(), "No upwind object");
375  return this_type::upwind()->non_zero_shape_ip();
376  }
377 
379  number upwind_shape_ip(size_t scvf, size_t scvf2) const
380  {
381  UG_NSSTAB_ASSERT(this_type::upwind_valid(), "No upwind object");
382  return this_type::upwind()->upwind_shape_ip(scvf, scvf2);
383  }
384 
386  number downwind_shape_ip(size_t scvf, size_t scvf2) const
387  {
388  UG_NSSTAB_ASSERT(this_type::upwind_valid(), "No upwind object");
389  return this_type::upwind()->downwind_shape_ip(scvf, scvf2);
390  }
391 
393  // internal handling
395 
396  protected:
398  template <typename TFVGeom>
399  void compute_diff_length(const TFVGeom& geo);
400 
402  // data
404 
405  protected:
408 
411 
412 };
413 
415 template <int dim>
417 
419 // FIELDS
421 
425 template <int TDim>
427  : public INavierStokesSRFV1Stabilization<TDim>
428 {
429  public:
432 
435 
437  static const int dim = TDim;
438 
439  protected:
440  // explicitly forward some function
445  using base_type::stab_vel;
447 
448  // functions from upwind
456 
457  public:
460  {
461  // vel comp not coupled
462  set_vel_comp_connected(false);
463 
464  // register evaluation function
465  register_func();
466  }
467 
469  template <typename TElem>
470  void update(const FV1Geometry<TElem, dim>* geo,
471  const LocalVector& vCornerValue,
472  const MathVector<dim> vStdVel[],
473  const bool bStokes,
474  const DataImport<number, dim>& kinVisco,
475  const DataImport<number, dim>& density,
476  const DataImport<MathVector<dim>, dim>* pSource,
477  const LocalVector* pvCornerValueOldTime, number dt);
478 
479  private:
481 
482  template <typename TElem>
484  {
485  typedef FV1Geometry<TElem, dim> TGeom;
486  typedef void (this_type::*TFunc)(const TGeom* geo,
487  const LocalVector& vCornerValue,
488  const MathVector<dim> vStdVel[],
489  const bool bStokes,
490  const DataImport<number, dim>& kinVisco,
491  const DataImport<number, dim>& density,
492  const DataImport<MathVector<dim>, dim>* pSource,
493  const LocalVector* pvCornerValueOldTime, number dt);
494 
495  this->template register_update_func<TGeom, TFunc>(&this_type::template update<TElem>);
496  }
497 };
498 
499 
501 // FLOW
503 
507 template <int TDim>
510 {
511  public:
514 
517 
519  static const int dim = TDim;
520 
521  protected:
522  // explicitly forward some function
523  using base_type::register_update_func;
524  using base_type::set_vel_comp_connected;
525  using base_type::diff_length_sq_inv;
526  using base_type::stab_shape_vel;
527  using base_type::stab_shape_p;
528  using base_type::stab_vel;
529 
530  // functions from upwind
531  using base_type::upwind_conv_length;
532  using base_type::downwind_conv_length;
533  using base_type::upwind_shape_sh;
534  using base_type::downwind_shape_sh;
535  using base_type::non_zero_shape_ip;
536  using base_type::upwind_shape_ip;
537  using base_type::downwind_shape_ip;
538 
539  public:
542  {
543  // vel comp coupled
544  set_vel_comp_connected(true);
545 
546  // register evaluation function
547  register_func();
548  }
549 
551  template <typename TElem>
552  void update(const FV1Geometry<TElem, dim>* geo,
553  const LocalVector& vCornerValue,
554  const MathVector<dim> vStdVel[],
555  const bool bStokes,
556  const DataImport<number, dim>& kinVisco,
557  const DataImport<number, dim>& density,
558  const DataImport<MathVector<dim>, dim>* pSource,
559  const LocalVector* pvCornerValueOldTime, number dt);
560 
561  private:
563 
564  template <typename TElem>
566  {
567  typedef FV1Geometry<TElem, dim> TGeom;
568  typedef void (this_type::*TFunc)(const TGeom* geo,
569  const LocalVector& vCornerValue,
570  const MathVector<dim> vStdVel[],
571  const bool bStokes,
572  const DataImport<number, dim>& kinVisco,
573  const DataImport<number, dim>& density,
574  const DataImport<MathVector<dim>, dim>* pSource,
575  const LocalVector* pvCornerValueOldTime, number dt);
576 
577  this->template register_update_func<TGeom, TFunc>(&this_type::template update<TElem>);
578  }
579 };
580 
582 // NO STABILIZATION (Note: The discretization is then unstable!)
584 
585 template <int TDim>
588 {
589  public:
592 
595 
597  static const int dim = TDim;
598 
599  protected:
600  // explicitly forward some function
601  using base_type::register_update_func;
602  using base_type::set_vel_comp_connected;
603  using base_type::stab_shape_vel;
604  using base_type::stab_shape_p;
605  using base_type::stab_vel;
606 
607  public:
610  {
611  // vel comp not interconnected
612  set_vel_comp_connected(false);
613 
614  // register evaluation function
615  register_func();
616  }
617 
619  template <typename TElem>
620  void update(const FV1Geometry<TElem, dim>* geo,
621  const LocalVector& vCornerValue,
622  const MathVector<dim> vStdVel[],
623  const bool bStokes,
624  const DataImport<number, dim>& kinVisco,
625  const DataImport<number, dim>& density,
626  const DataImport<MathVector<dim>, dim>* pSource,
627  const LocalVector* pvCornerValueOldTime, number dt);
628 
629  private:
631 
632  template <typename TElem>
634  {
635  typedef FV1Geometry<TElem, dim> TGeom;
636  typedef void (this_type::*TFunc)(const TGeom* geo,
637  const LocalVector& vCornerValue,
638  const MathVector<dim> vStdVel[],
639  const bool bStokes,
640  const DataImport<number, dim>& kinVisco,
641  const DataImport<number, dim>& density,
642  const DataImport<MathVector<dim>, dim>* pSource,
643  const LocalVector* pvCornerValueOldTime, number dt);
644 
645  this->template register_update_func<TGeom, TFunc>(&this_type::template update<TElem>);
646  }
647 };
648 
649 } // namespace NavierStokes
650 } // end namespace ug
651 
652 #endif /* __H__UG__PLUGINS__NAVIER_STOKES__FV__STABILIZATION__ */
function NavierStokes(fcts, subsets, discType)
static TGeom & get()
MathVector< dim > m_vStabVel[maxNumSCVF]
values of stabilized velocity at ip
Definition: stabilization.h:252
number m_vvvStabShapePressure[maxNumSCVF][dim][maxNumSH]
stab shapes w.r.t pressure
Definition: stabilization.h:261
number m_vvvvStabShapeVel[maxNumSCVF][dim][dim][maxNumSH]
stab shapes w.r.t vel
Definition: stabilization.h:258
static const size_t maxNumSCV
number of SubControlVolumes
Definition: stabilization.h:69
const ConstSmartPtr< INavierStokesUpwind< dim > > & upwind() const
returns the upwind
Definition: stabilization.h:98
void set_vel_comp_connected(bool bVelCompConnected)
sets the vel comp connected flag
Definition: stabilization.h:217
void update(const FVGeometryBase *geo, const LocalVector &vCornerValue, const MathVector< dim > vStdVel[], const bool bStokes, const DataImport< number, dim > &kinVisco, const DataImport< number, dim > &density, const DataImport< MathVector< dim >, dim > *pSource, const LocalVector *pvCornerValueOldTime, number dt)
compute values for new geometry and corner velocities
Definition: stabilization.h:191
number stab_shape_vel(size_t scvf, size_t compOut, size_t compIn, size_t sh) const
Definition: stabilization.h:171
void set_geometry_type()
set the FV1 Geometry type to use for next updates
Definition: stabilization.h:105
size_t num_ip() const
number of integration points
Definition: stabilization.h:154
ConstSmartPtr< INavierStokesUpwind< dim > > m_spConstUpwind
Upwind object (if set), the same as m_spUpwind, but as a const.
Definition: stabilization.h:269
INavierStokesFV1Stabilization()
constructor
Definition: stabilization.h:83
size_t num_sh() const
number of shapes (corners)
Definition: stabilization.h:157
bool vel_comp_connected() const
returns if stab velocity comp depends on other vel components
Definition: stabilization.h:167
size_t m_numSh
number of current shape functions (usually in corners)
Definition: stabilization.h:249
int m_id
id of current geometry type
Definition: stabilization.h:264
size_t m_numScvf
number of current scvf
Definition: stabilization.h:246
number & stab_shape_vel(size_t scvf, size_t compOut, size_t compIn, size_t sh)
Definition: stabilization.h:221
bool m_bVelCompConnected
flag if velocity components are interconnected
Definition: stabilization.h:255
void set_upwind(SmartPtr< INavierStokesUpwind< dim > > spUpwind)
sets the upwind method
Definition: stabilization.h:91
bool upwind_valid() const
returns if the upwind pointer is valid
Definition: stabilization.h:101
void(this_type::* UpdateFunc)(const FVGeometryBase *geo, const LocalVector &vCornerValue, const MathVector< dim > vStdVel[], const bool bStokes, const DataImport< number, dim > &kinVisco, const DataImport< number, dim > &density, const DataImport< MathVector< dim >, dim > *pSource, const LocalVector *pvCornerValueOldTime, number dt)
type of update function
Definition: stabilization.h:277
void compute_downwind(const TFVGeom &geo, const MathVector< dim > vStdVel[])
computes the downwind shapes
Definition: stabilization.h:140
std::vector< UpdateFunc > m_vUpdateFunc
Vector holding all update functions.
Definition: stabilization.h:293
number stab_shape_p(size_t scvf, size_t compOut, size_t sh) const
computed stab shape for pressure.
Definition: stabilization.h:181
static const size_t maxNumSCVF
max number of SubControlVolumeFaces
Definition: stabilization.h:72
SmartPtr< INavierStokesUpwind< dim > > m_spUpwind
Upwind object (if set)
Definition: stabilization.h:267
INavierStokesFV1Stabilization< dim > this_type
abbreviation for own type
Definition: stabilization.h:79
MathVector< dim > & stab_vel(size_t scvf)
stabilized velocity
Definition: stabilization.h:210
void compute_upwind(const TFVGeom &geo, const MathVector< dim > vStdVel[])
computes the upwind shapes
Definition: stabilization.h:131
void register_update_func(TAssFunc func)
register a update function for a Geometry
Definition: stabilization.cpp:69
fv1_dim_traits< dim, dim > traits
used traits
Definition: stabilization.h:65
const MathVector< dim > & stab_vel(size_t scvf) const
stabilized velocity
Definition: stabilization.h:160
number & stab_shape_p(size_t scvf, size_t compOut, size_t sh)
computed stab shape for pressure.
Definition: stabilization.h:231
static const size_t maxNumSH
max number of shape functions
Definition: stabilization.h:75
void compute_diff_length(const TFVGeom &geo)
computes the diffusion length
Definition: stabilization.cpp:106
number upwind_shape_sh(size_t scvf, size_t sh) const
upwind shape for corner vel
Definition: stabilization.h:358
number downwind_shape_ip(size_t scvf, size_t scvf2) const
upwind shapes for ip vel
Definition: stabilization.h:386
number diff_length_sq_inv(size_t scvf) const
diff length
Definition: stabilization.h:333
number m_vDiffLengthSqInv[this_type::maxNumSCVF]
vector holding diffusion Length squared and inverted
Definition: stabilization.h:410
number downwind_conv_length(size_t scvf) const
Convection Length.
Definition: stabilization.h:351
bool non_zero_shape_ip() const
returns if upwind shape w.r.t. ip vel is non-zero
Definition: stabilization.h:372
DiffusionLength m_diffLengthType
type of diffusion length computation
Definition: stabilization.h:407
number upwind_shape_ip(size_t scvf, size_t scvf2) const
upwind shapes for ip vel
Definition: stabilization.h:379
void set_diffusion_length(std::string diffLength)
sets the type of diff length used for evaluation
Definition: stabilization.cpp:89
INavierStokesSRFV1Stabilization< dim > this_type
Abbreviation for own type.
Definition: stabilization.h:309
number upwind_conv_length(size_t scvf) const
Convection Length.
Definition: stabilization.h:344
DiffusionLength
Definition: stabilization.h:313
@ COR
Definition: stabilization.h:316
@ RAW
Definition: stabilization.h:314
@ FIVEPOINT
Definition: stabilization.h:315
INavierStokesSRFV1Stabilization()
constructor
Definition: stabilization.h:321
number downwind_shape_sh(size_t scvf, size_t sh) const
upwind shape for corner vel
Definition: stabilization.h:365
Definition: upwind_interface.h:57
INavierStokesSRFV1Stabilization< TDim > base_type
Base class.
Definition: stabilization.h:431
NavierStokesFIELDSStabilization()
constructor
Definition: stabilization.h:459
NavierStokesFIELDSStabilization< TDim > this_type
This class.
Definition: stabilization.h:434
void update(const FV1Geometry< TElem, dim > *geo, const LocalVector &vCornerValue, const MathVector< dim > vStdVel[], const bool bStokes, const DataImport< number, dim > &kinVisco, const DataImport< number, dim > &density, const DataImport< MathVector< dim >, dim > *pSource, const LocalVector *pvCornerValueOldTime, number dt)
update of values for FV1Geometry
Definition: stabilization.cpp:126
static const int dim
Dimension.
Definition: stabilization.h:437
void register_func()
Definition: stabilization.h:483
INavierStokesSRFV1Stabilization< TDim > base_type
Base class.
Definition: stabilization.h:513
NavierStokesFLOWStabilization()
constructor
Definition: stabilization.h:541
void register_func()
Definition: stabilization.h:565
NavierStokesFLOWStabilization< TDim > this_type
This class.
Definition: stabilization.h:516
NavierStokesFV1WithoutStabilization()
Constructor.
Definition: stabilization.h:609
NavierStokesFV1WithoutStabilization< TDim > this_type
This class.
Definition: stabilization.h:594
void register_func()
Definition: stabilization.h:633
INavierStokesFV1Stabilization< TDim > base_type
Base class.
Definition: stabilization.h:591
static const int dim
#define UG_THROW(msg)
double number
SmartPtr< INavierStokesSRFV1Stabilization< dim > > CreateNavierStokesStabilization(const std::string &name)
creates upwind based on a string identifier
Definition: stabilization.cpp:47
#define UG_NSSTAB_ASSERT(cond, exp)
Definition: stabilization.h:38