NEML2 2.0.0
Loading...
Searching...
No Matches
imap.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/misc/defaults.h"
28#include "neml2/tensors/DTensor.h"
29#include "neml2/tensors/functions/einsum.h"
30#include "neml2/tensors/Scalar.h"
31#include "neml2/tensors/Vec.h"
32#include "neml2/tensors/R2.h"
33#include "neml2/tensors/SR2.h"
34#include "neml2/tensors/SSR4.h"
35
36namespace neml2
37{
38template <typename T>
39struct imap_t
40{
41 using type = Tensor;
42};
43
45template <typename T>
47imap(const TensorOptions & options = default_tensor_options());
48
50template <typename T>
52
54// Implementations
56
57template <typename T>
59imap(const TensorOptions & /*options*/)
60{
61 throw NEMLException("Identity map not implemented for this tensor type.");
62}
63
64template <typename T>
65typename imap_t<T>::type
66imap_v(const TensorOptions & options)
67{
68 return imap<T>(options);
69}
70
71// Scalar
72template <>
74{
75 using type = Scalar;
76};
77template <>
79imap(const TensorOptions & options)
80{
81 return Scalar::ones(options);
82}
83
84// Vec
85template <>
86struct imap_t<Vec>
87{
88 using type = R2;
89};
90template <>
92imap(const TensorOptions & options)
93{
94 return R2::identity(options);
95}
96
97// R2
98template <>
99struct imap_t<R2>
100{
101 using type = R4;
102};
103template <>
105imap(const TensorOptions & options)
106{
107 return neml2::Tensor::identity(9, options).base_reshape({3, 3, 3, 3});
108}
109
110// SR2
111template <>
112struct imap_t<SR2>
113{
114 using type = SSR4;
115};
116template <>
118imap(const TensorOptions & options)
119{
120 return SSR4::identity_sym(options);
121}
122
123// SSR4
124template <>
125inline DTensor<SSR4, SSR4, typename imap_t<SSR4>::type>
126imap(const TensorOptions & options)
127{
128 auto I = neml2::Tensor::identity(6, options);
129 return einsum("ik,jl", {I, I});
130}
131} // namespace neml2
Abstract representation of the derivative of a primitive tensor with respect to another primitive ten...
Definition DTensor.h:67
Definition errors.h:34
static Scalar ones(const TensorOptions &options=default_tensor_options())
Definition PrimitiveTensor.h:259
Base class for second order tensor.
Definition R2.h:49
static R2 identity(const TensorOptions &options=default_tensor_options())
Identity.
Definition R2.cxx:121
Fourth order tensor without symmetry.
Definition R4.h:43
The symmetric second order tensor.
Definition SR2.h:46
The symmetric fourth order tensor, with symmetry in the first two dimensionss as well as in the last ...
Definition SSR4.h:44
static SSR4 identity_sym(const TensorOptions &options=default_tensor_options())
Create the symmetric identity tensor .
Definition SSR4.cxx:101
Scalar.
Definition Scalar.h:38
neml2::Tensor base_reshape(TensorShapeRef shape) const
Definition TensorBaseImpl.h:603
Definition Tensor.h:47
static Tensor identity(Size n, const TensorOptions &options=default_tensor_options())
Identity tensor.
Definition Tensor.cxx:221
3-vector.
Definition Vec.h:43
Definition DiagnosticsInterface.cxx:30
Tensor einsum(c10::string_view equation, TensorList tensors)
Einstein summation along base dimensions.
Definition einsum.cxx:31
TensorOptions default_tensor_options()
Default floating point tensor options.
Definition defaults.cxx:42
imap_t< T >::type imap_v(const TensorOptions &options=default_tensor_options())
Get the identity map interpreted as the concrete primitive tensor type.
Definition imap.h:66
DTensor< T, T, typename imap_t< T >::type > imap(const TensorOptions &options=default_tensor_options())
Identity map.
Definition imap.h:59
c10::TensorOptions TensorOptions
Definition types.h:60
Definition imap.h:40
Tensor type
Definition imap.h:41