Plotting results per element

About the development of the FEM module/workbench.

Moderator: bernd

makkemal
Posts: 380
Joined: Wed Apr 29, 2015 12:41 pm

Plotting results per element

Postby makkemal » Mon Sep 10, 2018 4:10 pm

I have gotten back to some development work.
Adding some additional reading features to the dat file reader I am looking for a way to show result per element.

Attached is a file with 12 elements
Demo_fea.fcstd
(8.54 KiB) Downloaded 6 times
For the elements
[37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48.]
I would like to plot a certain set of values for instance
[664.2921 621.23066667 671.21576667 693.0764 664.2921
606.896 614.33466667 635.56533333 621.23066667 635.56533333
685.6079 678.68423333]

The current plotting seem to be by nodes (I may be wrong)
Thanks
Michael
User avatar
bernd
Posts: 7060
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Plotting results per element

Postby bernd » Mon Sep 10, 2018 4:24 pm

hi michael, wwlcome back, great to see you spending time on FEM.

ATM only node results are read into result object. See description of property groups of result object.

bernd
makkemal
Posts: 380
Joined: Wed Apr 29, 2015 12:41 pm

Re: Plotting results per element

Postby makkemal » Wed Sep 12, 2018 2:55 pm

How do I get the element numbers and nodes associated from the Resultmesh ?
In the python console to translate it to the element average ?

Thing moved around a bit since I last looked at this :D
fandaL
Posts: 321
Joined: Thu Jul 24, 2014 8:29 am

Re: Plotting results per element

Postby fandaL » Thu Sep 13, 2018 7:00 am

There is a complication to be mentioned. CalculiX gives nodal values averaged from all adjacent nodes, so if you make another average in the element from its nodes you will get kind of filter since your value (e.g. stress) is more or less influenced by the stresses in neighbouring elements. Imagine you have 2 elements each with different material (stiffness). Even with nodal stresses (averaged from elements) you will get on the boundary stress which is not exact neither for the stiffer nor for the weaker element.

You can look at M. Kraska's script to separate elements https://github.com/mkraska/CalculiX-Exa ... separatepy where in principle you create special nodes for each element and nodes DOFs are paired by *EQUATIONs, already in the inp file to avoid averaging. However, this approach works only for 3D elements, since *EQUATION does not bind rotational DOFs.

Another approach could be to use values from the dat file output where are values at integration points - somewhere inside the element (where is not typical stress extreme).
User avatar
bernd
Posts: 7060
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Plotting results per element

Postby bernd » Thu Sep 13, 2018 9:48 am

@fandaL: good point :)

@michael: open FEM 3D example

Code: Select all

mesh = App.ActiveDocument.Box_Mesh.FemMesh
for v in mesh.Volumes:
    print("Element {0}: Nodes: {1}".format(v, mesh.getElementNodes(v)))


Code: Select all

