Version: SMASH-3.1
clebschgordan_lookup.cc
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 
9 
10 #include <numeric>
11 #include <unordered_map>
12 
13 #include "gsl/gsl_sf_coupling.h"
14 
15 #include "smash/constants.h"
16 #include "smash/iomanipulators.h"
17 #include "smash/logging.h"
18 
19 namespace smash {
20 static constexpr int LResonances = LogArea::Resonances::id;
21 
22 double ClebschGordan::calculate_coefficient(const int j_a, const int j_b,
23  const int j_c, const int m_a,
24  const int m_b, const int m_c) {
25  const double wigner_3j = gsl_sf_coupling_3j(j_a, j_b, j_c, m_a, m_b, -m_c);
26  if (std::abs(wigner_3j) < really_small) {
27  return 0.;
28  }
29  assert((j_a - j_b + m_c) % 2 == 0);
30  const int j = (j_a - j_b + m_c) / 2;
31  double result = std::sqrt(j_c + 1) * wigner_3j;
32  result *= (j % 2 == 0) * 2 - 1; // == (-1)**j
33 
34  logg[LResonances].debug("CG: ", result, " I1: ", j_a, " I2: ", j_b,
35  " IR: ", j_c, " iz1: ", m_a, " iz2: ", m_b,
36  " izR: ", m_c);
37 
38  return result;
39 }
40 
41 double ClebschGordan::coefficient(const int j_a, const int j_b, const int j_c,
42  const int m_a, const int m_b, const int m_c) {
43  const ThreeSpins spin_information = {j_a, j_b, j_c, m_a, m_b, m_c};
44  if (auto search = lookup_table.find(spin_information);
45  search != lookup_table.end()) {
46  return search->second;
47  } else {
48  double result = calculate_coefficient(j_a, j_b, j_c, m_a, m_b, m_c);
49  lookup_table.insert({spin_information, result});
50  return result;
51  }
52 }
53 
54 } // namespace smash
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 .
Collection of useful constants that are known at compile time.
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
Definition: action.h:24
static constexpr int LResonances
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37
Auxiliary struct to be used as key in the look up table of Clebsch-Gordan coefficients.