-
Notifications
You must be signed in to change notification settings - Fork 12
Description
With #96 we moved from STEP file to BREP file as the file type used when transferring between cadquery and gmsh
Note that if the method is set to memory then the geometry is transferred in memory and not written to file, so this improvement would not impact everyone.
However when using the method=file then we make use of BREP files currently.
We could use binary brep files as mentioned by @adam-urbanczyk in this comment
Writing a small script to check that binary BREP files can be written in cadquery and read again in GMSH shows that both packages support binary BREPS and some timing improvements (binary brep is even quicker than brep).
This script is a minimal example of the 3 file formats
import gmsh
import cadquery as cq
import time
inner_box = cq.Workplane('XZ', origin=(0,0,0)).box(10, 10, 10)
outer_box = cq.Workplane('XZ', origin=(0,0,0)).box(20, 30, 11)
outer_box = outer_box.cut(inner_box)
faces_on_z_axis=outer_box.faces(cq.PerpendicularDirSelector(cq.Vector(0, 0, 1)))
assembly = cq.Assembly()
assembly.add(outer_box, name='outer_box')
assembly.add(inner_box)
start_time = time.time()
assembly.toCompound().exportBrep('boxes.brep')
print(f"Exporting brep took {time.time() - start_time:.7f} seconds")
start_time = time.time()
assembly.toCompound().exportBin('boxes_binary.brep')
print(f"Exporting binary brep took {time.time() - start_time:.7f} seconds")
start_time = time.time()
assembly.toCompound().exportStep('boxes.step')
print(f"Exporting step took {time.time() - start_time:.7f} seconds\n")
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 0)
start_time = time.time()
gmsh.model.occ.importShapes('boxes.brep')
print(f"Importing brep took {time.time() - start_time:.7f} seconds")
start_time = time.time()
gmsh.model.occ.importShapes('boxes_binary.brep')
print(f"Importing binary brep took {time.time() - start_time:.7f} seconds")
start_time = time.time()
gmsh.model.occ.importShapes('boxes.step')
print(f"Importing step took {time.time() - start_time:.7f} seconds")
gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(3)
gmsh.write('mesh_conformal.msh')
gmsh.finalize()The script prints out the following info which suggests binary brep is certainly faster for reading and writing (at least for this small geometry)
Exporting brep took 0.0003960 seconds
Exporting binary brep took 0.0001407 seconds
Exporting step took 0.0045393 seconds
Importing brep took 0.0003877 seconds
File was not written with this version of the topology
Importing binary brep took 0.0000224 seconds
Importing step took 0.0081987 secondsGMSH prints out this message when opening the binaray brep file, which I should investigate further
File was not written with this version of the topology
Apart from this I think it is worth trying to switch to binary breps after the next cadquery release.