Python 2.7.14 (default, Jan 16 2018, 16:11:42) [MSC v.1800 64 bit (AMD64)] on win32
Type 'help', 'copyright', 'credits' or 'license' for more information.
>>> mesh = App.ActiveDocument.Box_Mesh.FemMesh
>>> for v in mesh.Volumes:
...     print("Element {0}: Nodes: {1}".format(v, mesh.getElementNodes(v)))
... 
Element 149: Nodes: (40L, 19L, 10L, 20L, 168L, 106L, 196L, 171L, 66L, 107L)
Element 150: Nodes: (10L, 31L, 30L, 40L, 150L, 79L, 149L, 196L, 128L, 129L)
Element 151: Nodes: (38L, 17L, 18L, 47L, 163L, 62L, 166L, 140L, 197L, 198L)
Element 152: Nodes: (32L, 41L, 11L, 12L, 130L, 199L, 152L, 165L, 200L, 56L)
Element 153: Nodes: (12L, 32L, 41L, 42L, 165L, 130L, 200L, 201L, 143L, 92L)
Element 154: Nodes: (42L, 21L, 12L, 22L, 172L, 110L, 201L, 185L, 68L, 123L)
Element 155: Nodes: (10L, 31L, 40L, 11L, 150L, 128L, 196L, 55L, 151L, 202L)
Element 156: Nodes: (11L, 12L, 41L, 21L, 56L, 200L, 199L, 109L, 110L, 173L)
Element 157: Nodes: (20L, 41L, 11L, 40L, 170L, 199L, 108L, 171L, 91L, 202L)
Element 158: Nodes: (20L, 41L, 21L, 11L, 170L, 173L, 67L, 108L, 199L, 109L)
Element 159: Nodes: (32L, 11L, 41L, 31L, 152L, 199L, 130L, 80L, 151L, 131L)
Element 160: Nodes: (11L, 10L, 20L, 40L, 55L, 107L, 108L, 202L, 196L, 171L)
Element 161: Nodes: (38L, 17L, 47L, 37L, 163L, 197L, 140L, 86L, 162L, 141L)
Element 162: Nodes: (38L, 18L, 49L, 48L, 166L, 204L, 203L, 145L, 205L, 206L)
Element 163: Nodes: (46L, 15L, 45L, 36L, 207L, 208L, 96L, 139L, 159L, 137L)
Element 164: Nodes: (47L, 16L, 46L, 37L, 209L, 210L, 97L, 141L, 161L, 138L)
Element 165: Nodes: (18L, 4L, 2L, 49L, 122L, 64L, 63L, 204L, 189L, 190L)
Element 166: Nodes: (18L, 17L, 27L, 47L, 62L, 120L, 121L, 198L, 197L, 183L)
Element 167: Nodes: (38L, 18L, 48L, 47L, 166L, 205L, 145L, 140L, 198L, 98L)
Element 168: Nodes: (12L, 23L, 42L, 22L, 111L, 175L, 201L, 123L, 69L, 185L)
Element 169: Nodes: (26L, 47L, 27L, 17L, 180L, 183L, 73L, 119L, 197L, 120L)
Element 170: Nodes: (50L, 29L, 9L, 6L, 211L, 147L, 212L, 195L, 146L, 53L)
Element 171: Nodes: (27L, 48L, 18L, 47L, 182L, 205L, 121L, 183L, 98L, 198L)
Element 172: Nodes: (8L, 7L, 39L, 50L, 103L, 89L, 167L, 192L, 193L, 213L)
Element 173: Nodes: (40L, 9L, 39L, 30L, 214L, 215L, 90L, 129L, 148L, 126L)
Element 174: Nodes: (42L, 21L, 41L, 12L, 172L, 173L, 92L, 201L, 110L, 200L)
Element 175: Nodes: (50L, 9L, 29L, 39L, 212L, 147L, 211L, 213L, 215L, 127L)
Element 176: Nodes: (29L, 7L, 50L, 39L, 125L, 193L, 211L, 127L, 89L, 213L)
Element 177: Nodes: (31L, 11L, 41L, 40L, 151L, 199L, 131L, 128L, 202L, 91L)
Element 178: Nodes: (47L, 16L, 37L, 17L, 209L, 161L, 141L, 197L, 61L, 162L)
Element 179: Nodes: (40L, 9L, 30L, 10L, 214L, 148L, 129L, 196L, 54L, 149L)
Element 180: Nodes: (2L, 38L, 49L, 1L, 164L, 203L, 190L, 100L, 87L, 191L)
Element 181: Nodes: (2L, 38L, 18L, 49L, 164L, 166L, 63L, 190L, 203L, 204L)
Element 182: Nodes: (48L, 49L, 38L, 3L, 206L, 203L, 145L, 99L, 188L, 142L)
Element 183: Nodes: (38L, 49L, 1L, 3L, 203L, 191L, 87L, 142L, 188L, 88L)
Element 184: Nodes: (49L, 4L, 3L, 48L, 189L, 102L, 188L, 206L, 184L, 99L)
Element 185: Nodes: (28L, 48L, 4L, 18L, 187L, 184L, 75L, 124L, 205L, 122L)
Element 186: Nodes: (49L, 18L, 4L, 48L, 204L, 122L, 189L, 206L, 205L, 184L)
Element 187: Nodes: (7L, 50L, 5L, 29L, 193L, 194L, 76L, 125L, 211L, 77L)
Element 188: Nodes: (50L, 6L, 5L, 29L, 195L, 101L, 194L, 211L, 146L, 77L)
Element 189: Nodes: (50L, 9L, 19L, 6L, 212L, 105L, 216L, 195L, 53L, 104L)
Element 190: Nodes: (50L, 19L, 9L, 39L, 216L, 105L, 212L, 213L, 169L, 215L)
Element 191: Nodes: (50L, 19L, 8L, 6L, 216L, 65L, 192L, 195L, 104L, 52L)
Element 192: Nodes: (40L, 9L, 10L, 19L, 214L, 54L, 196L, 168L, 105L, 106L)
Element 193: Nodes: (51L, 44L, 34L, 14L, 217L, 144L, 218L, 219L, 220L, 156L)
Element 194: Nodes: (51L, 24L, 44L, 14L, 221L, 186L, 217L, 219L, 114L, 220L)
Element 195: Nodes: (25L, 15L, 24L, 51L, 116L, 115L, 71L, 222L, 223L, 221L)
Element 196: Nodes: (43L, 12L, 32L, 13L, 224L, 165L, 133L, 225L, 57L, 153L)
Element 197: Nodes: (43L, 12L, 23L, 42L, 224L, 111L, 174L, 93L, 201L, 175L)
Element 198: Nodes: (43L, 12L, 13L, 23L, 224L, 57L, 225L, 174L, 111L, 112L)
Element 199: Nodes: (43L, 12L, 42L, 32L, 224L, 201L, 93L, 133L, 165L, 143L)
Element 200: Nodes: (34L, 13L, 14L, 44L, 155L, 58L, 156L, 144L, 226L, 220L)
Element 201: Nodes: (14L, 24L, 15L, 51L, 114L, 115L, 59L, 219L, 221L, 223L)
Element 202: Nodes: (23L, 24L, 14L, 44L, 70L, 114L, 113L, 176L, 186L, 220L)
Element 203: Nodes: (33L, 32L, 13L, 43L, 81L, 153L, 154L, 132L, 133L, 225L)
Element 204: Nodes: (34L, 33L, 13L, 43L, 82L, 154L, 155L, 134L, 132L, 225L)
Element 205: Nodes: (35L, 14L, 15L, 51L, 157L, 59L, 158L, 227L, 219L, 223L)
Element 206: Nodes: (25L, 45L, 15L, 51L, 177L, 208L, 116L, 222L, 228L, 223L)
Element 207: Nodes: (44L, 43L, 13L, 23L, 94L, 225L, 226L, 176L, 174L, 112L)
Element 208: Nodes: (35L, 34L, 14L, 51L, 83L, 156L, 157L, 227L, 218L, 219L)
Element 209: Nodes: (46L, 15L, 36L, 16L, 207L, 159L, 139L, 210L, 60L, 160L)
Element 210: Nodes: (36L, 35L, 15L, 45L, 84L, 158L, 159L, 137L, 135L, 208L)
Element 211: Nodes: (37L, 36L, 16L, 46L, 85L, 160L, 161L, 138L, 139L, 210L)
Element 212: Nodes: (25L, 26L, 16L, 46L, 72L, 118L, 117L, 179L, 181L, 210L)
Element 213: Nodes: (47L, 16L, 17L, 26L, 209L, 61L, 197L, 180L, 118L, 119L)
Element 214: Nodes: (47L, 16L, 26L, 46L, 209L, 118L, 180L, 97L, 210L, 181L)
Element 215: Nodes: (27L, 28L, 18L, 48L, 74L, 124L, 121L, 182L, 187L, 205L)
Element 216: Nodes: (35L, 34L, 51L, 45L, 83L, 218L, 227L, 135L, 136L, 228L)
Element 217: Nodes: (13L, 14L, 44L, 23L, 58L, 220L, 226L, 112L, 113L, 176L)
Element 218: Nodes: (44L, 25L, 24L, 51L, 178L, 71L, 186L, 217L, 222L, 221L)
Element 219: Nodes: (44L, 45L, 25L, 51L, 95L, 177L, 178L, 217L, 228L, 222L)
Element 220: Nodes: (46L, 15L, 16L, 25L, 207L, 60L, 210L, 179L, 116L, 117L)
Element 221: Nodes: (46L, 15L, 25L, 45L, 207L, 116L, 179L, 96L, 208L, 177L)
Element 222: Nodes: (50L, 8L, 19L, 39L, 192L, 65L, 216L, 213L, 167L, 169L)
Element 223: Nodes: (35L, 51L, 15L, 45L, 227L, 223L, 158L, 135L, 228L, 208L)
Element 224: Nodes: (34L, 44L, 43L, 13L, 144L, 94L, 134L, 155L, 226L, 225L)
Element 225: Nodes: (51L, 44L, 45L, 34L, 217L, 95L, 228L, 218L, 144L, 136L)
Element 226: Nodes: (9L, 29L, 39L, 30L, 147L, 127L, 215L, 148L, 78L, 126L)
Element 227: Nodes: (40L, 9L, 19L, 39L, 214L, 105L, 168L, 90L, 215L, 169L)
>>> 
User avatar
bernd
Posts: 7060
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Plotting results per element

