FrictionQPotFEM 0.23.3
Loading...
Searching...
No Matches
detail.h
Go to the documentation of this file.
1
7#ifndef GOOSEFEM_DETAIL_H
8#define GOOSEFEM_DETAIL_H
9
10namespace GooseFEM {
11namespace detail {
12
13template <size_t nd, typename = void>
14struct tensor {
15};
16
17template <size_t nd>
18struct tensor<nd, typename std::enable_if_t<nd == 2>> {
26 template <class T>
27 static double inv(const T& A, T& Ainv)
28 {
29 double det = A(0, 0) * A(1, 1) - A(0, 1) * A(1, 0);
30
31 Ainv(0, 0) = A(1, 1) / det;
32 Ainv(0, 1) = -1.0 * A(0, 1) / det;
33 Ainv(1, 0) = -1.0 * A(1, 0) / det;
34 Ainv(1, 1) = A(0, 0) / det;
35
36 return det;
37 }
38};
39
40template <size_t nd>
41struct tensor<nd, typename std::enable_if_t<nd == 3>> {
49 template <class T>
50 static double inv(const T& A, T& Ainv)
51 {
52 double det = (A(0, 0) * A(1, 1) * A(2, 2) + A(0, 1) * A(1, 2) * A(2, 0) +
53 A(0, 2) * A(1, 0) * A(2, 1)) -
54 (A(0, 2) * A(1, 1) * A(2, 0) + A(0, 1) * A(1, 0) * A(2, 2) +
55 A(0, 0) * A(1, 2) * A(2, 1));
56
57 Ainv(0, 0) = (A(1, 1) * A(2, 2) - A(1, 2) * A(2, 1)) / det;
58 Ainv(0, 1) = (A(0, 2) * A(2, 1) - A(0, 1) * A(2, 2)) / det;
59 Ainv(0, 2) = (A(0, 1) * A(1, 2) - A(0, 2) * A(1, 1)) / det;
60
61 Ainv(1, 0) = (A(1, 2) * A(2, 0) - A(1, 0) * A(2, 2)) / det;
62 Ainv(1, 1) = (A(0, 0) * A(2, 2) - A(0, 2) * A(2, 0)) / det;
63 Ainv(1, 2) = (A(0, 2) * A(1, 0) - A(0, 0) * A(1, 2)) / det;
64
65 Ainv(2, 0) = (A(1, 0) * A(2, 1) - A(1, 1) * A(2, 0)) / det;
66 Ainv(2, 1) = (A(0, 1) * A(2, 0) - A(0, 0) * A(2, 1)) / det;
67 Ainv(2, 2) = (A(0, 0) * A(1, 1) - A(0, 1) * A(1, 0)) / det;
68
69 return det;
70 }
71};
72
73} // namespace detail
74} // namespace GooseFEM
75
76#endif
xt::xtensor< T, N > tensor
Fixed (static) rank array.
Definition: config.h:160
void det(const T &A, R &ret)
Same as Det() but writes to externally allocated output.
Definition: Cartesian3d.h:1003
void inv(const T &A, R &ret)
Same as Inv() but writes to externally allocated output.
Definition: Cartesian3d.h:1190
Toolbox to perform finite element computations.
Definition: Allocate.h:14