I'm trying to automate running various CFD runs where for each run a part in my assembly is moved slightly and remeshing is performed before running the simulation to get various parameter results. This is to characterise performance as the part moves and with various boundary conditions.
I have basically achieved this by recording macros and then using them as a guide to write the macro and it is simple to do, for the most part.
I can automate almost everything using the macros (python scripts) , including setting up the mesh file but when the "Run mesher" button is clicked nothing is recorded into the macros or the python console. I can see in the Workbench code that there are python methods to start the meshing and send the command to the OpenFOAM environment but I am not sure how to get access to the objects that have these methods from within a macro.
I presume the same will be true of running the solver too once the mesh is completed so will need to be able to call the solver too and also hopefully then call Paraview, without displaying, to analyse and extract the result values I require.
I understand that manual checking of the mesh produced is necessary in the first instance but I am assuming that once I have a working setup I should be able to automate the process.
Is there any way to do this?
Running mesher or solver from within macro?
Moderator: oliveroxtoby
Forum rules
and Helpful information for the FEM forum
and Helpful information for the FEM forum
Re: Running mesher or solver from within macro?
OK,
In case it helps others, I have managed to call the mesher from a macro by copying some code from TestCfd.py. I am not sure if this is right or robust but it seems to work.
I presume I can use the same method, with some more digging around in the test code, to call the solver. Then I have to work out how to call Paraview without a display and do the analysis I need.
It would also be nice to be able to call checkMesh and save or parse the results for serious errors that may creep in when the parts of my assembly are moved between runs.
In case it helps others, I have managed to call the mesher from a macro by copying some code from TestCfd.py. I am not sure if this is right or robust but it seems to work.
Code: Select all
doc = FreeCAD.ActiveDocument
obj = doc.getObject("<name_of_mesh>")
vobj = obj.ViewObject
import _TaskPanelCfdMesh
taskd = _TaskPanelCfdMesh._TaskPanelCfdMesh(obj)
taskd.obj = vobj.Object
taskd.runMesh()
taskd.mesh_process.waitForFinished()
It would also be nice to be able to call checkMesh and save or parse the results for serious errors that may creep in when the parts of my assembly are moved between runs.
- oliveroxtoby
- Posts: 812
- Joined: Fri Dec 23, 2016 9:43 am
- Location: South Africa
Re: Running mesher or solver from within macro?
The idea was to use the scripting to write a batch of cases that can then later be run in batch with a shell script, or submitted to a cluster, etc. But the method above looks fine.Geefer wrote: ↑Sat Feb 27, 2021 12:09 pm OK,
In case it helps others, I have managed to call the mesher from a macro by copying some code from TestCfd.py. I am not sure if this is right or robust but it seems to work.
I presume I can use the same method, with some more digging around in the test code, to call the solver. Then I have to work out how to call Paraview without a display and do the analysis I need.Code: Select all
doc = FreeCAD.ActiveDocument obj = doc.getObject("<name_of_mesh>") vobj = obj.ViewObject import _TaskPanelCfdMesh taskd = _TaskPanelCfdMesh._TaskPanelCfdMesh(obj) taskd.obj = vobj.Object taskd.runMesh() taskd.mesh_process.waitForFinished()
It would also be nice to be able to call checkMesh and save or parse the results for serious errors that may creep in when the parts of my assembly are moved between runs.
Re: Running mesher or solver from within macro?
Thanks, I had not thought about preparing all the cases upfront then running them independently of the FreeCAD environment as a batch Linux process (I've not yet run OpenFOAM except via the CfdOf GUI). That actually seems like a good idea as it also forces me to explicitly control the directories in which each case are written. I've been lazy so far so each run overwrites the previous one but then I'm just hacking a script together at the moment and will refine it later.oliveroxtoby wrote: ↑Sat Feb 27, 2021 1:16 pm The idea was to use the scripting to write a batch of cases that can then later be run in batch with a shell script, or submitted to a cluster, etc. But the method above looks fine.
However I must create the mesh object before creating the solver case which complicates things. For now I will probably continue on as I have and refine the process along the lines you mentioned at some point in the future.
- oliveroxtoby
- Posts: 812
- Joined: Fri Dec 23, 2016 9:43 am
- Location: South Africa
Re: Running mesher or solver from within macro?
Just to mention that both the mesh and solver cases can be written (and run later) without it being necesary to actually generate the mesh in between.
Re: Running mesher or solver from within macro?
Thanks. My mistake. I tried deleting the mesh object in the GUI then tried to write the solver case which is what doesn't work. So indeed it is possible to write all the mesh cases and solver cases in one go then run them later as you suggested. Next job is to work out how to write a Paraview script to do the analysis I need and call it from the macro (as a first step) then later as a batch process with all the other cases.oliveroxtoby wrote: ↑Sat Feb 27, 2021 7:09 pm Just to mention that both the mesh and solver cases can be written (and run later) without it being necesary to actually generate the mesh in between.
Thanks for your help.