GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 68.4% 39 / 0 / 57
Functions: 72.2% 13 / 0 / 18
Branches: 40.3% 29 / 0 / 72

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 1215 Timestep_Impl::Timestep_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) : ModelObject_Impl(idfObject, model, keepHandle) {
25
4/6
✓ Branch 1 taken 1215 times.
✓ Branch 4 taken 1215 times.
✓ Branch 7 taken 1215 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1215 times.
✗ Branch 13 not taken.
1215 OS_ASSERT(idfObject.iddObject().type() == Timestep::iddObjectType());
26 1215 }
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 2082 int Timestep_Impl::numberOfTimestepsPerHour() const {
61
1/1
✓ Branch 1 taken 2082 times.
2082 boost::optional<int> value = getInt(OS_TimestepFields::NumberofTimestepsperHour, true);
62
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 2082 times.
✗ Branch 4 not taken.
2082 OS_ASSERT(value);
63
1/1
✓ Branch 1 taken 2082 times.
4164 return value.get();
64 }
65
66 ✗ bool Timestep_Impl::isNumberOfTimestepsPerHourDefaulted() const {
67 ✗ return isEmpty(OS_TimestepFields::NumberofTimestepsperHour);
68 }
69
70 1164 bool Timestep_Impl::setNumberOfTimestepsPerHour(int numberOfTimestepsPerHour) {
71
2/2
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 1150 times.
1164 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 1164 bool result = setInt(OS_TimestepFields::NumberofTimestepsperHour, numberOfTimestepsPerHour);
77 1164 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 1150 Timestep::Timestep(const Model& model) : ModelObject(Timestep::iddObjectType(), model) {
92
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 1150 times.
✗ Branch 5 not taken.
1150 OS_ASSERT(getImpl<detail::Timestep_Impl>());
93
94
1/1
✓ Branch 1 taken 1150 times.
1150 setNumberOfTimestepsPerHour(6);
95 1150 }
96
97 // constructor
98
1/1
✓ Branch 3 taken 1851 times.
1851 Timestep::Timestep(std::shared_ptr<detail::Timestep_Impl> impl) : ModelObject(std::move(impl)) {}
99
100 12289 IddObjectType Timestep::iddObjectType() {
101
1/1
✓ Branch 1 taken 12289 times.
12289 IddObjectType result(IddObjectType::OS_Timestep);
102 12289 return result;
103 }
104
105 918 int Timestep::numberOfTimestepsPerHour() const {
106
1/1
✓ Branch 3 taken 918 times.
918 return getImpl<detail::Timestep_Impl>()->numberOfTimestepsPerHour();
107 }
108
109 ✗ bool Timestep::isNumberOfTimestepsPerHourDefaulted() const {
110 ✗ return getImpl<detail::Timestep_Impl>()->isNumberOfTimestepsPerHourDefaulted();
111 }
112
113 1164 bool Timestep::setNumberOfTimestepsPerHour(int numberOfTimestepsPerHour) {
114
1/1
✓ Branch 3 taken 1164 times.
1164 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