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 »

johnwang wrote: Tue Jul 27, 2021 12:30 am Hope we can select an edge , then set it as a hinge. It should tell which two meshes it connected and which constrain to release.

Edit:
Maybe just after selected the edge, select the two meshes and save these info into a Hinge object.
Or select two meshes and find out the connection by code.

hinge2.jpg
hinge.FCStd
@JohnWang, I think I know how I'd do that.

The best way I know of to do things like that is to use 1D elements wherever possible.

Basically, I would want to make a CBUSH connecting the two nodes together. The CBUSH would be co-linear with the edge, so that the lack of drilling stiffness in the shell elements wouldn't cause issues. Then, I'd put a PBUSH on there with stiffnesses of 1E8 in all components but component 4, the twisting stiffness. This would make it so that each CBUSH acted like a hinge.

If you can help me make a nearest neighbor tool of some kind, that can rapidly compute the node nearest to each other node in a list, I'd be able to use that to recreate the "Make 1-D Gaps" tool from Patran, which is an EXTREMELY good utility.

My largest fear in that regard though is just having someone actually skilled like you throw a giant, un-commented pile of python that's worse than Obfuscated C Code at me and having it be better than my work, freezing me in place; unable to help or move forward.

Steve already has such a super tool he mentions in the sci-py library, but I'm yet to find it. This code I've made is barely two days old now.

I have an octtree script in my back pocket that should work wonders, but I think it might be 200 lines of my python, and that feels tiring. I may need it to do the equivolencing scripts I want to do.

SIDENOTE: If anybody reading this wants to help me make this thing a gui, PLEASE MAKE YOURSELF KNOWN TO ME!!! I am the worst gui programmer who currently walks this earth. I use linux with i3wm, hate touching my mouse, have tried to play skyrim mouseless with vim keybindings, and think that terminal based software is more useable than regular software; as long as it isn't CAD software. SAVE ME FROM MYSELF, PLEASE.

Okay code time.
aerospaceweeb
Posts: 118
Joined: Fri Apr 09, 2021 3:26 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

bernd wrote: Mon Jul 26, 2021 4:56 am very cool stuff ...

two remarks in the regard of FreeCAD.

- At the beginning define "doc = App.ActiveDocument" than use doc, this way later it would even be possible to use the code not on the active document.

- In FEM everything is separated in Gui and App. FreeCAD can run headless withcout Gui, but only if the developer has taken this into account.

Every Gui code should be inside a

Code: Select all

if App.GuiUp:
    # Gui related imports and code
How do I actually write this to work? I can't figure out where to put this.
aerospaceweeb
Posts: 118
Joined: Fri Apr 09, 2021 3:26 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

Okay,

https://www.youtube.com/watch?v=M2JobDZGf-8

This is a patran esque workflow on how a ruled surface mesher is really all that you need.

If I had mouse selection tolerance set up correctly, this'd be way easier, but as of now, this is a level of convenience that GMSH can't really touch.

Debating what to prioritize first.
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 »

aerospaceweeb wrote: Tue Jul 27, 2021 2:50 am Basically, I would want to make a CBUSH connecting the two nodes together.
When outputing the meshes into Mystran case file, you could treat the hinge as CBUSH there.
Last edited by johnwang on Tue Jul 27, 2021 9:07 am, edited 1 time in total.
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 »

johnwang wrote: Tue Jul 27, 2021 12:13 am
aerospaceweeb wrote: Sun Jul 25, 2021 1:53 am Add it to the FEM gui somehow?
Any kind of interactive mesh generation is my goal here.
Do you want to make a workbench?

FEM gui needs to touch cpp file and no guarantee to be accepted.
John, if you'd be willing to help with gui stuff, I'd LOVE to.
aerospaceweeb
Posts: 118
Joined: Fri Apr 09, 2021 3:26 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

Wait what okay crap hang on haha.

I can barely read my own python code, this is a hell of a way to start.

I think we'd be better off trying to integrate into the proper FEM workbench. Orphans starve to death, and nobody can possibly be better at this than the FreeCAD maintainers.

Is this workbench compatible with the rest of the FEM workbench?
aerospaceweeb
Posts: 118
Joined: Fri Apr 09, 2021 3:26 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

I'm so sorry @heda. You made this code so god damn beautiful and I've got 20 tabs open trying to figure out what I even need to look up later and it's knocking me out.

