NEML2 1.4.0
Loading...
Searching...
No Matches
PowerLawSlipRule.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/crystal_plasticity/PowerLawSlipRule.h"
26#include "neml2/models/solid_mechanics/crystal_plasticity/SlipRule.h"
27
28namespace neml2
29{
30register_NEML2_object(PowerLawSlipRule);
31
34{
36 options.doc() =
37 "Power law slip rule defined as \\f$ \\dot{\\gamma}_i = \\dot{\\gamma}_0 \\left| "
38 "\\frac{\\tau_i}{\\hat{\\tau}_i} \\right|^{n-1} \\frac{\\tau_i}{\\hat{\\tau}_i} \\f$ with "
39 "\\f$ \\dot{\\gamma}_i \\f$ the slip rate on system \\f$ i \\f$, \\f$ \\tau_i \\f$ the "
40 "resolved shear, \\f$ \\hat{\\tau}_i \\f$ the slip system strength, \\f$ n \\f$ the rate "
41 "senstivity, and \\f$ \\dot{\\gamma}_0 \\f$ a reference slip rate.";
42
43 options.set<CrossRef<Scalar>>("gamma0");
44 options.set("gamma0").doc() = "Reference slip rate";
45
46 options.set<CrossRef<Scalar>>("n");
47 options.set("n").doc() = "Rate sensitivity exponent";
48
49 return options;
50}
51
53 : SlipRule(options),
54 _gamma0(declare_parameter<Scalar>("gamma0", "gamma0")),
55 _n(declare_parameter<Scalar>("n", "n"))
56{
57}
58
59void
61{
62 neml_assert_dbg(!d2out_din2, "Second derivative not implemented.");
63
64 // Grab the input
65 const auto rss = Scalar(_rss, batch_dim() + 1);
66 const auto tau = Scalar(_tau, batch_dim() + 1);
67
68 if (out)
69 _g = BatchTensor(_gamma0 * math::pow(abs(rss / tau), _n - 1.0) * rss / tau, batch_dim());
70
71 if (dout_din)
72 {
73 _g.d(_rss) = BatchTensor(
75 batch_dim());
76 _g.d(_tau) =
78 math::pow(tau, _n + 1)),
79 batch_dim());
80 }
81}
82} // namespace neml2
Definition BatchTensor.h:32
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
TorchSize batch_dim() const
This model's batch dim.
Definition Model.h:110
const torch::TensorOptions & options() const
This model's tensor options.
Definition Model.h:116
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
Power law slip rate of the form .
Definition PowerLawSlipRule.h:33
PowerLawSlipRule(const OptionSet &options)
Definition PowerLawSlipRule.cxx:52
const Scalar & _gamma0
Reference slip rate.
Definition PowerLawSlipRule.h:44
const Scalar & _n
Rate sensitivity.
Definition PowerLawSlipRule.h:47
static OptionSet expected_options()
Definition PowerLawSlipRule.cxx:33
void set_value(bool out, bool dout_din, bool d2out_din2) override
Set the slip rates and derivatives.
Definition PowerLawSlipRule.cxx:60
The (logical) scalar.
Definition Scalar.h:38
Parent class of slip rules, mapping from resolved shear and internal state to slip rates.
Definition SlipRule.h:38
const Variable< BatchTensor > & _rss
Resolved shears.
Definition SlipRule.h:52
const Variable< BatchTensor > & _tau
Slip strengths, mapped from internal variables.
Definition SlipRule.h:55
Variable< BatchTensor > & _g
Slip rates.
Definition SlipRule.h:49
static OptionSet expected_options()
Definition SlipRule.cxx:34
Derived batch_diag_embed(const Derived &a, TorchSize offset=0, TorchSize d1=-2, TorchSize d2=-1)
Definition BatchTensorBase.h:475
Derived pow(const Derived &a, const Real &n)
Definition BatchTensorBase.h:332
Definition CrossRef.cxx:32
void neml_assert_dbg(bool assertion, Args &&... args)
Definition error.h:85
Scalar abs(const Scalar &a)
Absolute value.
Definition Scalar.cxx:48