Elementtable by python

About the development of the FEM module/workbench.

Moderator: bernd

ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Elementtable by python

Post by ulrich1a »

wmayer wrote:What do you call an 'element'?
In the Finite Element Method the to be analyzed problem is organized in more or less simple 'elements'. Depending on the problem the element is either a 3D-volume like a tetrahedron or a hexahedron. In case the of a framework of trusses, the elements are edges. Other element-type exists like shells.
In the FEM-workbench there are only tetrahedrons actual, as those are available by automatic meshing algorithm.
The elements are defined by nodes. Each element has an ID and a list of nodes.
Each node has an ID and its coordinates.
The faces of an element are defined by the sequence of nodes in the element definition.

In order to support other type of forces applied to a part, like pressure, there is a need to get a list of element-faces that are aligned with a shape-face. Would the SMESHDS_GroupOnGeom function supply this list of element faces?
Exposing functions to python, that allows to get
- lists of element IDs in volume,
- list of face definitions that are aligned with a shape-face
would help to develop more functionality in python for the FEM-workbench.

Ulrich
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Elementtable by python

Post by bernd »

@werner
From point of view of a meshsoftware you are totally right, a volume-mes-element has volumes faces, edges and nodes. But from point of view from an FEM calculationsoftware a fem-volume-element has only volumes and nodes, a fem-shell-element has only faces and nodes and a fem-beam-element has only edges and nodes. May be the method should be named getFemElementTable() or we leave getElementTable() and all elements are returned (would be cool we'd be flexible in python than because have the whole mesh data) but ElementTable is not the right name than and a dictionary may be not the best data structure.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Elementtable by python

Post by wmayer »

Thanks Ulrich and Bernd for the explanation.
Would the SMESHDS_GroupOnGeom function supply this list of element faces?
Don't know exactly what the group is supposed to do but it is something different. When creating an FEM mesh from a shape a group won't be created. Apparently this can be done by using the method SMESH_Mesh::AddGroup
I was looking for GetElemNodes function and it doesn't seem to exist in 5.1.2
I have checked the sources from Salome 6.5.0 from Debian. This method is only in Python available but written in C++. It is of this form:

Code: Select all

const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
for ( int i = 0; i < elem->NbNodes(); ++i )
  result.pus_back(elem->GetNode( i )->GetID());
And here is a list of all methods of the Python API of the FEM mesh: http://docs.salome-platform.org/latest/ ... 1b05dcb8a0
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Elementtable by python

Post by wmayer »

May be the method should be named getFemElementTable() or we leave getElementTable() and all elements are returned (would be cool we'd be flexible in python than because have the whole mesh data) but ElementTable is not the right name than and a dictionary may be not the best data structure.
I suggest to implement these two methods: getElementsByType and getElementNodes where the argument for getElementsByType() is a string and accepts these values: Node, Edge, Face, Volume
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Elementtable by python

Post by sgrogan »

I think perhaps the strategy should be discussed a little more before too much effort is put into implementation.

JeffWitz makes a very important point here:viewtopic.php?f=18&t=10692&start=10#p86347
His method 2 I think looks forward. When more than one material is possible the coupling between the meshes will become significant. If the volume mesh is derived from a surface mesh a second object can share that surface mesh. When the "contact" surface meshes are conformal it will greatly simplify the coupling as both volume meshes will have the same surface nodes.

I know this is how the Ansys software I use at work does it. Imagine 2 coaxial cylinders viewed end on where the perimeter of the mesh approximation of the circles are octagons where the nodes are offset 22.5 degrees.

@JeffWitz I think we could use your expertise here.
"fight the good fight"
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Elementtable by python

Post by bernd »

wmayer wrote:I suggest to implement these two methods: getElementsByType and getElementNodes where the argument for getElementsByType() is a string and accepts these values: Node, Edge, Face, Volume
Just had a view at the links. Cool this two methods will be very helpful for the python guys around here!!! Just again a question. Would getElementsByType() return for example all meshedges (including the ones from the volumeelements) or only the femelemtedges?

@sgrogan: We should catch the big elephant in steps. Means the methods Werner suggested are a good point to start imho. But yes it's true as soon as we gone start supporting more meshes we may need to rethink some stuff. Same if we gone start supporting mixed calculations (1D and 2D and 3D.)
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Elementtable by python

Post by ickby »

as a little side step I like to represent an alternative data strukture which would ease things a lot when you guys decide to use vtk as postprocessing tool, but please ignore at will:

http://www.vtk.org/doc/nightly/html/cla ... ml#details
This is the main class in vtkl to store meshes and data. Here a few advantages:
1. it can hold arbitrary data (0D, 1D, 2D)
2. It support the cell notation, means one can directly qurey elements
3. one can assign multiple values or fields to any set of cells or points
4. can be used for vtk algorithms if the data shall be processed or filtered in any way
5. full python interface available via vtkPython
6- allow to store calculation results in the same data structure as the mesh

disadvantage:
1. it is not the simplest datastructure ever, needs some brain power to master it
2. needs vtk which is currently not a dependency
3. rewrite of already available algorithms needed
JeffWitz
Posts: 54
Joined: Fri Mar 27, 2015 9:14 am
Location: Lille, France

Re: Elementtable by python

Post by JeffWitz »

I will try to explain the issues I see in the different methods.

If you try to work in python with Table of connectivity (ToC) and Tabla of Nodes (ToN) you will have to put in memory a lot of things. It often happens to have mesh with several millions of Nodes so loading several times objects such as Toc and ToN is in term of performances absolutely not a good idea and lead to real limitations of the mesh size you can use for a given PC.

There is a lot of chance that there is an internal representation of ToC and ToN in FreeCAD or I don't think it will be able to write it CalculiX, so if this object is available from python, it could help to make face research on it.

For the other way I think you can look at the post posted here to use pythonOCC to help http://www.pythonocc.org/news/pythonocc ... processor/

It seems that they know how to solve this issue even if I don't find the Code that allows to create groups on PythonOCC.
I send a mail to Thomas Paviot to let him know that you are working on a FEM workbench ...

However I can explain how I use Salome-Meca in order to clarify.

Geometry :
--------------
* Import or create geometry in Salome,
* If the geometry has been imported one has to explode the solid in different faces (it is sure that there is a python method to do this in python, I can look at if you want) this is necessary to be able to create groups,
* Definition of the groups where the boundary conditions will be applied (on geometry).

Mesh :
-------
* Creating a mesh using netgen 3D-2D-1D (more or less the same process as you use).

Aster module :
------------------
* Launching the elasticity wizard and filling the forms given in,
* Launching the simulation.

Post Processing :
-------------------
*Define the output you want to process.

You are really close to Salome-Meca, in terms of functionalities the last thing that block to have a good basic linear analysis is to be able to define groups. May be with the use of PythonOCC things can get simpler and in python ?
You can find an example here : https://github.com/tpaviot/pythonocc-co ... le_mesh.py
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Elementtable by python

Post by wmayer »

Would getElementsByType() return for example all meshedges (including the ones from the volumeelements) or only the femelemtedges?
You can check this easily. Make a standard box from the Part workbench and make an FEM mesh with the option "Very fine". When querying the number of edges it tells you there are 36. If you look at the FEM mesh you will see that the original edges are divided two times (i.e. make 3 from 1 edge). Since the original box has 12 edges x 3 we have these 36. ==> it does not count all edges from the volumes (or faces)

The same applies to the faces where for each face from the box 16 triangles are created x 6 gives the 96 faces. The number of volumes is 118 which are all tetrahedrons and the number of nodes is 273.

With some test code I found out the ranges of the element IDs for this example:
nodes: [1, 273]
edges: [1, 36]
faces: [37, 132]
volumes: [133, 250]
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Elementtable by python

Post by bernd »

@Werner: Got it, thanks very much for the explanation.

Just for my understanding if I really got it. The Mesher (netgen) starts first to mesh all edges of the part, afterwards the faces (the shell of the part). For meshing the shell the meshed edges were taken. At the end the volumes where meshed. For this the meshed faces from the shell were taken. At the end all these shapes (edges, faces, volumes) together build the mesh the way you have been talking about all the time.
Post Reply