dune-fem 2.12-git
Loading...
Searching...
No Matches
common/scalarproducts.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_SCALARPRODURCTS_HH
2#define DUNE_FEM_SCALARPRODURCTS_HH
3
4#include <iostream>
5#include <memory>
6#include <set>
7#include <map>
8#include <limits>
9#include <algorithm>
10
14
17
18#if HAVE_DUNE_ISTL
20#endif
21
29
30namespace Dune
31{
32
33 namespace Fem
34 {
35
40#if HAVE_DUNE_ISTL
41 template <class DofVector>
42 struct ISTLScalarProductSelector
43 {
45 typedef Dune::BlockVector< Block > type;
46 };
47
48 template <class Block>
49 struct ISTLScalarProductSelector< Dune::Fem::ISTLBlockVector< Block > >
50 : public Dune::ScalarProduct< typename Dune::Fem::ISTLBlockVector< Block > :: DofContainerType >
51 {
52 typedef typename ISTLBlockVector< Block > :: DofContainerType type;
53
54 Dune::SolverCategory::Category category () const override { return SolverCategory::sequential; }
55 };
56#endif
57
60 template< class DiscreteFunction >
62#if HAVE_DUNE_ISTL
63 : public ISTLScalarProductSelector< typename DiscreteFunction :: DofVectorType >
64#endif
65 {
66 public:
67 typedef DiscreteFunction DiscreteFunctionType;
68
70 typedef typename DiscreteFunctionType :: DiscreteFunctionSpaceType
72
73 private:
75
76 public:
78 typedef typename DiscreteFunctionSpaceType :: RangeFieldType RangeFieldType;
79
81 typedef typename DiscreteFunctionSpaceType :: BlockMapperType MapperType;
82
83 // type of communication manager object which does communication
85
88
93
95 {
96 return space_;
97 }
98
100 template < class OtherDiscreteFunctionType >
101 RangeFieldType scalarProductDofs ( const DiscreteFunctionType &x, const OtherDiscreteFunctionType &y ) const
102 {
103 assert(x.space() == y.space());
104 assert(x.space() == space());
105 return dotProduct( x.dofVector(), y.dofVector() );
106 }
107
109 {
110 return space().auxiliaryDofs();
111 }
112
113 protected:
115 template < class DofVector, class OtherDofVector >
116 RangeFieldType dotProduct ( const DofVector &x, const OtherDofVector &y ) const
117 {
118 typedef typename DiscreteFunctionSpaceType::LocalBlockIndices LocalBlockIndices;
119
120 RangeFieldType scp = 0;
121 auto compScp = [&x, &y, &scp]( const size_t dof ){
122 Hybrid::forEach( LocalBlockIndices(), [ &x, &y, &scp, dof ] ( auto &&j ) { scp += x[ dof ][ j ] * y[ dof ][ j ]; } );
123 };
124 // compute scalar product for primary dofs
125 forEachPrimaryDof( space().auxiliaryDofs(), compScp );
126 return space().gridPart().comm().sum( scp );
127 }
128
129#if HAVE_DUNE_ISTL
130 protected:
131 typedef typename ISTLScalarProductSelector< typename DiscreteFunction :: DofVectorType > :: type BlockVectorType;
132
133 public:
135 virtual field_type dot (const BlockVectorType& x,
136 const BlockVectorType& y) const
137 {
138 return dotProduct( x, y );
139 }
140
142 virtual real_type norm( const BlockVectorType& x ) const
143 {
144 return std::abs( std::sqrt( dotProduct( x, x ) ) );
145 }
146
148 void deleteNonInterior( BlockVectorType& x) const
149 {
150#if HAVE_MPI
151 // case of ALUGrid and DGSpace or FVSpace
152 // BUG: We should not use the leafGridView to detect whether the grid has overlap!
153 const bool deleteGhostEntries = (space().gridPart().grid().leafGridView().overlapSize( 0 ) == 0) && !space().continuous();
154
155 // only delete ghost entries
156 if( deleteGhostEntries )
157 {
158 auto delEntry = [&x] (const size_t dof )
159 {
160 x[ dof ] = 0;
161 };
162 forEachAuxiliaryDof( space().auxiliaryDofs(), delEntry );
163 }
164#endif // #if HAVE_MPI
165 }
166#endif // #if HAVE_DUNE_ISTL
168 };
169
171
172 } // end namespace Fem
173
174} // end namespace Dune
175#endif // #ifndef DUNE_FEM_SCALARPRODURCTS_HH
SolverCategory::Category category() const override
auto dot(const A &a, const B &b) -> typename std::enable_if< IsNumber< A >::value &&!IsVector< A >::value &&!std::is_same< typename FieldTraits< A >::field_type, typename FieldTraits< A >::real_type > ::value, decltype(conj(a) *b)>::type
constexpr void forEach(Range &&range, F &&f)
Dune::FieldTraits< RangeFieldType >::real_type real_type
Definition common/scalarproducts.hh:87
const DiscreteFunctionSpaceType & space_
Definition common/scalarproducts.hh:167
const AuxiliaryDofsType & auxiliaryDofs() const
Definition common/scalarproducts.hh:108
const DiscreteFunctionSpaceType & space() const
Definition common/scalarproducts.hh:94
static void forEachAuxiliaryDof(const AuxiliaryDofs &auxiliaryDofs, F &&f)
Apply action encoded in Functor f to all auxiliary dofs.
Definition auxiliarydofs.hh:285
RangeFieldType scalarProductDofs(const DiscreteFunctionType &x, const OtherDiscreteFunctionType &y) const
evaluate scalar product and omit auxiliary nodes
Definition common/scalarproducts.hh:101
AuxiliaryDofs< typename DiscreteFunctionSpaceType::GridPartType, MapperType > AuxiliaryDofsType
Definition common/scalarproducts.hh:84
RangeFieldType field_type
Definition common/scalarproducts.hh:86
DiscreteFunctionSpaceType::BlockMapperType MapperType
type of used mapper
Definition common/scalarproducts.hh:81
DiscreteFunction DiscreteFunctionType
Definition common/scalarproducts.hh:67
ParallelScalarProduct(const DiscreteFunctionSpaceType &space)
constructor taking space
Definition common/scalarproducts.hh:90
RangeFieldType dotProduct(const DofVector &x, const OtherDofVector &y) const
evaluate scalar product on dofVector and omit auxiliary nodes
Definition common/scalarproducts.hh:116
DiscreteFunctionSpaceType::RangeFieldType RangeFieldType
type of range field
Definition common/scalarproducts.hh:78
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of the discrete function space
Definition common/scalarproducts.hh:71
static void forEachPrimaryDof(const AuxiliaryDofs &auxiliaryDofs, F &&f)
Apply action encoded in Functor f to all primary dofs.
Definition auxiliarydofs.hh:303
Dune::Fem::Double abs(const Dune::Fem::Double &a)
Definition double.hh:942
Definition common/scalarproducts.hh:65
In parallel computations the dofs of a discrete function are made up by all primary dofs....
Definition auxiliarydofs.hh:46
T sqrt(T... args)