MoCSI API Reference
Loading...
Searching...
No Matches
OneDimLinearElement.h
Go to the documentation of this file.
1#ifndef ONE_D_LINEAR_ELEMENT
2#define ONE_D_LINEAR_ELEMENT
3
4#include <map>
5#include <memory>
6#include <valarray>
7#include <vector>
8
9#include "GenericElement.h"
10#include "IniParser.h"
11#include "SimulationClassBase.h"
12
16template <typename T>
18{
19 private:
20 T m_area;
21 T m_element_length;
22
23 public:
24 void writeMatrixVectorBlock() override;
25 void writeBoundaryCondition() override;
26
28 std::map<std::string_view, std::vector<int>> all_boundary_points,
29 std::vector<int> nodal_values, SimulationClassBase<T>* sim, int cell_nr,
31 ~OneDimLinearElement() override = default;
32};
33
46template <typename T>
48 bool is_boundary_point, std::map<std::string_view, std::vector<int>> all_boundary_points,
49 std::vector<int> nodal_values, SimulationClassBase<T>* sim, int cell_nr,
52 m_area(this->m_properties.element_area),
53 m_element_length(this->m_properties.element_length)
54{
55}
56
63template <typename T>
65{
67 try
68 {
70 (this->m_sim->getFieldValue("HeatConductivity", this->m_nodal_values[0])
71 + this->m_sim->getFieldValue("HeatConductivity", this->m_nodal_values[1]))
72 / 2;
73 heat_capacity = (this->m_sim->getFieldValue("HeatCapacity", this->m_nodal_values[0])
74 + this->m_sim->getFieldValue("HeatCapacity", this->m_nodal_values[1]))
75 / 2;
76 density = (this->m_sim->getFieldValue("Density", this->m_nodal_values[0])
77 + this->m_sim->getFieldValue("Density", this->m_nodal_values[1]))
78 / 2;
79 source_terms = (this->m_sim->getFieldValue("HeatSource", this->m_nodal_values[0])
80 + this->m_sim->getFieldValue("HeatSource", this->m_nodal_values[1]))
81 / 2;
82 }
83 catch (const std::exception& e)
84 {
85 std::cerr << "[OneDimLinearElement]: One or more of the necessary base modules (Density, "
86 "HeatCapacity, HeatConductivity, HeatSource) "
87 "not loaded or "
88 "accessable!\n [OneDimLinearElement]:"
89 << e.what() << '\n';
90 throw BadInput(static_cast<std::string>(
91 "[OneDimLinearElement]: One or more of the necessary base modules "
92 "(Density, HeatCapacity, HeatConductivity, HeatSource) "
93 "not loaded or "
94 "accessable!\n [OneDimLinearElement]:")
95 + static_cast<std::string>(e.what()));
96 }
97 // T area{ SHAPEMODEL.getArea(this->m_element_nr)};
98
99 // Capacitance matrix entries
100 this->m_capacitance_matrix_elements[0] +=
101 2 * density * heat_capacity * m_area * m_element_length / 6;
102 this->m_capacitance_matrix_elements[1] +=
103 density * heat_capacity * m_area * m_element_length / 6;
104 this->m_capacitance_matrix_elements[2] +=
105 density * heat_capacity * m_area * m_element_length / 6;
106 this->m_capacitance_matrix_elements[3] +=
107 2 * density * heat_capacity * m_area * m_element_length / 6;
108
109 // Stiffness matrix entries
110 this->m_stiffness_matrix_elements[0] += heat_conductivity * m_area / m_element_length;
111 this->m_stiffness_matrix_elements[1] -= heat_conductivity * m_area / m_element_length;
112 this->m_stiffness_matrix_elements[2] -= heat_conductivity * m_area / m_element_length;
113 this->m_stiffness_matrix_elements[3] += heat_conductivity * m_area / m_element_length;
114
115 // Forcing vector entries
116 this->m_forcing_vector_elements[0] += m_area * source_terms * m_element_length / 2;
117 this->m_forcing_vector_elements[1] += m_area * source_terms * m_element_length / 2;
118}
119
124template <typename T>
126{
127 for (auto& [key, boundary_condition] : this->m_boundary_conditions)
128 {
129 writeMatrixVectorBlock(); // The interior entries of the boundary are never changed, so
130 // they need to be calculated
131 boundary_condition->writeBoundaryCondition(); // Then everything reading the boundary
132 // condition is calculated (and overwrites
133 // the previous values if necessary)
134 }
135}
136
137#endif
This error class inherits from std::exception and marks faulty parameter or CL inputs....
Definition IniParser.h:71
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:37
CsrSparseMatrix()
Constructor for an empty CsrSparseMatrix object. Leaves all storage arrays empty but sets the flag to...
Definition CsrMatrix.h:94
Cell/Element abstract base class for the finite element method. All 1D/2D/3D elements should inherit ...
Definition GenericElement.h:32
Concrete Implementation of a 1D linear (line) element for the FEM.
Definition OneDimLinearElement.h:18
void writeMatrixVectorBlock() override
The implementation of the FEM scheme on this element type. Calculates all the values that you get sol...
Definition OneDimLinearElement.h:64
~OneDimLinearElement() override=default
void writeBoundaryCondition() override
The implementation of a boundary cell in the FEM scheme on this element type. If this cell is a bound...
Definition OneDimLinearElement.h:125
OneDimLinearElement(bool is_boundary_point, std::map< std::string_view, std::vector< int > > all_boundary_points, std::vector< int > nodal_values, SimulationClassBase< T > *sim, int cell_nr, ElementProperties< T > props)
Constructor for a OneDimLinearElement object.
Definition OneDimLinearElement.h:47