RunTimeError when converting CAD file into UMesh

Versions

FLUKA: 4-5.1
Flair: 3.4-5.2

Good afternoon,

I’m having trouble trying to perform CAD file conversion into an unstructured mesh by using the Python script FLUKA_mesh_fix.py. In particular, the following RunTimeError is returned (I installed Gmsh and MeshLib version 3.0.2.183):

user-be@macbe17169 geom_mesh_utils % python FLUKA_mesh_fix.py stellarator/Stellarator_Wendelstein.3mf

Reading from: stellarator/Stellarator_Wendelstein.3mf

Meshing without healing, errors to be identified…

Using OFF for meshlib conversion

Bounding box center for the full initial mesh: <meshlib.mrmeshpy.Vector3f object at 0x10ebf9a70>

Min. corner of the full initial mesh: <meshlib.mrmeshpy.Vector3f object at 0x10ebf9a70>

Max. corner of the full initial mesh: <meshlib.mrmeshpy.Vector3f object at 0x10ebf9a70>

Bounding box dimensions: <meshlib.mrmeshpy.Vector3f object at 0x10ebf9a70>

Mesh 1 has 764 nodes

Info : Reading ‘stellarator/tmp.off’…

Info : Done reading ‘stellarator/tmp.off’

Backup created at mesh_log.txt_20251126_161520.bkp

Reading from: stellarator/Stellarator_Wendelstein.3mf

Meshing without healing, errors to be identified…

Using OFF for meshlib conversion

Bounding box center for the full initial mesh: <meshlib.mrmeshpy.Vector3f object at 0x117e3fc70>

Min. corner of the full initial mesh: <meshlib.mrmeshpy.Vector3f object at 0x117e3fc70>

Max. corner of the full initial mesh: <meshlib.mrmeshpy.Vector3f object at 0x117e3fc70>

Bounding box dimensions: <meshlib.mrmeshpy.Vector3f object at 0x117e3fc70>

Mesh 1 has 764 nodes

Info : Reading ‘stellarator/tmp.off’…

Info : Done reading ‘stellarator/tmp.off’

Traceback (most recent call last):

File “”, line 1, in

from multiprocessing.spawn import spawn_main; spawn_main**(tracker_fd=8, pipe_handle=19)**

~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/spawn.py”, line 122, in spawn_main

exitcode = _main(fd, parent_sentinel)

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/spawn.py”, line 131, in _main

prepare**(preparation_data)**

~~~~~~~^^^^^^^^^^^^^^^^^^

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/spawn.py”, line 246, in prepare

_fixup_main_from_path**(data[‘init_main_from_path’])**

~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/spawn.py”, line 297, in _fixup_main_from_path

main_content = runpy.run_path(main_path,

run_name=“_mp_main_”)

File “”, line 287, in run_path

File “”, line 98, in _run_module_code

File “”, line 88, in _run_code

File “/Users/user-be/Downloads/input/geom_mesh_utils/FLUKA_mesh_fix.py”, line 516, in

file_path=process_meshes_with_error_handling(args)

File “/Users/user-be/Downloads/input/geom_mesh_utils/FLUKA_mesh_fix.py”, line 446, in process_meshes_with_error_handling

to_heal = detect_mesh_errors(to_heal)

File “/Users/user-be/Downloads/input/geom_mesh_utils/FLUKA_mesh_fix.py”, line 266, in detect_mesh_errors

with multiprocessing.Pool**(processes=1)** as pool:

~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/context.py”, line 119, in Pool

return Pool(processes, initializer, initargs, maxtasksperchild,

context=self.get_context())

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/pool.py”, line 215, in _init_

self._repopulate_pool**()**

~~~~~~~~~~~~~~~~~~~~~^^

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/pool.py”, line 306, in _repopulate_pool

return self._repopulate_pool_static**(self._ctx, self.Process,**

~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^

self._processes,

^^^^^^^^^^^^^^^^

…<3 lines>…

self._maxtasksperchild,

^^^^^^^^^^^^^^^^^^^^^^^

self._wrap_exception)

^^^^^^^^^^^^^^^^^^^^^

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/pool.py”, line 329, in _repopulate_pool_static

w.start**()**

~~~~~~~^^

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/process.py”, line 121, in start

self._popen = self._Popen**(self)**

~~~~~~~~~~~^^^^^^

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/context.py”, line 289, in _Popen

return Popen(process_obj)

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/popen_spawn_posix.py”, line 32, in _init_

super()._init_(process_obj)

~~~~~~~~~~~~~~~~^^^^^^^^^^^^^

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/popen_fork.py”, line 20, in _init_

self._launch**(process_obj)**

~~~~~~~~~~~~^^^^^^^^^^^^^

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/popen_spawn_posix.py”, line 42, in _launch

