src/utilities/units/IPUnit.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef UTILITIES_UNITS_IPUNIT_HPP | ||
| 7 | #define UTILITIES_UNITS_IPUNIT_HPP | ||
| 8 | |||
| 9 | #include "../UtilitiesAPI.hpp" | ||
| 10 | #include "Unit.hpp" | ||
| 11 | |||
| 12 | namespace openstudio { | ||
| 13 | namespace detail { | ||
| 14 | |||
| 15 | class IPUnit_Impl; | ||
| 16 | |||
| 17 | } // namespace detail | ||
| 18 | |||
| 19 | /** Structure to hold IPUnit exponents needed for IPUnit construction. \relates IPUnit */ | ||
| 20 | struct UTILITIES_API IPExpnt | ||
| 21 | { | ||
| 22 | public: | ||
| 23 | 2337 | IPExpnt(int lbm = 0, int ft = 0, int s = 0, int R = 0, int A = 0, int cd = 0, int lbmol = 0, int lbf = 0, int deg = 0, int sr = 0, int people = 0, | |
| 24 | int cycle = 0, int dollar = 0) | ||
| 25 | 2337 | : m_lbm(lbm), | |
| 26 | 2337 | m_ft(ft), | |
| 27 | 2337 | m_s(s), | |
| 28 | 2337 | m_R(R), | |
| 29 | 2337 | m_A(A), | |
| 30 | 2337 | m_cd(cd), | |
| 31 | 2337 | m_lbmol(lbmol), | |
| 32 | 2337 | m_lbf(lbf), | |
| 33 | 2337 | m_deg(deg), | |
| 34 | 2337 | m_sr(sr), | |
| 35 | 2337 | m_people(people), | |
| 36 | 2337 | m_cycle(cycle), | |
| 37 | 2337 | m_dollar(dollar) {} | |
| 38 | |||
| 39 | private: | ||
| 40 | int m_lbm; | ||
| 41 | int m_ft; | ||
| 42 | int m_s; | ||
| 43 | int m_R; | ||
| 44 | int m_A; | ||
| 45 | int m_cd; | ||
| 46 | int m_lbmol; | ||
| 47 | int m_lbf; | ||
| 48 | int m_deg; | ||
| 49 | int m_sr; | ||
| 50 | int m_people; | ||
| 51 | int m_cycle; | ||
| 52 | int m_dollar; | ||
| 53 | |||
| 54 | friend class detail::IPUnit_Impl; | ||
| 55 | }; | ||
| 56 | |||
| 57 | /** IPUnit is a Unit with baseUnits fixed by its constructors, see IPExpnt. setBaseUnitExponent | ||
| 58 | * throws an exception if any other string is passed in as a baseUnit. IPUnit.hpp declares | ||
| 59 | * related operators and UnitFactory callback functions. */ | ||
| 60 | class UTILITIES_API IPUnit : public Unit | ||
| 61 | { | ||
| 62 | public: | ||
| 63 | /** @name Constructors and Destructors */ | ||
| 64 | //@{ | ||
| 65 | |||
| 66 | /** Default constructor. Example: \verbatim | ||
| 67 | IPUnit myEnergy(IPExpnt(0,1,0,0,1)); | ||
| 68 | std::cout << myEnergy; // produces "ft*lb_f" \endverbatim | ||
| 69 | * | ||
| 70 | * \param[in] exponents holds the exponents for each base unit. | ||
| 71 | * \param[in] scaleExponent exponent for scale. For instance 3 for kilo. | ||
| 72 | * \param[in] prettyString optional string to use in place of standardString. */ | ||
| 73 | IPUnit(const IPExpnt& exponents = IPExpnt(), int scaleExponent = 0, const std::string& prettyString = ""); | ||
| 74 | |||
| 75 | /** Alternate constructor. Specify the abbreviation of the scale, rather than its | ||
| 76 | * exponent. | ||
| 77 | * | ||
| 78 | * \param[in] scaleAbbreviation is string equal to a scale abbreviation. For instance | ||
| 79 | * "k" for kilo. | ||
| 80 | * \param[in] exponents holds the exponents for each base unit. | ||
| 81 | * \param[in] prettyString optional string to use in place of standardString. */ | ||
| 82 | IPUnit(const std::string& scaleAbbreviation, const IPExpnt& exponents = IPExpnt(), const std::string& prettyString = ""); | ||
| 83 | |||
| 84 | 3849 | virtual ~IPUnit() override = default; | |
| 85 | |||
| 86 | //@} | ||
| 87 | |||
| 88 | static double gc(); | ||
| 89 | |||
| 90 | /** @name Mathematical Operators */ | ||
| 91 | //@{ | ||
| 92 | |||
| 93 | /** Convert any non-zero lb_m exponent to lb_f. */ | ||
| 94 | void lbmToLbf(); | ||
| 95 | |||
| 96 | /** Convert any non-zero lb_f exponent to lb_m. */ | ||
| 97 | void lbfToLbm(); | ||
| 98 | |||
| 99 | //@} | ||
| 100 | protected: | ||
| 101 | /// @cond | ||
| 102 | using ImplType = detail::IPUnit_Impl; | ||
| 103 | |||
| 104 | explicit IPUnit(std::shared_ptr<detail::IPUnit_Impl> impl); | ||
| 105 | |||
| 106 | friend class Unit; | ||
| 107 | friend class detail::IPUnit_Impl; | ||
| 108 | |||
| 109 | /// @endcond | ||
| 110 | private: | ||
| 111 | REGISTER_LOGGER("openstudio.units.IPUnit"); | ||
| 112 | }; | ||
| 113 | |||
| 114 | /** \relates IPUnit*/ | ||
| 115 | using OptionalIPUnit = boost::optional<IPUnit>; | ||
| 116 | |||
| 117 | /** \relates IPUnit*/ | ||
| 118 | using IPUnitVector = std::vector<IPUnit>; | ||
| 119 | |||
| 120 | /** @name Create Functions Used by UnitFactory */ | ||
| 121 | //@{ | ||
| 122 | |||
| 123 | // base units | ||
| 124 | |||
| 125 | /** \relates IPUnit */ | ||
| 126 | UTILITIES_API IPUnit createIPMass(); | ||
| 127 | /** \relates IPUnit */ | ||
| 128 | UTILITIES_API IPUnit createIPLength(); | ||
| 129 | /** \relates IPUnit */ | ||
| 130 | UTILITIES_API IPUnit createIPTime(); | ||
| 131 | /** \relates IPUnit */ | ||
| 132 | UTILITIES_API IPUnit createIPTemperature(); | ||
| 133 | /** \relates IPUnit */ | ||
| 134 | UTILITIES_API IPUnit createIPElectricCurrent(); | ||
| 135 | /** \relates IPUnit */ | ||
| 136 | UTILITIES_API IPUnit createIPLuminousIntensity(); | ||
| 137 | /** \relates IPUnit */ | ||
| 138 | UTILITIES_API IPUnit createIPAmountOfSubstance(); | ||
| 139 | /** \relates IPUnit */ | ||
| 140 | UTILITIES_API IPUnit createIPAngle(); | ||
| 141 | /** \relates IPUnit */ | ||
| 142 | UTILITIES_API IPUnit createIPSolidAngle(); | ||
| 143 | /** \relates IPUnit */ | ||
| 144 | UTILITIES_API IPUnit createIPPeople(); | ||
| 145 | /** relates IPUnit */ | ||
| 146 | UTILITIES_API IPUnit createIPCycle(); | ||
| 147 | /** relates IPUnit */ | ||
| 148 | UTILITIES_API IPUnit createIPCurrency(); | ||
| 149 | |||
| 150 | // first order derived units | ||
| 151 | |||
| 152 | /** lb_f is preferred over equivalent using lb_m. \relates IPUnit */ | ||
| 153 | UTILITIES_API IPUnit createIPForce(); | ||
| 154 | /** ft*lb_f is preferred over equivalent using lb_m. \relates IPUnit */ | ||
| 155 | UTILITIES_API IPUnit createIPEnergy(); | ||
| 156 | /** ft*lb_f/s is preferred over equivalent using lb_m. \relates IPUnit */ | ||
| 157 | UTILITIES_API IPUnit createIPPower(); | ||
| 158 | /** Coulomb (C) = s*A. \relates IPUnit */ | ||
| 159 | UTILITIES_API IPUnit createIPElectricCharge(); | ||
| 160 | /** Lumen (lm) = cd*sr. \relates IPUnit */ | ||
| 161 | UTILITIES_API IPUnit createIPLuminousFlux(); | ||
| 162 | /** Foot-candles (fc) = lm/ft^2 = cd*sr/ft^2. \relates IPUnit */ | ||
| 163 | UTILITIES_API IPUnit createIPIlluminance(); | ||
| 164 | /** Hertz (Hz) = cycles/s. Making the distinction between 1/s and cycles/s here mainly to be | ||
| 165 | * consistent with the rotations per minute (rpm) designation made elsewhere. \relates IPUnit */ | ||
| 166 | UTILITIES_API IPUnit createIPFrequency(); | ||
| 167 | |||
| 168 | //@} | ||
| 169 | |||
| 170 | } // namespace openstudio | ||
| 171 | |||
| 172 | #endif // UTILITIES_UNITS_IPUNIT_HPP | ||
| 173 |