Postby bernd » Thu Sep 13, 2018 3:07 pm

ahh for the result mesh you should use the result mesh not the mesh for the input file:

Code: Select all

resmesh = App.ActiveDocument.Result_mesh.FemMesh
for v in resmesh.Volumes:
    print("Element {0}: Nodes: {1}".format(v, mesh.getElementNodes(v)))

makkemal
Posts: 380
Joined: Wed Apr 29, 2015 12:41 pm

Re: Plotting results per element

Postby makkemal » Fri Sep 14, 2018 7:06 am

Thanks very useful info :D
makkemal
Posts: 380
Joined: Wed Apr 29, 2015 12:41 pm

Re: Plotting results per element

Postby makkemal » Wed Sep 19, 2018 8:59 am

I have done some updates on the ccxdatfile reader
https://github.com/makkemal/FreeCAD/tre ... sults_read
This was mostly for own use
Since Element plots don't exist I did not update other readings functions.

Here is some code that changes element volumes to nodal values and assigns it to temperature

Code: Select all


from femtools import ccxtools
import FemGui
import ObjectsFem
import numpy as np


ObjectsFem.makeAnalysis(FreeCAD.ActiveDocument, 'Analysis')
FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.ActiveObject)
ObjectsFem.makeSolverCalculixCcxTools(FreeCAD.ActiveDocument)
FemGui.getActiveAnalysis().addObject(FreeCAD.ActiveDocument.ActiveObject)



