Astro  0.0.0
A C++ library for space dynamics
Loading...
Searching...
No Matches
Body.hxx
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 ASTRO_BODY_HXX
14#define ASTRO_BODY_HXX
15
16namespace Astro
17{
18
19 /*\
20 | ____ _
21 | | __ ) ___ __| |_ _
22 | | _ \ / _ \ / _` | | | |
23 | | |_) | (_) | (_| | |_| |
24 | |____/ \___/ \__,_|\__, |
25 | |___/
26 \*/
27
35 class Body : public Orbit
36 {
37 using MatrixA = Eigen::Matrix<Real, 6, 3>;
38 using VectorB = Eigen::Vector<Real, 6>;
39
41
42 public:
46 Body() {}
47
51 Body(Body const &) = default;
52
56 Body(Body &&) = default;
57
61 Body & operator=(const Body &) = default;
62
66 Body & operator=(Body &&) = default;
67
72 Real mass() const {return this->m_mass;}
73
78 void mass(Real t_mass) {this->m_mass = t_mass;}
79
93 {
94 Real const & p{this->m_equi.p};
95 Real const & f{this->m_equi.f};
96 Real const & g{this->m_equi.g};
97 Real const & h{this->m_equi.h};
98 Real const & k{this->m_equi.k};
99 Real s_L{std::sin(this->m_anom.L)};
100 Real c_L{std::cos(this->m_anom.L)};
101
102 Real w{1.0 + (f*c_L+g*s_L)};
103 Real s2{1.0 + (h*h+k*k)};
104 Real bf{std::sqrt(p/this->m_mu)};
105 Real bf1{bf/w};
106 Real bf2{(h*s_L-k*c_L)*bf1};
107
108 MatrixA A;
109 A <<
110 0.0, bf1*2.0*p, 0.0,
111 bf*s_L, bf1*((w+1.0)*c_L+f), -bf2*g,
112 -bf*c_L, bf1*((w+1.0)*s_L+g), bf2*f,
113 0.0, 0.0, bf1*s2*c_L/2.0,
114 0.0, 0.0, bf1*s2*s_L/2.0,
115 0.0, 0.0, bf2;
116 return A;
117 }
118
126 {
127 Real const & p{this->m_equi.p};
128 Real const & f{this->m_equi.f};
129 Real const & g{this->m_equi.g};
130 Real w{1.0 + (f*std::cos(this->m_anom.L) + g*std::sin(this->m_anom.L))};
131 return VectorB(0.0, 0.0, 0.0, 0.0, 0.0, std::sqrt(p*this->m_mu)*power2(w/p));
132 }
133
140 Vector6 cartesian_eom(Vector3 const & thrust_rtn) const
141 {
142 // Compute the cartesian perturbation
143 Vector3 thrust_xyz(this->cartesian_rtn_to_xyz(thrust_rtn));
144 thrust_xyz /= this->m_mass;
145
146 // Compute the equations of motion
147 Real r_norm{this->m_cart.r.norm()};
148 Vector3 r_mur3(this->m_mu/power3(r_norm) * this->m_cart.r);
149 return Vector6(
150 this->m_cart.v.x(),
151 this->m_cart.v.y(),
152 this->m_cart.v.z(),
153 thrust_xyz.x() - r_mur3.x(),
154 thrust_xyz.y() - r_mur3.y(),
155 thrust_xyz.z() - r_mur3.z()
156 );
157 }
158
167 Vector6 cartesian_eom(Real thrust_rad, Real thrust_tan, Real thrust_nor) const
168 {
169 return this->cartesian_eom(Vector3(thrust_rad, thrust_tan, thrust_nor));
170 }
171
178 Vector6 equinoctial_eom(Vector3 const & thrust) const
179 {
180 Real const & p{this->m_equi.p};
181 Real const & f{this->m_equi.f};
182 Real const & g{this->m_equi.g};
183 Real const & h{this->m_equi.h};
184 Real const & k{this->m_equi.k};
185 Real const & L{this->m_anom.L};
186
187 Real s_L{std::sin(L)};
188 Real c_L{std::cos(L)};
189
190 Real w{1.0 + (f*c_L+g*s_L)};
191 Real s2{1.0 + (h*h+k*k)};
192 Real bf{std::sqrt(p/this->m_mu)};
193
194 Real C_rad{thrust(0)*bf/this->m_mass};
195 Real C_tan{thrust(1)*bf/this->m_mass/w};
196 Real C_nor{thrust(2)*bf/this->m_mass/w};
197
198 Vector6 res;
199 res.setZero();
200
201 res(1) += C_rad*s_L;
202 res(2) -= C_rad*c_L;
203
204 res(0) += C_tan*2.0*p;
205 res(1) += C_tan*((w+1)*c_L+f);
206 res(2) += C_tan*((w+1)*s_L+g);
207
208 res(1) -= C_nor*(h*s_L-k*c_L)*g;
209 res(2) += C_nor*(h*s_L-k*c_L)*f;
210 res(3) += C_nor*s2*c_L/2.0;
211 res(4) += C_nor*s2*s_L/2.0;
212 res(5) += C_nor*(h*s_L-k*c_L);
213
214 res(5) += std::sqrt(p*this->m_mu)*power2(w/p);
215
216 return res;
217 }
218
227 Vector6 equinoctial_eom(Real thrust_rad, Real thrust_tan, Real thrust_nor) const
228 {
229 return this->equinoctial_eom(Vector3(thrust_rad, thrust_tan, thrust_nor));
230 }
231
232 }; // class Orbit
233
234} // namespace Astro
235
236#endif // ASTRO_ORBIT_HXX
Real m_mass
Definition Body.hxx:40
Vector6 equinoctial_eom(Vector3 const &thrust) const
Definition Body.hxx:178
Body & operator=(Body &&)=default
Body()
Definition Body.hxx:46
Real mass() const
Definition Body.hxx:72
Vector6 cartesian_eom(Real thrust_rad, Real thrust_tan, Real thrust_nor) const
Definition Body.hxx:167
Body(Body const &)=default
Eigen::Vector< Real, 6 > VectorB
Definition Body.hxx:38
Vector6 equinoctial_eom(Real thrust_rad, Real thrust_tan, Real thrust_nor) const
Definition Body.hxx:227
Eigen::Matrix< Real, 6, 3 > MatrixA
Definition Body.hxx:37
Body(Body &&)=default
MatrixA equinoctial_eom_A() const
Definition Body.hxx:92
VectorB equinoctial_eom_b() const
Definition Body.hxx:125
void mass(Real t_mass)
Definition Body.hxx:78
Vector6 cartesian_eom(Vector3 const &thrust_rtn) const
Definition Body.hxx:140
Body & operator=(const Body &)=default
Real m_mu
Definition Orbit.hxx:52
Vector3 cartesian_rtn_to_xyz(Vector3 const &vec) const
Definition Orbit.hxx:461
Anomaly m_anom
Definition Orbit.hxx:49
Equinoctial m_equi
Definition Orbit.hxx:47
Orbit()
Definition Orbit.hxx:58
Cartesian m_cart
Definition Orbit.hxx:45
The namespace for the Astro library.
Definition Astro.hh:72
static Real const QUIET_NAN
Definition Astro.hh:133
Eigen::Vector< Real, 6 > Vector6
Definition Astro.hh:98
double Real
Definition Astro.hh:83
Real power2(Real x)
Definition Utilities.hxx:32
Eigen::Vector< Real, 3 > Vector3
Definition Astro.hh:92
Real power3(Real x)
Definition Utilities.hxx:39