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 "5"
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 }
95 catch (const BadInput& e)
96 {
97 std::cerr << e.what() << '\n';
98 }
99 this->m_asteroid_type = this->ini_file_data.getStringParameters("asteroid_type");
100 this->m_volume_filling_factor =
101 this->ini_file_data.getDoubleParameters("volume_filling_factor");
102}
103
104template <typename T>
106 std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
107{
108 std::vector<std::string> implemented_asteroid_types{"S", "Q", "M", "C"};
109 if (std::find(implemented_asteroid_types.begin(), implemented_asteroid_types.end(),
110 this->m_asteroid_type)
111 == implemented_asteroid_types.end())
112 {
113 throw std::runtime_error(
114 static_cast<std::string>("Requested asteroid type not implemented."));
115 }
116
117 return true;
118}
119
120template <typename T>
122{
123 const std::valarray<T>& temperature{this->sim->getField("Temperature")};
124 if ((this->m_asteroid_type) == "S" || (this->m_asteroid_type) == "Q")
125 {
126 (*this->module_field) = this->m_volume_filling_factor * 3700;
127 }
128 else if ((this->m_asteroid_type) == "C")
129 {
130 (*this->module_field) = this->m_volume_filling_factor * 3110;
131 }
132 else if ((this->m_asteroid_type) == "M")
133 {
134 (*this->module_field) = this->m_volume_filling_factor * 7800;
135 }
136 else
137 {
138 std::cerr << "ERROR in DensityConstantGundlach2013RegolithSolidAsteroidType";
139 throw std::runtime_error(
140 static_cast<std::string>("Requested asteroid type not implemented."));
141 }
142}
143
144template <typename T>
146{
147 if (param == "InitChain")
148 {
149 return init();
150 }
151 if (param == "PreTimeStepChain")
152 {
153 return preTimeStep();
154 }
155 if (param == "PostTimeStepChain")
156 {
157 return postTimeStep();
158 }
159 if (param == "OutputChain")
160 {
161 return output();
162 }
163 return false;
164}
165
166template <typename T>
168{
169 calculateDensity();
170 return true;
171}
172
173template <typename T>
175{
176 calculateDensity();
177 return true;
178}
179
180template <typename T>
182 ModuleFactory<T>::registerModule(getName(), createMethode);
183
184#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:145
void calculateDensity()
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:121
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:174
bool setup(std::vector< std::shared_ptr< GenericSubmodule< T > > > all_submodules) override
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:105
bool init() override
Definition DensityConstantGundlach2013RegolithSolidAsteroidType.h:167
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:477
std::vector< std::string > getStringVectorParameters(const std::string &key) const
Definition InputManager.cpp:503
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:42
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:493
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