MoCSI API Reference
Loading...
Searching...
No Matches
MatrixManager.h
Go to the documentation of this file.
1#ifndef MATRIX_MANAGER_H
2#define MATRIX_MANAGER_H
3
4#include <algorithm>
5#include <memory>
6#include <string>
7#include <vector>
8
9#include "GenericMatrix.h"
10#include "MatrixFactory.h"
11#include "SimulationClassBase.h"
12
17template <typename T>
19{
20 private:
21 std::vector<std::pair<int, int>> m_non_zero_elements;
23
24 void flushMatrices();
25
26 public:
27 // It only makes sense for them to be public as I need to get references to these objects.
28 std::shared_ptr<GenericMatrix<T>> lhs_matrix{};
29 std::valarray<T> rhs_vector{};
30
32 std::shared_ptr<MatrixFactory<T>> matrix_factory);
33
35 std::shared_ptr<GenericMatrix<T>> stiffness_matrix,
36 std::valarray<T>& forcing_vector);
37};
38
42template <typename T>
44 std::shared_ptr<MatrixFactory<T>> matrix_factory)
45 : m_sim{sim}, lhs_matrix(matrix_factory->createShared())
46{
47 lhs_matrix->buildAtRuntime(size, size);
48 rhs_vector.resize(size);
49}
50
59template <typename T>
61 std::shared_ptr<GenericMatrix<T>> stiffness_matrix,
62 std::valarray<T>& forcing_vector)
63{
64 if (m_non_zero_elements.empty())
65 {
66 stiffness_matrix->updateNonZeroElements();
67 m_non_zero_elements = stiffness_matrix->getNonZeroElements();
68 }
69 T delta_t{m_sim->m_simulation_config.getDoubleParameters("time_delta")};
70 const std::valarray<T>& temperature{m_sim->m_field_map.at("Temperature")};
71 flushMatrices();
72 for (const auto& [row, col] : m_non_zero_elements)
73 {
74 (*lhs_matrix)(row, col) =
76 if (row == col)
77 {
78 rhs_vector[row] += forcing_vector[row] * delta_t;
79 }
80 rhs_vector[row] += (*capacitance_matrix)(row, col) * temperature[col];
81 }
82}
83
89template <typename T>
91{
92 lhs_matrix->zeroMatrix();
93 rhs_vector *= 0.0;
94}
95
96#endif
Error class to throw when a module chain has circular or missing dependencies. Inherits from std::exc...
Definition ChainManager.h:28
Class that manages the assembly of the global linear system of equations to be passed to the solver.
Definition MatrixManager.h:19
std::valarray< T > rhs_vector
Definition MatrixManager.h:29
MatrixManager(int size, SimulationClassBase< T > *sim, std::shared_ptr< MatrixFactory< T > > matrix_factory)
Constructor for MatrixManager.
Definition MatrixManager.h:43
void assembleGlobalLse(std::shared_ptr< GenericMatrix< T > > capacitance_matrix, std::shared_ptr< GenericMatrix< T > > stiffness_matrix, std::valarray< T > &forcing_vector)
Function which assembles the global linear system of equations from the global FEM matrices.
Definition MatrixManager.h:60
std::shared_ptr< GenericMatrix< T > > lhs_matrix
Definition MatrixManager.h:28