MoCSI API Reference
Loading...
Searching...
No Matches
HeatSource.h
Go to the documentation of this file.
1#ifndef HEAT_SOURCE_H
2#define HEAT_SOURCE_H
3
4#define HEAT_SOURCE_VERSION "6"
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
30template <typename T>
32{
33 private:
34 static bool m_registered;
35 std::string m_ini_filepath{"heat_source/HeatSource.ini"};
36
37 public:
39 bool setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules) override;
40 bool exec(std::string_view param) override; // main functionality of the module
41
42 bool init() override;
43 bool preTimeStep() override;
44 bool postTimeStep() override { return true; };
45 bool output() override { return true; };
46
47 void writeToSim();
48
49 std::vector<std::string> getChainInsertion() const override
50 {
51 return this->ini_file_data.getStringVectorParameters("chain_insertion");
52 };
53
54 static std::shared_ptr<GenericManagingModule<T>> createMethode(SimulationClassBase<T>* sim)
55 {
56 return std::make_shared<HeatSource<T>>(sim);
57 };
58 static std::string getName() { return "HeatSource"; };
59 std::string_view getNameLocal() const override { return "HeatSource"; };
60};
61
62// ================= Implementation =================
63
64template <typename T>
66{
67 try
68 {
69 std::string ini_folder_path{
70 this->sim->m_simulation_config.getStringParameters("ini_folder_path")};
71 this->ini_file_data.loadUserInput(ini_folder_path + m_ini_filepath);
73 }
74 catch (const BadInput& e)
75 {
76 std::cerr << "[HeatSource]: " << e.what() << '\n';
77 throw BadInput(static_cast<std::string>("[HeatSource]: ")
78 + static_cast<std::string>(e.what()));
79 }
80}
81
82template <typename T>
83bool HeatSource<T>::setup(std::vector<std::shared_ptr<GenericSubmodule<T>>> all_submodules)
84{
85 try
86 {
87 this->sim->m_field_map.insert(
88 {"HeatSource",
89 std::valarray<double>(
90 this->sim->m_simulation_config.getIntParameters("numerical_layers")
91 * this->sim->m_simulation_config.getIntParameters("number_of_facets"))});
92 this->module_field = std::make_shared<std::valarray<T>>(
93 this->sim->m_simulation_config.getIntParameters("numerical_layers")
94 * this->sim->m_simulation_config.getIntParameters("number_of_facets"));
95 this->setSubmodules(all_submodules);
96 }
97 catch (const BadInput& e)
98 {
99 std::cerr << "[HeatSource]: Failed to insert field map and/or local field!\n[HeatSource]: "
100 << e.what() << '\n';
101 throw BadInput(
102 static_cast<std::string>(
103 "[HeatSource]: Failed to insert field map and/or local field!\n[HeatSource]: ")
104 + static_cast<std::string>(e.what()));
105 }
106 return true;
107}
108
109template <typename T>
110bool HeatSource<T>::exec(std::string_view param)
111{
112 if (param == "InitChain")
113 {
114 return init();
115 }
116 if (param == "PreTimeStepChain")
117 {
118 return preTimeStep();
119 }
120 if (param == "PostTimeStepChain")
121 {
122 return postTimeStep();
123 }
124 if (param == "OutputChain")
125 {
126 return output();
127 }
128 return false;
129}
130
131template <typename T>
133{
134 this->sim->m_field_map["HeatSource"] = (*this->module_field);
135}
136
137template <typename T>
139{
140 this->sub_module_chain.runChain("InitChain");
141 writeToSim();
142 return true;
143}
144
145template <typename T>
147{
148 this->sub_module_chain.runChain("PreTimeStepChain");
149 writeToSim();
150 return true;
151}
152
153template <typename T>
155
156#endif // HEAT_SOURCE_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 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
Definition HeatSource.h:32
bool init() override
Definition HeatSource.h:138
static std::shared_ptr< GenericManagingModule< T > > createMethode(SimulationClassBase< T > *sim)
Definition HeatSource.h:54
bool setup(std::vector< std::shared_ptr< GenericSubmodule< T > > > all_submodules) override
Definition HeatSource.h:83
static std::string getName()
Definition HeatSource.h:58
bool exec(std::string_view param) override
Definition HeatSource.h:110
bool preTimeStep() override
Definition HeatSource.h:146
void writeToSim()
Definition HeatSource.h:132
std::vector< std::string > getChainInsertion() const override
Definition HeatSource.h:49
bool postTimeStep() override
Definition HeatSource.h:44
bool output() override
Definition HeatSource.h:45
std::string_view getNameLocal() const override
Definition HeatSource.h:59
HeatSource(SimulationClassBase< T > *sim)
Definition HeatSource.h:65
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