NEML2 1.4.0
Loading...
Searching...
No Matches
KocksMeckingFlowViscosity.cxx
1// Copyright 2023, 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/solid_mechanics/KocksMeckingFlowViscosity.h"
26
27namespace neml2
28{
29register_NEML2_object(KocksMeckingFlowViscosity);
30
33{
35 options.doc() =
36 "Calculates the temperature-dependent flow viscosity for a Perzyna-type model using the "
37 "Kocks-Mecking model. The value is \\f$ \\eta = \\exp{B} \\mu "
38 "\\dot{\\varepsilon}_0^\\frac{-k T A}{\\mu b^3} \\f$ with \\f$ \\mu "
39 "\\f$ the shear modulus, \\f$ \\dot{\\varepsilon}_0 \\f$ a reference strain rate, \\f$ b "
40 "\\f$ the Burgers vector, "
41 "\\f$ k\\f$ the Boltzmann constant, "
42 "\\f$ T \\f$ absolute temperature, \\f$ A \\f$ the Kocks-Mecking slope parameter, and \\f$ B "
43 "\\f$ the Kocks-Mecking intercept parameter.";
44
45 options.set<CrossRef<Scalar>>("A");
46 options.set("A").doc() = "The Kocks-Mecking slope parameter";
47 options.set<CrossRef<Scalar>>("B");
48 options.set("B").doc() = "The Kocks-Mecking intercept parameter";
49 options.set<CrossRef<Scalar>>("shear_modulus");
50 options.set("shear_modulus").doc() = "The shear modulus";
51
52 options.set<Real>("eps0");
53 options.set("eps0").doc() = "The reference strain rate";
54
55 options.set<Real>("k");
56 options.set("k").doc() = "Boltzmann constant";
57 options.set<Real>("b");
58 options.set("b").doc() = "The Burgers vector";
59
60 options.set<VariableName>("temperature") = VariableName("forces", "T");
61 options.set("temperature").doc() = "Absolute temperature";
62
63 return options;
64}
65
67 : NonlinearParameter<Scalar>(options),
68 _A(declare_parameter<Scalar>("A", "A")),
69 _B(declare_parameter<Scalar>("B", "B")),
70 _mu(declare_parameter<Scalar>("shear_modulus", "shear_modulus")),
71 _eps0(options.get<Real>("eps0")),
72 _k(options.get<Real>("k")),
73 _b3(options.get<Real>("b") * options.get<Real>("b") * options.get<Real>("b")),
74 _T(declare_input_variable<Scalar>("temperature"))
75{
76}
77
78void
80{
81 auto post = math::pow(_eps0, _k * _T * _A / (_mu * _b3));
82
83 if (out)
84 _p = math::exp(_B) * _mu * post;
85
86 if (dout_din)
87 {
88 _p.d(_T) = _A * math::exp(_B) * _k * std::log(_eps0) * post / _b3;
89
90 if (const auto A = nl_param("A"))
91 _p.d(*A) = math::exp(_B) * _k * _T * std::log(_eps0) * post / _b3;
92
93 if (const auto B = nl_param("B"))
94 _p.d(*B) = math::exp(_B) * _mu * post;
95
96 if (const auto mu = nl_param("mu"))
97 _p.d(*mu) = math::exp(_B) * post * (_b3 * _mu - _A * _k * _T * std::log(_eps0)) / (_b3 * _mu);
98 }
99
100 if (d2out_din2)
101 {
102 // T
103 _p.d(_T, _T) = math::pow(_A * _k * std::log(_eps0) / _b3, 2.0) * math::exp(_B) * post / _mu;
104
105 if (const auto A = nl_param("A"))
106 _p.d(_T, *A) = math::exp(_B) * _k * std::log(_eps0) * post * (_A * _k * _T + _b3 * _mu) /
107 (_b3 * _b3 * _mu);
108
109 if (const auto B = nl_param("B"))
110 _p.d(_T, *B) = _A * math::exp(_B) * _k * std::log(_eps0) * post / _b3;
111
112 if (const auto mu = nl_param("mu"))
113 _p.d(_T, *mu) =
114 -math::pow(_A * _k * std::log(_eps0) / (_b3 * _mu), 2.0) * math::exp(_B) * _T * post;
115
116 // A
117 if (const auto A = nl_param("A"))
118 {
119 _p.d(*A, _T) = math::exp(_B) * _k * std::log(_eps0) * post * (_A * _k * _T + _b3 * _mu) /
120 (_b3 * _b3 * _mu);
121
122 _p.d(*A, *A) = math::exp(_B) * math::pow(_k * _T * std::log(_eps0) / _b3, 2.0) * post / _mu;
123
124 if (const auto B = nl_param("B"))
125 _p.d(*A, *B) = math::exp(_B) * _k * _T * std::log(_eps0) * post / _b3;
126
127 if (const auto mu = nl_param("mu"))
128 _p.d(*A, *mu) =
129 -_A * math::exp(_B) * math::pow(_k * _T * std::log(_eps0) / (_b3 * _mu), 2.0) * post;
130 }
131
132 // B
133 if (const auto B = nl_param("B"))
134 {
135 _p.d(*B, _T) = _A * math::exp(_B) * _k * std::log(_eps0) * post / _b3;
136
137 if (const auto A = nl_param("A"))
138 _p.d(*B, *A) = math::exp(_B) * _k * _T * std::log(_eps0) * post / _b3;
139
140 _p.d(*B, *B) = math::exp(_B) * _mu * post;
141
142 if (const auto mu = nl_param("mu"))
143 _p.d(*B, *mu) =
144 math::exp(_B) * post * (_b3 * _mu - _A * _k * _T * std::log(_eps0)) / (_b3 * _mu);
145 }
146
147 // mu
148 if (const auto mu = nl_param("mu"))
149 {
150 _p.d(*mu, _T) =
151 -math::exp(_B) * math::pow(_A * _k * std::log(_eps0) / (_b3 * _mu), 2.0) * _T * post;
152
153 if (const auto A = nl_param("A)"))
154 _p.d(*mu, *A) =
155 -_A * math::exp(_B) * math::pow(_k * _T * std::log(_eps0) / (_b3 * _mu), 2.0) * post;
156
157 if (const auto B = nl_param("B"))
158 _p.d(*mu, *B) =
159 math::exp(_B) * post * (_b3 * _mu - _A * _k * _T * std::log(_eps0)) / (_b3 * _mu);
160
161 _p.d(*mu, *mu) = -math::pow(_A * _k * _T * std::log(_eps0) / (_b3 * _mu), 2.0) *
162 math::exp(_B) * post / _mu;
163 }
164 }
165}
166} // namespace neml2
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
A scalar-valued parameter defined by (mu0 - D/(exp(T0/T)-1)) * exp(_C)
Definition KocksMeckingFlowViscosity.h:35
const Real _k
The Boltzmann constant.
Definition KocksMeckingFlowViscosity.h:57
KocksMeckingFlowViscosity(const OptionSet &options)
Definition KocksMeckingFlowViscosity.cxx:66
const Scalar & _mu
The shear modulus.
Definition KocksMeckingFlowViscosity.h:51
const Variable< Scalar > & _T
The temperature.
Definition KocksMeckingFlowViscosity.h:63
const Scalar & _A
The Kocks-Mecking slope.
Definition KocksMeckingFlowViscosity.h:45
const Scalar & _B
The Kocks-Mecking intercept.
Definition KocksMeckingFlowViscosity.h:48
static OptionSet expected_options()
Definition KocksMeckingFlowViscosity.cxx:32
const Real _b3
Burgers vector cubed.
Definition KocksMeckingFlowViscosity.h:60
void set_value(bool out, bool dout_din, bool d2out_din2) override
The map between input -> output, and optionally its derivatives.
Definition KocksMeckingFlowViscosity.cxx:79
const Real _eps0
The reference strain rate.
Definition KocksMeckingFlowViscosity.h:54
The accessor containing all the information needed to access an item in a LabeledAxis.
Definition LabeledAxisAccessor.h:44
const torch::TensorOptions & options() const
This model's tensor options.
Definition Model.h:116
The base class for nonlinear parameters.
Definition NonlinearParameter.h:51
Variable< Scalar > & _p
The nonlinear parameter.
Definition NonlinearParameter.h:62
static OptionSet expected_options()
Definition NonlinearParameter.cxx:31
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
const VariableBase * nl_param(const std::string &) const
Query the existence of a nonlinear parameter.
Definition ParameterStore.cxx:56
The (logical) scalar.
Definition Scalar.h:38
Derivative d(const VariableBase &x)
Create a wrapper representing the derivative dy/dx.
Definition Variable.cxx:102
Derived exp(const Derived &a)
Definition BatchTensorBase.h:448
Derived pow(const Derived &a, const Real &n)
Definition BatchTensorBase.h:332
Definition CrossRef.cxx:32
double Real
Definition types.h:31
LabeledAxisAccessor VariableName
Definition Variable.h:35