DUNE PDELab (git)

localassembler.hh
1#ifndef DUNE_PDELAB_GRIDOPERATOR_ONESTEP_LOCALASSEMBLER_HH
2#define DUNE_PDELAB_GRIDOPERATOR_ONESTEP_LOCALASSEMBLER_HH
3
4#include <dune/typetree/typetree.hh>
5
6#include <dune/pdelab/gridoperator/onestep/residualengine.hh>
7#include <dune/pdelab/gridoperator/onestep/patternengine.hh>
8#include <dune/pdelab/gridoperator/onestep/jacobianengine.hh>
9#include <dune/pdelab/gridoperator/onestep/jacobianapplyengine.hh>
10#include <dune/pdelab/gridoperator/onestep/prestageengine.hh>
11#include <dune/pdelab/gridoperator/onestep/jacobianresidualengine.hh>
12
13#include <dune/pdelab/instationary/onestepparameter.hh>
14
15#include <dune/pdelab/gridoperator/common/assemblerutilities.hh>
16
17#include <dune/pdelab/gridfunctionspace/lfsindexcache.hh>
18
19namespace Dune{
20 namespace PDELab{
21
28 template<typename GO, typename LA0, typename LA1>
31 typename GO::Traits::MatrixBackend,
32 typename GO::Traits::TrialGridFunctionSpaceConstraints,
33 typename GO::Traits::TestGridFunctionSpaceConstraints>
34 {
35 public:
36
38 typedef LA0 LocalAssemblerDT0;
39 typedef LA1 LocalAssemblerDT1;
40
42
45 typename GO::Traits::MatrixBackend,
46 typename GO::Traits::TrialGridFunctionSpaceConstraints,
47 typename GO::Traits::TestGridFunctionSpaceConstraints> Base;
48
56
57 typedef typename LA1::LocalPatternAssemblerEngine LocalExplicitPatternAssemblerEngine;
60
68
69 void static_checks()
70 {
71 static_assert((std::is_same<typename LA0::Traits::Jacobian::Pattern,
72 typename LA1::Traits::Jacobian::Pattern>::value),
73 "Received two local assemblers which are non-compatible "
74 "due to different matrix pattern types");
75 static_assert((std::is_same<typename LA0::Traits::Jacobian,
76 typename LA1::Traits::Jacobian>::value),
77 "Received two local assemblers which are non-compatible "
78 "due to different jacobian types");
79 static_assert((std::is_same<typename LA0::Traits::Solution,
80 typename LA1::Traits::Solution>::value),
81 "Received two local assemblers which are non-compatible "
82 "due to different solution vector types");
83 static_assert((std::is_same<typename LA0::Traits::Residual,
84 typename LA1::Traits::Residual>::value),
85 "Received two local assemblers which are non-compatible "
86 "due to different residual vector types");
87 }
88
90 typedef typename Traits::RangeField Real;
91
94
95 static constexpr bool isLinear() { return LA0::isLinear() and LA1::isLinear();}
96
98 OneStepLocalAssembler (LA0 & la0_, LA1 & la1_, typename Traits::Residual & const_residual_)
99 : Base(la0_.trialConstraints(),la0_.testConstraints()),
100 la0(la0_), la1(la1_),
101 const_residual(const_residual_),
102 time(0.0), dt_mode(MultiplyOperator0ByDT), stage(0),
103 pattern_engine(*this), prestage_engine(*this), residual_engine(*this), jacobian_engine(*this),
104 explicit_jacobian_residual_engine(*this),
105 jacobian_apply_engine(*this)
106 { static_checks(); }
107
111 void preStep(Real time_, Real dt_, int stages_)
112 {
113 time = time_;
114 dt = dt_;
115
116 // This switch decides which term will be multiplied with dt
117 if(dt_mode == DivideOperator1ByDT)
118 {
119 dt_factor0 = 1.0;
120 dt_factor1 = 1.0 / dt;
121 }
122 else if(dt_mode == MultiplyOperator0ByDT)
123 {
124 dt_factor0 = dt;
125 dt_factor1 = 1.0;
126 }
127 else if(dt_mode == DoNotAssembleDT)
128 {
129 dt_factor0 = 1.0;
130 dt_factor1 = 1.0;
131 }
132 else
133 {
134 DUNE_THROW(Dune::Exception,"Unknown mode for assembling of time step size!");
135 }
136
137 la0.preStep(time_,dt_, stages_);
138 la1.preStep(time_,dt_, stages_);
139 }
140
142 void setMethod(const OneStepParameters & method_)
143 {
144 osp_method = & method_;
145 }
146
148 void setStage(int stage_)
149 {
150 stage = stage_;
151 }
152
153 enum DTAssemblingMode { DivideOperator1ByDT, MultiplyOperator0ByDT, DoNotAssembleDT };
154
158 void setDTAssemblingMode(DTAssemblingMode dt_mode_)
159 {
160 dt_mode = dt_mode_;
161 }
162
164 Real timeAtStage(int stage_) const
165 {
166 return time+osp_method->d(stage_)*dt;
167 }
168
171 {
172 return time+osp_method->d(stage)*dt;
173 }
174
175 void setWeight(const Real weight)
176 {
177 la0.setWeight(weight);
178 la1.setWeight(weight);
179 }
180
183
187 (typename Traits::MatrixPattern & p)
188 {
189 pattern_engine.setPattern(p);
190 return pattern_engine;
191 }
192
196 (const std::vector<typename Traits::Solution*> & x)
197 {
198 prestage_engine.setSolutions(x);
199 prestage_engine.setConstResidual(const_residual);
200 return prestage_engine;
201 }
202
206 (typename Traits::Residual & r, const typename Traits::Solution & x)
207 {
208 residual_engine.setSolution(x);
209 residual_engine.setConstResidual(const_residual);
210 residual_engine.setResidual(r);
211 return residual_engine;
212 }
213
217 (typename Traits::Jacobian & a, const typename Traits::Solution & x)
218 {
219 jacobian_engine.setSolution(x);
220 jacobian_engine.setJacobian(a);
221 return jacobian_engine;
222 }
223
226 LocalExplicitPatternAssemblerEngine & localExplicitPatternAssemblerEngine
227 (typename Traits::MatrixPattern & p)
228 {
229 return la1.localPatternAssemblerEngine(p);
230 }
231
235 (typename Traits::Jacobian & a,
236 typename Traits::Residual & r0, typename Traits::Residual & r1,
237 const std::vector<typename Traits::Solution*> & x)
238 {
239 // Init pre stage engine
240 prestage_engine.setSolutions( x );
241 prestage_engine.setConstResiduals(r0,r1);
242 explicit_jacobian_residual_engine.setLocalPreStageEngine(prestage_engine);
243
244 // Init jacobian engine
245 explicit_jacobian_residual_engine.setLocalJacobianEngine
246 (la1.localJacobianAssemblerEngine(a,*(x[stage])));
247
248 return explicit_jacobian_residual_engine;
249 }
250
254 (const typename Traits::Domain & update, typename Traits::Range & result)
255 {
256 jacobian_apply_engine.setUpdate(update);
257 jacobian_apply_engine.setResult(result);
258 return jacobian_apply_engine;
259 }
260
264 (const typename Traits::Domain & solution, const typename Traits::Domain & update, typename Traits::Range & result)
265 {
266 jacobian_apply_engine.setSolution(solution);
267 jacobian_apply_engine.setUpdate(update);
268 jacobian_apply_engine.setResult(result);
269 return jacobian_apply_engine;
270 }
271
273
274 private:
275
279 LA0 & la0;
280 LA1 & la1;
282
285 const OneStepParameters * osp_method;
286
288 typename Traits::Residual & const_residual;
289
291 Real time;
292
294 Real dt;
295
310 Real dt_factor0, dt_factor1;
311
314 DTAssemblingMode dt_mode;
315
317 int stage;
318
321 LocalPatternAssemblerEngine pattern_engine;
322 LocalPreStageAssemblerEngine prestage_engine;
323 LocalResidualAssemblerEngine residual_engine;
324 LocalJacobianAssemblerEngine jacobian_engine;
325 LocalExplicitJacobianResidualAssemblerEngine explicit_jacobian_residual_engine;
326 LocalJacobianApplyAssemblerEngine jacobian_apply_engine;
328 };
329
330 }
331}
332#endif // DUNE_PDELAB_GRIDOPERATOR_ONESTEP_LOCALASSEMBLER_HH
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
Base class for local assembler.
Definition: assemblerutilities.hh:217
const GO::Traits::TrialGridFunctionSpaceConstraints & trialConstraints() const
get the constraints on the trial grid function space
Definition: assemblerutilities.hh:233
const GO::Traits::TestGridFunctionSpaceConstraints & testConstraints() const
get the constraints on the test grid function space
Definition: assemblerutilities.hh:239
The local assembler for one step methods.
Definition: localassembler.hh:34
Dune::PDELab::LocalAssemblerBase< typename GO::Traits::MatrixBackend, typename GO::Traits::TrialGridFunctionSpaceConstraints, typename GO::Traits::TestGridFunctionSpaceConstraints > Base
The base class.
Definition: localassembler.hh:47
void setStage(int stage_)
Set the current stage of the one step scheme.
Definition: localassembler.hh:148
LocalPatternAssemblerEngine & localPatternAssemblerEngine(typename Traits::MatrixPattern &p)
Definition: localassembler.hh:187
LocalPreStageAssemblerEngine & localPreStageAssemblerEngine(const std::vector< typename Traits::Solution * > &x)
Definition: localassembler.hh:196
Real timeAtStage(int stage_) const
Access time at given stage.
Definition: localassembler.hh:164
Real timeAtStage() const
Access time at given stage.
Definition: localassembler.hh:170
void setMethod(const OneStepParameters &method_)
Set the one step method parameters.
Definition: localassembler.hh:142
void setDTAssemblingMode(DTAssemblingMode dt_mode_)
Definition: localassembler.hh:158
LA0 LocalAssemblerDT0
The types of the local assemblers of order one and zero.
Definition: localassembler.hh:38
LocalJacobianApplyAssemblerEngine & localJacobianApplyAssemblerEngine(const typename Traits::Domain &solution, const typename Traits::Domain &update, typename Traits::Range &result)
Definition: localassembler.hh:264
LocalResidualAssemblerEngine & localResidualAssemblerEngine(typename Traits::Residual &r, const typename Traits::Solution &x)
Definition: localassembler.hh:206
LocalJacobianApplyAssemblerEngine & localJacobianApplyAssemblerEngine(const typename Traits::Domain &update, typename Traits::Range &result)
Definition: localassembler.hh:254
OneStepLocalPatternAssemblerEngine< OneStepLocalAssembler > LocalPatternAssemblerEngine
Definition: localassembler.hh:51
OneStepLocalAssembler(LA0 &la0_, LA1 &la1_, typename Traits::Residual &const_residual_)
Constructor with empty constraints.
Definition: localassembler.hh:98
void preStep(Real time_, Real dt_, int stages_)
Definition: localassembler.hh:111
LocalExplicitPatternAssemblerEngine & localExplicitPatternAssemblerEngine(typename Traits::MatrixPattern &p)
Definition: localassembler.hh:227
LocalExplicitJacobianResidualAssemblerEngine & localExplicitJacobianResidualAssemblerEngine(typename Traits::Jacobian &a, typename Traits::Residual &r0, typename Traits::Residual &r1, const std::vector< typename Traits::Solution * > &x)
Definition: localassembler.hh:235
LocalJacobianAssemblerEngine & localJacobianAssemblerEngine(typename Traits::Jacobian &a, const typename Traits::Solution &x)
Definition: localassembler.hh:217
Dune::PDELab::TimeSteppingParameterInterface< Real > OneStepParameters
The type of the one step parameter object.
Definition: localassembler.hh:93
Traits::RangeField Real
The local operators type for real numbers e.g. time.
Definition: localassembler.hh:90
void setSolution(const Domain &solution_)
Definition: jacobianapplyengine.hh:73
void setUpdate(const Domain &update_)
Definition: jacobianapplyengine.hh:80
void setResult(Range &result_)
Definition: jacobianapplyengine.hh:87
void setJacobian(Jacobian &jacobian_)
Definition: jacobianengine.hh:78
void setSolution(const Solution &solution_)
Definition: jacobianengine.hh:71
void setPattern(Pattern &pattern_)
Definition: patternengine.hh:62
void setSolutions(const Solutions &solutions_)
Definition: prestageengine.hh:88
void setConstResiduals(Residual &const_residual_0_, Residual &const_residual_1_)
Definition: prestageengine.hh:95
void setConstResidual(Residual &const_residual_)
Definition: prestageengine.hh:108
void setConstResidual(const Residual &const_residual_)
Definition: residualengine.hh:88
void setSolution(const Solution &solution_)
Definition: residualengine.hh:81
void setResidual(Residual &residual_)
Definition: residualengine.hh:96
Base parameter class for time stepping scheme parameters.
Definition: onestepparameter.hh:44
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
virtual R d(int r) const =0
Return entries of the d Vector.
Dune namespace.
Definition: alignedallocator.hh:13
Definition: assemblerutilities.hh:51
GO::Traits::Range Residual
The type of the range (residual).
Definition: assemblerutilities.hh:88
MatrixBackend::template Pattern< Jacobian, TestGridFunctionSpace, TrialGridFunctionSpace > MatrixPattern
The matrix pattern.
Definition: assemblerutilities.hh:102
GO::Traits::Jacobian Jacobian
The type of the jacobian.
Definition: assemblerutilities.hh:95
GO::Traits::Domain Solution
The type of the domain (solution).
Definition: assemblerutilities.hh:78
GO::Traits::RangeField RangeField
The field type of the range (residual).
Definition: assemblerutilities.hh:82
GO::Traits::Range Range
The type of the range (residual).
Definition: assemblerutilities.hh:85
GO::Traits::Domain Domain
The type of the domain (solution).
Definition: assemblerutilities.hh:75
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)