dune-fem  2.4.1-rc
h1norm.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_H1NORM_HH
2 #define DUNE_FEM_H1NORM_HH
3 
5 
6 namespace Dune
7 {
8 
9  namespace Fem
10  {
11 
12  template< class GridPart >
13  class H1Norm
14  : public LPNormBase< GridPart, H1Norm< GridPart> >
15  {
18 
19  public:
20  typedef GridPart GridPartType;
21 
22  template< class Function >
24 
25  protected:
26  typedef typename BaseType::EntityType EntityType;
27 
29  public:
31 
32 
33  using BaseType::gridPart;
34  using BaseType::comm;
35 
36  public:
37  explicit H1Norm ( const GridPartType &gridPart, const unsigned int order = 0 );
38  H1Norm ( const ThisType &other );
39 
40  template< class DiscreteFunctionType >
41  typename Dune::FieldTraits< typename DiscreteFunctionType::RangeFieldType >::real_type
42  norm ( const DiscreteFunctionType &u ) const;
43 
44  template< class UDiscreteFunctionType, class VDiscreteFunctionType >
45  typename Dune::FieldTraits< typename UDiscreteFunctionType::RangeFieldType >::real_type
46  distance ( const UDiscreteFunctionType &u, const VDiscreteFunctionType &v ) const;
47 
48  template< class LocalFunctionType, class ReturnType >
49  void normLocal ( const EntityType &entity, unsigned int order, const LocalFunctionType &uLocal, ReturnType &sum ) const;
50 
51  template< class ULocalFunctionType, class VLocalFunctionType, class ReturnType >
52  void distanceLocal ( const EntityType &entity, unsigned int order, const ULocalFunctionType &uLocal, const VLocalFunctionType &vLocal, ReturnType &sum ) const;
53 
54  private:
55  // prohibit assignment
56  ThisType operator= ( const ThisType &other );
57 
58  const unsigned int order_;
59  };
60 
61 
62 
63  // H1Norm::FunctionJacobianSquare
64  // ------------------------------
65 
66  template< class GridPart >
67  template< class Function >
68  struct H1Norm< GridPart >::FunctionJacobianSquare
69  {
71 
73  typedef typename Dune::FieldTraits< typename FunctionType::RangeFieldType >::real_type RealType;
74  typedef FieldVector< RealType, 1 > RangeType;
75 
76  public:
77  explicit FunctionJacobianSquare ( const FunctionType &function )
78  : function_( function )
79  {}
80 
81  template< class Point >
82  void evaluate ( const Point &x, RangeType &ret ) const
83  {
84  const int dimRange = FunctionType::RangeType::dimension;
85 
86  typename FunctionType::RangeType phi;
87  function_.evaluate( x, phi );
88  ret[ 0 ] = phi.two_norm2();
89 
90  typename FunctionType::JacobianRangeType grad;
91  function_.jacobian( x, grad );
92  for( int i = 0; i < dimRange; ++i )
93  ret[ 0 ] += grad[ i ].two_norm2();
94  }
95 
96  private:
97  const FunctionType &function_;
98  };
99 
100 
101 
102  // Implementation of H1 Norm
103  // -------------------------
104 
105  template< class GridPart >
106  inline H1Norm< GridPart >::H1Norm ( const GridPartType &gridPart, const unsigned int order )
107  : BaseType( gridPart ),
108  order_( order )
109  {}
110 
111 
112 
113  template< class GridPart >
114  inline H1Norm< GridPart >::H1Norm ( const ThisType &other )
115  : BaseType( other ),
116  order_( other.order_ )
117  {}
118 
119 
120  template< class GridPart >
121  template< class DiscreteFunctionType >
122  inline typename Dune::FieldTraits< typename DiscreteFunctionType::RangeFieldType >::real_type
123  H1Norm< GridPart >::norm ( const DiscreteFunctionType &u ) const
124  {
125  typedef typename DiscreteFunctionType::RangeFieldType RangeFieldType;
126  typedef typename Dune::FieldTraits< RangeFieldType >::real_type RealType;
127  typedef FieldVector< RealType, 1 > ReturnType ;
128 
129  ReturnType sum = BaseType :: forEach( u, ReturnType( 0 ), order_ );
130 
131  // return result, e.g. sqrt of calculated sum
132  return sqrt( comm().sum( sum[ 0 ] ) );
133  }
134 
135  template< class GridPart >
136  template< class UDiscreteFunctionType, class VDiscreteFunctionType >
137  inline typename Dune::FieldTraits< typename UDiscreteFunctionType::RangeFieldType >::real_type
138  H1Norm< GridPart >::distance ( const UDiscreteFunctionType &u,
139  const VDiscreteFunctionType &v ) const
140  {
141  typedef typename UDiscreteFunctionType::RangeFieldType RangeFieldType;
142  typedef typename Dune::FieldTraits< RangeFieldType >::real_type RealType;
143  typedef FieldVector< RealType, 1 > ReturnType ;
144 
145  ReturnType sum = BaseType :: forEach( u, v, ReturnType( 0 ), order_ );
146 
147  // return result, e.g. sqrt of calculated sum
148  return sqrt( comm().sum( sum[ 0 ] ) );
149  }
150 
151  template< class GridPart >
152  template< class ULocalFunctionType, class VLocalFunctionType, class ReturnType >
153  inline void
154  H1Norm< GridPart >::distanceLocal ( const EntityType &entity, unsigned int order, const ULocalFunctionType &uLocal, const VLocalFunctionType &vLocal, ReturnType &sum ) const
155  {
156  typedef typename L2Norm< GridPart >::template FunctionDistance< ULocalFunctionType, VLocalFunctionType > LocalDistanceType;
157 
158  IntegratorType integrator( order );
159 
160  LocalDistanceType dist( uLocal, vLocal );
162 
163  integrator.integrateAdd( entity, dist2, sum );
164  }
165 
166 
167  template< class GridPart >
168  template< class LocalFunctionType, class ReturnType >
169  inline void
170  H1Norm< GridPart >::normLocal ( const EntityType &entity, unsigned int order, const LocalFunctionType &uLocal, ReturnType &sum ) const
171  {
172  // evaluate norm locally
173  IntegratorType integrator( order );
174 
176 
177  integrator.integrateAdd( entity, uLocal2, sum );
178  }
179 
180  } // namespace Fem
181 
182 } // namespace Dune
183 
184 #endif // #ifndef DUNE_FEM_H1NORM_HH
BaseType::EntityType EntityType
Definition: h1norm.hh:23
static double sqrt(const Double &v)
Definition: double.hh:870
static constexpr T sum(T a)
Definition: utility.hh:33
Definition: lpnorm.hh:26
FunctionSpaceType::RangeType RangeType
range type
Definition: function.hh:68
Dune::FieldTraits< typename DiscreteFunctionType::RangeFieldType >::real_type norm(const DiscreteFunctionType &u) const
Definition: h1norm.hh:123
void integrateAdd(const EntityType &entity, const Function &function, typename Function::RangeType &ret) const
add the integral over an entity to a variable
Definition: integrator.hh:71
void normLocal(const EntityType &entity, unsigned int order, const LocalFunctionType &uLocal, ReturnType &sum) const
Definition: h1norm.hh:170
ReturnType forEach(const DiscreteFunctionType &u, const ReturnType &initialValue, unsigned int order=0) const
Definition: lpnorm.hh:106
FunctionSpaceType::JacobianRangeType JacobianRangeType
jacobian type
Definition: function.hh:70
GridPartType::template Codim< 0 >::EntityType EntityType
Definition: lpnorm.hh:40
Definition: coordinate.hh:4
FunctionType::RangeFieldType RangeFieldType
Definition: h1norm.hh:72
integrator for arbitrary functions providing evaluate
Definition: integrator.hh:28
Dune::FieldTraits< typename UDiscreteFunctionType::RangeFieldType >::real_type distance(const UDiscreteFunctionType &u, const VDiscreteFunctionType &v) const
Definition: h1norm.hh:138
GridPart GridPartType
Definition: h1norm.hh:20
FunctionJacobianSquare(const FunctionType &function)
Definition: h1norm.hh:77
Integrator< QuadratureType > IntegratorType
Definition: h1norm.hh:30
CachingQuadrature< GridPartType, 0 > QuadratureType
Definition: h1norm.hh:28
Definition: l2norm.hh:19
H1Norm(const GridPartType &gridPart, const unsigned int order=0)
Definition: h1norm.hh:106
GridPartType::CollectiveCommunicationType comm() const
Definition: lpnorm.hh:157
Dune::FieldTraits< typename FunctionType::RangeFieldType >::real_type RealType
Definition: h1norm.hh:73
FunctionSpaceType::RangeFieldType RangeFieldType
field type of range
Definition: function.hh:64
Abstract class representing a function.
Definition: function.hh:43
void evaluate(const Point &x, RangeType &ret) const
Definition: h1norm.hh:82
FieldVector< RealType, 1 > RangeType
Definition: h1norm.hh:74
Function FunctionType
Definition: h1norm.hh:70
const GridPartType & gridPart() const
Definition: lpnorm.hh:155
void distanceLocal(const EntityType &entity, unsigned int order, const ULocalFunctionType &uLocal, const VLocalFunctionType &vLocal, ReturnType &sum) const
Definition: h1norm.hh:154
Definition: h1norm.hh:13