src/model/TableLookup.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 "TableLookup.hpp" | ||
| 7 | #include "TableLookup_Impl.hpp" | ||
| 8 | |||
| 9 | #include "ModelObjectList.hpp" | ||
| 10 | #include "ModelObjectList_Impl.hpp" | ||
| 11 | #include "TableIndependentVariable.hpp" | ||
| 12 | #include "TableIndependentVariable_Impl.hpp" | ||
| 13 | #include "Model.hpp" | ||
| 14 | #include "Model_Impl.hpp" | ||
| 15 | |||
| 16 | #include "../utilities/idf/IdfExtensibleGroup.hpp" | ||
| 17 | #include <utilities/idd/IddFactory.hxx> | ||
| 18 | |||
| 19 | #include <utilities/idd/OS_Table_Lookup_FieldEnums.hxx> | ||
| 20 | #include <utilities/idd/IddEnums.hxx> | ||
| 21 | |||
| 22 | #include "../utilities/units/Unit.hpp" | ||
| 23 | |||
| 24 | #include "../utilities/idf/WorkspaceExtensibleGroup.hpp" | ||
| 25 | #include "../utilities/core/Assert.hpp" | ||
| 26 | |||
| 27 | #include <algorithm> | ||
| 28 | #include <iomanip> | ||
| 29 | #include <limits> | ||
| 30 | |||
| 31 | namespace openstudio { | ||
| 32 | namespace model { | ||
| 33 | |||
| 34 | namespace detail { | ||
| 35 | |||
| 36 | 100 | TableLookup_Impl::TableLookup_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) : Curve_Impl(idfObject, model, keepHandle) { | |
| 37 |
4/6✓ Branch 1 taken 100 times.
✓ Branch 4 taken 100 times.
✓ Branch 7 taken 100 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 100 times.
✗ Branch 13 not taken.
|
100 | OS_ASSERT(idfObject.iddObject().type() == TableLookup::iddObjectType()); |
| 38 | 100 | } | |
| 39 | |||
| 40 | 11 | TableLookup_Impl::TableLookup_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 41 | 11 | : Curve_Impl(other, model, keepHandle) { | |
| 42 |
4/6✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 11 times.
✗ Branch 13 not taken.
|
11 | OS_ASSERT(other.iddObject().type() == TableLookup::iddObjectType()); |
| 43 | 11 | } | |
| 44 | |||
| 45 | 33 | TableLookup_Impl::TableLookup_Impl(const TableLookup_Impl& other, Model_Impl* model, bool keepHandle) : Curve_Impl(other, model, keepHandle) {} | |
| 46 | |||
| 47 | ✗ | const std::vector<std::string>& TableLookup_Impl::outputVariableNames() const { | |
| 48 | // Technically this is dependent on the actual number of independent variables used, but this is a staic one, and it's not worth the hassle | ||
| 49 | // (we could just mutate the static vector (and not make it const), still returning a const reference to it) | ||
| 50 | static const std::vector<std::string> result{ | ||
| 51 | "Performance Curve Output Value", "Performance Curve Input Variable 1 Value", "Performance Curve Input Variable 2 Value", | ||
| 52 | "Performance Curve Input Variable 3 Value", "Performance Curve Input Variable 4 Value", "Performance Curve Input Variable 5 Value", | ||
| 53 | ✗ | }; | |
| 54 | |||
| 55 | ✗ | return result; | |
| 56 | ✗ | } | |
| 57 | |||
| 58 | ✗ | IddObjectType TableLookup_Impl::iddObjectType() const { | |
| 59 | ✗ | return TableLookup::iddObjectType(); | |
| 60 | } | ||
| 61 | |||
| 62 | 24 | int TableLookup_Impl::numVariables() const { | |
| 63 |
1/1✓ Branch 1 taken 24 times.
|
24 | return independentVariables().size(); |
| 64 | } | ||
| 65 | |||
| 66 | ✗ | double TableLookup_Impl::evaluate(const std::vector<double>& /*independentVariables*/) const { | |
| 67 | ✗ | LOG(Warn, "Curve evaluation isn't implemented for TableLookup"); | |
| 68 | ✗ | return -9999.0; | |
| 69 | } | ||
| 70 | |||
| 71 | 14 | std::vector<ModelObject> TableLookup_Impl::children() const { | |
| 72 | // #4754 - in the case where we clone an object that uses this TableLookup as a resource into another model, | ||
| 73 | // we need the ModelObjectList to be a child of this object, so that ResourceObject::getRecursiveResourceSubTrees finds it | ||
| 74 | // (and the variables it references in a recursive manner) | ||
| 75 | 14 | std::vector<ModelObject> result; | |
| 76 |
3/3✓ Branch 1 taken 14 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 2 times.
|
28 | if (auto const varList_ = independentVariableList()) { |
| 77 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | result.push_back(varList_.get()); |
| 78 | 14 | } | |
| 79 | 14 | return result; | |
| 80 | ✗ | } | |
| 81 | |||
| 82 | 2 | ModelObject TableLookup_Impl::clone(Model model) const { | |
| 83 | |||
| 84 | // Call the ModelObject_Impl instead of ParentObject_Impl because we deal with the ModelObjectList ourselves | ||
| 85 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | auto modelObjectClone = ModelObject_Impl::clone(model).cast<TableLookup>(); // NOLINT |
| 86 | |||
| 87 | // ModelObjectList is kinda dumb, cloning it also clones the underlying objects regardless of whether they are resourceObjects or not | ||
| 88 | // We don't want that, so we make a new one, and populate it like the original | ||
| 89 |
1/1✓ Branch 1 taken 2 times.
|
2 | auto newVarList = ModelObjectList(model); |
| 90 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
|
2 | newVarList.setName(modelObjectClone.name().get() + " Independent Variable List"); |
| 91 |
2/2✓ Branch 3 taken 2 times.
✓ Branch 6 taken 2 times.
|
2 | bool ok = modelObjectClone.getImpl<detail::TableLookup_Impl>()->setIndependentVariableList(newVarList); |
| 92 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
|
2 | OS_ASSERT(ok); |
| 93 | |||
| 94 | // Now, the matter is to repopulate it. | ||
| 95 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 2 times.
|
4 | for (const TableIndependentVariable& var : this->independentVariables()) { |
| 96 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 1 time.
|
2 | if (model != this->model()) { |
| 97 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
1 | auto varClone = var.clone(model).cast<TableIndependentVariable>(); |
| 98 |
1/1✓ Branch 1 taken 1 time.
|
1 | modelObjectClone.addIndependentVariable(varClone); |
| 99 | 1 | } else { | |
| 100 | // Add that to the new object | ||
| 101 |
1/1✓ Branch 1 taken 1 time.
|
1 | modelObjectClone.addIndependentVariable(var); |
| 102 | } | ||
| 103 | 2 | } | |
| 104 | 4 | return std::move(modelObjectClone); | |
| 105 | 2 | } | |
| 106 | |||
| 107 | 2 | std::vector<IdfObject> TableLookup_Impl::remove() { | |
| 108 | 2 | std::vector<IdfObject> result; | |
| 109 | |||
| 110 | // ModelObjectList is kinda dumb, it removes all the modelObjects it has, which we don't want | ||
| 111 | // Instead we look at the independent variables listed, if they are used only once => delete them | ||
| 112 | // Then clear the modelObjectList, and remove it | ||
| 113 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
4 | if (boost::optional<ModelObjectList> varList = this->independentVariableList()) { |
| 114 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | auto vars = castVector<ResourceObject>(varList->modelObjects()); |
| 115 | |||
| 116 |
2/2✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
|
4 | for (auto& var : vars) { |
| 117 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | if (var.directUseCount() == 1) { |
| 118 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::vector<IdfObject> removedModelObject = var.remove(); |
| 119 |
1/1✓ Branch 5 taken 1 time.
|
1 | result.insert(result.end(), removedModelObject.begin(), removedModelObject.end()); |
| 120 | 1 | } | |
| 121 | } | ||
| 122 | |||
| 123 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | varList->clearExtensibleGroups(); // Clearer than removeAllModelObjects (which does the same thing, but could mean delete all objects) |
| 124 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | std::vector<IdfObject> removedVarList = varList->remove(); |
| 125 |
1/1✓ Branch 5 taken 2 times.
|
2 | result.insert(result.end(), removedVarList.begin(), removedVarList.end()); |
| 126 | 4 | } | |
| 127 | |||
| 128 |
1/1✓ Branch 1 taken 2 times.
|
2 | std::vector<IdfObject> removedObject = Curve_Impl::remove(); |
| 129 |
1/1✓ Branch 5 taken 2 times.
|
2 | result.insert(result.end(), removedObject.begin(), removedObject.end()); |
| 130 | |||
| 131 | 4 | return result; | |
| 132 | 2 | } | |
| 133 | |||
| 134 | 192 | boost::optional<ModelObjectList> TableLookup_Impl::independentVariableList() const { | |
| 135 |
2/2✓ Branch 1 taken 192 times.
✓ Branch 4 taken 192 times.
|
192 | return getObject<ModelObject>().getModelObjectTarget<ModelObjectList>(OS_Table_LookupFields::IndependentVariableListName); |
| 136 | } | ||
| 137 | |||
| 138 | 29 | std::string TableLookup_Impl::normalizationMethod() const { | |
| 139 |
1/1✓ Branch 1 taken 29 times.
|
29 | boost::optional<std::string> value = getString(OS_Table_LookupFields::NormalizationMethod, true); |
| 140 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✗ Branch 4 not taken.
|
29 | OS_ASSERT(value); |
| 141 |
2/2✓ Branch 1 taken 29 times.
✓ Branch 4 taken 29 times.
|
58 | return value.get(); |
| 142 | 29 | } | |
| 143 | |||
| 144 | 29 | double TableLookup_Impl::normalizationDivisor() const { | |
| 145 |
1/1✓ Branch 1 taken 29 times.
|
29 | boost::optional<double> value = getDouble(OS_Table_LookupFields::NormalizationDivisor, true); |
| 146 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✗ Branch 4 not taken.
|
29 | OS_ASSERT(value); |
| 147 |
1/1✓ Branch 1 taken 29 times.
|
58 | return value.get(); |
| 148 | } | ||
| 149 | |||
| 150 | 15 | boost::optional<double> TableLookup_Impl::minimumOutput() const { | |
| 151 | 15 | return getDouble(OS_Table_LookupFields::MinimumOutput, true); | |
| 152 | } | ||
| 153 | |||
| 154 | 15 | boost::optional<double> TableLookup_Impl::maximumOutput() const { | |
| 155 | 15 | return getDouble(OS_Table_LookupFields::MaximumOutput, true); | |
| 156 | } | ||
| 157 | |||
| 158 | 13 | std::string TableLookup_Impl::outputUnitType() const { | |
| 159 |
1/1✓ Branch 1 taken 13 times.
|
13 | boost::optional<std::string> value = getString(OS_Table_LookupFields::OutputUnitType, true); |
| 160 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 4 not taken.
|
13 | OS_ASSERT(value); |
| 161 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
|
26 | return value.get(); |
| 162 | 13 | } | |
| 163 | |||
| 164 | 101 | bool TableLookup_Impl::setNormalizationMethod(const std::string& normalizationMethod) { | |
| 165 | 101 | bool result = setString(OS_Table_LookupFields::NormalizationMethod, normalizationMethod); | |
| 166 | 101 | return result; | |
| 167 | } | ||
| 168 | |||
| 169 | 101 | bool TableLookup_Impl::setNormalizationDivisor(double normalizationDivisor) { | |
| 170 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 3 taken 100 times.
|
101 | if (std::abs(normalizationDivisor) < std::numeric_limits<double>::min()) { |
| 171 |
8/8✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 17 taken 1 time.
✓ Branch 20 taken 1 time.
✓ Branch 23 taken 1 time.
|
1 | LOG(Warn, "Unable to set " << briefDescription() << "'s Normalization divisor to zero."); |
| 172 | 1 | return false; | |
| 173 | } | ||
| 174 | |||
| 175 | 100 | bool result = setDouble(OS_Table_LookupFields::NormalizationDivisor, normalizationDivisor); | |
| 176 | 100 | return result; | |
| 177 | } | ||
| 178 | |||
| 179 | 50 | bool TableLookup_Impl::setMinimumOutput(double minimumOutput) { | |
| 180 | 50 | bool result = setDouble(OS_Table_LookupFields::MinimumOutput, minimumOutput); | |
| 181 | 50 | return result; | |
| 182 | } | ||
| 183 | |||
| 184 | 1 | void TableLookup_Impl::resetMinimumOutput() { | |
| 185 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | bool result = setString(OS_Table_LookupFields::MinimumOutput, ""); |
| 186 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | OS_ASSERT(result); |
| 187 | 1 | } | |
| 188 | |||
| 189 | 50 | bool TableLookup_Impl::setMaximumOutput(double maximumOutput) { | |
| 190 | 50 | bool result = setDouble(OS_Table_LookupFields::MaximumOutput, maximumOutput); | |
| 191 | 50 | return result; | |
| 192 | } | ||
| 193 | |||
| 194 | 1 | void TableLookup_Impl::resetMaximumOutput() { | |
| 195 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | bool result = setString(OS_Table_LookupFields::MaximumOutput, ""); |
| 196 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | OS_ASSERT(result); |
| 197 | 1 | } | |
| 198 | |||
| 199 | 140 | bool TableLookup_Impl::setOutputUnitType(const std::string& outputUnitType) { | |
| 200 | 140 | bool result = setString(OS_Table_LookupFields::OutputUnitType, outputUnitType); | |
| 201 | 140 | return result; | |
| 202 | } | ||
| 203 | |||
| 204 | 300 | bool TableLookup_Impl::addOutputValue(double outputValue) { | |
| 205 |
3/3✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
✓ Branch 7 taken 300 times.
|
300 | auto eg = getObject<ModelObject>().pushExtensibleGroup().cast<WorkspaceExtensibleGroup>(); |
| 206 |
1/1✓ Branch 1 taken 300 times.
|
300 | bool result = eg.setDouble(OS_Table_LookupExtensibleFields::OutputValue, outputValue); |
| 207 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 300 times.
|
300 | if (!result) { |
| 208 | ✗ | getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex()); | |
| 209 | } | ||
| 210 | |||
| 211 | 300 | return result; | |
| 212 | 300 | } | |
| 213 | |||
| 214 | 1 | bool TableLookup_Impl::removeOutputValue(unsigned groupIndex) { | |
| 215 | bool result; | ||
| 216 | |||
| 217 | 1 | unsigned num = numberofOutputValues(); | |
| 218 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | if (groupIndex < num) { |
| 219 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | getObject<ModelObject>().eraseExtensibleGroup(groupIndex); |
| 220 | 1 | result = true; | |
| 221 | } else { | ||
| 222 | ✗ | result = false; | |
| 223 | } | ||
| 224 | 1 | return result; | |
| 225 | } | ||
| 226 | |||
| 227 | 1 | void TableLookup_Impl::removeAllOutputValues() { | |
| 228 |
1/1✓ Branch 1 taken 1 time.
|
1 | this->clearExtensibleGroups(); |
| 229 | 1 | } | |
| 230 | |||
| 231 | 51 | std::vector<double> TableLookup_Impl::outputValues() const { | |
| 232 | 51 | std::vector<double> result; | |
| 233 |
3/3✓ Branch 1 taken 51 times.
✓ Branch 8 taken 148 times.
✓ Branch 9 taken 51 times.
|
199 | for (const auto& eg : extensibleGroups()) { |
| 234 |
1/1✓ Branch 1 taken 148 times.
|
148 | auto _d = eg.getDouble(OS_Table_LookupExtensibleFields::OutputValue); |
| 235 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 148 times.
✗ Branch 4 not taken.
|
148 | OS_ASSERT(_d); |
| 236 |
2/2✓ Branch 1 taken 148 times.
✓ Branch 4 taken 148 times.
|
148 | result.push_back(_d.get()); |
| 237 | 51 | } | |
| 238 | 51 | return result; | |
| 239 | ✗ | } | |
| 240 | |||
| 241 | 4 | unsigned TableLookup_Impl::numberofOutputValues() const { | |
| 242 | 4 | return numExtensibleGroups(); | |
| 243 | } | ||
| 244 | |||
| 245 | 45 | bool TableLookup_Impl::setOutputValues(const std::vector<double>& outputValues) { | |
| 246 | 45 | bool result = true; | |
| 247 | |||
| 248 |
1/1✓ Branch 1 taken 45 times.
|
45 | this->clearExtensibleGroups(); |
| 249 |
2/2✓ Branch 4 taken 232 times.
✓ Branch 5 taken 45 times.
|
277 | for (const auto& val : outputValues) { |
| 250 |
1/1✓ Branch 1 taken 232 times.
|
232 | result &= addOutputValue(val); |
| 251 | } | ||
| 252 | 45 | return result; | |
| 253 | } | ||
| 254 | |||
| 255 | 70 | bool TableLookup_Impl::addIndependentVariable(const TableIndependentVariable& tableIndependentVariable) { | |
| 256 | 70 | bool result = false; | |
| 257 |
1/1✓ Branch 1 taken 70 times.
|
70 | auto modelObjectList = independentVariableList(); |
| 258 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | if (modelObjectList) { |
| 259 |
2/2✓ Branch 1 taken 70 times.
✓ Branch 4 taken 70 times.
|
70 | result = modelObjectList->addModelObject(tableIndependentVariable); |
| 260 | } | ||
| 261 | 70 | return result; | |
| 262 | 70 | } | |
| 263 | |||
| 264 | 1 | bool TableLookup_Impl::removeIndependentVariable(const TableIndependentVariable& tableIndependentVariable) { | |
| 265 | 1 | bool result = false; | |
| 266 |
1/1✓ Branch 1 taken 1 time.
|
1 | auto modelObjectList = independentVariableList(); |
| 267 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | if (modelObjectList) { |
| 268 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | modelObjectList->removeModelObject(tableIndependentVariable); |
| 269 | 1 | result = true; | |
| 270 | } | ||
| 271 | 1 | return result; | |
| 272 | 1 | } | |
| 273 | |||
| 274 | 1 | void TableLookup_Impl::removeAllIndependentVariables() { | |
| 275 |
1/1✓ Branch 1 taken 1 time.
|
1 | auto modelObjectList = independentVariableList(); |
| 276 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | if (modelObjectList) { |
| 277 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | auto const modelObjects = modelObjectList->modelObjects(); |
| 278 | |||
| 279 |
2/2✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1 time.
|
3 | for (const auto& elem : modelObjects) { |
| 280 |
1/1✓ Branch 1 taken 2 times.
|
2 | auto const modelObject = elem.optionalCast<TableIndependentVariable>(); |
| 281 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (modelObject) { |
| 282 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | modelObjectList->removeModelObject(elem); |
| 283 | } | ||
| 284 | 2 | } | |
| 285 | 1 | } | |
| 286 | 1 | } | |
| 287 | |||
| 288 | 104 | std::vector<TableIndependentVariable> TableLookup_Impl::independentVariables() const { | |
| 289 | 104 | std::vector<TableIndependentVariable> result; | |
| 290 |
1/1✓ Branch 1 taken 104 times.
|
104 | auto const modelObjectList = independentVariableList(); |
| 291 |
1/2✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
|
104 | if (modelObjectList) { |
| 292 |
2/2✓ Branch 1 taken 104 times.
✓ Branch 4 taken 104 times.
|
104 | auto const modelObjects = modelObjectList->modelObjects(); |
| 293 | |||
| 294 |
2/2✓ Branch 5 taken 108 times.
✓ Branch 6 taken 104 times.
|
212 | for (const auto& elem : modelObjects) { |
| 295 |
1/1✓ Branch 1 taken 108 times.
|
108 | auto const modelObject = elem.optionalCast<TableIndependentVariable>(); |
| 296 |
1/2✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
|
108 | if (modelObject) { |
| 297 |
2/2✓ Branch 1 taken 108 times.
✓ Branch 4 taken 108 times.
|
108 | result.push_back(modelObject.get()); |
| 298 | } | ||
| 299 | 108 | } | |
| 300 | 104 | } | |
| 301 | 208 | return result; | |
| 302 | 104 | } | |
| 303 | |||
| 304 | 91 | bool TableLookup_Impl::setIndependentVariableList(const boost::optional<ModelObjectList>& modelObjectList) { | |
| 305 | 91 | bool result(false); | |
| 306 |
1/2✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
|
91 | if (modelObjectList) { |
| 307 |
3/3✓ Branch 1 taken 91 times.
✓ Branch 4 taken 91 times.
✓ Branch 7 taken 91 times.
|
91 | result = setPointer(OS_Table_LookupFields::IndependentVariableListName, modelObjectList.get().handle()); |
| 308 | } else { | ||
| 309 | ✗ | resetIndependentVariableList(); | |
| 310 | ✗ | result = true; | |
| 311 | } | ||
| 312 | 91 | return result; | |
| 313 | } | ||
| 314 | |||
| 315 | ✗ | void TableLookup_Impl::resetIndependentVariableList() { | |
| 316 | ✗ | bool result = setString(OS_Table_LookupFields::IndependentVariableListName, ""); | |
| 317 | ✗ | OS_ASSERT(result); | |
| 318 | ✗ | } | |
| 319 | |||
| 320 | } // namespace detail | ||
| 321 | |||
| 322 | 89 | TableLookup::TableLookup(const Model& model) : Curve(TableLookup::iddObjectType(), model) { | |
| 323 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 89 times.
✗ Branch 5 not taken.
|
89 | OS_ASSERT(getImpl<detail::TableLookup_Impl>()); |
| 324 | |||
| 325 | 89 | bool ok = true; | |
| 326 |
2/2✓ Branch 1 taken 89 times.
✓ Branch 4 taken 89 times.
|
89 | ok = setNormalizationMethod("None"); |
| 327 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 89 times.
✗ Branch 3 not taken.
|
89 | OS_ASSERT(ok); |
| 328 |
1/1✓ Branch 1 taken 89 times.
|
89 | ok = setNormalizationDivisor(1.0); |
| 329 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 89 times.
✗ Branch 3 not taken.
|
89 | OS_ASSERT(ok); |
| 330 |
2/2✓ Branch 1 taken 89 times.
✓ Branch 4 taken 89 times.
|
89 | ok = setOutputUnitType("Dimensionless"); |
| 331 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 89 times.
✗ Branch 3 not taken.
|
89 | OS_ASSERT(ok); |
| 332 | |||
| 333 |
1/1✓ Branch 1 taken 89 times.
|
89 | auto tableIndependentVariableList = ModelObjectList(model); |
| 334 |
4/4✓ Branch 1 taken 89 times.
✓ Branch 4 taken 89 times.
✓ Branch 7 taken 89 times.
✓ Branch 10 taken 89 times.
|
89 | tableIndependentVariableList.setName(this->name().get() + " Independent Variable List"); |
| 335 |
2/2✓ Branch 3 taken 89 times.
✓ Branch 6 taken 89 times.
|
89 | ok = getImpl<detail::TableLookup_Impl>()->setIndependentVariableList(tableIndependentVariableList); |
| 336 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 89 times.
✗ Branch 3 not taken.
|
89 | OS_ASSERT(ok); |
| 337 | 89 | } | |
| 338 | |||
| 339 | 7815 | IddObjectType TableLookup::iddObjectType() { | |
| 340 |
1/1✓ Branch 1 taken 7815 times.
|
7815 | return {IddObjectType::OS_Table_Lookup}; |
| 341 | } | ||
| 342 | |||
| 343 | ✗ | std::vector<std::string> TableLookup::normalizationMethodValues() { | |
| 344 | ✗ | return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Table_LookupFields::NormalizationMethod); | |
| 345 | } | ||
| 346 | |||
| 347 | ✗ | std::vector<std::string> TableLookup::validNormalizationMethodValues() { | |
| 348 | ✗ | return normalizationMethodValues(); | |
| 349 | } | ||
| 350 | |||
| 351 | ✗ | std::vector<std::string> TableLookup::outputUnitTypeValues() { | |
| 352 | ✗ | return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Table_LookupFields::OutputUnitType); | |
| 353 | } | ||
| 354 | |||
| 355 | ✗ | std::vector<std::string> TableLookup::validOutputUnitTypeValues() { | |
| 356 | ✗ | return outputUnitTypeValues(); | |
| 357 | } | ||
| 358 | |||
| 359 | 29 | std::string TableLookup::normalizationMethod() const { | |
| 360 |
1/1✓ Branch 3 taken 29 times.
|
29 | return getImpl<detail::TableLookup_Impl>()->normalizationMethod(); |
| 361 | } | ||
| 362 | |||
| 363 | 29 | double TableLookup::normalizationDivisor() const { | |
| 364 |
1/1✓ Branch 3 taken 29 times.
|
29 | return getImpl<detail::TableLookup_Impl>()->normalizationDivisor(); |
| 365 | } | ||
| 366 | |||
| 367 | 15 | boost::optional<double> TableLookup::minimumOutput() const { | |
| 368 |
1/1✓ Branch 3 taken 15 times.
|
15 | return getImpl<detail::TableLookup_Impl>()->minimumOutput(); |
| 369 | } | ||
| 370 | |||
| 371 | 15 | boost::optional<double> TableLookup::maximumOutput() const { | |
| 372 |
1/1✓ Branch 3 taken 15 times.
|
15 | return getImpl<detail::TableLookup_Impl>()->maximumOutput(); |
| 373 | } | ||
| 374 | |||
| 375 | 13 | std::string TableLookup::outputUnitType() const { | |
| 376 |
1/1✓ Branch 3 taken 13 times.
|
13 | return getImpl<detail::TableLookup_Impl>()->outputUnitType(); |
| 377 | } | ||
| 378 | |||
| 379 | 101 | bool TableLookup::setNormalizationMethod(const std::string& normalizationMethod) { | |
| 380 |
1/1✓ Branch 3 taken 101 times.
|
101 | return getImpl<detail::TableLookup_Impl>()->setNormalizationMethod(normalizationMethod); |
| 381 | } | ||
| 382 | |||
| 383 | 101 | bool TableLookup::setNormalizationDivisor(double normalizationDivisor) { | |
| 384 |
1/1✓ Branch 3 taken 101 times.
|
101 | return getImpl<detail::TableLookup_Impl>()->setNormalizationDivisor(normalizationDivisor); |
| 385 | } | ||
| 386 | |||
| 387 | 50 | bool TableLookup::setMinimumOutput(double minimumOutput) { | |
| 388 |
1/1✓ Branch 3 taken 50 times.
|
50 | return getImpl<detail::TableLookup_Impl>()->setMinimumOutput(minimumOutput); |
| 389 | } | ||
| 390 | |||
| 391 | 1 | void TableLookup::resetMinimumOutput() { | |
| 392 |
1/1✓ Branch 3 taken 1 time.
|
1 | getImpl<detail::TableLookup_Impl>()->resetMinimumOutput(); |
| 393 | 1 | } | |
| 394 | |||
| 395 | 50 | bool TableLookup::setMaximumOutput(double maximumOutput) { | |
| 396 |
1/1✓ Branch 3 taken 50 times.
|
50 | return getImpl<detail::TableLookup_Impl>()->setMaximumOutput(maximumOutput); |
| 397 | } | ||
| 398 | |||
| 399 | 1 | void TableLookup::resetMaximumOutput() { | |
| 400 |
1/1✓ Branch 3 taken 1 time.
|
1 | getImpl<detail::TableLookup_Impl>()->resetMaximumOutput(); |
| 401 | 1 | } | |
| 402 | |||
| 403 | 140 | bool TableLookup::setOutputUnitType(const std::string& outputUnitType) { | |
| 404 |
1/1✓ Branch 3 taken 140 times.
|
140 | return getImpl<detail::TableLookup_Impl>()->setOutputUnitType(outputUnitType); |
| 405 | } | ||
| 406 | |||
| 407 | 68 | bool TableLookup::addOutputValue(double outputValue) { | |
| 408 |
1/1✓ Branch 3 taken 68 times.
|
68 | return getImpl<detail::TableLookup_Impl>()->addOutputValue(outputValue); |
| 409 | } | ||
| 410 | |||
| 411 | 1 | bool TableLookup::removeOutputValue(unsigned groupIndex) { | |
| 412 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::TableLookup_Impl>()->removeOutputValue(groupIndex); |
| 413 | } | ||
| 414 | |||
| 415 | 1 | void TableLookup::removeAllOutputValues() { | |
| 416 |
1/1✓ Branch 3 taken 1 time.
|
1 | getImpl<detail::TableLookup_Impl>()->removeAllOutputValues(); |
| 417 | 1 | } | |
| 418 | |||
| 419 | 51 | std::vector<double> TableLookup::outputValues() const { | |
| 420 |
1/1✓ Branch 3 taken 51 times.
|
51 | return getImpl<detail::TableLookup_Impl>()->outputValues(); |
| 421 | } | ||
| 422 | |||
| 423 | 3 | unsigned TableLookup::numberofOutputValues() const { | |
| 424 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::TableLookup_Impl>()->numberofOutputValues(); |
| 425 | } | ||
| 426 | |||
| 427 | 45 | bool TableLookup::setOutputValues(const std::vector<double>& outputValues) { | |
| 428 |
1/1✓ Branch 3 taken 45 times.
|
45 | return getImpl<detail::TableLookup_Impl>()->setOutputValues(outputValues); |
| 429 | } | ||
| 430 | |||
| 431 | 70 | bool TableLookup::addIndependentVariable(const TableIndependentVariable& tableIndependentVariable) { | |
| 432 |
1/1✓ Branch 3 taken 70 times.
|
70 | return getImpl<detail::TableLookup_Impl>()->addIndependentVariable(tableIndependentVariable); |
| 433 | } | ||
| 434 | |||
| 435 | 1 | bool TableLookup::removeIndependentVariable(const TableIndependentVariable& tableIndependentVariable) { | |
| 436 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::TableLookup_Impl>()->removeIndependentVariable(tableIndependentVariable); |
| 437 | } | ||
| 438 | |||
| 439 | 1 | void TableLookup::removeAllIndependentVariables() { | |
| 440 |
1/1✓ Branch 3 taken 1 time.
|
1 | getImpl<detail::TableLookup_Impl>()->removeAllIndependentVariables(); |
| 441 | 1 | } | |
| 442 | |||
| 443 | 78 | std::vector<TableIndependentVariable> TableLookup::independentVariables() const { | |
| 444 |
1/1✓ Branch 3 taken 78 times.
|
78 | return getImpl<detail::TableLookup_Impl>()->independentVariables(); |
| 445 | } | ||
| 446 | |||
| 447 | /// @cond | ||
| 448 |
1/1✓ Branch 3 taken 78 times.
|
78 | TableLookup::TableLookup(std::shared_ptr<detail::TableLookup_Impl> impl) : Curve(std::dynamic_pointer_cast<detail::Curve_Impl>(std::move(impl))) {} |
| 449 | /// @endcond | ||
| 450 | |||
| 451 | } // namespace model | ||
| 452 | } // namespace openstudio | ||
| 453 |