1#ifndef DUNE_FEM_SOLVER_COMMUNICATION_HIERARCHICAL_HH
2#define DUNE_FEM_SOLVER_COMMUNICATION_HIERARCHICAL_HH
11#include <dune/istl/multitypeblockvector.hh>
12#include <dune/istl/solvercategory.hh>
14#include <dune/fem/common/hybrid.hh>
15#include <dune/fem/function/hierarchical/dofvector.hh>
16#include <dune/fem/space/common/commoperations.hh>
30 template<
class DiscreteFunctionSpace,
class DofContainer >
31 class HierarchicalCommunicationVector
33 typedef HierarchicalCommunicationVector< DiscreteFunctionSpace, DofContainer > ThisType;
38 typedef typename Dune::Fem::Impl::BlockIndicesFor< DofContainer >::Type BlockIndices;
41 typedef HierarchicalDofBlock< const DofContainer > ConstDofBlockType;
42 typedef HierarchicalDofBlock< DofContainer > DofBlockType;
44 explicit DofVector ( DofContainer &data ) : data_( data ) {}
46 ConstDofBlockType operator[] ( std::size_t i )
const {
return ConstDofBlockType( data_, i ); }
47 DofBlockType operator[] ( std::size_t i ) {
return DofBlockType( data_, i ); }
55 typedef typename DiscreteFunctionSpaceType::LocalBlockIndices BlockIndices;
57 static constexpr std::size_t blockSize = Hybrid::size( BlockIndices() );
59 typedef typename DofContainer::field_type DofType;
61 template<
class Operation >
64 typedef typename DiscreteFunctionSpaceType::template CommDataHandle< ThisType, Operation >::Type Type;
68 : dfSpace_( dfSpace ), dofVector_( dofContainer )
71 template<
class Operation >
72 typename CommDataHandle< Operation >::Type dataHandle (
const Operation &operation )
74 return space().createDataHandle( *
this, operation );
77 const DofVector &dofVector ()
const {
return dofVector_; }
78 DofVector &dofVector () {
return dofVector_; }
80 const DiscreteFunctionSpaceType &space ()
const {
return dfSpace_; }
92 template<
class DiscreteFunctionSpace >
93 class HierarchicalCommunication
95 typedef HierarchicalCommunication< DiscreteFunctionSpace > ThisType;
97 typedef typename DiscreteFunctionSpace::AuxiliaryDofsType AuxiliaryDofsType;
103 : dfSpace_( dfSpace ), solverCategory_( solverCategory )
109 void copyOwnerToAll (
const T &x, T &y )
const
113 HierarchicalCommunicationVector< DiscreteFunctionSpaceType, T > z( dfSpace_, y );
114 dfSpace_.communicator().exchange( z, DFCommunicationOperation::Add() );
118 void project ( T &x )
const
120 project( dfSpace_.auxiliaryDofs(), x );
123 template<
class T,
class F >
124 void dot (
const T &x,
const T &y, F &scp )
const
126 dot( dfSpace_.auxiliaryDofs(), x, y, scp );
127 scp = communicator().sum( scp );
131 typename Dune::FieldTraits< typename T::field_type >::real_type norm (
const T &x )
const
134 typename Dune::FieldTraits< typename T::field_type >::real_type norm2( 0 );
136 return sqrt( norm2 );
142 template<
class... V >
143 static void project (
const AuxiliaryDofsType &auxiliaryDofs, MultiTypeBlockVector< V... > &x )
145 Dune::Hybrid::forEach( std::index_sequence_for< V... >(), [ &auxiliaryDofs, &x ] (
auto &&i ) { ThisType::project( auxiliaryDofs, x[ i ] ); } );
148 template<
class B,
class A >
149 static void project (
const AuxiliaryDofsType &auxiliaryDofs, BlockVector< B, A > &x )
151 typedef typename B::field_type field_type;
152 for(
int i : auxiliaryDofs )
153 x[ i ] = field_type( 0 );
156 template<
class... V,
class F >
157 static void dot (
const AuxiliaryDofsType &auxiliaryDofs,
const MultiTypeBlockVector< V... > &x,
const MultiTypeBlockVector< V... > &y, F &scp )
162 template<
class B,
class A,
class F >
163 static void dot (
const AuxiliaryDofsType &auxiliaryDofs,
const BlockVector< B, A > &x,
const BlockVector< B, A > &y, F &scp )
165 const int numAuxiliarys = auxiliaryDofs.size();
166 for(
int auxiliary = 0, i = 0; auxiliary < numAuxiliarys; ++auxiliary, ++i )
168 const int nextAuxiliary = auxiliaryDofs[ auxiliary ];
169 for( ; i < nextAuxiliary; ++i )
170 scp += x[ i ] * y[ i ];
174 const DiscreteFunctionSpaceType &dfSpace_;
183 template<
class DiscreteFunctionSpace >
186 std::shared_ptr< HierarchicalCommunication< DiscreteFunctionSpace > > &communication )
188 communication.reset(
new HierarchicalCommunication< DiscreteFunctionSpace >( dfSpace, solverCategory ) );
199 template<
class DiscreteFunctionSpace >
201 :
public std::false_type
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Traits::CommunicationType CommunicationType
Collective communication.
Definition: gridpart.hh:97
Type traits to determine the type of reals (when working with complex numbers)
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
constexpr auto size(const T &t)
Size query.
Definition: hybridutilities.hh:73
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