Sandals  v0.0.0
A C++ library for ODEs/DAEs integration
Loading...
Searching...
No Matches
Linear.hxx
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *
3 * *
4 * The Sandals project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Enrico Bertolazzi *
7 * University of Trento University of Trento *
8 * e-mail: davide.stocco@unitn.it e-mail: enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10#pragma once
11
12#ifndef SANDALS_LINEAR_SYSTEM_HXX
13#define SANDALS_LINEAR_SYSTEM_HXX
14
15namespace Sandals {
16
17 /*\
18 | _ _
19 | | | (_)_ __ ___ __ _ _ __
20 | | | | | '_ \ / _ \/ _` | '__|
21 | | |___| | | | | __/ (_| | |
22 | |_____|_|_| |_|\___|\__,_|_|
23 |
24 \*/
25
35 template <Integer N, Integer M = 0>
36 class Linear : public Explicit<N, M>
37 {
38 public:
39 using Pointer = std::shared_ptr<SemiExplicit<N, M>>;
45 using Type = typename Explicit<N, M>::Type;
46
47 private:
48 Eigen::FullPivLU<MatrixE> m_lu;
49
50 public:
54 Linear() : Explicit<N, M>(Type::LINEAR, "(missing name)") {}
55
60 Linear(std::string t_name) : Explicit<N, M>(Type::LINEAR, t_name) {}
61
75 VectorF F(VectorF const &x, VectorF const &x_dot, Real t) const override
76 {
77 return this->E(t)*x_dot - this->A(t)*x - this->b(t);
78 }
79
95 MatrixJF JF_x(VectorF const &/*x*/, VectorF const &/*x_dot*/, Real t) const override {return -this->A(t);}
96
112 MatrixJF JF_x_dot(VectorF const &/*x*/, VectorF const &/*x_dot*/, Real t) const override {return this->E(t);}
113
125 VectorF f(VectorF const &x, Real t) const override
126 {
127 this->m_lu.compute(this->E(t));
128 SANDALS_ASSERT(this->m_lu.rank() == N, "Sandals:Linear::f(...): singular mass matrix E(t) detected.");
129 return this->m_lu.solve(this->A(t)*x + this->b(t));
130 }
131
145 MatrixJF Jf_x(VectorF const &/*x*/, Real t) const override
146 {
147 this->m_lu.compute(this->E(t));
148 SANDALS_ASSERT(this->m_lu.rank() == N, "Sandals:Linear::Jf_x(...): singular mass matrix E(t) detected.");
149 return this->m_lu.solve(this->A(t));
150 }
151
157 virtual MatrixE E(Real t) const = 0;
158
164 virtual MatrixA A(Real t) const = 0;
165
171 virtual VectorB b(Real t) const = 0;
172
173 }; // class Linear
174
175} // namespace Sandals
176
177#endif // SANDALS_LINEAR_SYSTEM_HXX
#define SANDALS_ASSERT(COND, MSG)
Definition Sandals.hh:43
typename Implicit< N, M >::MatrixJF MatrixJF
Definition Explicit.hxx:42
Explicit(Type t_type, std::string t_name)
Definition Explicit.hxx:52
typename Implicit< N, M >::Type Type
Definition Explicit.hxx:43
typename Implicit< N, M >::VectorF VectorF
Definition Explicit.hxx:41
typename Explicit< N, M >::MatrixJF MatrixE
Definition Linear.hxx:42
MatrixJF JF_x(VectorF const &, VectorF const &, Real t) const override
Definition Linear.hxx:95
Linear()
Definition Linear.hxx:54
MatrixJF JF_x_dot(VectorF const &, VectorF const &, Real t) const override
Definition Linear.hxx:112
VectorF F(VectorF const &x, VectorF const &x_dot, Real t) const override
Definition Linear.hxx:75
virtual MatrixE E(Real t) const =0
VectorF f(VectorF const &x, Real t) const override
Definition Linear.hxx:125
typename Explicit< N, M >::Type Type
Definition Linear.hxx:45
virtual MatrixA A(Real t) const =0
typename Explicit< N, M >::MatrixJF MatrixA
Definition Linear.hxx:43
typename Explicit< N, M >::MatrixJF MatrixJF
Definition Linear.hxx:41
typename Explicit< N, M >::VectorF VectorF
Definition Linear.hxx:40
Linear(std::string t_name)
Definition Linear.hxx:60
Eigen::FullPivLU< MatrixE > m_lu
Definition Linear.hxx:48
typename Explicit< N, M >::VectorF VectorB
Definition Linear.hxx:44
std::shared_ptr< SemiExplicit< N, M > > Pointer
Definition Linear.hxx:39
MatrixJF Jf_x(VectorF const &, Real t) const override
Definition Linear.hxx:145
virtual VectorB b(Real t) const =0
The namespace for the Sandals library.
Definition Sandals.hh:73
double Real
Definition Sandals.hh:84