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 
20 namespace NumLib
21 {
24 
32 template <NonlinearSolverTag NLTag>
34 {
35 public:
38 };
39 
48 template <ODESystemTag ODETag, NonlinearSolverTag NLTag>
50 
56 template <>
59  final : public TimeDiscretizedODESystemBase<NonlinearSolverTag::Newton>
60 {
61 public:
63  static const ODESystemTag ODETag =
65 
73 
80  explicit TimeDiscretizedODESystem(const int process_id, ODE& ode,
81  TimeDisc& time_discretization);
82 
83  ~TimeDiscretizedODESystem() override;
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 
89  void getResidual(GlobalVector const& x_new_timestep,
90  GlobalVector const& x_prev,
91  GlobalVector& res) const override;
92 
93  void getJacobian(GlobalMatrix& Jac) const override;
94 
95  void computeKnownSolutions(GlobalVector const& x,
96  int const process_id) override;
97 
98  void applyKnownSolutions(GlobalVector& x) const override;
99 
100  void applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res,
101  GlobalVector& minus_delta_x) const override;
102 
104  int const process_id) override
105  {
106  _ode.updateConstraints(lower, upper, process_id);
107  }
108 
109  bool isLinear() const override { return _ode.isLinear(); }
110 
111  void preIteration(const unsigned iter, GlobalVector const& x) override
112  {
113  _ode.preIteration(iter, x);
114  }
115 
117  {
118  return _ode.postIteration(x);
119  }
120 
121  TimeDisc& getTimeDiscretization() override { return _time_disc; }
123  const int process_id) const override
124  {
125  return _ode.getMatrixSpecifications(process_id);
126  }
127 
128 private:
131 
133  std::unique_ptr<MatTrans> _mat_trans;
134 
136  std::vector<NumLib::IndexValueVector<Index>> const* _known_solutions =
137  nullptr;
138 
143 
144  std::size_t _Jac_id = 0u;
145  std::size_t _M_id = 0u;
146  std::size_t _K_id = 0u;
147  std::size_t _b_id = 0u;
148 
150  mutable std::size_t _xdot_id = 0u;
151  mutable std::vector<std::size_t> _xdot_ids;
152 };
153 
160 template <>
163  final : public TimeDiscretizedODESystemBase<NonlinearSolverTag::Picard>
164 {
165 public:
167  static const ODESystemTag ODETag =
169 
177 
179  explicit TimeDiscretizedODESystem(const int process_id, ODE& ode,
180  TimeDisc& time_discretization);
181 
182  ~TimeDiscretizedODESystem() override;
183 
184  void assemble(std::vector<GlobalVector*> const& x_new_timestep,
185  std::vector<GlobalVector*> const& x_prev,
186  int const process_id) override;
187 
188  void getA(GlobalMatrix& A) const override
189  {
190  _mat_trans->computeA(*_M, *_K, A);
191  }
192 
193  void getRhs(GlobalVector const& x_prev, GlobalVector& rhs) const override
194  {
195  _mat_trans->computeRhs(*_M, *_K, *_b, x_prev, rhs);
196  }
197 
198  void computeKnownSolutions(GlobalVector const& x,
199  int const process_id) override;
200 
201  void applyKnownSolutions(GlobalVector& x) const override;
202 
203  void applyKnownSolutionsPicard(GlobalMatrix& A, GlobalVector& rhs,
204  GlobalVector& x) const override;
205 
206  bool isLinear() const override { return _ode.isLinear(); }
207 
208  void preIteration(const unsigned iter, GlobalVector const& x) override
209  {
210  _ode.preIteration(iter, x);
211  }
212 
214  {
215  return _ode.postIteration(x);
216  }
217 
218  TimeDisc& getTimeDiscretization() override { return _time_disc; }
220  const int process_id) const override
221  {
222  return _ode.getMatrixSpecifications(process_id);
223  }
224 
225 private:
228 
230  std::unique_ptr<MatTrans> _mat_trans;
231 
233  std::vector<NumLib::IndexValueVector<Index>> const* _known_solutions =
234  nullptr;
235 
239 
240  std::size_t _M_id = 0u;
241  std::size_t _K_id = 0u;
242  std::size_t _b_id = 0u;
243  mutable std::vector<std::size_t> _xdot_ids;
244 };
245 
247 } // 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.
void applyKnownSolutions(std::vector< Solutions > const *const known_solutions, Vector &x)
Applies known solutions to the solution vector x.