MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / getModelicaSetup

Function getModelicaSetup

src/workflow/RunModelica.cpp:261–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259 }
260
261 ModelicaSetup getModelicaSetup(const WorkflowJSON& workflowJSON, const boost::optional<openstudio::path>& finalSeedModelicaFile) {
262 ModelicaSetup setup;
263
264 auto addSearchPath = [&setup](const openstudio::path& dir) {
265 if (dir.empty()) {
266 return;
267 }
268 setup.searchPaths.push_back(dir);
269 };
270
271 auto addFileToLoad = [&setup, &addSearchPath](const openstudio::path& file) {
272 if (file.empty()) {
273 return;
274 }
275 const auto absoluteFile = boost::filesystem::absolute(file);
276 setup.files.push_back(absoluteFile);
277 addSearchPath(absoluteFile.parent_path());
278 };
279
280 const auto handleDirectory = [&addFileToLoad, &addSearchPath](const openstudio::path& dir) {
281 const auto absoluteDir = boost::filesystem::absolute(dir);
282 addSearchPath(absoluteDir);
283 const auto packageMo = absoluteDir / toPath("package.mo");
284 if (openstudio::filesystem::exists(packageMo)) {
285 addFileToLoad(packageMo);
286 }
287 };
288
289 for (const auto& envPath : getModelicaPathEnvEntries()) {
290 addSearchPath(envPath);
291 }
292
293 for (const auto& packageSpec : workflowJSON.modelicaPackages()) {
294 openstudio::path resolved;
295 if (packageSpec.is_absolute()) {
296 resolved = packageSpec;
297 } else {
298 if (auto located = workflowJSON.findFile(packageSpec)) {
299 resolved = *located;
300 }
301 }
302
303 if (resolved.empty()) {
304 throw std::runtime_error(fmt::format("Modelica package '{}' could not be resolved", toString(packageSpec)));
305 }
306
307 if (!openstudio::filesystem::exists(resolved)) {
308 throw std::runtime_error(fmt::format("Modelica package '{}' does not exist at '{}'", toString(packageSpec), resolved.generic_string()));
309 }
310
311 if (openstudio::filesystem::is_directory(resolved)) {
312 handleDirectory(resolved);
313 } else {
314 addFileToLoad(resolved);
315 }
316 }
317
318 if (finalSeedModelicaFile) {

Callers 1

runModelicaMethod · 0.85

Calls 10

dedupePathsFunction · 0.85
modelicaPackagesMethod · 0.80
findFileMethod · 0.80
seedModelicaFileMethod · 0.80
toPathFunction · 0.50
toStringFunction · 0.50
emptyMethod · 0.45
push_backMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected