## Understanding what NetGen is doing!

When using FreeCAD 0.17 it is not that difficult to make a simulation of something pressuring a cube that is fixed to the ground. I’t a simple case where we follow the typical simulation procedure… Make drawing, define boundary conditions, generate mesh, solve and get results.

I can understand that I need boundary conditions since these are the essence of the problem. But the mesh seems out of place. Or not… It is the building block of the finite element method where we describe a complex geometry into multiple small connected elements. The mesher will transform the solid in building blocks that represent the geometry we wish to study. We can use a mirrad of element types (block shapes) and the mathematical formulations they hold. NetGen should not be any different it can have tetrahedrons, hexahedrons, … and each specific nodes required…

But a question which came to my mind was how would the element shape originator and the element formulation originator work. Are they the same?Why I make this question? In freeCAD I generate a mesh with NetGen or Gmsh, however I solve it with Calculix and not the solver from NGSolve or Gmsh.

Before attempting a solution, a mesh is generated and thus the shape of the elements is defined and from the images they look tetrahedrons.

I found an answer to my questions in a paper written by one of the Authors of NetGen: Joachim Schöberl: An advancing front 2D/3D-mesh generator based on abstract rules.

The mesh is generated according to a specific sequence from a geometry. First special points are gathered on the corners of the target geometry, next edges have to be detected to then create a surface mesh that follows specific element shape rules; the final step is to create a volume mesh from the surface mesh and another specific rules necessary for element quality.

The output should be a cloud of nodes, elements and their connectivity to each other. From the paper it looks like it is purely connected to the geometry but then what connects to the differential equations we wish to solve? For instance how do I say a line is a beam? Or how do I create a body shell which basically is a shell with thickness.

Here comes the solver part. In case of calculix with NetGen used in this example all tetrahedrons should have a specific element type which will define the physics involved being structural, thermal, electric. In this case structural.

Indirectly the program gives a hint of the element type suggesting structural loads and forces in the boundary conditions or for a thermal case (not this one), the appropriate thermal boundary conditions.

As an example I am picking a Cube made in FreeCAD using NetGen mesher and Calculix solver. Before entering the solving process I generated the .inp file which contains the mesh, the boundary conditions and the material data to perform the simulation.

Somewhere in the .inp file you will find the following:

TYPE=C3D10

