Skip to content

Commit

Permalink
Add support for autosizing
Browse files Browse the repository at this point in the history
This change adds new outputs for zone sizing information. There are a
few limitations.

* Coincident sizing between zones is not yet supported, but is in the
  spec, and will be added later.
* Outputs related to the time of peak load are not yet populated.
* Need formal test methodolgy for this feature.
  • Loading branch information
kbenne committed Jun 28, 2024
1 parent d77597e commit 790306e
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0025 NEW)
cmake_minimum_required(VERSION 3.13)

project(Spawn VERSION 0.5.0)
project(Spawn VERSION 0.6.0)
include(CTest)

set(CMAKE_CXX_STANDARD 17)
Expand Down
5 changes: 4 additions & 1 deletion energyplus_coroutine/iddtypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace spawn {
constexpr std::array<const char *, 4> supportedScheduleTypes = {
"Schedule:Year", "Schedule:Compact", "Schedule:Constant", "Schedule:File"};

constexpr std::array<const char *, 287> supportedIDDTypes = {
constexpr std::array<const char *, 290> supportedIDDTypes = {
"Version",
"SimulationControl",
"PerformancePrecisionTradeoffs",
Expand All @@ -26,6 +26,9 @@ constexpr std::array<const char *, 287> supportedIDDTypes = {
"RunPeriod",
"RunPeriodControl:SpecialDays",
"RunPeriodControl:DaylightSavingTime",
"SizingPeriod:DesignDay",
"SizingPeriod:WeatherFileDays",
"SizingPeriod:WeatherFileConditionType",
"WeatherProperty:SkyTemperature",
"Site:WeatherStation",
"Site:HeightVariation",
Expand Down
10 changes: 6 additions & 4 deletions energyplus_coroutine/idfprep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@

namespace spawn {

json &adjustSimulationControl(json &jsonidf)
json &adjustSimulationControl(json &jsonidf, const Input &input)
{
constexpr auto simulationcontroltype = "SimulationControl";

// Remove the existing control first
jsonidf.erase(simulationcontroltype);

// TODO: fix this slop. Please add a consistent method of handling bool types
const auto autosize = input.autosize() ? "Yes" : "No";
// This is what we need for spawn
jsonidf[simulationcontroltype] = {{"Spawn-SimulationControl",
{{"do_plant_sizing_calculation", "No"},
{"do_system_sizing_calculation", "No"},
{"do_zone_sizing_calculation", "No"},
{"run_simulation_for_sizing_periods", "No"},
{"do_zone_sizing_calculation", autosize},
{"run_simulation_for_sizing_periods", autosize},
{"run_simulation_for_weather_file_run_periods", "Yes"}}}};

return jsonidf;
Expand Down Expand Up @@ -328,7 +330,7 @@ json &removeInfiltration(json &jsonidf, const Input &input)

void prepare_idf(json &jsonidf, const Input &input, const StartTime &start_time)
{
adjustSimulationControl(jsonidf);
adjustSimulationControl(jsonidf, input);
removeUnusedObjects(jsonidf);
addRunPeriod(jsonidf, input, start_time);
removeInfiltration(jsonidf, input);
Expand Down
5 changes: 5 additions & 0 deletions energyplus_coroutine/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ void Input::setEPWInputPath(const spawn_fs::path &epwpath)
spawnjson["EnergyPlus"]["weather"] = epwpath.string();
}

bool Input::autosize() const
{
return spawnjson.value("EnergyPlus", json()).value("autosize", false);
}

void Input::save(const spawn_fs::path &savepath) const
{
std::ofstream o(savepath.string());
Expand Down
2 changes: 2 additions & 0 deletions energyplus_coroutine/input/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Input
[[nodiscard]] spawn_fs::path epwInputPath() const;
void setEPWInputPath(const spawn_fs::path &epwpath);

[[nodiscard]] bool autosize() const;

double relativeSurfaceTolerance() const;

void save(const spawn_fs::path &savepath) const;
Expand Down
86 changes: 86 additions & 0 deletions energyplus_coroutine/spawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ void Spawn::start()
sim_thread.join();
}

// This will poppulate const parameters such as the zone sizing values
initConstParameters();

// This will make sure that we have a data exchange
setTime(start_time_.Seconds());
}
Expand Down Expand Up @@ -562,6 +565,84 @@ double Spawn::getSensorValue(Variable &var)
return getVariableValue(simState(), h);
}

void Spawn::initConstParameters()
{
isRunningCheck();

// TODO: look for a better way to check sizing.
// DoZoneSizing does not indicate that sizing was done,
// so we have to be careful about when to call initConstParameters
// sim_state.dataSize->FinalZoneSizing will not be filled out if zone sizing do not happen
if (!sim_state.dataGlobal->DoZoneSizing) {
return;
}

for (auto &varmap : variables) {
auto &var = varmap.second;
auto zone_num = zoneNum(var.name);

switch (var.type) { // NOLINT
case VariableType::QCOOSEN_FLOW: {
const auto value = sim_state.dataSize->FinalZoneSizing[zone_num].DesCoolLoad;
var.setValue(value, spawn::units::UnitSystem::EP);
break;
}
case VariableType::QCOOLAT_FLOW: {
const auto value = sim_state.dataSize->FinalZoneSizing[zone_num].DesLatentCoolLoad;
var.setValue(value, spawn::units::UnitSystem::EP);
break;
}
case VariableType::TOUTCOO: {
const auto value = sim_state.dataSize->FinalZoneSizing[zone_num].OutTempAtCoolPeak;
var.setValue(value, spawn::units::UnitSystem::EP);
break;
}
case VariableType::XOUTCOO: {
const auto value = sim_state.dataSize->FinalZoneSizing[zone_num].OutHumRatAtLatentCoolPeak;
var.setValue(value, spawn::units::UnitSystem::EP);
break;
}
case VariableType::TCOO: {
const auto value = 0;
var.setValue(value, spawn::units::UnitSystem::EP);
break;
}
case VariableType::QHEA_FLOW: {
const auto value = sim_state.dataSize->FinalZoneSizing[zone_num].DesHeatLoad;
var.setValue(value, spawn::units::UnitSystem::EP);
break;
}
case VariableType::TOUTHEA: {
const auto value = sim_state.dataSize->FinalZoneSizing[zone_num].OutTempAtHeatPeak;
var.setValue(value, spawn::units::UnitSystem::EP);
break;
}
case VariableType::XOUTHEA: {
const auto value = sim_state.dataSize->FinalZoneSizing[zone_num].OutHumRatAtLatentHeatPeak;
var.setValue(value, spawn::units::UnitSystem::EP);
break;
}
case VariableType::MOUTCOO_FLOW: {
const auto value = 0;
var.setValue(value, spawn::units::UnitSystem::EP);
break;
}
case VariableType::MOUTHEA_FLOW: {
const auto value = 0;
var.setValue(value, spawn::units::UnitSystem::EP);
break;
}
case VariableType::THEA: {
const auto value = 0;
var.setValue(value, spawn::units::UnitSystem::EP);
break;
}
default:
break;
}
}
}

void Spawn::exchange(const bool force)
{
isRunningCheck();
Expand Down Expand Up @@ -719,6 +800,11 @@ void Spawn::initZoneEquip()

void Spawn::externalHVACManager([[maybe_unused]] EnergyPlusState state)
{
// Don't run external HVAC during sizing
if (sim_state.dataGlobal->ZoneSizingCalc) {
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
Expand Down
4 changes: 4 additions & 0 deletions energyplus_coroutine/spawn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ class Spawn
double getInsideSurfaceHeatFlow(const int surfacenum) const;
double getOutsideSurfaceHeatFlow(const int surfacenum) const;

// Initialize Variables that have fixed values that do not change during the simulation.
// This should be called at the end of the ::start() sequence.
void initConstParameters();

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

0 comments on commit 790306e

Please sign in to comment.