FreeCAD as pre-post processor for MBDyn

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post processor for MBDyn

Post by mfasano »

louisgag wrote: Tue Jul 28, 2020 7:55 pm @mfasano and @T-Garnier
I've tried the addon quickly, it's a nice start.
I would recommend you provide a step-by-step example.
This will allow more people to try it and give feedback or code... perhaps you'll get some important tips.
I for myself find it somewhat difficult to understand even the simplest task of creating a body.
I don't have much experience with assembly4, but probably many users don't since it's still only in the development version.
Thanks for trying it out.

Writing a tutorial is a priority. I will make that my highest priority. T-Garnier suggested this too. I have made a recent update, no new elements, just minor changes. I will update instructions in the repository's wiki.

I decided to use assembly4 as a base because there is no constraint solver, MBDyn takes care of that, and The LCSs that define the constraints make it so I can set position and orientation with a click instead of calculating and typing in several input fields.

Two things about using Assembly4 with this workbench. You need to create the bodies inside the Assembly4; I do this because I don't know if I can get properties like center of mass or moment of inertia from a part in a linked file. There is discussion about doing this in the assembly 4 thread; post 675 gives instructions to do it.
https://forum.freecadweb.org/viewtopic. ... &start=260
A popular way to use assembly 4 is to create a master sketch and place LCSs in key points, and then link LCSs of parts to the LCSs on Master sketch. I don't do this. I calculate positions and orientations relative the the node, usually at the center of mass. It is easier when the LCS is on the part. I may look in to having the calculations of position and orientations more general. I use the LCSs that are directly in the parent assembly as fixed reference frames and nodes.
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post processor for MBDyn

Post by mfasano »

I have included a tutorial in a page of the wiki.
https://github.com/mfasano727/MBDynFCwb ... m-Tutorial

I hope it is helpful.
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post processor for MBDyn

Post by mfasano »

I have made a mechanism other than a pendulum. It is a slide crank. I had to add quite a few MBDyn elements. to get it. I added commands for a clamp joint, an axial revolution joint, an in line joint, a prismatic joint and a ramp drive caller. I used the slide crank example in Sky Engineering's MBDyn tutorial. http://www.sky-engin.jp/en/MBDynTutorial/index.html. It is an extensive tutorial and there are a lot of examples on there site too. I have updated the repo. with the new commands. I will update the command instructions and maybe another tutorial soon. Here is a link to an animation of the slide crank. I have also included the FreeCAD file and the MBDyn input file.
phpBB [video]
I tried to use the total joints to make the slide crank as well as other examples, but couldn't get it to work. I am going to make getting the total joints working a priority.

I found a bug that has not been fixed in this latest update. The parts in the parts group of the assembly 4 file can't have an attachment offset other than 0 position offset and 0 angle. If it is, the node position and orientation is off.
Attachments
input_SCz.txt
(3.63 KiB) Downloaded 55 times
slide_crankZ.FCStd
(60.19 KiB) Downloaded 54 times
Last edited by Kunda1 on Wed Aug 26, 2020 11:31 pm, edited 1 time in total.
Reason: Put clip in video bbcode
louisgag
Posts: 75
Joined: Fri Jan 17, 2020 9:59 am

Re: FreeCAD as pre-post processor for MBDyn

Post by louisgag »

Your video shows nice progress. When you have it ready I'll try the new tutorial and give feedback.
  • Does your code structure allow easy addition of new joints?
  • What is the issue you're facing with the total joint?
  • Is the bug you are referring to is in the FreeCAD daily assembly4 workbench?
It's still a bit early to talk about GSoC2021, but if you want to try mentoring for MBDyn you should mention that to Andrea Zanoni, he's the most interested in a FreeCAD addon and getting on the same page before the application period can't hurt!
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post processor for MBDyn

Post by mfasano »

louisgag wrote: Thu Aug 27, 2020 6:58 am Your video shows nice progress. When you have it ready I'll try the new tutorial and give feedback.
  • Does your code structure allow easy addition of new joints?
  • What is the issue you're facing with the total joint?
  • Is the bug you are referring to is in the FreeCAD daily assembly4 workbench?
The code structure does not make it easy to add new MBDY elements. I hope to improve that. There is a lot of code that gets repeated for each joint; I will try to put them in reusable functions.

I think it is that I don't know how to implement the total joints. I am a novice at MBDyn.

The bug is not and asm4 problem; it is my code.