fea = ccxtools.FemToolsCcx()
import feminout.importCcxDatResults
column=1  #column of interest
dat=feminout.importCcxDatResults.import_dat(u"C:/CalculiX/NGIMASEM2/Demo_prob/lifec.dat","Unnamed")
fea.setup_working_dir('C:/CalculiX/NGIMASEM2/Demo_prob/')
fea.set_base_name('lifec')
fea.load_results()


idxsteps=0
objects=App.ActiveDocument.Analysis.Group
for m in objects:
    if (m.isDerivedFrom('Fem::FemResultObject')):
        nodeval=np.zeros(App.ActiveDocument.Result_mesh.FemMesh.NodeCount) # get number of nodes
        mesh=App.ActiveDocument.Result_mesh.FemMesh
        mesh2num=dat[0]['vol'+str(idxsteps)][:,1]
        meshvalues=dat[0]['vol'+str(idxsteps)][:,column]
        for v in mesh.Volumes:
            idx=np.where(mesh2num == v)
            #print(idx[0])
            value=meshvalues[idx[0]]
            #print(value)
            #print("Element {0}: Nodes: {1}".format(v, mesh.getElementNodes(v)))
            nodesnum=mesh.getElementNodes(v)
            for node in nodesnum:
        	    #print("Node {0}".format(node))
               if nodeval[node-1]==0:
                   nodeval[node-1]=value  # if no Vallue assign 
               else:
                   nodeval[node-1]=(nodeval[node-1]+value)/2 #if value exists average
        #print(nodeval)
        m.Temperature=nodeval.tolist()
        idxsteps+=1


I'm not sure if this should be considered for main branch yet but may be use full for some.
User avatar
bernd
Posts: 7060
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Plotting results per element

Postby bernd » Fri Oct 05, 2018 4:53 am

could you give more informations about this. What is it useful for. If we have a better dat reader, why not integrating it in the main branch. Do you have the code on github too?
makkemal
Posts: 380
Joined: Wed Apr 29, 2015 12:41 pm

Re: Plotting results per element

Postby makkemal » Fri Oct 05, 2018 9:57 am

I use custum coding in calculix to create state variables.(tranfering some information)
Then in the input deck I have the following outputs specified

Code: Select all

*EL PRINT , ELSET=Eall
S,SDV,Evol
The reading of SDV and Evol is added to the Datfilereader in this branch
https://github.com/makkemal/FreeCAD/tre ... sults_read

But I fudge the results to nodes in the script above.
I think the datfilereading section is use ful but only once plotting data per element is avaiable.

Regards
Michael