Add General.NumThreads = CPU core count setting to Gmsh

settings file to enable multi-threaded meshing (much faster
for larger models)
This commit is contained in:
Anders Torger
2022-02-14 21:49:31 +01:00
committed by Uwe
parent 7720c3ab07
commit 7d628a6e03
3 changed files with 16 additions and 2 deletions

View File

@@ -733,6 +733,13 @@ class GmshTools():
geo = open(self.temp_file_geo, "w")
geo.write("// geo file for meshing with Gmsh meshing software created by FreeCAD\n")
geo.write("\n")
cpu_count = os.cpu_count()
if cpu_count != None and cpu_count > 1:
geo.write("// enable multi-core processing\n")
geo.write(f"General.NumThreads = {cpu_count};\n")
geo.write("\n")
geo.write("// open brep geometry\n")
# explicit use double quotes in geo file
geo.write('Merge "{}";\n'.format(self.temp_file_geometry))

View File

@@ -228,17 +228,21 @@ def compare_files(
file1 = open(file_name1, "r")
f1 = file1.readlines()
file1.close()
# TODO: add support for variable values in the reference file
# instead of using this workaround
# workaround to compare geos of elmer test and temporary file path
# (not only names change, path changes with operating system)
lf1 = [l for l in f1 if not (
l.startswith('Merge "') or l.startswith('Save "') or l.startswith("// ")
l.startswith('Merge "') or l.startswith('Save "') or l.startswith("// ") or l.startswith("General.NumThreads")
)]
lf1 = force_unix_line_ends(lf1)
file2 = open(file_name2, "r")
f2 = file2.readlines()
file2.close()
lf2 = [l for l in f2 if not (
l.startswith('Merge "') or l.startswith('Save "') or l.startswith("// ")
l.startswith('Merge "') or l.startswith('Save "') or l.startswith("// ") or l.startswith("General.NumThreads")
)]
lf2 = force_unix_line_ends(lf2)
import difflib

View File

@@ -1,5 +1,8 @@
// geo file for meshing with Gmsh meshing software created by FreeCAD
// enable multi-core processing
General.NumThreads = X;
// open brep geometry
Merge "/tmp/tmp0TVZbM.brep";