OGS
TimeDiscretizedODESystem.h
Go to the documentation of this file.
1
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
97 void getResidual(GlobalVector const& x_new_timestep,
98 GlobalVector const& x_prev,
99 GlobalVector& res) const override;
100
101 void getJacobian(GlobalMatrix& Jac) const override;
102
103 void computeKnownSolutions(GlobalVector const& x,
104 int const process_id) override;
105
106 void applyKnownSolutions(GlobalVector& x) const override;
107
108 void applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res,
109 GlobalVector const& x,
110 GlobalVector& minus_delta_x) const override;
111
112 void applyKnownSolutionsPETScSNES(GlobalMatrix& Jac, GlobalVector& res,
113 GlobalVector& x) const override;
114
116 int const process_id) override
117 {
118 _ode.updateConstraints(lower, upper, process_id);
119 }
120
121 bool isLinear() const override { return _ode.isLinear(); }
122
123 bool requiresNormalization() const override
124 {
125 return _ode.requiresNormalization();
126 }
127
128 void preIteration(const unsigned iter, GlobalVector const& x) override
129 {
130 _ode.preIteration(iter, x);
131 }
132
134 {
135 return _ode.postIteration(x);
136 }
137
138 TimeDisc& getTimeDiscretization() override { return _time_disc; }
140 const int process_id) const override
141 {
142 return _ode.getMatrixSpecifications(process_id);
143 }
144
145private:
148
150 std::unique_ptr<MatTrans> _mat_trans;
151
153 std::vector<NumLib::IndexValueVector<Index>> const* _known_solutions =
154 nullptr;
155
158
159 std::size_t _Jac_id = 0u;
160 std::size_t _b_id = 0u;
161};
162
169template <>
172 final : public TimeDiscretizedODESystemBase<NonlinearSolverTag::Picard>
173{
174public:
176 static const ODESystemTag ODETag =
178
186
188 explicit TimeDiscretizedODESystem(const int process_id, ODE& ode,
189 TimeDisc& time_discretization);
190
191 ~TimeDiscretizedODESystem() override;
192
193 void assemble(std::vector<GlobalVector*> const& x_new_timestep,
194 std::vector<GlobalVector*> const& x_prev,
195 int const process_id) override;
196
199 std::vector<GlobalIndexType>
201 {
202 return _ode.getIndicesOfResiduumWithoutInitialCompensation();
203 }
204
205 void getA(GlobalMatrix& A) const override
206 {
207 _mat_trans->computeA(*_M, *_K, A);
208 }
209
210 void getRhs(GlobalVector const& x_prev, GlobalVector& rhs) const override
211 {
212 _mat_trans->computeRhs(*_M, *_K, *_b, x_prev, rhs);
213 }
214
215 void getAandRhsNormalized(GlobalMatrix& A, GlobalVector& rhs) const override
216 {
217 _mat_trans->normalizeAandRhs(A, rhs);
218 }
219
220 void computeKnownSolutions(GlobalVector const& x,
221 int const process_id) override;
222
223 void applyKnownSolutions(GlobalVector& x) const override;
224
225 void applyKnownSolutionsPicard(GlobalMatrix& A, GlobalVector& rhs,
226 GlobalVector& x) const override;
227
228 bool isLinear() const override { return _ode.isLinear(); }
229
230 bool requiresNormalization() const override
231 {
232 return _ode.requiresNormalization();
233 }
234
235 void preIteration(const unsigned iter, GlobalVector const& x) override
236 {
237 _ode.preIteration(iter, x);
238 }
239
241 {
242 return _ode.postIteration(x);
243 }
244
245 TimeDisc& getTimeDiscretization() override { return _time_disc; }
247 const int process_id) const override
248 {
249 return _ode.getMatrixSpecifications(process_id);
250 }
251
253 {
254 if (_ode.shouldLinearSolverComputeOnlyUponTimestepChange() &&
255 _time_disc.getCurrentTimeIncrement() !=
256 _time_disc.getPreviousTimeIncrement())
257 {
259 }
260 if (_ode.shouldLinearSolverComputeOnlyUponTimestepChange() &&
261 _time_disc.getCurrentTimeIncrement() ==
262 _time_disc.getPreviousTimeIncrement())
263 {
265 }
267 }
268
269private:
272
274 std::unique_ptr<MatTrans> _mat_trans;
275
277 std::vector<NumLib::IndexValueVector<Index>> const* _known_solutions =
278 nullptr;
279
283
284 std::size_t _M_id = 0u;
285 std::size_t _K_id = 0u;
286 std::size_t _b_id = 0u;
287};
288
290} // namespace NumLib
Global vector based on Eigen vector.
Definition EigenVector.h:25
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
void updateConstraints(GlobalVector &lower, GlobalVector &upper, int const process_id) override
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.