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 15, 2024
1 parent 4546331 commit 0a935cf
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 131 deletions.
14 changes: 7 additions & 7 deletions energyplus_coroutine/energyplus_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int ZoneNum(EnergyPlus::EnergyPlusData &energyplus_data, const std::string_view
[[nodiscard]] double ZoneDesignCoolingLoad(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num)
{
if (!energyplus_data.dataSize->FinalZoneSizing.empty()) {
return energyplus_data.dataSize->FinalZoneSizing[zone_num].DesCoolLoad;
return energyplus_data.dataSize->FinalZoneSizing(zone_num).DesCoolLoad;
}

return 0.0;
Expand All @@ -97,7 +97,7 @@ int ZoneNum(EnergyPlus::EnergyPlusData &energyplus_data, const std::string_view
[[nodiscard]] double ZoneDesignCoolingLatentLoad(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num)
{
if (!energyplus_data.dataSize->FinalZoneSizing.empty()) {
return energyplus_data.dataSize->FinalZoneSizing[zone_num].DesLatentCoolLoad;
return energyplus_data.dataSize->FinalZoneSizing(zone_num).DesLatentCoolLoad;
}

return 0.0;
Expand All @@ -106,7 +106,7 @@ int ZoneNum(EnergyPlus::EnergyPlusData &energyplus_data, const std::string_view
[[nodiscard]] double ZoneOutdoorTempAtPeakCool(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num)
{
if (!energyplus_data.dataSize->FinalZoneSizing.empty()) {
return energyplus_data.dataSize->FinalZoneSizing[zone_num].OutTempAtCoolPeak;
return energyplus_data.dataSize->FinalZoneSizing(zone_num).OutTempAtCoolPeak;
}

return 0.0;
Expand All @@ -115,7 +115,7 @@ int ZoneNum(EnergyPlus::EnergyPlusData &energyplus_data, const std::string_view
[[nodiscard]] double ZoneOutdoorHumidityRatioAtPeakCool(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num)
{
if (!energyplus_data.dataSize->FinalZoneSizing.empty()) {
return energyplus_data.dataSize->FinalZoneSizing[zone_num].OutHumRatAtCoolPeak;
return energyplus_data.dataSize->FinalZoneSizing(zone_num).OutHumRatAtCoolPeak;
}

return 0.0;
Expand All @@ -129,7 +129,7 @@ int ZoneNum(EnergyPlus::EnergyPlusData &energyplus_data, const std::string_view
[[nodiscard]] double ZoneDesignHeatingLoad(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num)
{
if (!energyplus_data.dataSize->FinalZoneSizing.empty()) {
return energyplus_data.dataSize->FinalZoneSizing[zone_num].DesHeatLoad;
return energyplus_data.dataSize->FinalZoneSizing(zone_num).DesHeatLoad;
}

return 0.0;
Expand All @@ -138,7 +138,7 @@ int ZoneNum(EnergyPlus::EnergyPlusData &energyplus_data, const std::string_view
[[nodiscard]] double ZoneOutdoorTempAtPeakHeat(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num)
{
if (!energyplus_data.dataSize->FinalZoneSizing.empty()) {
return energyplus_data.dataSize->FinalZoneSizing[zone_num].OutTempAtHeatPeak;
return energyplus_data.dataSize->FinalZoneSizing(zone_num).OutTempAtHeatPeak;
}

return 0.0;
Expand All @@ -147,7 +147,7 @@ int ZoneNum(EnergyPlus::EnergyPlusData &energyplus_data, const std::string_view
[[nodiscard]] double ZoneOutdoorHumidityRatioAtPeakHeat(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num)
{
if (!energyplus_data.dataSize->FinalZoneSizing.empty()) {
return energyplus_data.dataSize->FinalZoneSizing[zone_num].OutHumRatAtHeatPeak;
return energyplus_data.dataSize->FinalZoneSizing(zone_num).OutHumRatAtHeatPeak;
}

return 0.0;
Expand Down
59 changes: 13 additions & 46 deletions energyplus_coroutine/spawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,9 @@ void Spawn::updateZoneHumidityRatio(const int zonenum, const double dt)

void Spawn::updateZoneConditions(bool skipConnectedZones)
{
// Check for...
if (
// 1. The beginning of the environment
sim_state.dataGlobal->BeginEnvrnFlag ||
// 2. The first call after warmup
(prevWarmupFlag && !(sim_state.dataGlobal->WarmupFlag))) {
prevZoneUpdate = currentTime();
} else {
const double dt = currentTime() - prevZoneUpdate;
prevZoneUpdate = currentTime();
const double dt = currentTime() - prevZoneUpdate;
prevZoneUpdate = currentTime();
if (dt > 0.0) {

for (const auto &zone : user_config_.zones) {
if (skipConnectedZones && zone.isconnected) {
Expand All @@ -388,8 +381,6 @@ void Spawn::updateZoneConditions(bool skipConnectedZones)
updateZoneHumidityRatio(zonenum, dt);
}
}

prevWarmupFlag = sim_state.dataGlobal->WarmupFlag;
}

void Spawn::updateLatentGains()
Expand Down Expand Up @@ -438,51 +429,27 @@ void Spawn::exchange(const bool force)
need_update = false;
}

void Spawn::initZoneEquip()
{
if (!sim_state.dataZoneEquip->ZoneEquipInputsFilled) {
EnergyPlus::DataZoneEquipment::GetZoneEquipmentData(sim_state);
sim_state.dataZoneEquip->ZoneEquipInputsFilled = true;
}
}

void Spawn::externalHVACManager([[maybe_unused]] EnergyPlusState state)
{
// Don't run external HVAC during sizing
if (sim_state.dataGlobal->ZoneSizingCalc) {
if (sim_state.dataGlobal->KickOffSimulation) {
// ManageHVAC initializes many structures that need to exist.
// Withouth calling this during the simulation kick off, the simulation will crash.
// After kick off, we skip this call, because the client is managing the HVAC.
EnergyPlus::HVACManager::ManageHVAC(sim_state);
// At this time, there is no data exchange or any other
// interaction with the client during kick off, so this funciton returns and the
// simulation continues through the startup process.
return;
}

// Although we do not use the ZoneTempPredictorCorrector,
// some global variables need to be initialized by InitZoneAirSetPoints
// This is protected by a one time flag so that it will only happen once
// during the simulation
if (sim_state.dataZoneCtrls->GetZoneAirStatsInputFlag) {
EnergyPlus::ZoneTempPredictorCorrector::GetZoneAirSetPoints(sim_state);
EnergyPlus::ZoneTempPredictorCorrector::InitZoneAirSetPoints(sim_state);
sim_state.dataZoneCtrls->GetZoneAirStatsInputFlag = false;
}

// Likewise init zone equipment one time
initZoneEquip();

// At this time, there is no data exchange or any other
// interaction with the FMU while KickOffSimulation is true.
// Sensors and actuators may not be setup at this point, so exchange
// might trigger exceptions
if (sim_state.dataGlobal->KickOffSimulation) {
// Similarly, there is no interaction with the client during warmup and sizing, so return now before signaling
if (sim_state.dataGlobal->DoingSizing || sim_state.dataGlobal->WarmupFlag) {
return;
}

// Exchange data with the FMU
exchange(true);

// There is no interaction with the FMU during warmup,
// so return now before signaling
if (sim_state.dataGlobal->DoingSizing || sim_state.dataGlobal->WarmupFlag) {
return;
}

// Only signal and wait for input if the current sim time is greather than or equal
// to the requested time
if (currentTime() >= requested_time_) {
Expand Down
3 changes: 1 addition & 2 deletions energyplus_coroutine/spawn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,9 @@ class Spawn
// updateZoneTemperature and updateZoneHumidityRatio calculations
double prevZoneUpdate{};
// State of the warmup flag during the previous zone update
bool prevWarmupFlag{false};
// bool prevWarmupFlag{false};

void updateLatentGains();
void initZoneEquip();

// WarmupManager will register its own callbacks during construction
// Maybe all of Spawn's implementation can be derived from "Manager" class
Expand Down
Loading

0 comments on commit 0a935cf

Please sign in to comment.