src/energyplus/ReverseTranslator/ReverseTranslateConstruction.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/Construction.hpp" | ||
| 9 | #include "../../model/Construction_Impl.hpp" | ||
| 10 | #include "../../model/Material.hpp" | ||
| 11 | #include "../../model/Material_Impl.hpp" | ||
| 12 | #include "../../model/OpaqueMaterial.hpp" | ||
| 13 | #include "../../model/OpaqueMaterial_Impl.hpp" | ||
| 14 | #include "../../model/FenestrationMaterial.hpp" | ||
| 15 | #include "../../model/FenestrationMaterial_Impl.hpp" | ||
| 16 | #include "../../model/ModelPartitionMaterial.hpp" | ||
| 17 | #include "../../model/ModelPartitionMaterial_Impl.hpp" | ||
| 18 | |||
| 19 | #include "../../utilities/idf/WorkspaceExtensibleGroup.hpp" | ||
| 20 | |||
| 21 | #include <utilities/idd/Construction_FieldEnums.hxx> | ||
| 22 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 23 | #include <utilities/idd/IddEnums.hxx> | ||
| 24 | |||
| 25 | #include "../../utilities/core/Assert.hpp" | ||
| 26 | |||
| 27 | using namespace openstudio::model; | ||
| 28 | |||
| 29 | namespace openstudio { | ||
| 30 | |||
| 31 | namespace energyplus { | ||
| 32 | |||
| 33 | 242 | OptionalModelObject ReverseTranslator::translateConstruction(const WorkspaceObject& workspaceObject) { | |
| 34 |
4/5✓ Branch 1 taken 242 times.
✓ Branch 4 taken 242 times.
✓ Branch 7 taken 242 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 242 times.
|
242 | if (workspaceObject.iddObject().type() != IddObjectType::Construction) { |
| 35 | ✗ | LOG(Error, "WorkspaceObject is not IddObjectType: Construction"); | |
| 36 | ✗ | return boost::none; | |
| 37 | } | ||
| 38 | |||
| 39 | // E+ 9.5.0: Check if the construction is referenced by a ConstructionProperty:InternalHeatSource | ||
| 40 |
2/2✓ Branch 1 taken 242 times.
✓ Branch 4 taken 242 times.
|
242 | std::vector<WorkspaceObject> constructionProps = workspaceObject.getSources(IddObjectType::ConstructionProperty_InternalHeatSource); |
| 41 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 240 times.
|
242 | if (!constructionProps.empty()) { |
| 42 |
8/8✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 17 taken 2 times.
✓ Branch 20 taken 2 times.
✓ Branch 23 taken 2 times.
|
2 | LOG(Info, "Construction '" << workspaceObject.nameString() << "' will be translated to a ConstructionWithInternalSource'"); |
| 43 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (constructionProps.size() > 1) { |
| 44 | ✗ | LOG(Warn, "Construction '" << workspaceObject.nameString() << "' is referenced by more than one ConstructionProperty:InternalHeatSource." | |
| 45 | << "Check IDF file for validity. Only the first one will be used."); | ||
| 46 | } | ||
| 47 |
1/1✓ Branch 2 taken 2 times.
|
2 | return translateConstructionWithInternalSource(constructionProps[0]); |
| 48 | } | ||
| 49 | |||
| 50 | // Otherwise, business as usual | ||
| 51 |
1/1✓ Branch 1 taken 240 times.
|
240 | Construction construction(m_model); |
| 52 |
2/4✓ Branch 1 taken 240 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 240 times.
✗ Branch 6 not taken.
|
240 | OS_ASSERT(construction.numLayers() == 0u); |
| 53 |
1/1✓ Branch 1 taken 240 times.
|
240 | OptionalString optS = workspaceObject.name(); |
| 54 |
1/2✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
|
240 | if (optS) { |
| 55 |
2/2✓ Branch 1 taken 240 times.
✓ Branch 4 taken 240 times.
|
240 | construction.setName(*optS); |
| 56 | } | ||
| 57 | |||
| 58 |
1/1✓ Branch 1 taken 240 times.
|
240 | unsigned n = workspaceObject.numExtensibleGroups(); |
| 59 | // now we get the workspace objects and try to find them and place them in the model object | ||
| 60 | // Loop over all the fields except the first, which is the name | ||
| 61 | 240 | OptionalWorkspaceObject owo; | |
| 62 | 240 | OptionalModelObject temp; | |
| 63 |
2/2✓ Branch 0 taken 526 times.
✓ Branch 1 taken 240 times.
|
766 | for (unsigned i = 0; i < n; ++i) { |
| 64 |
3/3✓ Branch 1 taken 526 times.
✓ Branch 4 taken 526 times.
✓ Branch 7 taken 526 times.
|
526 | owo = workspaceObject.getExtensibleGroup(i).cast<WorkspaceExtensibleGroup>().getTarget(ConstructionExtensibleFields::Layer); |
| 65 |
1/2✓ Branch 0 taken 526 times.
✗ Branch 1 not taken.
|
526 | if (owo) { |
| 66 |
2/2✓ Branch 1 taken 526 times.
✓ Branch 4 taken 526 times.
|
526 | temp = translateAndMapWorkspaceObject(*owo); |
| 67 | } | ||
| 68 |
3/6✓ Branch 0 taken 526 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 526 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 526 times.
|
1052 | if (!(owo && temp)) { |
| 69 | ✗ | LOG(Error, "Finding Construction Layer in workspace failed."); | |
| 70 | ✗ | construction.remove(); | |
| 71 | ✗ | return boost::none; | |
| 72 | } | ||
| 73 | // Assuming names of materials are unique | ||
| 74 |
2/2✓ Branch 1 taken 526 times.
✓ Branch 4 taken 526 times.
|
526 | OptionalMaterial mat = temp->optionalCast<Material>(); |
| 75 | |||
| 76 | 526 | bool inserted(false); | |
| 77 |
1/2✓ Branch 0 taken 526 times.
✗ Branch 1 not taken.
|
526 | if (mat) { |
| 78 |
2/2✓ Branch 1 taken 526 times.
✓ Branch 4 taken 526 times.
|
526 | OptionalOpaqueMaterial opaqueMaterial = mat->optionalCast<OpaqueMaterial>(); |
| 79 |
2/2✓ Branch 0 taken 447 times.
✓ Branch 1 taken 79 times.
|
526 | if (opaqueMaterial) { |
| 80 |
2/2✓ Branch 1 taken 447 times.
✓ Branch 4 taken 447 times.
|
447 | inserted = construction.insertLayer(i, *opaqueMaterial); |
| 81 | } else { | ||
| 82 |
2/2✓ Branch 1 taken 79 times.
✓ Branch 4 taken 79 times.
|
79 | OptionalFenestrationMaterial fenestrationMaterial = mat->optionalCast<FenestrationMaterial>(); |
| 83 |
1/2✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
|
79 | if (fenestrationMaterial) { |
| 84 |
2/2✓ Branch 1 taken 79 times.
✓ Branch 4 taken 79 times.
|
79 | inserted = construction.insertLayer(i, *fenestrationMaterial); |
| 85 | } else { | ||
| 86 | ✗ | OptionalModelPartitionMaterial modelPartitionMaterial = mat->optionalCast<ModelPartitionMaterial>(); | |
| 87 | ✗ | if (modelPartitionMaterial) { | |
| 88 | ✗ | if (construction.numLayers() == 0u) { | |
| 89 | ✗ | inserted = construction.setLayer(*modelPartitionMaterial); | |
| 90 | } | ||
| 91 | } | ||
| 92 | ✗ | } | |
| 93 | 79 | } | |
| 94 | 526 | } | |
| 95 | |||
| 96 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 526 times.
|
526 | if (!inserted) { |
| 97 | ✗ | LOG(Error, "Insertion of Construction Layer failed."); | |
| 98 | ✗ | construction.remove(); | |
| 99 | ✗ | return boost::none; | |
| 100 | } | ||
| 101 | 526 | } | |
| 102 | |||
| 103 |
1/1✓ Branch 1 taken 240 times.
|
240 | return construction; |
| 104 | 242 | } | |
| 105 | |||
| 106 | } // namespace energyplus | ||
| 107 | |||
| 108 | } // namespace openstudio | ||
| 109 |