Sandals  v0.0.0
A C++ library for ODEs/DAEs integration
Loading...
Searching...
No Matches
Sandals.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 INCLUDE_SANDALS_HH
14#define INCLUDE_SANDALS_HH
15
16// C++ standard libraries
17#include <iostream>
18#include <string>
19#include <cmath>
20#include <vector>
21#include <map>
22#include <memory>
23#include <chrono>
24
25// Eigen library
26#include <Eigen/Dense>
27
28// Optimist library
29#include <Optimist.hh>
30
31// Print Sandals errors
32#ifndef SANDALS_ERROR
33#define SANDALS_ERROR(MSG) \
34 { \
35 std::ostringstream os; \
36 os << MSG; \
37 throw std::runtime_error(os.str()); \
38 }
39#endif
40
41// Assert for Sandals
42#ifndef SANDALS_ASSERT
43#define SANDALS_ASSERT(COND, MSG) \
44 if (!(COND)) \
45 { \
46 SANDALS_ERROR(MSG); \
47 }
48#endif
49
50// Warning for Sandals
51#ifndef SANDALS_WARNING
52#define SANDALS_WARNING(MSG) \
53 { \
54 std::cout << MSG << std::endl; \
55 }
56#endif
57
58// Warning assert for Sandals
59#ifndef SANDALS_ASSERT_WARNING
60#define SANDALS_ASSERT_WARNING(COND, MSG) \
61 if (!(COND)) \
62 { \
63 SANDALS_WARNING(MSG); \
64 }
65#endif
66
72namespace Sandals
73{
74
75 /*\
76 | _ _ _
77 | / \ | (_) __ _ ___ ___ ___
78 | / _ \ | | |/ _` / __|/ _ \/ __|
79 | / ___ \| | | (_| \__ \ __/\__ \
80 | /_/ \_\_|_|\__,_|___/\___||___/
81 |
82 \*/
83
84 using Real = double;
85 using Integer = int;
86
87 using Vector0 = Eigen::Vector<Real, 0>;
88 using Matrix0 = Eigen::Matrix<Real, 0, 0>;
89 using Vector1 = Eigen::Vector<Real, 1>;
90 using Matrix1 = Eigen::Matrix<Real, 1, 1>;
91 using Vector2 = Eigen::Vector<Real, 2>;
92 using Matrix2 = Eigen::Matrix<Real, 2, 2>;
93 using Vector3 = Eigen::Vector<Real, 3>;
94 using Matrix3 = Eigen::Matrix<Real, 3, 3>;
95 using Vector4 = Eigen::Vector<Real, 4>;
96 using Matrix4 = Eigen::Matrix<Real, 4, 4>;
97 using Vector5 = Eigen::Vector<Real, 5>;
98 using Matrix5 = Eigen::Matrix<Real, 5, 5>;
99 using Vector6 = Eigen::Vector<Real, 6>;
100 using Matrix6 = Eigen::Matrix<Real, 6, 6>;
101 using Vector7 = Eigen::Vector<Real, 7>;
102 using Matrix7 = Eigen::Matrix<Real, 7, 7>;
103 using Vector8 = Eigen::Vector<Real, 8>;
104 using Matrix8 = Eigen::Matrix<Real, 8, 8>;
105 using Vector9 = Eigen::Vector<Real, 9>;
106 using Matrix9 = Eigen::Matrix<Real, 9, 9>;
107
108 using VectorX = Eigen::Vector<Real, Eigen::Dynamic>;
109 using MatrixX = Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic>;
110
111 /*\
112 | ____ _ _
113 | / ___|___ _ __ ___| |_ __ _ _ __ | |_ ___
114 | | | / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
115 | | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
116 | \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
117 |
118 \*/
119
120 static Real const EPSILON = std::numeric_limits<Real>::epsilon();
121 static Real const SQRT_EPSILON = std::sqrt(EPSILON);
122 static Real const CBRT_EPSILON = std::cbrt(EPSILON);
123 static Real const EPSILON_HIGH = Real(1.0e-12);
124 static Real const EPSILON_MEDIUM = Real(1.0e-10);
125 static Real const EPSILON_LOW = Real(1.0e-08);
126 static Real const INFTY = std::numeric_limits<Real>::infinity();
127 static Real const QUIET_NAN = std::numeric_limits<Real>::quiet_NaN();
128 static Real const PI = Real(3.141592653589793238462643383279502884197);
129 static Real const PIMUL2 = Real(6.283185307179586476925286766559005768394);
130 static Real const PIDIV2 = Real(1.570796326794896619231321691639751442098);
131 static Real const DEG2RAD = Real(0.017453292519943295769236907684886127134);
132 static Real const RAD2DEG = Real(57.29577951308232087679815481410517033240);
133
134 static Vector1 const NAN_VEC1 = Vector1::Constant(QUIET_NAN);
135 static Matrix1 const NAN_MAT1 = Matrix1::Constant(QUIET_NAN);
136 static Vector1 const ZEROS_VEC1 = Vector1::Zero();
137 static Matrix1 const ZEROS_MAT1 = Matrix1::Zero();
138 static Vector1 const ONES_VEC1 = Vector1::Ones();
139 static Matrix1 const ONES_MAT1 = Matrix1::Ones();
140 static Matrix1 const IDENTITY_MAT1 = Matrix1::Identity();
141
142 static Vector2 const NAN_VEC2 = Vector2::Constant(QUIET_NAN);
143 static Matrix2 const NAN_MAT2 = Matrix2::Constant(QUIET_NAN);
144 static Vector2 const ZEROS_VEC2 = Vector2::Zero();
145 static Matrix2 const ZEROS_MAT2 = Matrix2::Zero();
146 static Vector2 const ONES_VEC2 = Vector2::Ones();
147 static Matrix2 const ONES_MAT2 = Matrix2::Ones();
148 static Matrix2 const IDENTITY_MAT2 = Matrix2::Identity();
149
150 static Vector3 const NAN_VEC3 = Vector3::Constant(QUIET_NAN);
151 static Matrix3 const NAN_MAT3 = Matrix3::Constant(QUIET_NAN);
152 static Vector3 const ZEROS_VEC3 = Vector3::Zero();
153 static Matrix3 const ZEROS_MAT3 = Matrix3::Zero();
154 static Vector3 const ONES_VEC3 = Vector3::Ones();
155 static Matrix3 const ONES_MAT3 = Matrix3::Ones();
156 static Matrix3 const IDENTITY_MAT3 = Matrix3::Identity();
157
158 static Vector4 const NAN_VEC4 = Vector4::Constant(QUIET_NAN);
159 static Matrix4 const NAN_MAT4 = Matrix4::Constant(QUIET_NAN);
160 static Vector4 const ZEROS_VEC4 = Vector4::Zero();
161 static Matrix4 const ZEROS_MAT4 = Matrix4::Zero();
162 static Vector4 const ONES_VEC4 = Vector4::Ones();
163 static Matrix4 const ONES_MAT4 = Matrix4::Ones();
164 static Matrix4 const IDENTITY_MAT4 = Matrix4::Identity();
165
166 static Vector5 const NAN_VEC5 = Vector5::Constant(QUIET_NAN);
167 static Matrix5 const NAN_MAT5 = Matrix5::Constant(QUIET_NAN);
168 static Vector5 const ZEROS_VEC5 = Vector5::Zero();
169 static Matrix5 const ZEROS_MAT5 = Matrix5::Zero();
170 static Vector5 const ONES_VEC5 = Vector5::Ones();
171 static Matrix5 const ONES_MAT5 = Matrix5::Ones();
172 static Matrix5 const IDENTITY_MAT5 = Matrix5::Identity();
173
174 static Vector6 const NAN_VEC6 = Vector6::Constant(QUIET_NAN);
175 static Matrix6 const NAN_MAT6 = Matrix6::Constant(QUIET_NAN);
176 static Vector6 const ZEROS_VEC6 = Vector6::Zero();
177 static Matrix6 const ZEROS_MAT6 = Matrix6::Zero();
178 static Vector6 const ONES_VEC6 = Vector6::Ones();
179 static Matrix6 const ONES_MAT6 = Matrix6::Ones();
180 static Matrix6 const IDENTITY_MAT6 = Matrix6::Identity();
181
182 static Vector7 const NAN_VEC7 = Vector7::Constant(QUIET_NAN);
183 static Matrix7 const NAN_MAT7 = Matrix7::Constant(QUIET_NAN);
184 static Vector7 const ZEROS_VEC7 = Vector7::Zero();
185 static Matrix7 const ZEROS_MAT7 = Matrix7::Zero();
186 static Vector7 const ONES_VEC7 = Vector7::Ones();
187 static Matrix7 const ONES_MAT7 = Matrix7::Ones();
188 static Matrix7 const IDENTITY_MAT7 = Matrix7::Identity();
189
190 static Vector8 const NAN_VEC8 = Vector8::Constant(QUIET_NAN);
191 static Matrix8 const NAN_MAT8 = Matrix8::Constant(QUIET_NAN);
192 static Vector8 const ZEROS_VEC8 = Vector8::Zero();
193 static Matrix8 const ZEROS_MAT8 = Matrix8::Zero();
194 static Vector8 const ONES_VEC8 = Vector8::Ones();
195 static Matrix8 const ONES_MAT8 = Matrix8::Ones();
196 static Matrix8 const IDENTITY_MAT8 = Matrix8::Identity();
197
198 static Vector9 const NAN_VEC9 = Vector9::Constant(QUIET_NAN);
199 static Matrix9 const NAN_MAT9 = Matrix9::Constant(QUIET_NAN);
200 static Vector9 const ZEROS_VEC9 = Vector9::Zero();
201 static Matrix9 const ZEROS_MAT9 = Matrix9::Zero();
202 static Vector9 const ONES_VEC9 = Vector9::Ones();
203 static Matrix9 const ONES_MAT9 = Matrix9::Ones();
204 static Matrix9 const IDENTITY_MAT9 = Matrix9::Identity();
205
210 std::string Info() {
211 std::ostringstream os;
212 os
213 << "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" << std::endl
214 << "* Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *" << std::endl
215 << "* *" << std::endl
216 << "* The Sandals project is distributed under the BSD 2-Clause License. *" << std::endl
217 << "* *" << std::endl
218 << "* Davide Stocco Enrico Bertolazzi *" << std::endl
219 << "* University of Trento University of Trento *" << std::endl
220 << "* e-mail: davide.stocco@unitn.it e-mail: enrico.bertolazzi@unitn.it *" << std::endl
221 << "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" << std::endl;
222 return os.str();
223 }
224
229 void Info(std::ostream &os) {os << Info();}
230
231} // namespace Sandals
232
233// Time measurement
234#include "Sandals/TicToc.hxx"
235
236// ODEs/DAEs system
241
242// Runge-Kutta integrator
243#include "Sandals/Tableau.hxx"
244#include "Sandals/Solution.hxx"
245#include "Sandals/RungeKutta.hxx"
246
247// Butcher tableau for Runge-Kutta methods
273
274#endif // INCLUDE_SANDALS_HH
The namespace for the Sandals library.
Definition Sandals.hh:73
Eigen::Vector< Real, 6 > Vector6
Definition Sandals.hh:99
static Matrix8 const IDENTITY_MAT8
Definition Sandals.hh:196
Eigen::Vector< Real, Eigen::Dynamic > VectorX
Definition Sandals.hh:108
static Matrix2 const IDENTITY_MAT2
Definition Sandals.hh:148
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Definition Sandals.hh:109
double Real
Definition Sandals.hh:84
static Matrix8 const ZEROS_MAT8
Definition Sandals.hh:193
Eigen::Matrix< Real, 8, 8 > Matrix8
Definition Sandals.hh:104
static Matrix6 const ZEROS_MAT6
Definition Sandals.hh:177
static Matrix9 const ZEROS_MAT9
Definition Sandals.hh:201
static Vector9 const ONES_VEC9
Definition Sandals.hh:202
static Matrix4 const ZEROS_MAT4
Definition Sandals.hh:161
static Matrix5 const ONES_MAT5
Definition Sandals.hh:171
static Matrix1 const ZEROS_MAT1
Definition Sandals.hh:137
static Matrix8 const ONES_MAT8
Definition Sandals.hh:195
static Matrix6 const IDENTITY_MAT6
Definition Sandals.hh:180
static Vector1 const ZEROS_VEC1
Definition Sandals.hh:136
static Vector6 const ZEROS_VEC6
Definition Sandals.hh:176
static Real const EPSILON_HIGH
Definition Sandals.hh:123
static Vector7 const ZEROS_VEC7
Definition Sandals.hh:184
Eigen::Vector< Real, 8 > Vector8
Definition Sandals.hh:103
static Matrix3 const IDENTITY_MAT3
Definition Sandals.hh:156
Eigen::Vector< Real, 4 > Vector4
Definition Sandals.hh:95
static Matrix2 const NAN_MAT2
Definition Sandals.hh:143
static Matrix3 const NAN_MAT3
Definition Sandals.hh:151
static Matrix8 const NAN_MAT8
Definition Sandals.hh:191
static Matrix6 const NAN_MAT6
Definition Sandals.hh:175
static Vector3 const NAN_VEC3
Definition Sandals.hh:150
static Vector7 const ONES_VEC7
Definition Sandals.hh:186
static Real const EPSILON_LOW
Definition Sandals.hh:125
static Matrix4 const IDENTITY_MAT4
Definition Sandals.hh:164
static Vector4 const ONES_VEC4
Definition Sandals.hh:162
static Matrix7 const IDENTITY_MAT7
Definition Sandals.hh:188
Eigen::Matrix< Real, 5, 5 > Matrix5
Definition Sandals.hh:98
Eigen::Matrix< Real, 4, 4 > Matrix4
Definition Sandals.hh:96
static Matrix7 const NAN_MAT7
Definition Sandals.hh:183
static Matrix9 const ONES_MAT9
Definition Sandals.hh:203
static Matrix3 const ZEROS_MAT3
Definition Sandals.hh:153
static Vector5 const ZEROS_VEC5
Definition Sandals.hh:168
static Vector9 const ZEROS_VEC9
Definition Sandals.hh:200
static Matrix1 const NAN_MAT1
Definition Sandals.hh:135
static Vector8 const ONES_VEC8
Definition Sandals.hh:194
static Real const PI
Definition Sandals.hh:128
Eigen::Vector< Real, 5 > Vector5
Definition Sandals.hh:97
Eigen::Vector< Real, 3 > Vector3
Definition Sandals.hh:93
static Vector2 const ONES_VEC2
Definition Sandals.hh:146
static Matrix7 const ONES_MAT7
Definition Sandals.hh:187
static Vector7 const NAN_VEC7
Definition Sandals.hh:182
static Real const CBRT_EPSILON
Definition Sandals.hh:122
static Vector8 const NAN_VEC8
Definition Sandals.hh:190
static Matrix7 const ZEROS_MAT7
Definition Sandals.hh:185
static Real const EPSILON_MEDIUM
Definition Sandals.hh:124
static Matrix5 const IDENTITY_MAT5
Definition Sandals.hh:172
Eigen::Matrix< Real, 6, 6 > Matrix6
Definition Sandals.hh:100
static Real const INFTY
Definition Sandals.hh:126
static Real const RAD2DEG
Definition Sandals.hh:132
Eigen::Matrix< Real, 9, 9 > Matrix9
Definition Sandals.hh:106
static Matrix2 const ZEROS_MAT2
Definition Sandals.hh:145
static Matrix1 const IDENTITY_MAT1
Definition Sandals.hh:140
static Vector6 const NAN_VEC6
Definition Sandals.hh:174
static Vector1 const ONES_VEC1
Definition Sandals.hh:138
std::string Info()
Definition Sandals.hh:210
static Real const EPSILON
Definition Sandals.hh:120
Eigen::Matrix< Real, 2, 2 > Matrix2
Definition Sandals.hh:92
Eigen::Vector< Real, 9 > Vector9
Definition Sandals.hh:105
static Real const QUIET_NAN
Definition Sandals.hh:127
static Matrix1 const ONES_MAT1
Definition Sandals.hh:139
static Matrix4 const NAN_MAT4
Definition Sandals.hh:159
static Matrix9 const NAN_MAT9
Definition Sandals.hh:199
static Vector6 const ONES_VEC6
Definition Sandals.hh:178
static Vector2 const ZEROS_VEC2
Definition Sandals.hh:144
static Vector4 const ZEROS_VEC4
Definition Sandals.hh:160
Eigen::Vector< Real, 0 > Vector0
Definition Sandals.hh:87
Eigen::Matrix< Real, 0, 0 > Matrix0
Definition Sandals.hh:88
static Vector3 const ZEROS_VEC3
Definition Sandals.hh:152
static Vector2 const NAN_VEC2
Definition Sandals.hh:142
static Matrix4 const ONES_MAT4
Definition Sandals.hh:163
Eigen::Vector< Real, 2 > Vector2
Definition Sandals.hh:91
static Matrix3 const ONES_MAT3
Definition Sandals.hh:155
Eigen::Matrix< Real, 1, 1 > Matrix1
Definition Sandals.hh:90
Eigen::Matrix< Real, 3, 3 > Matrix3
Definition Sandals.hh:94
static Matrix6 const ONES_MAT6
Definition Sandals.hh:179
static Vector5 const ONES_VEC5
Definition Sandals.hh:170
static Matrix2 const ONES_MAT2
Definition Sandals.hh:147
static Vector8 const ZEROS_VEC8
Definition Sandals.hh:192
Eigen::Vector< Real, 1 > Vector1
Definition Sandals.hh:89
static Real const PIDIV2
Definition Sandals.hh:130
static Real const DEG2RAD
Definition Sandals.hh:131
static Vector5 const NAN_VEC5
Definition Sandals.hh:166
static Real const SQRT_EPSILON
Definition Sandals.hh:121
Eigen::Vector< Real, 7 > Vector7
Definition Sandals.hh:101
Eigen::Matrix< Real, 7, 7 > Matrix7
Definition Sandals.hh:102
static Vector9 const NAN_VEC9
Definition Sandals.hh:198
static Matrix5 const ZEROS_MAT5
Definition Sandals.hh:169
static Vector4 const NAN_VEC4
Definition Sandals.hh:158
static Vector1 const NAN_VEC1
Definition Sandals.hh:134
static Vector3 const ONES_VEC3
Definition Sandals.hh:154
static Real const PIMUL2
Definition Sandals.hh:129
static Matrix5 const NAN_MAT5
Definition Sandals.hh:167
int Integer
Definition Sandals.hh:85
static Matrix9 const IDENTITY_MAT9
Definition Sandals.hh:204