NEML2 1.4.0
Loading...
Searching...
No Matches
R4.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/misc/math.h"
26#include "neml2/tensors/R4.h"
27#include "neml2/tensors/Scalar.h"
28#include "neml2/tensors/R2.h"
29#include "neml2/tensors/R3.h"
30#include "neml2/tensors/SSR4.h"
31#include "neml2/tensors/R5.h"
32#include "neml2/tensors/Rot.h"
33#include "neml2/tensors/WWR4.h"
34
35namespace neml2
36{
37R4::R4(const SSR4 & T)
38 : R4(math::mandel_to_full(math::mandel_to_full(T, 1)))
39{
40}
41
42R4::R4(const WWR4 & T)
43 : R4(math::skew_to_full(math::skew_to_full(T, 1)))
44{
45}
46
47R4
48R4::rotate(const Rot & r) const
49{
50 R2 R = r.euler_rodrigues();
52
53 auto res = torch::einsum("...im,...jn,...ko,...lp,...mnop", {R, R, R, R, *this});
54 return R4(res, broadcast_batch_dim(*this, R));
55}
56
57R5
58R4::drotate(const Rot & r) const
59{
60 R2 R = r.euler_rodrigues();
61 R3 F = r.deuler_rodrigues();
63
64 auto res1 = torch::einsum("...jn,...ko,...lp,...mnop,...imt->...ijklt", {R, R, R, *this, F});
65 auto res2 = torch::einsum("...im,...ko,...lp,...mnop,...jnt->...ijklt", {R, R, R, *this, F});
66 auto res3 = torch::einsum("...im,...jn,...lp,...mnop,...kot->...ijklt", {R, R, R, *this, F});
67 auto res4 = torch::einsum("...im,...jn,...ko,...mnop,...lpt->...ijklt", {R, R, R, *this, F});
68 auto res = res1 + res2 + res3 + res4;
69
70 return R5(res, broadcast_batch_dim(*this, R, F));
71}
72
75{
76 return base_index({i, j, k, l});
77}
78
79R4
84
85R4
90
91R4
96} // namespace neml2
BatchTensor base_transpose(TorchSize d1, TorchSize d2) const
Transpose two base dimensions.
Definition BatchTensorBase.cxx:299
BatchTensor base_index(const TorchSlice &indices) const
Return an index sliced on the base dimensions.
Definition BatchTensorBase.cxx:193
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
A basic R2.
Definition R2.h:42
The (logical) full third order tensor.
Definition R3.h:41
The (logical) full fourth order tensor.
Definition R4.h:43
R4 rotate(const Rot &r) const
Rotate.
Definition R4.cxx:48
R4(const SSR4 &T)
Definition R4.cxx:37
R4 transpose(TorchSize d1, TorchSize d2) const
Arbitrary transpose two dimensions.
Definition R4.cxx:80
R4 transpose_major() const
Transpose major axes.
Definition R4.cxx:92
Scalar operator()(TorchSize i, TorchSize j, TorchSize k, TorchSize l) const
Accessor.
Definition R4.cxx:74
R4 transpose_minor() const
Transpose minor axes.
Definition R4.cxx:86
R5 drotate(const Rot &r) const
Derivative of the rotated tensor w.r.t. the Rodrigues vector.
Definition R4.cxx:58
The (logical) full fifth order tensor.
Definition R5.h:37
Rotation stored as modified Rodrigues parameters.
Definition Rot.h:49
The (logical) symmetric fourth order tensor, with symmetry in the first two dimensionss as well as in...
Definition SSR4.h:44
The (logical) scalar.
Definition Scalar.h:38
The (logical) symmetric fourth order tensor, with skew symmetry in the first two dimensions and last ...
Definition WWR4.h:40
Definition CrossRef.cxx:32
int64_t TorchSize
Definition types.h:35
void neml_assert_batch_broadcastable_dbg(T &&...)
A helper function to assert that (in Debug mode) all tensors are batch-broadcastable.
TorchSize broadcast_batch_dim(T &&...)
The batch dimension after broadcasting.