src/energyplus/ForwardTranslator/ForwardTranslateEnergyManagementSystemMeteredOutputVariable.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 "../ForwardTranslator.hpp" | ||
| 7 | |||
| 8 | #include "../../model/Model.hpp" | ||
| 9 | #include "../../model/OutputVariable.hpp" | ||
| 10 | #include "../../model/OutputVariable_Impl.hpp" | ||
| 11 | #include "../../model/OutputMeter.hpp" | ||
| 12 | #include "../../model/OutputMeter_Impl.hpp" | ||
| 13 | #include "../../model/Schedule.hpp" | ||
| 14 | #include "../../model/Schedule_Impl.hpp" | ||
| 15 | #include "../../model/EnergyManagementSystemMeteredOutputVariable.hpp" | ||
| 16 | #include "../../model/EnergyManagementSystemMeteredOutputVariable_Impl.hpp" | ||
| 17 | |||
| 18 | #include <utilities/idd/EnergyManagementSystem_MeteredOutputVariable_FieldEnums.hxx> | ||
| 19 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 20 | #include <utilities/idd/IddEnums.hxx> | ||
| 21 | |||
| 22 | using namespace openstudio::model; | ||
| 23 | |||
| 24 | using namespace std; | ||
| 25 | |||
| 26 | namespace openstudio { | ||
| 27 | |||
| 28 | namespace energyplus { | ||
| 29 | |||
| 30 | boost::optional<IdfObject> | ||
| 31 | 3 | ForwardTranslator::translateEnergyManagementSystemMeteredOutputVariable(EnergyManagementSystemMeteredOutputVariable& modelObject) { | |
| 32 | 3 | boost::optional<std::string> s; | |
| 33 | |||
| 34 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | IdfObject idfObject(openstudio::IddObjectType::EnergyManagementSystem_MeteredOutputVariable); |
| 35 |
1/1✓ Branch 1 taken 3 times.
|
3 | m_idfObjects.push_back(idfObject); |
| 36 | //Name | ||
| 37 |
1/1✓ Branch 1 taken 3 times.
|
3 | s = modelObject.name(); |
| 38 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (s) { |
| 39 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | idfObject.setName(*s); |
| 40 | } | ||
| 41 | // look for UID and if found replace with object name; otherwise just use string value | ||
| 42 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | s = modelObject.emsVariableName(); |
| 43 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (s) { |
| 44 | //find uids | ||
| 45 | 3 | const int subs[] = {1}; | |
| 46 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | std::string newline = s.get(); |
| 47 | 3 | std::string possible_uid; | |
| 48 | size_t pos; | ||
| 49 | 3 | bool is_uuid = false; | |
| 50 |
1/1✓ Branch 1 taken 3 times.
|
3 | const Model m = modelObject.model(); |
| 51 | 3 | boost::optional<ModelObject> mObject; | |
| 52 | |||
| 53 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 9 taken 3 times.
✓ Branch 14 taken 3 times.
|
3 | boost::sregex_token_iterator j(s.get().begin(), s.get().end(), uuidInString(), subs); |
| 54 | |||
| 55 |
3/3✓ Branch 2 taken 5 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 3 times.
|
5 | while (j != boost::sregex_token_iterator()) { |
| 56 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | possible_uid = *j++; |
| 57 | //look to see if uid is in the model and return the object | ||
| 58 |
1/1✓ Branch 1 taken 2 times.
|
2 | UUID uid = toUUID(possible_uid); |
| 59 |
1/1✓ Branch 1 taken 2 times.
|
2 | mObject = m.getModelObject<model::ModelObject>(uid); |
| 60 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (mObject) { |
| 61 | 2 | is_uuid = true; | |
| 62 | //replace uid with namestring | ||
| 63 | 2 | pos = newline.find(possible_uid); | |
| 64 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if (pos + 38 <= newline.length()) { |
| 65 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | newline.replace(pos, 38, mObject.get().nameString()); |
| 66 |
1/1✓ Branch 1 taken 2 times.
|
2 | idfObject.setString(EnergyManagementSystem_MeteredOutputVariableFields::EMSVariableName, newline); |
| 67 | } | ||
| 68 | } else { | ||
| 69 | //did not find an object with the UID so do not FT | ||
| 70 | ✗ | LOG(Error, | |
| 71 | "Key Name for EMS:MeteredOutputVariable '" << modelObject.nameString() << "' is UID but does not exist, it will not be translated."); | ||
| 72 | ✗ | return boost::none; | |
| 73 | } | ||
| 74 | } | ||
| 75 | //string is not a uuid so just translate its value for the EMSVariableName | ||
| 76 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2 times.
|
3 | if (!is_uuid) { |
| 77 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | idfObject.setString(EnergyManagementSystem_MeteredOutputVariableFields::EMSVariableName, s.get()); |
| 78 | } | ||
| 79 | 3 | } | |
| 80 | |||
| 81 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | idfObject.setString(EnergyManagementSystem_MeteredOutputVariableFields::UpdateFrequency, modelObject.updateFrequency()); |
| 82 | |||
| 83 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | s = modelObject.emsProgramOrSubroutineName(); |
| 84 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | if (s.is_initialized()) { |
| 85 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | idfObject.setString(EnergyManagementSystem_MeteredOutputVariableFields::EMSProgramorSubroutineName, s.get()); |
| 86 | } | ||
| 87 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | idfObject.setString(EnergyManagementSystem_MeteredOutputVariableFields::ResourceType, modelObject.resourceType()); |
| 88 | |||
| 89 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | idfObject.setString(EnergyManagementSystem_MeteredOutputVariableFields::GroupType, modelObject.groupType()); |
| 90 | |||
| 91 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | idfObject.setString(EnergyManagementSystem_MeteredOutputVariableFields::EndUseCategory, modelObject.endUseCategory()); |
| 92 | |||
| 93 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | s = modelObject.endUseSubcategory(); |
| 94 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | if (s.is_initialized()) { |
| 95 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | idfObject.setString(EnergyManagementSystem_MeteredOutputVariableFields::EndUseSubcategory, s.get()); |
| 96 | } | ||
| 97 | |||
| 98 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | s = modelObject.units(); |
| 99 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | if (s.is_initialized()) { |
| 100 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | idfObject.setString(EnergyManagementSystem_MeteredOutputVariableFields::Units, s.get()); |
| 101 | } | ||
| 102 |
1/1✓ Branch 1 taken 3 times.
|
3 | return idfObject; |
| 103 | 3 | } | |
| 104 | |||
| 105 | } // namespace energyplus | ||
| 106 | |||
| 107 | } // namespace openstudio | ||
| 108 |