OGS
TimeDiscretizedODESystem.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <memory>
14
15#include "MatrixTranslator.h"
16#include "NonlinearSystem.h"
17#include "ODESystem.h"
18#include "TimeDiscretization.h"
19
20namespace NumLib
21{
24
32template <NonlinearSolverTag NLTag>
34{
35public:
38};
39
48template <ODESystemTag ODETag, NonlinearSolverTag NLTag>
50
56template <>
59 final : public TimeDiscretizedODESystemBase<NonlinearSolverTag::Newton>
60{
61public:
63 static const ODESystemTag ODETag =
65
73
80 explicit TimeDiscretizedODESystem(const int process_id, ODE& ode,
81 TimeDisc& time_discretization);
82
84
85 void assemble(std::vector<GlobalVector*> const& x_new_timestep,
86 std::vector<GlobalVector*> const& x_prev,
87 int const process_id) override;
88
91 std::vector<GlobalIndexType>
93 {
94 return _ode.getIndicesOfResiduumWithoutInitialCompensation();
95 }
96
98 int const process_id) override
99 {
100 _ode.setReleaseNodalForces(r_neq, process_id);
101 }
102
103 void getResidual(GlobalVector const& x_new_timestep,
104 GlobalVector const& x_prev,
105 GlobalVector& res) const override;
106
107 void getJacobian(GlobalMatrix& Jac) const override;
108
109 void computeKnownSolutions(GlobalVector const& x,
110 int const process_id) override;
111
112 void applyKnownSolutions(GlobalVector& x) const override;
113
114 void applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res,
115 GlobalVector const& x,
116 GlobalVector& minus_delta_x) const override;
117
118 void applyKnownSolutionsPETScSNES(GlobalMatrix& Jac, GlobalVector& res,
119 GlobalVector& x) const override;
120
122 int const process_id) override
123 {
124 _ode.updateConstraints(lower, upper, process_id);
125 }
126
127 bool isLinear() const override { return _ode.isLinear(); }
128
129 bool requiresNormalization() const override
130 {
131 return _ode.requiresNormalization();
132 }
133
134 void preIteration(const unsigned iter, GlobalVector const& x) override
135 {
136 _ode.preIteration(iter, x);
137 }
138
140 {
141 return _ode.postIteration(x);
142 }
143
146 const int process_id) const override
147 {
148 return _ode.getMatrixSpecifications(process_id);
149 }
150
151private:
154
156 std::unique_ptr<MatTrans> _mat_trans;
157
159 std::vector<NumLib::IndexValueVector<Index>> const* _known_solutions =
160 nullptr;
161
164
165 std::size_t _Jac_id = 0u;
166 std::size_t _b_id = 0u;
167};
168
175template <>
178 final : public TimeDiscretizedODESystemBase<NonlinearSolverTag::Picard>
179{
180public:
182 static const ODESystemTag ODETag =
184
192
194 explicit TimeDiscretizedODESystem(const int process_id, ODE& ode,
195 TimeDisc& time_discretization);
196
197 ~TimeDiscretizedODESystem() override;
198
199 void assemble(std::vector<GlobalVector*> const& x_new_timestep,
200 std::vector<GlobalVector*> const& x_prev,
201 int const process_id) override;
202
205 std::vector<GlobalIndexType>
207 {
208 return _ode.getIndicesOfResiduumWithoutInitialCompensation();
209 }
210
212 int const process_id) override
213 {
214 _ode.setReleaseNodalForces(r_neq, process_id);
215 }
216
217 void getA(GlobalMatrix& A) const override
218 {
219 _mat_trans->computeA(*_M, *_K, A);
220 }
221
222 void getRhs(GlobalVector const& x_prev, GlobalVector& rhs) const override
223 {
224 _mat_trans->computeRhs(*_M, *_K, *_b, x_prev, rhs);
225 }
226
227 void getAandRhsNormalized(GlobalMatrix& A, GlobalVector& rhs) const override
228 {
229 _mat_trans->normalizeAandRhs(A, rhs);
230 }
231
232 void computeKnownSolutions(GlobalVector const& x,
233 int const process_id) override;
234
235 void applyKnownSolutions(GlobalVector& x) const override;
236
237 void applyKnownSolutionsPicard(
239 MathLib::DirichletBCApplicationMode const mode) const override;
240
241 bool isLinear() const override { return _ode.isLinear(); }
242
243 bool requiresNormalization() const override
244 {
245 return _ode.requiresNormalization();
246 }
247
248 void preIteration(const unsigned iter, GlobalVector const& x) override
249 {
250 _ode.preIteration(iter, x);
251 }
252
254 {
255 return _ode.postIteration(x);
256 }
257
260 const int process_id) const override
261 {
262 return _ode.getMatrixSpecifications(process_id);
263 }
264
266 {
267 if (_ode.shouldLinearSolverComputeOnlyUponTimestepChange() &&
268 _time_disc.getCurrentTimeIncrement() !=
269 _time_disc.getPreviousTimeIncrement())
270 {
272 }
273 if (_ode.shouldLinearSolverComputeOnlyUponTimestepChange() &&
274 _time_disc.getCurrentTimeIncrement() ==
275 _time_disc.getPreviousTimeIncrement())
276 {
278 }
280 }
281
282private:
285
287 std::unique_ptr<MatTrans> _mat_trans;
288
290 std::vector<NumLib::IndexValueVector<Index>> const* _known_solutions =
291 nullptr;
292
296
297 std::size_t _M_id = 0u;
298 std::size_t _K_id = 0u;
299 std::size_t _b_id = 0u;
300};
301
303} // namespace NumLib
MathLib::EigenMatrix GlobalMatrix
MathLib::EigenVector GlobalVector
virtual TimeDiscretization & getTimeDiscretization()=0
Exposes the used time discretization scheme.
std::unique_ptr< MatTrans > _mat_trans
the object used to compute the matrix/vector for the nonlinear solver
std::vector< NumLib::IndexValueVector< Index > > const * _known_solutions
stores precomputed values for known solutions
void updateConstraints(GlobalVector &lower, GlobalVector &upper, int const process_id) override
void assemble(std::vector< GlobalVector * > const &x_new_timestep, std::vector< GlobalVector * > const &x_prev, int const process_id) override
void assemble(std::vector< GlobalVector * > const &x_new_timestep, std::vector< GlobalVector * > const &x_prev, int const process_id) override
TimeDiscretizedODESystem(const int process_id, ODE &ode, TimeDisc &time_discretization)
Constructs a new instance.
std::vector< NumLib::IndexValueVector< Index > > const * _known_solutions
stores precomputed values for known solutions
std::unique_ptr< MatTrans > _mat_trans
the object used to compute the matrix/vector for the nonlinear solver
ODESystemTag
Tag used to specify the type of ODE.
Definition Types.h:27
IterationResult
Status flags telling the NonlinearSolver if an iteration succeeded.
@ FirstOrderImplicitQuasilinear
Definition Types.h:34
DirichletBCApplicationMode
Definition LinAlgEnums.h:42