FEM Result Export to File

About the development of the FEM module/workbench.

Moderator: bernd

whoneyc
Posts: 22
Joined: Tue Apr 20, 2021 9:44 pm

FEM Result Export to File

Post by whoneyc »

I would like to export my FEM results as a usable model. I can replicate similar requests I found while searching (https://forum.freecadweb.org/viewtopic.php?t=68433 and https://forum.freecadweb.org/viewtopic.php?f=18&t=48882) to create an array of Vector objects. How do I put this in a form which I can export as a mesh or solid? As an alternative, when I try to do something dead-simple like File>Export...>obj to take a copy of the result mesh, I return a mostly empty file. It feels like I am missing something obvious. Is there some way to pipe the Vector array into a mesh file which I can save?

OS: Ubuntu 20.04.5 LTS (KDE/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Branch: unknown
Hash: 0d9536ed3e8c7f40197b5606e1b7873625e1d6fe
Python version: 3.8.10
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.5.2
Locale: English/United States (en_US)


Example file seems unnecessary for this question, but I can provide a cube on request.
User avatar
NewJoker
Veteran
Posts: 3018
Joined: Sun Oct 11, 2020 7:49 pm

Re: FEM Result Export to File

Post by NewJoker »

This tool may help you: FEM FemMesh2Mesh
thschrader
Veteran
Posts: 3129
Joined: Sat May 20, 2017 12:06 pm
Location: Germany

Re: FEM Result Export to File

Post by thschrader »

NewJoker wrote: Thu Sep 15, 2022 9:00 pm This tool may help you: FEM FemMesh2Mesh
Thanks.
I used the script to generate the obj-mesh from FEM-result.
How can I get the deformed mesh? As a start to run FEM
with shell imperfections.
shell_imperfections.JPG
shell_imperfections.JPG (71.96 KiB) Viewed 2157 times
whoneyc
Posts: 22
Joined: Tue Apr 20, 2021 9:44 pm

Re: FEM Result Export to File

Post by whoneyc »

NewJoker wrote: Thu Sep 15, 2022 9:00 pm This tool may help you: FEM FemMesh2Mesh
That tool seemed promising, but it seems it only outputs the starting mesh not the displacement mesh. It looks like thschrader is asking the same thing.
User avatar
NewJoker
Veteran
Posts: 3018
Joined: Sun Oct 11, 2020 7:49 pm

Re: FEM Result Export to File

Post by NewJoker »

@thschrader @whoneyc According to the description on the wiki, this tool can export the deformed mesh but only for solid elements. For shell elements, undeformed mesh is exported. But maybe it wouldn’t be very difficult to add a code that could handle this.
whoneyc
Posts: 22
Joined: Tue Apr 20, 2021 9:44 pm

Re: FEM Result Export to File

Post by whoneyc »

NewJoker wrote: Fri Sep 16, 2022 5:03 pm But maybe it wouldn’t be very difficult to add a code that could handle this.
I agree, but this is my first time looking at FreeCAD scripting. Please bear with my newb problems here.

I have two methods to generate similar outputs. The first is to look at the FemMesh2Mesh output which follows the format:

Code: Select all

out_mesh = femmesh.femmesh2mesh.femmesh_2_mesh(FreeCAD.ActiveDocument.ResultMesh.FemMesh)
Mesh.show(Mesh.Mesh(out_mesh))
FreeCAD.ActiveDocument.ResultMesh.ViewObject.hide()
Next, I look at the output from @bernd 's code in the other thread:

Code: Select all

doc = App.ActiveDocument
resnodes_notdeformed = list(doc.ResultMesh.FemMesh.Nodes.values())
displacements = doc.CCX_Results.DisplacementVectors
sum = [a + b for a, b in zip(resnodes_notdeformed, displacements)]
Now I have two outputs which appear similar. Both are Python lists of 3 membered Vector objects. Great. I would expect the values to be the only thing different between two mesh-like objects would be the values based on the displacement when the operation occurs on a single deformed object before and after. However, the length of the list changes. For my test object, I start with an object containing 355 Vectors and the displaced object has 302.

When I attempt to run

Code: Select all

Mesh.show(Mesh.Mesh(sum))
I get an IndexError (list out of range). What is happening here? I will admit I am poking at something I am not experienced with, but I don't understand why the number of Vectors would change when performing the sum with the displacement vectors.
thschrader
Veteran
Posts: 3129
Joined: Sat May 20, 2017 12:06 pm
Location: Germany

Re: FEM Result Export to File

Post by thschrader »

NewJoker wrote: Fri Sep 16, 2022 5:03 pm @thschrader @whoneyc According to the description on the wiki, this tool can export the deformed mesh but only for solid elements. For shell elements, undeformed mesh is exported. But maybe it wouldn’t be very difficult to add a code that could handle this.
OK. But what must I do? Workflow?
Thanks, Thomas
fandaL
Posts: 440
Joined: Thu Jul 24, 2014 8:29 am

Re: FEM Result Export to File

Post by fandaL »

thschrader wrote: Sat Sep 17, 2022 7:44 am
NewJoker wrote: Fri Sep 16, 2022 5:03 pm @thschrader @whoneyc According to the description on the wiki, this tool can export the deformed mesh but only for solid elements. For shell elements, undeformed mesh is exported. But maybe it wouldn’t be very difficult to add a code that could handle this.
OK. But what must I do? Workflow?
Thanks, Thomas
Select the mesh object and the result file “CCX_Results”. Click FEM mesh to mesh. The new mesh object should appear (corresponding to deformation scale = 1).

For me it works for 3D as well as 2D mesh. Wiki seems to be outdated.

Note that for buckling and frequency analysis, deformation is normalized. CalculiX finds only the shape, not the scale. So the scale is real only for static (or thermomechanical) analysis.

Code: Select all

OS: Ubuntu Core 20 (ubuntu:GNOME/ubuntu)
Word size of FreeCAD: 64-bit
Version: 0.20.1.29177 +233 (Git) Snap 245
Build type: Release
Branch: tag: 0.20.1
Hash: f5d13554ecc7a456fb6e970568ae5c74ba727563
Python 3.8.10, Qt 5.15.3, Coin 4.0.0, Vtk 7.1.1, OCC 7.6.3
Locale: English/United States (en_US)
whoneyc
Posts: 22
Joined: Tue Apr 20, 2021 9:44 pm

Re: FEM Result Export to File

Post by whoneyc »

fandaL wrote: Sun Sep 18, 2022 10:11 am The new mesh object should appear (corresponding to deformation scale = 1).
This thread is getting a little derailed. I'm looking for the mesh object with deformation scale = 100 not 1.
fandaL
Posts: 440
Joined: Thu Jul 24, 2014 8:29 am

Re: FEM Result Export to File

Post by fandaL »

whoneyc wrote: Mon Sep 19, 2022 7:05 pm I'm looking for the mesh object with deformation scale = 100 not 1.
OK. I think it would be nice to add a scale as a parameter, but for now, you can do it manually:

1) Copy the source code to the FreeCAD python console
https://github.com/FreeCAD/FreeCAD/blob ... #L171-L180
where the highlighted block is changed to

Code: Select all

            triangle = [myFemMesh.getNodeById(face_nodes[0]) + dispVec0 * 100,
                        myFemMesh.getNodeById(face_nodes[1]) + dispVec1 * 100,
                        myFemMesh.getNodeById(face_nodes[2]) + dispVec2 * 100]
            output_mesh.extend(triangle)
            # print("my triangle: ", triangle)
            if len(face_nodes) == 4:
                dispVec3 = myResults.DisplacementVectors[myResults.NodeNumbers.index(face_nodes[3])]
                triangle = [myFemMesh.getNodeById(face_nodes[2]) + dispVec2 * 100,
                            myFemMesh.getNodeById(face_nodes[3]) + dispVec3 * 100,
                            myFemMesh.getNodeById(face_nodes[0]) + dispVec0 * 100]
(I have added * 100 six times)

2) select CCX_Results object and mesh object

3) run the modified function by

Code: Select all

import Mesh
out_mesh = femmesh_2_mesh(FreeCAD.ActiveDocument.ResultMesh.FemMesh, FreeCAD.ActiveDocument.CCX_Results)
Mesh.show(Mesh.Mesh(out_mesh))
Post Reply