MoCSI API Reference
Loading...
Searching...
No Matches
SolarVector.h
Go to the documentation of this file.
1#ifndef SOLAR_VECTOR_H
2#define SOLAR_VECTOR_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
28template <typename T>
30{
31 private:
32 static bool m_registered;
33 std::string m_ini_filepath{"solar_vector/SolarVector.ini"};
34
35 public:
37 bool setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules) override;
38 bool exec(std::string_view param) override; // main functionality of the module
39
40 bool init() override;
41 bool preTimeStep() override;
42 bool postTimeStep() override { return true; };
43 bool output() override { return true; };
44
45 void writeToSim();
46
47 std::vector<std::string> getChainInsertion() const override
48 {
49 return this->ini_file_data.getStringVectorParameters("chain_insertion");
50 };
51
52 static std::shared_ptr<GenericManagingModule<T>> createMethode(SimulationClassBase<T>* sim)
53 {
54 return std::make_shared<SolarVector<T>>(sim);
55 };
56 static std::string getName() { return "SolarVector"; };
57 std::string_view getNameLocal() const override { return "SolarVector"; };
58};
59
60// ================= Implementation =================
61
62template <typename T>
64{
65 try
66 {
67 std::string ini_folder_path{
68 this->sim->m_simulation_config.getStringParameters("ini_folder_path")};
69 this->ini_file_data.loadUserInput(ini_folder_path + m_ini_filepath);
71 }
72 catch (const BadInput& e)
73 {
74 std::cerr << e.what() << '\n';
75 }
76}
77
78template <typename T>
79bool SolarVector<T>::setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
80{
81 std::cout << "I am the setup function of the SolarVector module!\n";
82 this->sim->m_field_map.insert({"SolarVector", std::valarray<T>(3)});
83 this->module_field = std::make_shared<std::valarray<T>>(3);
84 this->setSubmodules(all_submodules);
85
86 return true;
87}
88
89template <typename T>
90bool SolarVector<T>::exec(std::string_view param)
91{
92 if (param == "InitChain")
93 {
94 return init();
95 }
96 if (param == "PreTimeStepChain")
97 {
98 return preTimeStep();
99 }
100 if (param == "PostTimeStepChain")
101 {
102 return postTimeStep();
103 }
104 if (param == "OutputChain")
105 {
106 return output();
107 }
108 return false;
109}
110
111template <typename T>
113{
114 this->sim->m_field_map["SolarVector"] = (*this->module_field);
115}
116
117template <typename T>
119{
120 this->sub_module_chain.runChain("PreTimeStepChain");
121 writeToSim();
122 return true;
123}
124
125template <typename T>
127{
128 this->sub_module_chain.runChain("InitChain");
129 writeToSim();
130 return true;
131}
132
133template <typename T>
135
136#endif // SOLAR_VECTOR_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
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
Definition SolarVector.h:30
std::string_view getNameLocal() const override
Definition SolarVector.h:57
static std::shared_ptr< GenericManagingModule< T > > createMethode(SimulationClassBase< T > *sim)
Definition SolarVector.h:52
static std::string getName()
Definition SolarVector.h:56
bool preTimeStep() override
Definition SolarVector.h:118
bool output() override
Definition SolarVector.h:43
bool setup(std::vector< std::shared_ptr< GenericSubmodule< T > > > all_submodules) override
Definition SolarVector.h:79
bool postTimeStep() override
Definition SolarVector.h:42
bool init() override
Definition SolarVector.h:126
SolarVector(SimulationClassBase< T > *sim)
Definition SolarVector.h:63
void writeToSim()
Definition SolarVector.h:112
bool exec(std::string_view param) override
Definition SolarVector.h:90
std::vector< std::string > getChainInsertion() const override
Definition SolarVector.h:47