MoCSI API Reference
Loading...
Searching...
No Matches
AlbedoConstantCustom.h
Go to the documentation of this file.
1#ifndef ALBEDO_CONSTANT_CUSTOM_H
2#define ALBEDO_CONSTANT_CUSTOM_H
3
4#define ALBEDO_CONSTANT_CUSTOM_VERSION "5"
5
6#include <iostream>
7#include <memory>
8#include <string>
9#include <valarray>
10
11#include "../../src/GenericSubmodule.h"
12#include "../../src/ModuleFactory.h"
13
33template <typename T>
35{
36 private:
37 static bool m_registered;
38 std::string m_ini_filepath{"albedo/AlbedoConstantCustom.ini"};
39 T m_user_supplied_albedo{};
40
41 public:
43 bool setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules) override;
44
45 bool exec(std::string_view param) override;
46
47 bool init() override;
48 bool preTimeStep() override;
49 bool postTimeStep() override { return true; };
50 bool output() override { return true; };
51
52 void calculateAlbedo();
53
54 void setFieldPtr(std::shared_ptr<std::valarray<T>> field_ptr) override
55 {
56 this->module_field = field_ptr;
57 }
58
59 static std::shared_ptr<GenericSubmodule<T>> createMethode(SimulationClassBase<T>* sim)
60 {
61 return std::make_shared<AlbedoConstantCustom<T>>(sim);
62 }
63 static std::string getName() { return "AlbedoConstantCustom"; }
64 std::string_view getNameLocal() const override { return "AlbedoConstantCustom"; };
65 std::vector<std::string> getDependencies() const override
66 {
67 return this->ini_file_data.getStringVectorParameters("dependencies");
68 };
69};
70
71// ================= Implementation =================
72
73template <typename T>
75 : GenericSubmodule<T>(sim)
76{
77 try
78 {
79 std::string ini_folder_path{
80 this->sim->m_simulation_config.getStringParameters("ini_folder_path")};
81 this->ini_file_data.loadUserInput(ini_folder_path + m_ini_filepath);
83 }
84 catch (const BadInput& e)
85 {
86 std::cerr << "[AlbedoConstantCustom]" << e.what() << '\n';
87 throw BadInput(static_cast<std::string>("[AlbedoConstantCustom]") + static_cast<std::string>(e.what()));
88 }
89}
90
91template <typename T>
93 std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
94{
95 try
96 {
97 m_user_supplied_albedo = this->ini_file_data.getDoubleParameters("user_supplied_albedo");
98 }
99 catch (const BadInput& e)
100 {
101 std::cerr << "[AlbedoConstantCustom]" << e.what() << '\n';
102 throw BadInput(static_cast<std::string>("[AlbedoConstantCustom]") + static_cast<std::string>(e.what()));
103 }
104
105 return true;
106}
107
108template <typename T>
109bool AlbedoConstantCustom<T>::exec(std::string_view param)
110{
111 if (param == "InitChain")
112 {
113 return init();
114 }
115 if (param == "PreTimeStepChain")
116 {
117 return preTimeStep();
118 }
119 if (param == "PostTimeStepChain")
120 {
121 return postTimeStep();
122 }
123 if (param == "OutputChain")
124 {
125 return output();
126 }
127 return false;
128}
129
130template <typename T>
132{
133 (*this->module_field) = m_user_supplied_albedo;
134}
135
136template <typename T>
138{
139 calculateAlbedo();
140 return true;
141}
142
143template <typename T>
145{
146 calculateAlbedo();
147 return true;
148}
149
150template <typename T>
152 ModuleFactory<T>::registerModule(getName(), createMethode);
153
154#endif // ALBEDO_CONSTANT_H
Submodule that assigns a constant albedo value.
Definition AlbedoConstantCustom.h:35
void setFieldPtr(std::shared_ptr< std::valarray< T > > field_ptr) override
Definition AlbedoConstantCustom.h:54
std::string_view getNameLocal() const override
Definition AlbedoConstantCustom.h:64
AlbedoConstantCustom(SimulationClassBase< T > *sim)
Definition AlbedoConstantCustom.h:74
static std::shared_ptr< GenericSubmodule< T > > createMethode(SimulationClassBase< T > *sim)
Definition AlbedoConstantCustom.h:59
bool setup(std::vector< std::shared_ptr< GenericSubmodule< T > > > all_submodules) override
Definition AlbedoConstantCustom.h:92
bool exec(std::string_view param) override
Definition AlbedoConstantCustom.h:109
bool preTimeStep() override
Definition AlbedoConstantCustom.h:144
bool output() override
Definition AlbedoConstantCustom.h:50
static std::string getName()
Definition AlbedoConstantCustom.h:63
bool init() override
Definition AlbedoConstantCustom.h:137
void calculateAlbedo()
Definition AlbedoConstantCustom.h:131
bool postTimeStep() override
Definition AlbedoConstantCustom.h:49
std::vector< std::string > getDependencies() const override
Definition AlbedoConstantCustom.h:65
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: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
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:498
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 SimulationClassBase.h:19
InputManager m_simulation_config
Definition SimulationClassBase.h:29