Run external scripts from FC - a workaround

About the development of the FEM module/workbench.

Moderator: bernd

Post Reply
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Run external scripts from FC - a workaround

Post by HoWil »

The creation of multidomain-meshes did dramatically evolve enabling supportive/external FEM-studies for instance in Elmer (as a workaround until it is integrated).
I want simply put the things together that are on the table:
* I generate my geometry in FC and export the mesh as .unv
* ElmerGrid has to be run to transfer the mesh for ElmerSolver to run this mesh together with an externally created solver-input file to compute results
* these results can be evaluated in Paraview give some result value which should be collected.

To cut a long story short, I want to run external scripts like ElmerGrid, ElmerSolver and Paraview from inside FC. I thought about using a macro/py-script or a input field where a external (bash) script can be specified.

Die anyone use something similar? Is there a better way to achieve this?
BR,
HoWil
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Run external scripts from FC - a workaround

Post by yorik »

It is not hard to achieve, python has a lot of tools to run external scripts/programs, and even collect their answer. Have a look at python's subprocess module, it's basically what you'll need.
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Run external scripts from FC - a workaround

Post by ulrich1a »

HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Run external scripts from FC - a workaround

Post by HoWil »

ulrich1a wrote:Here is an example: viewtopic.php?f=18&t=10789&start=20#p113297
Ulrich
Thanks Ulrich, This is exactly what I was looking for to begin with.

EDIT:
first steps are stony... 8-)

Code: Select all

selection = FreeCADGui.Selection.getSelection()
was in 0.17 changed?! to

Code: Select all

selection = FreeCADGui.Selection.getSelectionEx()
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Run external scripts from FC - a workaround

Post by ulrich1a »

Both function did exist before. The one gets selected objects from the tree, the other from the 3D-view.

Yes the first steps are not fast. I also need time to explore for me unknow functionality. The documentation needs more love.

Ulrich
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Run external scripts from FC - a workaround

Post by bernd »

more examples:

See FreeCAD FEMs GMSH module class: https://github.com/berndhahnebach/FreeC ... ls.py#L369

or the old GMSH macro the GMSH module class is based on:
Macro_GMSH and https://github.com/psicofil/Macros_Free ... Macro#L208

The CalculiX run uses subprocess too.
see https://github.com/berndhahnebach/FreeC ... cx.py#L196
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Run external scripts from FC - a workaround

Post by HoWil »

Thanks Ulrich and Bernd.

I have a preliminary working version 8-) .

I started with Ulrich's example viewtopic.php?f=18&t=10789&start=20#p113297 and created a first script which takes a Gmesh-Mesh as input, exports it as .unv and runs ElmerGrid, ElmerSolver and Paraview (optional).

For ElmerSolver is a .sif file and for Paraview a .vtk file via two separate dialogs requested.
EDIT:
The .sif file has to be created separately and uses in the attached example the labels from within FC.

The first rough version looks like:
FC_mesh_export_Elmer_Paraview_v0p4.FCMacro.py
(6.25 KiB) Downloaded 81 times
The example according to the 3D-calculix-beam with gmsh-mesh is attached with rough mesh :!: :
FC_external_Elmer_start.zip
complete project including the mod FC file (gmsh-mesh, with meshregion), the unv, the elmer data, and the vtk result files.
(465.09 KiB) Downloaded 57 times
The script was created for/tested with (The new mesh-type 'Fem::FemMeshObjectPython' is needed):
OS: Ubuntu 16.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.9481 (Git)
Build type: Unknown
Branch: femdev
Hash: c6ca36b29f19815e78bc2d4b4b02e86679d4fbc6
Python version: 2.7.12
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.0.0
Post Reply