-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,062 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,155 @@ | ||
#include "spawn.hpp" | ||
#include "energyplus_helpers.hpp" | ||
#include "util/conversion.hpp" | ||
#include <DataGlobals.hh> | ||
#include <DataHeatBalSurface.hh> | ||
#include <DataHeatBalance.hh> | ||
#include <EnergyPlusData.hh> | ||
#include <api/datatransfer.h> | ||
#include <string_view> | ||
|
||
namespace spawn { | ||
namespace spawn::energyplus { | ||
|
||
int ZoneNum(Spawn &spawn, std::string_view zone_name) | ||
ZoneSums::ZoneSums(EnergyPlus::EnergyPlusData &energyplus_data, int zone_num) | ||
{ | ||
auto &zone_heat_balance = energyplus_data.dataZoneTempPredictorCorrector->zoneHeatBalance(zone_num); | ||
zone_heat_balance.calcZoneOrSpaceSums(energyplus_data, true, zone_num); | ||
|
||
temp_dep_coef_ = zone_heat_balance.SumHA + zone_heat_balance.SumMCp; | ||
temp_ind_coef_ = zone_heat_balance.SumIntGain + zone_heat_balance.SumHATsurf + zone_heat_balance.SumMCpT; | ||
|
||
// Refer to | ||
// https://bigladdersoftware.com/epx/docs/8-8/engineering-reference/basis-for-the-zone-and-air-system-integration.html#basis-for-the-zone-and-air-system-integration | ||
q_con_sen_flow_ = temp_ind_coef_ - (temp_dep_coef_ * zone_heat_balance.MAT); | ||
} | ||
|
||
double ZoneSums::TempDepCoef() const | ||
{ | ||
return temp_dep_coef_; | ||
} | ||
|
||
double ZoneSums::TempIndCoef() const | ||
{ | ||
return temp_ind_coef_; | ||
} | ||
|
||
double ZoneSums::QConSenFlow() const | ||
{ | ||
return q_con_sen_flow_; | ||
} | ||
|
||
int ZoneNum(const EnergyPlus::EnergyPlusData &energyplus_data, const std::string_view zone_name) | ||
{ | ||
auto upper_zone_name = zone_name; | ||
std::transform(zone_name.begin(), zone_name.end(), upper_zone_name.begin(), ::toupper); | ||
|
||
for (int i = 0; i < spawn.EnergyPlusData().dataGlobal->NumOfZones; ++i) { | ||
if (spawn.EnergyPlusData().dataHeatBal->Zone[as_size_t(i)].Name == upper_zone_name) { | ||
for (int i = 0; i < energyplus_data.dataGlobal->NumOfZones; ++i) { | ||
if (energyplus_data.dataHeatBal->Zone[as_size_t(i)].Name == upper_zone_name) { | ||
return i + 1; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
[[nodiscard]] double ZoneVolume(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num) | ||
{ | ||
return energyplus_data.dataHeatBal->Zone(zone_num).Volume; | ||
} | ||
|
||
[[nodiscard]] double ZoneFloorArea(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num) | ||
{ | ||
return energyplus_data.dataHeatBal->Zone(zone_num).FloorArea; | ||
} | ||
|
||
[[nodiscard]] double ZoneVolCapMultpSens(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num) | ||
{ | ||
return energyplus_data.dataHeatBal->Zone(zone_num).ZoneVolCapMultpSens; | ||
} | ||
|
||
[[nodiscard]] double ZoneLatentGain(const EnergyPlus::EnergyPlusData &energyplus_data, int zone_num) | ||
{ | ||
return energyplus_data.dataZoneTempPredictorCorrector->zoneHeatBalance(zone_num).latentGain; | ||
} | ||
|
||
[[nodiscard]] double ZonePeopleHeatGain([[maybe_unused]] const EnergyPlus::EnergyPlusData &energyplus_data, | ||
[[maybe_unused]] int zone_num) | ||
{ | ||
// TODO: Fix this | ||
return 0.0; | ||
} | ||
|
||
[[nodiscard]] double ZoneMeanRadiantTemp([[maybe_unused]] const EnergyPlus::EnergyPlusData &energyplus_data, | ||
[[maybe_unused]] int zone_num) | ||
{ | ||
return energyplus_data.dataZoneTempPredictorCorrector->zoneHeatBalance(zone_num).MRT; | ||
} | ||
|
||
void SetZoneTemperature(EnergyPlus::EnergyPlusData &energyplus_data, const int zone_num, const double &temp) | ||
{ | ||
auto &zone_heat_balance = energyplus_data.dataZoneTempPredictorCorrector->zoneHeatBalance(zone_num); | ||
// Is it necessary to update all of these or can we | ||
// simply update ZT and count on EnergyPlus::HeatBalanceAirManager::ReportZoneMeanAirTemp() | ||
// to propogate the other variables? | ||
zone_heat_balance.ZT = temp; | ||
zone_heat_balance.ZTAV = temp; | ||
zone_heat_balance.MAT = temp; | ||
} | ||
|
||
[[nodiscard]] int | ||
VariableHandle(EnergyPlus::EnergyPlusData &energyplus_data, const std::string_view name, const std::string_view key) | ||
{ | ||
const auto h = ::getVariableHandle( | ||
static_cast<EnergyPlusState>(&energyplus_data), std::string(name).c_str(), std::string(key).c_str()); | ||
if (h == -1) { | ||
throw std::runtime_error(fmt::format("Attempt to get invalid variable using name '{}', and key '{}'", name, key)); | ||
} | ||
|
||
return h; | ||
} | ||
|
||
[[nodiscard]] double VariableValue(EnergyPlus::EnergyPlusData &energyplus_data, int handle) | ||
{ | ||
return ::getVariableValue(static_cast<EnergyPlusState>(&energyplus_data), handle); | ||
} | ||
|
||
[[nodiscard]] int SurfaceNum(EnergyPlus::EnergyPlusData &energyplus_data, std::string_view surface_name) | ||
{ | ||
std::string upper_name(surface_name); | ||
|
||
std::transform(surface_name.begin(), surface_name.end(), upper_name.begin(), ::toupper); | ||
for (const auto i : energyplus_data.dataSurface->AllHTNonWindowSurfaceList) { | ||
if (energyplus_data.dataSurface->Surface[as_size_t(i)].Name == upper_name) { | ||
return i + 1; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
} // namespace spawn | ||
[[nodiscard]] double SurfaceArea(EnergyPlus::EnergyPlusData &energyplus_data, int surface_num) | ||
{ | ||
return energyplus_data.dataSurface->Surface(surface_num).GrossArea; | ||
} | ||
|
||
[[nodiscard]] double SurfaceInsideHeatFlow(EnergyPlus::EnergyPlusData &energyplus_data, int surface_num) | ||
{ | ||
return energyplus_data.dataHeatBalSurf->SurfQdotConvInRep(surface_num) + | ||
energyplus_data.dataHeatBalSurf->SurfQdotRadNetSurfInRep(surface_num); | ||
} | ||
|
||
[[nodiscard]] double SurfaceOutsideHeatFlow(EnergyPlus::EnergyPlusData &energyplus_data, int surface_num) | ||
{ | ||
auto &surface = energyplus_data.dataSurface->Surface(as_size_t(surface_num)); | ||
auto &ext_bound_cond = surface.ExtBoundCond; | ||
if (ext_bound_cond > 0) { | ||
// EnergyPlus does not calculate the surface heat flux for interzone surfaces, | ||
// instead return the inside face heat flux of the matching surface | ||
return energyplus_data.dataHeatBalSurf->SurfQdotConvInRep(ext_bound_cond) + | ||
energyplus_data.dataHeatBalSurf->SurfQdotRadNetSurfInRep(ext_bound_cond); | ||
} else { | ||
return energyplus_data.dataHeatBalSurf->SurfQdotConvOutRep(surface_num) + | ||
energyplus_data.dataHeatBalSurf->SurfQdotRadOutRep(surface_num); | ||
} | ||
} | ||
|
||
} // namespace spawn::energyplus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.