DUNE PDELab (git)

residualengine.hh
1#ifndef DUNE_PDELAB_GRIDOPERATOR_ONESTEP_RESIDUALENGINE_HH
2#define DUNE_PDELAB_GRIDOPERATOR_ONESTEP_RESIDUALENGINE_HH
3
4#include <dune/pdelab/gridoperator/onestep/enginebase.hh>
5
6#include <cmath>
7
8namespace Dune{
9 namespace PDELab{
10
18 template<typename OSLA>
21 typename OSLA::LocalAssemblerDT0::LocalResidualAssemblerEngine,
22 typename OSLA::LocalAssemblerDT1::LocalResidualAssemblerEngine
23 >
24 {
25
27 typename OSLA::LocalAssemblerDT0::LocalResidualAssemblerEngine,
28 typename OSLA::LocalAssemblerDT1::LocalResidualAssemblerEngine
29 > BaseT;
30
31 using BaseT::la;
32 using BaseT::lae0;
33 using BaseT::lae1;
34 using BaseT::implicit;
35 using BaseT::setLocalAssemblerEngineDT0;
36 using BaseT::setLocalAssemblerEngineDT1;
37
38 public:
41
44 typedef typename OSLA::LocalAssemblerDT0 LocalAssemblerDT0;
45 typedef typename OSLA::LocalAssemblerDT1 LocalAssemblerDT1;
46
47 typedef typename LocalAssemblerDT0::LocalResidualAssemblerEngine ResidualEngineDT0;
48 typedef typename LocalAssemblerDT1::LocalResidualAssemblerEngine ResidualEngineDT1;
50
52 typedef typename OSLA::Traits::Residual Residual;
53
55 typedef typename OSLA::Traits::Solution Solution;
56
58 typedef typename OSLA::Real Real;
59
60 typedef OSLA LocalAssembler;
61
68 OneStepLocalResidualAssemblerEngine(const LocalAssembler & local_assembler_)
69 : BaseT(local_assembler_)
70 , invalid_residual(nullptr)
71 , invalid_solution(nullptr)
72 , residual_0(invalid_residual)
73 , residual_1(invalid_residual)
74 , const_residual_0(invalid_residual)
75 , const_residual_1(invalid_residual)
76 , solution(invalid_solution)
77 {}
78
81 void setSolution(const Solution & solution_)
82 {
83 solution = &solution_;
84 }
85
88 void setConstResidual(const Residual &const_residual_)
89 {
90 const_residual_0 = &const_residual_;
91 const_residual_1 = &const_residual_;
92 }
93
96 void setResidual(Residual & residual_)
97 {
98 residual_0 = &residual_;
99 residual_1 = &residual_;
100
101 // Initialize the engines of the two wrapped local assemblers
102 assert(solution != invalid_solution);
103 setLocalAssemblerEngineDT0(la.la0.localResidualAssemblerEngine(*residual_0,*solution));
104 setLocalAssemblerEngineDT1(la.la1.localResidualAssemblerEngine(*residual_1,*solution));
105 }
106
111 void setConstResiduals(const Residual &const_residual_0_, const Residual &const_residual_1_)
112 {
113 const_residual_0 = &const_residual_0_;
114 const_residual_1 = &const_residual_1_;
115 }
116
121 void setResiduals(Residual & residual_0_, Residual & residual_1_)
122 {
123 residual_0 = &residual_0_;
124 residual_1 = &residual_1_;
125
126 // Initialize the engines of the two wrapped local assemblers
127 assert(solution != invalid_solution);
128 setLocalAssemblerEngineDT0(la.la0.localResidualAssemblerEngine(*residual_0,*solution));
129 setLocalAssemblerEngineDT1(la.la1.localResidualAssemblerEngine(*residual_1,*solution));
130 }
131
136 {
137 la.la0.setWeight(b_rr * la.dt_factor0);
138 la.la1.setWeight(la.dt_factor1);
139 }
140
144 {
145 lae0->preAssembly();
146 lae1->preAssembly();
147
148 // Extract the coefficients of the time step scheme
149 b_rr = la.osp_method->b(la.stage,la.stage);
150 d_r = la.osp_method->d(la.stage);
151 using std::abs;
152 implicit = abs(b_rr) > 1e-6;
153
154 // prepare local operators for stage
155 la.la0.setTime(la.time + d_r * la.dt);
156 la.la1.setTime(la.time + d_r * la.dt);
157
158 setWeights();
159 }
160
161 template<typename GFSU, typename GFSV>
162 void postAssembly(const GFSU& gfsu, const GFSV& gfsv)
163 {
164
165 // Update residual vectors with constant part
166 assert(const_residual_0 != invalid_residual);
167 assert(const_residual_1 != invalid_residual);
168 *residual_0 += *const_residual_0;
169 if(residual_0 != residual_1){
170 assert(const_residual_0 != const_residual_1);
171 *residual_1 += *const_residual_1;
172 }
173
174 lae0->postAssembly(gfsu,gfsv);
175 lae1->postAssembly(gfsu,gfsv);
176 }
178
179
180 private:
181
183 Residual * const invalid_residual;
184
186 Solution * const invalid_solution;
187
192 Residual * residual_0;
193 Residual * residual_1;
195
200 const Residual * const_residual_0;
201 const Residual * const_residual_1;
203
205 const Solution * solution;
206
208 Real b_rr, d_r;
209
210 }; // End of class OneStepLocalResidualAssemblerEngine
211
212 }
213}
214
215#endif // DUNE_PDELAB_GRIDOPERATOR_ONESTEP_RESIDUALENGINE_HH
The local assembler engine for UDG sub triangulations which assembles the residual vector.
Definition: enginebase.hh:16
const LocalAssembler & la
Definition: enginebase.hh:472
The local assembler engine for one step methods which assembles the residual vector.
Definition: residualengine.hh:24
OSLA::Real Real
The type for real numbers.
Definition: residualengine.hh:58
OSLA::Traits::Solution Solution
The type of the solution vector.
Definition: residualengine.hh:55
void setResiduals(Residual &residual_0_, Residual &residual_1_)
Definition: residualengine.hh:121
OSLA OneStepLocalAssembler
The type of the wrapping local assembler.
Definition: residualengine.hh:40
OSLA::LocalAssemblerDT0 LocalAssemblerDT0
Definition: residualengine.hh:44
void setWeights()
Definition: residualengine.hh:135
void setConstResidual(const Residual &const_residual_)
Definition: residualengine.hh:88
void setSolution(const Solution &solution_)
Definition: residualengine.hh:81
OneStepLocalResidualAssemblerEngine(const LocalAssembler &local_assembler_)
Constructor.
Definition: residualengine.hh:68
void preAssembly()
Definition: residualengine.hh:143
void setConstResiduals(const Residual &const_residual_0_, const Residual &const_residual_1_)
Definition: residualengine.hh:111
OSLA::Traits::Residual Residual
The type of the residual vector.
Definition: residualengine.hh:52
void setResidual(Residual &residual_)
Definition: residualengine.hh:96
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)