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 "5"
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 this->sim->m_field_map.insert({"HeliocentricDistance", std::valarray<T>(1)});
87 this->module_field = std::make_shared<std::valarray<T>>(1);
88 this->setSubmodules(all_submodules);
89
90 return true;
91}
92
93template <typename T>
94bool HeliocentricDistance<T>::exec(std::string_view param)
95{
96 if (param == "InitChain")
97 {
98 return init();
99 }
100 if (param == "PreTimeStepChain")
101 {
102 return preTimeStep();
103 }
104 if (param == "PostTimeStepChain")
105 {
106 return postTimeStep();
107 }
108 if (param == "OutputChain")
109 {
110 return output();
111 }
112 return false;
113}
114
115template <typename T>
117{
118 this->sim->m_field_map["HeliocentricDistance"] = (*this->module_field);
119}
120
121template <typename T>
123{
124 this->sub_module_chain.runChain("PreTimeStepChain");
125 writeToSim();
126 return true;
127}
128
129template <typename T>
131{
132 this->sub_module_chain.runChain("InitChain");
133 writeToSim();
134 return true;
135}
136
137template <typename T>
139 ModuleFactory<T>::registerModule(getName(), createMethode);
140
141#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:130
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:116
bool preTimeStep() override
Definition HeliocentricDistance.h:122
bool exec(std::string_view param) override
Definition HeliocentricDistance.h:94
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