Creating a bespoke shell mesher in FreeCAD

About the development of the FEM module/workbench.

Moderator: bernd

aerospaceweeb
Posts: 118
Joined: Fri Apr 09, 2021 3:26 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

Would anyone here know the best way to get the highest node ID of any mesh entities in the current model?

I'm trying to make some elements have node and element IDs that don't conflict with the rest of the model, but I'm having some issues.

This sample code takes in a list called "nodes"
that's of the form

Code: Select all

nodes = [Node_ID, X_coordinate, Y_coordinate, Z_coordinate]
And here's the code section

Code: Select all

def offset_to_prevent_node_ID_conflict():
    # Get all of the mesh objects in the model
    mesh_objects_in_model = []
    for obj in FreeCAD.ActiveDocument.Objects:
        if obj.TypeId == 'Fem::FemMeshObject':
            mesh_objects_in_model.append(obj.FemMesh)
        elif obj.TypeId == 'Fem::FemMeshObjectPython':
            mesh_objects_in_model.append(obj.FemMesh)
            
    if len(mesh_objects_in_model) == 0:
        return

    for mesh_obj in mesh_objects_in_model:
        print(mesh_obj.Nodes)
I can't help but notice that if there's more than one mesh entity in the model, the node IDs can conflict with one another.

Are node IDs for multiple meshes resolved on export?
After trying I don't actually think I can even export multiple mesh bodies at the same time; am I not supposed to do that? It's not really a "gmsh" kind of thing at all, I know. It's barely even a patran thing at all, actually.

Maybe I should instead try to put both of the mesh objects into a single container instead?

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

Re: Creating a bespoke shell mesher in FreeCAD

Post by bernd »

aerospaceweeb wrote: Sun Aug 01, 2021 2:52 am Are node IDs for multiple meshes resolved on export?
actually I have never tried to select two meshes and export them in one file. Is this what you would like to have. I have no idea what happens and if this is supported by some exporter ...
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Creating a bespoke shell mesher in FreeCAD

Post by bernd »

aerospaceweeb wrote: Sun Aug 01, 2021 2:52 am Would anyone here know the best way to get the highest node ID of any mesh entities in the current model?
from one object with:

Code: Select all

max(list(YourFemMeshObject.FemMesh.Nodes.keys()))
if you make a loop above all object you should get the maximum node idea from all mesh objects.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Creating a bespoke shell mesher in FreeCAD

Post by bernd »

side note ...

AFAIK if you save and load a FreeCAD file all gaps in node numbering are removed, thus node count = max node id for such a loaded mesh. This is because the unv writer from Salome SMESH does this and we have decided to not patch is as long as there is no real need for it.
User avatar
johnwang
Veteran
Posts: 1339
Joined: Sun Jan 27, 2019 12:41 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by johnwang »

After create the hinge which connects two meshes,
Select two meshes and the hinge between them, then output Mystran case file.
hinge4.jpg
hinge4.jpg (92.13 KiB) Viewed 2320 times
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: Creating a bespoke shell mesher in FreeCAD

Post by heda »

aerospaceweeb wrote: Thu Jul 29, 2021 4:37 am If the warping check...
yepp you are absolutely right, the simple check I did for need to flip does not work (clearly had not thought that one through properly).
so I did a new one which checks the lines from the 4 points,
theoretically that one should be watertight (I think :-)),
however fc continuously throws curved balls, so in practice it fails in fc (seems like there can be misshaps in reported start/end points vs actual orientation), can't help but think that this is one of the things that at some point leads to other type of hard to find bugs in geometry creations.

this time around the selection is a bit more elaborate,
pretty happy with how that works, more specifically the possibility to easily go through a chain of curves with minimal amount of clicks.

have added a test-file, it generally works, but it has geometry in it giving strange results when using certain edge combinations.
anyone interested in bug hunting for core geometry could possibly use that as starting point of the hunt.

although this for now is mainly for play, it is not very hard to see a path to make this quite useful in building smaller type meshes from scratch from within fc where one has easy control over the outcome. it could be that for example fc has trouble importing a step because of some malformed definition of spline profile on a surface (has happened to me at least), then this could turn out to be very useful in creating a mesh from those edges in a simple way (since it just works from coordinates). if fc has trouble reading a surface, so does gmsh since they are using the same things for surface repr under the hood as far as I can gather. when this happens I have never been able to make it work decently neither in gmsh nor netgen.

or another example could be, having a body which is full of holes, and instead of defeature, one makes a shell mesh directly based on edges, that shell mesh is then shipped to gmsh or netgen to make a volume mesh, or keeping it as shells (welded structure?).