prep_data = spawn.get_preparation_data(process_obj._name)

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/spawn.py”, line 164, in get_preparation_data

_check_not_importing_main**()**

~~~~~~~~~~~~~~~~~~~~~~~~~^^

File “/opt/local/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/spawn.py”, line 140, in _check_not_importing_main

raise RuntimeError(‘’’

…<16 lines>…

‘’')

RuntimeError:

An attempt has been made to start a new process before the

current process has finished its bootstrapping phase.

This probably means that you are not using fork to start your

child processes and you have forgotten to use the proper idiom

in the main module:

if _name_ == ‘_main_’:

freeze_support()

The “freeze_support()” line can be omitted if the program

is not going to be frozen to produce an executable.

To fix this issue, refer to the “Safe importing of main module”

section in https://docs.python.org/3/library/multiprocessing.htmlInput files

Do you have any suggestion to fix it?

Thank you in advance

FLUKA_mesh_fix.py (17.6 KB)

Hi Lorenzo,

Yes, this issue is fixable, and it was identified recently on macOS.
On this OS, Python multiprocessing and system sed work slightly differently from Linux.

I am attaching a dev version of the script that fixes this issue and provides other useful improvements.

FLUKA_mesh_fix.py (22.1 KB)

Please let me know if it solves the issue.
Volodymyr

1 Like

Hi Volodymyr,

thank you a lot for the script, it seems to work properly: I tried to use it to mesh the Stellarator-Weldenstein geometry and it worked.

It seemed to be working also in the case of the complex geometry (HiRadMat irradiation facility) I’m trying to model, but several hours after I launched the script, at the end of the meshing process, it returned me this error:

(…)

Info : It. 182000 - 60245 nodes created - worst tet radius 1.00406 (nodes removed 504 121251)

Info : It. 182500 - 60575 nodes created - worst tet radius 1.77902 (nodes removed 504 121421)

Info : It. 183000 - 60601 nodes created - worst tet radius 1.34393 (nodes removed 506 121893)

Info : It. 183500 - 60839 nodes created - worst tet radius 1.47814 (nodes removed 507 122154)

Info : 3D refinement terminated (58524226 nodes total):

Info : - 23474 Delaunay cavities modified for star shapeness

Info : - 122715 nodes could not be inserted

Info : - 594754 tetrahedra created in 6.34951 sec. (93669 tets/s)

Info : 33845 node relocations

Info : Tetrahedrizing 70767 nodes…

Info : Done tetrahedrizing 70775 nodes (Wall 0.973558s, CPU 0.960222s)

Info : Reconstructing mesh…

Info : - Creating surface mesh

Info : Found two nearly self-intersecting facets (dihedral angle 5.39369E-06).

Info : 1st: [26163, 26162, 26156] #587

Info : 2nd: [26163, 26162, 26164] #587

Info : The dihedral angle between them is 0.000309035 degree.

Info : Hint: You may use Mesh.AngleToleranceFacetOverlap to decrease the dihedral angle tolerance 0.05 (degree)

Error : Invalid boundary mesh (overlapping facets) on surface 587 surface 587

Traceback (most recent call last):

File “/Users/user-be/cernbox/UMesh_HRM/FLUKA_mesh_fix_MOS.py”, line 655, in

main**()**

\~\~\~\~**^^**

File “/Users/user-be/cernbox/UMesh_HRM/FLUKA_mesh_fix_MOS.py”, line 601, in main

file_path=process_meshes_with_error_handling(args)

File “/Users/user-be/cernbox/UMesh_HRM/FLUKA_mesh_fix_MOS.py”, line 527, in process_meshes_with_error_handling

output_file=heal_and_remesh_meshes(to_heal)

File “/Users/user-be/cernbox/UMesh_HRM/FLUKA_mesh_fix_MOS.py”, line 508, in heal_and_remesh_meshes

finalize_and_write**(args,out_name, output_file,kernel = "geo")**

\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~**^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^**

File “/Users/user-be/cernbox/UMesh_HRM/FLUKA_mesh_fix_MOS.py”, line 334, in finalize_and_write

gmsh.model.mesh.generate**(3)**

\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~**^^^**

File “/Users/user-be/Library/Python/3.13/lib/python/site-packages/gmsh.py”, line 2189, in generate

raise Exception(logger.getLastError())

Exception: Invalid boundary mesh (overlapping facets) on surface 587 surface 587

As I understand it may be a problem of CAD geometry, do you have any tips to fix it?

I’d be particularly interested in modeling just few parts of the model, e.g. the dump parts.

Thank you in advance for the kind attention.

Hi Lorenzo,

Glad to hear that it fixed the issue with the meshing of the hands-on example.

Could you please share your CAD geometry (privately)? I can’t say anything without seeing it.

In general, from my experience, full-scale facilities contain a plethora of errors which may cause meshing issues.

Best regards,
Volodymyr