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/elasticity/GeneralElasticity.h"
26 : #include "neml2/tensors/SSFR5.h"
27 : #include "neml2/tensors/SSSSR8.h"
28 : #include "neml2/tensors/Tensor.h"
29 :
30 : namespace neml2
31 : {
32 : register_NEML2_object(GeneralElasticity);
33 :
34 : OptionSet
35 2 : GeneralElasticity::expected_options()
36 : {
37 2 : OptionSet options = AnisotropicElasticity::expected_options();
38 2 : options.doc() += " This verion implements a general relation using the elasticity tensor, "
39 2 : "expressed as an SSR4 object";
40 :
41 4 : options.set_parameter<TensorName<SSR4>>("elastic_stiffness_tensor");
42 2 : options.set("elastic_stiffness_tensor").doc() = "Elastic stiffness tensor";
43 :
44 2 : return options;
45 0 : }
46 :
47 5 : GeneralElasticity::GeneralElasticity(const OptionSet & options)
48 : : AnisotropicElasticity(options),
49 20 : _T(declare_parameter<SSR4>("T", "elastic_stiffness_tensor", /*allow nonlinear=*/true))
50 : {
51 5 : }
52 :
53 : void
54 10 : GeneralElasticity::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
55 : {
56 10 : const auto A = _T.rotate(_R);
57 10 : const auto Ainv = _compliance ? A.inverse() : SSR4();
58 :
59 10 : if (out)
60 7 : _to = (_compliance ? Ainv : A) * _from;
61 :
62 10 : if (dout_din)
63 : {
64 5 : if (_from.is_dependent())
65 5 : _to.d(_from) = _compliance ? Ainv : A;
66 :
67 5 : if (_R.is_dependent())
68 : {
69 5 : const auto dA_dR = _T.drotate(_R);
70 20 : const auto batch_sizes = utils::broadcast_batch_sizes({dA_dR, _from.value()});
71 5 : if (_compliance)
72 4 : _to.d(_R) =
73 16 : Tensor(at::einsum("...ijkl,...klm,...j", {A.dinverse(), dA_dR, _from}), batch_sizes);
74 : else
75 12 : _to.d(_R) = Tensor(at::einsum("...ijk,...j", {dA_dR, _from}), batch_sizes);
76 5 : }
77 :
78 15 : if (const auto * const T = nl_param("T"))
79 : {
80 2 : const auto dA_dT = _T.drotate_self(_R);
81 8 : const auto batch_sizes = utils::broadcast_batch_sizes({dA_dT, _from.value()});
82 2 : if (_compliance)
83 2 : _to.d(*T) =
84 8 : Tensor(at::einsum("...ijkl,...klmn,...j", {A.dinverse(), dA_dT, _from}), batch_sizes);
85 : else
86 4 : _to.d(*T) = Tensor(at::einsum("...ijkl,...j", {dA_dT, _from}), batch_sizes);
87 2 : }
88 : }
89 31 : }
90 : } // namespace neml2
|