Sandals  v0.0.0
A C++ library for ODEs/DAEs integration
Loading...
Searching...
No Matches
Solution.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_SOLUTION_HXX
14#define SANDALS_SOLUTION_HXX
15
16namespace Sandals {
17
18 /*\
19 | ____ _ _ _
20 | / ___| ___ | |_ _| |_(_) ___ _ __
21 | \___ \ / _ \| | | | | __| |/ _ \| '_ \
22 | ___) | (_) | | |_| | |_| | (_) | | | |
23 | |____/ \___/|_|\__,_|\__|_|\___/|_| |_|
24 |
25 \*/
26
55 template <Integer N, Integer M = 0>
56 struct Solution
57 {
58 using Vector = Eigen::Vector<Real, Eigen::Dynamic>;
59 using MatrixN = Eigen::Matrix<Real, N, Eigen::Dynamic>;
60 using MatrixM = Eigen::Matrix<Real, M, Eigen::Dynamic>;
61
65
69 Solution() : t(0), x(Vector::Zero(N, 0)), h(Vector::Zero(M, 0)) {}
70
76 : t(size), x(Vector::Zero(N, size)), h(Vector::Zero(M, size)) {}
77
83 this->t.resize(size);
84 this->x.resize(Eigen::NoChange, size);
85 this->h.resize(Eigen::NoChange, size);
86 }
87
93 this->t.conservativeResize(size);
94 this->x.conservativeResize(Eigen::NoChange, size);
95 this->h.conservativeResize(Eigen::NoChange, size);
96 }
97
101 void clear()
102 {
103 this->t.resize(0);
104 this->x.resize(Eigen::NoChange, 0);
105 this->h.resize(Eigen::NoChange, 0);
106 }
107
112 bool is_empty() const
113 {
114 return this->t.size() == 0 && this->x.cols()== 0 && this->h.cols() == 0;
115 }
116
121 Integer size() const {return this->t.size();}
122
127 std::vector<Real> std_t() const
128 {
129 return std::vector<Real>(this->t.data(), this->t.data() + this->t.size());
130 }
131
136 Vector eig_t() const {return this->t;}
137
143 std::vector<Real> std_x(Integer i) const
144 {
145 Vector tmp(this->x.row(i));
146 return std::vector<Real>(tmp.data(), tmp.data() + tmp.size());
147 }
148
153 std::map<Integer, std::vector<Real>> std_x() const
154 {
155 std::map<Integer, std::vector<Real>> x_map;
156 for (Integer i{0}; i < N; ++i) {x_map[i] = this->std_x(i);}
157 return x_map;
158 }
159
164 std::map<Integer, Vector> eig_x() const
165 {
166 std::map<Integer, Vector> x_map;
167 for (Integer i{0}; i < N; ++i) {x_map[i] = this->x.row(i);}
168 return x_map;
169 }
170
176 std::map<std::string, std::vector<Real>> std_x(std::vector<std::string> names) const
177 {
178 std::map<std::string, std::vector<Real>> x_map;
179 for (Integer i{0}; i < N; ++i) {x_map[names[i]] = this->std_x(i);}
180 return x_map;
181 }
182
188 std::map<std::string, Vector> eig_x(std::vector<std::string> names) const
189 {
190 std::map<std::string, Vector> x_map;
191 for (Integer i{0}; i < N; ++i) {x_map[names[i]] = this->x.row(i);}
192 return x_map;
193 }
194
200 std::vector<Real> std_h(Integer i) const
201 {
202 Vector tmp(this->h.row(i));
203 return std::vector<Real>(tmp.data(), tmp.data() + tmp.size());
204 }
205
210 std::map<Integer, std::vector<Real>> std_h() const
211 {
212 std::map<Integer, std::vector<Real>> h_map;
213 for (Integer i{0}; i < M; ++i) {h_map[i] = this->std_h(i);}
214 return h_map;
215 }
216
221 std::map<Integer, Vector> eig_h() const
222 {
223 std::map<Integer, Vector> h_map;
224 for (Integer i{0}; i < M; ++i) {h_map[i] = this->h.row(i);}
225 return h_map;
226 }
227
233 std::map<std::string, std::vector<Real>> std_h(std::vector<std::string> names) const
234 {
235 std::map<std::string, std::vector<Real>> h_map;
236 for (Integer i{0}; i < M; ++i) {h_map[names[i]] = this->std_h(i);}
237 return h_map;
238 }
239
245 std::map<std::string, Vector> eig_h(std::vector<std::string> names) const
246 {
247 std::map<std::string, Vector> h_map;
248 for (Integer i{0}; i < M; ++i) {h_map[names[i]] = this->h.row(i);}
249 return h_map;
250 }
251 };
252
253} // namespace Sandals
254
255#endif // SANDALS_SOLUTION_HXX
The namespace for the Sandals library.
Definition Sandals.hh:73
int Integer
Definition Sandals.hh:85
std::vector< Real > std_t() const
Definition Solution.hxx:127
Vector eig_t() const
Definition Solution.hxx:136
void clear()
Definition Solution.hxx:101
Vector t
Definition Solution.hxx:62
std::map< std::string, Vector > eig_h(std::vector< std::string > names) const
Definition Solution.hxx:245
std::map< std::string, Vector > eig_x(std::vector< std::string > names) const
Definition Solution.hxx:188
std::map< Integer, std::vector< Real > > std_h() const
Definition Solution.hxx:210
std::map< Integer, Vector > eig_x() const
Definition Solution.hxx:164
Eigen::Matrix< Real, M, Eigen::Dynamic > MatrixM
Definition Solution.hxx:60
std::vector< Real > std_x(Integer i) const
Definition Solution.hxx:143
Eigen::Matrix< Real, N, Eigen::Dynamic > MatrixN
Definition Solution.hxx:59
std::map< std::string, std::vector< Real > > std_x(std::vector< std::string > names) const
Definition Solution.hxx:176
Eigen::Vector< Real, Eigen::Dynamic > Vector
Definition Solution.hxx:58
void resize(Integer size)
Definition Solution.hxx:82
void conservative_resize(Integer size)
Definition Solution.hxx:92
bool is_empty() const
Definition Solution.hxx:112
std::map< std::string, std::vector< Real > > std_h(std::vector< std::string > names) const
Definition Solution.hxx:233
MatrixN x
Definition Solution.hxx:63
Integer size() const
Definition Solution.hxx:121
Solution(Integer size)
Definition Solution.hxx:75
std::vector< Real > std_h(Integer i) const
Definition Solution.hxx:200
Solution()
Definition Solution.hxx:69
MatrixM h
Definition Solution.hxx:64
std::map< Integer, Vector > eig_h() const
Definition Solution.hxx:221
std::map< Integer, std::vector< Real > > std_x() const
Definition Solution.hxx:153