From 980415903fa094555689358f06e37f5440ea8b82 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Wed, 2 Feb 2022 20:01:44 +0100
Subject: [PATCH] [cli] Added parameter -m for specifying a mesh input
 directory.

Per default meshes are loaded relative to the .prj-file directory.
When specifying -m the meshes are loaded relative to the specified
directory.
---
 Applications/ApplicationsLib/ProjectData.cpp |  5 +++--
 Applications/ApplicationsLib/ProjectData.h   |  7 ++++---
 Applications/CLI/ogs.cpp                     | 10 +++++++---
 BaseLib/PrjProcessing.cpp                    |  4 +---
 4 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp
index 38b6bd6a80d..d3fb9c9923f 100644
--- a/Applications/ApplicationsLib/ProjectData.cpp
+++ b/Applications/ApplicationsLib/ProjectData.cpp
@@ -283,8 +283,9 @@ ProjectData::ProjectData() = default;
 
 ProjectData::ProjectData(BaseLib::ConfigTree const& project_config,
                          std::string const& project_directory,
-                         std::string const& output_directory)
-    : _mesh_vec(readMeshes(project_config, project_directory))
+                         std::string const& output_directory,
+                         std::string const& mesh_directory)
+    : _mesh_vec(readMeshes(project_config, mesh_directory))
 {
     if (auto const python_script =
             //! \ogs_file_param{prj__python_script}
diff --git a/Applications/ApplicationsLib/ProjectData.h b/Applications/ApplicationsLib/ProjectData.h
index 411e22c0fad..716731eb9b4 100644
--- a/Applications/ApplicationsLib/ProjectData.h
+++ b/Applications/ApplicationsLib/ProjectData.h
@@ -55,17 +55,18 @@ public:
 
     /// Constructs project data by parsing provided configuration.
     ///
-    /// \param project_config Configuration as read from the prj file.
+    /// \param project_config    Configuration as read from the prj file.
     /// \param project_directory Where to look for files referenced in the
     ///                          \c config_tree.
     /// \param output_directory  Where to write simulation output files to.
+    /// \param mesh_directory    Directory where meshes are read from.
     ProjectData(BaseLib::ConfigTree const& project_config,
                 std::string const& project_directory,
-                std::string const& output_directory);
+                std::string const& output_directory,
+                std::string const& mesh_directory);
 
     ProjectData(ProjectData&) = delete;
 
-
     //
     // Process interface
     //
diff --git a/Applications/CLI/ogs.cpp b/Applications/CLI/ogs.cpp
index 04d30ad5371..a91f850016d 100644
--- a/Applications/CLI/ogs.cpp
+++ b/Applications/CLI/ogs.cpp
@@ -101,6 +101,11 @@ int main(int argc, char* argv[])
                                             false, "", "PATH");
     cmd.add(outdir_arg);
 
+    TCLAP::ValueArg<std::string> meshdir_arg(
+        "m", "mesh-input-directory",
+        "the directory where the meshes are read from", false, "", "PATH");
+    cmd.add(meshdir_arg);
+
     TCLAP::ValueArg<std::string> log_level_arg(
         "l", "log-level",
         "the verbosity of logging messages: none, error, warn, info, debug, "
@@ -214,9 +219,8 @@ int main(int argc, char* argv[])
             BaseLib::setProjectDirectory(
                 BaseLib::extractPath(project_arg.getValue()));
 
-            ProjectData project(project_config,
-                                BaseLib::getProjectDirectory(),
-                                outdir_arg.getValue());
+            ProjectData project(project_config, BaseLib::getProjectDirectory(),
+                                outdir_arg.getValue(), meshdir_arg.getValue());
 
             if (!reference_path_arg.isSet())
             {  // Ignore the test_definition section.
diff --git a/BaseLib/PrjProcessing.cpp b/BaseLib/PrjProcessing.cpp
index 84702330f45..510f19171bd 100644
--- a/BaseLib/PrjProcessing.cpp
+++ b/BaseLib/PrjProcessing.cpp
@@ -274,10 +274,8 @@ void prepareProjectFile(std::stringstream& prj_stream,
 
     std::vector<std::string> patch_files_copy = patch_files;
     readAndPatchPrj(prj_stream, prj_file, patch_files_copy);
-    // LB TODO later: replace canonical with absolute when a mesh input dir
-    // ogs parameter is implemented.
     replaceIncludes(prj_stream,
-                    std::filesystem::canonical(std::filesystem::path(prj_file))
+                    std::filesystem::absolute(std::filesystem::path(prj_file))
                         .parent_path());
     // re-apply xml patches to stream
     for (const auto& patch_file : patch_files_copy)
-- 
GitLab