src/workflow/RunInitialization.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 "Util.hpp" | ||
| 9 | |||
| 10 | #include "../model/Model.hpp" | ||
| 11 | #include "../model/WeatherFile.hpp" | ||
| 12 | #include "../model/FileOperations.hpp" | ||
| 13 | |||
| 14 | #include "../utilities/filetypes/WorkflowJSON.hpp" | ||
| 15 | #include "../utilities/filetypes/RunOptions.hpp" | ||
| 16 | |||
| 17 | #include "../utilities/core/Assert.hpp" | ||
| 18 | #include "../utilities/core/Filesystem.hpp" | ||
| 19 | |||
| 20 | #include <fmt/chrono.h> | ||
| 21 | |||
| 22 | namespace openstudio { | ||
| 23 | |||
| 24 | 22 | void OSWorkflow::runInitialization() { | |
| 25 | |||
| 26 | 22 | state = State::Initialization; | |
| 27 | |||
| 28 |
1/1✓ Branch 1 taken 22 times.
|
22 | auto rootDir = workflowJSON.absoluteRootDir(); |
| 29 |
6/6✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
✓ Branch 7 taken 22 times.
✓ Branch 10 taken 22 times.
✓ Branch 13 taken 22 times.
✓ Branch 16 taken 22 times.
|
22 | LOG(Debug, "The root_dir for the datapoint is " << rootDir); |
| 30 | |||
| 31 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
|
44 | detailedTimeBlock("Wiping directories", [this, &rootDir]() { |
| 32 | { | ||
| 33 |
1/1✓ Branch 1 taken 22 times.
|
44 | auto generatedFilesDir = rootDir / "generated_files"; |
| 34 |
3/3✓ Branch 1 taken 22 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 2 times.
|
22 | if (openstudio::filesystem::is_directory(generatedFilesDir)) { |
| 35 |
6/6✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
✓ Branch 7 taken 20 times.
✓ Branch 10 taken 20 times.
✓ Branch 13 taken 20 times.
✓ Branch 16 taken 20 times.
|
20 | LOG(Debug, "Removing existing generated files directory: " << generatedFilesDir); |
| 36 |
1/1✓ Branch 1 taken 20 times.
|
20 | openstudio::filesystem::remove_all(generatedFilesDir); |
| 37 | } | ||
| 38 |
6/6✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
✓ Branch 7 taken 22 times.
✓ Branch 10 taken 22 times.
✓ Branch 13 taken 22 times.
✓ Branch 16 taken 22 times.
|
22 | LOG(Debug, "Creating generated files directory: " << generatedFilesDir); |
| 39 |
1/1✓ Branch 1 taken 22 times.
|
22 | openstudio::filesystem::create_directories(generatedFilesDir); |
| 40 | |||
| 41 | // insert the generated files directory in the first spot so all generated ExternalFiles go here | ||
| 42 |
1/1✓ Branch 1 taken 22 times.
|
22 | auto fps = workflowJSON.filePaths(); |
| 43 |
1/1✓ Branch 1 taken 22 times.
|
22 | workflowJSON.resetFilePaths(); |
| 44 |
1/1✓ Branch 1 taken 22 times.
|
22 | workflowJSON.addFilePath(generatedFilesDir); |
| 45 |
2/2✓ Branch 5 taken 110 times.
✓ Branch 6 taken 22 times.
|
132 | for (const auto& fp : fps) { |
| 46 |
1/1✓ Branch 1 taken 110 times.
|
110 | workflowJSON.addFilePath(fp); |
| 47 | } | ||
| 48 | |||
| 49 |
1/1✓ Branch 1 taken 22 times.
|
44 | auto reportsDir = rootDir / "reports"; |
| 50 |
3/3✓ Branch 1 taken 22 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 6 times.
|
22 | if (openstudio::filesystem::is_directory(reportsDir)) { |
| 51 |
6/6✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
✓ Branch 10 taken 16 times.
✓ Branch 13 taken 16 times.
✓ Branch 16 taken 16 times.
|
16 | LOG(Debug, "Removing existing reports directory: " << reportsDir); |
| 52 |
1/1✓ Branch 1 taken 16 times.
|
16 | openstudio::filesystem::remove_all(reportsDir); |
| 53 | } | ||
| 54 | 22 | } | |
| 55 | 22 | }); | |
| 56 | |||
| 57 | // TODO: Validate the OSW measures if the flag is set to true, (the default state) | ||
| 58 | // There isn't a 'verify_osw' key in the RunOptions, so always do it for now. Maybe don't if `fast`? | ||
| 59 | { | ||
| 60 |
5/5✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
✓ Branch 7 taken 22 times.
✓ Branch 10 taken 22 times.
✓ Branch 13 taken 22 times.
|
22 | LOG(Info, "Attempting to validate the measure workflow"); |
| 61 | |||
| 62 |
3/3✓ Branch 1 taken 22 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 19 times.
|
22 | if (!workflowJSON.validateMeasures()) { |
| 63 |
13/13✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
✓ Branch 19 taken 3 times.
✓ Branch 22 taken 3 times.
✓ Branch 25 taken 3 times.
✓ Branch 28 taken 3 times.
✓ Branch 31 taken 3 times.
✓ Branch 34 taken 3 times.
✓ Branch 38 taken 3 times.
✓ Branch 41 taken 3 times.
|
3 | LOG_AND_THROW("Workflow is invalid"); |
| 64 | } | ||
| 65 | |||
| 66 |
5/5✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
✓ Branch 7 taken 19 times.
✓ Branch 10 taken 19 times.
✓ Branch 13 taken 19 times.
|
19 | LOG(Info, "Validated the measure workflow"); |
| 67 | } | ||
| 68 | |||
| 69 |
5/5✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
✓ Branch 7 taken 19 times.
✓ Branch 10 taken 19 times.
✓ Branch 13 taken 19 times.
|
19 | LOG(Debug, "Finding and loading the seed file"); |
| 70 |
1/1✓ Branch 1 taken 19 times.
|
19 | auto seedPath_ = workflowJSON.seedFile(); |
| 71 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 4 times.
|
19 | if (seedPath_) { |
| 72 |
2/2✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
|
15 | auto modelFullPath_ = workflowJSON.findFile(seedPath_.get()); |
| 73 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
|
15 | if (!modelFullPath_) { |
| 74 | ✗ | state = State::Errored; | |
| 75 | ✗ | throw std::runtime_error(fmt::format("Seed model {} specified in OSW cannot be found", seedPath_->string())); | |
| 76 | } | ||
| 77 | |||
| 78 |
4/5✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
✓ Branch 7 taken 15 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 15 times.
|
30 | if (modelFullPath_->extension() == openstudio::filesystem::path(".idf")) { |
| 79 | ✗ | if (m_add_timings && m_detailed_timings) { | |
| 80 | ✗ | m_timers->newTimer(" Loading seed IDF"); | |
| 81 | } | ||
| 82 | ✗ | detailedTimeBlock("Loading seed IDF", [this, &modelFullPath_] { workspace_ = openstudio::workflow::util::loadIDF(modelFullPath_.get()); }); | |
| 83 | |||
| 84 | } else { | ||
| 85 |
2/2✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
|
15 | detailedTimeBlock("Loading seed OSM (VersionTranslation)", |
| 86 |
2/2✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
|
45 | [this, &modelFullPath_] { model = openstudio::workflow::util::loadOSM(modelFullPath_.get()); }); |
| 87 | } | ||
| 88 | 15 | } else { | |
| 89 |
1/1✓ Branch 1 taken 4 times.
|
4 | model = openstudio::model::Model{}; |
| 90 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | openstudio::model::initializeModelObjects(model); |
| 91 | } | ||
| 92 | |||
| 93 |
1/1✓ Branch 1 taken 19 times.
|
19 | initializeWeatherFileFromOSW(); |
| 94 | |||
| 95 |
1/1✓ Branch 1 taken 19 times.
|
19 | const auto seedModelicaPath = workflowJSON.seedModelicaFile(); |
| 96 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (seedModelicaPath) { |
| 97 | ✗ | auto seedModelicaFileFullPath = workflowJSON.findFile(seedModelicaPath.get()); | |
| 98 | ✗ | if (!seedModelicaFileFullPath) { | |
| 99 | ✗ | state = State::Errored; | |
| 100 | ✗ | throw std::runtime_error(fmt::format("Seed Modelica File: {}, specified in OSW cannot be found", seedModelicaPath->string())); | |
| 101 | } | ||
| 102 | ✗ | modelicaFile = modelica::ModelicaFile(seedModelicaFileFullPath.get()); | |
| 103 | ✗ | m_modelicaSeedFileName = seedModelicaFileFullPath->filename(); | |
| 104 | ✗ | m_latestModelicaFilePath = seedModelicaFileFullPath.get(); | |
| 105 | ✗ | } | |
| 106 | |||
| 107 | // Set a clone of the WorkflowJSON for the model, so that it finds the filePaths (such as generated_files we added above) | ||
| 108 |
2/2✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
|
19 | model.setWorkflowJSON(workflowJSON.clone()); |
| 109 | |||
| 110 | // Tell the workflowJSON we have started, it'll log the start time and reset the stepResults | ||
| 111 |
1/1✓ Branch 1 taken 19 times.
|
19 | workflowJSON.start(); |
| 112 | 22 | } | |
| 113 | |||
| 114 | } // namespace openstudio | ||
| 115 |