src/energyplus/ReverseTranslator/ReverseTranslateConstructionWithInternalSource.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 "../ReverseTranslator.hpp" | ||
| 7 | |||
| 8 | #include "../../model/ConstructionWithInternalSource.hpp" | ||
| 9 | #include "../../model/ConstructionWithInternalSource_Impl.hpp" | ||
| 10 | #include "../../model/OpaqueMaterial.hpp" | ||
| 11 | #include "../../model/OpaqueMaterial_Impl.hpp" | ||
| 12 | #include "../../model/FenestrationMaterial.hpp" | ||
| 13 | #include "../../model/FenestrationMaterial_Impl.hpp" | ||
| 14 | #include "../../model/ModelPartitionMaterial.hpp" | ||
| 15 | #include "../../model/ModelPartitionMaterial_Impl.hpp" | ||
| 16 | #include "../../utilities/idf/WorkspaceExtensibleGroup.hpp" | ||
| 17 | |||
| 18 | #include <utilities/idd/Construction_FieldEnums.hxx> | ||
| 19 | #include <utilities/idd/ConstructionProperty_InternalHeatSource_FieldEnums.hxx> | ||
| 20 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 21 | #include <utilities/idd/IddEnums.hxx> | ||
| 22 | |||
| 23 | #include "../../utilities/core/Assert.hpp" | ||
| 24 | |||
| 25 | using namespace openstudio::model; | ||
| 26 | |||
| 27 | namespace openstudio { | ||
| 28 | |||
| 29 | namespace energyplus { | ||
| 30 | |||
| 31 | 2 | OptionalModelObject ReverseTranslator::translateConstructionWithInternalSource(const WorkspaceObject& workspaceObject) { | |
| 32 |
4/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
|
2 | if (workspaceObject.iddObject().type() != IddObjectType::ConstructionProperty_InternalHeatSource) { |
| 33 | ✗ | LOG(Error, "WorkspaceObject is not IddObjectType: ConstructionProperty_InternalHeatSource"); | |
| 34 | ✗ | return boost::none; | |
| 35 | } | ||
| 36 | |||
| 37 | // Construction Name | ||
| 38 |
1/1✓ Branch 1 taken 2 times.
|
2 | OptionalWorkspaceObject wo_construction = workspaceObject.getTarget(ConstructionProperty_InternalHeatSourceFields::ConstructionName); |
| 39 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!wo_construction) { |
| 40 | ✗ | LOG(Error, workspaceObject.briefDescription() << " does not reference any Construction. It will not be translated"); | |
| 41 | ✗ | return boost::none; | |
| 42 | } | ||
| 43 | |||
| 44 |
1/1✓ Branch 1 taken 2 times.
|
2 | openstudio::model::ConstructionWithInternalSource construction(m_model); |
| 45 | |||
| 46 | 2 | OptionalString s; | |
| 47 | 2 | OptionalDouble d; | |
| 48 | 2 | OptionalInt i; | |
| 49 | 2 | OptionalWorkspaceObject target; | |
| 50 | |||
| 51 | // Name is from the "Construction" object, not the ConstructionProperty:InternalHeatSource | ||
| 52 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | s = wo_construction->name(); |
| 53 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (s) { |
| 54 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | construction.setName(*s); |
| 55 | } | ||
| 56 | |||
| 57 |
1/1✓ Branch 1 taken 2 times.
|
2 | i = workspaceObject.getInt(ConstructionProperty_InternalHeatSourceFields::ThermalSourcePresentAfterLayerNumber); |
| 58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (i) { |
| 59 | ✗ | construction.setSourcePresentAfterLayerNumber(*i); | |
| 60 | } | ||
| 61 | |||
| 62 |
1/1✓ Branch 1 taken 2 times.
|
2 | i = workspaceObject.getInt(ConstructionProperty_InternalHeatSourceFields::TemperatureCalculationRequestedAfterLayerNumber); |
| 63 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (i) { |
| 64 | ✗ | construction.setTemperatureCalculationRequestedAfterLayerNumber(*i); | |
| 65 | } | ||
| 66 | |||
| 67 |
1/1✓ Branch 1 taken 2 times.
|
2 | i = workspaceObject.getInt(ConstructionProperty_InternalHeatSourceFields::DimensionsfortheCTFCalculation); |
| 68 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (i) { |
| 69 | ✗ | construction.setDimensionsForTheCTFCalculation(*i); | |
| 70 | } | ||
| 71 | |||
| 72 |
1/1✓ Branch 1 taken 2 times.
|
2 | d = workspaceObject.getDouble(ConstructionProperty_InternalHeatSourceFields::TubeSpacing); |
| 73 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (d) { |
| 74 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | construction.setTubeSpacing(*d); |
| 75 | } | ||
| 76 | |||
| 77 |
1/1✓ Branch 1 taken 2 times.
|
2 | d = workspaceObject.getDouble(ConstructionProperty_InternalHeatSourceFields::TwoDimensionalTemperatureCalculationPosition); |
| 78 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (d) { |
| 79 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | construction.setTwoDimensionalTemperatureCalculationPosition(*d); |
| 80 | } | ||
| 81 | |||
| 82 | // get extensible groups FROM THE CONSTRUCTION object for layers | ||
| 83 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | unsigned n = wo_construction->numExtensibleGroups(); |
| 84 | // now we get the workspace objects and try to find them and place them in the model object | ||
| 85 | // Loop over all the fields except the first, which is the name | ||
| 86 | 2 | OptionalWorkspaceObject owo; | |
| 87 | 2 | OptionalModelObject temp; | |
| 88 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | for (unsigned i = 0; i < n; ++i) { |
| 89 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
|
2 | owo = wo_construction->getExtensibleGroup(i).cast<WorkspaceExtensibleGroup>().getTarget(ConstructionExtensibleFields::Layer); |
| 90 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (owo) { |
| 91 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | temp = translateAndMapWorkspaceObject(*owo); |
| 92 | } | ||
| 93 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
4 | if (!(owo && temp)) { |
| 94 | ✗ | LOG(Error, "Finding Construction Layer in workspace failed."); | |
| 95 | ✗ | construction.remove(); | |
| 96 | ✗ | return boost::none; | |
| 97 | } | ||
| 98 | // Assuming names of materials are unique | ||
| 99 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | OptionalMaterial mat = temp->optionalCast<Material>(); |
| 100 | |||
| 101 | 2 | bool inserted(false); | |
| 102 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (mat) { |
| 103 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | OptionalOpaqueMaterial opaqueMaterial = mat->optionalCast<OpaqueMaterial>(); |
| 104 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (opaqueMaterial) { |
| 105 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | inserted = construction.insertLayer(i, *opaqueMaterial); |
| 106 | } else { | ||
| 107 | ✗ | OptionalFenestrationMaterial fenestrationMaterial = mat->optionalCast<FenestrationMaterial>(); | |
| 108 | ✗ | if (fenestrationMaterial) { | |
| 109 | ✗ | inserted = construction.insertLayer(i, *fenestrationMaterial); | |
| 110 | } else { | ||
| 111 | ✗ | OptionalModelPartitionMaterial modelPartitionMaterial = mat->optionalCast<ModelPartitionMaterial>(); | |
| 112 | ✗ | if (modelPartitionMaterial) { | |
| 113 | ✗ | if (construction.numLayers() == 0u) { | |
| 114 | ✗ | inserted = construction.setLayer(*modelPartitionMaterial); | |
| 115 | } | ||
| 116 | } | ||
| 117 | ✗ | } | |
| 118 | ✗ | } | |
| 119 | 2 | } | |
| 120 | |||
| 121 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!inserted) { |
| 122 | ✗ | LOG(Error, "Insertion of Construction Layer failed."); | |
| 123 | ✗ | construction.remove(); | |
| 124 | ✗ | return boost::none; | |
| 125 | } | ||
| 126 | 2 | } | |
| 127 | |||
| 128 | // We register this object in the map so it's not translated twice | ||
| 129 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | m_workspaceToModelMap.insert(std::make_pair(workspaceObject.handle(), construction)); |
| 130 | |||
| 131 |
1/1✓ Branch 1 taken 2 times.
|
2 | return construction; |
| 132 | 2 | } | |
| 133 | |||
| 134 | } // namespace energyplus | ||
| 135 | |||
| 136 | } // namespace openstudio | ||
| 137 |