Version: SMASH-3.1
fourvector.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2019,2022
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 #include "smash/fourvector.h"
8 
9 #include <cmath>
10 #include <iostream>
11 
12 #include "smash/iomanipulators.h"
13 #include "smash/numerics.h"
14 
15 namespace smash {
16 
18  const double velocity_squared = v.sqr();
19 
20  const double gamma =
21  velocity_squared < 1. ? 1. / std::sqrt(1. - velocity_squared) : 0;
22 
23  // this is used four times in the Vector:
24  const double xprime_0 = gamma * (this->x0() - this->threevec() * v);
25  // this is the part of the space-like components that is always the same:
26  const double constantpart = gamma / (gamma + 1) * (xprime_0 + this->x0());
27  return FourVector(xprime_0, this->threevec() - v * constantpart);
28 }
29 
30 bool FourVector::operator==(const FourVector& a) const {
31  return almost_equal_physics(x_[0], a.x_[0]) &&
32  almost_equal_physics(x_[1], a.x_[1]) &&
33  almost_equal_physics(x_[2], a.x_[2]) &&
34  almost_equal_physics(x_[3], a.x_[3]);
35 }
36 
37 std::ostream& operator<<(std::ostream& out, const FourVector& vec) {
38  out.put('(');
39  out.fill(' ');
40  for (auto x : vec) {
41  out << field<8> << x;
42  }
43  return out << ')';
44 }
45 
46 } // namespace smash
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
bool operator==(const FourVector &a) const
Check if all four vector components are almost equal (accuracy ).
Definition: fourvector.cc:30
FourVector lorentz_boost(const ThreeVector &v) const
Returns the FourVector boosted with velocity v.
Definition: fourvector.cc:17
ThreeVector threevec() const
Definition: fourvector.h:329
FourVector()
default constructor nulls the fourvector components
Definition: fourvector.h:36
std::array< double, 4 > x_
internal storage of this vector's components
Definition: fourvector.h:308
double x0() const
Definition: fourvector.h:313
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:31
double sqr() const
Definition: threevector.h:266
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:547
Definition: action.h:24
bool almost_equal_physics(const N x, const N y)
Same as smash::almost_equal, but for physical checks like energy-momentum conservation small_number i...
Definition: numerics.h:64
Generic numerical functions.