Code: Select all

    # check if curve 2 should be reversed
    # use the fact that an edge has two vertexes
    vert2vec = lambda vert: Vector(*(getattr(vert, xyz) for xyz in 'XYZ'))
    # I'm not sure if I should frame this, or shoot a movie around it
    # This is some god damn alien technology if I've ever seen it
    # I'm just trying to figure out what the hell this even does
    e1p1 = vert2vec(Curve_01.Vertexes[0])
    e2p1, e2p2 = (vert2vec(vert) for vert in Curve_02.Vertexes)
    reverse = e1p1.distanceToPoint(e2p1) > e1p1.distanceToPoint(e2p2)
    if reverse:
        print('curve should be flipped')
        N_Curve_2 = N_Curve_2[::-1]
Why would you do this just--
What is vert and how does it exist before it's defined?
Lambda functions are supposed to be like lisp but how is this calling Vector like it's a function, even though it's actually a thing initiated at the start of the file called App.Vector... and I don't even understand what that is is this an alias of some kind?
What the hell is an asterisk doing in front of an implied for loop behind a getattr function, calling the variable that doesn't exist yet?... Hindsight, I don't even know what getattr is/does.
Why... do you need to evaluate vert2vec like it's a tuple... is it a tuple? I think it's a tuple.
God this is only seven lines how can python demand 45 minutes to understand 7 lines AND STILL NOT BE UNDERSTOOD jesus word censored christ
No wonder nobody even tries to comment their python. The comments would have made the code longer than the fortran esque word censored that the short code avoided doing in the first place

*10 minutes later*
This is so far over my head dude I can't use any of this. I can't even understand how to make it let me click lines while the gui is open. I'll try again tomorrow.
keithsloan52
Veteran
Posts: 2753
Joined: Mon Feb 27, 2012 5:31 pm

Re: Creating a bespoke shell mesher in FreeCAD

Post by keithsloan52 »

aerospaceweeb wrote: Tue Jul 27, 2021 2:30 am
keithsloan52 wrote: Mon Jul 26, 2021 8:41 pm So my question why reinvent the wheel? Surely it would be better to add the facility to create Quad meshes to the existing FreeCAD facilities for invoking Gmsh.
GMSH is no ordinary wheel. Gmsh is a pennyfarthing with afterburning turbojets that only reach peak efficiency above speeds of Mach 3.

I've spent over 150 hours of my life trying to learn how to make the GMSH gui do what I want it to, and I hated very second of it.
Did you ever raise/discuss your problems with a gmsh gitlab issue or email with Christophe Geuzaine, I always found him helpful.

I think you are missing the point if you invoke Gmsh using either via the Mesh or FEM Workbench (They use different interfaces to Gmsh)
you don't have to deal with the details/internals of Gmsh, you are just selecting an object to Mesh and a few parameters. Adding an option to have it produce Quad Facets rather than Triangular ones would not make it complicated for a user to use but I get the clear impression adding such a facility would be well beyond your abilities. You do realise that Gmsh has a C++ library & python module its not just a GUI Application.
IN FACT, I hypothesize that nearly all of the "good" open source pre-processors out there aren't as good as my crappy and juvenile workflow in FreeCAD. This is for the simple reason that the ability to easily manipulate geometry is more important than the ability to mesh obscure and poorly realized geometry.
I see two problems here 1) Ego and 2) Not understanding that you could Quad Mesh FreeCAD Objects by using the library C++ or Python.
So things like the Curves workbench make FreeCAD an abhorrently more powerful tool than basically anything else like gmsh.
Oh really - Currently I have a BIG BIG problem with the Curve Workbench. I started a Workbench ImportNURBS ( Still under development) https://github.com/KeithSloan/ImportNURBS for importing 3dm files from Rhino, okay it creates Standard FreeCAD Bezier's/Nurbs etc
but the Curves Workbench does not have any facility for taking standard curves/surfaces etc and modifying them, the only things you can change
are curves and surfaces created with the curves workbench.

I also have another Workbench https://github.com/KeithSloan/GDML one feature of which is to create GDML Tessellated Objects
which can have both triangular and quad Facets, so I suspect that any workbench you create will (like the Curves workbench) not offer any
facility for me to access the Quad Mesh so I can produce an equivalent GDML object, all because you insist on reinventing the wheel
You know how much of a pain in the ass it is to simply split a surface and remesh it? It's nuts!!
I see Gmsh as a tool for creating Meshes for manipulating meshes I would use Blender.
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: Tue Jul 27, 2021 3:04 am
bernd wrote: Mon Jul 26, 2021 4:56 am - In FEM everything is separated in Gui and App. FreeCAD can run headless withcout Gui, but only if the developer has taken this into account.

