# Useful additional gmsh functionality

**URL:** <https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343>\
**Category:** Feature Requests\
**Created:** [December 16, 2023, 10:26pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343 "2023-12-16T22:26:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gunnar](https://avatars.discourse-cdn.com/v4/letter/g/ed655f/32.png) [@Gunnar](https://prepomax.discourse.group/u/Gunnar)\
**Post date:** [December 16, 2023, 10:26pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/1 "2023-12-16T22:26:29Z")

</div>

Hi,

after playing around with the Mesh optimization steps in prepomax, it seems that these settings are only taken into account for Netgen but not for Gmsh, right?

 ![0](https://global.discourse-cdn.com/free1/uploads/prepomax/original/2X/f/f063837dbb6258674bedf8298da31251e3a300bf.png)

In Gmsh the option “Optimize quality of thetrahedra with Netgen” can be activated, this optimization can help a lot to avoid creating elements with negative Jacobian:

 ![1](https://global.discourse-cdn.com/free1/uploads/prepomax/original/2X/6/6420302663547dfddfa88b201a9604a4e959ad17.png)

Can this option be added under “Tetrahedral Gmsh”?

 ![2](https://global.discourse-cdn.com/free1/uploads/prepomax/original/2X/3/30eebf47579361561411dad5c1d9eb7a0663c0dd.png)

In addition, in Gmsh the remaining elements with negative Jacobian can usually be eliminated subsequently by using “Regularization of high-order elements” with the default values/settings. It would be great if this option could also be added under Model \> Tools \> select part.

Greetings

---

<div class="post-metadata">

**Author:** ![Matej](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@Matej](https://prepomax.discourse.group/u/Matej)\
**Post date:** [December 20, 2023, 7:15pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/2 "2023-12-20T19:15:10Z")

</div>

> [@Gunnar](#):
>
> after playing around with the Mesh optimization steps in prepomax, it seems that these settings are only taken into account for Netgen but not for Gmsh, right?

You are right. Also, the Elements per edge is currently only a Netgen parameter.

> [@Gunnar](#):
>
> In Gmsh the option “Optimize quality of thetrahedra with Netgen” can be activated, this optimization can help a lot to avoid creating elements with negative Jacobian:

Do you have experience with bad meshes created by Gmsh? In my tests I did not encounter such problems. But it is a nice idea and easy to add.

> [@Gunnar](#):
>
> In addition, in Gmsh the remaining elements with negative Jacobian can usually be eliminated subsequently by using “Regularization of high-order elements” with the default values/settings. It would be great if this option could also be added under Model \> Tools \> select part.

Do you know if only the node positions change during this procedure or if any new elements are also created?

---

<div class="post-metadata">

**Author:** ![Gunnar](https://avatars.discourse-cdn.com/v4/letter/g/ed655f/32.png) [@Gunnar](https://prepomax.discourse.group/u/Gunnar)\
**Post date:** [December 20, 2023, 9:26pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/3 "2023-12-20T21:26:49Z")

</div>

> [@Matej](#):
>
> Do you have experience with bad meshes created by Gmsh? In my tests I did not encounter such problems. But it is a nice idea and easy to add.

I think following prozess shows best what i mean and how effective the additional gmsh optimizations can help to mesh “dirty CAD geometries” (my job is creating such dirty CAD parts 😉  
The initial mesh is created with gmsh in prepomax. The goal is to create a working mesh with a minimum number of nodes.

> [@Matej](#):
>
> Do you know if only the node positions change during this procedure or if any new elements are also created?

By using “Regularization of high-order elements” only the node positions change (at least for the default algorithm “Optimization”).

 ![00](https://global.discourse-cdn.com/free1/uploads/prepomax/original/2X/3/3cc1a4d9168a4e9d777b8d386c14c3c0830a66ea.jpeg)

You can test this with attached file  
[step.zip](https://prepomax.discourse.group/uploads/short-url/eImDr7tkImKbfGfS08A3LTedocz.zip) (74.7 KB)

Note: for the initial mesh i use “Midside nodes on geometry = Yes”

---

<div class="post-metadata">

**Author:** ![DanielC](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@DanielC](https://prepomax.discourse.group/u/DanielC)\
**Post date:** [December 22, 2023, 11:30am UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/4 "2023-12-22T11:30:13Z")

</div>

> [@Matej](#):
>
> Do you have experience with bad meshes created by Gmsh?

"I can confirm Gunnar’s observation regarding bad geometry. I had a corrugated hose that needed to be meshed, and it failed with Gmsh due to negaitve jacobian determinants. However, with Netgen, I managed to obtain a working mesh and results from Calculix, at least. It seems that Gmsh, in its current state in PreProMax, isn’t capable of handling complicated or dirty CAD, making it useless at the moment.

The Gmsh documentation mentions something about high-order tools to prevent negative Jacobians.

[https://gmsh.geuz.narkive.com/nW6gEHZR/detect-negative-jacobians](https://gmsh.geuz.narkive.com/nW6gEHZR/detect-negative-jacobians)  
type or paste code here

Nevertheless, thank you so much for putting in the effort to incorporate Gmsh into Prepromax!

Daniel

---

<div class="post-metadata">

**Author:** ![lucas\_bueno](https://yyz2.discourse-cdn.com/free1/user_avatar/prepomax.discourse.group/lucas_bueno/32/1168_2.png) [@lucas\_bueno](https://prepomax.discourse.group/u/lucas_bueno)\
**Post date:** [December 22, 2023, 11:34am UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/5 "2023-12-22T11:34:37Z")

</div>

> [@DanielC](#):
>
> making it useless at the moment.

Maybe it is a little bit too much for a critic. GMSH is very capable in many aspects, and even if it is not suitable for your specific situation, it does not mean it is useless. Actually, in my opinion, it is very useful for my needs. 🫡

---

<div class="post-metadata">

**Author:** ![DanielC](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@DanielC](https://prepomax.discourse.group/u/DanielC)\
**Post date:** [December 22, 2023, 11:38am UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/6 "2023-12-22T11:38:15Z")

</div>

As I mentioned before, I am very grateful for Gmsh in PreProMax. However, for industrial applications with real geometry, Gmsh in its current implementation in PreProMax is not usable for me, at least. This should not be taken as harsh criticism of Gmsh or PreproMax.

---

<div class="post-metadata">

**Author:** ![lucas\_bueno](https://yyz2.discourse-cdn.com/free1/user_avatar/prepomax.discourse.group/lucas_bueno/32/1168_2.png) [@lucas\_bueno](https://prepomax.discourse.group/u/lucas_bueno)\
**Post date:** [December 22, 2023, 11:52am UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/7 "2023-12-22T11:52:18Z")

</div>

Yes, I understand. Hopefully, both the PrePoMax implementation and GMSH itself will be more capable in the future. 😄

---

<div class="post-metadata">

**Author:** ![FEAnalyst](https://yyz2.discourse-cdn.com/free1/user_avatar/prepomax.discourse.group/feanalyst/32/688_2.png) [@FEAnalyst](https://prepomax.discourse.group/u/FEAnalyst)\
**Post date:** [December 22, 2023, 12:03pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/8 "2023-12-22T12:03:22Z")

</div>

I’ve seen several reports about the negative jacobian errors when using Gmsh in FreeCAD. It’s even described on their wiki: [FEM MeshGmshFromShape - FreeCAD Documentation](https://wiki.freecad.org/FEM_MeshGmshFromShape#Notes)

But, to be honest, most of the aforementioned cases where caused by the fact that the geometry was not well prepared for simulations. Many people using the FEM workbench in FreeCAD have no experience with FEA and they just take their designs with all the details and modeling issues (like intersections) and want to analyze them without the recommended (regardless of the simulation software) clean-ups and simplifications. Many cases where also involved thin-walled parts that should be meshed with shell elements.

I haven’t tested Gmsh in PrePoMax on complex geometries yet but my first advice in most cases would be to simplify the geometry as much as possible and use 2D/shell models when applicable. Even if Netgen works for some cases, the obtained mesh may not be suitable for accurate FEA. Still, there’s certainly an area for improvement in Gmsh itself (PrePoMax only provides an interface for it) but I wouldn’t say that it’s useless for “real geometry” since many people use it for quite complex models including organic shapes like biomechanical structures. Maybe some specific cases can be too difficult for Gmsh but then it would be good to discuss them on particular examples and maybe ask Gmsh devs for help.

---

<div class="post-metadata">

**Author:** ![Gunnar](https://avatars.discourse-cdn.com/v4/letter/g/ed655f/32.png) [@Gunnar](https://prepomax.discourse.group/u/Gunnar)\
**Post date:** [December 22, 2023, 12:47pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/9 "2023-12-22T12:47:53Z")

</div>

> [@DanielC](#):
>
> It seems that Gmsh, in its current state in PreProMax, isn’t capable of handling complicated or dirty CAD, making it useless at the moment.

I hope it is clear that my intention was not to make gmsh bad. Quite the opposite, I just wanted to point out that activating these options makes it even better (they are part of gmsh). The biggest advantage for prepomax is probably to have the ability for creating structural meshes now. For my shown example with the selected parameters, netgen works not much better to prevent elements with negative jacobians → Important using “Midside nodes on geometry = Yes”. Without that, netgen + gmsh created meshes without faulty elements.  
The other point is, everybody who uses FEM serious should know that the first step should be to cleanup/simplify the CAD geometry in such cases. I just wanted to show that it is possible.

---

<div class="post-metadata">

**Author:** ![DanielC](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@DanielC](https://prepomax.discourse.group/u/DanielC)\
**Post date:** [December 22, 2023, 4:12pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/10 "2023-12-22T16:12:10Z")

</div>

Yes, of course, Gmsh is also suitable for complex geometry. However, in some of my cases, I couldn’t make progress with Gmsh. And yes, I have cleaned up and simplified the geometry using numerous tools. There were also thin structures where I couldn’t proceed even with shell elements.

I just wanted to say that having the optimizations in Gmsh that Gunnar suggested would be helpful. That’s really all I meant to say. I expressed myself poorly, sorry 🙂

---

<div class="post-metadata">

**Author:** ![Gunnar](https://avatars.discourse-cdn.com/v4/letter/g/ed655f/32.png) [@Gunnar](https://prepomax.discourse.group/u/Gunnar)\
**Post date:** [December 22, 2023, 4:34pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/11 "2023-12-22T16:34:26Z")

</div>

I know and I didn’t want to be misunderstood too 👍

---

<div class="post-metadata">

**Author:** ![synt](https://yyz2.discourse-cdn.com/free1/user_avatar/prepomax.discourse.group/synt/32/4658_2.png) [@synt](https://prepomax.discourse.group/u/synt)\
**Post date:** [December 22, 2023, 5:00pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/12 "2023-12-22T17:00:01Z")

</div>

indeed, i tested this file by several meshes tuned setting and tetrahedral algorithm selection in Gmsh menus but still not succeed in solver. Problem always related to bad mesh shape and negative Jacobian.

> [@Gunnar](#):
>
> You can test this with attached file  
> [step.zip](https://prepomax.discourse.group/uploads/short-url/eImDr7tkImKbfGfS08A3LTedocz.zip) (74.7 KB)

it’s probably right, suggestion to Optimize quality with Netgen is important feature to make tetrahedral mesh results of complex geometry by Gmsh mesher to become usable.

> [@Gunnar](#):
>
> Can this option be added under “Tetrahedral Gmsh”?
> 
> ![2](https://global.discourse-cdn.com/free1/uploads/prepomax/original/2X/3/30eebf47579361561411dad5c1d9eb7a0663c0dd.png)

---

<div class="post-metadata">

**Author:** ![synt](https://yyz2.discourse-cdn.com/free1/user_avatar/prepomax.discourse.group/synt/32/4658_2.png) [@synt](https://prepomax.discourse.group/u/synt)\
**Post date:** [December 22, 2023, 5:22pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/13 "2023-12-22T17:22:45Z")

</div>

> [@Gunnar](#):
>
> The other point is, everybody who uses FEM serious should know that the first step should be to cleanup/simplify the CAD geometry in such cases. I just wanted to show that it is possible.

cleanup geometry such as fillet can be problematic due to sharp edges, and it may lead to stress singularities. Try to avoid whenever possible since the solution s unknown, use coarse mesh and quadratic instead.

---

<div class="post-metadata">

**Author:** ![synt](https://yyz2.discourse-cdn.com/free1/user_avatar/prepomax.discourse.group/synt/32/4658_2.png) [@synt](https://prepomax.discourse.group/u/synt)\
**Post date:** [December 22, 2023, 5:42pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/14 "2023-12-22T17:42:56Z")

</div>

> [@FEAnalyst](#):
>
> Many cases where also involved thin-walled parts that should be meshed with shell elements.

unfortunately, layering for setting number of element trough thickness is not yet available. It seems single element trough thickness of quadratic tetrahedral element (C3D10) can be far better than linear triangle (S3) or quadrangle (S4). Also, it may still comparable with quadratic triangle (S6) or quadrangle (S8/S8R). Tetrahedral mesh of thin part also have another advantage over single layer shell element, mesh can be refined at desired location and eliminates improperly definition of edge rotational boundary condition.

---

<div class="post-metadata">

**Author:** ![Matej](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@Matej](https://prepomax.discourse.group/u/Matej)\
**Post date:** [December 24, 2023, 3:57pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/15 "2023-12-24T15:57:45Z")

</div>

I was testing the optimization settings in Gmsh and found out the following.  
Firstly, there is a possibility to use Netgen for optimization of first order elements. Namely, if this optimization is started after the second order mesh is created it changes the mesh back to first order mesh.  
Secondly, a high order optimization can be used to optimize second order meshes. If first a Netgen optimization is used it helps to speed up the high order optimization.

So, I decided to add both possibilities.

 ![image](https://global.discourse-cdn.com/free1/uploads/prepomax/original/2X/0/0816fe0aa3be6378e043de3382f3aba37e2d6baf.png)

I will test this functionality further on shell meshes.

---

<div class="post-metadata">

**Author:** ![Gunnar](https://avatars.discourse-cdn.com/v4/letter/g/ed655f/32.png) [@Gunnar](https://prepomax.discourse.group/u/Gunnar)\
**Post date:** [December 24, 2023, 8:11pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/16 "2023-12-24T20:11:40Z")

</div>

> [@Matej](#):
>
> if this optimization is started after the second order mesh is created it changes the mesh back to first order mesh.

Okay i understand, when using “Optimize 3D (Netgen)” after creating the 2nd order mesh, the tetrahedral elements will be converted to 1st order elements. But what i mean is activating the checkbox before creating the 2nd order mesh. Then the optimization will also be made without converting them to 1st order elements. In the meantime i figured out that sometimes “Optimize quality of tetrahedra” for other examples works better than netgen, so it makes sense if this option also could be added.

> [@Matej](#):
>
> I will test this functionality further on shell meshes

The optimization only affects 3d tetrahedral elements.

 ![1](https://global.discourse-cdn.com/free1/uploads/prepomax/original/2X/9/983c9b271c0cc118d030c868c93418e4c927606c.png)

 ![0](https://global.discourse-cdn.com/free1/uploads/prepomax/original/2X/8/849c52b7162855542de8bd5c4cd61b07134deeaa.png)

---

<div class="post-metadata">

**Author:** ![Matej](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@Matej](https://prepomax.discourse.group/u/Matej)\
**Post date:** [December 25, 2023, 6:01pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/17 "2023-12-25T18:01:27Z")

</div>

> [@Gunnar](#):
>
> Okay i understand, when using “Optimize 3D (Netgen)” after creating the 2nd order mesh, the tetrahedral elements will be converted to 1st order elements. But what I mean is activating the checkbox before creating the 2nd order mesh.

Well, in the API it is a little different. There are some different functions to call, and I am unsure if they are the same as in GUI.

Currently, I have implemented the function:

gmsh/model/mesh/optimize

which has the following options:

Gmsh  
Netgen  
HighOrder  
HighOrderElastic  
HighOrderFastCurving  
Laplace2D  
Relocate2D  
Relocate3D  
QuadQuasiStructured  
UntangleMeshGeometry

I have split them into the following user options:

First order shell elements: None, Laplace2D, Relocate2D, QuadQuasiStructured  
First order solid elements: None, Gmsh, Netgen, Relocate3D  
Second order elements: None, HighOrder, HighOrderElastic, HighOrderFastCurving

And then, after some testing, I decided to use 10 loops for first order optimization and then 1 loop for second order optimisation.

For solid elements, the user can select first order and second order optimizations. Gmsh first creates first order mesh. Then, the first order optimization is performed. After that the mesh is converted to second order mesh, and then the second order optimization is performed.

---

<div class="post-metadata">

**Author:** ![Gunnar](https://avatars.discourse-cdn.com/v4/letter/g/ed655f/32.png) [@Gunnar](https://prepomax.discourse.group/u/Gunnar)\
**Post date:** [December 26, 2023, 2:21pm UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/18 "2023-12-26T14:21:24Z")

</div>

Thanks for clarifying. I don’t know most of these functions, so thank you for having them all available in the future.

Now i have made a new observation. Sorry this has nothing to do with this topic, i just wanted to mention it here. I tried to create a Transfinite mesh on a simple wedge-shaped part (attached the 3d file). It’s similar to your example shown in the video “PrePoMax & CalculiX - Transfinite volume meshes”.  
However, when i select “Recombine Yes” i get an error. Hence i guess Transfinite mesh for five sided volumes is no longer working? I tested with v2.0.1 and 2.0.2. With v2.0.0 it’s still working.

[wedge.zip](https://prepomax.discourse.group/uploads/short-url/t0VREK7rTjA6Zqc87j5FzSXUTjU.zip) (871 Bytes)

 ![1](https://global.discourse-cdn.com/free1/uploads/prepomax/original/2X/4/41f750f3ba5e55e65de940d18bc657f55d1c18c0.png)

---

<div class="post-metadata">

**Author:** ![Matej](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@Matej](https://prepomax.discourse.group/u/Matej)\
**Post date:** [December 27, 2023, 9:01am UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/19 "2023-12-27T09:01:46Z")

</div>

For me, it works in 2.0.1 and in my developer version 2.0.2. Did you use any Mesing parameters for the size settings? Can you share the .pmx file in which it does not work?

---

<div class="post-metadata">

**Author:** ![Gunnar](https://avatars.discourse-cdn.com/v4/letter/g/ed655f/32.png) [@Gunnar](https://prepomax.discourse.group/u/Gunnar)\
**Post date:** [December 27, 2023, 10:14am UTC](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343/20 "2023-12-27T10:14:42Z")

</div>

Attached the pmx file. Now i figured out that it works for me in v2.0.1+2.0.2 when i select Mesh type 2nd order “Yes” but not for 1st order mesh. In v2.0.0 both options work.

[1.pmx](https://prepomax.discourse.group/uploads/short-url/txne6aKHGapsDeQ1qDtLtI8B60Z.pmx) (8.4 KB)

[Next page](https://prepomax.discourse.group/t/useful-additional-gmsh-functionality/1343.md?page=2)
