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