1#ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLESPACE_HH
2#define DUNE_FEM_SPACE_COMBINEDSPACE_TUPLESPACE_HH
9#include <dune/common/hybridutilities.hh>
14#include <dune/fem/common/memory.hh>
15#include <dune/fem/common/utility.hh>
16#include <dune/fem/space/basisfunctionset/tuple.hh>
17#include <dune/fem/space/combinedspace/generic.hh>
18#include <dune/fem/space/combinedspace/interpolation.hh>
19#include <dune/fem/space/combinedspace/tuplelocalrestrictprolong.hh>
20#include <dune/fem/space/combinedspace/tuplemapper.hh>
21#include <dune/fem/space/common/defaultcommhandler.hh>
22#include <dune/fem/space/mapper/nonblockmapper.hh>
23#include <dune/fem/space/common/localinterpolation.hh>
32 template<
class CombineOp,
class ... DiscreteFunctionSpaces >
33 class TupleDiscreteFunctionSpaceImpl;
38 template<
class CombineOp,
class ... DiscreteFunctionSpaces >
39 struct TupleDiscreteFunctionSpaceTraits
41 static_assert(
sizeof ... ( DiscreteFunctionSpaces ) > 0,
42 "You should provide at least one space to the TupleDiscreteFunctionSpace" );
45 typedef std::tuple< std::shared_ptr< DiscreteFunctionSpaces > ... > DiscreteFunctionSpaceTupleType;
50 struct SubDiscreteFunctionSpace
53 typedef typename std::tuple_element< i, DiscreteFunctionSpaceTupleType >::type::element_type Type;
56 typedef typename Type::BlockMapperType BlockMapperType;
59 typedef NonBlockMapper< BlockMapperType, Type::localBlockSize > NonBlockMapperType;
62 static const Type &subDiscreteFunctionSpace (
const DiscreteFunctionSpaceTupleType &tuple )
64 assert( std::get< i >( tuple ) );
65 return *( std::get< i >( tuple ) );
68 static BlockMapperType &subBlockMapper (
const DiscreteFunctionSpaceTupleType &tuple )
70 return subDiscreteFunctionSpace( tuple ).blockMapper();
73 static NonBlockMapperType subNonBlockMapper (
const DiscreteFunctionSpaceTupleType &tuple )
75 return NonBlockMapperType( subDiscreteFunctionSpace( tuple ).blockMapper() );
80 static_assert( Std::are_all_same< typename DiscreteFunctionSpaces::GridPartType::template Codim< 0 >::EntityType ... >::value,
81 "TupleDiscreteFunctionSpace works only for GridPart's with the same entity type" );
83 static_assert( Std::are_all_same< std::integral_constant< int, DiscreteFunctionSpaces::Traits::codimension > ... >::value,
84 "TupleDiscreteFunctionSpace for spaces with different codimensions is not supported" );
85 static const int codimension = SubDiscreteFunctionSpace< 0 >::Type::Traits::codimension;
87 typedef typename SubDiscreteFunctionSpace< 0 >::Type::GridPartType GridPartType;
88 typedef typename GridPartType::GridType GridType;
90 typedef typename GridPartType::template Codim< 0 >::IteratorType IteratorType;
91 typedef typename IteratorType::Entity EntityType;
95 typedef TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > DiscreteFunctionSpaceType;
98 typedef TupleBasisFunctionSet< CombineOp,
typename DiscreteFunctionSpaces::BasisFunctionSetType ... > BasisFunctionSetType;
101 typedef TupleMapper< GridPartType, NonBlockMapper< typename DiscreteFunctionSpaces::BlockMapperType, DiscreteFunctionSpaces::localBlockSize > ... > BlockMapperType;
104 typedef std::index_sequence< 0 > LocalBlockIndices;
109 typedef TupleSpaceInterpolation< CombineOp, DiscreteFunctionSpaces ... > InterpolationImplType;
112 template<
class DiscreteFunction,
class Operation = DFCommunicationOperation::Copy >
113 struct CommDataHandle
116 typedef DefaultCommunicationHandler< DiscreteFunction, Operation > Type;
118 typedef Operation OperationType;
122 static BlockMapperType *getBlockMapper (
const DiscreteFunctionSpaceTupleType &spaceTuple )
124 return getBlockMapper( spaceTuple, std::index_sequence_for< DiscreteFunctionSpaces ... >() );
128 static DiscreteFunctionSpaceTupleType createSpaces ( GridPartType &gridPart,
InterfaceType commInterface,
131 DiscreteFunctionSpaceTupleType tuple;
132 Hybrid::forEach( std::make_index_sequence<
sizeof ... ( DiscreteFunctionSpaces ) >{},
135 typedef typename SubDiscreteFunctionSpace< i >::Type Element;
136 std::get< i >( tuple ) = std::make_shared< Element >( gridPart, commInterface, commDirection );
141 template<
class Entity >
142 static BasisFunctionSetType getBasisFunctionSet (
const Entity &entity,
const DiscreteFunctionSpaceTupleType &tuple )
144 return getBasisFunctionSet( entity, tuple, std::index_sequence_for< DiscreteFunctionSpaces ... >() );
147 template<
class T,
class F >
148 static T
accumulate (
const DiscreteFunctionSpaceTupleType &tuple, T value, F &&f )
150 Hybrid::forEach( std::index_sequence_for< DiscreteFunctionSpaces... >{}, [ & ] (
auto &&idx ) {
151 const std::size_t i = std::decay_t<
decltype( idx ) >::value;
152 value = f( value, SubDiscreteFunctionSpace< i >::subDiscreteFunctionSpace( tuple ) );
158 template< std::size_t ... i >
159 static BlockMapperType *getBlockMapper (
const DiscreteFunctionSpaceTupleType &tuple, std::index_sequence< i ... > )
161 return new BlockMapperType( SubDiscreteFunctionSpace< 0 >::subDiscreteFunctionSpace( tuple ).gridPart(),
162 SubDiscreteFunctionSpace< i >::subNonBlockMapper( tuple ) ... );
165 template<
class Entity, std::size_t ... i >
166 static BasisFunctionSetType getBasisFunctionSet (
const Entity &entity,
const DiscreteFunctionSpaceTupleType &tuple,
167 std::index_sequence< i ... > )
169 return BasisFunctionSetType( SubDiscreteFunctionSpace< i >::subDiscreteFunctionSpace( tuple ).basisFunctionSet( entity ) ... );
189 template<
class CombineOp,
class ... DiscreteFunctionSpaces >
190 class TupleDiscreteFunctionSpaceImpl
191 :
public GenericCombinedDiscreteFunctionSpace< TupleDiscreteFunctionSpaceTraits< CombineOp, DiscreteFunctionSpaces ... > >
193 typedef TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > ThisType;
194 typedef GenericCombinedDiscreteFunctionSpace< TupleDiscreteFunctionSpaceTraits< CombineOp, DiscreteFunctionSpaces ... > > BaseType;
197 typedef decltype ( std::index_sequence_for< DiscreteFunctionSpaces ... >() ) Sequence;
198 typedef typename BaseType::Traits Traits;
199 typedef typename BaseType::GridPartType GridPartType;
200 typedef typename BaseType::EntityType EntityType;
202 typedef typename Traits::InterpolationImplType InterpolationImplType;
204 typedef LocalInterpolationWrapper< ThisType > InterpolationType;
205 typedef typename Traits::DiscreteFunctionSpaceTupleType DiscreteFunctionSpaceTupleType;
215 typename = std::enable_if_t<(... &&
216 std::is_constructible<DiscreteFunctionSpaces, GP&>::value)> >
217 TupleDiscreteFunctionSpaceImpl ( GP &gridPart,
220 : BaseType( gridPart, commInterface, commDirection )
230 TupleDiscreteFunctionSpaceImpl ( DiscreteFunctionSpaces &&... spaces )
231 : BaseType(
std::make_tuple(
std::make_shared(
std::move( spaces ) )... ) )
241 TupleDiscreteFunctionSpaceImpl (
const DiscreteFunctionSpaces &... spaces )
242 : BaseType(
std::make_tuple( referenceToSharedPtr( spaces )... ) )
252 TupleDiscreteFunctionSpaceImpl ( std::shared_ptr< const DiscreteFunctionSpaces >... spaces )
253 : BaseType(
std::make_tuple(
std::move( spaces )... ) )
263 explicit TupleDiscreteFunctionSpaceImpl ( DiscreteFunctionSpaceTupleType spaceTuple )
264 : BaseType(
std::move( spaceTuple ) )
267 TupleDiscreteFunctionSpaceImpl (
const ThisType & ) =
delete;
268 ThisType &operator= (
const ThisType & ) =
delete;
271 std::tuple<
const DiscreteFunctionSpaces & ... > spaceTuple ()
const
273 return spaceTuple( std::index_sequence_for< DiscreteFunctionSpaces ... >() );
276 InterpolationType interpolation()
const
278 return InterpolationType( *
this );
282 InterpolationImplType interpolation (
const EntityType &entity )
const
284 return localInterpolation( entity );
287 InterpolationImplType localInterpolation (
const EntityType &entity )
const
289 return localInterpolation( entity, std::index_sequence_for< DiscreteFunctionSpaces ... >() );
293 template< std::size_t ... i >
294 std::tuple<
const DiscreteFunctionSpaces & ... > spaceTuple ( std::index_sequence< i ... > )
const
296 return std::tuple<
const DiscreteFunctionSpaces & ... >( BaseType::template subDiscreteFunctionSpace< i >() ... );
299 template< std::size_t ... i >
300 InterpolationImplType localInterpolation (
const EntityType &entity, std::index_sequence< i ... > )
const
302 return InterpolationImplType( std::get< i >( spaceTuple() ) ..., entity );
312 template<
class CombineOp,
class ... DiscreteFunctionSpaces,
class NewFunctionSpace >
313 struct DifferentDiscreteFunctionSpace< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces... >, NewFunctionSpace >
315 static_assert( (NewFunctionSpace::dimRange % TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces... >::dimRange == 0),
316 "DifferentDiscreteFunctionSpace can only be applied to TupleFunctionSpace, if new dimRange is a multiple of the original one." );
319 static const int factor = (NewFunctionSpace::dimRange / TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces... >::dimRange);
321 template<
class DiscreteFunctionSpace >
325 typedef TupleDiscreteFunctionSpaceImpl< CombineOp, typename DifferentDiscreteFunctionSpace< DiscreteFunctionSpaces, NewSubFunctionSpace< DiscreteFunctionSpaces > >::Type... > Type;
333 template<
class CombineOp,
class ... DiscreteFunctionSpaces >
334 class DefaultLocalRestrictProlong< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > >
335 :
public TupleLocalRestrictProlong< DiscreteFunctionSpaces ... >
337 typedef DefaultLocalRestrictProlong< TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > > ThisType;
338 typedef TupleDiscreteFunctionSpaceImpl< CombineOp, DiscreteFunctionSpaces ... > DiscreteFunctionSpacesType;
339 typedef TupleLocalRestrictProlong< DiscreteFunctionSpaces ... > BaseType;
342 DefaultLocalRestrictProlong (
const DiscreteFunctionSpacesType &space )
343 : BaseType( space.spaceTuple() )
349 template <
class ... DiscreteFunctionSpaces >
350 using TupleDiscreteFunctionSpace = TupleDiscreteFunctionSpaceImpl< TupleSpaceProduct, DiscreteFunctionSpaces ... >;
353 template <
class ... DiscreteFunctionSpaces >
354 using SummationDiscreteFunctionSpace = TupleDiscreteFunctionSpaceImpl< TupleSpaceSummation, DiscreteFunctionSpaces ... >;
356 template <
class ... DiscreteFunctionSpaces >
357 using EnrichedDiscreteFunctionSpace = SummationDiscreteFunctionSpace< DiscreteFunctionSpaces ... >;
IntersectionIteratorType::Intersection IntersectionType
type of intersection
Definition: adaptiveleafgridpart.hh:95
consecutive, persistent index set for the leaf level based on the grid's hierarchy index set
Definition: adaptiveleafindexset.hh:1351
A vector valued function space.
Definition: functionspace.hh:60
Different resources needed by all grid implementations.
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:279
Some useful basic math stuff.
Dune namespace.
Definition: alignedallocator.hh:13
convert functions space to space with new dim range
Definition: functionspace.hh:250