src/energyplus/ReverseTranslator/ReverseTranslateEnergyManagementSystemOutputVariable.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/EnergyManagementSystemOutputVariable.hpp" | ||
| 9 | #include "../../model/EnergyManagementSystemOutputVariable_Impl.hpp" | ||
| 10 | #include "../../model/EnergyManagementSystemProgram.hpp" | ||
| 11 | #include "../../model/EnergyManagementSystemProgram_Impl.hpp" | ||
| 12 | #include "../../model/EnergyManagementSystemSubroutine.hpp" | ||
| 13 | #include "../../model/EnergyManagementSystemSubroutine_Impl.hpp" | ||
| 14 | #include "../../model/EnergyManagementSystemGlobalVariable.hpp" | ||
| 15 | #include "../../model/EnergyManagementSystemGlobalVariable_Impl.hpp" | ||
| 16 | |||
| 17 | #include <utilities/idd/EnergyManagementSystem_OutputVariable_FieldEnums.hxx> | ||
| 18 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 19 | #include <utilities/idd/IddEnums.hxx> | ||
| 20 | |||
| 21 | using namespace openstudio::model; | ||
| 22 | |||
| 23 | namespace openstudio { | ||
| 24 | |||
| 25 | namespace energyplus { | ||
| 26 | |||
| 27 | 2 | OptionalModelObject ReverseTranslator::translateEnergyManagementSystemOutputVariable(const WorkspaceObject& workspaceObject) { | |
| 28 |
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::EnergyManagementSystem_OutputVariable) { |
| 29 | ✗ | LOG(Error, "WorkspaceObject is not IddObjectType: EnergyManagementSystem_OutputVariable"); | |
| 30 | ✗ | return boost::none; | |
| 31 | } | ||
| 32 | |||
| 33 | //make sure all other objects are translated first except below | ||
| 34 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 8 taken 56 times.
✓ Branch 9 taken 2 times.
|
58 | for (const WorkspaceObject& workspaceObject : m_workspace.objects()) { |
| 35 |
4/6✓ Branch 1 taken 56 times.
✓ Branch 4 taken 56 times.
✓ Branch 8 taken 52 times.
✓ Branch 9 taken 4 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
112 | if ((workspaceObject.iddObject().type() != IddObjectType::EnergyManagementSystem_Program) |
| 36 |
5/9✓ Branch 1 taken 56 times.
✓ Branch 4 taken 56 times.
✓ Branch 7 taken 56 times.
✓ Branch 10 taken 56 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 56 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
112 | && (workspaceObject.iddObject().type() != IddObjectType::EnergyManagementSystem_Subroutine) |
| 37 |
5/9✓ Branch 1 taken 56 times.
✓ Branch 4 taken 56 times.
✓ Branch 7 taken 56 times.
✓ Branch 10 taken 56 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 56 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
112 | && (workspaceObject.iddObject().type() != IddObjectType::EnergyManagementSystem_ProgramCallingManager) |
| 38 |
5/9✓ Branch 1 taken 56 times.
✓ Branch 4 taken 56 times.
✓ Branch 7 taken 56 times.
✓ Branch 10 taken 56 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 56 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
112 | && (workspaceObject.iddObject().type() != IddObjectType::EnergyManagementSystem_MeteredOutputVariable) |
| 39 |
9/14✓ Branch 1 taken 56 times.
✓ Branch 3 taken 56 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 56 times.
✓ Branch 9 taken 56 times.
✓ Branch 12 taken 56 times.
✓ Branch 15 taken 52 times.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 56 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 56 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
168 | && (workspaceObject.iddObject().type() != IddObjectType::EnergyManagementSystem_OutputVariable)) { |
| 40 |
1/1✓ Branch 1 taken 52 times.
|
52 | translateAndMapWorkspaceObject(workspaceObject); |
| 41 | } | ||
| 42 | 2 | } | |
| 43 | |||
| 44 |
1/1✓ Branch 1 taken 2 times.
|
2 | OptionalString s = workspaceObject.getString(EnergyManagementSystem_OutputVariableFields::Name); |
| 45 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!s) { |
| 46 | ✗ | LOG(Error, "EnergyManagementSystem_OutputVariable has no Name"); | |
| 47 | ✗ | return boost::none; | |
| 48 | } | ||
| 49 |
1/1✓ Branch 1 taken 2 times.
|
2 | openstudio::model::EnergyManagementSystemOutputVariable emsOutputVariable(m_model); |
| 50 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | emsOutputVariable.setName(*s); |
| 51 | |||
| 52 | // mark this object as translated so we don't recursively translate it below | ||
| 53 |
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(), emsOutputVariable)); |
| 54 | |||
| 55 |
1/1✓ Branch 1 taken 2 times.
|
2 | s = workspaceObject.getString(EnergyManagementSystem_OutputVariableFields::EMSVariableName); |
| 56 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!s) { |
| 57 | ✗ | LOG(Error, emsOutputVariable.nameString() + ": EMSVariableName not set"); | |
| 58 | ✗ | return boost::none; | |
| 59 | } else { | ||
| 60 |
1/1✓ Branch 1 taken 2 times.
|
2 | Workspace workspace = workspaceObject.workspace(); |
| 61 | //look for GlobalVariables, translate and check if there is a name match since GV's dont have name field. | ||
| 62 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | boost::optional<WorkspaceObject> wsObject = workspace.getObjectByTypeAndName(IddObjectType::EnergyManagementSystem_GlobalVariable, *s); |
| 63 | //for (WorkspaceObject& wsObject : workspace.getObjectsByType(IddObjectType::EnergyManagementSystem_GlobalVariable)) { | ||
| 64 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (wsObject) { |
| 65 | ✗ | boost::optional<model::ModelObject> modelObject = translateAndMapWorkspaceObject(wsObject.get()); | |
| 66 | ✗ | if (modelObject) { | |
| 67 | ✗ | if (modelObject.get().cast<EnergyManagementSystemGlobalVariable>().name() == s) { | |
| 68 | ✗ | emsOutputVariable.setEMSVariableName(*s); | |
| 69 | } | ||
| 70 | } | ||
| 71 | ✗ | } | |
| 72 | //look for name match on other (EMS) objects. | ||
| 73 | // DLM: I am not really sure what this is supposed to do, it was recursively calling translateAndMapWorkspaceObject on the current object. | ||
| 74 | // DLM: Also, it is continually setting the name on emsOutputVariable and not the new modelObject | ||
| 75 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
|
2 | for (WorkspaceObject& wsObject : workspace.getObjectsByName(*s)) { |
| 76 | ✗ | boost::optional<model::ModelObject> modelObject = translateAndMapWorkspaceObject(wsObject); | |
| 77 | ✗ | if (modelObject) { | |
| 78 | ✗ | emsOutputVariable.setEMSVariableName(*s); | |
| 79 | ✗ | break; | |
| 80 | } | ||
| 81 | 2 | } | |
| 82 | 2 | } | |
| 83 | |||
| 84 |
1/1✓ Branch 1 taken 2 times.
|
2 | s = workspaceObject.getString(EnergyManagementSystem_OutputVariableFields::UpdateFrequency); |
| 85 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!s) { |
| 86 | ✗ | LOG(Error, emsOutputVariable.nameString() + ": UpdateFrequency not set"); | |
| 87 | ✗ | return boost::none; | |
| 88 | } else { | ||
| 89 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | emsOutputVariable.setUpdateFrequency(*s); |
| 90 | } | ||
| 91 | |||
| 92 |
1/1✓ Branch 1 taken 2 times.
|
2 | s = workspaceObject.getString(EnergyManagementSystem_OutputVariableFields::TypeofDatainVariable); |
| 93 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!s) { |
| 94 | ✗ | LOG(Error, emsOutputVariable.nameString() + ": TypeofDatainVariable not set"); | |
| 95 | ✗ | return boost::none; | |
| 96 | } else { | ||
| 97 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | emsOutputVariable.setTypeOfDataInVariable(*s); |
| 98 | } | ||
| 99 | |||
| 100 |
1/1✓ Branch 1 taken 2 times.
|
2 | s = workspaceObject.getString(EnergyManagementSystem_OutputVariableFields::Units); |
| 101 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (s) { |
| 102 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | emsOutputVariable.setUnits(*s); |
| 103 | } | ||
| 104 | |||
| 105 |
1/1✓ Branch 1 taken 2 times.
|
2 | s = workspaceObject.getString(EnergyManagementSystem_OutputVariableFields::EMSProgramorSubroutineName); |
| 106 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (s) { |
| 107 |
1/1✓ Branch 1 taken 2 times.
|
2 | Workspace workspace = workspaceObject.workspace(); |
| 108 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
|
2 | for (WorkspaceObject& wsObject : workspace.getObjectsByName(*s)) { |
| 109 | ✗ | boost::optional<model::ModelObject> modelObject = translateAndMapWorkspaceObject(wsObject); | |
| 110 | ✗ | if (modelObject) { | |
| 111 | ✗ | if (modelObject.get().iddObjectType() == IddObjectType::OS_EnergyManagementSystem_Program) { | |
| 112 | ✗ | emsOutputVariable.setEMSProgramOrSubroutineName(modelObject.get().cast<EnergyManagementSystemProgram>()); | |
| 113 | ✗ | } else if (modelObject.get().iddObjectType() == IddObjectType::OS_EnergyManagementSystem_Subroutine) { | |
| 114 | ✗ | emsOutputVariable.setEMSProgramOrSubroutineName(modelObject.get().cast<EnergyManagementSystemSubroutine>()); | |
| 115 | } | ||
| 116 | ✗ | return emsOutputVariable; | |
| 117 | } | ||
| 118 | 2 | } | |
| 119 | 2 | } | |
| 120 | |||
| 121 |
1/1✓ Branch 1 taken 2 times.
|
2 | return emsOutputVariable; |
| 122 | 2 | } | |
| 123 | |||
| 124 | } // namespace energyplus | ||
| 125 | |||
| 126 | } // namespace openstudio | ||
| 127 |