MoCSI API Reference
Loading...
Searching...
No Matches
BCSinusoidalTemperature.h
Go to the documentation of this file.
1#ifndef BOUNDARY_CONDITION_SINUSOIDAL_TEMPERATURE_H
2#define BOUNDARY_CONDITION_SINUSOIDAL_TEMPERATURE_H
3
4#include <cmath>
5#include <memory>
6#include <numbers>
7#include <string>
8#include <valarray>
9#include <vector>
10
12#include "SimulationClassBase.h"
13
17template <typename T>
19{
20 private:
21 T m_temperature_amplitude{};
22 T m_base_temperature{};
23 T m_period{};
24 T m_dt{};
25 int m_numerical_layer{};
26 std::vector<std::reference_wrapper<T>> m_capacitance_extra_val{};
27 std::vector<std::reference_wrapper<T>> m_stiffness_extra_val{};
28 std::vector<std::reference_wrapper<T>> m_forcing_extra_val{};
29
30 public:
31 void writeBoundaryCondition() override;
34 std::valarray<T>& forcing_vector) override;
35
37 std::vector<std::vector<int>> connected_points, int facet_nr,
38 T area, std::string face_prefix);
39 ~BCSinusoidalTemperature() override = default;
40};
41
53template <typename T>
55 std::vector<int> boundary_points,
56 std::vector<std::vector<int>> connected_points,
57 int facet_nr, T area, std::string face_prefix)
59 m_base_temperature(
60 this->m_sim->m_simulation_config.getDoubleParameters("initial_temperature")),
61 m_numerical_layer(this->m_sim->m_simulation_config.getIntParameters("numerical_layers"))
62{
63 try
64 {
65 m_temperature_amplitude = this->m_sim->m_simulation_config.getDoubleParameters(
66 this->m_face_indicator_prefix + "temperature_amplitude");
67 m_period = this->m_sim->m_simulation_config.getDoubleParameters(
68 this->m_face_indicator_prefix + "period");
69 }
70 catch (const BadInput&)
71 {
72 std::cerr << "[BCSinusoidalTemperature]: Couldn't find amplitude and/or period value in "
73 "simulation "
74 "config under: "
75 << this->m_face_indicator_prefix << "temperature_amplitude / "
76 << this->m_face_indicator_prefix << "period.";
77 throw BadInput(static_cast<std::string>("[BCSinusoidalTemperature]: Couldn't find "
78 "amplitude and/or period value in simulation "
79 "config under: ")
80 + this->m_face_indicator_prefix
81 + static_cast<std::string>("temperature_amplitude / ")
82 + this->m_face_indicator_prefix + static_cast<std::string>("period."));
83 }
84 try
85 {
86 m_dt = this->m_sim->m_simulation_config.getDoubleParameters("time_delta");
87 }
88 catch (const BadInput& e)
89 {
90 std::cerr << "[BCSinusoidalTemperature]: " << e.what() << '\n';
91 throw BadInput(static_cast<std::string>("[BCSinusoidalTemperature]: ")
92 + static_cast<std::string>(e.what()));
93 }
94}
95
102template <typename T>
105 std::valarray<T>& forcing_vector)
106{
107 for (int i{0}; i < this->m_boundary_points.size(); i++)
108 {
109 std::vector<std::reference_wrapper<T>> temp_cap_mat{};
110 std::vector<std::reference_wrapper<T>> temp_stiff_mat{};
111 for (int j{0}; j < this->m_connected_points[i].size(); j++)
112 {
113 temp_cap_mat.emplace_back(
114 capacitance_matrix(this->m_boundary_points[i], this->m_connected_points[i][j]));
115 temp_stiff_mat.emplace_back(
116 stiffness_matrix(this->m_boundary_points[i], this->m_connected_points[i][j]));
117 }
118 this->m_capacitance_matrix_elements.emplace_back(temp_cap_mat);
119 this->m_stiffness_matrix_elements.emplace_back(temp_stiff_mat);
120 // These extra values are needed for dirichlet boundary conditions in the FEM scheme
121 this->m_forcing_vector_elements.emplace_back(forcing_vector[this->m_boundary_points[i]]);
122 m_capacitance_extra_val.emplace_back(
123 capacitance_matrix(this->m_boundary_points[i] + 1, this->m_boundary_points[i]));
124 m_stiffness_extra_val.emplace_back(
125 stiffness_matrix(this->m_boundary_points[i] + 1, this->m_boundary_points[i]));
126 m_forcing_extra_val.emplace_back(forcing_vector[this->m_boundary_points[i] + 1]);
127 }
128}
129
133template <typename T>
135{
136 for (int i{0}; i < this->m_boundary_points.size(); i++)
137 {
138 for (auto& val : this->m_capacitance_matrix_elements[i])
139 {
140 val *= 0.0;
141 }
142 for (auto& val : this->m_stiffness_matrix_elements[i])
143 {
144 val *= 0.0;
145 }
146 // Set almost everything to 0, so that the top equation in the matrix looks like T_n+1 * 1 =
147 // T_new.
148 this->m_stiffness_matrix_elements[i][0] += 1.0;
149 this->m_forcing_vector_elements[i] *= 0.0;
150 T st_mat_val{m_stiffness_extra_val[i]};
151 T ca_mat_val{m_capacitance_extra_val[i]};
152 m_stiffness_extra_val[i] *= 0.0;
153 m_capacitance_extra_val[i] *= 0.0;
154 // Calculate the temperature for this and the previous time step. The first is used for the
155 // top equation and the other for the second equation
157 m_base_temperature
158 - m_temperature_amplitude
159 * std::sin(2 * std::numbers::pi * (this->m_sim->time_step - 1) * m_dt
160 / m_period)};
162 m_base_temperature
163 - m_temperature_amplitude
164 * std::sin(2 * std::numbers::pi * (this->m_sim->time_step * m_dt) / m_period)};
165 this->m_forcing_vector_elements[i] += temperature;
166 m_forcing_extra_val[i] -= (st_mat_val * temperature + ca_mat_val * temperature / m_dt
168 // this->m_sim->forcing_vector[1] -= (st_mat_val * temperature * dt + 0.0 * ca_mat_val *
169 // temperature);
170 }
171}
172
173#endif
Concrete implementation of a sinusoidally varying temperature boundary condition in 1D.
Definition BCSinusoidalTemperature.h:19
void writeBoundaryCondition() override
Actual implementation of the boundary condition.
Definition BCSinusoidalTemperature.h:134
void getReferenceToElements(GenericMatrix< T > &capacitance_matrix, GenericMatrix< T > &stiffness_matrix, std::valarray< T > &forcing_vector) override
Sets up a referrence_wrapper vector to the elements within the matrix object. This adds a bit of pre-...
Definition BCSinusoidalTemperature.h:103
BCSinusoidalTemperature(SimulationClassBase< T > *sim, std::vector< int > boundary_points, std::vector< std::vector< int > > connected_points, int facet_nr, T area, std::string face_prefix)
Constructor for a BCSinusoidalTemperature object.
Definition BCSinusoidalTemperature.h:54
~BCSinusoidalTemperature() override=default
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
Boundary condition abstract base class for the finite element method. All boundary condition implemen...
Definition GenericBoundaryCondition.h:18
std::pair< int, int > size() const
Function that returns the size of the matrix as a pair in (rows, columns) format.
Definition GenericMatrix.h:120