The element type name used is C3D10, as expected expected since normally the solver has a ton of element types, and there should also be in the Calculix solver a similar variety  like for instance Ansys with Solid187 (https://www.sharcnet.ca/Software/Ansys/17.0/en-us/help/ans_elem/Hlp_E_SOLID187.html), Solid186 or Solid226; for a list see this reference:

https://www.sharcnet.ca/Software/Ansys/17.0/en-us/help/ans_elem/

More details about C3D10 element can be seen in:

http://web.mit.edu/calculix_v2.7/CalculiX/ccx_2.7/doc/ccx/node33.html

And a list off all Calculix elements can be seen here:

http://web.mit.edu/calculix_v2.7/CalculiX/ccx_2.7/doc/ccx/node25.html

```** written by FreeCAD inp file writer for CalculiX,Abaqus meshes

** Nodes
*Node, NSET=Nall
1, 10, 10, 0
2, 10, 10, 10
3, 10, 0, 0
4, 10, 0, 10
5, 0, 10, 0
6, 0, 10, 10
7, 0, 0, 0
8, 0, 0, 10
9, 0, 5, 10
10, 5, 10, 10
11, 10, 5, 10
12, 5, 0, 10
13, 0, 5, 0
14, 5, 10, 0
15, 10, 5, 0
16, 5, 0, 0
17, 10, 10, 5
18, 0, 10, 5
19, 10, 0, 5
20, 0, 0, 5
21, 5, 5, 10
22, 5, 5, 0
23, 5, 10, 5
24, 5, 0, 5
25, 10, 5, 5
26, 0, 5, 5

** Volume elements
<span style="color: #0000ff;"><strong>*Element, TYPE=C3D10, ELSET=Evolumes</strong></span>
25, 7, 4, 6, 8, 24, 21, 26, 20, 12, 9
26, 7, 6, 4, 1, 26, 21, 24, 22, 23, 25
27, 5, 7, 1, 6, 13, 22, 14, 18, 26, 23
28, 4, 7, 1, 3, 24, 22, 25, 19, 16, 15
29, 4, 2, 1, 6, 11, 17, 25, 21, 10, 23

** Define element set Eall
*ELSET, ELSET=Eall
Evolumes

***********************************************************
** Element sets for materials and FEM element type (solid, shell, beam, fluid)
** written by write_element_sets_material_and_femelement_type function
*ELSET,ELSET=SolidMaterialSolid
Evolumes

***********************************************************
** Node sets for fixed constraint
** written by write_node_sets_constraints_fixed function
** FemConstraintFixed
*NSET,NSET=FemConstraintFixed
3,
4,
7,
8,
12,
16,
19,
20,
24,

***********************************************************
** Materials
** written by write_materials function
** Young's modulus unit is MPa = N/mm2
** SolidMaterial
*MATERIAL, NAME=SolidMaterial
*ELASTIC
210000, 0.300

***********************************************************
** Sections
** written by write_femelementsets function
*SOLID SECTION, ELSET=SolidMaterialSolid, MATERIAL=SolidMaterial

***********************************************************
** At least one step is needed to run an CalculiX analysis of FreeCAD
** written by write_step_begin function
*STEP
*STATIC

***********************************************************
** Fixed Constraints
** written by write_constraints_fixed function
** FemConstraintFixed
*BOUNDARY
FemConstraintFixed,1
FemConstraintFixed,2
FemConstraintFixed,3

***********************************************************
** written by write_constraints_force function
** FemConstraintForce
** node loads on shape: Box:Face4
1,2,-0.0000000000000E+00
2,2,-0.0000000000000E+00
5,2,-0.0000000000000E+00
6,2,-0.0000000000000E+00
10,2,-1.6666666666667E+02
14,2,-1.6666666666667E+02
17,2,-1.6666666666667E+02
18,2,-1.6666666666667E+02
23,2,-3.3333333333333E+02

***********************************************************
** Outputs --&amp;gt; frd file
** written by write_outputs_types function
*NODE FILE
U
*EL FILE
S, E
** outputs --&amp;gt; dat file
*NODE PRINT , NSET=Nall
U
*EL PRINT , ELSET=Eall
S

***********************************************************
** written by write_step_end function
*END STEP

***********************************************************
** CalculiX Input file
** written by write_footer function
** written by --&amp;gt; FreeCAD 0.17.12321 (Git)
** written on --&amp;gt; Sun Oct 8 21:43:43 2017
** file name --&amp;gt;
** analysis name --&amp;gt; Analysis
**
**
**
** Units
**
** Geometry (mesh data) --&amp;gt; mm
** Materials (Young's modulus) --&amp;gt; N/mm2 = MPa
**
```

## Calculix interoperability

I talked a lot about Pre processors FreeCAD and Salome, in some cases the pre processor environment is more and offers the complete modelling package including a solver as in the case of FreeCAD. Calculix is the tool that will pick up a meshed model with boundary conditions and calculate specific results, being structural displacements, stresses, thermal behaviours and other physics.

A good work that was performed in making sense of these tools can be found on the following link:

https://www.theseus.fi/bitstream/handle/10024/87106/Neupane_Dilip.pdf?sequence=1

and Calculix documentation can be found here:

http://web.mit.edu/calculix_v2.7/CalculiX/cgx_2.7/doc/cgx/node4.html

It is important to know what Calculix needs input files  calculate something, this will depend on the type of files.

Geometry
• .Fbd
• .Step
• .stl

Mesh Generator and boundary-condition inputs (Model)

• Abaqus (Input)
• Ansys (Export)
• Code_Aster (Export)
• Samcef (Export)
• Dolfyn (Export)
• Duns (Export)
• Isaac (Export)
• OpenFOAM (Export)
• Nastran (Export)
• Tochnog (Export)

Mesh Generator

• Abaqus (.inp)
• Netgen

• Frd
• Duns
• Isaac
• OpenFOAM
• Nastran

## So what’s out there again?

I always get confused with the quantity of file types there are. FreeCAD, Salome, Code_Aster, Salome Meca, Calculix, Elmer, Gmsh, NetGen, ParaView, Python, OpenFOAM, … So how can one understand how each of these work and connect to each other?

We divide the file types in 5 categories:
• Geometry
• Mesh / Model
• Boundary Conditions + Model
• Solver
• Solution

Since these softwares can do a mixture of these 5 elements it’s not that easy to keep up with so many software and so many interconnections.

• Gemetry
○ Salome
○ Salome Meca
○ Gmsh
○ Elmer

• Mesh/Model
○ Salome
○ Salome Meca
○ Gmsh
○ NetGen
○ Elmer

• Boundary Conditions
○ Salome-Meca
○ Gmsh
○ Elmer

• Solver
○ Code_Aster
○ Calculix
○ OpenFOAM
○ Elmer

• Solution
○ Salome
○ Salome Meca
○ ParaViewer
○ Elmer

## Straight leg seat design for a bit of fun

Remembering when I was small, where i played countless hours with lego. Built many interesting constructions and tested the strength of many designs. That was a form of modeling the behaviour of a bridge, house or any structural  analysis that I could think of at that time. We all model things every day since we need to live in this world and figure out even if very basically the behaviour of objects. Think that when you hold an object you use the right force to hold it. Some how we know exactly the necessary configuration to execute physical task even without any though what so ever. When we look at a design and it challenges our notation that it will work it is because our underlaying protective system already is calculating and giving us feedback that it is dangerous to use. However this feeling can be wrong and the structure can be very safe, however most of the time our body is wright :).

