diff --git a/energyplus_coroutine/CMakeLists.txt b/energyplus_coroutine/CMakeLists.txt index 0b5329ddf..c19942990 100644 --- a/energyplus_coroutine/CMakeLists.txt +++ b/energyplus_coroutine/CMakeLists.txt @@ -22,8 +22,8 @@ add_library( variables.hpp variables.cpp - warmupmanager.hpp - warmupmanager.cpp + warmup_manager.hpp + warmup_manager.cpp input/emsactuator.hpp input/emsactuator.cpp diff --git a/energyplus_coroutine/energyplus_helpers.cpp b/energyplus_coroutine/energyplus_helpers.cpp new file mode 100644 index 000000000..b3d8b9b83 --- /dev/null +++ b/energyplus_coroutine/energyplus_helpers.cpp @@ -0,0 +1,21 @@ +#include "spawn.hpp" +#include "util/conversion.hpp" +#include + +namespace spawn { + +int ZoneNum(Spawn &spawn, 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) { + return i + 1; + } + } + + return 0; +} + +} // namespace spawn diff --git a/energyplus_coroutine/energyplus_helpers.hpp b/energyplus_coroutine/energyplus_helpers.hpp new file mode 100644 index 000000000..87ebcfe30 --- /dev/null +++ b/energyplus_coroutine/energyplus_helpers.hpp @@ -0,0 +1,34 @@ +#include +#include + +namespace spawn { + +class ZoneSums +{ +public: + ZoneSums(EnergyPlus::EnergyPlusData &sim_state_, int zone_num) + { + auto &zone_heat_balance = sim_state_.dataZoneTempPredictorCorrector->zoneHeatBalance(zone_num); + zone_heat_balance.calcZoneOrSpaceSums(sim_state_, 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); + } + + [[nodiscard]] double TempDepCoef() const; + [[nodiscard]] double TempIndCoef() const; + [[nodiscard]] double QConSenFlow() const; + +private: + double temp_dep_coef_; + double temp_ind_coef_; + double q_con_sen_flow_; +}; + +[[nodiscard]] int ZoneNum(std::string_view zone_name); + +} // namespace spawn diff --git a/energyplus_coroutine/input/input.cpp b/energyplus_coroutine/input/input.cpp index 2ef573038..e2d272dee 100644 --- a/energyplus_coroutine/input/input.cpp +++ b/energyplus_coroutine/input/input.cpp @@ -36,7 +36,7 @@ Input::Input(const std::string &spawninput) zones = Zone::createZones(spawnjson, jsonidf); schedules = Schedule::createSchedules(spawnjson, jsonidf); - outputVariables = OutputVariable::createOutputVariables(spawnjson, jsonidf); + outputVariables = input::OutputVariable::createOutputVariables(spawnjson, jsonidf); emsActuators = EMSActuator::createEMSActuators(spawnjson, jsonidf); surfaces = Surface::createSurfaces(spawnjson, jsonidf); runPeriod = RunPeriod::create_run_period(spawnjson); diff --git a/energyplus_coroutine/input/input.hpp b/energyplus_coroutine/input/input.hpp index 3a24d4e6e..4e4645a10 100644 --- a/energyplus_coroutine/input/input.hpp +++ b/energyplus_coroutine/input/input.hpp @@ -22,7 +22,7 @@ class Input std::vector zones; std::vector schedules; - std::vector outputVariables; + std::vector outputVariables; std::vector emsActuators; std::vector surfaces; RunPeriod runPeriod; @@ -46,13 +46,14 @@ class Input void save(const spawn_fs::path &savepath) const; + nlohmann::json jsonidf; + nlohmann::json spawnjson; + private: // Return an expanded absolute path, // this will prepend basepath if the given pathstring is not absolute [[nodiscard]] spawn_fs::path toPath(const std::string &pathstring) const; - nlohmann::json jsonidf; - nlohmann::json spawnjson; spawn_fs::path m_basepath; }; diff --git a/energyplus_coroutine/input/outputvariable.cpp b/energyplus_coroutine/input/outputvariable.cpp index 74dd84b59..5a289bc22 100644 --- a/energyplus_coroutine/input/outputvariable.cpp +++ b/energyplus_coroutine/input/outputvariable.cpp @@ -6,17 +6,18 @@ using json = nlohmann::json; namespace spawn { -OutputVariable::OutputVariable(std::string t_spawnname, std::string t_idfname, std::string t_idfkey) noexcept +input::OutputVariable::OutputVariable(std::string t_spawnname, std::string t_idfname, std::string t_idfkey) noexcept : spawnname(std::move(t_spawnname)), idfname(std::move(t_idfname)), idfkey(std::move(t_idfkey)) { std::transform(idfname.begin(), idfname.end(), idfname.begin(), ::toupper); std::transform(idfkey.begin(), idfkey.end(), idfkey.begin(), ::toupper); } -std::vector OutputVariable::createOutputVariables(const nlohmann::json &spawnjson, - [[maybe_unused]] const nlohmann::json &jsonidf) +std::vector +input::OutputVariable::createOutputVariables(const nlohmann::json &spawnjson, + [[maybe_unused]] const nlohmann::json &jsonidf) { - std::vector result; + std::vector result; const auto spawnOutputVariables = spawnjson.value("model", json::object()).value("outputVariables", std::vector(0)); @@ -25,7 +26,7 @@ std::vector OutputVariable::createOutputVariables(const nlohmann const auto idfname = spawnOutputVariable.value("name", ""); const auto idfkey = spawnOutputVariable.value("key", ""); const auto &buildvariable = [&]() { - OutputVariable variable(spawnname, idfname, idfkey); + input::OutputVariable variable(spawnname, idfname, idfkey); return variable; }; result.emplace_back(buildvariable()); diff --git a/energyplus_coroutine/input/outputvariable.hpp b/energyplus_coroutine/input/outputvariable.hpp index 4bfc667f2..46919f36c 100644 --- a/energyplus_coroutine/input/outputvariable.hpp +++ b/energyplus_coroutine/input/outputvariable.hpp @@ -4,21 +4,23 @@ #include "../../energyplus/third_party/nlohmann/json.hpp" namespace spawn { +namespace input { -class OutputVariable -{ -public: - [[nodiscard]] static std::vector createOutputVariables(const nlohmann::json &spawnjson, - const nlohmann::json &jsonidf); + class OutputVariable + { + public: + [[nodiscard]] static std::vector createOutputVariables(const nlohmann::json &spawnjson, + const nlohmann::json &jsonidf); - std::string spawnname; - std::string idfname; - std::string idfkey; + std::string spawnname; + std::string idfname; + std::string idfkey; -private: - OutputVariable(std::string t_spawnname, std::string t_idfname, std::string t_idfkey) noexcept; -}; + private: + OutputVariable(std::string t_spawnname, std::string t_idfname, std::string t_idfkey) noexcept; + }; +} // namespace input } // namespace spawn #endif // outputvariable_hh_INCLUDED diff --git a/energyplus_coroutine/libspawn.i b/energyplus_coroutine/libspawn.i index cb41bf02b..108b3f7eb 100644 --- a/energyplus_coroutine/libspawn.i +++ b/energyplus_coroutine/libspawn.i @@ -6,7 +6,7 @@ %{ #include "input/input.hpp" #include "variables.hpp" -#include "warmupmanager.hpp" +#include "warmup_anager.hpp" #include "../energyplus/src/EnergyPlus/Data/EnergyPlusData.hh" #include "../energyplus/src/EnergyPlus/Data/CommonIncludes.hh" #include "../energyplus/src/EnergyPlus/api/state.h" diff --git a/energyplus_coroutine/spawn.cpp b/energyplus_coroutine/spawn.cpp index 893db7537..aabb02c4c 100644 --- a/energyplus_coroutine/spawn.cpp +++ b/energyplus_coroutine/spawn.cpp @@ -231,7 +231,7 @@ double Spawn::getValue(const unsigned int index) const unsigned int Spawn::getIndex(const std::string &name) const { - const auto pred = [&name](const std::pair &v) { return v.second.name == name; }; + const auto pred = [&name](const std::pair &v) { return v.second.name == name; }; const auto it = std::find_if(variables.begin(), variables.end(), pred); if (it == std::end(variables)) { @@ -559,7 +559,7 @@ void Spawn::resetActuator(const std::string &componenttype, ::resetActuator(simState(), h); } -double Spawn::getSensorValue(Variable &var) +double Spawn::getSensorValue(Variable_ &var) { const auto h = getVariableHandle(var.outputvarname, var.outputvarkey); return getVariableValue(simState(), h); @@ -623,16 +623,19 @@ void Spawn::initConstParameters() break; } case VariableType::MOUTCOO_FLOW: { + // TODO const auto value = 0; var.setValue(value, spawn::units::UnitSystem::EP); break; } case VariableType::MOUTHEA_FLOW: { + // TODO const auto value = 0; var.setValue(value, spawn::units::UnitSystem::EP); break; } case VariableType::THEA: { + // TODO const auto value = 0; var.setValue(value, spawn::units::UnitSystem::EP); break; @@ -651,7 +654,7 @@ void Spawn::exchange(const bool force) return; } - auto actuateVar = [&](const Variable &var) { + auto actuateVar = [&](const Variable_ &var) { if (var.isValueSet()) { setActuatorValue(var.actuatorcomponenttype, var.actuatorcontroltype, @@ -880,4 +883,9 @@ EnergyPlusState Spawn::simState() return static_cast(&sim_state); } +EnergyPlus::EnergyPlusData &Spawn::EnergyPlusData() +{ + return sim_state; +} + } // namespace spawn diff --git a/energyplus_coroutine/spawn.hpp b/energyplus_coroutine/spawn.hpp index f7731a68a..56c743439 100644 --- a/energyplus_coroutine/spawn.hpp +++ b/energyplus_coroutine/spawn.hpp @@ -8,7 +8,7 @@ #include "input/input.hpp" #include "start_time.hpp" #include "variables.hpp" -#include "warmupmanager.hpp" +#include "warmup_manager.hpp" #include #include #include @@ -69,11 +69,13 @@ class Spawn void exchange(const bool force = false); + EnergyPlus::EnergyPlusData &EnergyPlusData(); + private: std::string instanceName; spawn_fs::path workingdir; Input input; - std::map variables; + std::map variables; StartTime start_time_; double requested_time_{0.0}; @@ -157,7 +159,7 @@ class Spawn void resetActuator(const std::string &componenttype, const std::string &controltype, const std::string &componentname); - double getSensorValue(Variable &var); + double getSensorValue(Variable_ &var); void setInsideSurfaceTemperature(const int surfacenum, double temp); void setOutsideSurfaceTemperature(const int surfacenum, double temp); @@ -174,6 +176,8 @@ class Spawn // Maybe all of EnergyPlus can derive from Manager and the simulation is // a simple hierarchy of loops with callback points along the way WarmupManager warmupManager{sim_state}; + + std::vector> variables_; }; spawn_fs::path iddpath(); diff --git a/energyplus_coroutine/variables.cpp b/energyplus_coroutine/variables.cpp index e6f22fcf0..34cae7017 100644 --- a/energyplus_coroutine/variables.cpp +++ b/energyplus_coroutine/variables.cpp @@ -12,18 +12,19 @@ #include "output_types.hpp" #include #include +#include using json = nlohmann::json; using namespace spawn::units; -std::map parseVariables(const spawn::Input &input) +std::map parseVariables(const spawn::Input &input) { - std::map result; + std::map result; int i = 0; for (const auto &schedule : input.schedules) { const auto &buildvar = [&]() { - Variable var; + Variable_ var; var.type = VariableType::SCHEDULE; var.name = schedule.spawnname; var.epunittype = spawn::units::UnitType::one; @@ -51,7 +52,7 @@ std::map parseVariables(const spawn::Input &input) for (const auto &outputVariable : input.outputVariables) { const auto &build = [&]() { - Variable var; + Variable_ var; var.type = VariableType::SENSOR; var.name = outputVariable.spawnname; var.outputvarname = outputVariable.idfname; @@ -88,7 +89,7 @@ std::map parseVariables(const spawn::Input &input) for (const auto &act : input.emsActuators) { const auto build = [&]() { - Variable var; + Variable_ var; var.type = VariableType::EMS_ACTUATOR; var.name = act.spawnname; var.actuatorcomponentkey = act.idfname; @@ -116,7 +117,7 @@ std::map parseVariables(const spawn::Input &input) for (const auto &zone : input.zones) { if (zone.isconnected) { { - Variable var; + Variable_ var; var.type = VariableType::T; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::C; @@ -137,7 +138,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::QCONSEN_FLOW; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::W; @@ -158,7 +159,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::AFLO; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::m2; @@ -179,7 +180,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::V; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::m3; @@ -200,7 +201,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::MSENFAC; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::one; @@ -220,7 +221,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::QGAIRAD_FLOW; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::W; @@ -245,7 +246,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::QLAT_FLOW; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::W; @@ -266,7 +267,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::QPEO_FLOW; var.name = zone.idfname; var.outputvarname = zone.ep_qpeo_flow_output_var_name; @@ -289,7 +290,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::TAVEINLET; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::C; @@ -313,7 +314,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::TRAD; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::C; @@ -334,7 +335,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::X; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::one; @@ -358,7 +359,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::MINLETS_FLOW; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::kg_per_s; @@ -385,7 +386,7 @@ std::map parseVariables(const spawn::Input &input) ++i; { const auto var_name = zone.idfname + "_QCooSen_flow"; - Variable var; + Variable_ var; var.type = VariableType::QCOOSEN_FLOW; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::W; @@ -408,7 +409,7 @@ std::map parseVariables(const spawn::Input &input) ++i; { const auto var_name = zone.idfname + "_QCooLat_flow"; - Variable var; + Variable_ var; var.type = VariableType::QCOOLAT_FLOW; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::W; @@ -431,7 +432,7 @@ std::map parseVariables(const spawn::Input &input) ++i; { const auto var_name = zone.idfname + "_TOutCoo"; - Variable var; + Variable_ var; var.type = VariableType::TOUTCOO; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::C; @@ -454,7 +455,7 @@ std::map parseVariables(const spawn::Input &input) ++i; { const auto var_name = zone.idfname + "_XOutCoo"; - Variable var; + Variable_ var; var.type = VariableType::XOUTCOO; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::one; @@ -477,7 +478,7 @@ std::map parseVariables(const spawn::Input &input) ++i; { const auto var_name = zone.idfname + "_tCoo"; - Variable var; + Variable_ var; var.type = VariableType::TCOO; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::s; @@ -500,7 +501,7 @@ std::map parseVariables(const spawn::Input &input) ++i; { const auto var_name = zone.idfname + "_QHea_flow"; - Variable var; + Variable_ var; var.type = VariableType::QHEA_FLOW; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::W; @@ -523,7 +524,7 @@ std::map parseVariables(const spawn::Input &input) ++i; { const auto var_name = zone.idfname + "_TOutHea"; - Variable var; + Variable_ var; var.type = VariableType::TOUTHEA; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::C; @@ -546,7 +547,7 @@ std::map parseVariables(const spawn::Input &input) ++i; { const auto var_name = zone.idfname + "_XOutHea"; - Variable var; + Variable_ var; var.type = VariableType::XOUTHEA; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::one; @@ -569,7 +570,7 @@ std::map parseVariables(const spawn::Input &input) ++i; { const auto var_name = zone.idfname + "_tHea"; - Variable var; + Variable_ var; var.type = VariableType::THEA; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::s; @@ -592,7 +593,7 @@ std::map parseVariables(const spawn::Input &input) ++i; { const auto var_name = zone.idfname + "_mOutCoo_flow"; - Variable var; + Variable_ var; var.type = VariableType::MOUTCOO_FLOW; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::kg_per_s; @@ -616,7 +617,7 @@ std::map parseVariables(const spawn::Input &input) ++i; { const auto var_name = zone.idfname + "_mOutHea_flow"; - Variable var; + Variable_ var; var.type = VariableType::MOUTHEA_FLOW; var.name = zone.idfname; var.epunittype = spawn::units::UnitType::kg_per_s; @@ -644,7 +645,7 @@ std::map parseVariables(const spawn::Input &input) for (const auto &surface : input.surfaces) { if (surface.controltype == spawn::Surface::ControlType::FrontBack) { { - Variable var; + Variable_ var; var.type = VariableType::ASURF; var.name = surface.idfname; var.epunittype = spawn::units::UnitType::m2; @@ -666,7 +667,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::QSURF_FRONT; var.name = surface.idfname; var.epunittype = spawn::units::UnitType::W; @@ -690,7 +691,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::TSURF_FRONT; var.name = surface.idfname; var.actuatorcomponentkey = surface.idfname; @@ -715,7 +716,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::QSURF_BACK; var.name = surface.idfname; var.epunittype = spawn::units::UnitType::W; @@ -740,7 +741,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::TSURF_BACK; var.name = surface.idfname; var.actuatorcomponentkey = surface.idfname; @@ -766,7 +767,7 @@ std::map parseVariables(const spawn::Input &input) ++i; } else if (surface.controltype == spawn::Surface::ControlType::Front) { { - Variable var; + Variable_ var; var.type = VariableType::ASURF; var.name = surface.idfname; var.epunittype = spawn::units::UnitType::m2; @@ -788,7 +789,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::TSURF; var.name = surface.idfname; var.actuatorcomponentkey = surface.idfname; @@ -813,7 +814,7 @@ std::map parseVariables(const spawn::Input &input) } ++i; { - Variable var; + Variable_ var; var.type = VariableType::QSURF; var.name = surface.idfname; var.epunittype = spawn::units::UnitType::W; @@ -842,7 +843,7 @@ std::map parseVariables(const spawn::Input &input) return result; } -void Variable::setValue(const double &value, const spawn::units::UnitSystem &system) +void Variable_::setValue(const double &value, const spawn::units::UnitSystem &system) { valueset = true; switch (system) { @@ -855,7 +856,7 @@ void Variable::setValue(const double &value, const spawn::units::UnitSystem &sys } } -double Variable::getValue(const spawn::units::UnitSystem &system) const +double Variable_::getValue(const spawn::units::UnitSystem &system) const { switch (system) { case UnitSystem::MO: @@ -867,12 +868,90 @@ double Variable::getValue(const spawn::units::UnitSystem &system) const return 0.0; } -void Variable::resetValue() +void Variable_::resetValue() { valueset = false; } -bool Variable::isValueSet() const +bool Variable_::isValueSet() const { return valueset; } + +namespace spawn { + +Variable::Variable(std::string_view name, + int value_reference, + units::UnitType ep_unit, // NOLINT + units::UnitType mo_unit) + : name_(name), value_reference_(value_reference), ep_unit_(ep_unit), mo_unit_(mo_unit) +{ +} + +std::string_view Variable::Name() const +{ + return name_; +} + +std::optional Variable::Value() const +{ + return value_; +} + +void Variable::SetValue(const double &value, const units::UnitSystem &unit) +{ + switch (unit) { + case UnitSystem::MO: + value_ = value; + break; + case UnitSystem::EP: + value_ = units::convert({value, ep_unit_}, mo_unit_).value; + break; + } +} + +void Variable::ResetValue() +{ + value_.reset(); +} + +void QConSenFlow::create(const Input &input, EnergyPlus::EnergyPlusData &sim_state, 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 = 0; + + variables.push_back(std::unique_ptr(new QConSenFlow(zone_name, zone_num, value_reference))); + + value_reference++; + } +} + +QConSenFlow::QConSenFlow(std::string_view zone_name, int zone_num, int value_reference) // NOLINT + : OutputVariable(std::string(zone_name) + "_QConSen_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") = "Convective sensible heat added to the zone"; + metadata_.append_attribute("causality") = "output"; + metadata_.append_attribute("variability") = "continuous"; + 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 QConSenFlow::ExchangeData(EnergyPlus::EnergyPlusData &sim_state) +{ + const double &value = ZoneSums(sim_state, zone_num_).QConSenFlow(); + SetValue(value, units::UnitSystem::EP); +} + +} // namespace spawn diff --git a/energyplus_coroutine/variables.hpp b/energyplus_coroutine/variables.hpp index 17ecbcca0..38bf0bc5b 100644 --- a/energyplus_coroutine/variables.hpp +++ b/energyplus_coroutine/variables.hpp @@ -1,8 +1,12 @@ #ifndef Variables_hh_INCLUDED #define Variables_hh_INCLUDED +#include "energyplus_helpers.hpp" #include "units.hpp" #include +#include +#include +#include #include #include #include @@ -58,7 +62,7 @@ namespace units { class Input; } // namespace spawn -class Variable +class Variable_ { public: VariableType type; @@ -91,6 +95,70 @@ class Variable bool valueset{false}; }; -std::map parseVariables(const spawn::Input &input); +std::map parseVariables(const spawn::Input &input); + +namespace spawn { + +class Variable; +using Variables = std::vector>; + +class Variable +{ +public: + Variable &operator=(const Variable &) = delete; + Variable &operator=(Variable &&) = delete; + Variable(const Variable &) = delete; + Variable(Variable &&) = delete; + virtual ~Variable() = default; + + [[nodiscard]] std::string_view Name() const; + [[nodiscard]] std::optional Value() const; + + virtual void ExchangeData(EnergyPlus::EnergyPlusData &sim_state) = 0; + +protected: + Variable(std::string_view name, int value_reference, units::UnitType ep_unit, units::UnitType mo_unit); + + void SetValue(const double &value, const units::UnitSystem &unit); + void ResetValue(); + + std::string name_; + int value_reference_; + spawn::units::UnitType ep_unit_; + spawn::units::UnitType mo_unit_; + pugi::xml_document metadata_; + + // value_ is always stored in the Modelica unit system, units::UnitSystem::MO + std::optional value_; +}; + +class OutputVariable : public Variable +{ +protected: + using Variable::Variable; +}; + +class InputVariable : public Variable +{ +public: + using Variable::ResetValue; + using Variable::SetValue; + +protected: + using Variable::Variable; +}; + +class QConSenFlow : public OutputVariable +{ +public: + static void create(const Input &input, EnergyPlus::EnergyPlusData &sim_state, Variables &variables); + void ExchangeData(EnergyPlus::EnergyPlusData &sim_state) final; + +private: + explicit QConSenFlow(std::string_view zone_name, int zone_num, int value_reference); + int zone_num_; +}; + +} // namespace spawn #endif // Variables_hh_INCLUDED diff --git a/energyplus_coroutine/warmupmanager.cpp b/energyplus_coroutine/warmup_manager.cpp similarity index 98% rename from energyplus_coroutine/warmupmanager.cpp rename to energyplus_coroutine/warmup_manager.cpp index 30410a225..e4900ba8d 100644 --- a/energyplus_coroutine/warmupmanager.cpp +++ b/energyplus_coroutine/warmup_manager.cpp @@ -1,4 +1,4 @@ -#include "./warmupmanager.hpp" +#include "./warmup_manager.hpp" #include "../energyplus/src/EnergyPlus/Data/EnergyPlusData.hh" #include "../energyplus/src/EnergyPlus/DataHeatBalSurface.hh" #include "../energyplus/src/EnergyPlus/DataHeatBalance.hh" diff --git a/energyplus_coroutine/warmupmanager.hpp b/energyplus_coroutine/warmup_manager.hpp similarity index 100% rename from energyplus_coroutine/warmupmanager.hpp rename to energyplus_coroutine/warmup_manager.hpp