Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
electric_permittivity_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_permittivity_model_h
5#define lethe_electric_permittivity_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 permittivity real and imaginary part on each quadrature point.
15 */
17{
18public:
19 /**
20 * @brief Instantiates and returns a pointer to a ElectricPermittivityModel object by casting it to
21 * the proper child class for the real part of the permittivity.
22 *
23 * @param[in] material_properties Parameters for a material
24 */
25 static std::shared_ptr<ElectricPermittivityModel>
26 model_cast_real(const Parameters::Material &material_properties);
27
28 /**
29 * @brief Instantiates and returns a pointer to a ElectricPermittivityModel object by casting it to
30 * the proper child class for the imaginary part of the permittivity.
31 *
32 * @param[in] material_properties Parameters for a material
33 */
34 static std::shared_ptr<ElectricPermittivityModel>
35 model_cast_imag(const Parameters::Material &material_properties);
36};
37
38
39/**
40 * @brief Constant electric permittivity.
41 */
43{
44public:
45 /**
46 * @brief Default constructor
47 */
48 ConstantElectricPermittivity(const double p_electric_permittivity)
49 : electric_permittivity(p_electric_permittivity)
50 {}
51
52 /**
53 * @brief Calculates the value of the electric permittivity
54 * @param[in] field_values Value of the various fields on which the electric
55 * permittivity depends.
56 * @return Value of the electric permittivity calculated with the `field_values`.
57 */
58 double
59 value([[maybe_unused]] const std::map<field, double> &field_values) override
60 {
62 };
63
64 /**
65 * @brief Calculates, in a vector, values of electric permittivities
66 * @param[in] field_vectors Vector of properties on which the electric
67 * permittivities depend
68 * @param[in,out] property_vector Values of the electric permittivities
69 */
70 void
72 [[maybe_unused]] const std::map<field, std::vector<double>> &field_vectors,
73 std::vector<double> &property_vector) override
74 {
75 property_vector.assign(property_vector.size(), electric_permittivity);
76 }
77
78 /**
79 * @brief Calculates the jacobian (the partial derivative) of the electric permittivity with respect to a field
80 * @param[in] field_values Value of the various fields on which the property
81 * may depend.
82 * @param[in] id Identifier of the field with respect to which the jacobian
83 * should be calculated
84 * @return Value of the partial derivative of the electric permittivity with respect to the specified field.
85 */
86
87 double
88 jacobian(const std::map<field, double> & /*field_values*/,
89 field /*id*/) override
90 {
91 return 0;
92 };
93
94 /**
95 * @brief Calculates, in a vector, the derivatives of the electric permittivity with respect to a field
96 * @param[in] field_vectors Vector for the values of the fields used to
97 * evaluate the property
98 * @param[in] id Identifier of the field with respect to which a derivative
99 * should be calculated
100 * @param[in,out] jacobian_vector Vector of values of the derivatives of the
101 * electric permittivity with respect to the specified field
102 */
103
104 void
106 const std::map<field, std::vector<double>> & /*field_vectors*/,
107 [[maybe_unused]] const field id,
108 std::vector<double> &jacobian_vector) override
109 {
110 std::ranges::fill(jacobian_vector, 0);
111 };
112
113private:
115};
116
117/**
118 * @brief Polynomial electric permittivity.
119 */
121{
122public:
123 /**
124 * @brief Default constructor
125 */
127 const std::vector<double> &p_electric_permittivity_polynomial_coefficients)
129 p_electric_permittivity_polynomial_coefficients)
130 {
132 }
133
134 /**
135 * @brief Calculates the value of the electric permittivity
136 * @param[in] field_values Value of the various fields on which the electric
137 * permittivity depends.
138 * @return Value of the electric permittivity calculated with the `field_values`.
139 */
140 double
141 value(const std::map<field, double> &field_values) override
142 {
143 AssertThrow(field_values.contains(field::temperature),
144 PhysicialPropertyModelFieldUndefined(
145 "PolynomialElectricPermittivity", "temperature"));
146 const double temperature = field_values.at(field::temperature);
147
148 // Compute the polynomial power using Horner's method for efficiency , i.e.
149 // P(x) = (...((a_n * x + a_{n-1}) * x + a_{n-2}) * x + ... + a_1) * x + a_0
150 double electric_permittivity = 0.0;
151 for (const auto &coefficient :
153 {
155 coefficient + temperature * electric_permittivity;
156 }
157
159 }
160
161 /**
162 * @brief Calculates, in a vector, values of electric permittivities
163 * @param[in] field_vectors Vector of properties on which the electric
164 * permittivities depend
165 * @param[in,out] property_vector Values of the electric permittivities
166 */
167 void
168 vector_value(const std::map<field, std::vector<double>> &field_vectors,
169 std::vector<double> &property_vector) override
170 {
171 AssertThrow(field_vectors.find(field::temperature) != field_vectors.end(),
172 PhysicialPropertyModelFieldUndefined(
173 "PolynomialElectricPermittivity", "temperature"));
174
175 const std::vector<double> &temperature =
176 field_vectors.at(field::temperature);
177 for (unsigned int i = 0; i < property_vector.size(); ++i)
178 {
179 // Compute the polynomial power using Horner's method for efficiency
180 // , i.e. P(x) = (...((a_n * x + a_{n-1}) * x + a_{n-2}) * x + ... +
181 // a_1) * x + a_0
182 double electric_permittivity = 0.0;
183 for (const auto &coefficient :
185 {
187 coefficient + temperature[i] * electric_permittivity;
188 }
189 property_vector[i] = electric_permittivity;
190 }
191 }
192
193 /**
194 * @brief Calculates the jacobian (the partial derivative) of the electric permittivity with respect to a field
195 * @param[in] field_values Value of the various fields on which the property
196 * may depend.
197 * @param[in] id Identifier of the field with respect to which the jacobian
198 * should be calculated
199 * @return Value of the partial derivative of the electric permittivity with respect to the specified field.
200 *
201 * @remark The jacobian is only implemented with respect to the temperature
202 * field.
203 */
204 double
205 jacobian(const std::map<field, double> &field_values, const field id) override
206 {
207 // The derivative can only be taken with respect to the temperature field,
208 // since the polynomial is a function of temperature.
209 if (id == field::temperature)
210 {
211 AssertThrow(field_values.find(field::temperature) != field_values.end(),
212 PhysicialPropertyModelFieldUndefined(
213 "PolynomialElectricPermittivity", "temperature"));
214
215 // Use a Horner accumulator to evaluate the derivative directly.
216 unsigned int polynomial_order =
218 double electric_permittivity_derivative =
220
221 double temperature = field_values.at(field::temperature);
222
223 for (unsigned int i = 1; i < polynomial_order; ++i)
224 {
225 electric_permittivity_derivative =
226 electric_permittivity_derivative * temperature +
227 (polynomial_order - i) *
229 }
230
231 return electric_permittivity_derivative;
232 }
233 else
234 return 0;
235 }
236
237 /**
238 * @brief Calculates, in a vector, the derivatives of the electric permittivity with respect to a field
239 * @param[in] field_vectors Vector for the values of the fields used to
240 * evaluate the property
241 * @param[in] id Identifier of the field with respect to which a derivative
242 * should be calculated
243 * @param[in,out] jacobian_vector Vector of values of the derivatives of the
244 * electric permittivity with respect to the specified field
245 *
246 * @remark The vector_jacobian is only implemented for the temperature field.
247 */
248 void
249 vector_jacobian(const std::map<field, std::vector<double>> &field_vectors,
250 const field id,
251 std::vector<double> &jacobian_vector) override
252 {
253 if (id == field::temperature)
254 {
255 AssertThrow(
256 field_vectors.find(field::temperature) != field_vectors.end(),
257 PhysicialPropertyModelFieldUndefined("PolynomialElectricPermittivity",
258 "temperature"));
259
260 const std::vector<double> &temperature =
261 field_vectors.at(field::temperature);
262 for (unsigned int i = 0; i < jacobian_vector.size(); ++i)
263 {
264 // Use a Horner accumulator to evaluate the derivative directly.
265 unsigned int polynomial_order =
267 double electric_permittivity_derivative =
268 polynomial_order *
270 for (unsigned int j = 1; j < polynomial_order; ++j)
271 {
272 electric_permittivity_derivative =
273 electric_permittivity_derivative * temperature[i] +
274 (polynomial_order - j) *
276 }
277
278 jacobian_vector[i] = electric_permittivity_derivative;
279 }
280 }
281 else
282 {
283 std::ranges::fill(jacobian_vector, 0);
284 }
285 }
286
287private:
289};
290
291#endif
void vector_jacobian(const std::map< field, std::vector< double > > &, const field id, std::vector< double > &jacobian_vector) override
Calculates, in a vector, the derivatives of the electric permittivity with respect to a field.
ConstantElectricPermittivity(const double p_electric_permittivity)
Default constructor.
double jacobian(const std::map< field, double > &, field) override
Calculates the jacobian (the partial derivative) of the electric permittivity 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 electric permittivities.
double value(const std::map< field, double > &field_values) override
Calculates the value of the electric permittivity.
Abstract class that allows to calculate the electric permittivity real and imaginary part on each qua...
static std::shared_ptr< ElectricPermittivityModel > model_cast_imag(const Parameters::Material &material_properties)
Instantiates and returns a pointer to a ElectricPermittivityModel object by casting it to the proper ...
static std::shared_ptr< ElectricPermittivityModel > model_cast_real(const Parameters::Material &material_properties)
Instantiates and returns a pointer to a ElectricPermittivityModel 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
const std::vector< double > electric_permittivity_polynomial_coefficients
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
Calculates, in a vector, values of electric permittivities.
PolynomialElectricPermittivity(const std::vector< double > &p_electric_permittivity_polynomial_coefficients)
Default constructor.
void vector_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector) override
Calculates, in a vector, the derivatives of the electric permittivity with respect to a field.
double value(const std::map< field, double > &field_values) override
Calculates the value of the electric permittivity.
double jacobian(const std::map< field, double > &field_values, const field id) override
Calculates the jacobian (the partial derivative) of the electric permittivity with respect to a field...
@ temperature
Temperature scalar field from heat transfer.