src/utilities/units/SIUnit.cpp
| 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 | #include "SIUnit.hpp" | ||
| 7 | #include "SIUnit_Impl.hpp" | ||
| 8 | |||
| 9 | #include "../core/Assert.hpp" | ||
| 10 | |||
| 11 | namespace openstudio { | ||
| 12 | namespace detail { | ||
| 13 | |||
| 14 | 18166 | SIUnit_Impl::SIUnit_Impl(const SIExpnt& exponents, int scaleExponent, const std::string& prettyString) | |
| 15 |
2/2✓ Branch 1 taken 18166 times.
✓ Branch 4 taken 18166 times.
|
18166 | : Unit_Impl(scaleExponent, prettyString, 12, UnitSystem::SI) { |
| 16 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[0].first = "kg"; |
| 17 | 18166 | m_units[0].second = exponents.m_kg; | |
| 18 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[1].first = "m"; |
| 19 | 18166 | m_units[1].second = exponents.m_m; | |
| 20 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[2].first = "s"; |
| 21 | 18166 | m_units[2].second = exponents.m_s; | |
| 22 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[3].first = "K"; |
| 23 | 18166 | m_units[3].second = exponents.m_K; | |
| 24 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[4].first = "A"; |
| 25 | 18166 | m_units[4].second = exponents.m_A; | |
| 26 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[5].first = "cd"; |
| 27 | 18166 | m_units[5].second = exponents.m_cd; | |
| 28 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[6].first = "mol"; |
| 29 | 18166 | m_units[6].second = exponents.m_mol; | |
| 30 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[7].first = "rad"; |
| 31 | 18166 | m_units[7].second = exponents.m_rad; | |
| 32 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[8].first = "sr"; |
| 33 | 18166 | m_units[8].second = exponents.m_sr; | |
| 34 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[9].first = "people"; |
| 35 | 18166 | m_units[9].second = exponents.m_people; | |
| 36 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[10].first = "cycle"; |
| 37 | 18166 | m_units[10].second = exponents.m_cycle; | |
| 38 |
1/1✓ Branch 2 taken 18166 times.
|
18166 | m_units[11].first = "$"; |
| 39 | 18166 | m_units[11].second = exponents.m_dollar; | |
| 40 | 18166 | } | |
| 41 | |||
| 42 | 1 | SIUnit_Impl::SIUnit_Impl(const std::string& scaleAbbreviation, const SIExpnt& exponents, const std::string& prettyString) | |
| 43 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | : Unit_Impl(scaleAbbreviation, prettyString, 12, UnitSystem::SI) { |
| 44 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[0].first = "kg"; |
| 45 | 1 | m_units[0].second = exponents.m_kg; | |
| 46 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[1].first = "m"; |
| 47 | 1 | m_units[1].second = exponents.m_m; | |
| 48 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[2].first = "s"; |
| 49 | 1 | m_units[2].second = exponents.m_s; | |
| 50 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[3].first = "K"; |
| 51 | 1 | m_units[3].second = exponents.m_K; | |
| 52 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[4].first = "A"; |
| 53 | 1 | m_units[4].second = exponents.m_A; | |
| 54 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[5].first = "cd"; |
| 55 | 1 | m_units[5].second = exponents.m_cd; | |
| 56 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[6].first = "mol"; |
| 57 | 1 | m_units[6].second = exponents.m_mol; | |
| 58 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[7].first = "rad"; |
| 59 | 1 | m_units[7].second = exponents.m_rad; | |
| 60 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[8].first = "sr"; |
| 61 | 1 | m_units[8].second = exponents.m_sr; | |
| 62 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[9].first = "people"; |
| 63 | 1 | m_units[9].second = exponents.m_people; | |
| 64 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[10].first = "cycle"; |
| 65 | 1 | m_units[10].second = exponents.m_cycle; | |
| 66 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_units[11].first = "$"; |
| 67 | 1 | m_units[11].second = exponents.m_dollar; | |
| 68 | 1 | } | |
| 69 | |||
| 70 | 2476753 | Unit SIUnit_Impl::clone() const { | |
| 71 |
3/5✓ Branch 1 taken 2476753 times.
✓ Branch 4 taken 2476753 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2476753 times.
✗ Branch 10 not taken.
|
2476753 | OS_ASSERT(system() == UnitSystem::SI); |
| 72 |
3/5✓ Branch 1 taken 2476753 times.
✓ Branch 4 taken 2476753 times.
✓ Branch 7 taken 2476753 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
2476753 | std::shared_ptr<SIUnit_Impl> impl(new SIUnit_Impl(*this)); |
| 73 |
2/2✓ Branch 2 taken 2476753 times.
✓ Branch 5 taken 2476753 times.
|
4953506 | return SIUnit(impl).cast<Unit>(); |
| 74 | 2476753 | } | |
| 75 | |||
| 76 | 11259 | void SIUnit_Impl::setBaseUnitExponent(const std::string& baseUnit, int exponent) { | |
| 77 |
1/1✓ Branch 1 taken 11259 times.
|
11259 | auto loc = findBaseUnit(baseUnit); |
| 78 |
2/2✓ Branch 2 taken 11255 times.
✓ Branch 3 taken 4 times.
|
11259 | if (loc != m_units.end()) { |
| 79 | 11255 | loc->second = exponent; | |
| 80 | } else { | ||
| 81 |
17/17✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 16 taken 4 times.
✓ Branch 19 taken 4 times.
✓ Branch 25 taken 4 times.
✓ Branch 28 taken 4 times.
✓ Branch 31 taken 4 times.
✓ Branch 34 taken 4 times.
✓ Branch 37 taken 4 times.
✓ Branch 40 taken 4 times.
✓ Branch 43 taken 4 times.
✓ Branch 46 taken 4 times.
✓ Branch 50 taken 4 times.
✓ Branch 53 taken 4 times.
|
4 | LOG_AND_THROW("Cannot add baseUnit " << baseUnit << " to an instance of SIUnit."); |
| 82 | } | ||
| 83 | 11255 | } | |
| 84 | |||
| 85 | } // namespace detail | ||
| 86 | |||
| 87 | 18166 | SIUnit::SIUnit(const SIExpnt& exponents, int scaleExponent, const std::string& prettyString) | |
| 88 |
4/6✓ Branch 1 taken 18166 times.
✓ Branch 4 taken 18166 times.
✓ Branch 7 taken 18166 times.
✓ Branch 10 taken 18166 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
18166 | : Unit(std::shared_ptr<detail::Unit_Impl>(new detail::SIUnit_Impl(exponents, scaleExponent, prettyString))) {} |
| 89 | |||
| 90 | 1 | SIUnit::SIUnit(const std::string& scaleAbbreviation, const SIExpnt& exponents, const std::string& prettyString) | |
| 91 |
4/6✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
1 | : Unit(std::shared_ptr<detail::Unit_Impl>(new detail::SIUnit_Impl(scaleAbbreviation, exponents, prettyString))) {} |
| 92 | |||
| 93 | /// @cond | ||
| 94 |
1/1✓ Branch 2 taken 2476762 times.
|
2476762 | SIUnit::SIUnit(std::shared_ptr<detail::SIUnit_Impl> impl) : Unit(std::dynamic_pointer_cast<detail::Unit_Impl>(impl)) {} |
| 95 | /// @endcond | ||
| 96 | |||
| 97 | 129 | SIUnit createSIMass() { | |
| 98 |
2/2✓ Branch 1 taken 129 times.
✓ Branch 5 taken 129 times.
|
258 | return SIUnit(SIExpnt(1)); |
| 99 | } | ||
| 100 | 337 | SIUnit createSILength() { | |
| 101 |
2/2✓ Branch 1 taken 337 times.
✓ Branch 5 taken 337 times.
|
674 | return SIUnit(SIExpnt(0, 1)); |
| 102 | } | ||
| 103 | 179 | SIUnit createSITime() { | |
| 104 |
2/2✓ Branch 1 taken 179 times.
✓ Branch 5 taken 179 times.
|
358 | return SIUnit(SIExpnt(0, 0, 1)); |
| 105 | } | ||
| 106 | 141 | SIUnit createSITemperature() { | |
| 107 |
2/2✓ Branch 1 taken 141 times.
✓ Branch 5 taken 141 times.
|
282 | return SIUnit(SIExpnt(0, 0, 0, 1)); |
| 108 | } | ||
| 109 | |||
| 110 | 105 | SIUnit createSIElectricCurrent() { | |
| 111 |
2/2✓ Branch 1 taken 105 times.
✓ Branch 5 taken 105 times.
|
210 | return SIUnit(SIExpnt(0, 0, 0, 0, 1)); |
| 112 | } | ||
| 113 | |||
| 114 | 100 | SIUnit createSILuminousIntensity() { | |
| 115 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return SIUnit(SIExpnt(0, 0, 0, 0, 0, 1)); |
| 116 | } | ||
| 117 | |||
| 118 | 158 | SIUnit createSIAmountOfSubstance() { | |
| 119 |
2/2✓ Branch 1 taken 158 times.
✓ Branch 5 taken 158 times.
|
316 | return SIUnit(SIExpnt(0, 0, 0, 0, 0, 0, 1)); |
| 120 | } | ||
| 121 | |||
| 122 | 100 | SIUnit createSIAngle() { | |
| 123 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return SIUnit(SIExpnt(0, 0, 0, 0, 0, 0, 0, 1)); |
| 124 | } | ||
| 125 | |||
| 126 | 100 | SIUnit createSISolidAngle() { | |
| 127 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return SIUnit(SIExpnt(0, 0, 0, 0, 0, 0, 0, 0, 1)); |
| 128 | } | ||
| 129 | |||
| 130 | 246 | SIUnit createSIPeople() { | |
| 131 |
2/2✓ Branch 1 taken 246 times.
✓ Branch 5 taken 246 times.
|
492 | return SIUnit(SIExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); |
| 132 | } | ||
| 133 | |||
| 134 | 102 | SIUnit createSICycle() { | |
| 135 |
2/2✓ Branch 1 taken 102 times.
✓ Branch 5 taken 102 times.
|
204 | return SIUnit(SIExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); |
| 136 | } | ||
| 137 | |||
| 138 | ✗ | SIUnit createSICurrency() { | |
| 139 | ✗ | return SIUnit(SIExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); | |
| 140 | } | ||
| 141 | |||
| 142 | 206 | SIUnit createSIForce() { | |
| 143 |
2/2✓ Branch 1 taken 206 times.
✓ Branch 5 taken 206 times.
|
412 | return SIUnit(SIExpnt(1, 1, -2), 0, "N"); |
| 144 | } | ||
| 145 | |||
| 146 | 131 | SIUnit createSIEnergy() { | |
| 147 |
2/2✓ Branch 1 taken 131 times.
✓ Branch 5 taken 131 times.
|
262 | return SIUnit(SIExpnt(1, 2, -2), 0, "J"); |
| 148 | } | ||
| 149 | |||
| 150 | 389 | SIUnit createSIPower() { | |
| 151 |
2/2✓ Branch 1 taken 389 times.
✓ Branch 5 taken 389 times.
|
778 | return SIUnit(SIExpnt(1, 2, -3), 0, "W"); |
| 152 | } | ||
| 153 | |||
| 154 | 100 | SIUnit createSIElectricCharge() { | |
| 155 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return SIUnit(SIExpnt(0, 0, 1, 0, 1), 0, "C"); |
| 156 | } | ||
| 157 | |||
| 158 | 103 | SIUnit createSIElectricalPotential() { | |
| 159 |
2/2✓ Branch 1 taken 103 times.
✓ Branch 5 taken 103 times.
|
206 | return SIUnit(SIExpnt(1, 2, -3, 0, -1), 0, "V"); |
| 160 | } | ||
| 161 | |||
| 162 | 100 | SIUnit createSIElectricCapacitance() { | |
| 163 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return SIUnit(SIExpnt(-1, -2, 4, 0, 2), 0, "F"); |
| 164 | } | ||
| 165 | |||
| 166 | 101 | SIUnit createSIElectricResistance() { | |
| 167 |
2/2✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
|
202 | return SIUnit(SIExpnt(1, 2, -3, 0, -2), 0, "ohm"); |
| 168 | } | ||
| 169 | |||
| 170 | 100 | SIUnit createSIMagneticFlux() { | |
| 171 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return SIUnit(SIExpnt(1, 2, -2, 0, -1), 0, "Wb"); |
| 172 | } | ||
| 173 | |||
| 174 | 100 | SIUnit createSIMagneticFieldStrength() { | |
| 175 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return SIUnit(SIExpnt(1, 0, -2, 0, -1), 0, "T"); |
| 176 | } | ||
| 177 | |||
| 178 | 100 | SIUnit createSIInductance() { | |
| 179 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return SIUnit(SIExpnt(1, 2, -2, 0, -2), 0, "H"); |
| 180 | } | ||
| 181 | |||
| 182 | 100 | SIUnit createSILuminousFlux() { | |
| 183 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return SIUnit(SIExpnt(0, 0, 0, 0, 0, 1, 0, 0, 1), 0, "lm"); |
| 184 | } | ||
| 185 | |||
| 186 | 101 | SIUnit createSIIlluminance() { | |
| 187 |
2/2✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
|
202 | return SIUnit(SIExpnt(0, -2, 0, 0, 0, 1, 0, 0, 1), 0, "lux"); |
| 188 | } | ||
| 189 | |||
| 190 | 100 | SIUnit createSIFrequency() { | |
| 191 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return SIUnit(SIExpnt(0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 1), 0, "Hz"); |
| 192 | } | ||
| 193 | |||
| 194 | 106 | SIUnit createSIEnergyUseIntensity() { | |
| 195 |
2/2✓ Branch 1 taken 106 times.
✓ Branch 5 taken 106 times.
|
212 | return SIUnit(SIExpnt(1, 0, -2), 0, "J/m^2"); |
| 196 | } | ||
| 197 | |||
| 198 | 102 | SIUnit createSIPowerDensity() { | |
| 199 |
2/2✓ Branch 1 taken 102 times.
✓ Branch 5 taken 102 times.
|
204 | return SIUnit(SIExpnt(1, 0, -3), 0, "W/m^2"); |
| 200 | } | ||
| 201 | |||
| 202 | 101 | SIUnit createSIPowerPerPerson() { | |
| 203 |
2/2✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
|
202 | return SIUnit(SIExpnt(1, 2, -3, 0, 0, 0, 0, 0, 0, -1), 0, "W/person"); |
| 204 | } | ||
| 205 | |||
| 206 | 119 | SIUnit createSIPressure() { | |
| 207 |
2/2✓ Branch 1 taken 119 times.
✓ Branch 5 taken 119 times.
|
238 | return SIUnit(SIExpnt(1, -1, -2), 0, "Pa"); |
| 208 | } | ||
| 209 | |||
| 210 | 101 | SIUnit createSIThermalConductance() { | |
| 211 |
2/2✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
|
202 | return SIUnit(SIExpnt(1, 0, -3, -1), 0, "W/m^2*K"); |
| 212 | } | ||
| 213 | |||
| 214 | 110 | SIUnit createSIThermalResistance() { | |
| 215 |
2/2✓ Branch 1 taken 110 times.
✓ Branch 5 taken 110 times.
|
220 | return SIUnit(SIExpnt(-1, 0, 3, 1), 0, "m^2*K/W"); |
| 216 | } | ||
| 217 | |||
| 218 | 101 | SIUnit createSIHeatCapacity() { | |
| 219 |
2/2✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
|
202 | return SIUnit(SIExpnt(1, 0, -2, -1), 0, "J/m^2*K"); |
| 220 | } | ||
| 221 | |||
| 222 | } // namespace openstudio | ||
| 223 |