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
60 template <typename Real, Integer N, Integer M = 0>
61 struct Solution
62 {
63 using Vector = Eigen::Vector<Real, Eigen::Dynamic>;
64 using MatrixN = Eigen::Matrix<Real, N, Eigen::Dynamic, Eigen::RowMajor>;
65 using MatrixM = Eigen::Matrix<Real, M, Eigen::Dynamic, Eigen::RowMajor>;
66
70
74 Solution() : t(0), x(Vector::Zero(N, 0)), h(Vector::Zero(M, 0)) {}
75
81 : t(size), x(Vector::Zero(N, size)), h(Vector::Zero(M, size)) {}
82
87 void resize(Integer const size) {
88 this->t.resize(size);
89 this->x.resize(Eigen::NoChange, size);
90 this->h.resize(Eigen::NoChange, size);
91 }
92
98 this->t.conservativeResize(size);
99 this->x.conservativeResize(Eigen::NoChange, size);
100 this->h.conservativeResize(Eigen::NoChange, size);
101 }
102
106 void clear()
107 {
108 this->t.resize(0);
109 this->x.resize(Eigen::NoChange, 0);
110 this->h.resize(Eigen::NoChange, 0);
111 }
112
117 bool is_empty() const
118 {
119 return this->t.size() == 0 && this->x.cols()== 0 && this->h.cols() == 0;
120 }
121
126 Integer size() const {return this->t.size();}
127
132 std::vector<Real> std_t() const
133 {
134 return std::vector<Real>(this->t.data(), this->t.data() + this->t.size());
135 }
136
141 Vector eig_t() const {return this->t;}
142
148 std::vector<Real> std_x(Integer i) const
149 {
150 Vector tmp(this->x.row(i));
151 return std::vector<Real>(tmp.data(), tmp.data() + tmp.size());
152 }
153
158 std::map<Integer, std::vector<Real>> std_x() const
159 {
160 std::map<Integer, std::vector<Real>> x_map;
161 for (Integer i{0}; i < N; ++i) {x_map[i] = this->std_x(i);}
162 return x_map;
163 }
164
169 std::map<Integer, Vector> eig_x() const
170 {
171 std::map<Integer, Vector> x_map;
172 for (Integer i{0}; i < N; ++i) {x_map[i] = this->x.row(i);}
173 return x_map;
174 }
175
181 std::map<std::string, std::vector<Real>> std_x(std::vector<std::string> const & names) const
182 {
183 std::map<std::string, std::vector<Real>> x_map;
184 for (Integer i{0}; i < N; ++i) {x_map[names[i]] = this->std_x(i);}
185 return x_map;
186 }
187
193 std::map<std::string, Vector> eig_x(std::vector<std::string> const & names) const
194 {
195 std::map<std::string, Vector> x_map;
196 for (Integer i{0}; i < N; ++i) {x_map[names[i]] = this->x.row(i);}
197 return x_map;
198 }
199
205 std::vector<Real> std_h(Integer const i) const
206 {
207 Vector tmp(this->h.row(i));
208 return std::vector<Real>(tmp.data(), tmp.data() + tmp.size());
209 }
210
215 std::map<Integer, std::vector<Real>> std_h() const
216 {
217 std::map<Integer, std::vector<Real>> h_map;
218 for (Integer i{0}; i < M; ++i) {h_map[i] = this->std_h(i);}
219 return h_map;
220 }
221
226 std::map<Integer, Vector> eig_h() const
227 {
228 std::map<Integer, Vector> h_map;
229 for (Integer i{0}; i < M; ++i) {h_map[i] = this->h.row(i);}
230 return h_map;
231 }
232
238 std::map<std::string, std::vector<Real>> std_h(std::vector<std::string> const & names) const
239 {
240 std::map<std::string, std::vector<Real>> h_map;
241 for (Integer i{0}; i < M; ++i) {h_map[names[i]] = this->std_h(i);}
242 return h_map;
243 }
244
250 std::map<std::string, Vector> eig_h(std::vector<std::string> const & names) const
251 {
252 std::map<std::string, Vector> h_map;
253 for (Integer i{0}; i < M; ++i) {h_map[names[i]] = this->h.row(i);}
254 return h_map;
255 }
256 };
257
258} // namespace Sandals
259
260#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:68
Solution()
Definition Solution.hh:74
Integer size() const
Definition Solution.hh:126
void resize(Integer const size)
Definition Solution.hh:87
bool is_empty() const
Definition Solution.hh:117
std::map< std::string, Vector > eig_x(std::vector< std::string > const &names) const
Definition Solution.hh:193
std::vector< Real > std_t() const
Definition Solution.hh:132
std::map< std::string, std::vector< Real > > std_h(std::vector< std::string > const &names) const
Definition Solution.hh:238
void conservative_resize(Integer const size)
Definition Solution.hh:97
Vector eig_t() const
Definition Solution.hh:141
Eigen::Matrix< Real, N, Eigen::Dynamic, Eigen::RowMajor > MatrixN
Definition Solution.hh:64
std::map< Integer, std::vector< Real > > std_h() const
Definition Solution.hh:215
std::map< Integer, std::vector< Real > > std_x() const
Definition Solution.hh:158
std::map< std::string, std::vector< Real > > std_x(std::vector< std::string > const &names) const
Definition Solution.hh:181
std::map< std::string, Vector > eig_h(std::vector< std::string > const &names) const
Definition Solution.hh:250
Eigen::Matrix< Real, M, Eigen::Dynamic, Eigen::RowMajor > MatrixM
Definition Solution.hh:65
Solution(Integer const size)
Definition Solution.hh:80
std::vector< Real > std_h(Integer const i) const
Definition Solution.hh:205
Vector t
Definition Solution.hh:67
void clear()
Definition Solution.hh:106
std::map< Integer, Vector > eig_x() const
Definition Solution.hh:169
MatrixM h
Definition Solution.hh:69
Eigen::Vector< Real, Eigen::Dynamic > Vector
Definition Solution.hh:63
std::map< Integer, Vector > eig_h() const
Definition Solution.hh:226
std::vector< Real > std_x(Integer i) const
Definition Solution.hh:148