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/ResolvedShear.h"
26 : #include "neml2/models/crystallography/CrystalGeometry.h"
27 :
28 : #include "neml2/tensors/Scalar.h"
29 : #include "neml2/tensors/R2.h"
30 : #include "neml2/tensors/SR2.h"
31 : #include "neml2/tensors/SFFR4.h"
32 : #include "neml2/tensors/list_tensors.h"
33 :
34 : namespace neml2
35 : {
36 : register_NEML2_object(ResolvedShear);
37 :
38 : OptionSet
39 2 : ResolvedShear::expected_options()
40 : {
41 2 : OptionSet options = Model::expected_options();
42 :
43 2 : options.doc() = "Calculates the resolved shears as \\f$ \\tau_i = \\sigma : Q "
44 : "\\operatorname{sym}\\left(d_i \\otimes n_i \\right) Q^T \\f$ where \\f$ \\tau_i "
45 : "\\f$ is the resolved shear on slip system i, \\f$ \\sigma \\f$ is the Cauchy "
46 : "stress \\f$ Q \\f$ is the orientation matrix, \\f$ d_i \\f$ is the slip "
47 2 : "direction, and \\f$ n_i \\f$ is the slip system normal.";
48 :
49 6 : options.set_output("resolved_shears") = VariableName(STATE, "internal", "resolved_shears");
50 2 : options.set("resolved_shears").doc() = "The name of the resolved shears";
51 :
52 6 : options.set_input("stress") = VariableName(STATE, "internal", "cauchy_stress");
53 2 : options.set("stress").doc() = "The name of the Cauchy stress tensor";
54 :
55 6 : options.set_input("orientation") = VariableName(STATE, "orientation_matrix");
56 4 : options.set("orientation").doc() = "The name of the orientation matrix";
57 :
58 4 : options.set<std::string>("crystal_geometry_name") = "crystal_geometry";
59 4 : options.set("crystal_geometry_name").doc() =
60 2 : "The name of the data object with the crystallographic information";
61 2 : return options;
62 0 : }
63 :
64 2 : ResolvedShear::ResolvedShear(const OptionSet & options)
65 : : Model(options),
66 2 : _crystal_geometry(register_data<crystallography::CrystalGeometry>(
67 4 : options.get<std::string>("crystal_geometry_name"))),
68 2 : _rss(declare_output_variable<Scalar>("resolved_shears", _crystal_geometry.nslip())),
69 2 : _S(declare_input_variable<SR2>("stress")),
70 4 : _R(declare_input_variable<R2>("orientation"))
71 : {
72 2 : }
73 :
74 : void
75 4 : ResolvedShear::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
76 : {
77 : // Unsqueeze a batch dimension for slip systems
78 4 : const auto S = SR2(_S).batch_unsqueeze(-1);
79 4 : const auto R = R2(_R).batch_unsqueeze(-1);
80 :
81 4 : if (out)
82 4 : _rss = _crystal_geometry.M().rotate(R).inner(S);
83 :
84 4 : if (dout_din)
85 : {
86 2 : if (_S.is_dependent())
87 : {
88 2 : const auto drss_dS = _crystal_geometry.M().rotate(R);
89 2 : _rss.d(_S) = Tensor(drss_dS, drss_dS.batch_dim() - 1);
90 2 : }
91 :
92 2 : if (_R.is_dependent())
93 : {
94 2 : const auto D = utils::broadcast_batch_dim(_S, _R);
95 10 : _rss.d(_R) = Tensor(at::einsum("...ijk,...i", {_crystal_geometry.M().drotate(R), S}), D);
96 : }
97 : }
98 8 : }
99 :
100 : } // namespace neml2
|