dune-fem 2.8.0
Loading...
Searching...
No Matches
tuplediscretefunction/discretefunction.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_FUNCTION_TUPLEDISCRETEFUNCTION_DISCRETEFUNCTION_HH
2#define DUNE_FEM_FUNCTION_TUPLEDISCRETEFUNCTION_DISCRETEFUNCTION_HH
3
4#include <string>
5#include <tuple>
6#include <utility>
7
8#include <dune/common/hybridutilities.hh>
9
15
18
19namespace Dune
20{
21
22 namespace Fem
23 {
24
26 template< class ... DiscreteFunctions >
27 class TupleDiscreteFunction;
28
29 // DiscreteFunctionTraits
30 // ----------------------
31
32 template< class ... DiscreteFunctions >
33 struct DiscreteFunctionTraits< TupleDiscreteFunction< DiscreteFunctions ... > >
35 TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... >,
36 TupleDofVector< typename DiscreteFunctions::DofVectorType ... >
37 >
38 {
39 typedef TupleDiscreteFunction< DiscreteFunctions ... > DiscreteFunctionType;
41 };
42
43
44 // TupleDiscreteFunction
45 // ---------------------
46
47 template< class ... DiscreteFunctions >
49 : public DiscreteFunctionDefault< TupleDiscreteFunction< DiscreteFunctions ... > >,
50 public std::tuple< DiscreteFunctions ... >
51 {
52 typedef TupleDiscreteFunction< DiscreteFunctions ... > ThisType;
54
56
57 typedef std::tuple< DiscreteFunctions ... > DiscreteFunctionTuple;
58
59 static_assert( sizeof ... ( DiscreteFunctions ) > 0, "TupleDiscreteFunction needs at least one DiscreteFunction." );
60
61 public:
62 typedef decltype ( std::index_sequence_for< DiscreteFunctions ... >() ) Sequence;
63
64 typedef TupleDofVector< typename DiscreteFunctions::DofVectorType ... > DofVectorType;
65
66 using BaseType::space;
67
69 typedef TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... > DiscreteFunctionSpaceType;
70
72 template< int i >
74 {
75 typedef typename std::tuple_element< i, DiscreteFunctionTuple >::type Type;
76 };
77
84 TupleDiscreteFunction ( const std::string &name,
85 const DiscreteFunctionSpaceType &dfSpace,
87 : TupleDiscreteFunction ( name, dfSpace, dofVector, Sequence() ) {}
88
94 TupleDiscreteFunction ( const std::string &name,
95 const DiscreteFunctionSpaceType &dfSpace )
96 : TupleDiscreteFunction ( name, dfSpace, Sequence() ) {}
97
98 // copy constructor
100 : TupleDiscreteFunction ( "copy of "+other.name(), other.space(), Sequence() )
101 {
102 dofVector_ = other.dofVector();
103 }
104
105 // move constructor
107 : BaseType ( static_cast< BaseType && >( other ) ),
108 DiscreteFunctionTuple( std::move( other ) ),
109 dofVector_( std::move( other.dofVector_ ) )
110 {}
111
113 ThisType &operator= ( const ThisType & ) = delete;
114
116 const DofVectorType &dofVector () const { return dofVector_; }
117
118 template< int i >
120 {
121 return std::get< i >( *this );
122 }
123
124 template< int i >
126 {
127 return std::get< i >( *this );
128 }
129
132 {
133 Hybrid::forEach( Sequence{}, [ & ]( auto i ){ std::get< i >( *this ).enableDofCompression(); } );
134 }
135
136 protected:
137
138 template< std::size_t ... I >
139 TupleDiscreteFunction ( const std::string &name, const DiscreteFunctionSpaceType &space, std::index_sequence< I ... > )
140 : BaseType( name, space ),
141 DiscreteFunctionTuple(
142 typename SubDiscreteFunction< I >::Type(
143 name + "_comp_" + std::to_string( I ), space.template subDiscreteFunctionSpace< I >()
144 ) ... ),
145 dofVector_( std::get< I >( *this ).dofVector() ... )
146 {}
147
148 template< std::size_t ... I >
150 DofVectorType &dofVector, std::index_sequence< I ... > )
151 : BaseType( name, space ),
152 DiscreteFunctionTuple(
153 typename SubDiscreteFunction< I >::Type(
154 name + "_comp_" + std::to_string( I ), space.template subDiscreteFunctionSpace< I >(),
155 std::get< I >( dofVector ) ) ... ),
157 {}
158
160 };
161
162 } // namespace Fem
163
164} // namespace Dune
165
166#endif // #ifndef DUNE_FEM_FUNCTION_TUPLEDISCRETEFUNCTION_DISCRETEFUNCTION_HH
STL namespace.
Definition: bindguard.hh:11
std::tuple_element< i, Tuple >::type & get(Dune::TypeIndexedTuple< Tuple, Types > &tuple)
Definition: typeindexedtuple.hh:122
static void forEach(IndexRange< T, sz > range, F &&f)
Definition: hybrid.hh:129
Traits class for a DiscreteFunction.
Definition: common/discretefunction.hh:61
Definition: common/discretefunction.hh:584
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: common/discretefunction.hh:709
const std::string & name() const
obtain the name of the discrete function
Definition: common/discretefunction.hh:691
Definition: common/discretefunction.hh:1081
Definition: common/scalarproducts.hh:73
forward declaration
Definition: tuplediscretefunction/discretefunction.hh:51
const DofVectorType & dofVector() const
Definition: tuplediscretefunction/discretefunction.hh:116
const SubDiscreteFunction< i >::Type & subDiscreteFunction() const
Definition: tuplediscretefunction/discretefunction.hh:125
TupleDiscreteFunction(const ThisType &other)
Definition: tuplediscretefunction/discretefunction.hh:99
decltype(std::index_sequence_for< DiscreteFunctions ... >()) Sequence
Definition: tuplediscretefunction/discretefunction.hh:62
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: common/discretefunction.hh:709
TupleDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, std::index_sequence< I ... >)
Definition: tuplediscretefunction/discretefunction.hh:139
TupleDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, DofVectorType &dofVector, std::index_sequence< I ... >)
Definition: tuplediscretefunction/discretefunction.hh:149
DofVectorType dofVector_
Definition: tuplediscretefunction/discretefunction.hh:159
TupleDiscreteFunction(ThisType &&other)
Definition: tuplediscretefunction/discretefunction.hh:106
TupleDofVector< typename DiscreteFunctions::DofVectorType ... > DofVectorType
Definition: tuplediscretefunction/discretefunction.hh:64
TupleDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &dfSpace)
Constructor to use if the vector storing the dofs does not exist yet.
Definition: tuplediscretefunction/discretefunction.hh:94
DofVectorType & dofVector()
Definition: tuplediscretefunction/discretefunction.hh:115
TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... > DiscreteFunctionSpaceType
type for the discrete function space this function lives in
Definition: tuplediscretefunction/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: tuplediscretefunction/discretefunction.hh:84
ThisType & operator=(const ThisType &)=delete
SubDiscreteFunction< i >::Type & subDiscreteFunction()
Definition: tuplediscretefunction/discretefunction.hh:119
void enableDofCompression()
Enable this discrete function for dof compression, i.e. during grid changes a dof compression is done...
Definition: tuplediscretefunction/discretefunction.hh:131
MutableLocalFunction< DiscreteFunctionType > LocalFunctionType
Definition: tuplediscretefunction/discretefunction.hh:40
TupleDiscreteFunction< DiscreteFunctions ... > DiscreteFunctionType
Definition: tuplediscretefunction/discretefunction.hh:39
helper struct to get the type of the i-th sub function
Definition: tuplediscretefunction/discretefunction.hh:74
std::tuple_element< i, DiscreteFunctionTuple >::type Type
Definition: tuplediscretefunction/discretefunction.hh:75
Definition: tuplediscretefunction/dofvector.hh:30
Definition: tuplespace.hh:192