Every Gui code should be inside a

Code: Select all

if App.GuiUp:
    # Gui related imports and code
How do I actually write this to work? I can't figure out where to put this.
on any place where you use Gui or FreeCADGui. If FreeCAD runs headless these will break your code. In FEM Gui and App code is strictly split. There are only a few modules which include App and Gui code one example is the ccxtools module. https://github.com/FreeCAD/FreeCAD/blob ... cxtools.py thus any Gui related code has to be guarded. search for Gui in this module. There will be a lot of the guards. but best is it to totally split the code in gui methods and non gui methods.

Imagine someone else would like to use the mesher in a script with a headless FreeCAD. It would not work with all the Gui inside.
aerospaceweeb
Posts: 118
Joined: Fri Apr 09, 2021 3:26 am

Re: Creating a bespoke shell mesher in FreeCAD

Post by aerospaceweeb »

You seem to be relatively opposed to the idea of a bespoke mesher in FreeCAD at all that isn't just gmsh.

It's honestly not very difficult to just make elements the way that the script we've made does it, as the FreeCAD FEM primitives are remarkably simple and straightforward to create.

Is it so hard to believe that a less procedural quad mesher is desirable? FeMap, Patran, Hypermesh, and other less common meshers like Mecway and M3d all have a far less strict mesh creation procedure for quads than gmsh does, which has its pros and its cons. Acting like gmsh is the end-all-be-all of meshers is incorrect to do. If I end up trying to do paver meshes of 2nd order tris, or curvature adaptive tet10 meshes of detailed solids, I'll use everything at my disposal to not have to write that code myself; including use CGX and gmsh. Isomeshes of quads are very simple to make, and FreeCADs macro language makes it extremely easy to do so.

As a person who does FEM for a living (unfortunately. It can be the most tedious part of a structural engineering job) I've almost never heard a defense mounted for a software that can "create" meshes, but can't manipulate them. Not there's not great utility in similar such software; although standalone post-processors are generally wonderful in my opinion. I've just never heard cohesive arguments for a divorce between mesh generation and mesh manipulation by anyone who uses FEM to do practical structural analysis for engineering purposes.

- User friendly equivolencing of nodes by ID list or by selection is a requirement to make any kind of cohesive structural mesh.
- The ability to create primitive MPC elements and connect those elements with 1D bar elements is critical, and frequently very difficult in explicit, geometry based meshing software like gmsh.
- The ability to move individual nodes around and project nodes onto curves and surfaces is a killer feature.
- The ability to get node lists by selecting associated geometry, and vice versa, is something that even enterprise grade FEM software TODAY aren't always the best at. The only "great" "independant" project I've seen take a stab at this has been PreProMax, but that's calculix only and windows only and I don't really know if it's open source yet. Salome is theoretically excellent too but once again, I've found it very hard to learn, and find its geometry manipulation capabilities to be a bit clunky (but not too clunky for a FEM software! Patran is about as clunky, I've just got more experience with it).

FreeCAD, by comparison, has some of the best geometry manipulation I've ever seen or heard off; and it had better, considering it's a CAD software first and foremost. CAD software that can use their CAD 3d environments and geometry to do meshing work are almost always preferable to standalone mesher software, unless that mesher software also offers comparably powerful geometry manipulation; like Spaceclaim or Hypermesh. It's for this reason that NX is so beloved by its user-base; as SimCenterNX is all of the power of NX with all of the theoretical comfort of FeMap, but with all of the clunkiness of FeMap removed! What a seductive idea.

As for remarks about the curves workbench; I'm sorry that it doesn't support your ImportNURBS workbench or GDML, but its "power" is independant of how well it supports features that are important to you. I was able to make sketches, sweep a surface, and then use the curves workbench to create a parametric number of isocurves along the surface, and then do a ruled mesh along those hulls in around 90 seconds. That's very fast, even for software like abaqus, patran, or femap, and that was using python code, written by a novice like me, in probably four times more lines than a master like you would have been able to do. FreeCAD has extremely large amounts of power in its built in FEM scripting capabilities. Using those built in FEM scrpting capabilities for their intended purpose is hardly re-inventing the wheel.
Post Reply