Access to nodal results on element by element basis

About the development of the FEM module/workbench.

Moderator: bernd

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

Re: Access to nodal results on element by element basis

Post by bernd »

this huge dict is just a helper between the frd file loader and the generator of the FreeCAD document objects for the result and result mesh. It is not intended to work as an API, not at all. It has been there right from the beginning before I came to FEM. I do not like it too. Furthermore the calculation of some values from the results takes place there (vanMises). My idea was to move them away from the result input reader. But to be honest I did not spent really time on all this nor I do have a good idea how to make this better. May be some class would be better as this dict monstrous!

bernd
User avatar
HarryvL
Veteran
Posts: 1335
Joined: Sat Jan 06, 2018 7:38 pm
Location: Netherlands

Re: Access to nodal results on element by element basis

Post by HarryvL »

The method readResult(frd_input) in importCcxFrdResults.py is very easy to read and is almost a user guide for the FRD file. The nested dict helps bring that clarity. So my comment was not intended as criticism. I just wondered if there is a simpler way to get to what I want. I am on a steep learning curve.

I place my function call in fill_femresult_mechanical, because it will return an array of nodal variables (similar to von Mises) that needs to be plotted and I can therefore mimic all the existing code for filling the Result and VTK objects. That's how I got the concrete Reinforcement Ratios and Mohr Coulomb stress to work.

PS: in finite element code, where there is a need to access global nodes on an element-by-element basis, you would typically use a multi-dimensional array, e.g.: global_node_number[element_number][local_node_number]. By the way, I am not at all suggesting to go back in time and use a FORTRAN design paradigm; although it would make me feel more comfortable :lol:
User avatar
HarryvL
Veteran
Posts: 1335
Joined: Sat Jan 06, 2018 7:38 pm
Location: Netherlands

Re: Access to nodal results on element by element basis

Post by HarryvL »

HarryvL wrote: Sun Jun 03, 2018 9:00 pm What I have in mind is different in that it plots continuous lines, showing the flow of load from application to support ... more like this:


Trajectories_1.jpg


Trajectories_2.gif
I finally got the post processing routine to work for a single 3D Tetra10Elem. Next step: integrate it into FC and produce some pretty pictures :D
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Access to nodal results on element by element basis

Post by bernd »

:D

HarryvL wrote: Wed Jun 06, 2018 4:49 am So my comment was not intended as criticism. ...
I really like any comment about how to improve the code base of FEM.

HarryvL wrote: Wed Jun 06, 2018 4:49 am PS: in finite element code, where there is a need to access global nodes on an element-by-element basis, you would typically use a multi-dimensional array, e.g.: global_node_number[element_number][local_node_number]. By the way, I am not at all suggesting to go back in time and use a FORTRAN design paradigm; although it would make me feel more comfortable :lol:
As stated before I'm not happy with how result object is designed and implemented in FreeCAD FEM. There should be a smarter way. Imagine if we gone start element integration values and all the different FEM analysis types like mechanica, thermomech, thermo, electric, magnetic, fluid and so on, all have different result sets, We need to be more flexible in result object somehow ...
User avatar
HarryvL
Veteran
Posts: 1335
Joined: Sat Jan 06, 2018 7:38 pm
Location: Netherlands

Re: Access to nodal results on element by element basis

Post by HarryvL »

HarryvL wrote: Sat Jun 02, 2018 9:45 am Hi, I want to do some post processing for which I need to cycle through the elements of the result mesh and for each element access the element nodal results and nodal coordinates. So not simply run through all nodes, but access them on an element by element basis. How can I best do that? Thanks. Harry
Note to self and others:

(EDIT: tidied up the following description)

mesh_data['Tetra10Elem'] ------- Dictionary where the "key" is the element_number and the "values" are the global_node_number Tuples
mesh_data['Nodes'] ---------------- Dictionary where the "key" is the global_node_number and the "values" are the node_coordinates Tuples

So I now use the following arrays to cycle through global nodes on an element-by-element basis:

elNodes=numpy.asarray(mesh_data['Tetra10Elem'].values()) --------- elNodes[i,j]=global node number of local node j in element i
noCoord=numpy.asarray(mesh_data['Nodes'].values()) ------------------ noCoord[i,j]=coordinate j (0=x,1=y,2=z) for global node i

