FEM: unit tests, add various tetra10 mesh element tests

This commit is contained in:
Bernd Hahnebach
2018-03-19 21:14:36 +01:00
committed by Yorik van Havre
parent 5e79d4b44e
commit e21c34a562
6 changed files with 188 additions and 1 deletions

View File

@@ -162,6 +162,12 @@ SET(FemTestsElmer_SRCS
femtest/testfiles/elmer/ELMERSOLVER_STARTINFO
)
SET(FemTestsMesh_SRCS
femtest/testfiles/mesh/__init__.py
femtest/testfiles/mesh/tetra10_mesh.inp
femtest/testfiles/mesh/tetra10_mesh.unv
)
SET(FemTools_SRCS
femtools/__init__.py
femtools/ccxtools.py
@@ -207,6 +213,7 @@ SET(FemAllScripts
${FemTestsFiles_SRCS}
${FemTestsCcx_SRCS}
${FemTestsElmer_SRCS}
${FemTestsMesh_SRCS}
${FemTools_SRCS}
${FemObjectsScripts_SRCS}
)
@@ -235,6 +242,7 @@ INSTALL(FILES ${FemTests_SRCS} DESTINATION Mod/Fem/femtest)
INSTALL(FILES ${FemTestsFiles_SRCS} DESTINATION Mod/Fem/femtest/testfiles)
INSTALL(FILES ${FemTestsCcx_SRCS} DESTINATION Mod/Fem/femtest/testfiles/ccx)
INSTALL(FILES ${FemTestsElmer_SRCS} DESTINATION Mod/Fem/femtest/testfiles/elmer)
INSTALL(FILES ${FemTestsMesh_SRCS} DESTINATION Mod/Fem/femtest/testfiles/mesh)
INSTALL(FILES ${FemTools_SRCS} DESTINATION Mod/Fem/femtools)
INSTALL(FILES ${FemObjectsScripts_SRCS} DESTINATION Mod/Fem/femobjects)

View File

@@ -22,7 +22,7 @@
# * *
# ***************************************************************************/
import Fem
import FreeCAD
import ObjectsFem
import unittest

View File

@@ -0,0 +1,29 @@
# ***************************************************************************
# * *
# * Copyright (c) 2017 - Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
__title__ = "Fem test cases"
__author__ = "Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"
## @package test_files
# \ingroup Fem
# \brief Fem test cases

View File

@@ -0,0 +1,24 @@
** written by FreeCAD inp file writer for CalculiX,Abaqus meshes
** highest dimension mesh elements only.
** Nodes
*Node, NSET=Nall
1, 6, 12, 18
2, 0, 0, 18
3, 12, 0, 18
4, 6, 6, 0
5, 3, 6, 18
6, 6, 0, 18
7, 9, 6, 18
8, 6, 9, 9
9, 3, 3, 9
10, 9, 3, 9
** Volume elements
*Element, TYPE=C3D10, ELSET=Evolumes
1, 2, 1, 3, 4, 5, 7, 6, 9, 8, 10
** Define element set Eall
*ELSET, ELSET=Eall
Evolumes

View File

@@ -0,0 +1,46 @@
-1
164
1 SI: Meter (newton) 2
1.0000000000000000E+0 1.0000000000000000E+0 1.0000000000000000E+0
2.7314999999999998E+2
-1
-1
2420
1
SMESH_Mesh
1 0 0
Global Cartesian Coordinate System
1.0000000000000000E+0 0.0000000000000000E+0 0.0000000000000000E+0
0.0000000000000000E+0 1.0000000000000000E+0 0.0000000000000000E+0
0.0000000000000000E+0 0.0000000000000000E+0 1.0000000000000000E+0
0.0000000000000000E+0 0.0000000000000000E+0 0.0000000000000000E+0
-1
-1
2411
1 1 1 11
6.0000000000000000E+00 1.2000000000000000E+01 1.8000000000000000E+01
2 1 1 11
0.0000000000000000E+00 0.0000000000000000E+00 1.8000000000000000E+01
3 1 1 11
1.2000000000000000E+01 0.0000000000000000E+00 1.8000000000000000E+01
4 1 1 11
6.0000000000000000E+00 6.0000000000000000E+00 0.0000000000000000E+00
5 1 1 11
3.0000000000000000E+00 6.0000000000000000E+00 1.8000000000000000E+01
6 1 1 11
6.0000000000000000E+00 0.0000000000000000E+00 1.8000000000000000E+01
7 1 1 11
9.0000000000000000E+00 6.0000000000000000E+00 1.8000000000000000E+01
8 1 1 11
6.0000000000000000E+00 9.0000000000000000E+00 9.0000000000000000E+00
9 1 1 11
3.0000000000000000E+00 3.0000000000000000E+00 9.0000000000000000E+00
10 1 1 11
9.0000000000000000E+00 3.0000000000000000E+00 9.0000000000000000E+00
-1
-1
2412
1 118 2 1 7 10
1 7 3 6 2 5 8 10
9 4
-1

View File

@@ -22,6 +22,7 @@
# * *
# ***************************************************************************/
import Fem
import FreeCAD
import unittest
@@ -72,6 +73,85 @@ class FemMeshTest(unittest.TestCase):
self.assertEqual(node_data, expected_nodes, "Nodes of Python created seg3 element are unexpected")
self.assertEqual(edge_data, expected_edges, "Edges of Python created seg3 element are unexpected")
def test_mesh_tetra10(self):
# 10 node tetrahedron --> tetra10
elem = 'tetra10'
femmesh = Fem.FemMesh()
femmesh.addNode(6, 12, 18, 1)
femmesh.addNode(0, 0, 18, 2)
femmesh.addNode(12, 0, 18, 3)
femmesh.addNode(6, 6, 0, 4)
femmesh.addNode(3, 6, 18, 5)
femmesh.addNode(6, 0, 18, 6)
femmesh.addNode(9, 6, 18, 7)
femmesh.addNode(6, 9, 9, 8)
femmesh.addNode(3, 3, 9, 9)
femmesh.addNode(9, 3, 9, 10)
femmesh.addVolume([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
node_data = {
'count': femmesh.NodeCount,
'nodes': femmesh.Nodes
}
elem_data = {'volcount': femmesh.VolumeCount, 'tetcount': femmesh.TetraCount, 'volumes': {
femmesh.Volumes[0], femmesh.getElementNodes(femmesh.Volumes[0]),
}}
expected_nodes = {'count': 10, 'nodes': {
1: FreeCAD.Vector(6.0, 12.0, 18.0),
2: FreeCAD.Vector(0.0, 0.0, 18.0),
3: FreeCAD.Vector(12.0, 0.0, 18.0),
4: FreeCAD.Vector(6.0, 6.0, 0.0),
5: FreeCAD.Vector(3.0, 6.0, 18.0),
6: FreeCAD.Vector(6.0, 0.0, 18.0),
7: FreeCAD.Vector(9.0, 6.0, 18.0),
8: FreeCAD.Vector(6.0, 9.0, 9.0),
9: FreeCAD.Vector(3.0, 3.0, 9.0),
10: FreeCAD.Vector(9.0, 3.0, 9.0),
}}
expected_elem = {'volcount': 1, 'tetcount': 1, 'volumes': {
1, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
}}
'''
fcc_print('\n')
fcc_print(elem_data)
fcc_print(expected_elem)
fcc_print('\n')
'''
self.assertEqual(node_data, expected_nodes, "Nodes of Python created " + elem + "mesh element are unexpected")
self.assertEqual(elem_data, expected_elem, "Elements of Python created " + elem + "mesh element are unexpected")
'''
obj = doc.addObject("Fem::FemMeshObject" , elem)
obj.FemMesh = femmesh
obj.Placement.Base = (30,50,0)
obj.ViewObject.DisplayMode = "Faces, Wireframe & Nodes"
'''
fcc_print(elem + 'export tests.\n')
base_outfile = testtools.get_fem_test_tmp_dir() + '/' + elem + '_mesh.'
base_testfile = testtools.get_fem_test_home_dir() + 'mesh/' + elem + '_mesh.'
filetyp = 'inp'
outfile = base_outfile + filetyp
testfile = base_testfile + filetyp
femmesh.writeABAQUS(outfile, 1, False)
import feminout.importToolsFem
import feminout.importInpMesh
femmesh_outfile = feminout.importToolsFem.make_femmesh(feminout.importInpMesh.read_inp(outfile))
femmesh_testfile = feminout.importToolsFem.make_femmesh(feminout.importInpMesh.read_inp(testfile))
self.assertEqual(femmesh_outfile.Nodes, femmesh_testfile.Nodes, "Test writing " + elem + " mesh to " + filetyp + " file failed. Nodes are different.\n")
self.assertEqual(femmesh_outfile.Volumes, femmesh_testfile.Volumes, "Test writing " + elem + " mesh to " + filetyp + " file failed. Volumes are different.\n")
filetyp = 'unv'
outfile = base_outfile + filetyp
testfile = base_testfile + filetyp
femmesh.write(outfile)
femmesh_outfile = Fem.read(outfile)
femmesh_testfile = Fem.read(testfile)
self.assertEqual(femmesh_outfile.Nodes, femmesh_testfile.Nodes, "Test writing " + elem + " mesh to " + filetyp + " file failed. Nodes are different.\n")
self.assertEqual(femmesh_outfile.Volumes, femmesh_testfile.Volumes, "Test writing " + elem + " mesh to " + filetyp + " file failed. Volumes are different.\n")
def test_unv_save_load(self):
tetra10 = Fem.FemMesh()
tetra10.addNode(6, 12, 18, 1)