diff --git a/energyplus_coroutine/CMakeLists.txt b/energyplus_coroutine/CMakeLists.txt index c19942990..82b4612a8 100644 --- a/energyplus_coroutine/CMakeLists.txt +++ b/energyplus_coroutine/CMakeLists.txt @@ -27,8 +27,8 @@ add_library( input/emsactuator.hpp input/emsactuator.cpp - input/input.hpp - input/input.cpp + input/user_config.hpp + input/user_config.cpp input/outputvariable.hpp input/outputvariable.cpp input/runperiod.hpp diff --git a/energyplus_coroutine/create_fmu.cpp b/energyplus_coroutine/create_fmu.cpp index 82da0f4f8..a0a5ee63d 100644 --- a/energyplus_coroutine/create_fmu.cpp +++ b/energyplus_coroutine/create_fmu.cpp @@ -1,7 +1,7 @@ #include "create_fmu.hpp" #include "idf_to_json.hpp" #include "idfprep.hpp" -#include "input/input.hpp" +#include "input/user_config.hpp" #include "modelDescription.xml.hpp" #include "util/conversion.hpp" #include "util/fmi_paths.hpp" @@ -13,12 +13,14 @@ using json = nlohmann::json; namespace spawn { -void createModelDescription(const spawn::Input &input, const spawn_fs::path &savepath, const std::string &id); +void createModelDescription(const spawn::UserConfig &user_config, + const spawn_fs::path &savepath, + const std::string &id); void copyIDFResourceFiles(const json &jsonidf, const spawn_fs::path &from, const spawn_fs::path &to); void energyplus::CreateFMU::operator()() const { - spawn::Input input(input_path.string()); + spawn::UserConfig user_config(input_path.string()); // We are going to copy the required files into an FMU staging directory, // also copy the json input file into root of the fmu staging directory, @@ -26,13 +28,13 @@ void energyplus::CreateFMU::operator()() const // contained within the fmu layout. // The default fmu output path - auto fmuPath = spawn_fs::current_path() / (input.fmuBaseName() + ".fmu"); + auto fmuPath = spawn_fs::current_path() / (user_config.fmuBaseName() + ".fmu"); // These are options to override the default output path if (!output_path.empty()) { fmuPath = output_path; } else if (!output_dir.empty()) { - fmuPath = output_dir / (input.fmuBaseName() + ".fmu"); + fmuPath = output_dir / (user_config.fmuBaseName() + ".fmu"); } if (fmuPath.extension() != ".fmu") { @@ -64,8 +66,8 @@ void energyplus::CreateFMU::operator()() const const auto modelDescriptionPath = fmuStagingPath / "modelDescription.xml"; const auto fmuResourcesPath = fmuStagingPath / "resources"; const auto fmuspawnPath = fmuResourcesPath / "model.spawn"; - const auto fmuidfPath = fmuResourcesPath / (input.idfInputPath().stem().string() + ".spawn.idf"); - const auto fmuepwPath = fmuResourcesPath / input.epwInputPath().filename(); + const auto fmuidfPath = fmuResourcesPath / (user_config.idfInputPath().stem().string() + ".spawn.idf"); + const auto fmuepwPath = fmuResourcesPath / user_config.epwInputPath().filename(); const auto fmuiddPath = fmuResourcesPath / idd_path.filename(); const auto fmuEPFMIPath = fmuStagingPath / fmi_lib_path(id); @@ -77,23 +79,23 @@ void energyplus::CreateFMU::operator()() const spawn_fs::create_directories(fmuResourcesPath); spawn_fs::create_directories(fmuEPFMIPath.parent_path()); - auto idfjson = idf_to_json(input.idfInputPath()); - auto start_time = StartTime(day_from_string(input.runPeriod.day_of_week_for_start_day), 0.0); - prepare_idf(idfjson, input, start_time); - copyIDFResourceFiles(idfjson, input.idfInputPath().parent_path(), fmuResourcesPath); + auto idfjson = idf_to_json(user_config.idfInputPath()); + auto start_time = StartTime(day_from_string(user_config.runPeriod.day_of_week_for_start_day), 0.0); + prepare_idf(idfjson, user_config, start_time); + copyIDFResourceFiles(idfjson, user_config.idfInputPath().parent_path(), fmuResourcesPath); json_to_idf(idfjson, fmuidfPath); spawn_fs::copy_file(epfmu_path, fmuEPFMIPath, spawn_fs::copy_options::overwrite_existing); spawn_fs::copy_file(idd_path, fmuiddPath, spawn_fs::copy_options::overwrite_existing); - spawn_fs::copy_file(input.epwInputPath(), fmuepwPath, spawn_fs::copy_options::overwrite_existing); + spawn_fs::copy_file(user_config.epwInputPath(), fmuepwPath, spawn_fs::copy_options::overwrite_existing); - createModelDescription(input, modelDescriptionPath, id); + createModelDescription(user_config, modelDescriptionPath, id); const auto relativeEPWPath = spawn_fs::relative(fmuepwPath, fmuResourcesPath); - input.setEPWInputPath(relativeEPWPath); + user_config.setEPWInputPath(relativeEPWPath); const auto relativeIdfPath = spawn_fs::relative(fmuidfPath, fmuResourcesPath); - input.setIdfInputPath(relativeIdfPath); - input.save(fmuspawnPath); + user_config.setIdfInputPath(relativeIdfPath); + user_config.save(fmuspawnPath); if (!no_zip) { zip_directory(fmuStagingPath.string(), fmuPath.string(), no_compress); @@ -101,7 +103,7 @@ void energyplus::CreateFMU::operator()() const } } -void createModelDescription([[maybe_unused]] const spawn::Input &input, +void createModelDescription([[maybe_unused]] const spawn::UserConfig &user_config, const spawn_fs::path &savepath, const std::string &id) { @@ -117,7 +119,7 @@ void createModelDescription([[maybe_unused]] const spawn::Input &input, [[maybe_unused]] auto xmlvariables = fmiModelDescription.child("ModelVariables"); // TODO: init variables - variable::Variables variables; + variable::Variables variables(user_config); // const auto variables = parseVariables(input); // for (const auto &varpair : variables) { diff --git a/energyplus_coroutine/idfprep.cpp b/energyplus_coroutine/idfprep.cpp index 241f3f9c6..e06d34332 100644 --- a/energyplus_coroutine/idfprep.cpp +++ b/energyplus_coroutine/idfprep.cpp @@ -1,10 +1,10 @@ #include "idfprep.hpp" -#include "input/input.hpp" +#include "input/user_config.hpp" #include "util/strings.hpp" namespace spawn { -json &adjustSimulationControl(json &jsonidf, const Input &input) +json &adjustSimulationControl(json &jsonidf, const UserConfig &user_config) { constexpr auto simulationcontroltype = "SimulationControl"; @@ -12,7 +12,7 @@ json &adjustSimulationControl(json &jsonidf, const Input &input) jsonidf.erase(simulationcontroltype); // TODO: fix this slop. Please add a consistent method of handling bool types - const auto autosize = input.autosize() ? "Yes" : "No"; + const auto autosize = user_config.autosize() ? "Yes" : "No"; // This is what we need for spawn jsonidf[simulationcontroltype] = {{"Spawn-SimulationControl", {{"do_plant_sizing_calculation", "No"}, @@ -24,7 +24,7 @@ json &adjustSimulationControl(json &jsonidf, const Input &input) return jsonidf; } -json &addRunPeriod(json &jsonidf, [[maybe_unused]] const Input &input, const StartTime &start_time) +json &addRunPeriod(json &jsonidf, [[maybe_unused]] const UserConfig &user_config, const StartTime &start_time) { constexpr auto runperiodtype = "RunPeriod"; // Remove the existing run periods first @@ -34,18 +34,19 @@ json &addRunPeriod(json &jsonidf, [[maybe_unused]] const Input &input, const Sta // 200 years should be plenty jsonidf[runperiodtype] = { {"Spawn-RunPeriod", - {{"apply_weekend_holiday_rule", input.runPeriod.apply_weekend_holiday_rule}, + {{"apply_weekend_holiday_rule", user_config.runPeriod.apply_weekend_holiday_rule}, {"begin_day_of_month", int(start_time.EnergyPlusEpoch().day())}, {"begin_month", int(start_time.EnergyPlusEpoch().month())}, {"begin_year", int(start_time.EnergyPlusEpoch().year())}, - {"day_of_week_for_start_day", input.runPeriod.day_of_week_for_start_day}, + {"day_of_week_for_start_day", user_config.runPeriod.day_of_week_for_start_day}, {"end_day_of_month", 31}, {"end_month", 12}, {"end_year", 2217}, - {"use_weather_file_daylight_saving_period", input.runPeriod.use_weather_file_daylight_saving_period}, - {"use_weather_file_holidays_and_special_days", input.runPeriod.use_weather_file_holidays_and_special_days}, - {"use_weather_file_rain_indicators", input.runPeriod.use_weather_file_rain_indicators}, - {"use_weather_file_snow_indicators", input.runPeriod.use_weather_file_snow_indicators}}}}; + {"use_weather_file_daylight_saving_period", user_config.runPeriod.use_weather_file_daylight_saving_period}, + {"use_weather_file_holidays_and_special_days", + user_config.runPeriod.use_weather_file_holidays_and_special_days}, + {"use_weather_file_rain_indicators", user_config.runPeriod.use_weather_file_rain_indicators}, + {"use_weather_file_snow_indicators", user_config.runPeriod.use_weather_file_snow_indicators}}}}; return jsonidf; } @@ -59,7 +60,7 @@ json &addRunPeriod(json &jsonidf, [[maybe_unused]] const Input &input, const Sta // this approach seems reasonable // With this approach QGaiRad_flow will interface with the OtherEquipment actuator, // Spawn user does not need to interface directly with the actuator -json &addOtherEquipment(json &jsonidf, const Input &input) +json &addOtherEquipment(json &jsonidf, const UserConfig &user_config) { constexpr auto scheduletype = "Schedule:Constant"; constexpr auto schedulename = "Spawn-RadiantGains-Schedule"; @@ -71,7 +72,7 @@ json &addOtherEquipment(json &jsonidf, const Input &input) jsonidf[scheduletype][schedulename] = {{"schedule_type_limits_name", schedule_typelimits_name}, {"hourly_value", "1.0"}}; - for (const auto &zone : input.zones) { + for (const auto &zone : user_config.zones) { if (!zone.isconnected) { continue; } @@ -125,7 +126,7 @@ json &removeUnusedObjects(json &jsonidf) return jsonidf; } -json &addPeopleOutputVariables(json &jsonidf, const Input &input) +json &addPeopleOutputVariables(json &jsonidf, const UserConfig &user_config) { // Some zones don't have people input, which will result in an EnergyPlus error, // Insert a default people object that defines zero people @@ -143,7 +144,7 @@ json &addPeopleOutputVariables(json &jsonidf, const Input &input) jsonidf[scheduletype][activitySchedulename] = {{"schedule_type_limits_name", schedule_typelimits_name}, {"hourly_value", "100.0"}}; - for (const auto &zone : input.zones) { + for (const auto &zone : user_config.zones) { if (!zone.isconnected) { continue; } @@ -169,14 +170,14 @@ json &addPeopleOutputVariables(json &jsonidf, const Input &input) } // Add output variables requested in the spawn input file, but not in the idf -json &addRequestedOutputVariables(json &jsonidf, const Input &input) +json &addRequestedOutputVariables(json &jsonidf, const UserConfig &user_config) { // A pair that holds an output variable name and key, using Varpair = std::pair; // Make a list of the requested outputs std::vector requestedpairs; - for (const auto &var : input.outputVariables) { + for (const auto &var : user_config.outputVariables) { requestedpairs.emplace_back(var.idfname, var.idfkey); } @@ -262,7 +263,7 @@ json &expandInfiltrationZoneLists(json &jsonidf) // since some zones have infiltration output variables and actuators while others don't. // To address this confusion we will insert default infiltration objects for connected zones, // which have zero flow specified. -json &addDefaultZeroInfiltration(json &jsonidf, const Input &input) +json &addDefaultZeroInfiltration(json &jsonidf, const UserConfig &user_config) { constexpr auto infiltrationType = "ZoneInfiltration:DesignFlowRate"; constexpr auto scheduletype = "Schedule:Constant"; @@ -275,7 +276,7 @@ json &addDefaultZeroInfiltration(json &jsonidf, const Input &input) jsonidf[scheduletype][schedulename] = {{"schedule_type_limits_name", schedule_typelimits_name}, {"hourly_value", "1.0"}}; - const auto zones = input.zones; + const auto zones = user_config.zones; for (const auto &zone : zones) { // Only add default infiltration for "connected" zones if (zone.isconnected) { @@ -296,7 +297,7 @@ json &addDefaultZeroInfiltration(json &jsonidf, const Input &input) } // Remove infiltration idf input objects for zones that are connected to Modelica -json &removeInfiltration(json &jsonidf, const Input &input) +json &removeInfiltration(json &jsonidf, const UserConfig &user_config) { // First expand any infiltration that uses zone lists expandInfiltrationZoneLists(jsonidf); @@ -307,7 +308,7 @@ json &removeInfiltration(json &jsonidf, const Input &input) {"ZoneInfiltration:EffectiveLeakageArea", "zone_name"}, {"ZoneInfiltration:FlowCoefficient", "zone_name"}}}; - const auto zones = input.zones; + const auto zones = user_config.zones; for (const auto &type : infiltrationTypes) { auto &infiltrationObjects = jsonidf[type.first]; @@ -323,20 +324,20 @@ json &removeInfiltration(json &jsonidf, const Input &input) } } - addDefaultZeroInfiltration(jsonidf, input); + addDefaultZeroInfiltration(jsonidf, user_config); return jsonidf; } -void prepare_idf(json &jsonidf, const Input &input, const StartTime &start_time) +void prepare_idf(json &jsonidf, const UserConfig &user_config, const StartTime &start_time) { - adjustSimulationControl(jsonidf, input); + adjustSimulationControl(jsonidf, user_config); removeUnusedObjects(jsonidf); - addRunPeriod(jsonidf, input, start_time); - removeInfiltration(jsonidf, input); - addOtherEquipment(jsonidf, input); - addRequestedOutputVariables(jsonidf, input); - addPeopleOutputVariables(jsonidf, input); + addRunPeriod(jsonidf, user_config, start_time); + removeInfiltration(jsonidf, user_config); + addOtherEquipment(jsonidf, user_config); + addRequestedOutputVariables(jsonidf, user_config); + addPeopleOutputVariables(jsonidf, user_config); } void validate_idf(json &jsonidf) diff --git a/energyplus_coroutine/idfprep.hpp b/energyplus_coroutine/idfprep.hpp index 3e0b154ab..3762cfc83 100644 --- a/energyplus_coroutine/idfprep.hpp +++ b/energyplus_coroutine/idfprep.hpp @@ -7,11 +7,11 @@ using json = nlohmann::json; namespace spawn { -class Input; +class UserConfig; // Reduce the jsonidf down to the EnergyPlus features that Spawn depends on, // and insert idf content that is required. -void prepare_idf(json &jsonidf, const Input &input, const StartTime &start_time); +void prepare_idf(json &jsonidf, const UserConfig &user_config, const StartTime &start_time); // Validate the jsonidf to ensure that the user input is not requesting something // that Spawn does not support, such as zone multipliers. diff --git a/energyplus_coroutine/input/input.cpp b/energyplus_coroutine/input/user_config.cpp similarity index 77% rename from energyplus_coroutine/input/input.cpp rename to energyplus_coroutine/input/user_config.cpp index e2d272dee..7b31d65c5 100644 --- a/energyplus_coroutine/input/input.cpp +++ b/energyplus_coroutine/input/user_config.cpp @@ -1,11 +1,11 @@ -#include "input.hpp" #include "../idf_to_json.hpp" +#include "user_config.hpp" using json = nlohmann::json; namespace spawn { -Input::Input(const std::string &spawninput) +UserConfig::UserConfig(const std::string &spawninput) { std::ifstream fileinput(spawninput); if (!fileinput.fail()) { @@ -42,22 +42,22 @@ Input::Input(const std::string &spawninput) runPeriod = RunPeriod::create_run_period(spawnjson); } -std::string Input::fmuname() const +std::string UserConfig::fmuname() const { return spawnjson.value("fmu", json()).value("name", "spawn.fmu"); } -std::string Input::fmuBaseName() const +std::string UserConfig::fmuBaseName() const { return spawn_fs::path(fmuname()).stem().string(); } -void Input::setFMUName(std::string name) +void UserConfig::setFMUName(std::string name) { spawnjson["fmu"]["name"] = std::move(name); } -spawn_fs::path Input::toPath(const std::string &pathstring) const +spawn_fs::path UserConfig::toPath(const std::string &pathstring) const { spawn_fs::path p(pathstring); if (!p.is_absolute()) { @@ -67,7 +67,7 @@ spawn_fs::path Input::toPath(const std::string &pathstring) const return p; } -double Input::relativeSurfaceTolerance() const +double UserConfig::relativeSurfaceTolerance() const { const auto tol = spawnjson.value("EnergyPlus", json())["relativeSurfaceTolerance"]; if (!tol.is_null()) { @@ -78,38 +78,38 @@ double Input::relativeSurfaceTolerance() const return 1.0e-6; } -spawn_fs::path Input::idfInputPath() const +spawn_fs::path UserConfig::idfInputPath() const { return toPath(spawnjson.value("EnergyPlus", json()).value("idf", "in.idf")); } -void Input::setIdfInputPath(const spawn_fs::path &idfpath) +void UserConfig::setIdfInputPath(const spawn_fs::path &idfpath) { spawnjson["EnergyPlus"]["idf"] = idfpath.string(); } -spawn_fs::path Input::epwInputPath() const +spawn_fs::path UserConfig::epwInputPath() const { return toPath(spawnjson.value("EnergyPlus", json()).value("weather", "in.epw")); } -void Input::setEPWInputPath(const spawn_fs::path &epwpath) +void UserConfig::setEPWInputPath(const spawn_fs::path &epwpath) { spawnjson["EnergyPlus"]["weather"] = epwpath.string(); } -bool Input::autosize() const +bool UserConfig::autosize() const { return spawnjson.value("EnergyPlus", json()).value("autosize", false); } -void Input::save(const spawn_fs::path &savepath) const +void UserConfig::save(const spawn_fs::path &savepath) const { std::ofstream o(savepath.string()); o << std::setw(4) << spawnjson << std::endl; } -spawn_fs::path Input::basepath() const +spawn_fs::path UserConfig::basepath() const { return m_basepath; } diff --git a/energyplus_coroutine/input/input.hpp b/energyplus_coroutine/input/user_config.hpp similarity index 95% rename from energyplus_coroutine/input/input.hpp rename to energyplus_coroutine/input/user_config.hpp index 4e4645a10..847fabfe8 100644 --- a/energyplus_coroutine/input/input.hpp +++ b/energyplus_coroutine/input/user_config.hpp @@ -15,10 +15,10 @@ namespace spawn { -class Input +class UserConfig { public: - explicit Input(const std::string &spawnInputJSON); + explicit UserConfig(const std::string &spawnInputJSON); std::vector zones; std::vector schedules; diff --git a/energyplus_coroutine/libspawn.i b/energyplus_coroutine/libspawn.i index 108b3f7eb..d9e047e74 100644 --- a/energyplus_coroutine/libspawn.i +++ b/energyplus_coroutine/libspawn.i @@ -4,7 +4,7 @@ %include %{ -#include "input/input.hpp" +#include "input/user_config.hpp" #include "variables.hpp" #include "warmup_anager.hpp" #include "../energyplus/src/EnergyPlus/Data/EnergyPlusData.hh" diff --git a/energyplus_coroutine/spawn.cpp b/energyplus_coroutine/spawn.cpp index 5c83da752..be1416a1d 100644 --- a/energyplus_coroutine/spawn.cpp +++ b/energyplus_coroutine/spawn.cpp @@ -4,7 +4,7 @@ #include "../util/math.hpp" #include "idf_to_json.hpp" #include "idfprep.hpp" -#include "input/input.hpp" +#include "input/user_config.hpp" #include "output_types.hpp" #include "start_time.hpp" @@ -22,7 +22,7 @@ namespace spawn { Spawn::Spawn(std::string t_name, const std::string &t_input, spawn_fs::path t_workingdir) // NOLINT - : instanceName(std::move(t_name)), workingdir(std::move(t_workingdir)), input(t_input) + : instanceName(std::move(t_name)), workingdir(std::move(t_workingdir)), user_config_(t_input) { } @@ -31,13 +31,13 @@ void Spawn::start() if (!is_running && !sim_exception_ptr && !sim_thread.joinable()) { is_running = true; - auto idfPath = input.idfInputPath(); + auto idfPath = user_config_.idfInputPath(); auto idfjson = idf_to_json(idfPath); //// Skip this step if the .spawn extension is present, //// which will indicate that the idf has already been "prepared" // if (idfPath.stem().extension() != ".spawn") { - prepare_idf(idfjson, input, start_time_); + prepare_idf(idfjson, user_config_, start_time_); idfPath = workingdir / (idfPath.stem().string() + ".spawn.idf"); json_to_idf(idfjson, idfPath); //} @@ -47,7 +47,7 @@ void Spawn::start() const auto &simulation = [&]() { try { - const auto epwPath = input.epwInputPath().string(); + const auto epwPath = user_config_.epwInputPath().string(); const auto idfPath_string = idfPath.string(); const auto iddPath = spawn::idd_path().string(); const auto workingdir_string = workingdir.string(); @@ -59,7 +59,7 @@ void Spawn::start() registerErrorCallback(simState(), [this](const auto level, const auto &message) { logMessage(level, message); }); registerExternalHVACManager(simState(), [this](EnergyPlusState state) { externalHVACManager(state); }); - sim_state.dataHeatBal->MaxAllowedDelTemp = input.relativeSurfaceTolerance(); + sim_state.dataHeatBal->MaxAllowedDelTemp = user_config_.relativeSurfaceTolerance(); RunEnergyPlus(sim_state); @@ -87,8 +87,6 @@ void Spawn::start() sim_thread.join(); } - variable::CreateVariables(input, variables_); - // This will poppulate const parameters such as the zone sizing values initConstParameters(); @@ -162,7 +160,7 @@ double Spawn::startTime() const noexcept void Spawn::setStartTime(const double &time) noexcept { - start_time_ = StartTime(day_from_string(input.runPeriod.day_of_week_for_start_day), time); + start_time_ = StartTime(day_from_string(user_config_.runPeriod.day_of_week_for_start_day), time); } void Spawn::setTime(const double &time) @@ -385,7 +383,7 @@ void Spawn::updateZoneConditions(bool skipConnectedZones) const double dt = currentTime() - prevZoneUpdate; prevZoneUpdate = currentTime(); - for (const auto &zone : input.zones) { + for (const auto &zone : user_config_.zones) { if (skipConnectedZones && zone.isconnected) { continue; } diff --git a/energyplus_coroutine/spawn.hpp b/energyplus_coroutine/spawn.hpp index 911448258..b1e7669a0 100644 --- a/energyplus_coroutine/spawn.hpp +++ b/energyplus_coroutine/spawn.hpp @@ -5,7 +5,7 @@ #include "../energyplus/src/EnergyPlus/Data/EnergyPlusData.hh" #include "../energyplus/src/EnergyPlus/api/state.h" #include "../util/filesystem.hpp" -#include "input/input.hpp" +#include "input/user_config.hpp" #include "start_time.hpp" #include "variables.hpp" #include "warmup_manager.hpp" @@ -72,7 +72,7 @@ class Spawn private: std::string instanceName; spawn_fs::path workingdir; - Input input; + UserConfig user_config_; StartTime start_time_; double requested_time_{0.0}; @@ -150,7 +150,7 @@ class Spawn // a simple hierarchy of loops with callback points along the way WarmupManager warmupManager{sim_state}; - variable::Variables variables_; + variable::Variables variables_{user_config_}; }; spawn_fs::path iddpath(); diff --git a/energyplus_coroutine/start_time.hpp b/energyplus_coroutine/start_time.hpp index 988d6a278..5c57e1caa 100644 --- a/energyplus_coroutine/start_time.hpp +++ b/energyplus_coroutine/start_time.hpp @@ -1,7 +1,7 @@ #ifndef SPAWN_ENERGYPLUS_COROUTINE_START_TIME_INCLUDED #define SPAWN_ENERGYPLUS_COROUTINE_START_TIME_INCLUDED -#include "input/input.hpp" +#include "input/user_config.hpp" #include "util/datetime.hpp" #include #include diff --git a/energyplus_coroutine/variables.cpp b/energyplus_coroutine/variables.cpp index c60a61b26..e1578a7b3 100644 --- a/energyplus_coroutine/variables.cpp +++ b/energyplus_coroutine/variables.cpp @@ -5,10 +5,10 @@ #include "../energyplus/src/EnergyPlus/UtilityRoutines.hh" #include "energyplus_helpers.hpp" #include "iddtypes.hpp" -#include "input/input.hpp" #include "input/outputvariable.hpp" #include "input/schedule.hpp" #include "input/surface.hpp" +#include "input/user_config.hpp" #include "input/zone.hpp" #include "output_types.hpp" #include "spawn.hpp" @@ -22,6 +22,65 @@ using namespace spawn::units; namespace spawn::variable { +Variables::Variables(const UserConfig &user_config) +{ + zone::V::create(user_config, *this); + zone::AFlo::create(user_config, *this); + zone::MSenFac::create(user_config, *this); + zone::QConSenFlow::create(user_config, *this); + zone::QLatFlow::create(user_config, *this); + zone::QPeoFlow::create(user_config, *this); + zone::TRad::create(user_config, *this); + zone::QCooSenFlow::create(user_config, *this); + zone::QCooLatFlow::create(user_config, *this); + zone::TOutCoo::create(user_config, *this); + zone::XOutCoo::create(user_config, *this); + zone::MOutCooFlow::create(user_config, *this); + zone::TCoo::create(user_config, *this); + zone::QHeaFlow::create(user_config, *this); + zone::TOutHea::create(user_config, *this); + zone::XOutHea::create(user_config, *this); + zone::MOutHeaFlow::create(user_config, *this); + zone::THea::create(user_config, *this); + zone::MInletsFlow::create(user_config, *this); + zone::TAveInlet::create(user_config, *this); + zone::T::create(user_config, *this); + zone::X::create(user_config, *this); + zone::QGaiRadFlow::create(user_config, *this); + other::Sensor::create(user_config, *this); + other::Actuator::create(user_config, *this); + other::Schedule::create(user_config, *this); + surface::A::create(user_config, *this); + surface::QFlow::create(user_config, *this); + surface::T::create(user_config, *this); + construction::A::create(user_config, *this); + construction::QFrontFlow::create(user_config, *this); + construction::QBackFlow::create(user_config, *this); + construction::TFront::create(user_config, *this); + construction::TBack::create(user_config, *this); +} + +void Variables::UpdateInputs(EnergyPlus::EnergyPlusData &energyplus_data) +{ + std::for_each(input_variables_.begin(), input_variables_.end(), [&energyplus_data](auto var) { + var.get().Update(energyplus_data); + }); +} + +void Variables::UpdateOutputs(EnergyPlus::EnergyPlusData &energyplus_data) +{ + std::for_each(output_variables_.begin(), output_variables_.end(), [&energyplus_data](auto var) { + var.get().Update(energyplus_data); + }); +} + +void Variables::UpdateParameters(EnergyPlus::EnergyPlusData &energyplus_data) +{ + std::for_each(parameter_variables_.begin(), parameter_variables_.end(), [&energyplus_data](auto var) { + var.get().Update(energyplus_data); + }); +} + void Variables::AddVariable(std::unique_ptr &&variable) { all_variables_.push_back(std::move(variable)); @@ -32,6 +91,11 @@ void Variables::AddVariable(Output &variable) output_variables_.push_back(variable); } +void Variables::AddVariable(Parameter &variable) +{ + parameter_variables_.push_back(variable); +} + void Variables::AddVariable(Input &variable) { input_variables_.push_back(variable); @@ -79,6 +143,12 @@ Output::Output(Variables &variables, std::string_view name, units::UnitType ep_u variables.AddVariable(*this); } +Parameter::Parameter(Variables &variables, std::string_view name, units::UnitType ep_unit, units::UnitType mo_unit) + : Variable(variables, name, ep_unit, mo_unit) +{ + variables.AddVariable(*this); +} + Input::Input(Variables &variables, std::string_view name, units::UnitType ep_unit, units::UnitType mo_unit) : Variable(variables, name, ep_unit, mo_unit) { @@ -87,9 +157,9 @@ Input::Input(Variables &variables, std::string_view name, units::UnitType ep_uni namespace zone { - void V::create(const spawn::Input &input, Variables &variables) + void V::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -98,7 +168,7 @@ namespace zone { } V::V(Variables &variables, const std::string_view zone_name) // NOLINT - : Output(variables, std::string(zone_name) + "_V", units::UnitType::m3, units::UnitType::m3), + : Parameter(variables, std::string(zone_name) + "_V", units::UnitType::m3, units::UnitType::m3), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -120,9 +190,9 @@ namespace zone { SetValue(energyplus::ZoneVolume(energyplus_data, zone_num_.get(energyplus_data)), units::UnitSystem::EP); } - void AFlo::create(const spawn::Input &input, Variables &variables) + void AFlo::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -131,7 +201,7 @@ namespace zone { } AFlo::AFlo(Variables &variables, const std::string_view zone_name) - : Output(variables, std::string(zone_name) + "_AFlo", units::UnitType::m2, units::UnitType::m2), + : Parameter(variables, std::string(zone_name) + "_AFlo", units::UnitType::m2, units::UnitType::m2), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -153,9 +223,9 @@ namespace zone { SetValue(energyplus::ZoneFloorArea(energyplus_data, zone_num_.get(energyplus_data)), units::UnitSystem::EP); } - void MSenFac::create(const spawn::Input &input, Variables &variables) + void MSenFac::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -164,7 +234,7 @@ namespace zone { } MSenFac::MSenFac(Variables &variables, const std::string_view zone_name) - : Output(variables, std::string(zone_name) + "_mSenFac", units::UnitType::one, units::UnitType::one), + : Parameter(variables, std::string(zone_name) + "_mSenFac", units::UnitType::one, units::UnitType::one), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -185,9 +255,9 @@ namespace zone { SetValue(energyplus::ZoneVolCapMultpSens(energyplus_data, zone_num_.get(energyplus_data)), units::UnitSystem::EP); } - void QConSenFlow::create(const spawn::Input &input, Variables &variables) + void QConSenFlow::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -219,9 +289,9 @@ namespace zone { SetValue(value, units::UnitSystem::EP); } - void QLatFlow::create(const spawn::Input &input, Variables &variables) + void QLatFlow::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -252,9 +322,9 @@ namespace zone { SetValue(energyplus::ZoneLatentGain(energyplus_data, zone_num_.get(energyplus_data)), units::UnitSystem::EP); } - void QPeoFlow::create(const spawn::Input &input, Variables &variables) + void QPeoFlow::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -285,9 +355,9 @@ namespace zone { SetValue(energyplus::ZonePeopleHeatGain(energyplus_data, zone_num_.get(energyplus_data)), units::UnitSystem::EP); } - void TRad::create(const spawn::Input &input, Variables &variables) + void TRad::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -318,9 +388,9 @@ namespace zone { SetValue(energyplus::ZoneMeanRadiantTemp(energyplus_data, zone_num_.get(energyplus_data)), units::UnitSystem::EP); } - void QCooSenFlow::create(const spawn::Input &input, Variables &variables) + void QCooSenFlow::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -329,7 +399,7 @@ namespace zone { } QCooSenFlow::QCooSenFlow(Variables &variables, const std::string_view zone_name) // NOLINT - : Output(variables, std::string(zone_name) + "_QCooSen_flow", units::UnitType::W, units::UnitType::W), + : Parameter(variables, std::string(zone_name) + "_QCooSen_flow", units::UnitType::W, units::UnitType::W), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -351,9 +421,9 @@ namespace zone { SetValue(energyplus::ZoneDesignCoolingLoad(energyplus_data, zone_num_.get(energyplus_data)), units::UnitSystem::EP); } - void QCooLatFlow::create(const spawn::Input &input, Variables &variables) + void QCooLatFlow::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -362,7 +432,7 @@ namespace zone { } QCooLatFlow::QCooLatFlow(Variables &variables, const std::string_view zone_name) // NOLINT - : Output(variables, std::string(zone_name) + "_QCooLat_flow", units::UnitType::W, units::UnitType::W), + : Parameter(variables, std::string(zone_name) + "_QCooLat_flow", units::UnitType::W, units::UnitType::W), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -385,9 +455,9 @@ namespace zone { units::UnitSystem::EP); } - void TOutCoo::create(const spawn::Input &input, Variables &variables) + void TOutCoo::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -396,7 +466,7 @@ namespace zone { } TOutCoo::TOutCoo(Variables &variables, const std::string_view zone_name) // NOLINT - : Output(variables, std::string(zone_name) + "_TOutCoo", units::UnitType::C, units::UnitType::K), + : Parameter(variables, std::string(zone_name) + "_TOutCoo", units::UnitType::C, units::UnitType::K), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -419,9 +489,9 @@ namespace zone { units::UnitSystem::EP); } - void XOutCoo::create(const spawn::Input &input, Variables &variables) + void XOutCoo::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -430,7 +500,7 @@ namespace zone { } XOutCoo::XOutCoo(Variables &variables, const std::string_view zone_name) // NOLINT - : Output(variables, std::string(zone_name) + "_XOutCoo", units::UnitType::one, units::UnitType::one), + : Parameter(variables, std::string(zone_name) + "_XOutCoo", units::UnitType::one, units::UnitType::one), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -453,9 +523,9 @@ namespace zone { units::UnitSystem::EP); } - void MOutCooFlow::create(const spawn::Input &input, Variables &variables) + void MOutCooFlow::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -464,7 +534,7 @@ namespace zone { } MOutCooFlow::MOutCooFlow(Variables &variables, const std::string_view zone_name) - : Output( + : Parameter( variables, std::string(zone_name) + "_mOutCoo_flow", units::UnitType::kg_per_s, units::UnitType::kg_per_s), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { @@ -488,9 +558,9 @@ namespace zone { SetValue(0.0, units::UnitSystem::EP); } - void TCoo::create(const spawn::Input &input, Variables &variables) + void TCoo::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -499,7 +569,7 @@ namespace zone { } TCoo::TCoo(Variables &variables, const std::string_view zone_name) - : Output(variables, std::string(zone_name) + "_TCoo", units::UnitType::s, units::UnitType::s), + : Parameter(variables, std::string(zone_name) + "_TCoo", units::UnitType::s, units::UnitType::s), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -522,9 +592,9 @@ namespace zone { SetValue(0.0, units::UnitSystem::EP); } - void QHeaFlow::create(const spawn::Input &input, Variables &variables) + void QHeaFlow::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -533,7 +603,7 @@ namespace zone { } QHeaFlow::QHeaFlow(Variables &variables, const std::string_view zone_name) - : Output(variables, std::string(zone_name) + "_QHea_flow", units::UnitType::W, units::UnitType::W), + : Parameter(variables, std::string(zone_name) + "_QHea_flow", units::UnitType::W, units::UnitType::W), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -555,9 +625,9 @@ namespace zone { SetValue(energyplus::ZoneDesignHeatingLoad(energyplus_data, zone_num_.get(energyplus_data)), units::UnitSystem::EP); } - void TOutHea::create(const spawn::Input &input, Variables &variables) + void TOutHea::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -566,7 +636,7 @@ namespace zone { } TOutHea::TOutHea(Variables &variables, const std::string_view zone_name) - : Output(variables, std::string(zone_name) + "_TOutHea", units::UnitType::C, units::UnitType::K), + : Parameter(variables, std::string(zone_name) + "_TOutHea", units::UnitType::C, units::UnitType::K), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -589,9 +659,9 @@ namespace zone { units::UnitSystem::EP); } - void XOutHea::create(const spawn::Input &input, Variables &variables) + void XOutHea::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -600,7 +670,7 @@ namespace zone { } XOutHea::XOutHea(Variables &variables, const std::string_view zone_name) // NOLINT - : Output(variables, std::string(zone_name) + "_XOutHea", units::UnitType::one, units::UnitType::one), + : Parameter(variables, std::string(zone_name) + "_XOutHea", units::UnitType::one, units::UnitType::one), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -623,9 +693,9 @@ namespace zone { units::UnitSystem::EP); } - void MOutHeaFlow::create(const spawn::Input &input, Variables &variables) + void MOutHeaFlow::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -634,7 +704,7 @@ namespace zone { } MOutHeaFlow::MOutHeaFlow(Variables &variables, const std::string_view zone_name) - : Output( + : Parameter( variables, std::string(zone_name) + "_mOutHea_flow", units::UnitType::kg_per_s, units::UnitType::kg_per_s), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { @@ -658,9 +728,9 @@ namespace zone { SetValue(0.0, units::UnitSystem::EP); } - void THea::create(const spawn::Input &input, Variables &variables) + void THea::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -669,7 +739,7 @@ namespace zone { } THea::THea(Variables &variables, const std::string_view zone_name) - : Output(variables, std::string(zone_name) + "_THea", units::UnitType::s, units::UnitType::s), + : Parameter(variables, std::string(zone_name) + "_THea", units::UnitType::s, units::UnitType::s), zone_num_([zone_name](EnergyPlus::EnergyPlusData &data) { return energyplus::ZoneNum(data, zone_name); }) { metadata_.set_name("ScalarVariable"); @@ -692,9 +762,9 @@ namespace zone { SetValue(0.0, units::UnitSystem::EP); } - void MInletsFlow::create(const spawn::Input &input, Variables &variables) + void MInletsFlow::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -728,9 +798,9 @@ namespace zone { // Right? } - void TAveInlet::create(const spawn::Input &input, Variables &variables) + void TAveInlet::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -760,9 +830,9 @@ namespace zone { // TODO: Do something with this value. } - void T::create(const spawn::Input &input, Variables &variables) + void T::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -794,9 +864,9 @@ namespace zone { } } - void X::create(const spawn::Input &input, Variables &variables) + void X::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -827,9 +897,9 @@ namespace zone { } } - void QGaiRadFlow::create(const spawn::Input &input, Variables &variables) + void QGaiRadFlow::create(const UserConfig &user_config, Variables &variables) { - const auto zones = input.spawnjson.value("model", json::object()).value("zones", std::vector(0)); + const auto zones = user_config.spawnjson.value("model", json::object()).value("zones", std::vector(0)); for (const auto &zone : zones) { std::string zone_name = zone.value("name", ""); @@ -866,10 +936,10 @@ namespace zone { } // namespace zone namespace other { - void Sensor::create(const spawn::Input &input, Variables &variables) + void Sensor::create(const UserConfig &user_config, Variables &variables) { const auto output_variables = - input.spawnjson.value("model", json::object()).value("outputVariables", std::vector(0)); + user_config.spawnjson.value("model", json::object()).value("outputVariables", std::vector(0)); for (const auto &variable : output_variables) { const auto sensor_name = variable.value("fmiName", ""); @@ -907,9 +977,10 @@ namespace other { SetValue(energyplus::VariableValue(energyplus_data, sensor_handle_.get(energyplus_data)), units::UnitSystem::EP); } - void Actuator::create(const spawn::Input &input, Variables &variables) + void Actuator::create(const UserConfig &user_config, Variables &variables) { - const auto actuators = input.spawnjson.value("model", json::object()).value("emsActuators", std::vector(0)); + const auto actuators = + user_config.spawnjson.value("model", json::object()).value("emsActuators", std::vector(0)); for (const auto &actuator : actuators) { const auto &name = actuator.value("fmiName", ""); @@ -952,9 +1023,10 @@ namespace other { } } - void Schedule::create(const spawn::Input &input, Variables &variables) + void Schedule::create(const UserConfig &user_config, Variables &variables) { - const auto schedules = input.spawnjson.value("model", json::object()).value("schedules", std::vector(0)); + const auto schedules = + user_config.spawnjson.value("model", json::object()).value("schedules", std::vector(0)); // Schedules values are set using the EnergyPlus actuator // @@ -963,8 +1035,8 @@ namespace other { std::map schedule_type_map; for (const auto &type : supportedScheduleTypes) { - if (input.jsonidf.contains(type)) { - for (const auto &schedule : input.jsonidf[type].items()) { + if (user_config.jsonidf.contains(type)) { + for (const auto &schedule : user_config.jsonidf[type].items()) { schedule_type_map[schedule.key()] = type; } } @@ -1016,9 +1088,10 @@ namespace other { } // namespace other namespace surface { - void A::create(const spawn::Input &input, Variables &variables) + void A::create(const UserConfig &user_config, Variables &variables) { - const auto surfaces = input.spawnjson.value("model", json::object()).value("zoneSurfaces", std::vector(0)); + const auto surfaces = + user_config.spawnjson.value("model", json::object()).value("zoneSurfaces", std::vector(0)); for (const auto &surface : surfaces) { const auto surface_name = surface.value("name", ""); @@ -1027,7 +1100,7 @@ namespace surface { } A::A(Variables &variables, const std::string_view surface_name) - : Output(variables, std::string(surface_name) + "_A", units::UnitType::m2, units::UnitType::m2), + : Parameter(variables, std::string(surface_name) + "_A", units::UnitType::m2, units::UnitType::m2), surface_num_( [surface_name](EnergyPlus::EnergyPlusData &data) { return energyplus::SurfaceNum(data, surface_name); }) { @@ -1050,9 +1123,10 @@ namespace surface { SetValue(energyplus::SurfaceArea(energyplus_data, surface_num_.get(energyplus_data)), spawn::units::UnitSystem::EP); } - void QFlow::create(const spawn::Input &input, Variables &variables) + void QFlow::create(const UserConfig &user_config, Variables &variables) { - const auto surfaces = input.spawnjson.value("model", json::object()).value("zoneSurfaces", std::vector(0)); + const auto surfaces = + user_config.spawnjson.value("model", json::object()).value("zoneSurfaces", std::vector(0)); for (const auto &surface : surfaces) { const auto surface_name = surface.value("name", ""); @@ -1087,9 +1161,10 @@ namespace surface { spawn::units::UnitSystem::EP); } - void T::create(const spawn::Input &input, Variables &variables) + void T::create(const UserConfig &user_config, Variables &variables) { - const auto surfaces = input.spawnjson.value("model", json::object()).value("zoneSurfaces", std::vector(0)); + const auto surfaces = + user_config.spawnjson.value("model", json::object()).value("zoneSurfaces", std::vector(0)); const std::string actuator_type("Surface"); const std::string actuator_controltype("Surface Inside Temperature"); @@ -1128,10 +1203,10 @@ namespace surface { } // namespace surface namespace construction { - void A::create(const spawn::Input &input, Variables &variables) + void A::create(const UserConfig &user_config, Variables &variables) { const auto surfaces = - input.spawnjson.value("model", json::object()).value("buildingSurfaceDetailed", std::vector(0)); + user_config.spawnjson.value("model", json::object()).value("buildingSurfaceDetailed", std::vector(0)); for (const auto &surface : surfaces) { const auto surface_name = surface.value("name", ""); @@ -1140,7 +1215,7 @@ namespace construction { } A::A(Variables &variables, const std::string_view surface_name) - : Output(variables, std::string(surface_name) + "_A", units::UnitType::m2, units::UnitType::m2), + : Parameter(variables, std::string(surface_name) + "_A", units::UnitType::m2, units::UnitType::m2), surface_num_( [surface_name](EnergyPlus::EnergyPlusData &data) { return energyplus::SurfaceNum(data, surface_name); }) { @@ -1163,10 +1238,10 @@ namespace construction { SetValue(energyplus::SurfaceArea(energyplus_data, surface_num_.get(energyplus_data)), spawn::units::UnitSystem::EP); } - void QFrontFlow::create(const spawn::Input &input, Variables &variables) + void QFrontFlow::create(const UserConfig &user_config, Variables &variables) { const auto surfaces = - input.spawnjson.value("model", json::object()).value("buildingSurfaceDetailed", std::vector(0)); + user_config.spawnjson.value("model", json::object()).value("buildingSurfaceDetailed", std::vector(0)); for (const auto &surface : surfaces) { const auto surface_name = surface.value("name", ""); @@ -1202,10 +1277,10 @@ namespace construction { spawn::units::UnitSystem::EP); } - void QBackFlow::create(const spawn::Input &input, Variables &variables) + void QBackFlow::create(const UserConfig &user_config, Variables &variables) { const auto surfaces = - input.spawnjson.value("model", json::object()).value("buildingSurfaceDetailed", std::vector(0)); + user_config.spawnjson.value("model", json::object()).value("buildingSurfaceDetailed", std::vector(0)); for (const auto &surface : surfaces) { const auto surface_name = surface.value("name", ""); @@ -1241,10 +1316,10 @@ namespace construction { spawn::units::UnitSystem::EP); } - void TFront::create(const spawn::Input &input, Variables &variables) + void TFront::create(const UserConfig &user_config, Variables &variables) { const auto surfaces = - input.spawnjson.value("model", json::object()).value("buildingSurfaceDetailed", std::vector(0)); + user_config.spawnjson.value("model", json::object()).value("buildingSurfaceDetailed", std::vector(0)); for (const auto &surface : surfaces) { const auto surface_name = surface.value("name", ""); @@ -1277,10 +1352,10 @@ namespace construction { } } - void TBack::create(const spawn::Input &input, Variables &variables) + void TBack::create(const UserConfig &user_config, Variables &variables) { const auto surfaces = - input.spawnjson.value("model", json::object()).value("buildingSurfaceDetailed", std::vector(0)); + user_config.spawnjson.value("model", json::object()).value("buildingSurfaceDetailed", std::vector(0)); for (const auto &surface : surfaces) { const auto surface_name = surface.value("name", ""); @@ -1314,42 +1389,4 @@ namespace construction { } } // namespace construction -void CreateVariables(const spawn::Input &input, Variables &variables) -{ - zone::V::create(input, variables); - zone::AFlo::create(input, variables); - zone::MSenFac::create(input, variables); - zone::QConSenFlow::create(input, variables); - zone::QLatFlow::create(input, variables); - zone::QPeoFlow::create(input, variables); - zone::TRad::create(input, variables); - zone::QCooSenFlow::create(input, variables); - zone::QCooLatFlow::create(input, variables); - zone::TOutCoo::create(input, variables); - zone::XOutCoo::create(input, variables); - zone::MOutCooFlow::create(input, variables); - zone::TCoo::create(input, variables); - zone::QHeaFlow::create(input, variables); - zone::TOutHea::create(input, variables); - zone::XOutHea::create(input, variables); - zone::MOutHeaFlow::create(input, variables); - zone::THea::create(input, variables); - zone::MInletsFlow::create(input, variables); - zone::TAveInlet::create(input, variables); - zone::T::create(input, variables); - zone::X::create(input, variables); - zone::QGaiRadFlow::create(input, variables); - other::Sensor::create(input, variables); - other::Actuator::create(input, variables); - other::Schedule::create(input, variables); - surface::A::create(input, variables); - surface::QFlow::create(input, variables); - surface::T::create(input, variables); - construction::A::create(input, variables); - construction::QFrontFlow::create(input, variables); - construction::QBackFlow::create(input, variables); - construction::TFront::create(input, variables); - construction::TBack::create(input, variables); -} - } // namespace spawn::variable diff --git a/energyplus_coroutine/variables.hpp b/energyplus_coroutine/variables.hpp index 799c9dd84..72b9db5ff 100644 --- a/energyplus_coroutine/variables.hpp +++ b/energyplus_coroutine/variables.hpp @@ -17,7 +17,7 @@ namespace units { enum class UnitSystem; } // namespace units -class Input; +class UserConfig; class Spawn; } // namespace spawn @@ -71,6 +71,13 @@ class Output : public Variable Output(Variables &variables, std::string_view name, units::UnitType ep_unit, units::UnitType mo_unit); }; +// A Variable like Output, but the value does not change during the simulation +class Parameter : public Variable +{ +protected: + Parameter(Variables &variables, std::string_view name, units::UnitType ep_unit, units::UnitType mo_unit); +}; + // A Variable that is an input to EnergyPlus class Input : public Variable { @@ -115,10 +122,8 @@ template class CachedValue GetterFunction getter_; }; -void CreateVariables(const spawn::Input &input, Variables &variables); - using VariableVector = std::vector>; -using VariableRefs = std::vector>; +using VariableRefs = std::vector>; // This is a container to hold a set of Variable instances. // In the main Spawn API, a variable is accessed by index, @@ -126,38 +131,50 @@ using VariableRefs = std::vector>; class Variables { public: - Variables() = default; + explicit Variables(const UserConfig &user_config); Variables &operator=(const Variables &) = delete; Variables &operator=(Variables &&) = delete; Variables(const Variables &) = delete; Variables(Variables &&) = delete; virtual ~Variables() = default; - void AddVariable(std::unique_ptr &&variable); - void AddVariable(Output &variable); - void AddVariable(Input &variable); - [[nodiscard]] const VariableVector &AllVariables() const; [[nodiscard]] const VariableRefs &Inputs() const; [[nodiscard]] const VariableRefs &Outputs() const; + [[nodiscard]] const VariableRefs &Parameters() const; + + void UpdateInputs(EnergyPlus::EnergyPlusData &energyplus_data); + void UpdateOutputs(EnergyPlus::EnergyPlusData &energyplus_data); + void UpdateParameters(EnergyPlus::EnergyPlusData &energyplus_data); private: - // This vector owns all of the variables + void AddVariable(std::unique_ptr &&variable); + void AddVariable(Input &variable); + void AddVariable(Output &variable); + void AddVariable(Parameter &variable); + + // This vector owns all of the variables VariableVector all_variables_; // It is common to iterate over only the inputs, outputs, or parameters, - // therefore additional vectors of references are used as efficient indexes + // therefore these vectors of references are used as efficient indexes // for the different types of Variable. VariableRefs input_variables_; VariableRefs output_variables_; + VariableRefs parameter_variables_; + + friend class Variable; + friend class Input; + friend class Output; + friend class Parameter; }; // Begin defining the specific Variable types, which are documented here: // https://lbl-srg.github.io/soep/softwareArchitecture.html#coupling-of-the-envelope-model namespace zone { - class V : public Output + class V : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -166,10 +183,10 @@ namespace zone { CachedValue zone_num_; }; - class AFlo : public Output + class AFlo : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -177,10 +194,10 @@ namespace zone { CachedValue zone_num_; }; - class MSenFac : public Output + class MSenFac : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -191,7 +208,7 @@ namespace zone { class QConSenFlow : public Output { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -202,7 +219,7 @@ namespace zone { class QLatFlow : public Output { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -213,7 +230,7 @@ namespace zone { class QPeoFlow : public Output { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -224,7 +241,7 @@ namespace zone { class TRad : public Output { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -232,10 +249,10 @@ namespace zone { CachedValue zone_num_; }; - class QCooSenFlow : public Output + class QCooSenFlow : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -243,10 +260,10 @@ namespace zone { CachedValue zone_num_; }; - class QCooLatFlow : public Output + class QCooLatFlow : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -254,10 +271,10 @@ namespace zone { CachedValue zone_num_; }; - class TOutCoo : public Output + class TOutCoo : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -265,10 +282,10 @@ namespace zone { CachedValue zone_num_; }; - class XOutCoo : public Output + class XOutCoo : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -276,10 +293,10 @@ namespace zone { CachedValue zone_num_; }; - class MOutCooFlow : public Output + class MOutCooFlow : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -287,10 +304,10 @@ namespace zone { CachedValue zone_num_; }; - class TCoo : public Output + class TCoo : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -298,10 +315,10 @@ namespace zone { CachedValue zone_num_; }; - class QHeaFlow : public Output + class QHeaFlow : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -309,10 +326,10 @@ namespace zone { CachedValue zone_num_; }; - class TOutHea : public Output + class TOutHea : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -320,10 +337,10 @@ namespace zone { CachedValue zone_num_; }; - class XOutHea : public Output + class XOutHea : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -331,10 +348,10 @@ namespace zone { CachedValue zone_num_; }; - class MOutHeaFlow : public Output + class MOutHeaFlow : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -342,10 +359,10 @@ namespace zone { CachedValue zone_num_; }; - class THea : public Output + class THea : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -356,7 +373,7 @@ namespace zone { class MInletsFlow : public Input { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -367,7 +384,7 @@ namespace zone { class TAveInlet : public Input { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -378,7 +395,7 @@ namespace zone { class T : public Input { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -389,7 +406,7 @@ namespace zone { class X : public Input { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -400,7 +417,7 @@ namespace zone { class QGaiRadFlow : public Input { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -418,7 +435,7 @@ namespace other { class Sensor : public Output { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -435,7 +452,7 @@ namespace other { class Actuator : public Input { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -454,7 +471,7 @@ namespace other { class Schedule : public Input { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -472,10 +489,10 @@ namespace other { } // namespace other namespace surface { - class A : public Output + class A : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -487,7 +504,7 @@ namespace surface { class QFlow : public Output { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -499,7 +516,7 @@ namespace surface { class T : public Input { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -510,10 +527,10 @@ namespace surface { } // namespace surface namespace construction { - class A : public Output + class A : public Parameter { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -525,7 +542,7 @@ namespace construction { class QFrontFlow : public Output { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -537,7 +554,7 @@ namespace construction { class QBackFlow : public Output { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -549,7 +566,7 @@ namespace construction { class TFront : public Input { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: @@ -561,7 +578,7 @@ namespace construction { class TBack : public Input { public: - static void create(const spawn::Input &input, Variables &variables); + static void create(const UserConfig &user_config, Variables &variables); void Update(EnergyPlus::EnergyPlusData &energyplus_data) final; private: