1#ifndef DUNE_FEM_FUNCTION_TUPLEDISCRETEFUNCTION_DISCRETEFUNCTION_HH
2#define DUNE_FEM_FUNCTION_TUPLEDISCRETEFUNCTION_DISCRETEFUNCTION_HH
8#include <dune/common/hybridutilities.hh>
10#include <dune/fem/common/stackallocator.hh>
11#include <dune/fem/function/common/discretefunction.hh>
12#include <dune/fem/function/common/scalarproducts.hh>
13#include <dune/fem/function/localfunction/mutable.hh>
14#include <dune/fem/function/tuplediscretefunction/functor.hh>
16#include <dune/fem/function/tuplediscretefunction/dofvector.hh>
17#include <dune/fem/space/combinedspace.hh>
26 template<
class ... DiscreteFunctions >
27 class TupleDiscreteFunction;
32 template<
class ... DiscreteFunctions >
33 struct DiscreteFunctionTraits< TupleDiscreteFunction< DiscreteFunctions ... > >
34 :
public DefaultDiscreteFunctionTraits<
35 TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... >,
36 TupleDofVector< typename DiscreteFunctions::DofVectorType ... >
47 template<
class ... DiscreteFunctions >
50 public std::tuple< DiscreteFunctions ... >
57 typedef std::tuple< DiscreteFunctions ... > DiscreteFunctionTuple;
59 static_assert(
sizeof ... ( DiscreteFunctions ) > 0,
"TupleDiscreteFunction needs at least one DiscreteFunction." );
62 typedef decltype ( std::index_sequence_for< DiscreteFunctions ... >() ) Sequence;
64 typedef TupleDofVector<
typename DiscreteFunctions::DofVectorType ... > DofVectorType;
75 typedef typename std::tuple_element< i, DiscreteFunctionTuple >::type Type;
86 DofVectorType &dofVector )
102 dofVector_ = other.dofVector();
106 TupleDiscreteFunction ( ThisType&& other )
107 : BaseType ( static_cast< BaseType && >( other ) ),
108 DiscreteFunctionTuple(
std::move( other ) ),
109 dofVector_(
std::move( other.dofVector_ ) )
112 TupleDiscreteFunction () =
delete;
113 ThisType &operator= (
const ThisType & ) =
delete;
115 DofVectorType &dofVector () {
return dofVector_; }
116 const DofVectorType &dofVector ()
const {
return dofVector_; }
119 typename SubDiscreteFunction< i >::Type& subDiscreteFunction()
121 return std::get< i >( *
this );
125 const typename SubDiscreteFunction< i >::Type& subDiscreteFunction()
const
127 return std::get< i >( *
this );
133 Hybrid::forEach( Sequence{}, [ & ](
auto i ){ std::get< i >( *this ).enableDofCompression(); } );
138 template< std::size_t ... I >
141 DiscreteFunctionTuple(
142 typename SubDiscreteFunction< I >::Type(
143 name +
"_comp_" +
std::to_string( I ),
space.template subDiscreteFunctionSpace< I >()
145 dofVector_(
std::
get< I >( *this ).dofVector() ... )
148 template< std::size_t ... I >
149 TupleDiscreteFunction (
const std::string &
name,
const DiscreteFunctionSpaceType &
space,
150 DofVectorType &dofVector, std::index_sequence< I ... > )
152 DiscreteFunctionTuple(
153 typename SubDiscreteFunction< I >::Type(
154 name +
"_comp_" +
std::to_string( I ),
space.template subDiscreteFunctionSpace< I >(),
155 std::
get< I >( dofVector ) ) ... ),
156 dofVector_( dofVector )
159 DofVectorType dofVector_;
Definition: discretefunction.hh:584
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: discretefunction.hh:709
const std::string & name() const
obtain the name of the discrete function
Definition: discretefunction.hh:691
Definition: scalarproducts.hh:65
forward declaration
Definition: discretefunction.hh:51
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: discretefunction.hh:709
TupleDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &dfSpace)
Constructor to use if the vector storing the dofs does not exist yet.
Definition: discretefunction.hh:94
TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... > DiscreteFunctionSpaceType
type for the discrete function space this function lives in
Definition: discretefunction.hh:69
TupleDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &dfSpace, DofVectorType &dofVector)
Constructor to use if the vector storing the dofs (which is a block vector) already exists.
Definition: discretefunction.hh:84
void enableDofCompression()
Enable this discrete function for dof compression, i.e. during grid changes a dof compression is done...
Definition: discretefunction.hh:131
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
Dune namespace.
Definition: alignedallocator.hh:13
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
helper struct to get the type of the i-th sub function
Definition: discretefunction.hh:74