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 "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
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 this->sim->m_field_map.insert({"SolarVector", std::valarray<T>(3)});
82 this->module_field = std::make_shared<std::valarray<T>>(3);
83 this->setSubmodules(all_submodules);
84
85 return true;
86}
87
88template <typename T>
89bool SolarVector<T>::exec(std::string_view param)
90{
91 if (param == "InitChain")
92 {
93 return init();
94 }
95 if (param == "PreTimeStepChain")
96 {
97 return preTimeStep();
98 }
99 if (param == "PostTimeStepChain")
100 {
101 return postTimeStep();
102 }
103 if (param == "OutputChain")
104 {
105 return output();
106 }
107 return false;
108}
109
110template <typename T>
112{
113 this->sim->m_field_map["SolarVector"] = (*this->module_field);
114}
115
116template <typename T>
118{
119 this->sub_module_chain.runChain("PreTimeStepChain");
120 writeToSim();
121 return true;
122}
123
124template <typename T>
126{
127 this->sub_module_chain.runChain("InitChain");
128 writeToSim();
129 return true;
130}
131
132template <typename T>
134
135#endif // SOLAR_VECTOR_H
This error class inherits from std::exception and marks faulty parameter or CL inputs....
Definition IniParser.h:71
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:35
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
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
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 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:117
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:125
SolarVector(SimulationClassBase< T > *sim)
Definition SolarVector.h:63
void writeToSim()
Definition SolarVector.h:111
bool exec(std::string_view param) override
Definition SolarVector.h:89
std::vector< std::string > getChainInsertion() const override
Definition SolarVector.h:47