MoCSI API Reference
Loading...
Searching...
No Matches
SimulationClassUnitTesting.h
Go to the documentation of this file.
1#ifndef SIMULATION_CLASS_UNIT_TESTING_H
2#define SIMULATION_CLASS_UNIT_TESTING_H
3
4#include <filesystem>
5#include <fstream>
6#include <iostream>
7#include <map>
8#include <memory>
9#include <string>
10#include <valarray>
11#include <vector>
12
13#include "ChainManager.h"
14#include "GridFactory.h"
15#include "ModuleFactory.h"
16#include "SetupRunner.h"
17#include "ShapeFactory.h"
18#include "SimulationClassBase.h"
19
20template <typename T>
22{
23 public:
25 SimulationClassUnitTesting(const std::string& user_ini);
26
28 void setUserIni(const std::string& user_ini) override;
29
30 int run() override;
31 int runInitChain();
32
33 ~SimulationClassUnitTesting() override = default;
34
35 private:
36 std::string m_init_str{"InitChain"};
37 std::string m_preTs_str{"PreTimeStepChain"};
38 std::string m_postTs_str{"PostTimeStepChain"};
39 std::string m_postNonLinIter_str{"PostNonLinIterChain"};
40 std::string m_output_str{"OutputChain"};
41 ChainManager<GenericManagingModule<double>> m_global_chain{"global"};
42};
43
44template <typename T>
46{
47 // Set absolute paths and load ini file
48 std::filesystem::path ini_folder_path =
49 (std::filesystem::path(PROJECT_ROOT) / "build/tests/ini_files/");
50 std::string default_ini_path =
51 std::filesystem::absolute(ini_folder_path / "default.ini").string();
52
53 std::vector<std::string> lines;
54 std::ifstream infile(default_ini_path);
55 std::string line;
56
57 while (std::getline(infile, line))
58 {
59 if (line.rfind("ini_folder_path =", 0) == 0)
60 {
61 line = "ini_folder_path = \"" + ini_folder_path.string() + "\"";
62 }
63 lines.push_back(line);
64 }
65 infile.close();
66
67 std::ofstream outfile(default_ini_path, std::ios::trunc);
68 for (const auto& l : lines)
69 {
70 outfile << l << "\n";
71 }
72 outfile.close();
73
74 std::cout << "PATH: " << default_ini_path << "\n";
75
76 this->m_simulation_config = InputManager(default_ini_path);
77}
78
79template <typename T>
81{
82 this->m_simulation_config.loadUserInput(
83 this->m_simulation_config.getStringParameters("ini_folder_path") + user_ini);
84}
85
86template <typename T>
88{
89 this->setAbsoluteDefaultIniPath();
90}
91
92template <typename T>
95{
96 // Do not use when working with absolute paths since base constructor will always run first
97}
98
99template <typename T>
101{
102 // Loading of the shape model so that all the mesh info is available at grid creation.
103 std::unique_ptr<ShapeFactory<T>> shape_creator{std::make_unique<ShapeFactory<T>>(
104 this, this->m_simulation_config.getBoolParameters("use_shape_file"),
105 this->m_simulation_config.getStringParameters("spatial_dimension"))};
106 std::shared_ptr<ShapeBase<T>> simulation_shape = shape_creator->getShapePtr();
107 std::unique_ptr<GridFactory<T>> grid_creator{std::make_unique<GridFactory<T>>(
108 this, simulation_shape,
109 this->m_simulation_config.getStringParameters("spatial_dimension"))};
110 std::shared_ptr<GridBase<T>> simulation_grid = grid_creator->getGridPtr();
111
112 this->m_field_map.insert(
113 {"Temperature", std::valarray<double>(
114 this->m_simulation_config.getDoubleParameters("initial_temperature"),
115 this->m_simulation_config.getIntParameters("numerical_layers")
116 * this->m_simulation_config.getIntParameters("number_of_facets"))});
117
118 std::vector<std::shared_ptr<GenericManagingModule<double>>> all_modules{
120 std::vector<std::shared_ptr<GenericSubmodule<double>>> all_submodules{
122 m_global_chain.autoLoader(all_modules);
123
124 runSetup<T>(all_modules, all_submodules, m_global_chain.getManagingModuleNames());
125 return 0;
126}
127
128template <typename T>
130{
131 this->setInitChainStr();
132 m_global_chain.runChain(this->m_current_position);
133 return 0;
134}
135
136#endif
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:35
CsrSparseMatrix()
Constructor for an empty CsrSparseMatrix object. Leaves all storage arrays empty but sets the flag to...
Definition CsrMatrix.h:92
This class that manages parameter input through the default ini and user supplied ini files + CLI....
Definition InputManager.h:26
static std::vector< std::shared_ptr< GenericSubmodule< T > > > createAllSubmodules(SimulationClassBase< T > *sim_pointer)
Creates every submodule in the submodule registry.
Definition ModuleFactory.h:165
static std::vector< std::shared_ptr< GenericManagingModule< T > > > createAllManagingModules(SimulationClassBase< T > *sim_pointer)
Creates every module in the module registry.
Definition ModuleFactory.h:146
Definition SimulationClassBase.h:19
Definition SimulationClassUnitTesting.h:22
SimulationClassUnitTesting()
Definition SimulationClassUnitTesting.h:87
int runInitChain()
Definition SimulationClassUnitTesting.h:129
void setAbsoluteDefaultIniPath()
Definition SimulationClassUnitTesting.h:45
void setUserIni(const std::string &user_ini) override
Definition SimulationClassUnitTesting.h:80
int run() override
Definition SimulationClassUnitTesting.h:100
~SimulationClassUnitTesting() override=default