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