mesh distortion on reload (only quadratic elements)

About the development of the FEM module/workbench.

Moderator: bernd

wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: mesh distortion on reload (only quadratic elements)

Post by wmayer »

vejmarie wrote:Is this on 32 bits or 64 bits Windows that the issue appears ? That is strange it did work on MacOS and Linux ;). This reminds me why I am not using Windows (I am kidding guys don't worry)
Any idea where exactly in the unv export it's needed to make the enum of the size of an unsigned long? And why doesn't the original Salome source code doesn't do it this way?
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: mesh distortion on reload (only quadratic elements)

Post by wmayer »

sgrogan wrote:Probably git commit 732bd85 shows the problem. The previous git commit 19f8fd4 does not.
I undid the changes for the sizes of the enums in git commit 732bd85 and for me I still got the problems. I used Bernd's project file for import/export. Only after setting the size to unsigned long long (i.e. a size of 8 bytes) it worked on Windows, too.
sgrogan wrote:I can't find "long long" in the FreeCAD sources though. With C++11 "long long" is OK?
MSVC has defined the type __int64 for 8 byte int's. You find a typedef in FCConfig.h that sets int64_t and uint64_t.
UR_ wrote:win 32 bit build is ok.
So, this means that the size of the enum must be equal to the word size in FreeCAD. So, instead of using unsigned long as we do now we have to switch to size_t because this is a typedef to the required type.

As test you can use this test application:

Code: Select all

#include <stdio.h>
int main(int argc, char**)
{
  printf("sizeof(size_t) = %d", sizeof(size_t));
}
When compiled as 64-bit under Windows it prints 8 while for 32-bit it prints 4.
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: mesh distortion on reload (only quadratic elements)

Post by wmayer »

I have pushed a branch which works fine on Win64 and Ubuntu 14.04 64-bit. Please test also on other platforms.

Does anyone know how to create a 2nd order mesh using the Python API so that we could also write a unit test?
User avatar
vejmarie
Posts: 713
Joined: Mon Jan 04, 2016 4:52 pm
Location: Somewhere between France, USA and Taiwan
Contact:

Re: mesh distortion on reload (only quadratic elements)

Post by vejmarie »

wmayer wrote:
vejmarie wrote:Is this on 32 bits or 64 bits Windows that the issue appears ? That is strange it did work on MacOS and Linux ;). This reminds me why I am not using Windows (I am kidding guys don't worry)
Any idea where exactly in the unv export it's needed to make the enum of the size of an unsigned long? And why doesn't the original Salome source code doesn't do it this way?
Salome is not supported on MacOS or Windows, or not tested as much as on Linux, which could explain why they didn't faced this issue.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: mesh distortion on reload (only quadratic elements)

Post by bernd »

wmayer wrote:I have pushed a branch which works fine on Win64 and Ubuntu 14.04 64-bit. Please test also on other platforms.
:D
wmayer wrote:Does anyone know how to create a 2nd order mesh using the Python API so that we could also write a unit test?

Code: Select all

# 10 node tetrahedron --> tetra10 ###############
import Fem
tetra10 = Fem.FemMesh()
tetra10.addNode( 6, 12, 18, 1)
tetra10.addNode( 0,  0, 18, 2)
tetra10.addNode(12,  0, 18, 3)
tetra10.addNode( 6,  6,  0, 4)

tetra10.addNode( 3,  6, 18, 5)
tetra10.addNode( 6,  0, 18, 6)
tetra10.addNode( 9,  6, 18, 7)

tetra10.addNode( 6,  9,  9, 8)
tetra10.addNode( 3,  3,  9, 9)
tetra10.addNode( 9,  3,  9,10)
tetra10.addVolume([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
tetra10

# make a document object, possible, but not needed
obj = App.ActiveDocument.addObject("Fem::FemMeshObject","tetra10")
obj.FemMesh = tetra10
obj.ViewObject.DisplayMode = "Faces, Wireframe & Nodes"


# write and read the mesh
mymeshfile = '/tmp/hallo.unv'
tetra10.write(mymeshfile)
newmesh = Fem.read(mymeshfile)
newmesh

# make a document object, possible, but not needed
obj = App.ActiveDocument.addObject("Fem::FemMeshObject","newtetra10")
obj.FemMesh = newmesh
obj.ViewObject.DisplayMode = "Faces, Wireframe & Nodes"
obj.Placement.Base = (0,30,0)
UR_
Veteran
Posts: 1355
Joined: Tue Jan 03, 2017 8:42 pm

Re: mesh distortion on reload (only quadratic elements)

Post by UR_ »

vejmarie wrote:
Salome is not supported on MacOS or Windows, or not tested as much as on Linux, which could explain why they didn't faced this issue.
Salome users can lay back.
Everything's alright. 8-)

saved and reloaded on Salome 8.2.0 Win64
Screenshot Salome 8.2.0 Win64.png
Screenshot Salome 8.2.0 Win64.png (74.62 KiB) Viewed 1884 times
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: mesh distortion on reload (only quadratic elements)

Post by sgrogan »

wmayer wrote:MSVC has defined the type __int64 for 8 byte int's. You find a typedef in FCConfig.h that sets int64_t and uint64_t.
Thanks for looking. I had seen this as well, but didn't know which would be preferred. I see you've chosen size_t. Out of curiousity what is the difference from uint64_t?
"fight the good fight"
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: mesh distortion on reload (only quadratic elements)

Post by wmayer »

sgrogan wrote:
wmayer wrote:MSVC has defined the type __int64 for 8 byte int's. You find a typedef in FCConfig.h that sets int64_t and uint64_t.
Thanks for looking. I had seen this as well, but didn't know which would be preferred. I see you've chosen size_t. Out of curiousity what is the difference from uint64_t?
I have extended the above example:

Code: Select all

#include <stdio.h>
#include <stdint.h>

int main(int argc, char**)
{
  printf("sizeof(size_t) = %d\n", sizeof(size_t));
  printf("sizeof(uint64_t) = %d\n", sizeof(uint64_t));
}
When building as 32-bit application then the output is 4 for the size_t and of course 8 for the uint64_t. So, I expect that using uint64_t will again break the export of unv files for 32-bit applications.
UR_ wrote:Salome users can lay back.
Everything's alright. 8-)

saved and reloaded on Salome 8.2.0 Win64
But this means that Salome must has solved this issue differently as in their code they don't set the enum sizes.
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: mesh distortion on reload (only quadratic elements)

Post by wmayer »

bernd wrote:
wmayer wrote:Does anyone know how to create a 2nd order mesh using the Python API so that we could also write a unit test?

Code: Select all

# 10 node tetrahedron --> tetra10 ###############
import Fem
tetra10 = Fem.FemMesh()
tetra10.addNode( 6, 12, 18, 1)
tetra10.addNode( 0,  0, 18, 2)
tetra10.addNode(12,  0, 18, 3)
tetra10.addNode( 6,  6,  0, 4)

tetra10.addNode( 3,  6, 18, 5)
tetra10.addNode( 6,  0, 18, 6)
tetra10.addNode( 9,  6, 18, 7)

tetra10.addNode( 6,  9,  9, 8)
tetra10.addNode( 3,  3,  9, 9)
tetra10.addNode( 9,  3,  9,10)
tetra10.addVolume([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
tetra10

# make a document object, possible, but not needed
obj = App.ActiveDocument.addObject("Fem::FemMeshObject","tetra10")
obj.FemMesh = tetra10
obj.ViewObject.DisplayMode = "Faces, Wireframe & Nodes"


# write and read the mesh
mymeshfile = '/tmp/hallo.unv'
tetra10.write(mymeshfile)
newmesh = Fem.read(mymeshfile)
newmesh

# make a document object, possible, but not needed
obj = App.ActiveDocument.addObject("Fem::FemMeshObject","newtetra10")
obj.FemMesh = newmesh
obj.ViewObject.DisplayMode = "Faces, Wireframe & Nodes"
obj.Placement.Base = (0,30,0)
Thank you very much.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: mesh distortion on reload (only quadratic elements)

Post by bernd »

wmayer wrote:
bernd wrote:
wmayer wrote:Does anyone know how to create a 2nd order mesh using the Python API so that we could also write a unit test?

Code: Select all

...
Thank you very much.
might be helpful too ...

Code: Select all

tetra10.Volume
newmesh.Volume

Code: Select all

>>> 
>>> tetra10.Volume
432 mm^3
>>> newmesh.Volume
432 mm^3
>>> 
Post Reply