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 SOLAR_VECTOR_VERSION "7"
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 << "[SolarVector]: " << e.what() << '\n';
75 throw BadInput(static_cast<std::string>("[SolarVector]: ")
76 + static_cast<std::string>(e.what()));
77 }
78}
79
80template <typename T>
81bool SolarVector<T>::setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
82{
83 try
84 {
85 this->sim->m_field_map.insert({"SolarVector", std::valarray<T>(3)});
86 this->module_field = std::make_shared<std::valarray<T>>(3);
87 this->setSubmodules(all_submodules);
88 }
89 catch (const BadInput& e)
90 {
91 std::cerr << "[SolarVector]: Failed to insert field map and/or local "
92 "field!\n[SolarVector]: "
93 << e.what() << '\n';
94 throw BadInput(
95 static_cast<std::string>("[SolarVector]: Failed to insert field map and/or local "
96 "field!\n[SolarVector]: ")
97 + static_cast<std::string>(e.what()));
98 }
99 return true;
100}
101
102template <typename T>
103bool SolarVector<T>::exec(std::string_view param)
104{
105 if (param == "InitChain")
106 {
107 return init();
108 }
109 if (param == "PreTimeStepChain")
110 {
111 return preTimeStep();
112 }
113 if (param == "PostTimeStepChain")
114 {
115 return postTimeStep();
116 }
117 if (param == "OutputChain")
118 {
119 return output();
120 }
121 return false;
122}
123
124template <typename T>
126{
127 this->sim->m_field_map["SolarVector"] = (*this->module_field);
128}
129
130template <typename T>
132{
133 this->sub_module_chain.runChain("PreTimeStepChain");
134 writeToSim();
135 return true;
136}
137
138template <typename T>
140{
141 this->sub_module_chain.runChain("InitChain");
142 writeToSim();
143 return true;
144}
145
146template <typename T>
148
149#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:37
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:508
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:45
static constexpr bool registerModule(std::string name, creation_method module) noexcept
Function that adds a module to the module registry map.
Definition ModuleFactory.h:76
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:131
bool output() override
Definition SolarVector.h:43
bool setup(std::vector< std::shared_ptr< GenericSubmodule< T > > > all_submodules) override
Definition SolarVector.h:81
bool postTimeStep() override
Definition SolarVector.h:42
bool init() override
Definition SolarVector.h:139
SolarVector(SimulationClassBase< T > *sim)
Definition SolarVector.h:63
void writeToSim()
Definition SolarVector.h:125
bool exec(std::string_view param) override
Definition SolarVector.h:103
std::vector< std::string > getChainInsertion() const override
Definition SolarVector.h:47