TBTK
Need a break? Support the development by playing Polarity Puzzles
Derived.h
Go to the documentation of this file.
1 /* Copyright 2019 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
23 #ifndef COM_DAFER45_TBTK_QUANTITY_DERIVED
24 #define COM_DAFER45_TBTK_QUANTITY_DERIVED
25 
26 #include "TBTK/Quantity/Base.h"
27 #include "TBTK/Quantity/Quantity.h"
28 #include "TBTK/TBTKMacros.h"
29 
30 #include <iostream>
31 #include <map>
32 #include <string>
33 
34 namespace TBTK{
35 namespace Quantity{
36 
39 
75 template<typename Units, typename Exponents>
76 class Derived : public Quantity<Units, Exponents>{
77 public:
78  using IsBaseQuantity = std::false_type;
81  using Unit = typename Quantity<Units, Exponents>::Unit;
82  using Exponent = typename Quantity<Units, Exponents>::Exponent;
83 
94  static double getConversionFactor(
95  Angle::Unit angleUnit,
96  Charge::Unit chargeUnit,
97  Count::Unit countUnit,
98  Energy::Unit energyUnit,
99  Length::Unit lengthUnit,
100  Temperature::Unit temperatureUnit,
101  Time::Unit timeUnit
102  );
103 
105  static int getExponent(Angle);
106 
108  static int getExponent(Charge);
109 
111  static int getExponent(Count);
112 
114  static int getExponent(Energy);
115 
117  static int getExponent(Length);
118 
120  static int getExponent(Temperature);
121 
123  static int getExponent(Time);
124 private:
125  friend void initializeDerivedQuantities();
126 };
127 
128 template<typename Units, typename Exponents>
130  Angle::Unit angleUnit,
131  Charge::Unit chargeUnit,
132  Count::Unit countUnit,
133  Energy::Unit energyUnit,
134  Length::Unit lengthUnit,
135  Temperature::Unit temperatureUnit,
136  Time::Unit timeUnit
137 ){
138  return pow(
139  Angle::getConversionFactor(angleUnit),
140  static_cast<int>(Exponent::Angle)
141  )*pow(
142  Charge::getConversionFactor(chargeUnit),
143  static_cast<int>(Exponent::Charge)
144  )*pow(
145  Count::getConversionFactor(countUnit),
146  static_cast<int>(Exponent::Count)
147  )*pow(
148  Energy::getConversionFactor(energyUnit),
149  static_cast<int>(Exponent::Energy)
150  )*pow(
151  Length::getConversionFactor(lengthUnit),
152  static_cast<int>(Exponent::Length)
153  )*pow(
154  Temperature::getConversionFactor(temperatureUnit),
155  static_cast<int>(Exponent::Temperature)
156  )*pow(
157  Time::getConversionFactor(timeUnit),
158  static_cast<int>(Exponent::Time)
159  );
160 }
161 
162 template<typename Units, typename Exponents>
164  return static_cast<int>(Exponents::Angle);
165 }
166 
167 template<typename Units, typename Exponents>
169  return static_cast<int>(Exponents::Charge);
170 }
171 
172 template<typename Units, typename Exponents>
174  return static_cast<int>(Exponents::Count);
175 }
176 
177 template<typename Units, typename Exponents>
179  return static_cast<int>(Exponents::Energy);
180 }
181 
182 template<typename Units, typename Exponents>
184  return static_cast<int>(Exponents::Length);
185 }
186 
187 template<typename Units, typename Exponents>
189  return static_cast<int>(Exponents::Temperature);
190 }
191 
192 template<typename Units, typename Exponents>
194  return static_cast<int>(Exponents::Time);
195 }
196 
197 //Mass
198 enum class MassUnit {kg, g, mg, ug, ng, pg, fg, ag, u};
199 enum class MassExponent {
200  Angle = 0,
201  Charge = 0,
202  Count = 0,
203  Energy = 1,
204  Length = -2,
205  Temperature = 0,
206  Time = 2
207 };
223 
224 //MagneticField
225 enum class MagneticFieldUnit {MT, kT, T, mT, uT, nT, GG, MG, kG, G, mG, uG};
226 enum class MagneticFieldExponent {
227  Angle = 0,
228  Charge = -1,
229  Count = 0,
230  Energy = 1,
231  Length = -2,
232  Temperature = 0,
233  Time = 1
234 };
253 
254 //Voltage
255 enum class VoltageUnit {GV, MV, kV, V, mV, uV, nV};
256 enum class VoltageExponent {
257  Angle = 0,
258  Charge = -1,
259  Count = 0,
260  Energy = 1,
261  Length = 0,
262  Temperature = 0,
263  Time = 0
264 };
278 
279 //Velocity
280 enum class VelocityUnit {};
281 enum class VelocityExponent {
282  Angle = 0,
283  Charge = 0,
284  Count = 0,
285  Energy = 0,
286  Length = 1,
287  Temperature = 0,
288  Time = -1
289 };
296 
297 //Planck
298 enum class PlanckUnit {};
299 enum class PlanckExponent {
300  Angle = 0,
301  Charge = 0,
302  Count = 0,
303  Energy = 1,
304  Length = 0,
305  Temperature = 0,
306  Time = 1
307 };
313 
314 //Boltzmann
315 enum class BoltzmannUnit {};
316 enum class BoltzmannExponent{
317  Angle = 0,
318  Charge = 0,
319  Count = 0,
320  Energy = 1,
321  Length = 0,
322  Temperature = -1,
323  Time = 0
324 };
331 
332 //Permeability
333 enum class PermeabilityUnit {};
334 enum class PermeabilityExponent {
335  Angle = 0,
336  Charge = -2,
337  Count = 0,
338  Energy = 1,
339  Length = -1,
340  Temperature = 0,
341  Time = 2
342 };
349 
350 //Permittivity
351 enum class PermittivityUnit {};
352 enum class PermittivityExponent{
353  Angle = 0,
354  Charge = 2,
355  Count = 0,
356  Energy = -1,
357  Length = -1,
358  Temperature = 0,
359  Time = 0
360 };
367 
368 //Magneton
369 enum class MagnetonUnit {};
370 enum class MagnetonExponent{
371  Angle = 0,
372  Charge = 1,
373  Count = 0,
374  Energy = 0,
375  Length = 2,
376  Temperature = 0,
377  Time = -1
378 };
385 
386 }; //End of namesapce Quantity
387 }; //End of namesapce TBTK
388 
389 #endif
390 
TBTK::Quantity::Derived::Mass
Derived< MassUnit, MassExponent > Mass
Definition: Derived.h:222
TBTK::Quantity::Derived::Permittivity
Derived< PermittivityUnit, PermittivityExponent > Permittivity
Definition: Derived.h:366
TBTK::Quantity::Derived::getConversionFactor
static double getConversionFactor(Angle::Unit angleUnit, Charge::Unit chargeUnit, Count::Unit countUnit, Energy::Unit energyUnit, Length::Unit lengthUnit, Temperature::Unit temperatureUnit, Time::Unit timeUnit)
Definition: Derived.h:129
TBTK::Quantity::Derived::initializeDerivedQuantities
friend void initializeDerivedQuantities()
TBTK::Quantity::Derived::Planck
Derived< PlanckUnit, PlanckExponent > Planck
Definition: Derived.h:312
TBTK::Quantity::Derived::getExponent
static int getExponent(Angle)
Definition: Derived.h:163
TBTK::Quantity::Derived::Boltzmann
Derived< BoltzmannUnit, BoltzmannExponent > Boltzmann
Definition: Derived.h:330
Base.h
Base Quantity.
TBTK::Quantity::Derived::Permeability
Derived< PermeabilityUnit, PermeabilityExponent > Permeability
Definition: Derived.h:348
TBTK::Quantity::Derived
Derived Quantity.
Definition: Derived.h:76
Quantity.h
Base class for Quantities.
TBTK::Quantity::Derived::Voltage
Derived< VoltageUnit, VoltageExponent > Voltage
Definition: Derived.h:277
TBTK::Quantity::initializeDerivedQuantities
void initializeDerivedQuantities()
TBTK::Quantity::Quantity
Base class for Quantitis.
Definition: Quantity.h:168
TBTKMacros.h
Precompiler macros.
TBTK::Quantity::Derived::MagneticField
Derived< MagneticFieldUnit, MagneticFieldExponent > MagneticField
Definition: Derived.h:252
TBTK::Quantity::Derived::Velocity
Derived< VelocityUnit, VelocityExponent > Velocity
Definition: Derived.h:295
TBTK::Quantity::Derived::Magneton
Derived< MagnetonUnit, MagnetonExponent > Magneton
Definition: Derived.h:384