Line data Source code
1 : // Copyright 2024, UChicago Argonne, LLC
2 : // All Rights Reserved
3 : // Software Name: NEML2 -- the New Engineering material Model Library, version 2
4 : // By: Argonne National Laboratory
5 : // OPEN SOURCE LICENSE (MIT)
6 : //
7 : // Permission is hereby granted, free of charge, to any person obtaining a copy
8 : // of this software and associated documentation files (the "Software"), to deal
9 : // in the Software without restriction, including without limitation the rights
10 : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 : // copies of the Software, and to permit persons to whom the Software is
12 : // furnished to do so, subject to the following conditions:
13 : //
14 : // The above copyright notice and this permission notice shall be included in
15 : // all copies or substantial portions of the Software.
16 : //
17 : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 : // THE SOFTWARE.
24 :
25 : #include "neml2/models/ArrheniusParameter.h"
26 : #include "neml2/tensors/functions/exp.h"
27 : #include "neml2/tensors/Scalar.h"
28 :
29 : namespace neml2
30 : {
31 : register_NEML2_object(ArrheniusParameter);
32 :
33 : OptionSet
34 2 : ArrheniusParameter::expected_options()
35 : {
36 2 : OptionSet options = Model::expected_options();
37 2 : options.doc() = "Define the variable as a function of temperature according to the Arrhenius law "
38 : "\\f$ p = p_0 \\exp \\left( -\\frac{Q}{RT} \\right) \\f$, where \\f$ p_0 \\f$ is "
39 : "the reference value, \\f$ Q \\f$ is the activation energy, \\f$ R \\f$ is the "
40 2 : "ideal gas constant, and \\f$ T \\f$ is the temperature.";
41 :
42 4 : options.set<bool>("define_second_derivatives") = true;
43 :
44 4 : options.set_parameter<TensorName<Scalar>>("reference_value");
45 4 : options.set("reference_value").doc() = "Reference value";
46 :
47 4 : options.set_parameter<TensorName<Scalar>>("activation_energy");
48 4 : options.set("activation_energy").doc() = "Activation energy";
49 :
50 4 : options.set<double>("ideal_gas_constant");
51 2 : options.set("ideal_gas_constant").doc() = "The ideal gas constant";
52 :
53 6 : options.set_input("temperature") = VariableName(FORCES, "T");
54 2 : options.set("temperature").doc() = "Temperature";
55 :
56 6 : options.set_output("parameter") = VariableName(PARAMETERS, "p");
57 2 : options.set("parameter").doc() = "The output parameter";
58 :
59 2 : return options;
60 0 : }
61 :
62 2 : ArrheniusParameter::ArrheniusParameter(const OptionSet & options)
63 : : Model(options),
64 6 : _p0(declare_parameter<Scalar>("p0", "reference_value")),
65 10 : _Q(declare_parameter<Scalar>("Q", "activation_energy")),
66 2 : _R(options.get<double>("ideal_gas_constant")),
67 2 : _T(declare_input_variable<Scalar>("temperature")),
68 4 : _p(declare_output_variable<Scalar>("parameter"))
69 : {
70 2 : }
71 :
72 : void
73 4 : ArrheniusParameter::set_value(bool out, bool dout_din, bool d2out_din2)
74 : {
75 4 : const auto p = _p0 * exp(-_Q / _R / _T);
76 :
77 4 : if (out)
78 2 : _p = p;
79 :
80 4 : if (_T.is_dependent())
81 4 : if (dout_din || d2out_din2)
82 : {
83 2 : const auto dp_dT = p * _Q / _R / _T / _T;
84 :
85 2 : if (dout_din)
86 1 : _p.d(_T) = dp_dT;
87 :
88 2 : if (d2out_din2)
89 1 : _p.d(_T, _T) = dp_dT * _Q / _R / _T / _T - 2 * p * _Q / _R / _T / _T / _T;
90 2 : }
91 4 : }
92 : } // namespace neml2
|