FreeCAD as pre-post processor for MBDyn
Moderator: bernd
Forum rules
and Helpful information for the FEM forum
and Helpful information for the FEM forum
Re: FreeCAD as pre-post procesor for MBDyn
Made some more progress today... fixing errors in the code, a bit more complicated simulations start to be really fun:
Last edited by Kunda1 on Tue Nov 12, 2019 8:58 am, edited 2 times in total.
Reason: added video tags
Reason: added video tags
- microelly2
- Veteran
- Posts: 4688
- Joined: Tue Nov 12, 2013 4:06 pm
- Contact:
Re: FreeCAD as pre-post procesor for MBDyn
Wow. nice to see this interface.
Re: FreeCAD as pre-post procesor for MBDyn
You still haven't made this public, right?josegegas wrote: ↑Tue Nov 12, 2019 5:17 am Made some more progress today... fixing errors in the code, a bit more complicated simulations start to be really fun:
https://www.youtube.com/watch?v=YyUkuVBGgyU&t=315s
My advice is to use dedicated icons for your scripted objects (those that appear on the tree view). This makes the workbench look more professional, because it doesn't use the plain "cube" icon from the Part Workbench. It also prevents confusion, as some of your objects may only work with your particular workbench.
When you create your scripted object, you can assign a "view provider" to define visual properties, including the icon.
Code: Select all
obj = App.ActiveDocument.addObject("Part::FeaturePython", "MBDsolid")
MBDObject(obj) # Class that sets ups the general properties of the scripted object
MBDViewProvider(obj.ViewObject) # Class that sets up the visual properties
class MBDViewProvider:
def __init__(self, vobj):
vobj.Proxy = self
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def execute(self, vobj):
return
def getIcon(self):
return os.path.join(os.path.dirname(__file__), "icons", "MDBobject.svg")
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.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: FreeCAD as pre-post procesor for MBDyn
No, not public yet. I'll make it public once it is more usable. I'm still catching errors...vocx wrote: ↑Tue Nov 12, 2019 6:02 amYou still haven't made this public, right?josegegas wrote: ↑Tue Nov 12, 2019 5:17 am Made some more progress today... fixing errors in the code, a bit more complicated simulations start to be really fun:
https://www.youtube.com/watch?v=YyUkuVBGgyU&t=315s
My advice is to use dedicated icons for your scripted objects (those that appear on the tree view). This makes the workbench look more professional, because it doesn't use the plain "cube" icon from the Part Workbench. It also prevents confusion, as some of your objects may only work with your particular workbench.
When you create your scripted object, you can assign a "view provider" to define visual properties, including the icon.Code: Select all
obj = App.ActiveDocument.addObject("Part::FeaturePython", "MBDsolid") MBDObject(obj) # Class that sets ups the general properties of the scripted object MBDViewProvider(obj.ViewObject) # Class that sets up the visual properties class MBDViewProvider: def __init__(self, vobj): vobj.Proxy = self def __getstate__(self): return None def __setstate__(self, state): return None def execute(self, vobj): return def getIcon(self): return os.path.join(os.path.dirname(__file__), "icons", "MDBobject.svg")
Yes I was wondering how to add icons to the scripted objects. I will do this. Thanks! Also, do you know how to make an object part of another object? I mean, as in the FEM workbench, when you create a new analysis, the analysis itself contains scripted objects, such as the mesh, the material, constraints, etc. I'd like to do the same instead of using those containers with the folder icon, or are these the same?
Cheers
Re: FreeCAD as pre-post procesor for MBDyn
You have multiple options, dependend if it only needs to serve as group or if it should be a special object (e.g. Part::Feature)
1. Make a simple group with custom icon
2. Make any object with group extension (this allows e.g. Part::Feature to be a group)
The extension approach has the added advantage that you can make the group only accept certain types of object by implementing the "allowObject" function:
1. Make a simple group with custom icon
Code: Select all
import FreeCAD
class VPGroup:
def __init__(self, obj):
obj.Proxy = self
def getIcon(self):
'''Return the icon in XPM format which will appear in the tree view. This method is\
optional and if not defined a default icon is shown.'''
return """
/* XPM */
static const char * ViewProviderBox_xpm[] = {
"16 16 6 1",
" c None",
". c #141010",
"+ c #615BD2",
"@ c #C39D55",
"# c #000000",
"$ c #57C355",
" ........",
" ......++..+..",
" .@@@@.++..++.",
" .@@@@.++..++.",
" .@@ .++++++.",
" ..@@ .++..++.",
"###@@@@ .++..++.",
"##$.@@$#.++++++.",
"#$#$.$$$........",
"#$$####### ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
" #$#$$$$$# ",
" ##$$$$$# ",
" ####### "};
"""
obj = App.ActiveDocument.addObject("App::DocumentObjectGroupPython")
VPGroup(obj.ViewObject)
Code: Select all
import FreeCAD
class MyCustomGroup():
def __init__(self, obj):
obj.addExtension("App::GroupExtensionPython", self)
class MyCustomGroupViewProvider():
def __init__(self, obj):
obj.addExtension("Gui::ViewProviderGroupExtensionPython", self)
obj.Proxy = self
def getIcon(self):
'''Return the icon in XPM format which will appear in the tree view. This method is\
optional and if not defined a default icon is shown.'''
return """
/* XPM */
static const char * ViewProviderBox_xpm[] = {
"16 16 6 1",
" c None",
". c #141010",
"+ c #615BD2",
"@ c #C39D55",
"# c #000000",
"$ c #57C355",
" ........",
" ......++..+..",
" .@@@@.++..++.",
" .@@@@.++..++.",
" .@@ .++++++.",
" ..@@ .++..++.",
"###@@@@ .++..++.",
"##$.@@$#.++++++.",
"#$#$.$$$........",
"#$$####### ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
" #$#$$$$$# ",
" ##$$$$$# ",
" ####### "};
"""
obj = App.ActiveDocument.addObject("Part::FeaturePython","Group")
MyCustomGroup(obj)
MyCustomGroupViewProvider(obj.ViewObject)
Code: Select all
class MyCustomGroup():
def __init__(self, obj):
obj.addExtension("App::GroupExtensionPython", self)
def allowObject(self, obj):
#check if obj is allowed, maybe by type?
return obj.isDerivedFrom("Part::FeaturePython")
Re: FreeCAD as pre-post procesor for MBDyn
The folder object corresponds to a Std Group which is created asjosegegas wrote: ↑Tue Nov 12, 2019 6:23 am Yes I was wondering how to add icons to the scripted objects. I will do this. Thanks! Also, do you know how to make an object part of another object? I mean, as in the FEM workbench, when you create a new analysis, the analysis itself contains scripted objects, such as the mesh, the material, constraints, etc. I'd like to do the same instead of using those containers with the folder icon, or are these the same?
Cheers
Code: Select all
obj = App.ActiveDocument.addObject("App::DocumentObjectGroup", "Group")
In the view provider the "Object" is the real object. This can hold a "Component" property that will hold those external objects that will be placed under this Object in the tree view.
Code: Select all
# Real object
class MBDSolid:
def __init__(self, obj, tp="MBDSolid"):
if obj:
obj.Proxy = self
self.Type = tp
obj.addProperty("App::PropertyLinkList", "Components", "Base", QT_TRANSLATE_NOOP("App::Property", "The components of this block"))
# This property will appear in the property editor
# Then the view provider
class MBDViewProvider:
def __init__(self, vobj):
vobj.Proxy = self
self.Object = vobj.Object
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def attach(self,vobj):
self.Object = vobj.Object
def execute(self, vobj):
return
def getIcon(self):
return os.path.join(os.path.dirname(__file__), "icons", "MDBobject.svg")
def claimChildren(self):
objs = []
if hasattr(self.Object, "Components"):
objs.extend(self.Object.Components)
return objs
# Those objects that are inside the Components property will appear as children in the tree
The Analysis object in FEM seems to use the same ViewProvider as a Std Group (App::DocumentObjectGroup). Maybe it's basically a Group with a specific FEM icon, so maybe you could do the same.
https://github.com/FreeCAD/FreeCAD/blob ... is.cpp#L81
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.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: FreeCAD as pre-post procesor for MBDyn
Very nice indeed! Two questions...
Is it already possible, or do you see that it could be possible in the future, to solve with this such examples as freecad-heini-1 has asked for here https://forum.freecadweb.org/viewtopic. ... 10#p343888 and https://forum.freecadweb.org/viewtopic. ... 20#p344564 ? As I understand it is basically about the contact (collision) between two surfaces...
Do you think it would be possible to have with this also interactive simulations, so that the model would be solved but then instead of running it as an animation, one would be able to pick a part of it with the mouse and move it manually?
Re: FreeCAD as pre-post procesor for MBDyn
saso wrote: ↑Tue Nov 12, 2019 10:25 amVery nice indeed! Two questions...
Is it already possible, or do you see that it could be possible in the future, to solve with this such examples as freecad-heini-1 has asked for here https://forum.freecadweb.org/viewtopic. ... 10#p343888 and https://forum.freecadweb.org/viewtopic. ... 20#p344564 ? As I understand it is basically about the contact (collision) between two surfaces...
Do you think it would be possible to have with this also interactive simulations, so that the model would be solved but then instead of running it as an animation, one would be able to pick a part of it with the mouse and move it manually?
This is perfectly possible! My next goal is actually to simulate a complete 4 stroke engine. Here is some work so far:
https://www.youtube.com/watch?v=x_lCrEkQUrE
You can't see the cams in the video, but I already modeled and simulated them. Here's a video of a cam simulated with MBDyn:
https://www.youtube.com/watch?v=ZwDzvJ9XD7M
You can find the code for that simulation in the video description. Here's an elastic contact example:
https://www.youtube.com/watch?v=H6fry6T5fSU
MBDyn is such a beautiful software, and integrated with FreeCAD will be a very powerful tool. I actually think that MBDyn can do as the definitive asembly workbench for FreeCAD. As you can see in my videos, the parts move perfectly because MBDyn takes care of the assembly, it looks for all the constraints and everything. I'm quite existed about this.
- microelly2
- Veteran
- Posts: 4688
- Joined: Tue Nov 12, 2013 4:06 pm
- Contact:
Re: FreeCAD as pre-post procesor for MBDyn
At the moment I see that you work with mbd configuration files and you have related objects inside freecad.
Does it make sense to implement the mbd nodes as nodes in pyflow and do the configration work there?
For me working in a network is easier than in the object tree hierarchy where I cannot see the relations between the object.
here some impressions on pyflow
https://www.youtube.com/playlist?list=P ... tKxbGxrmlr
Does it make sense to implement the mbd nodes as nodes in pyflow and do the configration work there?
For me working in a network is easier than in the object tree hierarchy where I cannot see the relations between the object.
here some impressions on pyflow
https://www.youtube.com/playlist?list=P ... tKxbGxrmlr
Re: FreeCAD as pre-post procesor for MBDyn
Yes, lately I was actually thinking about something similar, this is why I asked this questionsjosegegas wrote: ↑Tue Nov 12, 2019 12:23 pm I actually think that MBDyn can do as the definitive asembly workbench for FreeCAD. As you can see in my videos, the parts move perfectly because MBDyn takes care of the assembly, it looks for all the constraints and everything. I'm quite existed about this.
I was however thinking about doing it with Modelica, since Modelica is a language, we could even write our own libraries with it, if some of the existing ones would not be useful for our needs... But I am not preferring one solution over the other, similar to how we can use different solvers for FEM/CFD it would be IMO good to also have support for different solutions for simulations.
But directly using something like this for the assembly solver I am not sure if it is really possible. For assembling the model (from different parts and sub-assemblies) the user does not really need all the power of such simulation engines, what s/he needs however is a very fast (real time) solver, simulation engines however normally need some time (in complex models it can actually be a very long time) to "solve" the simulation. So, for the basic assembly we would need a simplified version of such a simulation engine with a sort of JIT compiler OR a combination of a more standard assembly constraints/mates and a more advanced ones for simulations (and I think most commercial parametric cad software is doing it like this).
This is however actually also one of the reasons for this post https://forum.freecadweb.org/viewtopic.php?f=8&t=40775, if Modelica, as a language, is a step further from the simulation packages and libraries, then DifferentialEquations.jl and SUNDIALS projects are another step further in to research of the best algorithms and mathematics that are behind this.