MoCSI API Reference
Loading...
Searching...
No Matches
GenericElement.h
Go to the documentation of this file.
1#ifndef GENERIC_ELEMENT_H
2#define GENERIC_ELEMENT_H
3
4#include <functional>
5#include <map>
6#include <memory>
7#include <utility>
8#include <valarray>
9#include <vector>
10
12#include "GenericMatrix.h"
13#include "SimulationClassBase.h"
14
19template <typename T>
25
30template <typename T>
32{
33 protected:
35 std::map<std::string_view, std::vector<int>>
36 m_boundary_points; // Map that holds the boundary type and the nodes which are
37 // boundary points in that element
38 std::vector<int> m_nodal_values;
39 std::vector<std::reference_wrapper<T>> m_capacitance_matrix_elements{};
40 std::vector<std::reference_wrapper<T>> m_stiffness_matrix_elements{};
41 std::vector<std::reference_wrapper<T>> m_forcing_vector_elements{};
43 int m_element_nr{-1};
44 std::map<std::string_view, std::unique_ptr<GenericBoundaryCondition<T>>>
47
48 public:
49 virtual void writeMatrixVectorBlock() = 0;
50 virtual void writeBoundaryCondition() = 0;
51
53 std::map<std::string_view, std::unique_ptr<GenericBoundaryCondition<T>>>&
55 std::map<std::string_view, std::unique_ptr<GenericBoundaryCondition<T>>>&
64 std::valarray<T>& forcing_vector);
65 bool isBoundary() { return m_is_boundary; }
66
68 std::map<std::string_view, std::vector<int>> all_boundary_points,
69 std::vector<int> nodal_values, SimulationClassBase<T>* sim, int num_cell,
71 virtual ~GenericElement() = default;
72};
73
85template <typename T>
87 std::map<std::string_view, std::vector<int>> all_boundary_points,
88 std::vector<int> nodal_values, SimulationClassBase<T>* sim,
90 : m_is_boundary{is_boundary_point},
91 m_boundary_points{std::move(all_boundary_points)},
92 m_nodal_values{std::move(nodal_values)},
93 m_sim{sim},
94 m_element_nr{num_cell},
95 m_properties{properties}
96{
97}
98
105template <typename T>
107 std::map<std::string_view, std::unique_ptr<GenericBoundaryCondition<T>>>& boundary_cond)
108{
109 m_boundary_conditions = std::move(boundary_cond);
110}
111
118template <typename T>
121 std::valarray<T>& forcing_vector)
122{
123 for (int i : this->m_nodal_values)
124 {
125 for (int j : this->m_nodal_values)
126 {
127 this->m_capacitance_matrix_elements.emplace_back(capacitance_matrix(i, j));
128 this->m_stiffness_matrix_elements.emplace_back(stiffness_matrix(i, j));
129 }
130 this->m_forcing_vector_elements.emplace_back(forcing_vector[i]);
131 }
132}
133
134template <typename T>
137{
140 {
141 for (int i : this->m_nodal_values)
142 {
143 for (int j : this->m_nodal_values)
144 {
147 }
148 }
149 }
150}
151
152#endif
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:35
void registerElement(T value, int rows, int cols) override
Registers the element and it's initial value within a COO style vector for dynamic creation.
Definition CsrMatrix.h:126
CsrSparseMatrix()
Constructor for an empty CsrSparseMatrix object. Leaves all storage arrays empty but sets the flag to...
Definition CsrMatrix.h:92
const MatrixType getMatrixType() override
Definition CsrMatrix.h:69
Cell/Element abstract base class for the finite element method. All 1D/2D/3D elements should inherit ...
Definition GenericElement.h:32
std::vector< std::reference_wrapper< T > > m_forcing_vector_elements
Definition GenericElement.h:41
void registerElementsCsr(GenericMatrix< T > &capacitance_matrix, GenericMatrix< T > &stiffness_matrix)
Definition GenericElement.h:135
virtual void writeMatrixVectorBlock()=0
void setBoundaryConditions(std::map< std::string_view, std::unique_ptr< GenericBoundaryCondition< T > > > &boundary_cond)
Sets the map of boundary condition objects.
Definition GenericElement.h:106
virtual ~GenericElement()=default
std::map< std::string_view, std::unique_ptr< GenericBoundaryCondition< T > > > m_boundary_conditions
Definition GenericElement.h:45
int m_element_nr
Definition GenericElement.h:43
std::map< std::string_view, std::vector< int > > m_boundary_points
Definition GenericElement.h:36
bool isBoundary()
Definition GenericElement.h:65
std::vector< std::reference_wrapper< T > > m_capacitance_matrix_elements
Definition GenericElement.h:39
ElementProperties< T > m_properties
Definition GenericElement.h:46
bool m_is_boundary
Definition GenericElement.h:34
std::map< std::string_view, std::unique_ptr< GenericBoundaryCondition< T > > > & getBoundaryCondition()
Definition GenericElement.h:56
virtual void writeBoundaryCondition()=0
std::vector< std::reference_wrapper< T > > m_stiffness_matrix_elements
Definition GenericElement.h:40
SimulationClassBase< T > * m_sim
Definition GenericElement.h:42
GenericElement(bool is_boundary_point, std::map< std::string_view, std::vector< int > > all_boundary_points, std::vector< int > nodal_values, SimulationClassBase< T > *sim, int num_cell, ElementProperties< T > properties)
Constructor for a GenericElement object. Sets all parameters that are known at creation.
Definition GenericElement.h:86
std::vector< int > m_nodal_values
Definition GenericElement.h:38
void getReferenceToElements(GenericMatrix< T > &capacitance_matrix, GenericMatrix< T > &stiffness_matrix, std::valarray< T > &forcing_vector)
Sets up a reference_wrapper vector to the elements within the matrix object. This adds a bit of pre-c...
Definition GenericElement.h:119
Struct carrying the element properties that are needed to create the different element types....
Definition GenericElement.h:21
T element_length
Definition GenericElement.h:22
T element_area
Definition GenericElement.h:23