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 procesor for MBDyn

Post by mfasano »

Here is a test model and resulting input file. It is a double pendulum . I didn't bother to change the units; I guess MBDyn uses SI units, FreeCAD uses mm for length.
Attachments
test_MBDyn.FCStd
(9.86 KiB) Downloaded 58 times
input.txt
(1.79 KiB) Downloaded 75 times
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: FreeCAD as pre-post procesor for MBDyn

Post by vocx »

mfasano wrote: Wed Mar 25, 2020 9:38 am ...
Here is the code.
https://github.com/mfasano727/MBDynFCwb
Would it be possible to structure the code how the current Draft Workbench does it?

I think many workbenches just throw their files in the root directory and this is very messy. Also many combine graphical code with generic non-GUI code. For maximum flexibility, it's best to keep them separate.

For example, the basic structure that I suggest is the following.

Code: Select all

MBDynFC/
    InitGui.py
    mbdyn_objects/
    mbdyn_guitools/
    mbdyn_utilities/
All scripted objects files would be inside the objects/ folder, while Gui Commands, that is, button and menu commands, would be in the guitools/ folder, and any other supporting code that is for auxiliary things could be in its utilities/ folder.

The problem with putting everything in the root directory is that it's messy, and moreover it is in a general namespace. If another module has the same module names, they may clash. Placing the modules inside subdirectories helps a lot with this issue, you just need to modify the imports.

Code: Select all

import mbdyn_guitoos.ref_cmd
By the way, I dislike completely that you add the generated code from the .ui files. The .ui files can be imported directly, so that you don't have to manually craft the interface.

See how Draft makes it. See the code of draftguitools/gui_polararray.py, which internally calls drafttaskpanels/task_polararray.py, which is the one importing the appropriate .ui file.

Also, you could take it even further and already prepare the workbench as a "namespace workbench". This is a new style of writing workbenches. See https://github.com/FreeCAD/freecad.workbench_starterkit

Basically, the entire structure is inside a freecad folder.

Code: Select all

freecad/
    mbdynfc/
        init_gui.py
        mbdyn_objects/
        mbdyn_guitools/
        mbdyn_utilities/
Last edited by vocx on Wed Mar 25, 2020 9:43 pm, edited 1 time in total.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post procesor for MBDyn

Post by mfasano »

I will restructure my code. I will not be using the namespace workbench at this time.

Thanks vocx.
vocx wrote: Wed Mar 25, 2020 7:03 pm
Would it be possible to structure the code how the current Draft Workbench does it?

I think many workbenches just throw their files in the root directory and this is very messy. Also many combine graphical code with generic non-GUI code. For maximum flexibility, it's best to keep them separate.

For example, the basic structure that I suggest is the following.

Code: Select all

MBDynFC/
    InitGui.py
    mbdyn_objects/
    mbdyn_guitools/
    mbdyn_utilities/
louisgag
Posts: 75
Joined: Fri Jan 17, 2020 9:59 am

Re: FreeCAD as pre-post procesor for MBDyn

Post by louisgag »

Thanks for sharing your code.
I loaded the workbench but could not do much as the dialogs don't seem to do anything when I press "ok".
I'm on Linux, FreeCAD 18.4
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post procesor for MBDyn

Post by mfasano »

I am in the process of writing instructions in the wiki of repository. I am a windows user, and I am using version 19. I don't know if that is the problem. You need to start with the IVP command and set initial values. when you click ok there it creates an initial values object as well as a few folders for other objects. You can see them in the tree view.

I reached out to Andrea Zanoni. I have not heard from him, but it was only yesterday. Do you have a GSOC student yet?
louisgag wrote: Thu Mar 26, 2020 8:13 am Thanks for sharing your code.
I loaded the workbench but could not do much as the dialogs don't seem to do anything when I press "ok".
I'm on Linux, FreeCAD 18.4
louisgag
Posts: 75
Joined: Fri Jan 17, 2020 9:59 am

Re: FreeCAD as pre-post procesor for MBDyn

Post by louisgag »

We have potential students, yes, but sometimes projects can be divided in more parts.
Are you asking because you are interested?
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post procesor for MBDyn

Post by mfasano »

I am interested in helping out. I don't care if you use any of my code. I think Jose is further a long anyway. I was just experimenting with storing the MBDyn inputs in scripted objects. I'm wondering if a spread sheet may be a better way to store the data. Another way is write code that reads the input file, and then you can make changes if you like.
louisgag wrote: Thu Mar 26, 2020 2:55 pm We have potential students, yes, but sometimes projects can be divided in more parts.
Are you asking because you are interested?
louisgag
Posts: 75
Joined: Fri Jan 17, 2020 9:59 am

Re: FreeCAD as pre-post procesor for MBDyn

Post by louisgag »

Ok that's nice of you. Just make sure Zanoni is in the loop, otherwise you risk going on a tangent that he doesn't approve of and, as is often the case with open-source software, end up developing you own code which has nothing to do with the original one anymore. I told him you go in touch with him but he said me he didn't hear from any Fasano, did I get your name right?

I've tried your version of the wqorkbench again, something works indeed (interestingly not with 0.19, that gives a segmentation fault).

What I did notice by browsing your code is that you probably forked the master branch of the MBDynFreeCADGUI Gitlab, but most of what was done in the GSoC project is in the other branches. I thkink you lost a lot of already done work that way. Have a look at this branch for example: https://gitlab.com/zanoni-mbdyn/mbdynfr ... odel-class
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post procesor for MBDyn

Post by mfasano »

louisgag wrote: Thu Mar 26, 2020 7:01 pm Ok that's nice of you. Just make sure Zanoni is in the loop, otherwise you risk going on a tangent that he doesn't approve of and, as is often the case with open-source software, end up developing you own code which has nothing to do with the original one anymore. I told him you go in touch with him but he said me he didn't hear from any Fasano, did I get your name right?

I've tried your version of the wqorkbench again, something works indeed (interestingly not with 0.19, that gives a segmentation fault).

What I did notice by browsing your code is that you probably forked the master branch of the MBDynFreeCADGUI Gitlab, but most of what was done in the GSoC project is in the other branches. I thkink you lost a lot of already done work that way. Have a look at this branch for example: https://gitlab.com/zanoni-mbdyn/mbdynfr ... odel-class
I will rewrite Zanoni. I will CC you.

I do not know why the code will not work. I do not have access to linux machine. I will try it on a Mac soon.

I pieced together code from all the branches in the your link to get close to a complete workbench the bulk of the code was in one newer file MBDynModel.py. I only used part of that file; it is in the file model_so.py in my code.

I have updated the code per vocx as well as fixed spelling errors in the dialogs. The biggest change was to make so only the fields in the orientation matrix input that are needed given the orientation matrix type are visible. I will continue with writing instructions.
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post procesor for MBDyn

Post by mfasano »

@louisgag;

I emailed Zanoni using the address he has on his profile I got by selecting his name in the team list in the MBDyn web site. I did not include you.
Post Reply