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 VERSION "4"
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 << e.what() << '\n';
85 }
86}
87
88template <typename T>
90 std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
91{
92 m_solar_vector.resize(3);
93 m_polar_angle = this->ini_file_data.getDoubleParameters("polar_angle") * std::numbers::pi / 180;
94 m_azimuth = this->ini_file_data.getDoubleParameters("azimuth") * std::numbers::pi / 180;
95 this->m_solar_vector[0] = std::sin(m_polar_angle) * std::cos(m_azimuth);
96 this->m_solar_vector[1] = std::sin(m_polar_angle) * std::sin(m_azimuth);
97 this->m_solar_vector[2] = std::cos(m_polar_angle);
98 return true;
99}
100
101template <typename T>
102bool SolarVectorConstantCustom<T>::exec(std::string_view param)
103{
104 if (param == "InitChain")
105 {
106 return init();
107 }
108 if (param == "PreTimeStepChain")
109 {
110 return preTimeStep();
111 }
112 if (param == "PostTimeStepChain")
113 {
114 return postTimeStep();
115 }
116 if (param == "OutputChain")
117 {
118 return output();
119 }
120 return false;
121}
122
123template <typename T>
125{
126 (*this->module_field) = this->m_solar_vector;
127}
128
129template <typename T>
131{
132 calculateSolarVector();
133 return true;
134}
135
136template <typename T>
138{
139 calculateSolarVector();
140 return true;
141}
142
143template <typename T>
145 ModuleFactory<T>::registerModule(getName(), createMethode);
146
147#endif // SOLAR_VECTOR_CONSTANT_CUSTOM_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 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: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 SolarVectorConstantCustom.h:29
std::string_view getNameLocal() const override
Definition SolarVectorConstantCustom.h:62
bool init() override
Definition SolarVectorConstantCustom.h:137
bool setup(std::vector< std::shared_ptr< GenericSubmodule< T > > > all_submodules) override
Definition SolarVectorConstantCustom.h:89
bool preTimeStep() override
Definition SolarVectorConstantCustom.h:130
bool postTimeStep() override
Definition SolarVectorConstantCustom.h:47
void calculateSolarVector()
Definition SolarVectorConstantCustom.h:124
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:102
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