MoCSI API Reference
Loading...
Searching...
No Matches
Albedo.h
Go to the documentation of this file.
1#ifndef ALBEDO_H
2#define ALBEDO_H
3
4#define ALBEDO_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
35template <typename T>
37{
38 private:
45 static bool m_registered;
46
52 std::string m_ini_filepath{"albedo/Albedo.ini"};
53
54 public:
63
72 bool setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules) override;
73
86 bool exec(std::string_view param) override; // main functionality of the module
87
95 bool init() override;
96
104 bool preTimeStep() override;
105
113 bool postTimeStep() override { return true; };
114
122 bool output() override { return true; };
123
129 void writeToSim();
130
139 std::vector<std::string> getChainInsertion() const override
140 {
141 return this->ini_file_data.getStringVectorParameters("chain_insertion");
142 };
143
152 static std::shared_ptr<GenericManagingModule<T>> createMethode(SimulationClassBase<T>* sim)
153 {
154 return std::make_shared<Albedo<T>>(sim);
155 };
156
162 static std::string getName() { return "Albedo"; };
163
169 std::string_view getNameLocal() const override { return "Albedo"; };
170};
171
172// ================= Implementation =================
173
174template <typename T>
176{
177 try
178 {
179 std::string ini_folder_path{
180 this->sim->m_simulation_config.getStringParameters("ini_folder_path")};
181 this->ini_file_data.loadUserInput(ini_folder_path + m_ini_filepath);
183 }
184 catch (const BadInput& e)
185 {
186 std::cerr << e.what() << '\n';
187 }
188}
189
190template <typename T>
191bool Albedo<T>::setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
192{
193 this->sim->m_field_map.insert(
194 {"Albedo",
195 std::valarray<T>(this->sim->m_simulation_config.getIntParameters("number_of_facets"))});
196 this->module_field = std::make_shared<std::valarray<T>>(
197 this->sim->m_simulation_config.getIntParameters("number_of_facets"));
198 this->setSubmodules(all_submodules);
199 return true;
200}
201
202template <typename T>
203bool Albedo<T>::exec(std::string_view param)
204{
205 if (param == "InitChain")
206 {
207 return init();
208 }
209 if (param == "PreTimeStepChain")
210 {
211 return preTimeStep();
212 }
213 if (param == "PostTimeStepChain")
214 {
215 return postTimeStep();
216 }
217 if (param == "OutputChain")
218 {
219 return output();
220 }
221 return false;
222}
223
224template <typename T>
226{
227 this->sim->m_field_map["Albedo"] = (*this->module_field);
228}
229
230template <typename T>
232{
233 this->sub_module_chain.runChain("InitChain");
234 writeToSim();
235 return true;
236}
237
238template <typename T>
240{
241 this->sub_module_chain.runChain("PreTimeStepChain");
242 writeToSim();
243 return true;
244}
245
246template <typename T>
247bool Albedo<T>::m_registered = ModuleFactory<T>::registerModule(getName(), createMethode);
248
249#endif // ALBEDO_H
Managing module that calculates and manages surface albedo.
Definition Albedo.h:37
static std::shared_ptr< GenericManagingModule< T > > createMethode(SimulationClassBase< T > *sim)
Factory method for creating an Albedo module.
Definition Albedo.h:152
bool exec(std::string_view param) override
Main execution method of the module.
Definition Albedo.h:203
std::vector< std::string > getChainInsertion() const override
Get chain insertion points.
Definition Albedo.h:139
Albedo(SimulationClassBase< T > *sim)
Construct the Albedo module.
Definition Albedo.h:175
void writeToSim()
Write the current albedo field to the simulation.
Definition Albedo.h:225
bool postTimeStep() override
Post-time-step processing.
Definition Albedo.h:113
bool preTimeStep() override
Pre-time-step processing.
Definition Albedo.h:239
std::string_view getNameLocal() const override
Get the localized name of the module.
Definition Albedo.h:169
bool setup(std::vector< std::shared_ptr< GenericSubmodule< T > > > all_submodules) override
Setup method called after construction.
Definition Albedo.h:191
bool output() override
Output stage.
Definition Albedo.h:122
bool init() override
Initialization step.
Definition Albedo.h:231
static std::string getName()
Get the name of the module.
Definition Albedo.h:162
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:75
Definition SimulationClassBase.h:19
InputManager m_simulation_config
Definition SimulationClassBase.h:29