GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 50
Functions: 0.0% 0 / 0 / 2
Branches: 0.0% 0 / 0 / 122

src/workflow/RunModelicaMeasures.cpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #include "OSWorkflow.hpp"
7
8 #include "../utilities/filetypes/EpwFile.hpp"
9
10 namespace openstudio {
11
12 ✗ void OSWorkflow::runModelicaMeasures() {
13 ✗ state = State::ModelicaMeasures;
14
15 ✗ LOG(Info, "Beginning to execute Modelica Measures");
16 ✗ const auto workflow = runner.workflow();
17 ✗ const auto seedModelicaModel = workflow.seedModelicaModel();
18 ✗ OS_ASSERT(seedModelicaModel);
19
20 ✗ const auto runDir = workflow.absoluteRunDir();
21 ✗ const auto quotePath = [](const openstudio::path& p) {
22 ✗ auto s = p.generic_string();
23 ✗ s.insert(s.begin(), '"');
24 ✗ s.push_back('"');
25 ✗ return s;
26 ✗ };
27 ✗ auto params = runner.modelicaParameters();
28
29 ✗ const auto idfPath = runDir / "in.idf";
30 ✗ params.setParameterValue(*seedModelicaModel, "idfPath", quotePath(idfPath));
31 ✗ LOG(Info, "Setting Modelica parameter 'idfPath' to '" << idfPath.generic_string() << "'");
32
33 ✗ if (const auto epwPath = runner.lastEpwFilePath()) {
34 ✗ params.setParameterValue(*seedModelicaModel, "epwPath", quotePath(*epwPath));
35 ✗ LOG(Info, "Setting Modelica parameter 'epwPath' to '" << epwPath->generic_string() << "'");
36
37 ✗ const auto mosPath = runDir / "in.mos";
38 ✗ bool generatedMos = false;
39 ✗ if (auto epwFile = EpwFile::load(*epwPath, true)) {
40 try {
41 ✗ const auto parent = mosPath.parent_path();
42 ✗ if (!parent.empty()) {
43 ✗ openstudio::filesystem::create_directories(parent);
44 }
45 ✗ } catch (const std::exception& e) {
46 ✗ LOG(Warn, "Unable to ensure directory for Modelica .mos file '" << mosPath.generic_string() << "': " << e.what());
47 ✗ }
48
49 ✗ generatedMos = epwFile->translateToMos(mosPath);
50 ✗ if (!generatedMos) {
51 ✗ LOG(Warn, "Failed to convert weather file '" << epwPath->generic_string() << "' into '" << mosPath.generic_string() << "'");
52 }
53 } else {
54 ✗ LOG(Warn, "Unable to load weather file '" << epwPath->generic_string() << "' to generate a Modelica .mos file");
55 ✗ }
56
57 ✗ if (generatedMos) {
58 ✗ params.setParameterValue(*seedModelicaModel, "weaPath", quotePath(mosPath));
59 ✗ LOG(Info, "Setting Modelica parameter 'weaPath' to '" << mosPath.generic_string() << "'");
60 }
61 ✗ } else {
62 ✗ LOG(Warn, "No weather file available from the workflow; 'epwPath' and 'weaPath' Modelica parameters were not set");
63 ✗ }
64
65 ✗ applyMeasures(MeasureType::ModelicaMeasure, ApplyMeasureType::Regular);
66 try {
67 ✗ saveModelicaFileSnapshot(workflowJSON.absoluteRunDir());
68 ✗ } catch (const std::exception& e) {
69 ✗ runner.registerError(e.what());
70 ✗ state = State::Errored;
71 ✗ throw;
72 ✗ }
73 ✗ LOG(Info, "Finished applying Modelica Measures.");
74
75 ✗ communicateMeasureAttributes();
76 ✗ }
77
78 } // namespace openstudio
79