v0.15.0
Loading...
Searching...
No Matches
Lie.hpp
Go to the documentation of this file.
1/**
2 * @file Lie.hpp
3 * @brief Lie algebra implementation
4 * @version 0.1
5 * @date 2024-12-22
6 *
7 * @copyright Copyright (c) 2024
8 *
9 */
10
11#pragma once
12
13namespace LieGroups {
14
15template <class T> struct TensorTypeExtractor {
16 typedef typename std::remove_pointer<T>::type Type;
17};
18template <class T, int I> struct TensorTypeExtractor<FTensor::PackPtr<T, I>> {
19 typedef typename std::remove_pointer<T>::type Type;
20};
21
22struct SO3 {
23
24 SO3() = delete;
25 ~SO3() = delete;
26
27 template <typename T> inline static auto getVee(T &&w1, T &&w2, T &&w3) {
29
30 std::forward<T>(w1), std::forward<T>(w2), std::forward<T>(w3)
31
32 );
33 }
34
35 template <typename T> inline static auto getHat(T &&w1, T &&w2, T &&w3) {
36 return getHatImpl(std::forward<A>(getVee(w1, w2, w3)));
37 }
38
39 template <typename A> inline static auto getVee(A &&t_w_hat) {
40 return getVeeImpl(std::forward<A>(t_w_hat));
41 }
42
43 template <typename A> inline static auto getHat(A &&t_w_vee) {
44 return getHatImpl(std::forward<A>(t_w_vee));
45 }
46
47 template <typename A, typename B>
48 inline static auto exp(A &&t_w_vee, B &&theta) {
49 return expImpl(std::forward<A>(t_w_vee), std::forward<B>(theta));
50 }
51
52 template <typename A, typename B>
53 inline static auto Jl(A &&t_w_vee, B &&theta) {
54 return JlImpl(std::forward<A>(t_w_vee), std::forward<B>(theta));
55 }
56
57 template <typename A, typename B>
58 inline static auto Jr(A &&t_w_vee, B &&theta) {
59 return JrImpl(std::forward<A>(t_w_vee), std::forward<B>(theta));
60 }
61
62 template <typename A, typename B, typename C>
63 inline static auto action(A &&t_w_vee, B &&theta, C &&t_A) {
64 return actionImpl(std::forward<A>(t_w_vee), std::forward<B>(theta),
65 std::forward<C>(t_A));
66 }
67
68 template <typename A, typename B>
69 inline static auto dActionJl(A &&t_w_vee, B &&t_A) {
70 return dActionJlImpl(std::forward<A>(t_w_vee), std::forward<B>(t_A));
71 }
72
73 template <typename A, typename B>
74 inline static auto dActionJr(A &&t_w_vee, B &&t_A) {
75 return dActionJrImpl(std::forward<A>(t_w_vee), std::forward<B>(t_A));
76 }
77
78 template <typename A, typename B>
79 inline static auto diffExp(A &&t_w_vee, B &&theta) {
80 return diffExpImpl(std::forward<A>(t_w_vee), std::forward<B>(theta));
81 }
82
83private:
84 inline static constexpr int dim = 3;
85 inline static FTENSOR_INDEX(dim, i);
86 inline static FTENSOR_INDEX(dim, j);
87 inline static FTENSOR_INDEX(dim, k);
88 inline static FTENSOR_INDEX(dim, l);
89 inline static FTENSOR_INDEX(dim, m);
90 inline static FTENSOR_INDEX(dim, n);
91
92 template <typename T>
93 inline static auto getVeeImpl(FTensor::Tensor2<T, dim, dim> &t_w_hat) {
94 using D = typename TensorTypeExtractor<T>::Type;
96 t_w_vee(k) = (levi_civita(i, j, k) * t_w_hat(i, j)) / 2;
97 return t_w_vee;
98 }
99
100 template <typename T>
101 inline static auto getHatImpl(FTensor::Tensor1<T, dim> &t_w_vee) {
102 using D = typename TensorTypeExtractor<T>::Type;
104 t_w_hat(i, j) = levi_civita(i, j, k) * t_w_vee(k);
105 return t_w_hat;
106 }
107
108 template <typename T1, typename T2, typename T3>
109 inline static auto genericFormImpl(FTensor::Tensor1<T1, dim> &t_w_vee,
110 const T2 alpha, const T3 beta) {
111 using D = typename TensorTypeExtractor<T1>::Type;
113 auto t_hat = getHat(t_w_vee);
114 t_X(i, j) = FTensor::Kronecker_Delta<int>()(i, j) + alpha * t_hat(i, j) +
115 beta * (t_hat(i, k) * t_hat(k, j));
116 return t_X;
117 }
118
119 template <typename T1, typename T2>
120 inline static auto expImpl(FTensor::Tensor1<T1, dim> &t_w_vee,
121 const T2 theta) {
122 if (std::fabs(theta) < std::numeric_limits<T2>::epsilon()) {
123 return genericFormImpl(t_w_vee, 1, 0.5);
124 }
125 const auto s = sin(theta);
126 const auto s_half = sin(theta / 2);
127 const auto a = s / theta;
128 const auto b = 2 * (s_half / theta) * (s_half / theta);
129 return genericFormImpl(t_w_vee, a, b);
130 }
131
132 template <typename T1, typename T2>
133 inline static auto diffExpImpl(FTensor::Tensor1<T1, dim> &t_w_vee,
134 const T2 theta) {
135
136 auto get_tensor = [&t_w_vee](auto a, auto diff_a, auto b, auto diff_b) {
137 FTENSOR_INDEX(3, i);
138 FTENSOR_INDEX(3, j);
139 FTENSOR_INDEX(3, k);
140 FTENSOR_INDEX(3, l);
141
142 using D = typename TensorTypeExtractor<T1>::Type;
144 auto t_hat = getHat(t_w_vee);
145 t_diff_exp(i, j, k) =
146
147 a * FTensor::levi_civita<int>(i, j, k)
148
149 +
150
151 diff_a * t_hat(i, j) * t_w_vee(k)
152
153 +
154
155 b * (t_hat(i, l) * FTensor::levi_civita<int>(l, j, k) +
156 FTensor::levi_civita<int>(i, l, k) * t_hat(l, j))
157
158 +
159
160 diff_b * t_hat(i, l) * t_hat(l, j) * t_w_vee(k);
161
162 return t_diff_exp;
163 };
164
165 if(std::fabs(theta) < std::numeric_limits<T2>::epsilon()){
166 return get_tensor(1., -1. / 3., 0., 1. / 1.2);
167 }
168
169 const auto ss = sin(theta);
170 const auto a = ss / theta;
171
172 const auto theta2 = theta * theta;
173 const auto cc = cos(theta);
174 const auto diff_a = (theta * cc - ss) / (theta2 * theta);
175
176 const auto ss_2 = sin(theta / 2.);
177 const auto cc_2 = cos(theta / 2.);
178 const auto b = 2. * ss_2 * ss_2 / theta2;
179 const auto diff_b =
180 (2. * theta * ss_2 * cc_2 - 4. * ss_2 * ss_2) / (theta2 * theta2);
181
182 return get_tensor(a, diff_a, b, diff_b);
183 }
184
185 template <typename T1, typename T2>
186 inline static auto JlImpl(FTensor::Tensor1<T1, dim> &t_w_vee,
187 const T2 &theta) {
188 if (std::fabs(theta) < std::numeric_limits<T2>::epsilon()) {
189 return genericFormImpl(t_w_vee, 0.5, 1. / 6.);
190 }
191 const auto s = sin(theta);
192 const auto s_half = sin(theta / 2);
193 const auto a = 2 * (s_half / theta) * (s_half / theta);
194 const auto b = ((theta - s) / theta) / theta / theta;
195 return genericFormImpl(t_w_vee, a, b);
196 }
197
198 template <typename T1, typename T2>
199 inline static auto JrImpl(FTensor::Tensor1<T1, dim> &t_w_vee,
200 const T2 theta) {
201 if (std::fabs(theta) < std::numeric_limits<T2>::epsilon()) {
202 return genericFormImpl(t_w_vee, -0.5, 1. / 6.);
203 }
204 const auto s = sin(theta);
205 const auto s_half = sin(theta / 2);
206 const auto a = 2 * (s_half / theta) * (s_half / theta);
207 const auto b = ((theta - s) / theta) / theta / theta;
208 return genericFormImpl(t_w_vee, -a, b);
209 }
210
211 template <typename T1, typename T2, typename T3>
212 inline static auto actionImpl(FTensor::Tensor1<T1, dim> &t_w_vee,
213 const T2 theta,
215 using D = typename TensorTypeExtractor<T3>::Type;
217 t_B(i, j) = exp(t_w_vee, theta)(i,k) * t_A(k, j);
218 return t_B;
219 }
220
221
222}; // namespace SO3
223
224}; // namespace LieGroups
#define FTENSOR_INDEX(DIM, I)
constexpr double a
Kronecker Delta class.
FTensor::Index< 'i', SPACE_DIM > i
double D
const double n
refractive index of diffusive medium
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
Tensors class implemented by Walter Landry.
Definition FTensor.hpp:51
constexpr AssemblyType A
FTensor::Index< 'm', 3 > m
static auto diffExpImpl(FTensor::Tensor1< T1, dim > &t_w_vee, const T2 theta)
Definition Lie.hpp:133
static auto dActionJr(A &&t_w_vee, B &&t_A)
Definition Lie.hpp:74
static auto Jr(A &&t_w_vee, B &&theta)
Definition Lie.hpp:58
static constexpr int dim
Definition Lie.hpp:84
static auto Jl(A &&t_w_vee, B &&theta)
Definition Lie.hpp:53
static auto action(A &&t_w_vee, B &&theta, C &&t_A)
Definition Lie.hpp:63
static auto JrImpl(FTensor::Tensor1< T1, dim > &t_w_vee, const T2 theta)
Definition Lie.hpp:199
static FTENSOR_INDEX(dim, l)
static FTENSOR_INDEX(dim, k)
static auto JlImpl(FTensor::Tensor1< T1, dim > &t_w_vee, const T2 &theta)
Definition Lie.hpp:186
static auto getVee(A &&t_w_hat)
Definition Lie.hpp:39
static auto getHatImpl(FTensor::Tensor1< T, dim > &t_w_vee)
Definition Lie.hpp:101
static auto getHat(T &&w1, T &&w2, T &&w3)
Definition Lie.hpp:35
static FTENSOR_INDEX(dim, j)
static auto genericFormImpl(FTensor::Tensor1< T1, dim > &t_w_vee, const T2 alpha, const T3 beta)
Definition Lie.hpp:109
static auto diffExp(A &&t_w_vee, B &&theta)
Definition Lie.hpp:79
static auto dActionJl(A &&t_w_vee, B &&t_A)
Definition Lie.hpp:69
static auto actionImpl(FTensor::Tensor1< T1, dim > &t_w_vee, const T2 theta, FTensor::Tensor2_symmetric< T3, dim > &t_A)
Definition Lie.hpp:212
static auto expImpl(FTensor::Tensor1< T1, dim > &t_w_vee, const T2 theta)
Definition Lie.hpp:120
static auto getHat(A &&t_w_vee)
Definition Lie.hpp:43
static FTENSOR_INDEX(dim, n)
static FTENSOR_INDEX(dim, m)
static auto getVeeImpl(FTensor::Tensor2< T, dim, dim > &t_w_hat)
Definition Lie.hpp:93
static FTENSOR_INDEX(dim, i)
static auto getVee(T &&w1, T &&w2, T &&w3)
Definition Lie.hpp:27
static auto exp(A &&t_w_vee, B &&theta)
Definition Lie.hpp:48
std::remove_pointer< T >::type Type
Definition Lie.hpp:16