Neg. Jacobians at Surface 2nd Order Elements

About the development of the FEM module/workbench.

Moderator: bernd

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

Neg. Jacobians at Surface 2nd Order Elements

Post by UR_ »

bernd wrote: :bell:


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
Screenshot 003.png (4.38 KiB) Viewed 1670 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
+
+        obj.addProperty(

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
(967 Bytes) Downloaded 30 times

What do you think?
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Neg. Jacobians at Surface 2nd Order Elements

Post by bernd »

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_
Veteran
Posts: 1355
Joined: Tue Jan 03, 2017 8:42 pm

Re: Neg. Jacobians at Surface 2nd Order Elements

Post by UR_ »

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

Re: Neg. Jacobians at Surface 2nd Order Elements

Post by Jee-Bee »

nice addition!
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Neg. Jacobians at Surface 2nd Order Elements

Post by bernd »

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

Re: Neg. Jacobians at Surface 2nd Order Elements

Post by UR_ »

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

This is the right one:

gmshtools.py
(41.57 KiB) Downloaded 29 times

(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. :roll: :lol:
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Neg. Jacobians at Surface 2nd Order Elements

Post by bernd »

git commit e7be69e

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

Re: Neg. Jacobians at Surface 2nd Order Elements

Post by vocx »

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.
Comparing /opt/freecad-build-main/Mod/Fem/femtest/data/elmer/group_mesh.geo to /tmp/FEM_unittests/FEM_solverframework/SolverElmer/group_mesh.geo failed!
--- 
+++ 
@@ -15,0 +16 @@
+Mesh.SecondOrderLinear = 1; // Second order nodes are created by linear interpolation instead by curvilinear
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Neg. Jacobians at Surface 2nd Order Elements

Post by bernd »

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"
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Neg. Jacobians at Surface 2nd Order Elements

Post by bernd »

Post Reply