## Neg. Jacobians at Surface 2nd Order Elements

About the development of the FEM module/workbench.

Moderator: bernd

UR_
Posts: 1154
Joined: Tue Jan 03, 2017 8:42 pm

### Neg. Jacobians at Surface 2nd Order Elements

bernd wrote:

Hi bernd,

as well known, neg. jacobians occur very often and most of them appears near part's surface while using elements of 2nd order.

Gmsh offers a parameter to suppress some of them.

shape2mesh.geo:
Mesh.SecondOrderLinear = 1; // Second order nodes are created by linear interpolation instead curvilinear

Usually Gmsh tries to follow part's surface as close as possible. Therefore midpoints of surface 2nd order elements are curvilinear moved to match
desired curvature of part.
Sometimes bad shaped tetrahedrons (high edge ratio) hit limit, resulting in neg. jacobians.

Above mentioned parameter stops element distortion and ensures straight elements at surface with linear interpolated midpoints.

Therefore I introduced a new property to FEMmeshGmsh

Screenshot 003.png (4.38 KiB) Viewed 655 times

to get above shown shape2mesh.geo layout

_FemMeshGmsh.py:

Code: Select all

``````diff U C:/Users/aio/FreeCADcode/src/Mod/Fem/femobjects/_FemMeshGmsh.py C:/Users/aio/Miniconda3/envs/freecad/Library/Mod/Fem/femobjects/_FemMeshGmsh.py
--- C:/Users/aio/FreeCADcode/src/Mod/Fem/femobjects/_FemMeshGmsh.py	Mon Dec 16 18:45:08 2019
+++ C:/Users/aio/Miniconda3/envs/freecad/Library/Mod/Fem/femobjects/_FemMeshGmsh.py	Mon Dec 16 14:09:13 2019
@@ -177,0 +178,8 @@
+            "App::PropertyBool",
+            "SecondOrderLinear",
+            "FEM Gmsh Mesh Params",
+            "Second order nodes are created by linear interpolation"
+        )
+        obj.SecondOrderLinear = True
+
``````

gmshtools.py:

Code: Select all

``````diff U C:/Users/aio/FreeCADcode/src/Mod/Fem/femmesh/gmshtools.py C:/Users/aio/Miniconda3/envs/freecad/Library/Mod/Fem/femmesh/gmshtools.py
--- C:/Users/aio/FreeCADcode/src/Mod/Fem/femmesh/gmshtools.py	Mon Dec 16 18:48:20 2019
+++ C:/Users/aio/Miniconda3/envs/freecad/Library/Mod/Fem/femmesh/gmshtools.py	Mon Dec 16 18:42:53 2019
@@ -759,0 +760,5 @@
+
+        if hasattr(self.mesh_obj, "SecondOrderLinear") and self.mesh_obj.SecondOrderLinear is True:
+            geo.write("Mesh.SecondOrderLinear = 1; // Second order nodes are created by linear interpolation instead by curvilinear\n")
+        else:
+            geo.write("Mesh.SecondOrderLinear = 0; // Second order nodes are created by linear interpolation instead by curvilinear\n")
@@ -761 +766 @@
-
+
``````
Patches.zip

What do you think?
bernd
Posts: 9052
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

### Re: Neg. Jacobians at Surface 2nd Order Elements

I had problems to apply the patches thus I just copied the code ...

Is this what you would like to add? https://github.com/berndhahnebach/FreeC ... it/4141d4e
UR_
Posts: 1154
Joined: Tue Jan 03, 2017 8:42 pm

### Re: Neg. Jacobians at Surface 2nd Order Elements

bernd wrote:
Tue Dec 17, 2019 4:47 am
Is this what you would like to add?
Yes, that's right.
Jee-Bee
Posts: 1988
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

### Re: Neg. Jacobians at Surface 2nd Order Elements

bernd
Posts: 9052
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

### Re: Neg. Jacobians at Surface 2nd Order Elements

UR_
Posts: 1154
Joined: Tue Jan 03, 2017 8:42 pm

### Re: Neg. Jacobians at Surface 2nd Order Elements

Concerning gmshtools.py, I've send you wrong diff file.
I'm so sorry, my fault

This is the right one:

gmshtools.py

(Because you have problems to process my diff files, I've attached whole file, so you can diff yourself)

If it's done, you are allowed to start your sermon, something like: "Please familiarize yourself with Git" or something else.
bernd
Posts: 9052
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

### Re: Neg. Jacobians at Surface 2nd Order Elements

git commit e7be69e

Ahh, btw it would be much easier for all involved if you would use git and github for PRs
vocx
Posts: 2858
Joined: Thu Oct 18, 2018 9:18 pm

### Re: Neg. Jacobians at Surface 2nd Order Elements

Maybe you noticed already but FEM has a failing test, which seems to be due to this.

Code: Select all

``````freecad -t TestFem
``````

Code: Select all

``````FAIL: test_solver_elmer (femtest.app.test_solverframework.TestSolverFrameWork)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/freecad-build-main/Mod/Fem/femtest/app/test_solverframework.py", line 188, in test_solver_elmer
self.assertFalse(ret, "GMSH geo write file test failed.\n{}".format(ret))
AssertionError: 'Comparing /opt/freecad-build-main/Mod/Fem/femtest/data/elmer/group_mesh.geo to /tmp/FEM_unittests/FEM_solverframework/SolverElmer/group_mesh.geo failed!\n--- \n+++ \n@@ -15,0 +16 @@\n+Mesh.SecondOrderLinear = 1; // Second order nodes are created by linear interpolation instead by curvilinear\n' is not false : GMSH geo write file test failed.
---
+++
@@ -15,0 +16 @@
+Mesh.SecondOrderLinear = 1; // Second order nodes are created by linear interpolation instead by curvilinear
``````
To support the documentation effort, and code development, your donation is appreciated: paypal.
bernd
Posts: 9052
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

### Re: Neg. Jacobians at Surface 2nd Order Elements

vocx wrote:
Tue Dec 17, 2019 7:41 pm
Maybe you noticed already but FEM has a failing test, which seems to be due to this.
confirmed ... elmer test fails ...

Code: Select all

``````./bin/FreeCADCmd --run-test "femtest.app.test_solverframework.TestSolverFrameWork.test_solver_elmer"
``````
bernd
Posts: 9052
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland