NEML2 1.4.0
Loading...
Searching...
No Matches
VecBase.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/tensors/VecBase.h"
26#include "neml2/tensors/tensors.h"
27#include "neml2/tensors/macros.h"
28
29namespace neml2
30{
31template <class Derived>
32Derived
34 const Real & v2,
35 const Real & v3,
36 const torch::TensorOptions & options)
37{
38 return VecBase<Derived>::fill(Scalar(v1, options), Scalar(v2, options), Scalar(v3, options));
39}
40
41template <class Derived>
43VecBase<Derived>::fill(const Scalar & v1, const Scalar & v2, const Scalar & v3)
44{
45 return Derived(torch::stack({v1, v2, v3}, -1), v1.batch_dim());
46}
47
48template <class Derived>
49R2
50VecBase<Derived>::identity_map(const torch::TensorOptions & options)
51{
52 return R2::identity(options);
54
55template <class Derived>
58{
59 return this->base_index({i});
61
62template <class Derived>
65{
66 return dot(*this);
67}
68
69template <class Derived>
72{
73 return math::sqrt(dot(*this));
74}
76template <class Derived>
79{
80 return this->rotate(r.euler_rodrigues());
82
83template <class Derived>
86{
87 return R * Vec(*this);
88}
89
90template <class Derived>
91R2
93{
94 return torch::einsum("...ijk,...j", {r.deuler_rodrigues(), *this});
95}
96
97template <class Derived>
98R3
100{
101 auto I = R2::identity(R.options());
102 return torch::einsum("...ij,...k", {I, *this});
103}
104
105#define VECBASE_INSTANTIATE(T) template class VecBase<T>
106FOR_ALL_VECBASE(VECBASE_INSTANTIATE);
107} // namespace neml2
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
CrossRef()=default
static R2 identity(const torch::TensorOptions &options=default_tensor_options())
Identity.
Definition R2Base.cxx:170
A basic R2.
Definition R2.h:42
The (logical) full third order tensor.
Definition R3.h:41
Rotation stored as modified Rodrigues parameters.
Definition Rot.h:49
The (logical) scalar.
Definition Scalar.h:38
Derived rotate(const Rot &r) const
Rotate using a Rodrigues vector.
Definition VecBase.cxx:78
Scalar operator()(TorchSize i) const
Accessor.
Definition VecBase.cxx:57
static R2 identity_map(const torch::TensorOptions &options=default_tensor_options())
The derivative of a vector with respect to itself.
Definition VecBase.cxx:50
Scalar norm_sq() const
Norm squared.
Definition VecBase.cxx:64
static Derived fill(const Real &v1, const Real &v2, const Real &v3, const torch::TensorOptions &options=default_tensor_options())
Definition VecBase.cxx:33
Scalar norm() const
Norm.
Definition VecBase.cxx:71
R2 drotate(const Rot &r) const
Derivative of the rotated vector w.r.t. the Rodrigues vector.
Definition VecBase.cxx:92
The (logical) vector.
Definition Vec.h:42
Derived sqrt(const Derived &a)
Definition BatchTensorBase.h:439
Definition CrossRef.cxx:32
double Real
Definition types.h:33