Skip to content

Commit

Permalink
WIP: Refactor variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kbenne committed Aug 1, 2024
1 parent 7eae7e5 commit 7fe417c
Show file tree
Hide file tree
Showing 4 changed files with 384 additions and 41 deletions.
19 changes: 18 additions & 1 deletion energyplus_coroutine/energyplus_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
9 changes: 9 additions & 0 deletions energyplus_coroutine/energyplus_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
278 changes: 276 additions & 2 deletions energyplus_coroutine/variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<json>(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<MOutCooFlow>(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<json>(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<TCoo>(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<json>(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<QHeaFlow>(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
Expand All @@ -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<json>(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<TOutHea>(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<json>(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<XOutHea>(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<json>(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<MOutHeaFlow>(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<json>(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<THea>(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,
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 7fe417c

Please sign in to comment.