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 »

And this wasn't even touching on the benefits of making coarse meshes in CAD based software with direct manipulation tools at your disposal.

If I update the loft of a wing, and I'm using gmsh, it is a tremendous pain to update that mesh geometry to be flush with the new Outer Mold Line of the wing again. I'd probably need to bring the new geometry into gmsh again, and then re-make the mesh from the surfaces.

However, with orphan meshes, you can project the free edge nodes onto the edges of the surface, project the mesh nodes along surface normals to be flush with the skins, and with terrifying little effort, your old mesh is accurate to your new geometry now. Something like that gets harder to do the more abstraction you put between your FEM data and your geometry data; but to be frank, compared to the absolute mess that some commercial meshers make you go through, gmsh isn't nearly as bad as it could be.
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: Creating a bespoke shell mesher in FreeCAD

Post by heda »

vert2vec lambda is what it sounds like, it makes a fc vertex to a fc vector, so one can use 'distanceToPoint'
as side note, there really could be some helper functions on the points/vertexes/vectors objects, suppose that would simplify code all around fc source, just having a '.to_tuple()' or something like that would be useful.

getattr(vertex, 'X') is same as vertex.X, maybe that is one of my bad habits to tend to do "python comprehensions"

"let me click lines while the gui is open" - you can't in that version, selection must be good to go before you run the macro.

this should really be an add-on, if for nothing else the release cycle is long for fc, so anything in an infant state should be an add-on to begin with - imho.

since did not have a clue of how to make a workbench - just to see if I could pull it off - I made one.
given the templates on the wiki, can't say it was hard, pyside appears to be trickier than fc.

this works as a regular wb on my box.
just basic functionality, but should be enough code in there for anyone to build on as they wish.
it is not tuned to be working headless, and it is just to unzip in the 'mod' folder as any 'add-on'.

at last, on the note whether this potentially is useful or not - dunno, but I take it as a chance to learn a bit more about fc. AFAIK there are plenty of uni's out there with their own educational fem solvers, so if there was a way to make simple 1d/2d meshes in fc - who knows, maybe some of those will start using fc to generate the mesh in fc (and postprocess will probably not be far behind) - sure it would be purely educational, but at the same time these uni's are likely to work on more specialized solvers, and then fc might very well become a realistic choice for those as well..., who knows what the future could bring.

for heavier meshing, with holes etc requiring adaptive node placement/element sizing, sure gmsh or friends is the choice, but for something simple and fairly regular in shape - why not a simple mesher usable directly in fc?

edit: removed attachment, look at later posts
Last edited by heda on Wed Aug 04, 2021 10:50 pm, edited 3 times in total.
aerospaceweeb
Posts: 118
Joined: Fri Apr 09, 2021 3:26 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

Heda, you are a joy and an inspiration.

Terribly sorry for my frustrations. I'll pick this apart this weekend, I will. You and john both have given me templates of addons to play with, and I'm certain that I can figure out how to make some buttons to make these mesh tools play a bit better.
aerospaceweeb
Posts: 118
Joined: Fri Apr 09, 2021 3:26 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

Okay I lied.

The moment I saw how luxuriously well commented this workbench you've made was, I was already waltzing to the desktop.

The next feature I think I need to add is an equivalence routine. Well, that, or a routine that can have the node IDs not be duplicates of one another.

I'm in love with this FCMesher addon format.

One thing I'm having trouble with is the namespaces. I need to be able to access the elementary nastran data structures from any subroutine, er function.

The most important two are E2N and nodes, which contain, respectively
[Element ID, Node ID, Node ID, ...] for any number of nodes in any kind of element; I think it would need to be an array of 21 columns in fortran; one for the element ID and the rest for up to a 20 noded hexahedral element, which FreeCAD supports.
The second is nodes [x, y, z, NodeID]. Fairly straightforward.

The simplest implementation of an equivolencing routine is also the stupidest and one of the worst performing. I love it. It's so easy to write I usually just do it, as my models are usually tiny.

Code: Select all

# Compute the distance each node is from each other node, which, for N nodes, results in an NxN square array of distances.

# Assume an equivalencing tolerance, usually something like 0.01 units.

# For each node, fetch the vector of distances it is from each other node
# (make sure you have a flag to skip the nodes distance from itself)
# Sort the vector of distances from each other node, keeping the indices stored for later
# Loop through the node list in a while loop
# While the distance is less than the tolerance, replace the lower of the two node IDs in the E2N with the higher node ID.
# The while loop construct allows for more than one node to be collapsed together! A very annoying sticking point that a lot of equivolence subroutines struggle with.

Right now, I'm trying to find a way to either search through the current FreeCAD part and look for mesh data, or retrieve the E2N and nodes data from the functions I've still got in this code.

Few minutes later, I was able to loop through the freeCAD part, but it looks like you can have nodes and elements BEFORE they have IDs! This makes perfect sense. CFD meshers do it all of the time, but I think another tool that may be work making is something to go through all the FEM entities in the model, and if they aren't numbered, slap a number on em'. That one seems pretty easy too.
aerospaceweeb
Posts: 118
Joined: Fri Apr 09, 2021 3:26 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

Ah Heda, I've thought of an issue.

If the warping check is performed by checking the distances from one node to another, it fails in edge cases where endpoint distances may not be the best representative of the "least warped" mesh. Such cases are edge cases, but the warping check algorithm would always catch this.

I've got a bizzare case of writers block almost when it comes to pasting over your code haha. It almost feels sacrilegious... well that and it's hard to replace code I'm not great at understanding. Imma getting there.
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 »

Cools stuff. Making a workbench it the best to way of developing new tools. If they prof to be good they can be easy integrated into main source of FreeCAD. Just make sure to use GPL2 as license as we can not integrate GPL3 code into FreeCAD. If you guys start to work on github we could add this small mesher to AddOn installer. It is very easy to install and update than inside FreeCAD gui.

cheers keep up the spirit.

BTW, totally offtopic, but I just mention it anyway: in the regard of making quads in FreeCAD with Gmsh. https://forum.freecadweb.org/viewtopic.php?f=22&t=20351 This works quite well for quad4 elements even with holes.
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 »

in the regard of export to Mystran mesh format. Have some patience this will be possible soon with main FreeCAD too.

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

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

@Bernd,

Thank you! That gmsh stuff looks excellent! I'm almost certain now that paver meshes in the future will just be calling that gmsh script, running it, and cramming its outputs into a FEM object of somekind. I'm never going to write anything that good at this rate haha.

Right now though, would you happen to know the best way to permanently make a node posess an ID?
I can see that it's possible to make an element hold an ID, but for nodes this is appearing difficult.

Am I just missing it in the documentation? I feel like I must be.
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 »

Select two meshes, then add a Hinge example.
hingeadd.jpg
hingeadd.jpg (21.47 KiB) Viewed 2493 times
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
aerospaceweeb
Posts: 118
Joined: Fri Apr 09, 2021 3:26 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

John, that looks amazing! I'd love to see the code for it.
Post Reply