ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
spiceutils.h
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16#ifndef UTILS_SPICE_H
17#define UTILS_SPICE_H
18
19#include <vector>
20#include <string>
21
22#include "core/macros.h"
23#include "core/CartesianVector.hpp"
24#include "six_dof_dynamics/DCM.hpp"
25#include "six_dof_dynamics/Frame.hpp"
26
27namespace modelspace {
28 /// @brief A function to load in a sinle spice kernel
29 /// @param A single spice kernel to load
30 void loadKernel(std::string kernel);
31
32 /**
33 * @brief The Spice Manager is a single class instance to manage spice frames and return SPICE states
34 *
35 * The Spice Manager is a wrapper around SPICE utilities to simplify the process
36 * of getting SPICE states. It needs to exist for the following reasons:
37 * - Python/SWIG has some weirdness that couples with spice on kernel loading. Loading kernels
38 * here prevents having to load kernels multiple times
39 * - Having a single class for all spice bodies ensures they're all using the same reference
40 * point (we woldn't want to reference relative to earth sometimes and the sun others)
41 *
42 * By default, the Spice Manager will select the central body to be Earth, if the Earth is
43 * present in the simulation. If Earth is not present, the Spice Manager will select its
44 * central body as the largest body present in the simulation by mass. (i.e. Sun > Venus)
45 *
46 * If the user desires a different central body than the one chosen by the SPICE manager,
47 * the central body may be set via setCentralBody. This will override the default behavior.
48 */
49 class SpiceManager {
50 public:
51 SpiceManager() {}
52 ~SpiceManager() {}
53
54 /// @brief A function to load in a list of SPICE kernels
55 /// @param kernel_list A vector list of kernel files to load
56 void loadKernels(std::vector<std::string> kernel_list);
57
58 /// @brief Function to register a spice body with the spice manager
59 /// @param body_name The SPICE body name to register
60 void registerSpiceBody(const std::string &body_name);
61
62 /// @brief Get the frame name associated with a body
63 /// @param body_name The body name to query
64 /// @return The string name associated with the body -- empty string if body is not found
65 std::string getBodyFrameName(const std::string &body_name);
66
67 /// @brief Function to set the central body in the SPICE manager
68 /// @param central_body The central body to set
69 void setCentralBody(const std::string &central_body);
70
71 /// @brief Function to output the current central body
72 /// @return The current central body
73 std::string centralBody() {return _central_body;}
74
75 /// @brief Function to return the gravitational parameter for a SPICE body
76 /// @param body_name The body name to return gravitational parameter for
77 /// @return The gravitational parameter in km^3/s^2
78 double getGravitationalParameter(const std::string &body_name);
79
80 /// @brief Function to return the position of a SPICE body relative to central body
81 /// @param body_name The body name to query
82 /// @param tdb_time The ephemeris time to query state position
83 /// @return The J2000 position of the SPICE body relative to central body in km
84 CartesianVector3D getSpicePosition(const std::string &body_name, double tdb_time);
85
86 /// @brief Function to return the velocity of a SPICE body relative to central body
87 /// @param body_name The body name to query
88 /// @param tdb_time The ephemeris time to query state position
89 /// @return The J2000 velocity of the SPICE body relative to central body in km/s
90 CartesianVector3D getSpiceVelocity(const std::string &body_name, double tdb_time);
91
92 /// @brief Function to return the attitude of a SPICE body relative to central body
93 /// @param body_name The body name to query
94 /// @param tdb_time The ephemeris time to query state position
95 /// @return The J2000 attitude of the SPICE body relative to central body as a DCM
96 DCMD getSpiceAttitude(const std::string &body_name, double tdb_time);
97
98 /// @brief Function to return the angular velocity of a SPICE body relative to central body
99 /// @param body_name The body name to query
100 /// @param tdb_time The ephemeris time to query state position
101 /// @return The J2000 angular velocity of the SPICE body relative to central body in rad/s
102 CartesianVector3D getSpiceAngularVelocity(const std::string &body_name, double tdb_time);
103 protected:
104 // Record of all SPICE bodies tracked by the SPICE manager
105 std::vector<std::string> _spice_bodies;
106
107 // String indicating the central body for the SPICE manager
108 std::string _central_body;
109
110 // Boolean tracking whether central body was already set manually
111 bool _manual_set = false;
112
113 // Boolean to protect from duplicate spice kernel loading
114 bool _kernels_loaded = false;
115
116 // Temporary variables for calculation
117 double _tmp_state[6];
118 double _lt = 0.0;
119 double _tmp_dbl[3][3];
120 DCMD _tmp_dcm_p_pci;
121 double _tmp_vec[3];
122 CartesianVector3D _tmp_omega_p_pci__pci;
123 double _ftmtrx[6][6];
124 };
125}
126
127#endif
The Spice Manager is a single class instance to manage spice frames and return SPICE states.
Definition spiceutils.h:49
void setCentralBody(const std::string &central_body)
Function to set the central body in the SPICE manager.
Definition spiceutils.cpp:87
clockwerk::DCM< double > getSpiceAttitude(const std::string &body_name, double tdb_time)
Function to return the attitude of a SPICE body relative to central body.
Definition spiceutils.cpp:111
void loadKernels(std::vector< std::string > kernel_list)
A function to load in a list of SPICE kernels.
Definition spiceutils.cpp:29
double getGravitationalParameter(const std::string &body_name)
Function to return the gravitational parameter for a SPICE body.
Definition spiceutils.cpp:92
std::string centralBody()
Function to output the current central body.
Definition spiceutils.h:73
clockwerk::CartesianVector< double, 3 > getSpicePosition(const std::string &body_name, double tdb_time)
Function to return the position of a SPICE body relative to central body.
Definition spiceutils.cpp:99
clockwerk::CartesianVector< double, 3 > getSpiceAngularVelocity(const std::string &body_name, double tdb_time)
Function to return the angular velocity of a SPICE body relative to central body.
Definition spiceutils.cpp:126
void registerSpiceBody(const std::string &body_name)
Function to register a spice body with the spice manager.
Definition spiceutils.cpp:43
std::string getBodyFrameName(const std::string &body_name)
Get the frame name associated with a body.
Definition spiceutils.cpp:70
clockwerk::CartesianVector< double, 3 > getSpiceVelocity(const std::string &body_name, double tdb_time)
Function to return the velocity of a SPICE body relative to central body.
Definition spiceutils.cpp:105
#define CartesianVector3D
Definition macros.h:54
#define DCMD
Definition macros.h:70
Class to propagate CR3BP dynamics in characteristic units.
Definition ConfigurationWriter.cpp:18
void loadKernel(std::string kernel)
A function to load in a sinle spice kernel.
Definition spiceutils.cpp:25