I tested two designs on the simple table to understand what would happen.

This design present complete load transfer to the legs. The connection between table and leg is compress. Very little to none torsion is present. This design looks very stable, simple and is the classic, maybe the only simpler alternative is to use a solid cylinder instead, but that would make the seat very heavy. This design probably will hold as much as what the material used (wood, iron) can handle.

Comparing one design with another we can see that the behaviour to pressure  is completely different. The straight legs approach is stronger and would deal better with increased weight on top.

## Calculix – FreeCad – NetGen what else????

Previously I talked about gmsh and NetGen and showed a generated mesh. I did’t go much in detail and will continue to not do so for now. Noticed on a few blogs that FreeCad had a specific FEM environment that supposedly would work connected to Calculix and NetGen.

I found this really good tutorial in https://www.freecadweb.org/wiki/FEM_tutorial

Basically it is a FreeCAD help to get running the FEM module. I did exactly what was here, but not on my mac since I know that I would face eventually some difficulties. I used windows.

I had to install the necessary modules for everything to work.

Calculix, NetGen, Gmsh and a plugin from here https://github.com/psicofil/Macros_FreeCAD

To be honest I didn’t have that many expectations since It is a freeware simulation packages built from many separate projects. I wasn’t expecting much….

The interface was surprisingly easy to use compared to Gmsh or Calculix alone. Take a look bellow.

Meshing wasn’t a trouble but it looked like it created something similar to a spider web.

Before running the resulting mesh with boundary conditions.

The final step was to solve and look at something move or visualize some colors. To visualize the final solved solution was very simple. I just had to press results.

Final comments: simulation starts to become user friendly and looking back there has been remarkable advances in the open community search for a free and open source FEM software. Although far from perfect it is usable and these will be the drivers of a even more persistent and strong effort to match comercial software since more users will start to use these types of FEM packages which would not be possible until today.

So who is the main beneficiary? The hobbyist and the entrepreneur.