src/utilities/units/ThermUnit.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 "ThermUnit.hpp" | ||
| 7 | #include "ThermUnit_Impl.hpp" | ||
| 8 | |||
| 9 | #include "../core/Assert.hpp" | ||
| 10 | |||
| 11 | namespace openstudio { | ||
| 12 | namespace detail { | ||
| 13 | |||
| 14 | 1226 | ThermUnit_Impl::ThermUnit_Impl(const ThermExpnt& exponents, int scaleExponent, const std::string& prettyString) | |
| 15 |
2/2✓ Branch 1 taken 1226 times.
✓ Branch 4 taken 1226 times.
|
1226 | : Unit_Impl(scaleExponent, prettyString, 12, UnitSystem::Therm) { |
| 16 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[0].first = "therm"; |
| 17 | 1226 | m_units[0].second = exponents.m_therm; | |
| 18 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[1].first = "in"; |
| 19 | 1226 | m_units[1].second = exponents.m_in; | |
| 20 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[2].first = "yr"; |
| 21 | 1226 | m_units[2].second = exponents.m_yr; | |
| 22 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[3].first = "R"; |
| 23 | 1226 | m_units[3].second = exponents.m_R; | |
| 24 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[4].first = "A"; |
| 25 | 1226 | m_units[4].second = exponents.m_A; | |
| 26 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[5].first = "cd"; |
| 27 | 1226 | m_units[5].second = exponents.m_cd; | |
| 28 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[6].first = "lbmol"; |
| 29 | 1226 | m_units[6].second = exponents.m_lbmol; | |
| 30 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[7].first = "deg"; |
| 31 | 1226 | m_units[7].second = exponents.m_deg; | |
| 32 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[8].first = "sr"; |
| 33 | 1226 | m_units[8].second = exponents.m_sr; | |
| 34 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[9].first = "people"; |
| 35 | 1226 | m_units[9].second = exponents.m_people; | |
| 36 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[10].first = "cycle"; |
| 37 | 1226 | m_units[10].second = exponents.m_cycle; | |
| 38 |
1/1✓ Branch 2 taken 1226 times.
|
1226 | m_units[11].first = "$"; |
| 39 | 1226 | m_units[11].second = exponents.m_dollar; | |
| 40 | 1226 | } | |
| 41 | |||
| 42 | ✗ | ThermUnit_Impl::ThermUnit_Impl(const std::string& scaleAbbreviation, const ThermExpnt& exponents, const std::string& prettyString) | |
| 43 | ✗ | : Unit_Impl(scaleAbbreviation, prettyString, 12, UnitSystem::Therm) { | |
| 44 | ✗ | m_units[0].first = "therm"; | |
| 45 | ✗ | m_units[0].second = exponents.m_therm; | |
| 46 | ✗ | m_units[1].first = "in"; | |
| 47 | ✗ | m_units[1].second = exponents.m_in; | |
| 48 | ✗ | m_units[2].first = "yr"; | |
| 49 | ✗ | m_units[2].second = exponents.m_yr; | |
| 50 | ✗ | m_units[3].first = "R"; | |
| 51 | ✗ | m_units[3].second = exponents.m_R; | |
| 52 | ✗ | m_units[4].first = "A"; | |
| 53 | ✗ | m_units[4].second = exponents.m_A; | |
| 54 | ✗ | m_units[5].first = "cd"; | |
| 55 | ✗ | m_units[5].second = exponents.m_cd; | |
| 56 | ✗ | m_units[6].first = "lbmol"; | |
| 57 | ✗ | m_units[6].second = exponents.m_lbmol; | |
| 58 | ✗ | m_units[7].first = "deg"; | |
| 59 | ✗ | m_units[7].second = exponents.m_deg; | |
| 60 | ✗ | m_units[8].first = "sr"; | |
| 61 | ✗ | m_units[8].second = exponents.m_sr; | |
| 62 | ✗ | m_units[9].first = "people"; | |
| 63 | ✗ | m_units[9].second = exponents.m_people; | |
| 64 | ✗ | m_units[10].first = "cycle"; | |
| 65 | ✗ | m_units[10].second = exponents.m_cycle; | |
| 66 | ✗ | m_units[11].first = "$"; | |
| 67 | ✗ | m_units[11].second = exponents.m_dollar; | |
| 68 | ✗ | } | |
| 69 | |||
| 70 | 133 | Unit ThermUnit_Impl::clone() const { | |
| 71 |
3/5✓ Branch 1 taken 133 times.
✓ Branch 4 taken 133 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 133 times.
✗ Branch 10 not taken.
|
133 | OS_ASSERT(system() == UnitSystem::Therm); |
| 72 |
3/5✓ Branch 1 taken 133 times.
✓ Branch 4 taken 133 times.
✓ Branch 7 taken 133 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
133 | std::shared_ptr<ThermUnit_Impl> impl(new ThermUnit_Impl(*this)); |
| 73 |
2/2✓ Branch 2 taken 133 times.
✓ Branch 5 taken 133 times.
|
266 | return ThermUnit(impl).cast<Unit>(); |
| 74 | 133 | } | |
| 75 | |||
| 76 | 48 | void ThermUnit_Impl::setBaseUnitExponent(const std::string& baseUnit, int exponent) { | |
| 77 |
1/1✓ Branch 1 taken 48 times.
|
48 | auto loc = findBaseUnit(baseUnit); |
| 78 |
1/2✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | if (loc != m_units.end()) { |
| 79 | 48 | loc->second = exponent; | |
| 80 | } else { | ||
| 81 | ✗ | LOG_AND_THROW("Cannot add base units to an instance of ThermUnit."); | |
| 82 | } | ||
| 83 | 48 | } | |
| 84 | |||
| 85 | } // namespace detail | ||
| 86 | |||
| 87 | 1226 | ThermUnit::ThermUnit(const ThermExpnt& exponents, int scaleExponent, const std::string& prettyString) | |
| 88 |
4/6✓ Branch 1 taken 1226 times.
✓ Branch 4 taken 1226 times.
✓ Branch 7 taken 1226 times.
✓ Branch 10 taken 1226 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
1226 | : Unit(std::shared_ptr<detail::Unit_Impl>(new detail::ThermUnit_Impl(exponents, scaleExponent, prettyString))) {} |
| 89 | |||
| 90 | ✗ | ThermUnit::ThermUnit(const std::string& scaleAbbreviation, const ThermExpnt& exponents, const std::string& prettyString) | |
| 91 | ✗ | : Unit(std::shared_ptr<detail::Unit_Impl>(new detail::ThermUnit_Impl(scaleAbbreviation, exponents, prettyString))) {} | |
| 92 | |||
| 93 | /// @cond | ||
| 94 |
1/1✓ Branch 2 taken 133 times.
|
133 | ThermUnit::ThermUnit(std::shared_ptr<detail::ThermUnit_Impl> impl) : Unit(std::dynamic_pointer_cast<detail::Unit_Impl>(impl)) {} |
| 95 | /// @endcond | ||
| 96 | |||
| 97 | 100 | ThermUnit createThermEnergy() { | |
| 98 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return ThermUnit(ThermExpnt(1)); // therm |
| 99 | } | ||
| 100 | |||
| 101 | 108 | ThermUnit createThermLength() { | |
| 102 |
2/2✓ Branch 1 taken 108 times.
✓ Branch 5 taken 108 times.
|
216 | return ThermUnit(ThermExpnt(0, 1)); |
| 103 | } | ||
| 104 | |||
| 105 | 113 | ThermUnit createThermTime() { | |
| 106 |
2/2✓ Branch 1 taken 113 times.
✓ Branch 5 taken 113 times.
|
226 | return ThermUnit(ThermExpnt(0, 0, 1)); |
| 107 | } | ||
| 108 | |||
| 109 | 100 | ThermUnit createThermTemperature() { | |
| 110 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return ThermUnit(ThermExpnt(0, 0, 0, 1)); |
| 111 | } | ||
| 112 | |||
| 113 | 100 | ThermUnit createThermElectricCurrent() { | |
| 114 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return ThermUnit(ThermExpnt(0, 0, 0, 0, 1)); |
| 115 | } | ||
| 116 | |||
| 117 | 100 | ThermUnit createThermLuminousIntensity() { | |
| 118 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return ThermUnit(ThermExpnt(0, 0, 0, 0, 0, 1)); |
| 119 | } | ||
| 120 | |||
| 121 | 100 | ThermUnit createThermAmountOfSubstance() { | |
| 122 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return ThermUnit(ThermExpnt(0, 0, 0, 0, 0, 0, 1)); |
| 123 | } | ||
| 124 | |||
| 125 | 100 | ThermUnit createThermAngle() { | |
| 126 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return ThermUnit(ThermExpnt(0, 0, 0, 0, 0, 0, 0, 1)); |
| 127 | } | ||
| 128 | |||
| 129 | 100 | ThermUnit createThermSolidAngle() { | |
| 130 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return ThermUnit(ThermExpnt(0, 0, 0, 0, 0, 0, 0, 0, 1)); |
| 131 | } | ||
| 132 | |||
| 133 | 101 | ThermUnit createThermPeople() { | |
| 134 |
2/2✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
|
202 | return ThermUnit(ThermExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); |
| 135 | } | ||
| 136 | |||
| 137 | 100 | ThermUnit createThermCycle() { | |
| 138 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return ThermUnit(ThermExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); |
| 139 | } | ||
| 140 | |||
| 141 | ✗ | ThermUnit createThermCurrency() { | |
| 142 | ✗ | return ThermUnit(ThermExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); | |
| 143 | } | ||
| 144 | |||
| 145 | 100 | ThermUnit createThermLuminousFlux() { | |
| 146 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return ThermUnit(ThermExpnt(0, 0, 0, 0, 0, 1, 0, 0, 1), 0, "lm"); |
| 147 | } | ||
| 148 | |||
| 149 | } // namespace openstudio | ||
| 150 |