Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
electric_conductivity_model.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2025-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_electric_conductivity_model_h
5#define lethe_electric_conductivity_model_h
6
7#include <core/parameters.h>
9
10#include <algorithm>
11
12/**
13 * @brief Abstract class that allows to calculate the
14 * electric conductivity on each quadrature point.
15 */
17{
18public:
19 /**
20 * @brief Instantiates and returns a pointer to an ElectricConductivityModel
21 * object by casting it to the proper child class
22 *
23 * @param[in] material_properties Parameters for a material
24 */
25 static std::shared_ptr<ElectricConductivityModel>
26 model_cast(const Parameters::Material &material_properties);
27};
28
29
30/**
31 * @brief Constant electric conductivity.
32 */
34{
35public:
36 /**
37 * @brief Default constructor
38 */
39 ConstantElectricConductivity(const double p_electric_conductivity)
40 : electric_conductivity(p_electric_conductivity)
41 {}
42
43 /**
44 * @brief Calculates the value of the electric conductivity
45 * @param[in] field_values Values of the various fields on which the electric
46 * conductivity depends.
47 * @return Value of the electric conductivity calculated with the `field_values`.
48 */
49 double
50 value([[maybe_unused]] const std::map<field, double> &field_values) override
51 {
53 };
54
55 /**
56 * @brief Calculates, in a vector, values of of electric conductivities
57 * @param[in] field_vectors Vector of fields on which the electric
58 * conductivities depend
59 * @param[in,out] property_vector Values of the electric conductivities
60 */
61 void
63 [[maybe_unused]] const std::map<field, std::vector<double>> &field_vectors,
64 std::vector<double> &property_vector) override
65 {
66 property_vector.assign(property_vector.size(), electric_conductivity);
67 }
68
69 /**
70 * @brief Calculates the jacobian (the partial derivative) of the electric conductivity with respect to a field
71 * @param[in] field_values Value of the various fields on which the property
72 * may depend.
73 * @param[in] id Identifier of the field with respect to which the jacobian
74 * should be calculated
75 * @return Value of the partial derivative of the electric conductivity with respect to the field.
76 */
77
78 double
79 jacobian(const std::map<field, double> & /*field_values*/,
80 field /*id*/) override
81 {
82 return 0;
83 };
84
85 /**
86 * @brief Calculates the derivatives of the electric conductivity with respect to a field
87 * @param[in] field_vectors Vector for the values of the fields used to
88 * evaluate the property
89 * @param[in] id Identifier of the field with respect to which a derivative
90 * should be calculated
91 * @param[in,out] jacobian_vector Vector of the values of the derivatives of
92 * the electric conductivity with respect to the specified field
93 */
94
95 void
97 const std::map<field, std::vector<double>> & /*field_vectors*/,
98 [[maybe_unused]] const field id,
99 std::vector<double> &jacobian_vector) override
100 {
101 std::ranges::fill(jacobian_vector, 0);
102 };
103
104private:
106};
107
108/**
109 * @brief Polynomial electric conductivity.
110 */
112{
113public:
114 /**
115 * @brief Default constructor
116 */
118 const std::vector<double> &p_electric_conductivity_polynomial_coefficients)
120 p_electric_conductivity_polynomial_coefficients)
121 {
123 }
124
125 /**
126 * @brief Calculates the value of the electric conductivity
127 * @param[in] field_values Values of the various fields on which the electric
128 * conductivity depends.
129 * @return Value of the electric conductivity calculated with the `field_values`.
130 */
131 double
132 value(const std::map<field, double> &field_values) override
133 {
134 AssertThrow(field_values.contains(field::temperature),
135 PhysicialPropertyModelFieldUndefined(
136 "PolynomialElectricConductivity", "temperature"));
137 const double temperature = field_values.at(field::temperature);
138
139 // Compute the polynomial power using Horner's method for efficiency , i.e.
140 // P(x) = (...((a_n * x + a_{n-1}) * x + a_{n-2}) * x + ... + a_1) * x + a_0
141 double electric_conductivity = 0.0;
142 for (const auto &coefficient :
144 {
145 electric_conductivity =
146 coefficient + temperature * electric_conductivity;
147 }
148
149 return electric_conductivity;
150 }
151
152 /**
153 * @brief Calculates, in a vector, values of of electric conductivities
154 * @param[in] field_vectors Vector of fields on which the electric
155 * conductivities depend
156 * @param[in,out] property_vector Values of the electric conductivities
157 */
158 void
159 vector_value(const std::map<field, std::vector<double>> &field_vectors,
160 std::vector<double> &property_vector) override
161 {
162 AssertThrow(field_vectors.find(field::temperature) != field_vectors.end(),
163 PhysicialPropertyModelFieldUndefined(
164 "PolynomialElectricConductivity", "temperature"));
165
166 const std::vector<double> &temperature =
167 field_vectors.at(field::temperature);
168 for (unsigned int i = 0; i < property_vector.size(); ++i)
169 {
170 // Compute the polynomial power using Horner's method for efficiency
171 // , i.e. P(x) = (...((a_n * x + a_{n-1}) * x + a_{n-2}) * x + ... +
172 // a_1) * x + a_0
173 double electric_conductivity = 0.0;
174 for (const auto &coefficient :
176 {
177 electric_conductivity =
178 coefficient + temperature[i] * electric_conductivity;
179 }
180 property_vector[i] = electric_conductivity;
181 }
182 }
183
184 /**
185 * @brief Calculates the jacobian (the partial derivative) of the electric conductivity with respect to a field
186 * @param[in] field_values Value of the various fields on which the property
187 * may depend.
188 * @param[in] id Identifier of the field with respect to which the jacobian
189 * should be calculated
190 * @return Value of the partial derivative of the electric conductivity with respect to the field.
191 *
192 * @remark The jacobian is only implemented with respect to the temperature
193 * field.
194 */
195 double
196 jacobian(const std::map<field, double> &field_values, const field id) override
197 {
198 // The derivative can only be taken with respect to the temperature field,
199 // since the polynomial is a function of temperature.
200 if (id == field::temperature)
201 {
202 AssertThrow(field_values.find(field::temperature) != field_values.end(),
203 PhysicialPropertyModelFieldUndefined(
204 "PolynomialElectricConductivity", "temperature"));
205
206 // Use a Horner accumulator to evaluate the derivative directly.
207 unsigned int polynomial_order =
209 double electric_conductivity_derivative =
211
212 double temperature = field_values.at(field::temperature);
213
214 for (unsigned int i = 1; i < polynomial_order; ++i)
215 {
216 electric_conductivity_derivative =
217 electric_conductivity_derivative * temperature +
218 (polynomial_order - i) *
220 }
221
222 return electric_conductivity_derivative;
223 }
224 else
225 return 0;
226 }
227
228 /**
229 * @brief Calculates the derivatives of the electric conductivity with respect to a field
230 * @param[in] field_vectors Vector for the values of the fields used to
231 * evaluate the property
232 * @param[in] id Identifier of the field with respect to which a derivative
233 * should be calculated
234 * @param[in,out] jacobian_vector Vector of the values of the derivatives of
235 * the electric conductivity with respect to the specified field
236 *
237 * @remark The vector_jacobian is only implemented with respect to the
238 * temperature field.
239 */
240 void
241 vector_jacobian(const std::map<field, std::vector<double>> &field_vectors,
242 const field id,
243 std::vector<double> &jacobian_vector) override
244 {
245 if (id == field::temperature)
246 {
247 AssertThrow(
248 field_vectors.find(field::temperature) != field_vectors.end(),
249 PhysicialPropertyModelFieldUndefined("PolynomialElectricConductivity",
250 "temperature"));
251
252 const std::vector<double> &temperature =
253 field_vectors.at(field::temperature);
254 for (unsigned int i = 0; i < jacobian_vector.size(); ++i)
255 {
256 // Use a Horner accumulator to evaluate the derivative directly.
257 unsigned int polynomial_order =
259 double electric_conductivity_derivative =
260 polynomial_order *
262 for (unsigned int j = 1; j < polynomial_order; ++j)
263 {
264 electric_conductivity_derivative =
265 electric_conductivity_derivative * temperature[i] +
266 (polynomial_order - j) *
268 }
269
270 jacobian_vector[i] = electric_conductivity_derivative;
271 }
272 }
273 else
274 {
275 std::ranges::fill(jacobian_vector, 0);
276 }
277 }
278
279private:
281};
282
283#endif
ConstantElectricConductivity(const double p_electric_conductivity)
Default constructor.
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
Calculates, in a vector, values of of electric conductivities.
void vector_jacobian(const std::map< field, std::vector< double > > &, const field id, std::vector< double > &jacobian_vector) override
Calculates the derivatives of the electric conductivity with respect to a field.
double value(const std::map< field, double > &field_values) override
Calculates the value of the electric conductivity.
double jacobian(const std::map< field, double > &, field) override
Calculates the jacobian (the partial derivative) of the electric conductivity with respect to a field...
Abstract class that allows to calculate the electric conductivity on each quadrature point.
static std::shared_ptr< ElectricConductivityModel > model_cast(const Parameters::Material &material_properties)
Instantiates and returns a pointer to an ElectricConductivityModel object by casting it to the proper...
Material - Class that defines the physical property of a material. Generally a material will be a flu...
Definition parameters.h:594
PhysicalPropertyModel()
Default constructor. Set the model_depends_on to false for all variables.
std::map< field, bool > model_depends_on
PolynomialElectricConductivity(const std::vector< double > &p_electric_conductivity_polynomial_coefficients)
Default constructor.
double value(const std::map< field, double > &field_values) override
Calculates the value of the electric conductivity.
const std::vector< double > electric_conductivity_polynomial_coefficients
double jacobian(const std::map< field, double > &field_values, const field id) override
Calculates the jacobian (the partial derivative) of the electric conductivity with respect to a field...
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
Calculates, in a vector, values of of electric conductivities.
void vector_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector) override
Calculates the derivatives of the electric conductivity with respect to a field.
@ temperature
Temperature scalar field from heat transfer.