From 5b2cf228aebe0c9c00dcb5ab3efcac4544a91838 Mon Sep 17 00:00:00 2001 From: Lars Bilke Date: Wed, 8 May 2024 10:22:34 +0200 Subject: [PATCH 1/2] [ogs] -m switch: fallback to reading gml from prj-file directory. When a mesh directory is given with the -m switch, the gml file is also read from the given mesh directory. This commit adds a fallback to also reading from the prj-file directory. Motivation is when using partitioned meshes they often are created in subdirectories of the project. Before this one had to copy the gml file into that location too. --- Applications/ApplicationsLib/ProjectData.cpp | 36 ++++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp index 6b2b5896127..4923d8b5104 100644 --- a/Applications/ApplicationsLib/ProjectData.cpp +++ b/Applications/ApplicationsLib/ProjectData.cpp @@ -152,11 +152,25 @@ namespace { -void readGeometry(std::string const& fname, GeoLib::GEOObjects& geo_objects) +void readGeometry(std::string const& fname, GeoLib::GEOObjects& geo_objects, + std::string const& dir_first, std::string const& dir_second) { DBUG("Reading geometry file '{:s}'.", fname); GeoLib::IO::BoostXmlGmlInterface gml_reader(geo_objects); - gml_reader.readFile(fname); + std::string geometry_file = BaseLib::copyPathToFileName(fname, dir_first); + if (!BaseLib::IsFileExisting(geometry_file)) + { + // Fallback to reading gml from prj-file directory + geometry_file = BaseLib::copyPathToFileName(fname, dir_second); + WARN("File {:s} not found in {:s}! Trying reading from {:s}.", fname, + dir_first, dir_second); + if (!BaseLib::IsFileExisting(geometry_file)) + { + OGS_FATAL("Could not read geometry file {:s} in {:s}.", fname, + dir_second); + } + } + gml_reader.readFile(geometry_file); } std::unique_ptr readSingleMesh( @@ -192,7 +206,8 @@ std::unique_ptr readSingleMesh( } std::vector> readMeshes( - BaseLib::ConfigTree const& config, std::string const& directory) + BaseLib::ConfigTree const& config, std::string const& directory, + std::string const& project_directory) { std::vector> meshes; @@ -213,9 +228,8 @@ std::vector> readMeshes( //! \ogs_file_param{prj__geometry} config.getConfigParameterOptional("geometry")) { - std::string const geometry_file = - BaseLib::copyPathToFileName(*geometry_file_name, directory); - readGeometry(geometry_file, geoObjects); + readGeometry(*geometry_file_name, geoObjects, directory, + project_directory); } } else @@ -224,11 +238,11 @@ std::vector> readMeshes( //! \ogs_file_param{prj__mesh} readSingleMesh(config.getConfigParameter("mesh"), directory)); - std::string const geometry_file = BaseLib::copyPathToFileName( + auto const geometry_file_name = //! \ogs_file_param{prj__geometry} - config.getConfigParameter("geometry"), - directory); - readGeometry(geometry_file, geoObjects); + config.getConfigParameter("geometry"); + readGeometry(geometry_file_name, geoObjects, directory, + project_directory); } { // generate meshes from geometries @@ -332,7 +346,7 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config, std::string const& output_directory, std::string const& mesh_directory, [[maybe_unused]] std::string const& script_directory) - : _mesh_vec(readMeshes(project_config, mesh_directory)), + : _mesh_vec(readMeshes(project_config, mesh_directory, project_directory)), _named_rasters(readRasters(project_config, project_directory, GeoLib::AABB(_mesh_vec[0]->getNodes().begin(), _mesh_vec[0]->getNodes().end()) From e9deb7d8f5a8f8b84a5770b4163cee988d7f9142 Mon Sep 17 00:00:00 2001 From: Lars Bilke Date: Wed, 8 May 2024 10:30:01 +0200 Subject: [PATCH 2/2] [ogs,partmesh] Fixed a warning when output directory is not given. Follow-up on !4989 and !4996. --- Applications/CLI/ogs.cpp | 1 + .../Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/Applications/CLI/ogs.cpp b/Applications/CLI/ogs.cpp index 41727f6ddba..6a0e81c80a7 100644 --- a/Applications/CLI/ogs.cpp +++ b/Applications/CLI/ogs.cpp @@ -65,6 +65,7 @@ int main(int argc, char* argv[]) INFO("This is OpenGeoSys-6 version {:s}.", GitInfoLib::GitInfo::ogs_version); + if (cli_arg.outdir.length() > 0) { std::error_code mkdir_err; if (std::filesystem::create_directories(cli_arg.outdir, mkdir_err)) diff --git a/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp b/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp index 95707a7ca09..bf4017eaa78 100644 --- a/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp +++ b/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp @@ -118,6 +118,7 @@ int main(int argc, char* argv[]) }); const auto output_directory = output_directory_arg.getValue(); + if (output_directory.length() > 0) { std::error_code mkdir_err; if (std::filesystem::create_directories(output_directory, mkdir_err))