DUNE-FEM (unstable)

scalarproducts.hh
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 
13 #include <dune/common/ftraits.hh>
14 
15 #include <dune/grid/common/gridenums.hh>
17 
18 #if HAVE_DUNE_ISTL
20 #endif
21 
22 #include <dune/fem/common/hybrid.hh>
23 #include <dune/fem/storage/singletonlist.hh>
24 #include <dune/fem/misc/mpimanager.hh>
25 #include <dune/fem/space/common/auxiliarydofs.hh>
26 #include <dune/fem/space/common/commindexmap.hh>
27 #include <dune/fem/function/blockvectorfunction/declaration.hh>
28 #include <dune/fem/function/blockvectors/defaultblockvectors.hh>
29 
30 namespace 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 
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 
86  typedef RangeFieldType field_type;
87  typedef typename Dune::FieldTraits< RangeFieldType >::real_type real_type;
88 
91  : space_( space )
92  {}
93 
94  const DiscreteFunctionSpaceType &space() const
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 
108  const AuxiliaryDofsType &auxiliaryDofs() const
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
167  const DiscreteFunctionSpaceType &space_;
168  };
169 
171 
172  } // end namespace Fem
173 
174 } // end namespace Dune
175 #endif // #ifndef DUNE_FEM_SCALARPRODURCTS_HH
A vector of blocks with memory management.
Definition: bvector.hh:392
In parallel computations the dofs of a discrete function are made up by all primary dofs....
Definition: auxiliarydofs.hh:46
Definition: scalarproducts.hh:65
TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... > DiscreteFunctionSpaceType
type for the discrete function space this function lives in
Definition: discretefunction.hh:69
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Base class for scalar product and norm computation.
Definition: scalarproducts.hh:52
Describes the parallel communication interface class for MessageBuffers and DataHandles.
A few common exception classes.
Define base class for scalar product and norm.
Type traits to determine the type of reals (when working with complex numbers)
Implements a generic iterator class for writing stl conformant iterators.
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
computes the dot product for fundamental data types according to Petsc's VectDot function: dot(a,...
Definition: dotproduct.hh:42
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: scalarproducts.hh:101
DiscreteFunctionType ::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of the discrete function space
Definition: scalarproducts.hh:71
DiscreteFunctionSpaceType ::RangeFieldType RangeFieldType
type of range field
Definition: scalarproducts.hh:78
ParallelScalarProduct(const DiscreteFunctionSpaceType &space)
constructor taking space
Definition: scalarproducts.hh:90
DiscreteFunctionSpaceType ::BlockMapperType MapperType
type of used mapper
Definition: scalarproducts.hh:81
RangeFieldType dotProduct(const DofVector &x, const OtherDofVector &y) const
evaluate scalar product on dofVector and omit auxiliary nodes
Definition: scalarproducts.hh:116
static void forEachPrimaryDof(const AuxiliaryDofs &auxiliaryDofs, F &&f)
Apply action encoded in Functor f to all primary dofs.
Definition: auxiliarydofs.hh:303
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
Dune namespace.
Definition: alignedallocator.hh:13
Category
Definition: solvercategory.hh:23
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:25
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)