Version: SMASH-3.1
clebschgordan_lookup.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 
8 #ifndef SRC_INCLUDE_SMASH_CLEBSCHGORDAN_LOOKUP_H_
9 #define SRC_INCLUDE_SMASH_CLEBSCHGORDAN_LOOKUP_H_
10 
11 #include <cassert>
12 #include <iostream>
13 #include <unordered_map>
14 
15 #include "smash/iomanipulators.h"
16 
17 namespace smash {
18 
23  public:
32  static double coefficient(const int j_a, const int j_b, const int j_c,
33  const int m_a, const int m_b, const int m_c);
34 
41  struct ThreeSpins {
42  int j1;
43  int j2;
44  int j3;
45  int m1;
46  int m2;
47  int m3;
48 
49  private:
57  auto tied() const { return std::tie(j1, j2, j3, m1, m2, m3); }
58 
59  public:
68  bool operator==(const ThreeSpins &other) const {
69  return tied() == other.tied();
70  }
71  };
72 
73  private:
88  static double calculate_coefficient(const int j_a, const int j_b,
89  const int j_c, const int m_a,
90  const int m_b, const int m_c);
91 
101  struct ThreeSpinHash {
163  std::size_t operator()(const ThreeSpins &in) const noexcept {
164  assert(in.j1 >= 0 && in.j1 < 16);
165  assert(in.j2 >= 0 && in.j2 < 16);
166  assert(in.j3 >= 0 && in.j3 < 16);
167  assert(std::abs(in.m1) < 16);
168  assert(std::abs(in.m2) < 16);
169  assert(std::abs(in.m3) < 16);
170  /*
171  * Although strictly speaking, this would only generate a very poor hash,
172  * we prefer making compilation fail if size_t has less than 32 bits.
173  * This is after all very unlikely and we'll deal with it only if needed.
174  */
175  static_assert(sizeof(std::size_t) >= 4);
176  // This is the amount to shift to obtain "5-bits numbers"
177  constexpr auto bitshift = sizeof(size_t) * 8 - 5;
178  // The different shift to the right make the 5-bit occupy different bits
179  return (static_cast<std::size_t>(in.j1) << bitshift >> (bitshift - 25)) +
180  (static_cast<std::size_t>(in.j2) << bitshift >> (bitshift - 20)) +
181  (static_cast<std::size_t>(in.j3) << bitshift >> (bitshift - 15)) +
182  (static_cast<std::size_t>(in.m1) << bitshift >> (bitshift - 10)) +
183  (static_cast<std::size_t>(in.m2) << bitshift >> (bitshift - 5)) +
184  (static_cast<std::size_t>(in.m3) << bitshift >> bitshift);
185  }
186  };
187 
192  inline static std::unordered_map<ThreeSpins, double, ThreeSpinHash>
194  {{0, 0, 0, +0, +0, +0}, 1.00000000000000000},
195  {{0, 1, 1, +0, -1, -1}, 1.00000000000000022},
196  {{0, 1, 1, +0, +1, +1}, 1.00000000000000022},
197  {{0, 2, 2, +0, -2, -2}, 0.99999999999999989},
198  {{0, 2, 2, +0, +0, +0}, 0.99999999999999989},
199  {{0, 2, 2, +0, +2, +2}, 0.99999999999999989},
200  {{0, 3, 3, +0, -3, -3}, 1.00000000000000000},
201  {{0, 3, 3, +0, -1, -1}, 0.99999999999999989},
202  {{0, 3, 3, +0, +1, +1}, 0.99999999999999989},
203  {{0, 3, 3, +0, +3, +3}, 1.00000000000000000},
204  {{1, 0, 1, -1, +0, -1}, 1.00000000000000022},
205  {{1, 0, 1, +1, +0, +1}, 1.00000000000000022},
206  {{1, 1, 0, -1, +1, +0}, -0.70710678118654757},
207  {{1, 1, 0, +1, -1, +0}, 0.70710678118654757},
208  {{1, 1, 2, -1, -1, -2}, 0.99999999999999989},
209  {{1, 1, 2, -1, +1, +0}, 0.70710678118654746},
210  {{1, 1, 2, +1, -1, +0}, 0.70710678118654746},
211  {{1, 1, 2, +1, +1, +2}, 0.99999999999999989},
212  {{1, 2, 1, -1, +0, -1}, -0.57735026918962584},
213  {{1, 2, 1, -1, +2, +1}, -0.81649658092772615},
214  {{1, 2, 1, +1, -2, -1}, 0.81649658092772615},
215  {{1, 2, 1, +1, +0, +1}, 0.57735026918962584},
216  {{1, 2, 3, -1, -2, -3}, 1.00000000000000000},
217  {{1, 2, 3, -1, +0, -1}, 0.81649658092772615},
218  {{1, 2, 3, -1, +2, +1}, 0.57735026918962584},
219  {{1, 2, 3, +1, -2, -1}, 0.57735026918962584},
220  {{1, 2, 3, +1, +0, +1}, 0.81649658092772615},
221  {{1, 2, 3, +1, +2, +3}, 1.00000000000000000},
222  {{1, 3, 2, -1, -1, -2}, -0.49999999999999983},
223  {{1, 3, 2, -1, +1, +0}, -0.70710678118654724},
224  {{1, 3, 2, -1, +3, +2}, -0.86602540378443837},
225  {{1, 3, 2, +1, -3, -2}, 0.86602540378443837},
226  {{1, 3, 2, +1, -1, +0}, 0.70710678118654724},
227  {{1, 3, 2, +1, +1, +2}, 0.49999999999999983},
228  {{1, 3, 4, -1, -3, -4}, 1.00000000000000022},
229  {{1, 3, 4, -1, -1, -2}, 0.86602540378443871},
230  {{1, 3, 4, -1, +1, +0}, 0.70710678118654746},
231  {{1, 3, 4, -1, +3, +2}, 0.49999999999999994},
232  {{1, 3, 4, +1, -3, -2}, 0.49999999999999994},
233  {{1, 3, 4, +1, -1, +0}, 0.70710678118654746},
234  {{1, 3, 4, +1, +1, +2}, 0.86602540378443871},
235  {{1, 3, 4, +1, +3, +4}, 1.00000000000000022},
236  {{2, 0, 2, -2, +0, -2}, 0.99999999999999989},
237  {{2, 0, 2, +0, +0, +0}, 0.99999999999999989},
238  {{2, 0, 2, +2, +0, +2}, 0.99999999999999989},
239  {{2, 1, 1, -2, +1, -1}, -0.81649658092772615},
240  {{2, 1, 1, +0, -1, -1}, 0.57735026918962584},
241  {{2, 1, 1, +0, +1, +1}, -0.57735026918962584},
242  {{2, 1, 1, +2, -1, +1}, 0.81649658092772615},
243  {{2, 1, 3, -2, -1, -3}, 1.00000000000000000},
244  {{2, 1, 3, -2, +1, -1}, 0.57735026918962584},
245  {{2, 1, 3, +0, -1, -1}, 0.81649658092772615},
246  {{2, 1, 3, +0, +1, +1}, 0.81649658092772615},
247  {{2, 1, 3, +2, -1, +1}, 0.57735026918962584},
248  {{2, 1, 3, +2, +1, +3}, 1.00000000000000000},
249  {{2, 2, 0, -2, +2, +0}, 0.57735026918962584},
250  {{2, 2, 0, +0, +0, +0}, -0.57735026918962573},
251  {{2, 2, 0, +2, -2, +0}, 0.57735026918962584},
252  {{2, 2, 2, -2, +0, -2}, -0.70710678118654735},
253  {{2, 2, 2, -2, +2, +0}, -0.70710678118654735},
254  {{2, 2, 2, +0, -2, -2}, 0.70710678118654735},
255  {{2, 2, 2, +0, +2, +2}, -0.70710678118654735},
256  {{2, 2, 2, +2, -2, +0}, 0.70710678118654735},
257  {{2, 2, 2, +2, +0, +2}, 0.70710678118654735},
258  {{2, 2, 4, -2, -2, -4}, 1.00000000000000022},
259  {{2, 2, 4, -2, +0, -2}, 0.70710678118654746},
260  {{2, 2, 4, -2, +2, +0}, 0.40824829046386313},
261  {{2, 2, 4, +0, -2, -2}, 0.70710678118654746},
262  {{2, 2, 4, +0, +0, +0}, 0.81649658092772615},
263  {{2, 2, 4, +0, +2, +2}, 0.70710678118654746},
264  {{2, 2, 4, +2, -2, +0}, 0.40824829046386313},
265  {{2, 2, 4, +2, +0, +2}, 0.70710678118654746},
266  {{2, 2, 4, +2, +2, +4}, 1.00000000000000022},
267  {{2, 3, 1, -2, +1, -1}, 0.40824829046386302},
268  {{2, 3, 1, -2, +3, +1}, 0.70710678118654746},
269  {{2, 3, 1, +0, -1, -1}, -0.57735026918962573},
270  {{2, 3, 1, +0, +1, +1}, -0.57735026918962573},
271  {{2, 3, 1, +2, -3, -1}, 0.70710678118654746},
272  {{2, 3, 1, +2, -1, +1}, 0.40824829046386302},
273  {{2, 3, 3, -2, -1, -3}, -0.63245553203367610},
274  {{2, 3, 3, -2, +1, -1}, -0.73029674334022165},
275  {{2, 3, 3, -2, +3, +1}, -0.63245553203367610},
276  {{2, 3, 3, +0, -3, -3}, 0.77459666924148352},
277  {{2, 3, 3, +0, -1, -1}, 0.25819888974716126},
278  {{2, 3, 3, +0, +1, +1}, -0.25819888974716126},
279  {{2, 3, 3, +0, +3, +3}, -0.77459666924148352},
280  {{2, 3, 3, +2, -3, -1}, 0.63245553203367610},
281  {{2, 3, 3, +2, -1, +1}, 0.73029674334022165},
282  {{2, 3, 3, +2, +1, +3}, 0.63245553203367610},
283  {{2, 3, 5, -2, -3, -5}, 0.99999999999999989},
284  {{2, 3, 5, -2, -1, -3}, 0.77459666924148318},
285  {{2, 3, 5, -2, +1, -1}, 0.54772255750516596},
286  {{2, 3, 5, -2, +3, +1}, 0.31622776601683794},
287  {{2, 3, 5, +0, -3, -3}, 0.63245553203367599},
288  {{2, 3, 5, +0, -1, -1}, 0.77459666924148318},
289  {{2, 3, 5, +0, +1, +1}, 0.77459666924148318},
290  {{2, 3, 5, +0, +3, +3}, 0.63245553203367599},
291  {{2, 3, 5, +2, -3, -1}, 0.31622776601683794},
292  {{2, 3, 5, +2, -1, +1}, 0.54772255750516596},
293  {{2, 3, 5, +2, +1, +3}, 0.77459666924148318},
294  {{2, 3, 5, +2, +3, +5}, 0.99999999999999989},
295  {{3, 0, 3, -3, +0, -3}, 1.00000000000000000},
296  {{3, 0, 3, -1, +0, -1}, 0.99999999999999989},
297  {{3, 0, 3, +1, +0, +1}, 0.99999999999999989},
298  {{3, 0, 3, +3, +0, +3}, 1.00000000000000000},
299  {{3, 1, 2, -3, +1, -2}, -0.86602540378443837},
300  {{3, 1, 2, -1, -1, -2}, 0.49999999999999983},
301  {{3, 1, 2, -1, +1, +0}, -0.70710678118654724},
302  {{3, 1, 2, +1, -1, +0}, 0.70710678118654724},
303  {{3, 1, 2, +1, +1, +2}, -0.49999999999999983},
304  {{3, 1, 2, +3, -1, +2}, 0.86602540378443837},
305  {{3, 1, 4, -3, -1, -4}, 1.00000000000000022},
306  {{3, 1, 4, -3, +1, -2}, 0.49999999999999994},
307  {{3, 1, 4, -1, -1, -2}, 0.86602540378443871},
308  {{3, 1, 4, -1, +1, +0}, 0.70710678118654746},
309  {{3, 1, 4, +1, -1, +0}, 0.70710678118654746},
310  {{3, 1, 4, +1, +1, +2}, 0.86602540378443871},
311  {{3, 1, 4, +3, -1, +2}, 0.49999999999999994},
312  {{3, 1, 4, +3, +1, +4}, 1.00000000000000022},
313  {{3, 2, 1, -3, +2, -1}, 0.70710678118654746},
314  {{3, 2, 1, -1, +0, -1}, -0.57735026918962573},
315  {{3, 2, 1, -1, +2, +1}, 0.40824829046386302},
316  {{3, 2, 1, +1, -2, -1}, 0.40824829046386302},
317  {{3, 2, 1, +1, +0, +1}, -0.57735026918962573},
318  {{3, 2, 1, +3, -2, +1}, 0.70710678118654746},
319  {{3, 2, 3, -3, +0, -3}, -0.77459666924148352},
320  {{3, 2, 3, -3, +2, -1}, -0.63245553203367610},
321  {{3, 2, 3, -1, -2, -3}, 0.63245553203367610},
322  {{3, 2, 3, -1, +0, -1}, -0.25819888974716126},
323  {{3, 2, 3, -1, +2, +1}, -0.73029674334022165},
324  {{3, 2, 3, +1, -2, -1}, 0.73029674334022165},
325  {{3, 2, 3, +1, +0, +1}, 0.25819888974716126},
326  {{3, 2, 3, +1, +2, +3}, -0.63245553203367610},
327  {{3, 2, 3, +3, -2, +1}, 0.63245553203367610},
328  {{3, 2, 3, +3, +0, +3}, 0.77459666924148352},
329  {{3, 2, 5, -3, -2, -5}, 0.99999999999999989},
330  {{3, 2, 5, -3, +0, -3}, 0.63245553203367599},
331  {{3, 2, 5, -3, +2, -1}, 0.31622776601683794},
332  {{3, 2, 5, -1, -2, -3}, 0.77459666924148318},
333  {{3, 2, 5, -1, +0, -1}, 0.77459666924148318},
334  {{3, 2, 5, -1, +2, +1}, 0.54772255750516596},
335  {{3, 2, 5, +1, -2, -1}, 0.54772255750516596},
336  {{3, 2, 5, +1, +0, +1}, 0.77459666924148318},
337  {{3, 2, 5, +1, +2, +3}, 0.77459666924148318},
338  {{3, 2, 5, +3, -2, +1}, 0.31622776601683794},
339  {{3, 2, 5, +3, +0, +3}, 0.63245553203367599},
340  {{3, 2, 5, +3, +2, +5}, 0.99999999999999989},
341  {{3, 3, 0, -3, +3, +0}, -0.49999999999999994},
342  {{3, 3, 0, -1, +1, +0}, 0.49999999999999994},
343  {{3, 3, 0, +1, -1, +0}, -0.49999999999999994},
344  {{3, 3, 0, +3, -3, +0}, 0.49999999999999994},
345  {{3, 3, 2, -3, +1, -2}, 0.54772255750516596},
346  {{3, 3, 2, -3, +3, +0}, 0.67082039324993692},
347  {{3, 3, 2, -1, -1, -2}, -0.63245553203367599},
348  {{3, 3, 2, -1, +1, +0}, -0.22360679774997907},
349  {{3, 3, 2, -1, +3, +2}, 0.54772255750516596},
350  {{3, 3, 2, +1, -3, -2}, 0.54772255750516596},
351  {{3, 3, 2, +1, -1, +0}, -0.22360679774997907},
352  {{3, 3, 2, +1, +1, +2}, -0.63245553203367599},
353  {{3, 3, 2, +3, -3, +0}, 0.67082039324993692},
354  {{3, 3, 2, +3, -1, +2}, 0.54772255750516596},
355  {{3, 3, 4, -3, -1, -4}, -0.70710678118654746},
356  {{3, 3, 4, -3, +1, -2}, -0.70710678118654746},
357  {{3, 3, 4, -3, +3, +0}, -0.49999999999999994},
358  {{3, 3, 4, -1, -3, -4}, 0.70710678118654746},
359  {{3, 3, 4, -1, +1, +0}, -0.49999999999999994},
360  {{3, 3, 4, -1, +3, +2}, -0.70710678118654746},
361  {{3, 3, 4, +1, -3, -2}, 0.70710678118654746},
362  {{3, 3, 4, +1, -1, +0}, 0.49999999999999994},
363  {{3, 3, 4, +1, +3, +4}, -0.70710678118654746},
364  {{3, 3, 4, +3, -3, +0}, 0.49999999999999994},
365  {{3, 3, 4, +3, -1, +2}, 0.70710678118654746},
366  {{3, 3, 4, +3, +1, +4}, 0.70710678118654746},
367  {{3, 3, 6, -3, -3, -6}, 1.00000000000000022},
368  {{3, 3, 6, -3, -1, -4}, 0.70710678118654746},
369  {{3, 3, 6, -3, +1, -2}, 0.44721359549995793},
370  {{3, 3, 6, -3, +3, +0}, 0.22360679774997894},
371  {{3, 3, 6, -1, -3, -4}, 0.70710678118654746},
372  {{3, 3, 6, -1, -1, -2}, 0.77459666924148352},
373  {{3, 3, 6, -1, +1, +0}, 0.67082039324993670},
374  {{3, 3, 6, -1, +3, +2}, 0.44721359549995793},
375  {{3, 3, 6, +1, -3, -2}, 0.44721359549995793},
376  {{3, 3, 6, +1, -1, +0}, 0.67082039324993670},
377  {{3, 3, 6, +1, +1, +2}, 0.77459666924148352},
378  {{3, 3, 6, +1, +3, +4}, 0.70710678118654746},
379  {{3, 3, 6, +3, -3, +0}, 0.22360679774997894},
380  {{3, 3, 6, +3, -1, +2}, 0.44721359549995793},
381  {{3, 3, 6, +3, +1, +4}, 0.70710678118654746},
382  {{3, 3, 6, +3, +3, +6}, 1.00000000000000022},
383  };
384 };
385 
386 } // namespace smash
387 
388 #endif // SRC_INCLUDE_SMASH_CLEBSCHGORDAN_LOOKUP_H_
Class to store and retrieve/calculate Clebsch-Gordan coefficients.
static std::unordered_map< ThreeSpins, double, ThreeSpinHash > lookup_table
Tabulation of Clebsch-Gordan coefficients.
static double coefficient(const int j_a, const int j_b, const int j_c, const int m_a, const int m_b, const int m_c)
Check in the Clebsch-Gordan lookup table if the requested coefficient is available.
static double calculate_coefficient(const int j_a, const int j_b, const int j_c, const int m_a, const int m_b, const int m_c)
Calculate Clebsch-Gordan coefficient .
Definition: action.h:24
This is one of the possible ways to prepare a hashing mechanism to use a custom object in a std::unor...
std::size_t operator()(const ThreeSpins &in) const noexcept
The overload of the operator() is the only needed ingredient to make this class ready to be used as h...
Auxiliary struct to be used as key in the look up table of Clebsch-Gordan coefficients.
int m2
z component of second isospin
int m1
z component of first isospin
bool operator==(const ThreeSpins &other) const
Comparison operator between two set of spin information.
int m3
z component of third isospin
auto tied() const
A utility function to avoid duplication in comparison operator(s).