NEML2 1.4.0
Loading...
Searching...
No Matches
SSR4.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/SSR4.h"
27#include "neml2/tensors/Scalar.h"
28#include "neml2/tensors/SR2.h"
29#include "neml2/tensors/R4.h"
30#include "neml2/tensors/R5.h"
31#include "neml2/tensors/SSFR5.h"
32#include "neml2/tensors/Rot.h"
33
34namespace neml2
35{
36SSR4::SSR4(const R4 & T)
37 : SSR4(math::full_to_mandel(
38 math::full_to_mandel(
39 (T + T.transpose_minor() + R4(T.transpose(0, 1)) + R4(T.transpose(2, 3))) / 4.0),
40 1))
41{
42}
43
44SSR4
45SSR4::identity(const torch::TensorOptions & options)
46{
47 return SSR4(torch::tensor({{1, 1, 1, 0, 0, 0},
48 {1, 1, 1, 0, 0, 0},
49 {1, 1, 1, 0, 0, 0},
50 {0, 0, 0, 0, 0, 0},
51 {0, 0, 0, 0, 0, 0},
52 {0, 0, 0, 0, 0, 0}},
53 options),
54 0);
55}
56
57SSR4
58SSR4::identity_sym(const torch::TensorOptions & options)
59{
60 return SSR4(torch::eye(6, options), 0);
61}
62
63SSR4
64SSR4::identity_vol(const torch::TensorOptions & options)
65{
66 return SSR4::identity(options) / 3;
67}
68
69SSR4
70SSR4::identity_dev(const torch::TensorOptions & options)
71{
72 return SSR4::identity_sym(options) - SSR4::identity(options) / 3;
73}
74
75SSR4
77{
79
80 const auto zero = Scalar::zeros_like(E);
81 const auto pf = E / ((1.0 + nu) * (1.0 - 2.0 * nu));
82 const auto C1 = (1.0 - nu) * pf;
83 const auto C2 = nu * pf;
84 const auto C4 = (1.0 - 2.0 * nu) * pf;
85
86 return SSR4(torch::stack({torch::stack({C1, C2, C2, zero, zero, zero}, -1),
87 torch::stack({C2, C1, C2, zero, zero, zero}, -1),
88 torch::stack({C2, C2, C1, zero, zero, zero}, -1),
89 torch::stack({zero, zero, zero, C4, zero, zero}, -1),
90 torch::stack({zero, zero, zero, zero, C4, zero}, -1),
91 torch::stack({zero, zero, zero, zero, zero, C4}, -1)},
92 -1),
93 E.batch_dim());
94}
95
96SSR4
97SSR4::isotropic_E_nu(const Real & E, const Real & nu, const torch::TensorOptions & options)
98{
99 return SSR4::isotropic_E_nu(Scalar(E, options), Scalar(nu, options));
100}
101
102SSR4
103SSR4::rotate(const Rot & r) const
104{
105 return R4(*this).rotate(r);
106}
107
108SSFR5
109SSR4::drotate(const Rot & r) const
110{
111 auto dR = R4(*this).drotate(r);
113}
114
115Scalar
117{
118 const auto a = math::mandel_reverse_index[i][j];
119 const auto b = math::mandel_reverse_index[k][l];
120 return base_index({a, b}) / (math::mandel_factor(a) * math::mandel_factor(b));
121}
122
123SSR4
125{
126 return SSR4(torch::linalg::inv(*this), batch_dim());
127}
128
129SSR4
131{
132 return *this;
133}
134
135SSR4
140
141SR2
142operator*(const SSR4 & a, const SR2 & b)
143{
145 return SR2(torch::matmul(a, b.unsqueeze(-1)).squeeze(-1), broadcast_batch_dim(a, b));
146}
147
148SR2
149operator*(const SR2 & a, const SSR4 & b)
150{
152 return SR2(torch::matmul(a.unsqueeze(-2), b).squeeze(-2), broadcast_batch_dim(a, b));
153}
154
155SSR4
156operator*(const SSR4 & a, const SSR4 & b)
157{
159 return SSR4(torch::matmul(a, b), broadcast_batch_dim(a, b));
160}
161} // namespace neml2
BatchTensor base_transpose(TorchSize d1, TorchSize d2) const
Transpose two base dimensions.
Definition BatchTensorBase.cxx:299
TorchSize batch_dim() const
Return the number of batch dimensions.
Definition BatchTensorBase.cxx:128
BatchTensor base_index(const TorchSlice &indices) const
Return an index sliced on the base dimensions.
Definition BatchTensorBase.cxx:193
static Derived zeros_like(const Derived &other)
Zero tensor like another, i.e. same batch and base shapes, same tensor options, etc.
Definition BatchTensorBase.cxx:59
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
The (logical) full fourth order tensor.
Definition R4.h:43
R4 rotate(const Rot &r) const
Rotate.
Definition R4.cxx:48
R5 drotate(const Rot &r) const
Derivative of the rotated tensor w.r.t. the Rodrigues vector.
Definition R4.cxx:58
Rotation stored as modified Rodrigues parameters.
Definition Rot.h:49
The (logical) symmetric second order tensor.
Definition SR2.h:46
The logical fifth order tensor with minor symmetry in the 1st and 2nd dimensions as well as in the 3r...
Definition SSFR5.h:38
The (logical) symmetric fourth order tensor, with symmetry in the first two dimensionss as well as in...
Definition SSR4.h:44
SSFR5 drotate(const Rot &r) const
Derivative of the rotated tensor w.r.t. the Rodrigues vector.
Definition SSR4.cxx:109
SSR4 transpose_minor() const
Transpose minor axes, no-op.
Definition SSR4.cxx:130
static SSR4 identity_dev(const torch::TensorOptions &options=default_tensor_options())
Create the deviatoric identity tensor .
Definition SSR4.cxx:70
static SSR4 identity(const torch::TensorOptions &options=default_tensor_options())
Create the identity tensor .
Definition SSR4.cxx:45
static SSR4 identity_sym(const torch::TensorOptions &options=default_tensor_options())
Create the symmetric identity tensor .
Definition SSR4.cxx:58
SSR4(const R4 &T)
Initialize with the symmetrized fourth order tensor.
Definition SSR4.cxx:36
Scalar operator()(TorchSize i, TorchSize j, TorchSize k, TorchSize l) const
Accessor.
Definition SSR4.cxx:116
static SSR4 identity_vol(const torch::TensorOptions &options=default_tensor_options())
Create the volumetric identity tensor .
Definition SSR4.cxx:64
static SSR4 isotropic_E_nu(const Scalar &E, const Scalar &nu)
Create the fourth order elasticity tensor given the Young's modulus and the Poisson's ratio.
Definition SSR4.cxx:76
SSR4 rotate(const Rot &r) const
Rotate.
Definition SSR4.cxx:103
SSR4 transpose_major() const
Transpose major axes.
Definition SSR4.cxx:136
SSR4 inverse() const
Definition SSR4.cxx:124
The (logical) scalar.
Definition Scalar.h:38
constexpr Real mandel_factor(TorchSize i)
Definition math.h:50
constexpr TorchSize mandel_reverse_index[3][3]
Definition math.h:43
BatchTensor full_to_mandel(const BatchTensor &full, TorchSize dim)
Convert a BatchTensor from full notation to Mandel notation.
Definition math.cxx:166
Definition CrossRef.cxx:32
BatchTensor operator*(const BatchTensor &a, const BatchTensor &b)
Definition BatchTensor.cxx:153
int64_t TorchSize
Definition types.h:33
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.
double Real
Definition types.h:31
void neml_assert_broadcastable_dbg(T &&...)
A helper function to assert (in Debug mode) that all tensors are broadcastable.