src/model/Timestep.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 "Timestep.hpp" | ||
| 7 | #include "Timestep_Impl.hpp" | ||
| 8 | #include "SimulationControl.hpp" | ||
| 9 | #include "SimulationControl_Impl.hpp" | ||
| 10 | #include "Model.hpp" | ||
| 11 | #include "Model_Impl.hpp" | ||
| 12 | #include "ScheduleDay.hpp" | ||
| 13 | #include "ScheduleDay_Impl.hpp" | ||
| 14 | #include "../utilities/core/Assert.hpp" | ||
| 15 | #include <utilities/idd/OS_Timestep_FieldEnums.hxx> | ||
| 16 | #include <utilities/idd/IddEnums.hxx> | ||
| 17 | |||
| 18 | namespace openstudio { | ||
| 19 | |||
| 20 | namespace model { | ||
| 21 | |||
| 22 | namespace detail { | ||
| 23 | |||
| 24 | 1201 | Timestep_Impl::Timestep_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) : ModelObject_Impl(idfObject, model, keepHandle) { | |
| 25 |
4/6✓ Branch 1 taken 1201 times.
✓ Branch 4 taken 1201 times.
✓ Branch 7 taken 1201 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1201 times.
✗ Branch 13 not taken.
|
1201 | OS_ASSERT(idfObject.iddObject().type() == Timestep::iddObjectType()); |
| 26 | 1201 | } | |
| 27 | |||
| 28 | 64 | Timestep_Impl::Timestep_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 29 | 64 | : ModelObject_Impl(other, model, keepHandle) { | |
| 30 |
4/6✓ Branch 1 taken 64 times.
✓ Branch 4 taken 64 times.
✓ Branch 7 taken 64 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 64 times.
✗ Branch 13 not taken.
|
64 | OS_ASSERT(other.iddObject().type() == Timestep::iddObjectType()); |
| 31 | 64 | } | |
| 32 | |||
| 33 | 121 | Timestep_Impl::Timestep_Impl(const Timestep_Impl& other, Model_Impl* model, bool keepHandle) : ModelObject_Impl(other, model, keepHandle) {} | |
| 34 | |||
| 35 | 8 | IddObjectType Timestep_Impl::iddObjectType() const { | |
| 36 | 8 | return Timestep::iddObjectType(); | |
| 37 | } | ||
| 38 | |||
| 39 | // return the parent object in the hierarchy | ||
| 40 | 3 | boost::optional<ParentObject> Timestep_Impl::parent() const { | |
| 41 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | boost::optional<ParentObject> result(model().getUniqueModelObject<SimulationControl>()); |
| 42 | 3 | return result; | |
| 43 | } | ||
| 44 | |||
| 45 | // set the parent, child may have to call methods on the parent | ||
| 46 | ✗ | bool Timestep_Impl::setParent(ParentObject& newParent) { | |
| 47 | ✗ | if (newParent.optionalCast<SimulationControl>() && (newParent.model() == model())) { | |
| 48 | ✗ | return true; | |
| 49 | } | ||
| 50 | ✗ | return false; | |
| 51 | } | ||
| 52 | |||
| 53 | // TODO: remove | ||
| 54 | 1 | const std::vector<std::string>& Timestep_Impl::outputVariableNames() const { | |
| 55 |
2/4✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
|
1 | static const std::vector<std::string> result; |
| 56 | // Not appropriate: no specific output | ||
| 57 | 1 | return result; | |
| 58 | } | ||
| 59 | |||
| 60 | 2054 | int Timestep_Impl::numberOfTimestepsPerHour() const { | |
| 61 |
1/1✓ Branch 1 taken 2054 times.
|
2054 | boost::optional<int> value = getInt(OS_TimestepFields::NumberofTimestepsperHour, true); |
| 62 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2054 times.
✗ Branch 4 not taken.
|
2054 | OS_ASSERT(value); |
| 63 |
1/1✓ Branch 1 taken 2054 times.
|
4108 | return value.get(); |
| 64 | } | ||
| 65 | |||
| 66 | ✗ | bool Timestep_Impl::isNumberOfTimestepsPerHourDefaulted() const { | |
| 67 | ✗ | return isEmpty(OS_TimestepFields::NumberofTimestepsperHour); | |
| 68 | } | ||
| 69 | |||
| 70 | 1150 | bool Timestep_Impl::setNumberOfTimestepsPerHour(int numberOfTimestepsPerHour) { | |
| 71 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 1136 times.
|
1150 | if (numberOfTimestepsPerHour != this->numberOfTimestepsPerHour()) { |
| 72 |
4/4✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
✓ Branch 11 taken 179 times.
✓ Branch 12 taken 14 times.
|
193 | for (auto& sch_day : model().getConcreteModelObjects<ScheduleDay>()) { |
| 73 |
1/1✓ Branch 3 taken 179 times.
|
179 | sch_day.getImpl<ScheduleDay_Impl>()->clearCachedTimeSeries(); |
| 74 | 14 | } | |
| 75 | } | ||
| 76 | 1150 | bool result = setInt(OS_TimestepFields::NumberofTimestepsperHour, numberOfTimestepsPerHour); | |
| 77 | 1150 | return result; | |
| 78 | } | ||
| 79 | |||
| 80 | ✗ | void Timestep_Impl::resetNumberOfTimestepsPerHour() { | |
| 81 | ✗ | for (auto& sch_day : model().getConcreteModelObjects<ScheduleDay>()) { | |
| 82 | ✗ | sch_day.getImpl<ScheduleDay_Impl>()->clearCachedTimeSeries(); | |
| 83 | ✗ | } | |
| 84 | ✗ | bool result = setString(OS_TimestepFields::NumberofTimestepsperHour, ""); | |
| 85 | ✗ | OS_ASSERT(result); | |
| 86 | ✗ | } | |
| 87 | |||
| 88 | } // namespace detail | ||
| 89 | |||
| 90 | /// constructor | ||
| 91 | 1136 | Timestep::Timestep(const Model& model) : ModelObject(Timestep::iddObjectType(), model) { | |
| 92 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 1136 times.
✗ Branch 5 not taken.
|
1136 | OS_ASSERT(getImpl<detail::Timestep_Impl>()); |
| 93 | |||
| 94 |
1/1✓ Branch 1 taken 1136 times.
|
1136 | setNumberOfTimestepsPerHour(6); |
| 95 | 1136 | } | |
| 96 | |||
| 97 | // constructor | ||
| 98 |
1/1✓ Branch 3 taken 1823 times.
|
1823 | Timestep::Timestep(std::shared_ptr<detail::Timestep_Impl> impl) : ModelObject(std::move(impl)) {} |
| 99 | |||
| 100 | 12103 | IddObjectType Timestep::iddObjectType() { | |
| 101 |
1/1✓ Branch 1 taken 12103 times.
|
12103 | IddObjectType result(IddObjectType::OS_Timestep); |
| 102 | 12103 | return result; | |
| 103 | } | ||
| 104 | |||
| 105 | 904 | int Timestep::numberOfTimestepsPerHour() const { | |
| 106 |
1/1✓ Branch 3 taken 904 times.
|
904 | return getImpl<detail::Timestep_Impl>()->numberOfTimestepsPerHour(); |
| 107 | } | ||
| 108 | |||
| 109 | ✗ | bool Timestep::isNumberOfTimestepsPerHourDefaulted() const { | |
| 110 | ✗ | return getImpl<detail::Timestep_Impl>()->isNumberOfTimestepsPerHourDefaulted(); | |
| 111 | } | ||
| 112 | |||
| 113 | 1150 | bool Timestep::setNumberOfTimestepsPerHour(int numberOfTimestepsPerHour) { | |
| 114 |
1/1✓ Branch 3 taken 1150 times.
|
1150 | return getImpl<detail::Timestep_Impl>()->setNumberOfTimestepsPerHour(numberOfTimestepsPerHour); |
| 115 | } | ||
| 116 | |||
| 117 | ✗ | void Timestep::resetNumberOfTimestepsPerHour() { | |
| 118 | ✗ | getImpl<detail::Timestep_Impl>()->resetNumberOfTimestepsPerHour(); | |
| 119 | ✗ | } | |
| 120 | |||
| 121 | } // namespace model | ||
| 122 | } // namespace openstudio | ||
| 123 |