MoCSI API Reference
Loading...
Searching...
No Matches
SolarVectorConstantCustom.h
Go to the documentation of this file.
1#ifndef SOLAR_VECTOR_CONSTANT_CUSTOM_H
2#define SOLAR_VECTOR_CONSTANT_CUSTOM_H
3
4#define SOLAR_VECTOR_CONSTANT_CUSTOM_VERSION "6"
5
6#include <iostream>
7#include <memory>
8#include <numbers>
9#include <string>
10#include <valarray>
11
12#include "../../src/GenericSubmodule.h"
13#include "../../src/ModuleFactory.h"
14
27template <typename T>
29{
30 private:
31 static bool m_registered;
32 std::string m_ini_filepath{"solar_vector/SolarVectorConstantCustom.ini"};
33 std::valarray<T> m_solar_vector;
34 double m_polar_angle;
35 double m_azimuth;
36
37 public:
39 bool setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
40 override; // loads module into necessary module chains (auto load for calculation
41 // chains)
42 bool exec(std::string_view param) override; // main functionality of the module
43
44 // Since the distance is constant it must not be updated
45 bool init() override;
46 bool preTimeStep() override;
47 bool postTimeStep() override { return true; };
48 bool output() override { return true; };
49
51
52 void setFieldPtr(std::shared_ptr<std::valarray<T>> field_ptr) override
53 {
54 this->module_field = field_ptr;
55 }
56
57 static std::shared_ptr<GenericSubmodule<T>> createMethode(SimulationClassBase<T>* sim)
58 {
59 return std::make_shared<SolarVectorConstantCustom<T>>(sim);
60 }
61 static std::string getName() { return "SolarVectorConstantCustom"; }
62 std::string_view getNameLocal() const override { return "SolarVectorConstantCustom"; };
63 std::vector<std::string> getDependencies() const override
64 {
65 return this->ini_file_data.getStringVectorParameters("dependencies");
66 };
67};
68
69// ================= Implementation =================
70
71template <typename T>
73 : GenericSubmodule<T>(sim)
74{
75 try
76 {
77 std::string ini_folder_path{
78 this->sim->m_simulation_config.getStringParameters("ini_folder_path")};
79 this->ini_file_data.loadUserInput(ini_folder_path + m_ini_filepath);
81 }
82 catch (const BadInput& e)
83 {
84 std::cerr << "[SolarVectorConstantCustom]: " << e.what() << '\n';
85 throw BadInput(static_cast<std::string>("[SolarVectorConstantCustom]: ")
86 + static_cast<std::string>(e.what()));
87 }
88}
89
90template <typename T>
92 std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
93{
94 m_solar_vector.resize(3);
95 try
96 {
97 m_polar_angle =
98 this->ini_file_data.getDoubleParameters("polar_angle") * std::numbers::pi / 180;
99 m_azimuth = this->ini_file_data.getDoubleParameters("azimuth") * std::numbers::pi / 180;
100 }
101 catch (const BadInput& e)
102 {
103 std::cerr << "[SolarVectorConstantCustom]: " << e.what() << '\n';
104 throw BadInput(static_cast<std::string>("[SolarVectorConstantCustom]: ")
105 + static_cast<std::string>(e.what()));
106 }
107 this->m_solar_vector[0] = std::sin(m_polar_angle) * std::cos(m_azimuth);
108 this->m_solar_vector[1] = std::sin(m_polar_angle) * std::sin(m_azimuth);
109 this->m_solar_vector[2] = std::cos(m_polar_angle);
110 return true;
111}
112
113template <typename T>
115{
116 if (param == "InitChain")
117 {
118 return init();
119 }
120 if (param == "PreTimeStepChain")
121 {
122 return preTimeStep();
123 }
124 if (param == "PostTimeStepChain")
125 {
126 return postTimeStep();
127 }
128 if (param == "OutputChain")
129 {
130 return output();
131 }
132 return false;
133}
134
135template <typename T>
137{
138 (*this->module_field) = this->m_solar_vector;
139}
140
141template <typename T>
143{
144 calculateSolarVector();
145 return true;
146}
147
148template <typename T>
150{
151 calculateSolarVector();
152 return true;
153}
154
155template <typename T>
157 ModuleFactory<T>::registerModule(getName(), createMethode);
158
159#endif // SOLAR_VECTOR_CONSTANT_CUSTOM_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 submodules. Submodules are below managing modules and will only be run by...
Definition GenericSubmodule.h:25
InputManager ini_file_data
Definition GenericSubmodule.h:36
std::vector< std::string > m_generic_submodules
Definition GenericSubmodule.h:34
const SimulationClassBase< T > * sim
Definition GenericSubmodule.h:32
std::shared_ptr< std::valarray< T > > module_field
Definition GenericSubmodule.h:29
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 SolarVectorConstantCustom.h:29
std::string_view getNameLocal() const override
Definition SolarVectorConstantCustom.h:62
bool init() override
Definition SolarVectorConstantCustom.h:149
bool setup(std::vector< std::shared_ptr< GenericSubmodule< T > > > all_submodules) override
Definition SolarVectorConstantCustom.h:91
bool preTimeStep() override
Definition SolarVectorConstantCustom.h:142
bool postTimeStep() override
Definition SolarVectorConstantCustom.h:47
void calculateSolarVector()
Definition SolarVectorConstantCustom.h:136
std::vector< std::string > getDependencies() const override
Definition SolarVectorConstantCustom.h:63
SolarVectorConstantCustom(SimulationClassBase< T > *sim)
Definition SolarVectorConstantCustom.h:72
bool exec(std::string_view param) override
Definition SolarVectorConstantCustom.h:114
static std::string getName()
Definition SolarVectorConstantCustom.h:61
static std::shared_ptr< GenericSubmodule< T > > createMethode(SimulationClassBase< T > *sim)
Definition SolarVectorConstantCustom.h:57
void setFieldPtr(std::shared_ptr< std::valarray< T > > field_ptr) override
Definition SolarVectorConstantCustom.h:52
bool output() override
Definition SolarVectorConstantCustom.h:48