FreeCAD as pre-post procesor for MBDyn

About the development of the FEM module/workbench.

Moderator: bernd

vocx
Posts: 1727
Joined: Thu Oct 18, 2018 9:18 pm

Re: FreeCAD as pre-post procesor for MBDyn

Postby vocx » Wed Sep 11, 2019 4:22 pm

mfasano wrote:
Wed Sep 11, 2019 1:39 pm
From the video it looks like you open shell and run a command.
Maybe that was a prototype. I presume jose is planning on setting this up from a single button press, just like the FEM Workbench does.

In any case, yes, Python can run arbitrary programs. The very old way of doing it, is using

Code: Select all

os.system("mbdyn -options input.file")
But the recommended way nowadays is with the subprocess module.

Code: Select all

import subprocess
subprocess.run(["mbdyn", "-options", "input.file"], capture_output=True)
User avatar
bernd
Posts: 8442
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: FreeCAD as pre-post procesor for MBDyn

Postby bernd » Wed Sep 11, 2019 5:48 pm

subprocess is what FEM uses
josegegas
Posts: 39
Joined: Sat Feb 11, 2017 12:54 am
Location: New Zealand

Re: FreeCAD as pre-post procesor for MBDyn

Postby josegegas » Wed Sep 11, 2019 8:53 pm

mfasano wrote:
Wed Sep 11, 2019 1:39 pm
josegegas wrote:
Wed Sep 11, 2019 12:45 pm
mfasano wrote:
Wed Sep 11, 2019 12:36 pm
MBDyn needs to be run from a terminal. Is there a way to run a shell script from python?
Yep. I've don this. So that MBDyn can be executed from FreeCAD with a click...
From the video it looks like you open shell and run a command.
Yes, old video... Just programed this. What I still don't know how to do is to show the messages from MBDyn into FreeCAD. I mean, to take the messages MBDyn generates in the shell and show them somewhere in the FreeCAD gui. Any Idea?
vocx
Posts: 1727
Joined: Thu Oct 18, 2018 9:18 pm

Re: FreeCAD as pre-post procesor for MBDyn

Postby vocx » Thu Sep 12, 2019 12:23 am

josegegas wrote:
Wed Sep 11, 2019 8:53 pm
... I mean, to take the messages MBDyn generates in the shell and show them somewhere in the FreeCAD gui. Any Idea?
With subprocess you capture the output of your command.

Code: Select all

out = subprocess.run(["ls", "-l", "/usr/share/freecad"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf8")
print(out.stdout)
It seems FEM uses Popen(). https://github.com/berndhahnebach/FreeC ... ks.py#L105

This is the internal class, while the high level functions are run() (for Python 3.5 and above), or the older call(), check_call(), and check_output() (for Python 3.4 and below).

Code: Select all

process = subprocess.Popen(["ls", "-l", "/usr/share/freecad"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf8")
out, err = process.communicate()
print(out)
print(err)
The standard output or standard error then can be printed in the terminal, the FreeCAD console, or used in some Qt dialogs.
User avatar
bernd
Posts: 8442
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: FreeCAD as pre-post procesor for MBDyn

Postby bernd » Fri Sep 13, 2019 4:18 am

Creat work. He could have saved himself work if he would not have done it from scratch but would have used some existant code from FEM instead.
vocx
Posts: 1727
Joined: Thu Oct 18, 2018 9:18 pm

Re: FreeCAD as pre-post procesor for MBDyn

Postby vocx » Fri Sep 13, 2019 5:34 am

bernd wrote:
Fri Sep 13, 2019 4:18 am
Creat work. He could have saved himself work if he would not have done it from scratch but would have used some existant code from FEM instead.
mfasano already knew about that GSoC project.
mfasano wrote:
Tue Sep 10, 2019 1:58 pm
We are not the first to consider using FreeCAD as a pre and post processor for MBDyn. The progrmmers of MBDyn thought of making it a Google Summer of Code project. I guess that never happened. Maybe if we make a good start of it, we could make extending it a Summer of Code project.
But neither that (proposal barely two weeks ago), nor the ones described in this thread are anywhere close to be completed. So there is still time to test and discuss if a particular implementation makes sense.

The way mfasano and josegegas describe the MBDyn solver (input file and command line execution), I feel it could be integrated very well into the FEM Workbench.
User avatar
bernd
Posts: 8442
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: FreeCAD as pre-post procesor for MBDyn

Postby bernd » Fri Sep 13, 2019 6:32 am

vocx wrote:
Fri Sep 13, 2019 5:34 am
The way mfasano and josegegas describe the MBDyn solver (input file and command line execution), I feel it could be integrated very well into the FEM Workbench.
+1 if any help is needed all FEM developers are happy to answer any questions in this regard
User avatar
bernd
Posts: 8442
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: FreeCAD as pre-post procesor for MBDyn

Postby bernd » Fri Sep 13, 2019 6:35 am

User avatar
saso
Posts: 1333
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: FreeCAD as pre-post procesor for MBDyn

Postby saso » Fri Sep 13, 2019 7:09 am

vocx wrote:
Fri Sep 13, 2019 5:34 am
The way mfasano and josegegas describe the MBDyn solver (input file and command line execution), I feel it could be integrated very well into the FEM Workbench.
IMO it should be implemented as an add-on, the GPL license does not allow to distribute it directly with FreeCAD, as of now it is available only for linux and even if the implementation can be done similar to existing FEM solvers, this is not FEM.