thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Config
PhysicalQtyOps.h
Go to the documentation of this file.
1
// -*- C++ -*-
2
//
3
// PhysicalQtyOps.h is a part of ThePEG - Toolkit for HEP Event Generation
4
// Copyright (C) 2006-2019 David Grellscheid, Leif Lonnblad
5
//
6
// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8
//
9
#ifndef Physical_Qty_Ops_H
10
#define Physical_Qty_Ops_H
11
#include "
PhysicalQty.h
"
12
#include <cmath>
13
18
namespace
ThePEG
{
20
21
// qty = qty * qty
22
template
<
typename
T,
typename
U>
23
inline
constexpr
typename
BinaryOpTraits<T,U>::MulT
24
operator*(T q1, U q2) {
25
typedef
typename
BinaryOpTraits<T,U>::MulT RetT;
26
return
RetT{RetT::baseunit(), q1.rawValue()*q2.rawValue()};
27
}
28
29
// qty = qty / qty
30
template
<
typename
T,
typename
U>
31
inline
constexpr
typename
BinaryOpTraits<T,U>::DivT
32
operator/(T q1, U q2) {
33
typedef
typename
BinaryOpTraits<T,U>::DivT RetT;
34
return
RetT{RetT::baseunit(), q1.rawValue()/q2.rawValue()};
35
}
36
37
// qty = qty + qty
38
template
<
typename
T,
typename
U>
39
inline
enable_if_same_qty<T,T,U>
40
operator+(T q1, U q2) {
41
q1 += q2;
42
return
q1;
43
}
44
45
// qty = qty - qty
46
template
<
typename
T,
typename
U>
47
inline
enable_if_same_qty<T,T,U>
48
operator-(T q1, U q2) {
49
q1 -= q2;
50
return
q1;
51
}
52
53
// qty == qty
54
template
<
typename
T,
typename
U>
55
inline
constexpr
enable_if_same_qty<bool,T,U>
56
operator==(T q1, U q2) {
57
return
q1.rawValue()==q2.rawValue();
58
}
59
60
// qty != qty
61
template
<
typename
T,
typename
U>
62
inline
constexpr
enable_if_same_qty<bool,T,U>
63
operator!=(T q1, U q2) {
64
return
q1.rawValue()!=q2.rawValue();
65
}
66
67
// qty < qty
68
template
<
typename
T,
typename
U>
69
inline
constexpr
enable_if_same_qty<bool,T,U>
70
operator<(T q1, U q2) {
71
return
q1.rawValue()<q2.rawValue();
72
}
73
74
// qty <= qty
75
template
<
typename
T,
typename
U>
76
inline
constexpr
enable_if_same_qty<bool,T,U>
77
operator<=(T q1, U q2) {
78
return
q1.rawValue()<=q2.rawValue();
79
}
80
81
// qty > qty
82
template
<
typename
T,
typename
U>
83
inline
constexpr
enable_if_same_qty<bool,T,U>
84
operator>(T q1, U q2) {
85
return
q1.rawValue()>q2.rawValue();
86
}
87
88
// qty >= qty
89
template
<
typename
T,
typename
U>
90
inline
constexpr
enable_if_same_qty<bool,T,U>
91
operator>=(T q1, U q2) {
92
return
q1.rawValue()>=q2.rawValue();
93
}
94
95
// comparisons with ZERO
96
template
<
typename
T>
97
inline
constexpr
enable_if_same_qty<bool, T>
98
operator==(T q1, ZeroUnit) {
99
return
q1.rawValue() == 0.0;
100
}
101
template
<
typename
T>
102
inline
constexpr
enable_if_same_qty<bool, T>
103
operator!=(T q1, ZeroUnit) {
104
return
q1.rawValue() != 0.0;
105
}
106
template
<
typename
T>
107
inline
constexpr
enable_if_same_qty<bool, T>
108
operator<(T q1, ZeroUnit) {
109
return
q1.rawValue() < 0.0;
110
}
111
template
<
typename
T>
112
inline
constexpr
enable_if_same_qty<bool, T>
113
operator>(T q1, ZeroUnit) {
114
return
q1.rawValue() > 0.0;
115
}
116
template
<
typename
T>
117
inline
constexpr
enable_if_same_qty<bool, T>
118
operator<=(T q1, ZeroUnit) {
119
return
q1.rawValue() <= 0.0;
120
}
121
template
<
typename
T>
122
inline
constexpr
enable_if_same_qty<bool, T>
123
operator>=(T q1, ZeroUnit) {
124
return
q1.rawValue() >= 0.0;
125
}
126
127
// qty = qty * double
128
template
<
typename
T>
129
inline
constexpr
enable_if_same_qty<T, T>
130
operator*(T q,
double
x) {
131
return
T{q,x};
132
}
133
134
// qty = double * qty
135
template
<
typename
T>
136
inline
constexpr
enable_if_same_qty<T, T>
137
operator*(
double
x,T q) {
138
return
T{q,x};
139
}
140
141
// qty = qty / double
142
template
<
typename
T>
143
inline
constexpr
enable_if_same_qty<T, T>
144
operator/(T q,
double
x) {
145
return
T{q, 1./x};
146
}
147
148
// qty = double / qty
149
template
<
typename
T>
150
inline
constexpr
enable_if_same_qty<typename T::Inverse, T>
151
operator/(
double
x, T q) {
152
typedef
typename
T::Inverse RetT;
153
return
RetT{RetT::baseunit(), x/q.rawValue()};
154
}
155
156
// qty = -qty
157
template
<
typename
T>
158
inline
constexpr
enable_if_same_qty<T, T>
159
operator-(T q) {
160
typedef
T RetT;
161
return
RetT{q, -1.0};
162
}
163
164
// qty = sqrt(qty) // std::sqrt is not constexpr
165
template
<
typename
T>
166
inline
enable_if_same_qty<typename T::Sqrt, T>
167
sqrt(T q) {
168
typedef
typename
T::Sqrt RetT;
169
return
RetT{RetT::baseunit(), std::sqrt(q.rawValue())};
170
}
171
172
// double = atan2(y,x)
173
template
<
typename
T,
typename
U>
174
inline
constexpr
enable_if_same_qty<double,T,U>
175
atan2(T y, U x) {
176
return
std::atan2(y.rawValue(), x.rawValue());
177
}
178
179
// qty = abs(qty)
180
template
<
typename
T>
181
inline
constexpr
enable_if_same_qty<T, T>
182
abs(T q) {
183
return
T{T::baseunit(), std::abs(q.rawValue())};
184
}
185
186
// qty = pow<P,R>(qty)
187
template
<
long
int
Num,
long
int
Den,
typename
T>
188
inline
constexpr
enable_if_same_qty<typename T::template Power<Num,Den>, T>
189
pow(T q) {
190
typedef
typename
T::template Power<Num,Den> RetT;
191
return
RetT{RetT::baseunit(), std::pow(q.rawValue(),
double
(Num)/
double
(Den))};
192
}
193
194
// max for T,U types
195
template
<
typename
T,
typename
U>
196
inline
T max(
const
T & t,
const
U & u) {
197
const
T & utmp =
u
;
198
return
std::max(t, utmp);
199
}
200
201
// ZeroUnit in front should take U type
202
template
<
typename
U>
203
inline
U max(
const
ZeroUnit & t,
const
U & u) {
204
const
U & ttmp =
t
;
205
return
std::max(ttmp, u);
206
}
207
208
// min for T,U types
209
template
<
typename
T,
typename
U>
210
inline
T min(
const
T & t,
const
U & u) {
211
const
T & utmp =
u
;
212
return
std::min(t, utmp);
213
}
214
215
// ZeroUnit in front should take U type
216
template
<
typename
U>
217
inline
U min(
const
ZeroUnit & t,
const
U & u) {
218
const
U & ttmp =
t
;
219
return
std::min(ttmp, u);
220
}
221
222
224
}
225
226
#endif
PhysicalQty.h
The PhysicalQty class allows compile-time checking of dimensional correctness.
ThePEG::ParticleID::t
@ t
(t)
Definition:
EnumParticles.h:54
ThePEG::ParticleID::u
@ u
(u)
Definition:
EnumParticles.h:30
ThePEG
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
Generated on Thu Jun 20 2024 14:47:00 for ThePEG by
1.9.6