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& minus_delta_x) const override;
110
112 int const process_id) override
113 {
114 _ode.updateConstraints(lower, upper, process_id);
115 }
116
117 bool isLinear() const override { return _ode.isLinear(); }
118
119 void preIteration(const unsigned iter, GlobalVector const& x) override
120 {
121 _ode.preIteration(iter, x);
122 }
123
125 {
126 return _ode.postIteration(x);
127 }
128
129 TimeDisc& getTimeDiscretization() override { return _time_disc; }
131 const int process_id) const override
132 {
133 return _ode.getMatrixSpecifications(process_id);
134 }
135
136private:
139
141 std::unique_ptr<MatTrans> _mat_trans;
142
144 std::vector<NumLib::IndexValueVector<Index>> const* _known_solutions =
145 nullptr;
146
151
152 std::size_t _Jac_id = 0u;
153 std::size_t _M_id = 0u;
154 std::size_t _K_id = 0u;
155 std::size_t _b_id = 0u;
156};
157
164template <>
167 final : public TimeDiscretizedODESystemBase<NonlinearSolverTag::Picard>
168{
169public:
171 static const ODESystemTag ODETag =
173
181
183 explicit TimeDiscretizedODESystem(const int process_id, ODE& ode,
184 TimeDisc& time_discretization);
185
186 ~TimeDiscretizedODESystem() override;
187
188 void assemble(std::vector<GlobalVector*> const& x_new_timestep,
189 std::vector<GlobalVector*> const& x_prev,
190 int const process_id) override;
191
194 std::vector<GlobalIndexType>
196 {
197 return _ode.getIndicesOfResiduumWithoutInitialCompensation();
198 }
199
200 void getA(GlobalMatrix& A) const override
201 {
202 _mat_trans->computeA(*_M, *_K, A);
203 }
204
205 void getRhs(GlobalVector const& x_prev, GlobalVector& rhs) const override
206 {
207 _mat_trans->computeRhs(*_M, *_K, *_b, x_prev, rhs);
208 }
209
210 void computeKnownSolutions(GlobalVector const& x,
211 int const process_id) override;
212
213 void applyKnownSolutions(GlobalVector& x) const override;
214
215 void applyKnownSolutionsPicard(GlobalMatrix& A, GlobalVector& rhs,
216 GlobalVector& x) const override;
217
218 bool isLinear() const override { return _ode.isLinear(); }
219
220 void preIteration(const unsigned iter, GlobalVector const& x) override
221 {
222 _ode.preIteration(iter, x);
223 }
224
226 {
227 return _ode.postIteration(x);
228 }
229
230 TimeDisc& getTimeDiscretization() override { return _time_disc; }
232 const int process_id) const override
233 {
234 return _ode.getMatrixSpecifications(process_id);
235 }
236
237 bool linearSolverNeedsToCompute() const override
238 {
239 return !_ode.shouldLinearSolverComputeOnlyUponTimestepChange() ||
240 _time_disc.getCurrentTimeIncrement() !=
241 _time_disc.getPreviousTimeIncrement();
242 }
243
244private:
247
249 std::unique_ptr<MatTrans> _mat_trans;
250
252 std::vector<NumLib::IndexValueVector<Index>> const* _known_solutions =
253 nullptr;
254
258
259 std::size_t _M_id = 0u;
260 std::size_t _K_id = 0u;
261 std::size_t _b_id = 0u;
262};
263
265} // 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.