OGS
MatrixTranslator.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
10#include "Types.h"
11
12namespace NumLib
13{
16
23template <ODESystemTag ODETag>
25
32template <>
34{
35public:
37 virtual void computeA(GlobalMatrix const& M, GlobalMatrix const& K,
38 GlobalMatrix& A) const = 0;
39
41 virtual void computeRhs(const GlobalMatrix& M, const GlobalMatrix& K,
42 const GlobalVector& b, const GlobalVector& x_prev,
43 GlobalVector& rhs) const = 0;
44
47 virtual void normalizeAandRhs(GlobalMatrix& A, GlobalVector& b) const = 0;
48
53 virtual void computeResidual(GlobalMatrix const& M, GlobalMatrix const& K,
54 GlobalVector const& b, double dt,
55 GlobalVector const& x_curr,
56 GlobalVector const& x_prev,
57 GlobalVector& res) const = 0;
58
60 virtual void computeJacobian(GlobalMatrix const& Jac_in,
61 GlobalMatrix& Jac_out) const = 0;
62
63 virtual ~MatrixTranslator() = default;
64};
65
71template <ODESystemTag ODETag>
73
82template <>
84 : public MatrixTranslator<ODESystemTag::FirstOrderImplicitQuasilinear>
85{
86public:
92 : _time_disc(timeDisc)
93 {
94 }
95
97 void computeA(GlobalMatrix const& M, GlobalMatrix const& K,
98 GlobalMatrix& A) const override;
99
101 void computeRhs(const GlobalMatrix& M, const GlobalMatrix& /*K*/,
102 const GlobalVector& b, const GlobalVector& x_prev,
103 GlobalVector& rhs) const override;
104
107 void normalizeAandRhs(GlobalMatrix& A, GlobalVector& b) const override;
108
110 void computeResidual(GlobalMatrix const& M, GlobalMatrix const& K,
111 GlobalVector const& b, double dt,
112 GlobalVector const& x_curr, GlobalVector const& x_prev,
113 GlobalVector& res) const override;
114
117 void computeJacobian(GlobalMatrix const& Jac_in,
118 GlobalMatrix& Jac_out) const override;
119
120private:
122
124 mutable std::size_t _tmp_id = 0u;
125};
126
129template <ODESystemTag ODETag>
130std::unique_ptr<MatrixTranslator<ODETag>> createMatrixTranslator(
131 TimeDiscretization const& timeDisc)
132{
133 return std::unique_ptr<MatrixTranslator<ODETag>>(
134 new MatrixTranslatorGeneral<ODETag>(timeDisc));
135}
136
138} // namespace NumLib
MathLib::EigenMatrix GlobalMatrix
MathLib::EigenVector GlobalVector
std::size_t _tmp_id
ID of the vector storing intermediate computations.
TimeDiscretization const & _time_disc
the time discretization used.
virtual void computeJacobian(GlobalMatrix const &Jac_in, GlobalMatrix &Jac_out) const =0
Computes the Jacobian of the residual and writes it to Jac_out.
virtual void computeA(GlobalMatrix const &M, GlobalMatrix const &K, GlobalMatrix &A) const =0
Computes A from M and K.
virtual void normalizeAandRhs(GlobalMatrix &A, GlobalVector &b) const =0
virtual void computeRhs(const GlobalMatrix &M, const GlobalMatrix &K, const GlobalVector &b, const GlobalVector &x_prev, GlobalVector &rhs) const =0
Computes rhs from M, K, b and x_prev.
virtual void computeResidual(GlobalMatrix const &M, GlobalMatrix const &K, GlobalVector const &b, double dt, GlobalVector const &x_curr, GlobalVector const &x_prev, GlobalVector &res) const =0
std::unique_ptr< MatrixTranslator< ODETag > > createMatrixTranslator(TimeDiscretization const &timeDisc)
ODESystemTag
Tag used to specify the type of ODE.
Definition Types.h:20
@ FirstOrderImplicitQuasilinear
Definition Types.h:27