Version: SMASH-3.1
energymomentumtensor.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2015-2018,2020-2022,2024
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_ENERGYMOMENTUMTENSOR_H_
11 #define SRC_INCLUDE_SMASH_ENERGYMOMENTUMTENSOR_H_
12 
13 #include <array>
14 #include <cmath>
15 #include <cstdint>
16 #include <string>
17 
18 #include "fourvector.h"
19 #include "particledata.h"
20 
21 namespace smash {
22 
30  public:
32  typedef std::array<double, 10> tmn_type;
34  EnergyMomentumTensor() { Tmn_.fill(0.); }
35 
40  explicit EnergyMomentumTensor(const tmn_type &Tmn) {
41  for (size_t i = 0; i < 10; i++) {
42  Tmn_[i] = Tmn[i];
43  }
44  }
45 
47  double operator[](std::size_t i) const { return Tmn_[i]; }
48 
54  static std::int8_t tmn_index(std::int8_t mu, std::int8_t nu) {
55  // clang-format off
56  constexpr std::array<std::int8_t, 16> indices = {0, 1, 2, 3,
57  1, 4, 5, 6,
58  2, 5, 7, 8,
59  3, 6, 8, 9};
60  // clang-format on
61  if (mu < 4 && nu < 4 && mu >= 0 && nu >= 0) {
62  return indices[mu + 4 * nu];
63  } else {
64  throw std::invalid_argument("Invalid indices: " + std::to_string(mu) +
65  ", " + std::to_string(nu));
66  }
67  }
68 
74  EnergyMomentumTensor inline operator*=(double a);
76  EnergyMomentumTensor inline operator/=(double a);
77 
79  using iterator = tmn_type::iterator;
81  using const_iterator = tmn_type::const_iterator;
82 
88 
94  EnergyMomentumTensor boosted(const FourVector &u) const;
95 
102  void add_particle(const FourVector &mom);
109  void add_particle(const ParticleData &p, double factor);
112  }
113 
120  iterator begin() { return Tmn_.begin(); }
121 
125  iterator end() { return Tmn_.end(); }
126 
128  const_iterator begin() const { return Tmn_.begin(); }
130  const_iterator end() const { return Tmn_.end(); }
131 
133  const_iterator cbegin() const { return Tmn_.cbegin(); }
135  const_iterator cend() const { return Tmn_.cend(); }
136 
137  private:
144 };
145 
152 std::ostream &operator<<(std::ostream &out, const EnergyMomentumTensor &Tmn);
153 
155  const EnergyMomentumTensor &Tmn0) {
156  for (size_t i = 0; i < 10; i++) {
157  Tmn_[i] += Tmn0[i];
158  }
159  return *this;
160 }
163  const EnergyMomentumTensor &b) {
164  a += b;
165  return a;
166 }
167 
169  const EnergyMomentumTensor &Tmn0) {
170  for (size_t i = 0; i < 10; i++) {
171  Tmn_[i] -= Tmn0[i];
172  }
173  return *this;
174 }
177  const EnergyMomentumTensor &b) {
178  a -= b;
179  return a;
180 }
181 
183  for (size_t i = 0; i < 10; i++) {
184  Tmn_[i] *= a;
185  }
186  return *this;
187 }
190  a *= b;
191  return a;
192 }
195  b *= a;
196  return b;
197 }
198 
200  for (size_t i = 0; i < 10; i++) {
201  Tmn_[i] /= a;
202  }
203  return *this;
204 }
207  a /= b;
208  return a;
209 }
210 
211 } // namespace smash
212 
213 #endif // SRC_INCLUDE_SMASH_ENERGYMOMENTUMTENSOR_H_
The EnergyMomentumTensor class represents a symmetric positive semi-definite energy-momentum tensor .
EnergyMomentumTensor operator*=(double a)
Scaling of the tensor by scalar .
tmn_type::const_iterator const_iterator
Constant iterator over the components.
const_iterator end() const
Const overload of the above.
tmn_type::iterator iterator
Iterator over the components.
EnergyMomentumTensor boosted(const FourVector &u) const
Boost to a given 4-velocity.
FourVector landau_frame_4velocity() const
Find the Landau frame 4-velocity from energy-momentum tensor.
tmn_type Tmn_
The internal storage of the components.
EnergyMomentumTensor operator+=(const EnergyMomentumTensor &Tmn0)
Addition of to tensor.
EnergyMomentumTensor operator/=(double a)
Division of the tensor by scalar .
std::array< double, 10 > tmn_type
The energy-momentum tensor is symmetric and has 10 independent components.
EnergyMomentumTensor operator-=(const EnergyMomentumTensor &Tmn0)
Subtraction of of tensor.
EnergyMomentumTensor(const tmn_type &Tmn)
Copy constructor.
iterator begin()
Returns an iterator starting at the (0,0) component.
const_iterator begin() const
Const overload of the above.
void add_particle_for_derivatives(const ParticleData &, double, ThreeVector)
Dummy function need for update_general_lattice.
iterator end()
Returns an iterator pointing after the (3,3)th component.
EnergyMomentumTensor()
Default constructor (nulls all components)
double operator[](std::size_t i) const
Return ith component of the tensor.
const_iterator cbegin() const
static std::int8_t tmn_index(std::int8_t mu, std::int8_t nu)
Access the index of component .
void add_particle(const FourVector &mom)
Given momentum of the particle adds to the energy momentum tensor.
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:58
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:31
@ Tmn
Energy-momentum tensor in lab frame.
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:547
constexpr int p
Proton.
Definition: action.h:24
EnergyMomentumTensor operator-(EnergyMomentumTensor a, const EnergyMomentumTensor &b)
Direct subtraction operator.
EnergyMomentumTensor operator*(EnergyMomentumTensor a, const double b)
Direct multiplication operator.
EnergyMomentumTensor operator+(EnergyMomentumTensor a, const EnergyMomentumTensor &b)
Direct addition operator.
EnergyMomentumTensor operator/(EnergyMomentumTensor a, const double b)
Direct division operator.