KASKADE 7 development version
systemTraits.hh
Go to the documentation of this file.
1#ifndef SYSTEMTRAITS_HH
2#define SYSTEMTRAITS_HH
3
6
8
9namespace Dune
10{
11 template <class,class> class Preconditioner;
12}
13
14namespace Kaskade
15{
16 template <class,class,class,class> class PreconditionerFactory;
17
18 namespace SystemTraits_Detail
19 {
20 template <class Functional>
21 std::integral_constant<int,Functional::stateId> getStateIdImpl(decltype(Functional::stateId)*);
22
23 template <class Functional>
24 std::integral_constant<int,Functional::yIdx> getStateIdImpl(decltype(Functional::yIdx)*);
25
26 template <class Functional>
27 std::integral_constant<int,Functional::controlId> getControlIdImpl(decltype(Functional::controlId)*);
28
29 template <class Functional>
30 std::integral_constant<int,Functional::uIdx> getControlIdImpl(decltype(Functional::uIdx)*);
31
32 template <class Functional>
33 std::integral_constant<int,Functional::adjointId> getAdjointIdImpl(decltype(Functional::adjointId)*);
34
35 template <class Functional>
36 std::integral_constant<int,Functional::pIdx> getAdjointIdImpl(decltype(Functional::pIdx)*);
37
38 template <class Functional>
39 std::integral_constant<int,Functional::lIdx> getAdjointIdImpl(decltype(Functional::lIdx)*);
40 }
41
42
43 template <class Functional>
44 constexpr int getStateId()
45 {
46 typedef decltype(SystemTraits_Detail::getStateIdImpl<Functional>(nullptr)) type;
47 return type::value;
48 }
49
50 template <class Functional>
51 constexpr int getControlId()
52 {
53 typedef decltype(SystemTraits_Detail::getControlIdImpl<Functional>(nullptr)) type;
54 return type::value;
55 }
56
57 template <class Functional>
58 constexpr int getAdjointId()
59 {
60 typedef decltype(SystemTraits_Detail::getAdjointIdImpl<Functional>(nullptr)) type;
61 return type::value;
62 }
63
64
65 template <class Functional, class Assembler>
66 struct OptimalControlTraits
67 {
68 // variable ids
69 static constexpr int yIdx = getStateId<Functional>();
70 static constexpr int uIdx = getControlId<Functional>();
71 static constexpr int pIdx = getAdjointId<Functional>();
72
73 static constexpr int stateId = yIdx;
74 static constexpr int adjointId = pIdx;
75 static constexpr int controlId = uIdx;
76
77 // grid
78 typedef typename Assembler::Grid Grid;
79
80 // spaces
81 typedef typename Assembler::Spaces Spaces;
82
83 // variable set descriptions
84 typedef typename Assembler::AnsatzVariableSetDescription AnsatzVariableSetDescription;
85 typedef typename Assembler::TestVariableSetDescription TestVariableSetDescription;
86
87 // spaces associated with variables
88 static constexpr int stateSpaceId = boost::fusion::result_of::value_at_c<typename AnsatzVariableSetDescription::Variables,stateId>::type::spaceIndex;
89 static constexpr int controlSpaceId = boost::fusion::result_of::value_at_c<typename AnsatzVariableSetDescription::Variables,controlId>::type::spaceIndex;
90 static constexpr int adjointSpaceId = boost::fusion::result_of::value_at_c<typename AnsatzVariableSetDescription::Variables,adjointId>::type::spaceIndex;
91
92 // components of each variable
93 static constexpr int stateComponents = AnsatzVariableSetDescription::template Components<stateId>::m;
94 static constexpr int controlComponents = AnsatzVariableSetDescription::template Components<controlId>::m;
95 static constexpr int adjointComponents = AnsatzVariableSetDescription::template Components<adjointId>::m;
96 static_assert(stateComponents == adjointComponents, "state and adjoint variables should have the same number of components");
97
98 // operators
99 typedef AssembledGalerkinOperator<Assembler> SystemOperator;
100 typedef AssembledGalerkinOperator<Assembler,pIdx,pIdx+1,yIdx,yIdx+1> StateOperator;
101 typedef AssembledGalerkinOperator<Assembler,pIdx,pIdx+1,uIdx,uIdx+1> ControlOperator;
102 typedef AssembledGalerkinOperator<Assembler,yIdx,yIdx+1,pIdx,pIdx+1> AdjointOperator;
103 typedef AssembledGalerkinOperator<Assembler,uIdx,uIdx+1,uIdx,uIdx+1> NormUOperator;
104 typedef AssembledGalerkinOperator<Assembler,yIdx,yIdx+1,yIdx,yIdx+1> NormYOperator;
105 typedef AssembledGalerkinOperator<Assembler,uIdx,uIdx+1,yIdx,yIdx+1> NormUYOperator;
106 typedef AssembledGalerkinOperator<Assembler,yIdx,yIdx+1,uIdx,uIdx+1> NormYUOperator;
107 typedef AssembledGalerkinOperator<Assembler,uIdx,uIdx+1,pIdx,pIdx+1> ControlOperatorT;
108
109 // domain and range
110 typedef typename SystemOperator::Domain Domain;
111 typedef typename SystemOperator::Range Range;
112 typedef typename Functional::AnsatzVars::Scalar Scalar;
113 typedef typename Functional::AnsatzVars::template CoefficientVectorRepresentation<yIdx,yIdx+1> CreateVectorY;
114 typedef typename CreateVectorY::type VectorY;
115 typedef typename Functional::AnsatzVars::template CoefficientVectorRepresentation<uIdx,uIdx+1> CreateVectorU;
116 typedef typename CreateVectorU::type VectorU;
117 typedef typename Functional::AnsatzVars::template CoefficientVectorRepresentation<pIdx,pIdx+1> CreateVectorP;
118 typedef typename CreateVectorP::type VectorP;
119 typedef typename Functional::AnsatzVars::template CoefficientVectorRepresentation<> CreateCoefficientVector;
120 typedef typename CreateCoefficientVector::type CoefficientVector;
121 typedef VectorY StateCoefficientVector;
122 typedef VectorP AdjointCoefficientVector;
123 typedef VectorU ControlCoefficientVector;
124 typedef CreateVectorY StateCoefficientVectorCreator;
125 typedef CreateVectorP AdjointCoefficientVectorCreator;
126 typedef CreateVectorU ControlCoefficientVectorCreator;
127
128 // preconditioners
129 typedef Dune::Preconditioner<VectorY,VectorP> StatePreconditioner;
130 typedef Dune::Preconditioner<VectorP,VectorY> AdjointPreconditioner;
131 typedef Dune::Preconditioner<VectorU,VectorU> NormUPreconditioner;
132
133 // preconditioner factories
134 typedef PreconditionerFactory<Assembler,VectorY,VectorY,Scalar> NormYPreconditionerFactory;
135 typedef PreconditionerFactory<Assembler,VectorU,VectorU,Scalar> NormUPreconditionerFactory;
136 typedef PreconditionerFactory<Assembler,VectorP,VectorY,Scalar> AdjointPreconditionerFactory;
137 typedef PreconditionerFactory<Assembler,VectorY,VectorP,Scalar> StatePreconditionerFactory;
138
139 // multi grid solvers
140 typedef MultiGridSolver<Grid,stateComponents> StateMGSolver;
141 typedef MultiGridSolver<Grid,controlComponents> ControlMGSolver;
142
143 // multi grid preconditioners
144 typedef MultiGridPreconditioner<Grid,stateComponents> StateMGPreconditioner;
145 typedef MultiGridPreconditioner<Grid,controlComponents> ControlMGPreconditioner;
146 };
147
148}
149
150
152
153#endif // SYSTEMTRAITS_HH
std::integral_constant< int, Functional::controlId > getControlIdImpl(decltype(Functional::controlId) *)
std::integral_constant< int, Functional::stateId > getStateIdImpl(decltype(Functional::stateId) *)
std::integral_constant< int, Functional::adjointId > getAdjointIdImpl(decltype(Functional::adjointId) *)
static int const m
number of component of this variable
Definition: variables.hh:80