Skip to content

Commit

Permalink
Add option --output-vars
Browse files Browse the repository at this point in the history
This option on spawn executable will output a json string of all
supported EnergyPlus output variables. The json structure also includes
the EnergyPlus and Modelica units corresponding to each variable.

ref lbl-srg/modelica-buildings#2223
  • Loading branch information
kbenne committed Nov 6, 2020
1 parent 210c5c7 commit b3b0091
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cli/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../lib/fmugenerator.hpp"
#include "../lib/outputtypes.hpp"
#include <CLI/CLI.hpp>
#include <nlohmann/json.hpp>
#include <cstdio>
Expand Down Expand Up @@ -123,8 +124,9 @@ int main(int argc, const char *argv[]) {
auto compressOption = app.add_flag("--no-compress", nocompress, "Skip compressing the contents of the fmu zip archive. An uncompressed zip archive will be created instead.");
compressOption->needs(createOption);

auto versionOption =
app.add_flag("-v,--version", "Print version info and exit");
auto outputVarsOption = app.add_flag("--output-vars", "Report the EnergyPlus output variables supported by this version of Spawn.");

auto versionOption = app.add_flag("-v,--version", "Print version info and exit");

#if defined ENABLE_MODELICA_COMPILER
std::string moinput = "";
Expand All @@ -145,6 +147,8 @@ int main(int argc, const char *argv[]) {
#endif
} else if (*versionOption) {
std::cout << "Spawn-" << spawn::VERSION_STRING << std::endl;
} else if (*outputVarsOption) {
std::cout << nlohmann::json(outputtypes).dump(4) << std::endl;
}
} catch(...) {
eptr = std::current_exception();
Expand Down
13 changes: 13 additions & 0 deletions lib/outputtypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "units.hpp"
#include <map>
#include <nlohmann/json.hpp>

struct OutputProperties {
OutputProperties() = delete;
Expand All @@ -11,6 +12,18 @@ struct OutputProperties {
spawn::units::UnitType epUnitType;
};

static void to_json(nlohmann::json& j, const OutputProperties& p) {
j = nlohmann::json{
{"modelicaUnit", spawn::units::toString(p.moUnitType)},
{"energyplusUnit", spawn::units::toString(p.epUnitType)}
};
}

static void from_json(const nlohmann::json& j, OutputProperties& p) {
p.moUnitType = spawn::units::fromString(j.at("modelicaUnit").get<std::string>());
p.epUnitType = spawn::units::fromString(j.at("energyplusUnit").get<std::string>());
}

const std::map<const char *, OutputProperties> outputtypes {
{"Site Outdoor Air Drybulb Temperature",{spawn::units::UnitType::K, spawn::units::UnitType::C}},
{"Site Outdoor Air Dewpoint Temperature",{spawn::units::UnitType::K, spawn::units::UnitType::C}},
Expand Down

0 comments on commit b3b0091

Please sign in to comment.