these are the arrays typically available in a finite element code.
Last edited by HarryvL on Mon Jul 02, 2018 3:39 am, edited 1 time in total.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Access to nodal results on element by element basis

Post by bernd »

HarryvL wrote: Fri Jun 29, 2018 4:51 am
HarryvL wrote: Sat Jun 02, 2018 9:45 am Hi, I want to do some post processing for which I need to cycle through the elements of the result mesh and for each element access the element nodal results and nodal coordinates. So not simply run through all nodes, but access them on an element by element basis. How can I best do that? Thanks. Harry
Note to self and others:

elements=mesh_data['Tetra10Elem'] ------- Dictionary with key=element_number and values=global_node_number Tuples
elements=mesh_data['Nodes'] ---------------- Dictionary with key=global_node_number and values=node_coordinates Tuples

So I now use the following arrays to cycle through global nodes on an element-by-element basis:

elNodes=numpy.asarray(mesh_data['Tetra10Elem'].values()) --------- elNodes[i,j]=global node number of local node j in element i
noCoord=numpy.asarray(mesh_data['Nodes'].values()) ------------------ noCoord[i,j]=coordinate j (0=x,1=y,2=z) for global node i

these are the arrays typically available in a finite element code.
Does it makes sense to directly add them somehow ?
User avatar
HarryvL
Veteran
Posts: 1335
Joined: Sat Jan 06, 2018 7:38 pm
Location: Netherlands

Re: Access to nodal results on element by element basis

Post by HarryvL »

do you mean use the dicts instead of the arrays in the computation?
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Access to nodal results on element by element basis

Post by bernd »

HarryvL wrote: Fri Jun 29, 2018 5:06 am do you mean use the dicts instead of the arrays in the computation?
Add the missing arrays to the FreeCAD FemMesh as properties to be able to access them directly by for example

Code: Select all

App.ActiveDocument.HarrysBridgeMesh.FemMesh.elNodes
and

Code: Select all

App.ActiveDocument.HarrysBridgeMesh.FemMesh.noCoords
User avatar
HarryvL
Veteran
Posts: 1335
Joined: Sat Jan 06, 2018 7:38 pm
Location: Netherlands

Re: Access to nodal results on element by element basis

Post by HarryvL »

Yes that would work and I guess make them available to the console and external scripts?
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Access to nodal results on element by element basis

Post by bernd »

HarryvL wrote: Fri Jun 29, 2018 4:51 am
HarryvL wrote: Sat Jun 02, 2018 9:45 am Hi, I want to do some post processing for which I need to cycle through the elements of the result mesh and for each element access the element nodal results and nodal coordinates. So not simply run through all nodes, but access them on an element by element basis. How can I best do that? Thanks. Harry
Note to self and others:

(EDIT: tidied up the following description)

mesh_data['Tetra10Elem'] ------- Dictionary where the "key" is the element_number and the "values" are the global_node_number Tuples
mesh_data['Nodes'] ---------------- Dictionary where the "key" is the global_node_number and the "values" are the node_coordinates Tuples

So I now use the following arrays to cycle through global nodes on an element-by-element basis:

elNodes=numpy.asarray(mesh_data['Tetra10Elem'].values()) --------- elNodes[i,j]=global node number of local node j in element i
noCoord=numpy.asarray(mesh_data['Nodes'].values()) ------------------ noCoord[i,j]=coordinate j (0=x,1=y,2=z) for global node i

these are the arrays typically available in a finite element code.
open FEM 3D example from StartWorkBench an run the following code ...

Code: Select all

femmesh = App.ActiveDocument.Box_Mesh.FemMesh

elements = femmesh.Edges + femmesh.Faces + femmesh.Volumes
elNodes = {}
for e in elements:
    elNodes[e] = femmesh.getElementNodes(e)

nodes = femmesh.Nodes
noCoord = {}
for n in  nodes:
    noCoord[n] = (nodes[n].x, nodes[n].y, nodes[n].z)

elNodes
noCoord
Are these the arrays you are looking for?
Post Reply