or if one for example have an airplane wing, only the outer profile but want to make some quick internal support webs. start with ruled surface mesh like this, and from that make the webs from generated nodes.

these type of workflows allows for full control over element size/position on all edges from fc.

obviously the "femmesh 2 mesh" creates a swiss cheese mesh due to the quads on the ruled surfaces (but it works), otherwise that would have been pretty handy to take a ruled mesh and make a matching geometry with "mesh 2 shape" & refine (if the auto-geometry creation fails - which it for sure will from time to time).

one can of course use "fill holes" and "add faces" to make a proper tri-mesh.
or one could use "Mesh Remodel" add-on, fc seems to allow for selection and use of femmesh nodes to create lines, wires and faces from nodes (although there is no highlighting of selected, but that can be tracked in the "selection view").

my driver for doing this has been to learn a bit about the basics in making a wb, just for learning purpose - that target is now fulfilled - so don't really see myself doing much more on this from now on.

on the multiple mesh thing, bernd will of course know it all (and has answered above - after me authoring this answer offline), but I think...
fc mesh is really intended as an easy to use pre/post, and the first thing to get done was that it is possible to mesh one single solid and show results for that. this I think was the original milestone to get done, and that is probably still largely reflected in the codebase.

as with everything in fc, it however evolves over time, since people are coding small pieces here and there to increase functionality.

one simple example of a missing basic functionality afaik is, there is no way to do a proper torque load from within fc gui, one has to resort modifying the input deck by hand to get it done.

looking forward to see how this evolves.
the download is the "add-on".

edit: removed attachment, look at later posts
Last edited by heda on Wed Aug 04, 2021 10:49 pm, edited 2 times in total.
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: Creating a bespoke shell mesher in FreeCAD

Post by heda »

simplifying what bernd wrote a bit, the below works as well

Code: Select all

max(YourFemMeshObject.FemMesh.Nodes)
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Creating a bespoke shell mesher in FreeCAD

Post by bernd »

this why I love Python. It works like a humans brain. I assumed it would work but I was on the way and could not test ...
aerospaceweeb
Posts: 118
Joined: Fri Apr 09, 2021 3:26 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

@Bernd
side note ...

AFAIK if you save and load a FreeCAD file all gaps in node numbering are removed, thus node count = max node id for such a loaded mesh. This is because the unv writer from Salome SMESH does this and we have decided to not patch is as long as there is no real need for it.
Unfortunately, that's not going to be particularly good for the nastran users of the world.
The IDs on nodes and elements are static in most modern solvers; as the node and element IDs are used to tell what parts of an assembly you're dealing with.

For example, I know that on an american fighter jet that shall remain nameless, they use all eight characters of the nastran ID stack to control for sides of the vehicle.

X3,XXX,XXX == Right hand side nodes
X4,XXX,XXX == Left hand side nodes

I was fighting with the mesher for quite a while and wondering where the node IDs were stored, but now I see they're just kind of absorbed into the indices of the mesh object, which was the source of why I wasn't able to avoid clashing of IDs in the mesh objects.

As for your previous comment regarding not being able to export two mesh objects simultaneously, this makes sense with that.

A lot of CFD preprocessors work this way too, where the IDs of the cells and nodes aren't that important, all that is important are the coordinates and the connectivities.

I want to look into what Heda has managed to do with the mesher, but after that I'll be trying to find some workarounds for storing the node ID and element IDs more permanently attached to the mesh object in some way. This would make it far, far easier to do things like equivalencing and hex element creation by thickening a shell mesh, for example.

The hex mesh example is what I was working on for most of Sunday my time, as the trick I know from an old script I found was that you can take copy a node and translate it along the average of its element normals, and add to its ID the length of the original node list in the shell mesh. Now the connectivity matrix for the hex element is very easy, as N5-N8 are really just N1+len(nodes), N2+len(nodes) ... etc!! This is a super cool trick that makes making hex meshes VERY easy, but I can't do it, partially because it keeps absorbing the gaps in my node IDs.
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: Creating a bespoke shell mesher in FreeCAD

Post by heda »

to clarify a bit...

failed in warp detection in the earlier post was for the surface creation, not for the mesh creation.
anyhow, the order how vertexes are listed, or can be extracted from edges in combination with the orientation does not make much sense to me,
regardless of that the code is now such that both mesh and surface seems to behave on the test file.

having the surface there should open up for the possible route to define bc's on geometry...
have not tried it, will leave to others to figure out what is further needed to make that work.

basically this is fully functional for the ruled mesh part and hopefully quite user friendly, at least until someone manages to break it...
Attachments
FCMesher.zip
(152.1 KiB) Downloaded 45 times
Post Reply