Version: SMASH-2.0
fourvector.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2019
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 #include <cmath>
8 #include <iostream>
9 
10 #include "smash/fourvector.h"
11 #include "smash/iomanipulators.h"
12 #include "smash/numerics.h"
13 
14 namespace smash {
15 
17  const double velocity_squared = v.sqr();
18 
19  const double gamma =
20  velocity_squared < 1. ? 1. / std::sqrt(1. - velocity_squared) : 0;
21 
22  // this is used four times in the Vector:
23  const double xprime_0 = gamma * (this->x0() - this->threevec() * v);
24  // this is the part of the space-like components that is always the same:
25  const double constantpart = gamma / (gamma + 1) * (xprime_0 + this->x0());
26  return FourVector(xprime_0, this->threevec() - v * constantpart);
27 }
28 
29 bool FourVector::operator==(const FourVector& a) const {
30  return almost_equal_physics(x_[0], a.x_[0]) &&
31  almost_equal_physics(x_[1], a.x_[1]) &&
32  almost_equal_physics(x_[2], a.x_[2]) &&
33  almost_equal_physics(x_[3], a.x_[3]);
34 }
35 
36 std::ostream& operator<<(std::ostream& out, const FourVector& vec) {
37  out.put('(');
38  out.fill(' ');
39  for (auto x : vec) {
40  out << field<8> << x;
41  }
42  return out << ')';
43 }
44 
45 } // namespace smash
smash
Definition: action.h:24
smash::FourVector::operator==
bool operator==(const FourVector &a) const
Check if all four vector components are almost equal (accuracy ).
Definition: fourvector.cc:29
smash::operator<<
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Definition: action.h:518
smash::ThreeVector::sqr
double sqr() const
Definition: threevector.h:259
smash::FourVector::x_
std::array< double, 4 > x_
internal storage of this vector's components
Definition: fourvector.h:298
fourvector.h
smash::ThreeVector
Definition: threevector.h:31
smash::FourVector::x0
double x0() const
Definition: fourvector.h:303
smash::almost_equal_physics
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:62
numerics.h
iomanipulators.h
smash::FourVector
Definition: fourvector.h:33
smash::FourVector::lorentz_boost
FourVector lorentz_boost(const ThreeVector &v) const
Returns the FourVector boosted with velocity v.
Definition: fourvector.cc:16
smash::FourVector::threevec
ThreeVector threevec() const
Definition: fourvector.h:319
smash::FourVector::FourVector
FourVector()
default constructor nulls the fourvector components
Definition: fourvector.h:36