MoCSI API Reference
Loading...
Searching...
No Matches
HeliocentricDistance.h
Go to the documentation of this file.
1#ifndef HELIOCENTRIC_DISTANCE_H
2#define HELIOCENTRIC_DISTANCE_H
3
4#define VERSION "4"
5
6#include <iostream>
7#include <memory>
8#include <string>
9#include <valarray>
10
11#include "../../src/GenericManagingModule.h"
12#include "../../src/ModuleFactory.h"
13
31template <typename T>
33{
34 private:
35 static bool m_registered;
36 std::string m_ini_filepath{"heliocentric_distance/HeliocentricDistance.ini"};
37
38 public:
40 bool setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules) override;
41 bool exec(std::string_view param) override; // main functionality of the module
42
43 bool init() override;
44 bool preTimeStep() override;
45 bool postTimeStep() override { return true; };
46 bool output() override { return true; };
47
48 void writeToSim();
49
50 std::vector<std::string> getChainInsertion() const override
51 {
52 return this->ini_file_data.getStringVectorParameters("chain_insertion");
53 };
54
55 static std::shared_ptr<GenericManagingModule<T>> createMethode(SimulationClassBase<T>* sim)
56 {
57 return std::make_shared<HeliocentricDistance<T>>(sim);
58 };
59 static std::string getName() { return "HeliocentricDistance"; };
60 std::string_view getNameLocal() const override { return "HeliocentricDistance"; };
61};
62
63// ================= Implementation =================
64
65template <typename T>
67 : GenericManagingModule<T>(sim)
68{
69 try
70 {
71 std::string ini_folder_path{
72 this->sim->m_simulation_config.getStringParameters("ini_folder_path")};
73 this->ini_file_data.loadUserInput(ini_folder_path + m_ini_filepath);
75 }
76 catch (const BadInput& e)
77 {
78 std::cerr << e.what() << '\n';
79 }
80}
81
82template <typename T>
84 std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
85{
86 std::cout << "I am the setup function of the HeliocentricDistance module!\n";
87 this->sim->m_field_map.insert({"HeliocentricDistance", std::valarray<T>(1)});
88 this->module_field = std::make_shared<std::valarray<T>>(1);
89 this->setSubmodules(all_submodules);
90
91 return true;
92}
93
94template <typename T>
95bool HeliocentricDistance<T>::exec(std::string_view param)
96{
97 if (param == "InitChain")
98 {
99 return init();
100 }
101 if (param == "PreTimeStepChain")
102 {
103 return preTimeStep();
104 }
105 if (param == "PostTimeStepChain")
106 {
107 return postTimeStep();
108 }
109 if (param == "OutputChain")
110 {
111 return output();
112 }
113 return false;
114}
115
116template <typename T>
118{
119 this->sim->m_field_map["HeliocentricDistance"] = (*this->module_field);
120}
121
122template <typename T>
124{
125 this->sub_module_chain.runChain("PreTimeStepChain");
126 writeToSim();
127 return true;
128}
129
130template <typename T>
132{
133 this->sub_module_chain.runChain("InitChain");
134 writeToSim();
135 return true;
136}
137
138template <typename T>
140 ModuleFactory<T>::registerModule(getName(), createMethode);
141
142#endif // HELIOCENTRIC_DISTANCE_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
Abstract base class for the managing modules. Managing modules are the highest tier of modules and ar...
Definition GenericManagingModule.h:29
InputManager ini_file_data
Definition GenericManagingModule.h:38
SimulationClassBase< T > * sim
Definition GenericManagingModule.h:31
std::vector< std::string > m_generic_submodules
Definition GenericManagingModule.h:36
Abstract base class for the submodules. Submodules are below managing modules and will only be run by...
Definition GenericSubmodule.h:25
Definition HeliocentricDistance.h:33
static std::shared_ptr< GenericManagingModule< T > > createMethode(SimulationClassBase< T > *sim)
Definition HeliocentricDistance.h:55
std::string_view getNameLocal() const override
Definition HeliocentricDistance.h:60
std::vector< std::string > getChainInsertion() const override
Definition HeliocentricDistance.h:50
bool init() override
Definition HeliocentricDistance.h:131
HeliocentricDistance(SimulationClassBase< T > *sim)
Definition HeliocentricDistance.h:66
static std::string getName()
Definition HeliocentricDistance.h:59
bool output() override
Definition HeliocentricDistance.h:46
bool setup(std::vector< std::shared_ptr< GenericSubmodule< T > > > all_submodules) override
Definition HeliocentricDistance.h:83
bool postTimeStep() override
Definition HeliocentricDistance.h:45
void writeToSim()
Definition HeliocentricDistance.h:117
bool preTimeStep() override
Definition HeliocentricDistance.h:123
bool exec(std::string_view param) override
Definition HeliocentricDistance.h:95
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:68
Definition SimulationClassBase.h:15
InputManager m_simulation_config
Definition SimulationClassBase.h:24