electromagnetism.h
Go to the documentation of this file.
1 /**
2  * @file lardataalg/Utilities/quantities/electromagnetism.h
3  * @brief Dimensioned variables representing electromagnetic quantities.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date November 2, 2018
6  * @see lardataalg/Utilities/quantities.h
7  *
8  * Set of basic quantities related to electromagnetism. Currently, quantities
9  * are defined based on the following units:
10  * * coulomb (fC, pC, nC, uC, mC, C)
11  * * volt (uV, mV, V, kV, MV, GV)
12  *
13  * This is a header-only library.
14  *
15  * @todo Also belong here: ampere, volt, farad, ohm...
16  *
17  */
18 
19 #ifndef LARDATAALG_UTILITIES_QUANTITIES_ELECTROMAGNETISM_H
20 #define LARDATAALG_UTILITIES_QUANTITIES_ELECTROMAGNETISM_H
21 
22 // LArSoft libraries
24 
25 // C/C++ standard libraries
26 #include <string_view>
27 #include <ratio>
28 
29 
30 //------------------------------------------------------------------------------
31 namespace util::quantities {
32 
33  namespace units {
34 
35  using namespace std::string_view_literals; // for operator""sv()
36 
37  struct Coulomb: public concepts::UnitBase {
38  static constexpr auto symbol = "C"sv;
39  static constexpr auto name = "coulomb"sv;
40  };
41 
42  struct Volt: public concepts::UnitBase {
43  static constexpr auto symbol = "V"sv;
44  static constexpr auto name = "volt"sv;
45  };
46 
47  } // namespace units
48 
49 
50  // -- BEGIN Charge -----------------------------------------------------------
51  /**
52  * @name Charge quantities
53  *
54  * These charge quantities are tied to `util::quantities::units::Coulomb`.
55  * A few options are provided:
56  *
57  * * most general template, `scaled_coulomb`, allowing to choose both the
58  * scale of the unit (e.g. `std::pico` for picocoulomb) and the type of
59  * the numerical representation
60  * * generic templates (e.g. `coulomb_as`), allowing to choose which numerical
61  * representation to use
62  * * double precision (e.g. `coulomb`), ready for use
63  *
64  */
65  /// @{
66 
67 
68  /// The most generic `units::Coulomb`-based quantity.
69  template <typename R, typename T = double>
71 
72  //
73  // coulomb
74  //
75  /// Type of charge stored in coulomb.
76  template <typename T = double>
78 
79  /// Type of charge stored in coulombs, in double precision.
81 
82  //
83  // millicoulomb
84  //
85  /// Type of charge stored in millicoulomb.
86  template <typename T = double>
88 
89  /// Type of charge stored in millicoulomb, in double precision.
91 
92  //
93  // microcoulomb
94  //
95  /// Type of charge stored in microcoulomb.
96  template <typename T = double>
98 
99  /// Type of charge stored in microcoulomb, in double precision.
101 
102  //
103  // nanocoulomb
104  //
105  /// Type of charge stored in nanocoulomb.
106  template <typename T = double>
108 
109  /// Type of charge stored in nanocoulomb, in double precision.
111 
112  //
113  // picocoulomb
114  //
115  /// Type of charge stored in picocoulomb.
116  template <typename T = double>
118 
119  /// Type of charge stored in picocoulomb, in double precision.
121 
122  //
123  // femtocoulomb
124  //
125  /// Type of charge stored in femtocoulomb.
126  template <typename T = double>
128 
129  /// Type of charge stored in femtocoulomb, in double precision.
131 
132 
133  // -- END Charge -------------------------------------------------------------
134 
135 
136  // -- BEGIN Electric potential -----------------------------------------------
137  /**
138  * @name Electric potential quantities
139  *
140  * These potential quantities are tied to `util::quantities::units::Volt`.
141  * A few options are provided:
142  *
143  * * most general template, `scaled_volt`, allowing to choose both the
144  * scale of the unit (e.g. `std::kilo` for kilovolt) and the type of
145  * the numerical representation
146  * * generic templates (e.g. `volt_as`), allowing to choose which numerical
147  * representation to use
148  * * double precision (e.g. `volt`), ready for use
149  *
150  */
151  /// @{
152 
153 
154  /// The most generic `units::Volt`-based quantity.
155  template <typename R, typename T = double>
157 
158  //
159  // volt
160  //
161  /// Type of potential stored in volt.
162  template <typename T = double>
164 
165  /// Type of potential stored in volts, in double precision.
166  using volt = volt_as<>;
167 
168  //
169  // millivolt
170  //
171  /// Type of potential stored in millivolt.
172  template <typename T = double>
174 
175  /// Type of potential stored in millivolt, in double precision.
177 
178  //
179  // microvolt
180  //
181  /// Type of potential stored in microvolt.
182  template <typename T = double>
184 
185  /// Type of potential stored in microvolt, in double precision.
187 
188  //
189  // kilovolt
190  //
191  /// Type of potential stored in kilovolt.
192  template <typename T = double>
194 
195  /// Type of potential stored in kilovolt, in double precision.
197 
198  //
199  // megavolt
200  //
201  /// Type of potential stored in megavolt.
202  template <typename T = double>
204 
205  /// Type of potential stored in megavolt, in double precision.
207 
208  //
209  // gigavolt
210  //
211  /// Type of potential stored in gigavolt.
212  template <typename T = double>
214 
215  /// Type of potential stored in gigavolt, in double precision.
217 
218  /// @}
219  // -- END Electric potential -------------------------------------------------
220 
221 
222  /**
223  * @brief Literal constants for quantities.
224  *
225  * These functions allow a simplified syntax for specifying a charge or
226  * potential quantity.
227  * In order to use these, their namespace must be used:
228  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
229  * using namespace util::quantities::electromagnetism_literals;
230  *
231  * // definition of `util::quantities::picocoulomb` constant:
232  * constexpr auto Q_pC = 230_pC;
233  *
234  * // assignment (likely to a quantity) of
235  * // `util::quantities::femtocoulomb{500.0}`
236  * Q = 500_fC;
237  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
238  *
239  */
240  namespace electromagnetism_literals {
241 
242  // @{
243  /// Literal coulomb value.
244  constexpr coulomb operator""_C (long double v)
245  { return coulomb{ static_cast<double>(v) }; }
246  constexpr coulomb operator""_C (unsigned long long int v)
247  { return coulomb{ static_cast<double>(v) }; }
248  // @}
249 
250  // @{
251  /// Literal millicoulomb value.
252  constexpr millicoulomb operator""_mC (long double v)
253  { return millicoulomb{ static_cast<double>(v) }; }
254  constexpr millicoulomb operator""_mC (unsigned long long int v)
255  { return millicoulomb{ static_cast<double>(v) }; }
256  // @}
257 
258  // @{
259  /// Literal microcoulomb value.
260  constexpr microcoulomb operator""_uC (long double v)
261  { return microcoulomb{ static_cast<double>(v) }; }
262  constexpr microcoulomb operator""_uC (unsigned long long int v)
263  { return microcoulomb{ static_cast<double>(v) }; }
264  // @}
265 
266  // @{
267  /// Literal nanocoulomb value.
268  constexpr nanocoulomb operator""_nC (long double v)
269  { return nanocoulomb{ static_cast<double>(v) }; }
270  constexpr nanocoulomb operator""_nC (unsigned long long int v)
271  { return nanocoulomb{ static_cast<double>(v) }; }
272  // @}
273 
274  // @{
275  /// Literal picocoulomb value.
276  constexpr picocoulomb operator""_pC (long double v)
277  { return picocoulomb{ static_cast<double>(v) }; }
278  constexpr picocoulomb operator""_pC (unsigned long long int v)
279  { return picocoulomb{ static_cast<double>(v) }; }
280  // @}
281 
282  // @{
283  /// Literal femtocoulomb value.
284  constexpr femtocoulomb operator""_fC (long double v)
285  { return femtocoulomb{ static_cast<double>(v) }; }
286  constexpr femtocoulomb operator""_fC (unsigned long long int v)
287  { return femtocoulomb{ static_cast<double>(v) }; }
288  // @}
289 
290 
291  // @{
292  /// Literal volt value.
293  constexpr volt operator""_V (long double v)
294  { return volt{ static_cast<double>(v) }; }
295  constexpr volt operator""_V (unsigned long long int v)
296  { return volt{ static_cast<double>(v) }; }
297  // @}
298 
299  // @{
300  /// Literal millivolt value.
301  constexpr millivolt operator""_mV (long double v)
302  { return millivolt{ static_cast<double>(v) }; }
303  constexpr millivolt operator""_mV (unsigned long long int v)
304  { return millivolt{ static_cast<double>(v) }; }
305  // @}
306 
307  // @{
308  /// Literal microvolt value.
309  constexpr microvolt operator""_uV (long double v)
310  { return microvolt{ static_cast<double>(v) }; }
311  constexpr microvolt operator""_uV (unsigned long long int v)
312  { return microvolt{ static_cast<double>(v) }; }
313  // @}
314 
315  // @{
316  /// Literal kilovolt value.
317  constexpr kilovolt operator""_kV (long double v)
318  { return kilovolt{ static_cast<double>(v) }; }
319  constexpr kilovolt operator""_kV (unsigned long long int v)
320  { return kilovolt{ static_cast<double>(v) }; }
321  // @}
322 
323  // @{
324  /// Literal megavolt value.
325  constexpr megavolt operator""_MV (long double v)
326  { return megavolt{ static_cast<double>(v) }; }
327  constexpr megavolt operator""_MV (unsigned long long int v)
328  { return megavolt{ static_cast<double>(v) }; }
329  // @}
330 
331  // @{
332  /// Literal gigavolt value.
333  constexpr gigavolt operator""_GV (long double v)
334  { return gigavolt{ static_cast<double>(v) }; }
335  constexpr gigavolt operator""_GV (unsigned long long int v)
336  { return gigavolt{ static_cast<double>(v) }; }
337  // @}
338 
339  } // electromagnetism_literals
340 
341 
342 } // namespace util::quantities
343 
344 //------------------------------------------------------------------------------
345 
346 
347 #endif // LARDATAALG_UTILITIES_QUANTITIES_ELECTROMAGNETISM_H
static QCString name
Definition: declinfo.cpp:673
A value measured in the specified unit.
Definition: quantities.h:566
Numeric variable proxies with embedded unit of measurement.
Types of variables with a unit.
Definition: intervals.h:20