MoCSI API Reference
Loading...
Searching...
No Matches
DensityConstantGundlach2013RegolithSolidAsteroidType.h
Go to the documentation of this file.
1#ifndef DENSITY_CONSTANT_GUNDLACH_2013_REGOLITH_SOLID_ASTEROID_TYPE_H
2#define DENSITY_CONSTANT_GUNDLACH_2013_REGOLITH_SOLID_ASTEROID_TYPE_H
3
4#define DENSITY_CONSTANT_GUNDLACH_2013_REGOLITH_SOLID_ASTEROID_TYPE_VERSION "6"
5
6#include <iostream>
7#include <memory>
8#include <string>
9#include <valarray>
10
11#include "../../src/GenericSubmodule.h"
12#include "../../src/ModuleFactory.h"
13
34template <typename T>
36{
37 private:
38 static bool m_registered;
39 std::string m_ini_filepath{
40 "density/DensityConstantGundlach2013RegolithSolidAsteroidType.ini"};
41 std::string m_asteroid_type{};
42 T m_volume_filling_factor{};
43
44 public:
46 bool setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
47 override; // loads module into necessary module chains (auto load for calculation
48 // chains)
49 bool exec(std::string_view param) override; // main functionality of the module
50
51 bool init() override;
52 bool preTimeStep() override;
53 bool postTimeStep() override { return true; };
54 bool output() override { return true; };
55
56 void calculateDensity();
57
58 void setFieldPtr(std::shared_ptr<std::valarray<T>> field_ptr) override
59 {
60 this->module_field = field_ptr;
61 }
62
63 static std::shared_ptr<GenericSubmodule<T>> createMethode(SimulationClassBase<T>* sim)
64 {
65 return std::make_shared<DensityConstantGundlach2013RegolithSolidAsteroidType<T>>(sim);
66 }
67 static std::string getName()
68 {
69 return "DensityConstantGundlach2013RegolithSolidAsteroidType";
70 }
71 std::string_view getNameLocal() const override
72 {
73 return "DensityConstantGundlach2013RegolithSolidAsteroidType";
74 };
75 std::vector<std::string> getDependencies() const override
76 {
77 return this->ini_file_data.getStringVectorParameters("dependencies");
78 };
79};
80
81// ================= Implementation =================
82
83template <typename T>
86 : GenericSubmodule<T>(sim)
87{
88 try
89 {
90 std::string ini_folder_path{
91 this->sim->m_simulation_config.getStringParameters("ini_folder_path")};
92 this->ini_file_data.loadUserInput(ini_folder_path + m_ini_filepath);
94 this->m_asteroid_type = this->ini_file_data.getStringParameters("asteroid_type");
95 this->m_volume_filling_factor =
96 this->ini_file_data.getDoubleParameters("volume_filling_factor");
97 }
98 catch (const BadInput& e)
99 {
100 std::cerr << "[DensityConstantGundlach2013RegolithSolidAsteroidType]: " << e.what() << '\n';
101 throw BadInput(
102 static_cast<std::string>("[DensityConstantGundlach2013RegolithSolidAsteroidType]: ")
103 + static_cast<std::string>(e.what()));
104 }
105}
106
107template <typename T>
109 std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
110{
111 std::vector<std::string> implemented_asteroid_types{"S", "Q", "M", "C"};
112 if (std::find(implemented_asteroid_types.begin(), implemented_asteroid_types.end(),
113 this->m_asteroid_type)
114 == implemented_asteroid_types.end())
115 {
116 std::cerr << "[DensityConstantGundlach2013RegolithSolidAsteroidType]: Requested asteroid "
117 "type not implemented.\n";
118 throw std::runtime_error(static_cast<std::string>(
119 "[DensityConstantGundlach2013RegolithSolidAsteroidType]: Requested "
120 "asteroid type not implemented."));
121 }
122
123 return true;
124}
125
126template <typename T>
128{
129 const std::valarray<T>& temperature{this->sim->getField("Temperature")};
130 if ((this->m_asteroid_type) == "S" || (this->m_asteroid_type) == "Q")
131 {
132 (*this->module_field) = this->m_volume_filling_factor * 3700;
133 }
134 else if ((this->m_asteroid_type) == "C")
135 {
136 (*this->module_field) = this->m_volume_filling_factor * 3110;
137 }
138 else if ((this->m_asteroid_type) == "M")
139 {
140 (*this->module_field) = this->m_volume_filling_factor * 7800;
141 }
142 else
143 {
144 std::cerr << "[DensityConstantGundlach2013RegolithSolidAsteroidType]: Requested asteroid "
145 "type not implemented.\n";
146 throw std::runtime_error(
147 static_cast<std::string>("[DensityConstantGundlach2013RegolithSolidAsteroidType]: "
148 "Requested asteroid type not implemented."));
149 }
150}
151
152template <typename T>
154{
155 if (param == "InitChain")
156 {
157 return init();
158 }
159 if (param == "PreTimeStepChain")
160 {
161 return preTimeStep();
162 }
163 if (param == "PostTimeStepChain")
164 {
165 return postTimeStep();
166 }
167 if (param == "OutputChain")
168 {
169 return output();
170 }
171 return false;
172}
173
174template <typename T>
176{
177 calculateDensity();
178 return true;
179}
180
181template <typename T>
183{
184 calculateDensity();
185 return true;
186}
187
188template <typename T>
190 ModuleFactory<T>::registerModule(getName(), createMethode);
191
192#endif // DENSITY_CONSTANT_GUNDLACH_2013_REGOLITH_SOLID_ASTEROID_TYPE_H
This error class inherits from std::exception and marks faulty parameter or CL inputs....
Definition IniParser.h:71
const char * what() const noexcept override
Definition IniParser.h:78
Submodule calculating asteroid bulk density using type-specific constants.
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:36
bool output() override
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:54
std::vector< std::string > getDependencies() const override
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:75
bool exec(std::string_view param) override
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:153
void calculateDensity()
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:127
bool postTimeStep() override
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:53
static std::shared_ptr< GenericSubmodule< T > > createMethode(SimulationClassBase< T > *sim)
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:63
void setFieldPtr(std::shared_ptr< std::valarray< T > > field_ptr) override
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:58
bool preTimeStep() override
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:182
bool setup(std::vector< std::shared_ptr< GenericSubmodule< T > > > all_submodules) override
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:108
bool init() override
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:175
static std::string getName()
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:67
std::string_view getNameLocal() const override
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:71
Abstract base class for the submodules. Submodules are below managing modules and will only be run by...
Definition GenericSubmodule.h:25
InputManager ini_file_data
Definition GenericSubmodule.h:36
std::vector< std::string > m_generic_submodules
Definition GenericSubmodule.h:34
const SimulationClassBase< T > * sim
Definition GenericSubmodule.h:32
std::shared_ptr< std::valarray< T > > module_field
Definition GenericSubmodule.h:29
double getDoubleParameters(const std::string &key) const
Getter function to access the m_DoubleParameters map and returns a double.
Definition InputManager.cpp:482
std::vector< std::string > getStringVectorParameters(const std::string &key) const
Definition InputManager.cpp:508
void loadUserInput(const std::string &user_ini_file_path)
Public function to load and merge user supplied ini files with the already stored data.
Definition InputManager.cpp:45
std::string getStringParameters(const std::string &key) const
Getter function to access the m_parameters map and returns a string. Throws a BadInput error,...
Definition InputManager.cpp:498
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
Definition SimulationClassBase.h:19
InputManager m_simulation_config
Definition SimulationClassBase.h:29