MoCSI API Reference
Loading...
Searching...
No Matches
SolarVectorVariableSpice.h
Go to the documentation of this file.
1#ifndef SOLAR_VECTOR_VARIABLE_SPICE_H
2#define SOLAR_VECTOR_VARIABLE_SPICE_H
3
4#define SOLAR_VECTOR_VARIABLE_SPICE_VERSION "6"
5
6#ifdef SPICE_PRESENT
7
8extern "C"
9{
10#include "SpiceUsr.h"
11}
12
13#include <iostream>
14#include <memory>
15#include <string>
16#include <valarray>
17
18#include "../../src/GenericSubmodule.h"
19#include "../../src/ModuleFactory.h"
20
40template <typename T>
42{
43 private:
44 static bool m_registered;
45 std::string m_ini_filepath{"solar_vector/SolarVectorVariableSpice.ini"};
46 std::valarray<T> m_solar_vector;
47 std::string m_start_time_utc;
48 std::string m_observer_id;
49 std::string m_reference_frame_id;
50 std::string m_rotating_frame_id;
51 std::string m_abcorr;
52 ConstSpiceChar* m_target = "SUN";
57
58 public:
60 bool setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
61 override; // loads module into necessary module chains (auto load for calculation
62 // chains)
63 bool exec(std::string_view param) override; // main functionality of the module
64
65 bool init() override;
66 bool preTimeStep() override;
67 bool postTimeStep() override { return true; };
68 bool output() override { return true; };
69
70 void calculateSolarVector();
71
72 void setFieldPtr(std::shared_ptr<std::valarray<T>> field_ptr) override
73 {
74 this->module_field = field_ptr;
75 }
76
77 static std::shared_ptr<GenericSubmodule<T>> createMethode(SimulationClassBase<T>* sim)
78 {
79 return std::make_shared<SolarVectorVariableSpice<T>>(sim);
80 }
81 static std::string getName() { return "SolarVectorVariableSpice"; }
82 std::string_view getNameLocal() const override { return "SolarVectorVariableSpice"; };
83 std::vector<std::string> getDependencies() const override
84 {
85 return this->ini_file_data.getStringVectorParameters("dependencies");
86 };
87};
88
89// ================= Implementation =================
90
91template <typename T>
93 : GenericSubmodule<T>(sim)
94{
95 try
96 {
97 std::string ini_folder_path{
98 this->sim->m_simulation_config.getStringParameters("ini_folder_path")};
99 this->ini_file_data.loadUserInput(ini_folder_path + m_ini_filepath);
100 this->m_generic_submodules = this->ini_file_data.getStringVectorParameters("submodules");
101 }
102 catch (const BadInput& e)
103 {
104 std::cerr << e.what() << '\n';
105 }
106}
107
108template <typename T>
110 std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
111{
112 m_solar_vector.resize(3);
113
114 return true;
115}
116
117template <typename T>
118bool SolarVectorVariableSpice<T>::exec(std::string_view param)
119{
120 if (param == "InitChain")
121 {
122 return init();
123 }
124 if (param == "PreTimeStepChain")
125 {
126 return preTimeStep();
127 }
128 if (param == "PostTimeStepChain")
129 {
130 return postTimeStep();
131 }
132 if (param == "OutputChain")
133 {
134 return output();
135 }
136 return false;
137}
138
139template <typename T>
141{
142 // Calculate current ephemerides times from current timestep
143 this->m_et = this->m_start_time_et + this->sim->elapsed_time;
144
145 spkpos_c(this->m_target, this->m_et, this->m_rotating_frame_id.c_str(), this->m_abcorr.c_str(),
146 this->m_observer_id.c_str(), this->m_body_center_to_sun_vector_rotating,
147 &this->m_light_time);
148
149 // Change unit from km to m and save in module field
150 for (int i{0}; i < 3; i++)
151 {
152 (*this->module_field)[i] = this->m_body_center_to_sun_vector_rotating[i] * 1000;
153 }
154}
155
156template <typename T>
158{
159 calculateSolarVector();
160 return true;
161}
162
163template <typename T>
165{
166 // Load metadata kernel (can be done multiple times for different modules)
167 if (this->sim->my_rank == 0)
168 {
169 std::cout << "[SolarVectorVariableSpice] Loading SPICE kernels.\n";
170 }
171 furnsh_c(this->ini_file_data.getStringParameters("spice_metakernel_path").c_str());
172 if (this->sim->my_rank == 0)
173 {
174 std::cout << "[SolarVectorVariableSpice] Done.\n";
175 }
176
177 // Read ini file for correct IDs
178 this->m_start_time_utc = this->ini_file_data.getStringParameters("start_time_utc");
179 str2et_c(this->m_start_time_utc.c_str(), &this->m_start_time_et);
180 this->m_et = this->m_start_time_et;
181 this->m_observer_id = this->ini_file_data.getStringParameters("object_id");
182 this->m_reference_frame_id = this->ini_file_data.getStringParameters("reference_frame_id");
183 this->m_rotating_frame_id = this->ini_file_data.getStringParameters("rotating_frame_id");
184 this->m_abcorr = this->ini_file_data.getStringParameters("abcorr");
185 if (this->sim->my_rank == 0)
186 {
187 std::cout << "[SolarVectorVariableSpice] Loaded parameters.\n";
188 }
189
190 calculateSolarVector();
191
192 return true;
193}
194
195template <typename T>
197 ModuleFactory<T>::registerModule(getName(), createMethode);
198
199#endif // SPICE_PRESENT
200
201#endif // SOLAR_VECTOR_VARIABLE_SPICE_H
This error class inherits from std::exception and marks faulty parameter or CL inputs....
Definition IniParser.h:71
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:35
CsrSparseMatrix()
Constructor for an empty CsrSparseMatrix object. Leaves all storage arrays empty but sets the flag to...
Definition CsrMatrix.h:92
Abstract base class for the submodules. Submodules are below managing modules and will only be run by...
Definition GenericSubmodule.h:25
static constexpr bool registerModule(std::string name, creation_method module) noexcept
Function that adds a module to the module registry map.
Definition ModuleFactory.h:75