Version: SMASH-3.0
energymomentumtensor.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2015-2018,2020-2022
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 <string>
16 
17 #include "fourvector.h"
18 #include "particledata.h"
19 
20 namespace smash {
21 
29  public:
31  typedef std::array<double, 10> tmn_type;
33  EnergyMomentumTensor() { Tmn_.fill(0.); }
34 
39  explicit EnergyMomentumTensor(const tmn_type &Tmn) {
40  for (size_t i = 0; i < 10; i++) {
41  Tmn_[i] = Tmn[i];
42  }
43  }
44 
46  double operator[](std::size_t i) const { return Tmn_[i]; }
47 
53  static std::int8_t tmn_index(std::int8_t mu, std::int8_t nu) {
54  // clang-format off
55  constexpr std::array<std::int8_t, 16> indices = {0, 1, 2, 3,
56  1, 4, 5, 6,
57  2, 5, 7, 8,
58  3, 6, 8, 9};
59  // clang-format on
60  if (mu < 4 && nu < 4 && mu >= 0 && nu >= 0) {
61  return indices[mu + 4 * nu];
62  } else {
63  throw std::invalid_argument("Invalid indices: " + std::to_string(mu) +
64  ", " + std::to_string(nu));
65  }
66  }
67 
73  EnergyMomentumTensor inline operator*=(double a);
75  EnergyMomentumTensor inline operator/=(double a);
76 
78  using iterator = tmn_type::iterator;
80  using const_iterator = tmn_type::const_iterator;
81 
87 
93  EnergyMomentumTensor boosted(const FourVector &u) const;
94 
101  void add_particle(const FourVector &mom);
108  void add_particle(const ParticleData &p, double factor);
111  }
112 
119  iterator begin() { return Tmn_.begin(); }
120 
124  iterator end() { return Tmn_.end(); }
125 
127  const_iterator begin() const { return Tmn_.begin(); }
129  const_iterator end() const { return Tmn_.end(); }
130 
132  const_iterator cbegin() const { return Tmn_.cbegin(); }
134  const_iterator cend() const { return Tmn_.cend(); }
135 
136  private:
143 };
144 
151 std::ostream &operator<<(std::ostream &out, const EnergyMomentumTensor &Tmn);
152 
154  const EnergyMomentumTensor &Tmn0) {
155  for (size_t i = 0; i < 10; i++) {
156  Tmn_[i] += Tmn0[i];
157  }
158  return *this;
159 }
162  const EnergyMomentumTensor &b) {
163  a += b;
164  return a;
165 }
166 
168  const EnergyMomentumTensor &Tmn0) {
169  for (size_t i = 0; i < 10; i++) {
170  Tmn_[i] -= Tmn0[i];
171  }
172  return *this;
173 }
176  const EnergyMomentumTensor &b) {
177  a -= b;
178  return a;
179 }
180 
182  for (size_t i = 0; i < 10; i++) {
183  Tmn_[i] *= a;
184  }
185  return *this;
186 }
189  a *= b;
190  return a;
191 }
194  b *= a;
195  return b;
196 }
197 
199  for (size_t i = 0; i < 10; i++) {
200  Tmn_[i] /= a;
201  }
202  return *this;
203 }
206  a /= b;
207  return a;
208 }
209 
210 } // namespace smash
211 
212 #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
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:537
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.