Sandals  v0.0.0
A C++ library for ODEs/DAEs integration
Loading...
Searching...
No Matches
Solution.hh
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_SOLUTION_HH
14#define SANDALS_SOLUTION_HH
15
16#include <Sandals.hh>
17
18namespace Sandals {
19
20 /*\
21 | ____ _ _ _
22 | / ___| ___ | |_ _| |_(_) ___ _ __
23 | \___ \ / _ \| | | | | __| |/ _ \| '_ \
24 | ___) | (_) | | |_| | |_| | (_) | | | |
25 | |____/ \___/|_|\__,_|\__|_|\___/|_| |_|
26 |
27 \*/
28
58 template <typename Real, Integer N, Integer M = 0>
59 struct Solution
60 {
61 using Vector = Eigen::Vector<Real, Eigen::Dynamic>;
62 using MatrixN = Eigen::Matrix<Real, N, Eigen::Dynamic>;
63 using MatrixM = Eigen::Matrix<Real, M, Eigen::Dynamic>;
64
68
72 Solution() : t(0), x(Vector::Zero(N, 0)), h(Vector::Zero(M, 0)) {}
73
79 : t(size), x(Vector::Zero(N, size)), h(Vector::Zero(M, size)) {}
80
86 this->t.resize(size);
87 this->x.resize(Eigen::NoChange, size);
88 this->h.resize(Eigen::NoChange, size);
89 }
90
96 this->t.conservativeResize(size);
97 this->x.conservativeResize(Eigen::NoChange, size);
98 this->h.conservativeResize(Eigen::NoChange, size);
99 }
100
104 void clear()
105 {
106 this->t.resize(0);
107 this->x.resize(Eigen::NoChange, 0);
108 this->h.resize(Eigen::NoChange, 0);
109 }
110
115 bool is_empty() const
116 {
117 return this->t.size() == 0 && this->x.cols()== 0 && this->h.cols() == 0;
118 }
119
124 Integer size() const {return this->t.size();}
125
130 std::vector<Real> std_t() const
131 {
132 return std::vector<Real>(this->t.data(), this->t.data() + this->t.size());
133 }
134
139 Vector eig_t() const {return this->t;}
140
146 std::vector<Real> std_x(Integer i) const
147 {
148 Vector tmp(this->x.row(i));
149 return std::vector<Real>(tmp.data(), tmp.data() + tmp.size());
150 }
151
156 std::map<Integer, std::vector<Real>> std_x() const
157 {
158 std::map<Integer, std::vector<Real>> x_map;
159 for (Integer i{0}; i < N; ++i) {x_map[i] = this->std_x(i);}
160 return x_map;
161 }
162
167 std::map<Integer, Vector> eig_x() const
168 {
169 std::map<Integer, Vector> x_map;
170 for (Integer i{0}; i < N; ++i) {x_map[i] = this->x.row(i);}
171 return x_map;
172 }
173
179 std::map<std::string, std::vector<Real>> std_x(std::vector<std::string> names) const
180 {
181 std::map<std::string, std::vector<Real>> x_map;
182 for (Integer i{0}; i < N; ++i) {x_map[names[i]] = this->std_x(i);}
183 return x_map;
184 }
185
191 std::map<std::string, Vector> eig_x(std::vector<std::string> names) const
192 {
193 std::map<std::string, Vector> x_map;
194 for (Integer i{0}; i < N; ++i) {x_map[names[i]] = this->x.row(i);}
195 return x_map;
196 }
197
203 std::vector<Real> std_h(Integer i) const
204 {
205 Vector tmp(this->h.row(i));
206 return std::vector<Real>(tmp.data(), tmp.data() + tmp.size());
207 }
208
213 std::map<Integer, std::vector<Real>> std_h() const
214 {
215 std::map<Integer, std::vector<Real>> h_map;
216 for (Integer i{0}; i < M; ++i) {h_map[i] = this->std_h(i);}
217 return h_map;
218 }
219
224 std::map<Integer, Vector> eig_h() const
225 {
226 std::map<Integer, Vector> h_map;
227 for (Integer i{0}; i < M; ++i) {h_map[i] = this->h.row(i);}
228 return h_map;
229 }
230
236 std::map<std::string, std::vector<Real>> std_h(std::vector<std::string> names) const
237 {
238 std::map<std::string, std::vector<Real>> h_map;
239 for (Integer i{0}; i < M; ++i) {h_map[names[i]] = this->std_h(i);}
240 return h_map;
241 }
242
248 std::map<std::string, Vector> eig_h(std::vector<std::string> names) const
249 {
250 std::map<std::string, Vector> h_map;
251 for (Integer i{0}; i < M; ++i) {h_map[names[i]] = this->h.row(i);}
252 return h_map;
253 }
254 };
255
256} // namespace Sandals
257
258#endif // SANDALS_SOLUTION_HH
The namespace for the Sandals library.
Definition Sandals.hh:89
SANDALS_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Sandals.hh:97
MatrixN x
Definition Solution.hh:66
Solution()
Definition Solution.hh:72
Integer size() const
Definition Solution.hh:124
std::map< std::string, Vector > eig_h(std::vector< std::string > names) const
Definition Solution.hh:248
bool is_empty() const
Definition Solution.hh:115
Eigen::Matrix< Real, M, Eigen::Dynamic > MatrixM
Definition Solution.hh:63
std::vector< Real > std_t() const
Definition Solution.hh:130
Vector eig_t() const
Definition Solution.hh:139
std::map< Integer, std::vector< Real > > std_h() const
Definition Solution.hh:213
std::map< Integer, std::vector< Real > > std_x() const
Definition Solution.hh:156
std::map< std::string, Vector > eig_x(std::vector< std::string > names) const
Definition Solution.hh:191
Eigen::Matrix< Real, N, Eigen::Dynamic > MatrixN
Definition Solution.hh:62
Solution(Integer size)
Definition Solution.hh:78
void resize(Integer size)
Definition Solution.hh:85
Vector t
Definition Solution.hh:65
std::map< std::string, std::vector< Real > > std_x(std::vector< std::string > names) const
Definition Solution.hh:179
void clear()
Definition Solution.hh:104
std::vector< Real > std_h(Integer i) const
Definition Solution.hh:203
std::map< Integer, Vector > eig_x() const
Definition Solution.hh:167
void conservative_resize(Integer size)
Definition Solution.hh:95
MatrixM h
Definition Solution.hh:67
Eigen::Vector< Real, Eigen::Dynamic > Vector
Definition Solution.hh:61
std::map< Integer, Vector > eig_h() const
Definition Solution.hh:224
std::map< std::string, std::vector< Real > > std_h(std::vector< std::string > names) const
Definition Solution.hh:236
std::vector< Real > std_x(Integer i) const
Definition Solution.hh:146