ug4
local_shape_function_set.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__LIB_DISC__LOCAL_FINITE_ELEMENT__LOCAL_SHAPE_FUCNTION_SET__
34 #define __H__UG__LIB_DISC__LOCAL_FINITE_ELEMENT__LOCAL_SHAPE_FUCNTION_SET__
35 
36 // extern libraries
37 #include <cassert>
38 #include <map>
39 
40 // other ug4 modules
41 #include "common/math/ugmath.h"
42 
43 // library intern headers
46 
47 namespace ug {
48 
50 // Interface for local shape function sets
52 
55 
57 
66 template < int TDim,
67  typename TShape = number,
68  typename TGrad = MathVector<TDim> >
70 {
71  public:
73  static const int dim = TDim;
74 
77 
79  typedef TShape shape_type;
80 
82  typedef TGrad grad_type;
83 
84  public:
86  virtual bool continuous() const = 0;
87 
89 
96  virtual shape_type shape(size_t i, const MathVector<dim>& x) const = 0;
97 
99 
106  virtual void shape(shape_type& shape, size_t i, const MathVector<dim>& x) const = 0;
107 
109 
116  virtual void shapes(shape_type* vShape, const MathVector<dim>& x) const = 0;
117  virtual void shapes(std::vector<shape_type>& vShape, const MathVector<dim>& x) const = 0;
119 
121 
127  virtual void shapes(std::vector<std::vector<shape_type> >& vvShape,
128  const std::vector<MathVector<dim> >& vLocPos) const = 0;
129 
131 
137  virtual void grad(grad_type& g, size_t i, const MathVector<dim>& x) const = 0;
138 
140 
147  virtual void grads(grad_type* vGrad, const MathVector<dim>& x) const = 0;
148  virtual void grads(std::vector<grad_type>& vGrad, const MathVector<dim>& x) const = 0;
150 
152 
158  virtual void grads(std::vector<std::vector<grad_type> >& vvGrad,
159  const std::vector<MathVector<dim> >& vLocPos) const = 0;
160 
163 };
164 
166 
168 // Common base class for local shape function sets to ease implementation
170 
172 template <typename TImpl, int TDim,
173  typename TShape = number,
174  typename TGrad = MathVector<TDim> >
175 class BaseLSFS
176 {
177  public:
179  typedef TImpl ImplType;
180 
182  static const int dim = TDim;
183 
185  typedef TShape shape_type;
186 
188  typedef TGrad grad_type;
189 
191  // methods implemented by derived class
193 
194  public:
196  inline shape_type shape(size_t i, const MathVector<dim>& x) const
197  {
198  return getImpl().shape(i, x);
199  }
200 
202  inline void grad(grad_type& g, size_t i, const MathVector<dim>& x) const
203  {
204  getImpl().grad(g, i, x); return;
205  }
206 
208  // methods generated generically
210 
211  public:
213  inline void shape(shape_type& sh, size_t i, const MathVector<dim>& x) const
214  {
215  sh = shape(i, x);
216  }
217 
218 
220  inline void shapes(shape_type* vShape, const MathVector<dim>& x) const
221  {
222  for(size_t sh = 0; sh < getImpl().num_sh(); ++sh)
223  vShape[sh] = shape(sh, x);
224  }
225 
227  inline void shapes(std::vector<shape_type>& vShape, const MathVector<dim>& x) const
228  {
229  vShape.resize(getImpl().num_sh()); shapes(&vShape[0], x);
230  }
231 
233  inline void shapes(std::vector<std::vector<shape_type> >& vvShape,
234  const std::vector<MathVector<dim> >& vLocPos) const
235  {
236  vvShape.resize(vLocPos.size());
237  for(size_t ip = 0; ip < vLocPos.size(); ++ip)
238  shapes(vvShape[ip], vLocPos[ip]);
239  }
240 
242  inline void grads(grad_type* vGrad, const MathVector<dim>& x) const
243  {
244  for(size_t sh = 0; sh < getImpl().num_sh(); ++sh)
245  grad(vGrad[sh], sh, x);
246  }
247 
249  inline void grads(std::vector<grad_type>& vGrad, const MathVector<dim>& x) const
250  {
251  vGrad.resize(getImpl().num_sh()); grads(&vGrad[0], x);
252  }
253 
255  inline void grads(std::vector<std::vector<grad_type> >& vvGrad,
256  const std::vector<MathVector<dim> >& vLocPos) const
257  {
258  vvGrad.resize(vLocPos.size());
259  for(size_t ip = 0; ip < vLocPos.size(); ++ip)
260  grads(vvGrad[ip], vLocPos[ip]);
261  }
262 
263  protected:
265  ImplType& getImpl() {return static_cast<ImplType&>(*this);}
266 
268  const ImplType& getImpl() const {return static_cast<const ImplType&>(*this);}
269 
270 };
271 
272 } // namespace ug
273 
274 #endif /* __H__UG__LIB_DISC__LOCAL_FINITE_ELEMENT__LOCAL_SHAPE_FUCNTION_SET__ */
static interface for trial spaces
Definition: local_shape_function_set.h:176
void grad(grad_type &g, size_t i, const MathVector< dim > &x) const
evaluates the gradient of the shape function
Definition: local_shape_function_set.h:202
void shapes(std::vector< shape_type > &vShape, const MathVector< dim > &x) const
returns all shape functions evaluated at a point
Definition: local_shape_function_set.h:227
shape_type shape(size_t i, const MathVector< dim > &x) const
evaluates the shape function
Definition: local_shape_function_set.h:196
TImpl ImplType
type of implementation
Definition: local_shape_function_set.h:179
ImplType & getImpl()
access to implementation
Definition: local_shape_function_set.h:265
void shape(shape_type &sh, size_t i, const MathVector< dim > &x) const
evaluates the shape function
Definition: local_shape_function_set.h:213
void grads(std::vector< std::vector< grad_type > > &vvGrad, const std::vector< MathVector< dim > > &vLocPos) const
returns all gradients evaluated at a point
Definition: local_shape_function_set.h:255
void shapes(shape_type *vShape, const MathVector< dim > &x) const
returns all shape functions evaluated at a point
Definition: local_shape_function_set.h:220
void grads(std::vector< grad_type > &vGrad, const MathVector< dim > &x) const
returns all gradients evaluated at a point
Definition: local_shape_function_set.h:249
TShape shape_type
Shape type.
Definition: local_shape_function_set.h:185
void shapes(std::vector< std::vector< shape_type > > &vvShape, const std::vector< MathVector< dim > > &vLocPos) const
returns all shape functions evaluated at a point
Definition: local_shape_function_set.h:233
static const int dim
dimension of reference element
Definition: local_shape_function_set.h:182
const ImplType & getImpl() const
const access to implementation
Definition: local_shape_function_set.h:268
void grads(grad_type *vGrad, const MathVector< dim > &x) const
returns all gradients evaluated at a point
Definition: local_shape_function_set.h:242
TGrad grad_type
Gradient type.
Definition: local_shape_function_set.h:188
Definition: local_dof_set.h:158
virtual base class for local shape function sets
Definition: local_shape_function_set.h:70
virtual void grads(std::vector< std::vector< grad_type > > &vvGrad, const std::vector< MathVector< dim > > &vLocPos) const =0
returns all gradients evaluated at a several points
TGrad grad_type
Gradient type.
Definition: local_shape_function_set.h:82
TShape shape_type
Shape type.
Definition: local_shape_function_set.h:79
MathVector< dim > position_type
Domain position type.
Definition: local_shape_function_set.h:76
virtual void grads(grad_type *vGrad, const MathVector< dim > &x) const =0
returns all gradients evaluated at a point
virtual shape_type shape(size_t i, const MathVector< dim > &x) const =0
evaluates the shape function
virtual void shapes(shape_type *vShape, const MathVector< dim > &x) const =0
returns all shape functions evaluated at a point
virtual void shapes(std::vector< shape_type > &vShape, const MathVector< dim > &x) const =0
returns all shape functions evaluated at a point
virtual void shapes(std::vector< std::vector< shape_type > > &vvShape, const std::vector< MathVector< dim > > &vLocPos) const =0
returns all shape functions evaluated at several point
virtual void grad(grad_type &g, size_t i, const MathVector< dim > &x) const =0
evaluates the gradient of the shape function
static const int dim
Dimension, where shape functions are defined.
Definition: local_shape_function_set.h:73
virtual bool continuous() const =0
returns if space constructs continuous functions
virtual void shape(shape_type &shape, size_t i, const MathVector< dim > &x) const =0
evaluates the shape function
virtual ~LocalShapeFunctionSet()
virtual destructor
Definition: local_shape_function_set.h:162
virtual void grads(std::vector< grad_type > &vGrad, const MathVector< dim > &x) const =0
returns all gradients evaluated at a point
double number
Definition: types.h:124
the ug namespace