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 »

do you implement this in Vtk, in the result task panel or as macro?
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 »

Same as reinforcement ratios and Mohr Coulomb. Available both in result object (type rx, ry, rz or mc in equation panel) and in VTK (for export to Paraview). Works nicely.
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 »

So not as Macro
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 »

So currently studying importCcxFrdResults(), readResult(), importToolsFem.make_femmesh(), ObjectsFem.makeMeshResult(), ObjectsFem.makeResultMechanical(), importToolsFem.fill_femtrsult_mechanical()
.......
to see how it relates to the App.ActiveDocument.Calculix_static_results.NodeNumbers.index(n) you mentioned.

A good, but tough, learning experience :D
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 »

If I would call my function from fill_femresult_mechanical(), like I did for the reinforcement ratios and Mohr Coulomb stress, then I guess I could simply pass the results object and inside my function extract stress by element nodes as follows?

Code: Select all

def MyFunction(results):
	elements=results[“Penta15Elem”] 
	for elem in elements:
		for n in elem:
			sig1=results.PrincipalMax[n]
#			etc.
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: Mon Jun 04, 2018 9:07 pm If I would call my function from fill_femresult_mechanical(), like I did for the reinforcement ratios and Mohr Coulomb stress, then I guess I could simply pass the results object and inside my function extract stress by element nodes as follows?

Code: Select all

def MyFunction(results):
	elements=results[“Penta15Elem”] 
	for elem in elements:
		for n in elem:
			sig1=results.PrincipalMax[n]
#			etc.
Well, that was completely wrong. Mesh information is stored in a Dictionary and results are separately stored in a PythonFeature object :shock:

So I need to pass both to my function:

Code: Select all

def fill_femresult_mechanical(results, result_set, span,mesh_data):
	info_by_element(results, mesh_data)
	return
	
def info_by_element(results, mesh_data):
	print("results: {}".format(type(results)))        		#FeaturePython
	print("mesh_data: {}".format(type(mesh_data)))    #Dictionary
   
	elements=mesh_data['Tetra10Elem']
    
	for key in elements:
        	nodes=np.asarray(elements[key])
        	count=0
        	for node in nodes:
            		count+=1
            		print("element: {}, element node: {}, node number: {}, Max Principal Stress: {}".format(key, count, node, results.PrincipalMax[node]))
        return
Now this works in principle, but the problem is that the global node number "node" does not correspond with the index for results.PrincipalMax, so I get an "IndexError: list index out of range" error. The search continues :(
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 »

global node number starts with 1, index of results with 0 AFAIK, but I did not had a deeper look at your code ...
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: Tue Jun 05, 2018 8:07 pm Well, that was completely wrong. Mesh information is stored in a Dictionary and results are separately stored in a PythonFeature object :shock:
so you mean inside the method fill_femresult_mechanical ?
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 »

bernd wrote: Tue Jun 05, 2018 8:46 pm global node number starts with 1, index of results with 0 AFAIK, but I did not had a deeper look at your code ...
Yes you are right. That was the simple error. It now works :D
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 »

bernd wrote: Tue Jun 05, 2018 8:50 pm
HarryvL wrote: Tue Jun 05, 2018 8:07 pm Well, that was completely wrong. Mesh information is stored in a Dictionary and results are separately stored in a PythonFeature object :shock:
so you mean inside the method fill_femresult_mechanical ?
At first I thought I could access both the "global node numbers by element" and the "stress results" from the same results object.

I now understand that global numbers by element are stored in a nested Dictionary (a dictionary of dictionaries), where at the first level key = element type (e.g. 'Tetra10Elem') and the values are themselves Dictionaries with key = element number and the values are Tuples containing the nodes for that particular element (in this example 10 values for each element number) :shock:

The stress values are stored in the results object and these can simply be extracted as the attributes for that object, e.g. results.StressValues[n] is the von Mises stress at node n+1 ;)

I call my function indeed in fill_femresult_mechanical. However, as the nested dictionary with global node numbers per element (result_mesh) is not available there, I pass it as an extra parameter in the call of fill_femresult_mechanical in importCcxFrdResults.

Wow, that's a lot more difficult than what I am used to in an old-fashioned Finite Element program.

I may be missing a trick ... if so, then I am eager to be educated :D

Here the final test routine:

Code: Select all

def fill_femresult_mechanical(results, result_set, span, mesh_data):
    
    #bulk of the code removed for clarity
    
    info_by_element(results, mesh_data)

    return results


def info_by_element(results, mesh_data):
    
    print("results: {}".format(type(results)))                 #FeaturePython
    print("mesh_data: {}".format(type(mesh_data)))     #Dictionary
   
    elements=mesh_data['Tetra10Elem']

    print("number of nodes in results.PrincipalMax {}".format(len(results.StressValues)))
        
    max_node = 0
    
    for key in elements:
        nodes = np.asarray(elements[key])
        count = 0
        for node in nodes:
            count += 1
            if node>max_node: max_node = node
            print("element: {}, element node: {}, node number: {}, Max Principal Stress: {}".format(key, count, node, results.StressValues[node-1]))
            
    print("number of nodes: {}".format(max_node))

    return

Post Reply