OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
PartData.cpp
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2// $RCSfile: PartData.cpp,v $
3// ------------------------------------------------------------------------
4// $Revision: 1.1.1.1.2.1 $
5// ------------------------------------------------------------------------
6// Copyright: see Copyright.readme
7// ------------------------------------------------------------------------
8//
9// Class: PartData
10// PartData represents a set of reference values for use in algorithms.
11//
12// ------------------------------------------------------------------------
13// Class category: Algorithms
14// ------------------------------------------------------------------------
15//
16// $Date: 2003/12/02 23:04:59 $
17// $Author: dbruhwil $
18//
19// ------------------------------------------------------------------------
20
21#include "Algorithms/PartData.h"
22#include <cmath>
24
25// Class PartData
26// ------------------------------------------------------------------------
27
28PartData::PartData(double q, double m, double momentum) {
29 charge = q;
30 mass = m;
31 setP(momentum);
32}
33
35 charge = 1.0;
36 mass = 0.0;
37 beta = 1.0;
38 gamma = 1.0e10;
39}
40
41void PartData::setP(double p) {
42 if (mass == 0.0) {
43 throw LogicalError("PartData::setP()", "Particle mass must not be zero.");
44 }
45
46 if (p == 0.0) {
47 throw LogicalError("PartData::setP()", "Particle momentum must not be zero.");
48 }
49
50 double e = std::sqrt(p * p + mass * mass);
51 beta = p / e;
52 gamma = e / mass;
53}
54
55void PartData::setE(double energy) {
56 if (energy <= mass) {
57 throw LogicalError("PartData::setE()", "Energy should be > mass.");
58 }
59
60 gamma = energy / mass;
61 // beta = std::sqrt(energy*energy - mass*mass) / energy;
62 double ginv = 1.0 / gamma;
63 beta = std::sqrt((1.0 - ginv) * (1.0 + ginv));
64}
65
66void PartData::setBeta(double v) {
67 if (v >= 1.0) {
68 throw LogicalError("PartData::setBeta()", "Beta should be < 1.");
69 }
70
71 beta = v;
72 gamma = 1.0 / std::sqrt(1.0 - beta * beta);
73}
74
75void PartData::setGamma(double v) {
76 if (v <= 1.0) {
77 throw LogicalError("PartData::setGamma()", "Gamma should be > 1.");
78 }
79
80 gamma = v;
81 beta = std::sqrt(gamma * gamma - 1.0) / gamma;
82}
Logical error exception.
double mass
Definition PartData.h:98
void setGamma(double gamma)
Set gamma.
Definition PartData.cpp:75
double charge
Definition PartData.h:97
double gamma
Definition PartData.h:100
void setP(double p)
Set reference momentum.
Definition PartData.cpp:41
void setE(double E)
Set reference energy.
Definition PartData.cpp:55
double beta
Definition PartData.h:99
void setBeta(double beta)
Set beta.
Definition PartData.cpp:66