From 7fe417cf2a9967001d61d9cd48ca24fee7b75fcc Mon Sep 17 00:00:00 2001 From: Kyle Benne Date: Thu, 1 Aug 2024 12:13:34 -0500 Subject: [PATCH] WIP: Refactor variables --- energyplus_coroutine/energyplus_helpers.cpp | 19 +- energyplus_coroutine/energyplus_helpers.hpp | 9 + energyplus_coroutine/variables.cpp | 278 +++++++++++++++++++- energyplus_coroutine/variables.hpp | 119 ++++++--- 4 files changed, 384 insertions(+), 41 deletions(-) diff --git a/energyplus_coroutine/energyplus_helpers.cpp b/energyplus_coroutine/energyplus_helpers.cpp index e36b37679..b60dc51eb 100644 --- a/energyplus_coroutine/energyplus_helpers.cpp +++ b/energyplus_coroutine/energyplus_helpers.cpp @@ -105,7 +105,24 @@ int ZoneNum(const EnergyPlus::EnergyPlusData &energyplus_data, const std::string return energyplus_data.dataSize->FinalZoneSizing[zone_num].OutHumRatAtCoolPeak; } -// const auto value = sim_state.dataSize->FinalZoneSizing[zone_num].OutHumRatAtLatentCoolPeak; +//[[nodiscard]] double ZoneTimeAtPeakCool(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num) +//{ +// return 0.0; +//} + +[[nodiscard]] double ZoneDesignHeatingLoad(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num) +{ + return energyplus_data.dataSize->FinalZoneSizing[zone_num].DesHeatLoad; +} + +[[nodiscard]] double ZoneOutdoorTempAtPeakHeat(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num) +{ + return energyplus_data.dataSize->FinalZoneSizing[zone_num].OutTempAtHeatPeak; +} +[[nodiscard]] double ZoneOutdoorHumidityRatioAtPeakHeat(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num) +{ + return energyplus_data.dataSize->FinalZoneSizing[zone_num].OutHumRatAtHeatPeak; +} void SetZoneTemperature(EnergyPlus::EnergyPlusData &energyplus_data, const int zone_num, const double &temp) { diff --git a/energyplus_coroutine/energyplus_helpers.hpp b/energyplus_coroutine/energyplus_helpers.hpp index 04d337dda..abe34f881 100644 --- a/energyplus_coroutine/energyplus_helpers.hpp +++ b/energyplus_coroutine/energyplus_helpers.hpp @@ -41,6 +41,15 @@ class ZoneSums [[nodiscard]] double ZoneOutdoorHumidityRatioAtPeakCool(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num); +//[[nodiscard]] double ZoneTimeAtPeakCool(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num); + +[[nodiscard]] double ZoneDesignHeatingLoad(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num); + +[[nodiscard]] double ZoneOutdoorTempAtPeakHeat(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num); + +[[nodiscard]] double ZoneOutdoorHumidityRatioAtPeakHeat(const EnergyPlus::EnergyPlusData &energyplus_data, + int zone_num); + void SetZoneTemperature(EnergyPlus::EnergyPlusData &energyplus_data, const int zone_num, const double &temp); void SetZoneHumidityRatio(EnergyPlus::EnergyPlusData &energyplus_data, const int zone_num, const double &ratio); diff --git a/energyplus_coroutine/variables.cpp b/energyplus_coroutine/variables.cpp index 5d4569583..753092b71 100644 --- a/energyplus_coroutine/variables.cpp +++ b/energyplus_coroutine/variables.cpp @@ -3,6 +3,7 @@ #include "../energyplus/src/EnergyPlus/DataStringGlobals.hh" #include "../energyplus/src/EnergyPlus/InputProcessing/IdfParser.hh" #include "../energyplus/src/EnergyPlus/UtilityRoutines.hh" +#include "energyplus_helpers.hpp" #include "iddtypes.hpp" #include "input/input.hpp" #include "input/outputvariable.hpp" @@ -1338,6 +1339,121 @@ namespace zone { SetValue(energyplus::ZoneOutdoorHumidityRatioAtPeakCool(energyplus_data, zone_num_), units::UnitSystem::EP); } + void MOutCooFlow::create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables) + { + int value_reference = variables.size(); // NOLINT + const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + + for (const auto &zone : zones) { + std::string zone_name = zone.value("name", ""); + int zone_num = energyplus::ZoneNum(energyplus_data, zone_name); + + variables.push_back(std::unique_ptr(new MOutCooFlow(zone_name, zone_num, value_reference))); + value_reference++; + } + } + + MOutCooFlow::MOutCooFlow(std::string_view zone_name, int zone_num, int value_reference) // NOLINT + : OutputVariable(std::string(zone_name) + "_mOutCoo_flow", + value_reference, + units::UnitType::kg_per_s, + units::UnitType::kg_per_s), + zone_num_(zone_num) + { + metadata_.set_name("ScalarVariable"); + metadata_.append_attribute("name") = name_.c_str(); + metadata_.append_attribute("valueReference") = std::to_string(value_reference_).c_str(); + metadata_.append_attribute("description") = "Minimum outdoor air flow rate during the cooling design load"; + metadata_.append_attribute("causality") = "calculatedParameter"; + metadata_.append_attribute("variability") = "fixed"; + metadata_.append_attribute("initial") = "calculated"; + + auto real = metadata_.append_child("Real"); + real.append_attribute("quantity") = "MassFlowRate"; + real.append_attribute("relativeQuantity") = "false"; + real.append_attribute("unit") = units::toString(mo_unit_).c_str(); + } + + void MOutCooFlow::Update([[maybe_unused]] EnergyPlus::EnergyPlusData &energyplus_data) + { + // TODO: get this value + } + + void TCoo::create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables) + { + int value_reference = variables.size(); // NOLINT + const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + + for (const auto &zone : zones) { + std::string zone_name = zone.value("name", ""); + int zone_num = energyplus::ZoneNum(energyplus_data, zone_name); + + variables.push_back(std::unique_ptr(new TCoo(zone_name, zone_num, value_reference))); + value_reference++; + } + } + + TCoo::TCoo(std::string_view zone_name, int zone_num, int value_reference) // NOLINT + : OutputVariable(std::string(zone_name) + "_TCoo", value_reference, units::UnitType::s, units::UnitType::s), + zone_num_(zone_num) + { + metadata_.set_name("ScalarVariable"); + metadata_.append_attribute("name") = name_.c_str(); + metadata_.append_attribute("valueReference") = std::to_string(value_reference_).c_str(); + metadata_.append_attribute("description") = "Time at which these loads occurred"; + metadata_.append_attribute("causality") = "calculatedParameter"; + metadata_.append_attribute("variability") = "fixed"; + metadata_.append_attribute("initial") = "calculated"; + + auto real = metadata_.append_child("Real"); + real.append_attribute("quantity") = "Time"; + real.append_attribute("relativeQuantity") = "false"; + real.append_attribute("unit") = units::toString(mo_unit_).c_str(); + } + + void TCoo::Update([[maybe_unused]] EnergyPlus::EnergyPlusData &energyplus_data) + { + // TODO get this value + SetValue(0.0, units::UnitSystem::EP); + } + + void QHeaFlow::create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables) + { + int value_reference = variables.size(); // NOLINT + const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + + for (const auto &zone : zones) { + std::string zone_name = zone.value("name", ""); + int zone_num = energyplus::ZoneNum(energyplus_data, zone_name); + + variables.push_back(std::unique_ptr(new QHeaFlow(zone_name, zone_num, value_reference))); + value_reference++; + } + } + + QHeaFlow::QHeaFlow(std::string_view zone_name, int zone_num, int value_reference) // NOLINT + : OutputVariable(std::string(zone_name) + "_QHea_flow", value_reference, units::UnitType::W, units::UnitType::W), + zone_num_(zone_num) + { + metadata_.set_name("ScalarVariable"); + metadata_.append_attribute("name") = name_.c_str(); + metadata_.append_attribute("valueReference") = std::to_string(value_reference_).c_str(); + metadata_.append_attribute("description") = "Design heating load"; + metadata_.append_attribute("causality") = "calculatedParameter"; + metadata_.append_attribute("variability") = "fixed"; + metadata_.append_attribute("initial") = "calculated"; + + auto real = metadata_.append_child("Real"); + real.append_attribute("quantity") = "Power"; + real.append_attribute("relativeQuantity") = "false"; + real.append_attribute("unit") = units::toString(mo_unit_).c_str(); + } + + void QHeaFlow::Update(EnergyPlus::EnergyPlusData &energyplus_data) + { + SetValue(energyplus::ZoneDesignHeatingLoad(energyplus_data, zone_num_), units::UnitSystem::EP); + } + void MInletsFlow::create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables) { int value_reference = variables.size(); // NOLINT @@ -1353,6 +1469,159 @@ namespace zone { } } + void TOutHea::create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables) + { + int value_reference = variables.size(); // NOLINT + const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + + for (const auto &zone : zones) { + std::string zone_name = zone.value("name", ""); + int zone_num = energyplus::ZoneNum(energyplus_data, zone_name); + + variables.push_back(std::unique_ptr(new TOutHea(zone_name, zone_num, value_reference))); + value_reference++; + } + } + + TOutHea::TOutHea(std::string_view zone_name, int zone_num, int value_reference) // NOLINT + : OutputVariable(std::string(zone_name) + "_TOutHea", value_reference, units::UnitType::C, units::UnitType::K), + zone_num_(zone_num) + { + metadata_.set_name("ScalarVariable"); + metadata_.append_attribute("name") = name_.c_str(); + metadata_.append_attribute("valueReference") = std::to_string(value_reference_).c_str(); + metadata_.append_attribute("description") = "Outdoor drybulb temperature at the heating design load"; + metadata_.append_attribute("causality") = "calculatedParameter"; + metadata_.append_attribute("variability") = "fixed"; + metadata_.append_attribute("initial") = "calculated"; + + auto real = metadata_.append_child("Real"); + real.append_attribute("quantity") = "ThermodynamicTemperature"; + real.append_attribute("relativeQuantity") = "false"; + real.append_attribute("unit") = units::toString(mo_unit_).c_str(); + } + + void TOutHea::Update(EnergyPlus::EnergyPlusData &energyplus_data) + { + SetValue(energyplus::ZoneOutdoorTempAtPeakHeat(energyplus_data, zone_num_), units::UnitSystem::EP); + } + + void XOutHea::create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables) + { + int value_reference = variables.size(); // NOLINT + const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + + for (const auto &zone : zones) { + std::string zone_name = zone.value("name", ""); + int zone_num = energyplus::ZoneNum(energyplus_data, zone_name); + + variables.push_back(std::unique_ptr(new XOutHea(zone_name, zone_num, value_reference))); + value_reference++; + } + } + + XOutHea::XOutHea(std::string_view zone_name, int zone_num, int value_reference) // NOLINT + : OutputVariable( + std::string(zone_name) + "_XOutHea", value_reference, units::UnitType::one, units::UnitType::one), + zone_num_(zone_num) + { + metadata_.set_name("ScalarVariable"); + metadata_.append_attribute("name") = name_.c_str(); + metadata_.append_attribute("valueReference") = std::to_string(value_reference_).c_str(); + metadata_.append_attribute("description") = + "Outdoor humidity ratio at the heating design load per total air mass of the zone"; + metadata_.append_attribute("causality") = "calculatedParameter"; + metadata_.append_attribute("variability") = "fixed"; + metadata_.append_attribute("initial") = "calculated"; + + auto real = metadata_.append_child("Real"); + real.append_attribute("relativeQuantity") = "false"; + real.append_attribute("unit") = units::toString(mo_unit_).c_str(); + } + + void XOutHea::Update(EnergyPlus::EnergyPlusData &energyplus_data) + { + SetValue(energyplus::ZoneOutdoorHumidityRatioAtPeakHeat(energyplus_data, zone_num_), units::UnitSystem::EP); + } + + void MOutHeaFlow::create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables) + { + int value_reference = variables.size(); // NOLINT + const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + + for (const auto &zone : zones) { + std::string zone_name = zone.value("name", ""); + int zone_num = energyplus::ZoneNum(energyplus_data, zone_name); + + variables.push_back(std::unique_ptr(new MOutHeaFlow(zone_name, zone_num, value_reference))); + value_reference++; + } + } + + MOutHeaFlow::MOutHeaFlow(std::string_view zone_name, int zone_num, int value_reference) // NOLINT + : OutputVariable(std::string(zone_name) + "_mOutHea_flow", + value_reference, + units::UnitType::kg_per_s, + units::UnitType::kg_per_s), + zone_num_(zone_num) + { + metadata_.set_name("ScalarVariable"); + metadata_.append_attribute("name") = name_.c_str(); + metadata_.append_attribute("valueReference") = std::to_string(value_reference_).c_str(); + metadata_.append_attribute("description") = "Minimum outdoor air flow rate during the heating design load"; + metadata_.append_attribute("causality") = "calculatedParameter"; + metadata_.append_attribute("variability") = "fixed"; + metadata_.append_attribute("initial") = "calculated"; + + auto real = metadata_.append_child("Real"); + real.append_attribute("quantity") = "MassFlowRate"; + real.append_attribute("relativeQuantity") = "false"; + real.append_attribute("unit") = units::toString(mo_unit_).c_str(); + } + + void MOutHeaFlow::Update([[maybe_unused]] EnergyPlus::EnergyPlusData &energyplus_data) + { + // TODO: get this value + } + + void THea::create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables) + { + int value_reference = variables.size(); // NOLINT + const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + + for (const auto &zone : zones) { + std::string zone_name = zone.value("name", ""); + int zone_num = energyplus::ZoneNum(energyplus_data, zone_name); + + variables.push_back(std::unique_ptr(new THea(zone_name, zone_num, value_reference))); + value_reference++; + } + } + + THea::THea(std::string_view zone_name, int zone_num, int value_reference) // NOLINT + : OutputVariable(std::string(zone_name) + "_THea", value_reference, units::UnitType::s, units::UnitType::s), + zone_num_(zone_num) + { + metadata_.set_name("ScalarVariable"); + metadata_.append_attribute("name") = name_.c_str(); + metadata_.append_attribute("valueReference") = std::to_string(value_reference_).c_str(); + metadata_.append_attribute("description") = "Time at which these loads occurred"; + metadata_.append_attribute("causality") = "calculatedParameter"; + metadata_.append_attribute("variability") = "fixed"; + metadata_.append_attribute("initial") = "calculated"; + + auto real = metadata_.append_child("Real"); + real.append_attribute("quantity") = "Time"; + real.append_attribute("relativeQuantity") = "false"; + real.append_attribute("unit") = units::toString(mo_unit_).c_str(); + } + + void THea::Update([[maybe_unused]] EnergyPlus::EnergyPlusData &energyplus_data) + { + // TODO get this value + SetValue(0.0, units::UnitSystem::EP); + } + MInletsFlow::MInletsFlow(std::string_view zone_name, int zone_num, int value_reference) // NOLINT : InputVariable(std::string(zone_name) + "_mInlets_flow", value_reference, @@ -2020,12 +2289,17 @@ void CreateVariables(const Input &input, EnergyPlus::EnergyPlusData &energyplus_ zone::QLatFlow::create(input, energyplus_data, variables); zone::QPeoFlow::create(input, energyplus_data, variables); zone::TRad::create(input, energyplus_data, variables); - zone::QCooSenFlow::create(input, energyplus_data, variables); zone::QCooLatFlow::create(input, energyplus_data, variables); zone::TOutCoo::create(input, energyplus_data, variables); zone::XOutCoo::create(input, energyplus_data, variables); - + zone::MOutCooFlow::create(input, energyplus_data, variables); + zone::TCoo::create(input, energyplus_data, variables); + zone::QHeaFlow::create(input, energyplus_data, variables); + zone::TOutHea::create(input, energyplus_data, variables); + zone::XOutHea::create(input, energyplus_data, variables); + zone::MOutHeaFlow::create(input, energyplus_data, variables); + zone::THea::create(input, energyplus_data, variables); zone::MInletsFlow::create(input, energyplus_data, variables); zone::TAveInlet::create(input, energyplus_data, variables); zone::T::create(input, energyplus_data, variables); diff --git a/energyplus_coroutine/variables.hpp b/energyplus_coroutine/variables.hpp index 1a0364e1f..7bbe89f16 100644 --- a/energyplus_coroutine/variables.hpp +++ b/energyplus_coroutine/variables.hpp @@ -1,7 +1,6 @@ #ifndef Variables_hh_INCLUDED #define Variables_hh_INCLUDED -#include "energyplus_helpers.hpp" #include "units.hpp" #include #include @@ -54,6 +53,10 @@ enum class VariableType using VariableAttribute = std::pair; +namespace EnergyPlus { +struct EnergyPlusData; +} + namespace spawn { namespace units { enum class UnitSystem; @@ -273,6 +276,83 @@ namespace zone { int zone_num_; }; + class MOutCooFlow : public OutputVariable + { + public: + static void create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables); + void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; + + private: + explicit MOutCooFlow(std::string_view zone_name, int zone_num, int value_reference); + int zone_num_; + }; + + class TCoo : public OutputVariable + { + public: + static void create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables); + void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; + + private: + explicit TCoo(std::string_view zone_name, int zone_num, int value_reference); + int zone_num_; + }; + + class QHeaFlow : public OutputVariable + { + public: + static void create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables); + void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; + + private: + explicit QHeaFlow(std::string_view zone_name, int zone_num, int value_reference); + int zone_num_; + }; + + class TOutHea : public OutputVariable + { + public: + static void create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables); + void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; + + private: + explicit TOutHea(std::string_view zone_name, int zone_num, int value_reference); + int zone_num_; + }; + + class XOutHea : public OutputVariable + { + public: + static void create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables); + void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; + + private: + explicit XOutHea(std::string_view zone_name, int zone_num, int value_reference); + int zone_num_; + }; + + class MOutHeaFlow : public OutputVariable + { + public: + static void create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables); + void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; + + private: + explicit MOutHeaFlow(std::string_view zone_name, int zone_num, int value_reference); + int zone_num_; + }; + + class THea : public OutputVariable + { + public: + static void create(const Input &input, EnergyPlus::EnergyPlusData &energyplus_data, Variables &variables); + void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; + + private: + explicit THea(std::string_view zone_name, int zone_num, int value_reference); + int zone_num_; + }; + class MInletsFlow : public InputVariable { public: @@ -478,41 +558,4 @@ namespace construction { } // namespace spawn::variable -//// Output VariableType::V, -//// Output VariableType::AFLO, -//// Output VariableType::MSENFAC, -//// Output VariableType::QCONSEN_FLOW, -//// Output VariableType::QLAT_FLOW, -//// Output VariableType::QPEO_FLOW, -//// Output VariableType::TRAD, -//// Output VariableType::SENSOR, -//// Output VariableType::ASURF, -//// Output VariableType::QSURF, -//// Output VariableType::QSURF_FRONT, -//// Output VariableType::QSURF_BACK, - -//// Input VariableType::MINLETS_FLOW, -//// Input VariableType::TAVEINLET, -//// Input VariableType::T: -//// Input VariableType::X: -//// Input VariableType::EMS_ACTUATOR: -//// Input VariableType::SCHEDULE: -//// Input VariableType::QGAIRAD_FLOW: -//// Input VariableType::TSURF_FRONT: -//// Input VariableType::TSURF: -//// Input VariableType::TSURF_BACK: -// -// // Sizing related parameters -//// QCOOSEN_FLOW, -//// QCOOLAT_FLOW, -//// TOUTCOO, -// XOUTCOO, -// TCOO, -// QHEA_FLOW, -// TOUTHEA, -// XOUTHEA, -// MOUTCOO_FLOW, -// MOUTHEA_FLOW, -// THEA - #endif // Variables_hh_INCLUDED