Sandals  v0.0.0
A C++ library for ODEs/DAEs integration
Loading...
Searching...
No Matches
SemiExplicit.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
11#pragma once
12
13#ifndef SANDALS_SEMIEXPLICIT_SYSTEM_HXX
14#define SANDALS_SEMIEXPLICIT_SYSTEM_HXX
15
16namespace Sandals {
17
18 /*\
19 | ____ _ _____ _ _ _ _
20 | / ___| ___ _ __ ___ (_) ____|_ ___ __ | (_) ___(_) |_
21 | \___ \ / _ \ '_ ` _ \| | _| \ \/ / '_ \| | |/ __| | __|
22 | ___) | __/ | | | | | | |___ > <| |_) | | | (__| | |_
23 | |____/ \___|_| |_| |_|_|_____/_/\_\ .__/|_|_|\___|_|\__|
24 | |_|
25 \*/
26
37 template <Integer N, Integer M = 0>
38 class SemiExplicit : public Explicit<N, M>
39 {
40 public:
41 using Pointer = std::shared_ptr<SemiExplicit<N, M>>;
45 using TensorTA = typename std::vector<MatrixJF>;
48 using Type = typename Explicit<N, M>::Type;
49
50 private:
51 mutable Eigen::FullPivLU<MatrixA> m_lu;
52
53 public:
54
58 SemiExplicit() : Explicit<N, M>(Type::SEMIEXPLICIT, "(missing name)") {}
59
64 SemiExplicit(std::string t_name) : Explicit<N, M>(Type::SEMIEXPLICIT, t_name) {}
65
79 VectorF F(VectorF const &x, VectorF const &x_dot, Real t) const override
80 {
81 return this->A(x, t)*x_dot - this->b(x, t);
82 }
83
101 MatrixJF JF_x(VectorF const &x, VectorF const &x_dot, Real t) const override
102 {
103 return -this->Jf_x(x, x_dot, t);
104 }
105
121 MatrixJF JF_x_dot(VectorF const &x, VectorF const &/*x_dot*/, Real t) const override
122 {
123 return this->A(x, t);
124 }
125
137 VectorF f(VectorF const &x, Real t) const override
138 {
139 this->m_lu.compute(this->A(x, t));
140 SANDALS_ASSERT(this->m_lu.rank() == N,
141 "Sandals:SemiExplicit::f(...): singular mass matrix A detected.");
142 return this->m_lu.solve(this->b(x, t));
143 }
144
160 MatrixJF Jf_x(VectorF const &x, VectorF const &x_dot, Real t) const
161 {
162 TensorTA TA_x{this->TA_x(x, t)};
163 MatrixJF tAp{MatrixJF::Zero()};
164 for (Integer i{0}; i < N; ++i) {tAp.col(i) = TA_x[i] * x_dot;} // TODO: Check if TA_x.size() = N
165 this->m_lu.compute(this->A(x, t));
166 SANDALS_ASSERT(this->m_lu.rank() == N,
167 "Sandals:SemiExplicit::Jf_x(...): singular mass matrix A detected.");
168 return this->m_lu.solve(this->Jb_x(x, t) - tAp);
169 }
170
185 MatrixJF Jf_x(VectorF const &x, Real t) const override {return this->Jf_x(x, this->f(x, t), t);}
186
193 virtual MatrixA A(VectorF const &x, Real t) const = 0;
194
208 virtual TensorTA TA_x(VectorF const &x, Real t) const = 0;
209
216 virtual VectorB b(VectorF const &x, Real t) const = 0;
217
231 virtual MatrixJB Jb_x(VectorF const &x, Real t) const = 0;
232
233 }; // class SemiExplicit
234
235} // namespace Sandals
236
237#endif // SANDALS_SEMIEXPLICIT_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
virtual TensorTA TA_x(VectorF const &x, Real t) const =0
SemiExplicit()
Definition SemiExplicit.hxx:58
VectorF F(VectorF const &x, VectorF const &x_dot, Real t) const override
Definition SemiExplicit.hxx:79
typename Explicit< N, M >::VectorF VectorB
Definition SemiExplicit.hxx:46
virtual MatrixA A(VectorF const &x, Real t) const =0
SemiExplicit(std::string t_name)
Definition SemiExplicit.hxx:64
typename Explicit< N, M >::MatrixJF MatrixA
Definition SemiExplicit.hxx:44
typename Explicit< N, M >::Type Type
Definition SemiExplicit.hxx:48
MatrixJF Jf_x(VectorF const &x, VectorF const &x_dot, Real t) const
Definition SemiExplicit.hxx:160
Eigen::FullPivLU< MatrixA > m_lu
Definition SemiExplicit.hxx:51
MatrixJF Jf_x(VectorF const &x, Real t) const override
Definition SemiExplicit.hxx:185
MatrixJF JF_x_dot(VectorF const &x, VectorF const &, Real t) const override
Definition SemiExplicit.hxx:121
typename std::vector< MatrixJF > TensorTA
Definition SemiExplicit.hxx:45
typename Explicit< N, M >::MatrixJF MatrixJF
Definition SemiExplicit.hxx:43
virtual VectorB b(VectorF const &x, Real t) const =0
typename Explicit< N, M >::MatrixJF MatrixJB
Definition SemiExplicit.hxx:47
MatrixJF JF_x(VectorF const &x, VectorF const &x_dot, Real t) const override
Definition SemiExplicit.hxx:101
virtual MatrixJB Jb_x(VectorF const &x, Real t) const =0
std::shared_ptr< SemiExplicit< N, M > > Pointer
Definition SemiExplicit.hxx:41
typename Explicit< N, M >::VectorF VectorF
Definition SemiExplicit.hxx:42
VectorF f(VectorF const &x, Real t) const override
Definition SemiExplicit.hxx:137
The namespace for the Sandals library.
Definition Sandals.hh:73
double Real
Definition Sandals.hh:84
int Integer
Definition Sandals.hh:85