DUNE PDELab (git)

onestep.hh
1// -*- tab-width: 2; indent-tabs-mode: nil -*-
2// vi: set et ts=2 sw=2 sts=2:
3#ifndef DUNE_PDELAB_GRIDOPERATOR_ONESTEP_HH
4#define DUNE_PDELAB_GRIDOPERATOR_ONESTEP_HH
5
6#include <tuple>
7
8#include <dune/pdelab/constraints/common/constraints.hh>
9#include <dune/pdelab/gridfunctionspace/genericdatahandle.hh>
10#include <dune/pdelab/gridoperator/common/gridoperatorutilities.hh>
11#include <dune/pdelab/gridoperator/onestep/localassembler.hh>
12#include <dune/pdelab/instationary/onestep.hh>
13
14namespace Dune{
15 namespace PDELab{
16
17 template<typename GO0, typename GO1, bool implicit = true>
18 class OneStepGridOperator
19 {
20 public:
21
23 typedef typename GO0::Pattern Pattern;
24
26 typedef typename GO0::Traits::Assembler Assembler;
27
30 typedef typename GO0::Traits::LocalAssembler LocalAssemblerDT0;
31 typedef typename GO1::Traits::LocalAssembler LocalAssemblerDT1;
33
35 typedef OneStepLocalAssembler<OneStepGridOperator,LocalAssemblerDT0,LocalAssemblerDT1> LocalAssembler;
36
38 typedef typename GO0::BorderDOFExchanger BorderDOFExchanger;
39
42 <typename GO0::Traits::TrialGridFunctionSpace,
43 typename GO0::Traits::TestGridFunctionSpace,
44 typename GO0::Traits::MatrixBackend,
45 typename GO0::Traits::DomainField,
46 typename GO0::Traits::RangeField,
47 typename GO0::Traits::JacobianField,
48 typename GO0::Traits::TrialGridFunctionSpaceConstraints,
49 typename GO0::Traits::TestGridFunctionSpaceConstraints,
50 Assembler,
51 LocalAssembler> Traits;
52
55 typedef typename Traits::Domain Domain;
56 typedef typename Traits::Range Range;
57 typedef typename Traits::Jacobian Jacobian;
59
60 template <typename MFT>
61 struct MatrixContainer
62 {
63 typedef Jacobian Type;
64 };
65
67 typedef typename LocalAssembler::Real Real;
68
70 typedef typename LocalAssembler::OneStepParameters OneStepParameters;
71
73 OneStepGridOperator(GO0 & go0_, GO1 & go1_)
74 : global_assembler(go0_.assembler()),
75 go0(go0_), go1(go1_),
76 la0(go0_.localAssembler()), la1(go1_.localAssembler()),
77 const_residual( go0_.testGridFunctionSpace() ),
78 local_assembler(la0,la1, const_residual)
79 {
80 GO0::setupGridOperators(std::tie(go0_,go1_));
81 if(not implicit)
82 local_assembler.setDTAssemblingMode(LocalAssembler::DoNotAssembleDT);
83 }
84
88 void divideMassTermByDeltaT()
89 {
90 if(not implicit)
91 DUNE_THROW(Dune::Exception,"This function should not be called in explicit mode");
92 local_assembler.setDTAssemblingMode(LocalAssembler::DivideOperator1ByDT);
93 }
94 void multiplySpatialTermByDeltaT()
95 {
96 if(not implicit)
97 DUNE_THROW(Dune::Exception,"This function should not be called in explicit mode");
98 local_assembler.setDTAssemblingMode(LocalAssembler::MultiplyOperator0ByDT);
99 }
100
102 const typename Traits::TrialGridFunctionSpace& trialGridFunctionSpace() const
103 {
104 return global_assembler.trialGridFunctionSpace();
105 }
106
108 const typename Traits::TestGridFunctionSpace& testGridFunctionSpace() const
109 {
110 return global_assembler.testGridFunctionSpace();
111 }
112
114 typename Traits::TrialGridFunctionSpace::Traits::SizeType globalSizeU () const
115 {
116 return trialGridFunctionSpace().globalSize();
117 }
118
120 typename Traits::TestGridFunctionSpace::Traits::SizeType globalSizeV () const
121 {
122 return testGridFunctionSpace().globalSize();
123 }
124
125 Assembler & assembler() const { return global_assembler; }
126
127 LocalAssembler & localAssembler() const { return local_assembler; }
128
130 void fill_pattern(Pattern & p) const
131 {
132 if(implicit)
133 {
134 typedef typename LocalAssembler::LocalPatternAssemblerEngine PatternEngine;
135 PatternEngine & pattern_engine = local_assembler.localPatternAssemblerEngine(p);
136 global_assembler.assemble(pattern_engine);
137 }
138 else
139 {
140 typedef typename LocalAssembler::LocalExplicitPatternAssemblerEngine PatternEngine;
141 PatternEngine & pattern_engine = local_assembler.localExplicitPatternAssemblerEngine(p);
142 global_assembler.assemble(pattern_engine);
143 }
144 }
145
147 void preStage(unsigned int stage, const std::vector<Domain*> & x)
148 {
149 if(not implicit)
150 DUNE_THROW(Dune::Exception,"This function should not be called in explicit mode");
151
152 typedef typename LocalAssembler::LocalPreStageAssemblerEngine PreStageEngine;
153 local_assembler.setStage(stage);
154 PreStageEngine & prestage_engine = local_assembler.localPreStageAssemblerEngine(x);
155 global_assembler.assemble(prestage_engine);
156 }
157
159 void residual(const Domain & x, Range & r) const
160 {
161 if(not implicit)
162 DUNE_THROW(Dune::Exception,"This function should not be called in explicit mode");
163
164 typedef typename LocalAssembler::LocalResidualAssemblerEngine ResidualEngine;
165 ResidualEngine & residual_engine = local_assembler.localResidualAssemblerEngine(r,x);
166 global_assembler.assemble(residual_engine);
167 }
168
170 void jacobian(const Domain & x, Jacobian & a) const
171 {
172 if(not implicit)
173 DUNE_THROW(Dune::Exception,"This function should not be called in explicit mode");
174
175 typedef typename LocalAssembler::LocalJacobianAssemblerEngine JacobianEngine;
176 JacobianEngine & jacobian_engine = local_assembler.localJacobianAssemblerEngine(a,x);
177 global_assembler.assemble(jacobian_engine);
178 }
179
181 void explicit_jacobian_residual(unsigned int stage, const std::vector<Domain*> & x,
182 Jacobian & a, Range & r1, Range & r0)
183 {
184 if(implicit)
185 DUNE_THROW(Dune::Exception,"This function should not be called in implicit mode");
186
187 local_assembler.setStage(stage);
188
189 typedef typename LocalAssembler::LocalExplicitJacobianResidualAssemblerEngine
190 ExplicitJacobianResidualEngine;
191
192 ExplicitJacobianResidualEngine & jacobian_residual_engine
193 = local_assembler.localExplicitJacobianResidualAssemblerEngine(a,r0,r1,x);
194 global_assembler.assemble(jacobian_residual_engine);
195 }
196
198 void jacobian_apply(const Domain & update, Range & result) const
199 {
200 if ((not la0.localOperator().isLinear) or (not la1.localOperator().isLinear))
201 DUNE_THROW(Dune::Exception, "Your trying to use a linear jacobian apply for a non linear problem.");
202 global_assembler.assemble(local_assembler.localJacobianApplyAssemblerEngine(update, result));
203 }
204
206 void jacobian_apply(const Domain & solution, const Domain & update, Range & result) const
207 {
208 if (la0.localOperator().isLinear and la1.localOperator().isLinear)
209 DUNE_THROW(Dune::Exception, "Your trying to use a non linear jacobian apply for a linear problem.");
210 global_assembler.assemble(local_assembler.localJacobianApplyAssemblerEngine(solution, update, result));
211 }
212
214 template<typename F, typename X>
215 void interpolate (unsigned stage, const X& xold, F& f, X& x) const
216 {
217 // Set time in boundary value function
218 f.setTime(local_assembler.timeAtStage(stage));
219
220 go0.localAssembler().setTime(local_assembler.timeAtStage(stage));
221
222 // Interpolate
223 go0.interpolate(xold,f,x);
224
225 // Copy non-constrained dofs from old time step
226 Dune::PDELab::copy_nonconstrained_dofs(local_assembler.trialConstraints(),xold,x);
227
228 // If there are Dirichlet-constrained DOFs on processor boundaries, we need to make
229 // those DOFs consistent again
230 auto es = trialGridFunctionSpace().entitySet();
231 if (es.comm().size() > 1)
232 {
233 CopyDataHandle<typename Traits::TrialGridFunctionSpace,X> data_handle(trialGridFunctionSpace(),x);
234 es.communicate(data_handle,InteriorBorder_All_Interface,ForwardCommunication);
235 }
236 }
237
239 void setMethod (const TimeSteppingParameterInterface<Real>& method_)
240 {
241 local_assembler.setMethod(method_);
242 }
243
245 void preStep (const TimeSteppingParameterInterface<Real>& method_, Real time_, Real dt_)
246 {
247 local_assembler.setMethod(method_);
248 local_assembler.preStep(time_,dt_,method_.s());
249 }
250
252 void postStep ()
253 {
254 la0.postStep();
255 la1.postStep();
256 }
257
259 void postStage ()
260 {
261 la0.postStage();
262 la1.postStage();
263 }
264
266 Real suggestTimestep (Real dt) const
267 {
268 Real suggested_dt = std::min(la0.suggestTimestep(dt),la1.suggestTimestep(dt));
269 if (trialGridFunctionSpace().gridView().comm().size()>1)
270 suggested_dt = trialGridFunctionSpace().gridView().comm().min(suggested_dt);
271 return suggested_dt;
272 }
273
274 void update()
275 {
276 go0.update();
277 go1.update();
278 const_residual = Range(go0.testGridFunctionSpace());
279 }
280
281 void make_consistent(Jacobian& a) const
282 {
283 go0.make_consistent(a);
284 }
285
286 const typename Traits::MatrixBackend& matrixBackend() const
287 {
288 return go0.matrixBackend();
289 }
290
291 const typename LocalAssembler::Traits::TrialGridFunctionSpaceConstraints trialConstraints() const
292 {
293 return local_assembler.trialConstraints();
294 }
295
296 private:
297 Assembler & global_assembler;
298 GO0 & go0;
299 GO1 & go1;
300 LocalAssemblerDT0 & la0;
301 LocalAssemblerDT1 & la1;
302 Range const_residual;
303 mutable LocalAssembler local_assembler;
304 };
305
306 }
307}
308#endif // DUNE_PDELAB_GRIDOPERATOR_ONESTEP_HH
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
OneStepLocalPatternAssemblerEngine< OneStepLocalAssembler > LocalPatternAssemblerEngine
Definition: localassembler.hh:51
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
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
@ ForwardCommunication
communicate as given in InterfaceType
Definition: gridenums.hh:171
@ InteriorBorder_All_Interface
send interior and border, receive all entities
Definition: gridenums.hh:88
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177
void copy_nonconstrained_dofs(const CG &cg, const XG &xgin, XG &xgout)
Definition: constraints.hh:987
constexpr auto min
Function object that returns the smaller of the given values.
Definition: hybridutilities.hh:506
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Traits class for the grid operator.
Definition: gridoperatorutilities.hh:34
GFSU TrialGridFunctionSpace
The trial grid function space.
Definition: gridoperatorutilities.hh:37
GFSV TestGridFunctionSpace
The test grid function space.
Definition: gridoperatorutilities.hh:40
MB MatrixBackend
The matrix backend of the grid operator.
Definition: gridoperatorutilities.hh:51
Dune::PDELab::Backend::Matrix< MB, Domain, Range, JF > Jacobian
The type of the jacobian.
Definition: gridoperatorutilities.hh:72
Dune::PDELab::Backend::Vector< GFSV, RF > Range
The type of the range (residual).
Definition: gridoperatorutilities.hh:65
Dune::PDELab::Backend::Vector< GFSU, DF > Domain
The type of the domain (solution).
Definition: gridoperatorutilities.hh:58
GO::Traits::TrialGridFunctionSpaceConstraints TrialGridFunctionSpaceConstraints
The type of the trial grid function space constraints.
Definition: assemblerutilities.hh:61
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)