From 9e18bd2d002b316cbe682e0ef0d8cbbba0299a85 Mon Sep 17 00:00:00 2001 From: Jed Brown Date: Tue, 13 Jun 2023 00:12:15 -0600 Subject: [PATCH] FEM: fix gmsh relative paths Relative paths appearing in Gmsh .geo files are relative to the .geo file, not relative to the cwd when the gmsh executable was invoked. This is okay when using absolute paths with the default "Temporary directories" mode, but if one selects (in Preferences -> FEM) "Beside .FCStd file", then relative paths are written to the .geo file. This causes a (suppressed in FreeCAD output) warning from Gmsh that the brep file is missing as well as the error: Unexpected error when creating mesh: File to load not existing or not readable: partname/FEMMeshGmsh/BaseFeature_Mesh.unv In this commit we just use relative paths, which is also convenient if users move these files elsewhere (e.g., to work directly with advanced features in Gmsh). --- src/Mod/Fem/femmesh/gmshtools.py | 5 +++-- src/Mod/Fem/femtest/data/elmer/group_mesh.geo | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Mod/Fem/femmesh/gmshtools.py b/src/Mod/Fem/femmesh/gmshtools.py index a8de810248..cfdc4edcf4 100644 --- a/src/Mod/Fem/femmesh/gmshtools.py +++ b/src/Mod/Fem/femmesh/gmshtools.py @@ -720,6 +720,7 @@ class GmshTools(): self.part_obj.Shape.exportBrep(self.temp_file_geometry) def write_geo(self): + temp_dir = os.path.dirname(self.temp_file_geo) geo = open(self.temp_file_geo, "w") geo.write("// geo file for meshing with Gmsh meshing software created by FreeCAD\n") geo.write("\n") @@ -732,7 +733,7 @@ class GmshTools(): geo.write("// open brep geometry\n") # explicit use double quotes in geo file - geo.write('Merge "{}";\n'.format(self.temp_file_geometry)) + geo.write('Merge "{}";\n'.format(os.path.relpath(self.temp_file_geometry, temp_dir))) geo.write("\n") # groups @@ -879,7 +880,7 @@ class GmshTools(): geo.write("// Ignore Physical definitions and save all elements;\n") geo.write("Mesh.SaveAll = 1;\n") # explicit use double quotes in geo file - geo.write('Save "{}";\n'.format(self.temp_file_mesh)) + geo.write('Save "{}";\n'.format(os.path.relpath(self.temp_file_mesh, temp_dir))) geo.write("\n\n") # some useful information diff --git a/src/Mod/Fem/femtest/data/elmer/group_mesh.geo b/src/Mod/Fem/femtest/data/elmer/group_mesh.geo index f379e9e6ff..c20ca320ae 100644 --- a/src/Mod/Fem/femtest/data/elmer/group_mesh.geo +++ b/src/Mod/Fem/femtest/data/elmer/group_mesh.geo @@ -4,7 +4,7 @@ General.NumThreads = X; // open brep geometry -Merge "/tmp/tmp0TVZbM.brep"; +Merge "tmp0TVZbM.brep"; // group data Physical Surface("Face1") = {1}; @@ -43,7 +43,7 @@ Coherence Mesh; // Remove duplicate vertices // save // Ignore Physical definitions and save all elements; Mesh.SaveAll = 1; -Save "/tmp/tmpjVhNNb.unv"; +Save "tmpjVhNNb.unv"; // **********************************************************************