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/tensors/R4.h"
26 : #include "neml2/tensors/Scalar.h"
27 : #include "neml2/tensors/R2.h"
28 : #include "neml2/tensors/R3.h"
29 : #include "neml2/tensors/SSR4.h"
30 : #include "neml2/tensors/R5.h"
31 : #include "neml2/tensors/Rot.h"
32 : #include "neml2/tensors/WWR4.h"
33 : #include "neml2/tensors/R8.h"
34 : #include "neml2/tensors/assertions.h"
35 : #include "neml2/tensors/mandel_notation.h"
36 :
37 : namespace neml2
38 : {
39 :
40 66 : R4::R4(const SSR4 & T)
41 66 : : R4(mandel_to_full(mandel_to_full(T, 1)))
42 : {
43 66 : }
44 :
45 0 : R4::R4(const WWR4 & T)
46 0 : : R4(skew_to_full(skew_to_full(T, 1)))
47 : {
48 0 : }
49 :
50 : R4
51 145 : R4::rotate(const Rot & r) const
52 : {
53 145 : R2 R = r.euler_rodrigues();
54 145 : neml_assert_batch_broadcastable_dbg(*this, R);
55 :
56 1015 : auto res = at::einsum("...im,...jn,...ko,...lp,...mnop", {R, R, R, R, *this});
57 290 : return R4(res, utils::broadcast_batch_dim(*this, R));
58 290 : }
59 :
60 : R5
61 13 : R4::drotate(const Rot & r) const
62 : {
63 13 : R2 R = r.euler_rodrigues();
64 13 : R3 F = r.deuler_rodrigues();
65 13 : neml_assert_batch_broadcastable_dbg(*this, R, F);
66 :
67 91 : auto res1 = at::einsum("...jn,...ko,...lp,...mnop,...imt->...ijklt", {R, R, R, *this, F});
68 91 : auto res2 = at::einsum("...im,...ko,...lp,...mnop,...jnt->...ijklt", {R, R, R, *this, F});
69 91 : auto res3 = at::einsum("...im,...jn,...lp,...mnop,...kot->...ijklt", {R, R, R, *this, F});
70 91 : auto res4 = at::einsum("...im,...jn,...ko,...mnop,...lpt->...ijklt", {R, R, R, *this, F});
71 13 : auto res = res1 + res2 + res3 + res4;
72 :
73 26 : return R5(res, utils::broadcast_batch_dim(*this, R, F));
74 65 : }
75 :
76 : R8
77 4 : R4::drotate_self(const Rot & r) const
78 : {
79 4 : R2 R = r.euler_rodrigues();
80 4 : neml_assert_batch_broadcastable_dbg(*this, R);
81 :
82 24 : auto res = R8(at::einsum("...im,...jn,...ko,...lp->...ijklmnop", {R, R, R, R}), R.batch_dim());
83 :
84 4 : if (res.batch_dim() < this->batch_dim())
85 2 : return res.batch_expand_as(*this);
86 2 : return res;
87 8 : }
88 :
89 : Scalar
90 486 : R4::operator()(Size i, Size j, Size k, Size l) const
91 : {
92 2430 : return base_index({i, j, k, l});
93 486 : }
94 :
95 : R4
96 139 : R4::transpose(Size d1, Size d2) const
97 : {
98 139 : return TensorBase<R4>::base_transpose(d1, d2);
99 : }
100 :
101 : R4
102 68 : R4::transpose_minor() const
103 : {
104 68 : return TensorBase<R4>::base_transpose(0, 1).base_transpose(2, 3);
105 : }
106 :
107 : R4
108 1 : R4::transpose_major() const
109 : {
110 1 : return TensorBase<R4>::base_transpose(0, 2).base_transpose(1, 3);
111 : }
112 : } // namespace neml2
|