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/solid_mechanics/crystal_plasticity/PowerLawSlipRule.h"
26 : #include "neml2/models/solid_mechanics/crystal_plasticity/SlipRule.h"
27 : #include "neml2/tensors/Scalar.h"
28 : #include "neml2/tensors/functions/pow.h"
29 : #include "neml2/tensors/functions/abs.h"
30 : #include "neml2/tensors/functions/diag_embed.h"
31 : #include "neml2/tensors/functions/log.h"
32 : #include "neml2/tensors/functions/abs.h"
33 :
34 : namespace neml2
35 : {
36 : register_NEML2_object(PowerLawSlipRule);
37 :
38 : OptionSet
39 2 : PowerLawSlipRule::expected_options()
40 : {
41 2 : OptionSet options = SlipRule::expected_options();
42 2 : options.doc() =
43 : "Power law slip rule defined as \\f$ \\dot{\\gamma}_i = \\dot{\\gamma}_0 \\left| "
44 : "\\frac{\\tau_i}{\\hat{\\tau}_i} \\right|^{n-1} \\frac{\\tau_i}{\\hat{\\tau}_i} \\f$ with "
45 : "\\f$ \\dot{\\gamma}_i \\f$ the slip rate on system \\f$ i \\f$, \\f$ \\tau_i \\f$ the "
46 : "resolved shear, \\f$ \\hat{\\tau}_i \\f$ the slip system strength, \\f$ n \\f$ the rate "
47 2 : "senstivity, and \\f$ \\dot{\\gamma}_0 \\f$ a reference slip rate.";
48 :
49 4 : options.set_parameter<TensorName<Scalar>>("gamma0");
50 4 : options.set("gamma0").doc() = "Reference slip rate";
51 :
52 4 : options.set_parameter<TensorName<Scalar>>("n");
53 2 : options.set("n").doc() = "Rate sensitivity exponent";
54 :
55 2 : return options;
56 0 : }
57 :
58 3 : PowerLawSlipRule::PowerLawSlipRule(const OptionSet & options)
59 : : SlipRule(options),
60 9 : _gamma0(declare_parameter<Scalar>("gamma0", "gamma0", true)),
61 15 : _n(declare_parameter<Scalar>("n", "n", true))
62 : {
63 3 : }
64 :
65 : void
66 6 : PowerLawSlipRule::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
67 : {
68 6 : const auto D = utils::broadcast_batch_dim(_rss, _tau, _gamma0, _n);
69 :
70 6 : if (out)
71 5 : _g = _gamma0 * pow(abs(_rss / _tau), _n - 1.0) * _rss / _tau;
72 :
73 6 : if (dout_din)
74 : {
75 3 : if (_rss.is_dependent())
76 6 : _g.d(_rss) =
77 9 : Tensor(batch_diag_embed(_gamma0 * _n * pow(abs(_rss / _tau), _n - 1.0) / _tau), D);
78 :
79 3 : if (_tau.is_dependent())
80 6 : _g.d(_tau) = Tensor(batch_diag_embed(-_n * _gamma0 * _rss * pow(abs(_rss.value()), _n - 1.0) /
81 6 : pow(Scalar(_tau), _n + 1)),
82 3 : D);
83 :
84 9 : if (const auto * const gamma0 = nl_param("gamma0"))
85 1 : _g.d(*gamma0) = Tensor(pow(abs(_rss / _tau), _n - 1.0) * _rss / _tau, D);
86 :
87 9 : if (const auto * const n = nl_param("n"))
88 2 : _g.d(*n) = Tensor(
89 3 : _gamma0 * log(abs(_rss / _tau)) * pow(abs(_rss / _tau), _n - 1.0) * _rss / _tau, D);
90 : }
91 6 : }
92 : } // namespace neml2
|