Hi all,
A quick introduction first. FreeCAD has an FEM module that implement two different meshers : GMSH and Netgen. Unfortunately, refinement and parameters tuning for Netgen cannot be done directly from FreeCAD’s UI (nor python commands as it uses a pre-compiled version). As I want to perform my meshing using Netgen, I implemented a python script to perform meshing using Netgen’s python functions, linked to a FreeCAD file.
This is a pretty straightforward process and the only functions I use from netgen are:
geo = OCCGeometry(stp_file)
param = MeshingParameters(...params...)
geo.GenerateMesh(param)
And this works great ! I can control my Netgen parameters and apply refinement wherever I think relevant.
Unfortunately, once this work done, I try to merge it with my Fem scripts. There seems to be a conflict between Netgen and FreeCAD’s Fem
module. During import, depending on which module I import first, the following errors are triggered :
Traceback (most recent call last):
File "c:/Users/username/AppData/Roaming/FreeCAD/Macro/meshing_trials.py", line 120, in <module>
import netgen
File "C:\Users\username\AppData\Local\Programs\FreeCAD 0.21\bin\lib\site-packages\netgen\__init__.py", line 44, in <module>
from . import libngpy
ImportError: DLL load failed while importing libngpy: The specified procedure could not be found.
or
Traceback (most recent call last):
File "c:/Users/username/AppData/Roaming/FreeCAD/Macro/meshing_trials.py", line 11, in <module>
import Fem
ImportError: DLL load failed while importing Fem: The specified procedure could not be found.
To execute python code, FreeCAD uses python 3.8.17. I created a venv in VSC that takes FreeCAD’s python executable to run scripts. Both individual scripts run perfectly in said venv, but when I add the missing import, both then fail with the errors here-above.
Therefore here are my questions :
- What is the python version that netgen uses ? Could it be that this is an issue ? Maybe I should install the same netgen version as FreeCAD is using (I don’t see how this could cause conflicts as FreeCAD uses a pre-compiled version as said).
- Is there anywhere I could retrieve only the functions/class I need ? Maybe by getting a narrowed-down version of netgen I could get this to work.
- Any other idea on how to solve this compatibility issue ?
As both modules work perfectly individually, i’ve excluded the possibility of missing dependencies, but maybe I am wrong ?
Even if you don’t have a hands-in complete solution, any potential hint on how to solve this would already be of great help! I cannot seem to find any similar cases on FreeCAD’s forum…
EDIT: Maybe running a precompiled version of netgen through the subprocess
module could be a solution ? I am very new at building from source. Is there a way to create an executable that’d take as arguments a step file and a meshing_parameters.txt
file (which would include the path to the mesh refinement file, as currently done in python) ?
Thanks a lot !