NEML2 1.4.0
Loading...
Searching...
No Matches
R2Base.h
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#pragma once
26
27#include "neml2/tensors/PrimitiveTensor.h"
28
29namespace neml2
30{
31class Scalar;
32class Vec;
33class SR2;
34class R3;
35class R4;
36class Rot;
37class WR2;
38class R2;
39
40template <class>
41class VecBase;
42
48template <class Derived>
49class R2Base : public PrimitiveTensor<Derived, 3, 3>
50{
51public:
53
55 explicit operator SR2() const;
56
58 [[nodiscard]] static Derived
59 fill(const Real & a, const torch::TensorOptions & options = default_tensor_options());
60 [[nodiscard]] static Derived fill(const Scalar & a);
62 [[nodiscard]] static Derived
63 fill(const Real & a11,
64 const Real & a22,
65 const Real & a33,
66 const torch::TensorOptions & options = default_tensor_options());
67 [[nodiscard]] static Derived fill(const Scalar & a11, const Scalar & a22, const Scalar & a33);
69 [[nodiscard]] static Derived
70 fill(const Real & a11,
71 const Real & a22,
72 const Real & a33,
73 const Real & a23,
74 const Real & a13,
75 const Real & a12,
76 const torch::TensorOptions & options = default_tensor_options());
77 [[nodiscard]] static Derived fill(const Scalar & a11,
78 const Scalar & a22,
79 const Scalar & a33,
80 const Scalar & a23,
81 const Scalar & a13,
82 const Scalar & a12);
84 [[nodiscard]] static Derived
85 fill(const Real & a11,
86 const Real & a12,
87 const Real & a13,
88 const Real & a21,
89 const Real & a22,
90 const Real & a23,
91 const Real & a31,
92 const Real & a32,
93 const Real & a33,
94 const torch::TensorOptions & options = default_tensor_options());
95 [[nodiscard]] static Derived fill(const Scalar & a11,
96 const Scalar & a12,
97 const Scalar & a13,
98 const Scalar & a21,
99 const Scalar & a22,
100 const Scalar & a23,
101 const Scalar & a31,
102 const Scalar & a32,
103 const Scalar & a33);
105 [[nodiscard]] static Derived skew(const Vec & v);
107 [[nodiscard]] static Derived
108 identity(const torch::TensorOptions & options = default_tensor_options());
109
111 Derived rotate(const Rot & r) const;
112
114 Derived rotate(const R2 & R) const;
115
117 R3 drotate(const Rot & r) const;
118
120 R4 drotate(const R2 & R) const;
121
123 Scalar operator()(Size i, Size j) const;
124
126 Derived inverse() const;
127
129 Derived transpose() const;
130};
131
133// TODO: Fix the return type
134template <class Derived1,
135 class Derived2,
136 typename = typename std::enable_if_t<std::is_base_of_v<R2Base<Derived1>, Derived1>>,
137 typename = typename std::enable_if_t<std::is_base_of_v<VecBase<Derived2>, Derived2>>>
138Vec operator*(const Derived1 & A, const Derived2 & b);
139
141// TODO: Fix the return type
142template <class Derived1,
143 class Derived2,
144 typename = typename std::enable_if_t<std::is_base_of_v<R2Base<Derived1>, Derived1>>,
145 typename = typename std::enable_if_t<std::is_base_of_v<R2Base<Derived2>, Derived2>>>
146R2 operator*(const Derived1 & A, const Derived2 & B);
147
148} // namespace neml2
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:56
PrimitiveTensor inherits from TensorBase and additionally templates on the base shape.
Definition PrimitiveTensor.h:38
PrimitiveTensor()=default
Default constructor.
The (logical) full second order tensor.
Definition R2Base.h:50
Derived rotate(const Rot &r) const
Rotate using a Rodrigues vector.
Definition R2Base.cxx:177
R3 drotate(const Rot &r) const
Derivative of the rotated tensor w.r.t. the Rodrigues vector.
Definition R2Base.cxx:191
Scalar operator()(Size i, Size j) const
Accessor.
Definition R2Base.cxx:212
static Derived fill(const Real &a, const torch::TensorOptions &options=default_tensor_options())
Fill the diagonals with a11 = a22 = a33 = a.
Definition R2Base.cxx:40
static Derived identity(const torch::TensorOptions &options=default_tensor_options())
Identity.
Definition R2Base.cxx:170
Derived transpose() const
transpose
Definition R2Base.cxx:226
Derived inverse() const
Inversion.
Definition R2Base.cxx:219
static Derived skew(const Vec &v)
Skew matrix from Vec.
Definition R2Base.cxx:158
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
Rotation stored as modified Rodrigues parameters.
Definition Rot.h:49
The (logical) symmetric second order tensor.
Definition SR2.h:46
The (logical) scalar.
Definition Scalar.h:38
The (logical) vector.
Definition Vec.h:42
Definition CrossRef.cxx:30
Vec operator*(const Derived1 &A, const Derived2 &b)
matrix-vector product
Definition R2Base.cxx:233
torch::TensorOptions & default_tensor_options()
Definition types.cxx:30
double Real
Definition types.h:31
int64_t Size
Definition types.h:33