OGS
TimeDiscretizedODESystem.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <memory>
7
8#include "MatrixTranslator.h"
9#include "NonlinearSystem.h"
10#include "ODESystem.h"
11#include "TimeDiscretization.h"
12
13namespace NumLib
14{
17
25template <NonlinearSolverTag NLTag>
27{
28public:
31};
32
41template <ODESystemTag ODETag, NonlinearSolverTag NLTag>
43
49template <>
52 final : public TimeDiscretizedODESystemBase<NonlinearSolverTag::Newton>
53{
54public:
56 static const ODESystemTag ODETag =
58
66
73 explicit TimeDiscretizedODESystem(const int process_id, ODE& ode,
74 TimeDisc& time_discretization);
75
77
78 void assemble(std::vector<GlobalVector*> const& x_new_timestep,
79 std::vector<GlobalVector*> const& x_prev,
80 int const process_id) override;
81
84 std::vector<GlobalIndexType>
86 {
87 return _ode.getIndicesOfResiduumWithoutInitialCompensation();
88 }
89
91 int const process_id) override
92 {
93 _ode.setReleaseNodalForces(r_neq, process_id);
94 }
95
96 void getResidual(GlobalVector const& x_new_timestep,
97 GlobalVector const& x_prev,
98 GlobalVector& res) const override;
99
100 void getJacobian(GlobalMatrix& Jac) const override;
101
102 void computeKnownSolutions(GlobalVector const& x,
103 int const process_id) override;
104
105 void applyKnownSolutions(GlobalVector& x) const override;
106
107 void applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res,
108 GlobalVector const& x,
109 GlobalVector& minus_delta_x) const override;
110
111 void applyKnownSolutionsPETScSNES(GlobalMatrix& Jac, GlobalVector& res,
112 GlobalVector& x) const override;
113
115 int const process_id) override
116 {
117 _ode.updateConstraints(lower, upper, process_id);
118 }
119
120 bool isLinear() const override { return _ode.isLinear(); }
121
122 bool requiresNormalization() const override
123 {
124 return _ode.requiresNormalization();
125 }
126
127 void preIteration(const unsigned iter, GlobalVector const& x) override
128 {
129 _ode.preIteration(iter, x);
130 }
131
133 {
134 return _ode.postIteration(x);
135 }
136
139 const int process_id) const override
140 {
141 return _ode.getMatrixSpecifications(process_id);
142 }
143
144private:
147
149 std::unique_ptr<MatTrans> _mat_trans;
150
152 std::vector<NumLib::IndexValueVector<Index>> const* _known_solutions =
153 nullptr;
154
157
158 std::size_t _Jac_id = 0u;
159 std::size_t _b_id = 0u;
160};
161
168template <>
171 final : public TimeDiscretizedODESystemBase<NonlinearSolverTag::Picard>
172{
173public:
175 static const ODESystemTag ODETag =
177
185
187 explicit TimeDiscretizedODESystem(const int process_id, ODE& ode,
188 TimeDisc& time_discretization);
189
190 ~TimeDiscretizedODESystem() override;
191
192 void assemble(std::vector<GlobalVector*> const& x_new_timestep,
193 std::vector<GlobalVector*> const& x_prev,
194 int const process_id) override;
195
198 std::vector<GlobalIndexType>
200 {
201 return _ode.getIndicesOfResiduumWithoutInitialCompensation();
202 }
203
205 int const process_id) override
206 {
207 _ode.setReleaseNodalForces(r_neq, process_id);
208 }
209
210 void getA(GlobalMatrix& A) const override
211 {
212 _mat_trans->computeA(*_M, *_K, A);
213 }
214
215 void getRhs(GlobalVector const& x_prev, GlobalVector& rhs) const override
216 {
217 _mat_trans->computeRhs(*_M, *_K, *_b, x_prev, rhs);
218 }
219
220 void getAandRhsNormalized(GlobalMatrix& A, GlobalVector& rhs) const override
221 {
222 _mat_trans->normalizeAandRhs(A, rhs);
223 }
224
225 void computeKnownSolutions(GlobalVector const& x,
226 int const process_id) override;
227
228 void applyKnownSolutions(GlobalVector& x) const override;
229
230 void applyKnownSolutionsPicard(
232 MathLib::DirichletBCApplicationMode const mode) const override;
233
234 bool isLinear() const override { return _ode.isLinear(); }
235
236 bool requiresNormalization() const override
237 {
238 return _ode.requiresNormalization();
239 }
240
241 void preIteration(const unsigned iter, GlobalVector const& x) override
242 {
243 _ode.preIteration(iter, x);
244 }
245
247 {
248 return _ode.postIteration(x);
249 }
250
253 const int process_id) const override
254 {
255 return _ode.getMatrixSpecifications(process_id);
256 }
257
259 {
260 if (_ode.shouldLinearSolverComputeOnlyUponTimestepChange() &&
261 _time_disc.getCurrentTimeIncrement() !=
262 _time_disc.getPreviousTimeIncrement())
263 {
265 }
266 if (_ode.shouldLinearSolverComputeOnlyUponTimestepChange() &&
267 _time_disc.getCurrentTimeIncrement() ==
268 _time_disc.getPreviousTimeIncrement())
269 {
271 }
273 }
274
275private:
278
280 std::unique_ptr<MatTrans> _mat_trans;
281
283 std::vector<NumLib::IndexValueVector<Index>> const* _known_solutions =
284 nullptr;
285
289
290 std::size_t _M_id = 0u;
291 std::size_t _K_id = 0u;
292 std::size_t _b_id = 0u;
293};
294
296} // 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:20
IterationResult
Status flags telling the NonlinearSolver if an iteration succeeded.
@ FirstOrderImplicitQuasilinear
Definition Types.h:27
DirichletBCApplicationMode
Definition LinAlgEnums.h:33