It's still a bit early to talk about GSoC2021, but if you want to try mentoring for MBDyn you should mention that to Andrea Zanoni, he's the most interested in a FreeCAD addon and getting on the same page before the application period can't hurt!
I will be updating Andrea on my progress soon. It has been a while. He seems more interested in using python to make it easier to write the input file than using FreeCAD. I was considering my classes inheriting his python classes, but I found it easier to write them from scratch. It is not to late to attempt that.
HaiLiExp
Posts: 4
Joined: Sun Oct 25, 2020 6:36 pm

Re: FreeCAD as pre-post processor for MBDyn

Post by HaiLiExp »

Hallo

Thank you very much first of all for your workbench, it is really helpful, I appreciate your excellent work.

I began MBDyn and FreeCAD with your tutorial file pend_part_as4.FCStd. When I do "Write MBDyn input diaglot" -> run simulation, the follow error occurs:


19:28:03 filename: Accept5 Placement [Pos=(5,5,50), Yaw-Pitch-Roll=(0,0,0)]filename: Accept2 0.02end animationSimulation Started.....
19:29:52 Filename: D:\Watch\pend\pend_hinge_input.mbd
19:29:52 write inttialwrite node euler321write node euler321row= 1, col= 1row= 1, col= 1row= 1, col= 2row= 1, col= 3row= 2, col= 1row= 2, col= 2row= 2, col= 2row= 2, col= 3row= 3, col= 1row= 3, col= 2row= 3, col= 3row= 3, col= 3row= 1, col= 1row= 1, col= 1row= 1, col= 2row= 1, col= 3row= 2, col= 1row= 2, col= 2row= 2, col= 2row= 2, col= 3row= 3, col= 1row= 3, col= 2row= 3, col= 3row= 3, col= 3MBDyn jointsMBDyn jointsStart NowTraceback (most recent call last):
19:30:02 File "D:\Watch\MBDynFreeCAD\FreeCAD_0.19.22756-Win-Conda_vc14.x-x86_64\Mod\MBDynFCwb-asm4\MBDyn_guitools\MBDynFreeCAD.py", line 153, in outputMessage
19:30:02 proc = subprocess.Popen(args)
19:30:02 File "D:\Watch\MBDynFreeCAD\FreeCAD_0.19.22756-Win-Conda_vc14.x-x86_64\bin\lib\subprocess.py", line 854, in __init__
19:30:02 self._execute_child(args, executable, preexec_fn, close_fds,
19:30:02 File "D:\Watch\MBDynFreeCAD\FreeCAD_0.19.22756-Win-Conda_vc14.x-x86_64\bin\lib\subprocess.py", line 1307, in _execute_child
19:30:03 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
19:30:03 OSError: [WinError 87] The parameter is incorrect

I use Windows10, installation of freeCAD is done by unzip "FreeCAD_0.19.22756-Win-Conda_vc14.x-x86_64.7z", and copy the folder "MBDynFCwb-asm4" into the "FreeCAD_0.19.22756-Win-Conda_vc14.x-x86_64\Mod" folder. The MBDyn is done as described in your github page "mfasano727/MBDynFCwb": "windows build of MBDyn".

I would appreciate if you could help me on this problem. Thank you very much in advance!

Best regards
Hai Li
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post processor for MBDyn

Post by mfasano »

HaiLiExp wrote: Sun Oct 25, 2020 6:51 pm 19:30:02 File "D:\Watch\MBDynFreeCAD\FreeCAD_0.19.22756-Win-Conda_vc14.x-x86_64\Mod\MBDynFCwb-asm4\MBDyn_guitools\MBDynFreeCAD.py", line 153, in outputMessage
19:30:02 proc = subprocess.Popen(args)
19:30:02 File "D:\Watch\MBDynFreeCAD\FreeCAD_0.19.22756-Win-Conda_vc14.x-x86_64\bin\lib\subprocess.py", line 854, in __init__
19:30:02 self._execute_child(args, executable, preexec_fn, close_fds,
19:30:02 File "D:\Watch\MBDynFreeCAD\FreeCAD_0.19.22756-Win-Conda_vc14.x-x86_64\bin\lib\subprocess.py", line 1307, in _execute_child
19:30:03 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
19:30:03 OSError: [WinError 87] The parameter is incorrect
It could be that your not finding the MBDyn program. With the MBDyn workbench chosen, go to the edit menu and select preferences. scroll down on the left and select the MBDyn hummingbird icon. On the right select the solver tab. Make sure the path to the MBDyn solver is to the mbdyn.exe file.

In the working directory you selected(make sure it exists) when running the MDyn solver, there should be a file called "_console.log" do you have that?
T-Garnier
Posts: 18
Joined: Sat Jun 27, 2020 5:30 am

Re: FreeCAD as pre-post processor for MBDyn

Post by T-Garnier »

Hello Hai Li,

Thanks for your feedback.

From what I understand of your problem, it occurs when you try to open the log file view log button (line 153 of the python scrit) not when you pressed the run simulation button.

Actually the log file can't be open directly in freecad. So you have to define an external application to open it.
To do so, you have to:
- Go to the preference page (Edit->preferences...->MBDyn)
- In the editor section define tha path (including the executable) to an application capable of opening a text file (notepade++, atom,...).

Personally, I use Atom. It has the advantage to highlight the mbdyn syntax (mbdyn input file) with an additional plugin.


Same problem should occurs if you try to edit an input file.

I will add a check to see if the user defined a text editor or not to avoid this behavior.

Regards,
Thomas
HaiLiExp
Posts: 4
Joined: Sun Oct 25, 2020 6:36 pm

Re: FreeCAD as pre-post processor for MBDyn

Post by HaiLiExp »

Hello mfasano

Thank you very much first of all for your help. I had configured the solver as you described and the _console.log exist. This time the content is as the following:

reading from file "D:\Watch\pend\pend_hinge_input.mbd"
warning, derivatives tolerance <= 0.0 is illegal; using default value 1e-006
Creating scalar solver with Naive linear solver
Reading Structural(1)
Reading Structural(2)
Reading Body(1)
Reading Body(2)
Reading Joint(1)
Reading Joint(2)
Reading Gravity
Initial derivatives calculation 1 does not converge; aborting...
(hint: try playing with the "derivatives coefficient" value)
An error occurred during the execution of MBDyn; aborting...

I don't have a multibody dynamics background, I was a CFD man. Could you give me some hints about this error? Thank you very much in advance!

Hello Thomas
Thank you very much for your help! I installed the atom and set the path for the editor as you described. When I run simulation, the atom appeared and showed the same content as the _console.log. This is the only change I made and the it helps to proceed and the following report shows in the "report view":

16:52:58 Filename: D:\Watch\pend\pend_hinge_input.mbd
16:52:58 write inttialwrite node euler321write node euler321row= 1, col= 1row= 1, col= 1row= 1, col= 2row= 1, col= 3row= 2, col= 1row= 2, col= 2row= 2, col= 2row= 2, col= 3row= 3, col= 1row= 3, col= 2row= 3, col= 3row= 3, col= 3row= 1, col= 1row= 1, col= 1row= 1, col= 2row= 1, col= 3row= 2, col= 1row= 2, col= 2row= 2, col= 2row= 2, col= 3row= 3, col= 1row= 3, col= 2row= 3, col= 3row= 3, col= 3MBDyn jointsMBDyn jointsSimulation Started.....
16:53:03 Filename: D:\Watch\pend\pend_hinge_input.mbd
16:53:03 write inttialwrite node euler321write node euler321row= 1, col= 1row= 1, col= 1row= 1, col= 2row= 1, col= 3row= 2, col= 1row= 2, col= 2row= 2, col= 2row= 2, col= 3row= 3, col= 1row= 3, col= 2row= 3, col= 3row= 3, col= 3row= 1, col= 1row= 1, col= 1row= 1, col= 2row= 1, col= 3row= 2, col= 1row= 2, col= 2row= 2, col= 2row= 2, col= 3row= 3, col= 1row= 3, col= 2row= 3, col= 3row= 3, col= 3MBDyn jointsMBDyn jointsStart NowLoading MBDyn Solver settings...... MBDyn Solver settings loaded.

When I click on "view status", I got the content of _console.log in atom editor. I would appreciate if you could give me some hints to proceed. Thank you very much in advance!

Best regards
Hai Li
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post processor for MBDyn

Post by mfasano »

HaiLiExp wrote: Tue Oct 27, 2020 4:10 pm Hello mfasano

Thank you very much first of all for your help. I had configured the solver as you described and the _console.log exist. This time the content is as the following:

reading from file "D:\Watch\pend\pend_hinge_input.mbd"
warning, derivatives tolerance <= 0.0 is illegal; using default value 1e-006
Creating scalar solver with Naive linear solver
Reading Structural(1)
Reading Structural(2)
Reading Body(1)
Reading Body(2)
Reading Joint(1)
Reading Joint(2)
Reading Gravity
Initial derivatives calculation 1 does not converge; aborting...
(hint: try playing with the "derivatives coefficient" value)
An error occurred during the execution of MBDyn; aborting...
I found if the initial derivative calculation does not converge, increasing the derivative tolerance helps. try a value of 0.05.
Post Reply