DUNE-FEM (unstable)

discretefunction.hh
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
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>
15
16#include <dune/fem/function/tuplediscretefunction/dofvector.hh>
17#include <dune/fem/space/combinedspace.hh>
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 ... > >
34 : public DefaultDiscreteFunctionTraits<
35 TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... >,
36 TupleDofVector< typename DiscreteFunctions::DofVectorType ... >
37 >
38 {
39 typedef TupleDiscreteFunction< DiscreteFunctions ... > DiscreteFunctionType;
40 typedef MutableLocalFunction< DiscreteFunctionType > LocalFunctionType;
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,
86 DofVectorType &dofVector )
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
99 TupleDiscreteFunction ( const ThisType &other )
100 : TupleDiscreteFunction ( "copy of "+other.name(), other.space(), Sequence() )
101 {
102 dofVector_ = other.dofVector();
103 }
104
105 // move constructor
106 TupleDiscreteFunction ( ThisType&& other )
107 : BaseType ( static_cast< BaseType && >( other ) ),
108 DiscreteFunctionTuple( std::move( other ) ),
109 dofVector_( std::move( other.dofVector_ ) )
110 {}
111
112 TupleDiscreteFunction () = delete;
113 ThisType &operator= ( const ThisType & ) = delete;
114
115 DofVectorType &dofVector () { return dofVector_; }
116 const DofVectorType &dofVector () const { return dofVector_; }
117
118 template< int i >
119 typename SubDiscreteFunction< i >::Type& subDiscreteFunction()
120 {
121 return std::get< i >( *this );
122 }
123
124 template< int i >
125 const typename SubDiscreteFunction< i >::Type& subDiscreteFunction() const
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 >
149 TupleDiscreteFunction ( const std::string &name, const DiscreteFunctionSpaceType &space,
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 ) ) ... ),
156 dofVector_( dofVector )
157 {}
158
159 DofVectorType dofVector_;
160 };
161
162 } // namespace Fem
163
164} // namespace Dune
165
166#endif // #ifndef DUNE_FEM_FUNCTION_TUPLEDISCRETEFUNCTION_DISCRETEFUNCTION_HH
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
STL namespace.
helper struct to get the type of the i-th sub function
Definition: discretefunction.hh:74
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)