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
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
144 TimeDisc& getTimeDiscretization() override { return _time_disc; }
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(GlobalMatrix& A, GlobalVector& rhs,
238 GlobalVector& x) const override;
239
240 bool isLinear() const override { return _ode.isLinear(); }
241
242 bool requiresNormalization() const override
243 {
244 return _ode.requiresNormalization();
245 }
246
247 void preIteration(const unsigned iter, GlobalVector const& x) override
248 {
249 _ode.preIteration(iter, x);
250 }
251
253 {
254 return _ode.postIteration(x);
255 }
256
257 TimeDisc& getTimeDiscretization() override { return _time_disc; }
259 const int process_id) const override
260 {
261 return _ode.getMatrixSpecifications(process_id);
262 }
263
265 {
266 if (_ode.shouldLinearSolverComputeOnlyUponTimestepChange() &&
267 _time_disc.getCurrentTimeIncrement() !=
268 _time_disc.getPreviousTimeIncrement())
269 {
271 }
272 if (_ode.shouldLinearSolverComputeOnlyUponTimestepChange() &&
273 _time_disc.getCurrentTimeIncrement() ==
274 _time_disc.getPreviousTimeIncrement())
275 {
277 }
279 }
280
281private:
284
286 std::unique_ptr<MatTrans> _mat_trans;
287
289 std::vector<NumLib::IndexValueVector<Index>> const* _known_solutions =
290 nullptr;
291
295
296 std::size_t _M_id = 0u;
297 std::size_t _K_id = 0u;
298 std::size_t _b_id = 0u;
299};
300
302} // namespace NumLib
Global vector based on Eigen vector.
Definition EigenVector.h:26
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.