diff --git a/src/Mod/Fem/TestFem.py b/src/Mod/Fem/TestFem.py index f839a9983e..ded057e795 100644 --- a/src/Mod/Fem/TestFem.py +++ b/src/Mod/Fem/TestFem.py @@ -30,6 +30,7 @@ from femtest.testcommon import FemCommon from femtest.testobject import FemObject from femtest.testmesh import FemMeshTest +from femtest.testmesh import TestEleTetra10 from femtest.testccxtools import FemCcxAnalysisTest from femtest.testsolverframework import SolverFrameWorkTest diff --git a/src/Mod/Fem/femtest/testmesh.py b/src/Mod/Fem/femtest/testmesh.py index d0e821eaa4..21e3f497b9 100644 --- a/src/Mod/Fem/femtest/testmesh.py +++ b/src/Mod/Fem/femtest/testmesh.py @@ -74,200 +74,6 @@ 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 - fcc_print(outfile) - fcc_print(testfile) - import feminout.importToolsFem - import feminout.importInpMesh - femmesh.writeABAQUS(outfile, 1, False) # write the mesh - femmesh_outfile = feminout.importToolsFem.make_femmesh(feminout.importInpMesh.read_inp(outfile)) # read the mesh from written mesh - femmesh_testfile = feminout.importToolsFem.make_femmesh(feminout.importInpMesh.read_inp(testfile)) # read the mesh from test mesh - # reading the test mesh - # fcc_print([femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])]) - self.assertEqual( - femmesh_testfile.Nodes, - expected_nodes['nodes'], - "Test reading " + elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" - ) - self.assertEqual( - [femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])], - expected_elem['volumes'], - "Test reading " + elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" - ) - # reading the written mesh - self.assertEqual( - femmesh_outfile.Nodes, - expected_nodes['nodes'], - "Test reading " + elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" - ) - self.assertEqual( - [femmesh_outfile.Volumes[0], femmesh_outfile.getElementNodes(femmesh_outfile.Volumes[0])], - expected_elem['volumes'], - "Test reading " + elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" - ) - # both - 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[0], femmesh_outfile.getElementNodes(femmesh_outfile.Volumes[0])], - [femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])], - "Test writing " + elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" - ) - - filetyp = 'unv' - outfile = base_outfile + filetyp - testfile = base_testfile + filetyp - fcc_print(outfile) - fcc_print(testfile) - femmesh.write(outfile) # write the mesh - femmesh_outfile = Fem.read(outfile) # read the mesh from written mesh - femmesh_testfile = Fem.read(testfile) # read the mesh from test mesh - # reading the test mesh - self.assertEqual( - femmesh_testfile.Nodes, - expected_nodes['nodes'], - "Test writing " + elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" - ) - self.assertEqual( - [femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])], - expected_elem['volumes'], - "Test writing " + elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" - ) - # reading the written mesh - self.assertEqual( - femmesh_outfile.Nodes, - expected_nodes['nodes'], - "Test writing " + elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" - ) - self.assertEqual( - [femmesh_outfile.Volumes[0], femmesh_outfile.getElementNodes(femmesh_outfile.Volumes[0])], - expected_elem['volumes'], - "Test writing " + elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" - ) - # both - 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 = 'z88' - outfile = base_outfile + filetyp - testfile = base_testfile + filetyp - fcc_print(outfile) - fcc_print(testfile) - femmesh.write(outfile) # write the mesh - import feminout.importZ88Mesh - femmesh_testfile = feminout.importZ88Mesh.read(outfile) # read the mesh from written mesh - femmesh_outfile = feminout.importZ88Mesh.read(testfile) # read the mesh from test mesh - # reading the test mesh - self.assertEqual( - femmesh_testfile.Nodes, - expected_nodes['nodes'], - "Test writing " + elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" - ) - self.assertEqual( - [femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])], - expected_elem['volumes'], - "Test writing " + elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" - ) - # reading the written mesh - self.assertEqual( - femmesh_outfile.Nodes, - expected_nodes['nodes'], - "Test writing " + elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" - ) - self.assertEqual( - [femmesh_outfile.Volumes[0], femmesh_outfile.getElementNodes(femmesh_outfile.Volumes[0])], - expected_elem['volumes'], - "Test writing " + elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" - ) - # both - 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) @@ -321,3 +127,216 @@ class FemMeshTest(unittest.TestCase): def tearDown(self): FreeCAD.closeDocument(self.doc_name) pass + + +class TestEleTetra10(unittest.TestCase): + + def setUp(self): + self.doc_name = "TestEleTetra10" + try: + FreeCAD.setActiveDocument(self.doc_name) + except: + FreeCAD.newDocument(self.doc_name) + finally: + FreeCAD.setActiveDocument(self.doc_name) + self.active_doc = FreeCAD.ActiveDocument + + self.elem = 'tetra10' + self.base_testfile = testtools.get_fem_test_home_dir() + 'mesh/' + self.elem + '_mesh.' + self.base_outfile = testtools.get_fem_test_tmp_dir() + '/' + self.elem + '_mesh.' + # 10 node tetrahedron --> 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]) + self.femmesh = femmesh + self.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), + } + } + self.expected_elem = { + 'volcount': 1, 'tetcount': 1, 'volumes': [1, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)] + } + ''' + fcc_print('\n') + fcc_print(expected_nodes) + fcc_print(expected_elem) + fcc_print('\n') + ''' + + def test_tetra10_create(self): + fcc_print('test creating tetra10 \n') + node_data = { + 'count': self.femmesh.NodeCount, + 'nodes': self.femmesh.Nodes + } + elem_data = { + 'volcount': self.femmesh.VolumeCount, + 'tetcount': self.femmesh.TetraCount, + 'volumes': [self.femmesh.Volumes[0], self.femmesh.getElementNodes(self.femmesh.Volumes[0])] + } + self.assertEqual(node_data, self.expected_nodes, "Nodes of Python created " + self.elem + "mesh element are unexpected") + self.assertEqual(elem_data, self.expected_elem, "Elements of Python created " + self.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" + ''' + + def test_tetra10_inp(self): + fcc_print(self.elem + 'tetra10 inp file format.\n') + filetyp = 'inp' + outfile = self.base_outfile + filetyp + testfile = self.base_testfile + filetyp + fcc_print(outfile) + fcc_print(testfile) + import feminout.importToolsFem + import feminout.importInpMesh + self.femmesh.writeABAQUS(outfile, 1, False) # write the mesh + femmesh_outfile = feminout.importToolsFem.make_femmesh(feminout.importInpMesh.read_inp(outfile)) # read the mesh from written mesh + femmesh_testfile = feminout.importToolsFem.make_femmesh(feminout.importInpMesh.read_inp(testfile)) # read the mesh from test mesh + # reading the test mesh + # fcc_print([femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])]) + self.assertEqual( + femmesh_testfile.Nodes, + self.expected_nodes['nodes'], + "Test reading " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" + ) + self.assertEqual( + [femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])], + self.expected_elem['volumes'], + "Test reading " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" + ) + # reading the written mesh + self.assertEqual( + femmesh_outfile.Nodes, + self.expected_nodes['nodes'], + "Test reading " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" + ) + self.assertEqual( + [femmesh_outfile.Volumes[0], femmesh_outfile.getElementNodes(femmesh_outfile.Volumes[0])], + self.expected_elem['volumes'], + "Test reading " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" + ) + # both + self.assertEqual( + femmesh_outfile.Nodes, + femmesh_testfile.Nodes, + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" + ) + self.assertEqual( + [femmesh_outfile.Volumes[0], femmesh_outfile.getElementNodes(femmesh_outfile.Volumes[0])], + [femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])], + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" + ) + + def test_tetra10_unv(self): + filetyp = 'unv' + outfile = self.base_outfile + filetyp + testfile = self.base_testfile + filetyp + fcc_print(outfile) + fcc_print(testfile) + self.femmesh.write(outfile) # write the mesh + femmesh_outfile = Fem.read(outfile) # read the mesh from written mesh + femmesh_testfile = Fem.read(testfile) # read the mesh from test mesh + # reading the test mesh + self.assertEqual( + femmesh_testfile.Nodes, + self.expected_nodes['nodes'], + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" + ) + self.assertEqual( + [femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])], + self.expected_elem['volumes'], + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" + ) + # reading the written mesh + self.assertEqual( + femmesh_outfile.Nodes, + self.expected_nodes['nodes'], + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" + ) + self.assertEqual( + [femmesh_outfile.Volumes[0], femmesh_outfile.getElementNodes(femmesh_outfile.Volumes[0])], + self.expected_elem['volumes'], + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" + ) + # both + self.assertEqual( + femmesh_outfile.Nodes, + femmesh_testfile.Nodes, + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" + ) + self.assertEqual( + femmesh_outfile.Volumes, + femmesh_testfile.Volumes, + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" + ) + + def test_tetra10_z88(self): + filetyp = 'z88' + outfile = self.base_outfile + filetyp + testfile = self.base_testfile + filetyp + fcc_print(outfile) + fcc_print(testfile) + self.femmesh.write(outfile) # write the mesh + import feminout.importZ88Mesh + femmesh_testfile = feminout.importZ88Mesh.read(outfile) # read the mesh from written mesh + femmesh_outfile = feminout.importZ88Mesh.read(testfile) # read the mesh from test mesh + # reading the test mesh + self.assertEqual( + femmesh_testfile.Nodes, + self.expected_nodes['nodes'], + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" + ) + self.assertEqual( + [femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])], + self.expected_elem['volumes'], + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" + ) + # reading the written mesh + self.assertEqual( + femmesh_outfile.Nodes, + self.expected_nodes['nodes'], + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" + ) + self.assertEqual( + [femmesh_outfile.Volumes[0], femmesh_outfile.getElementNodes(femmesh_outfile.Volumes[0])], + self.expected_elem['volumes'], + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" + ) + # both + self.assertEqual( + femmesh_outfile.Nodes, + femmesh_testfile.Nodes, + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n" + ) + self.assertEqual( + femmesh_outfile.Volumes, + femmesh_testfile.Volumes, + "Test writing " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n" + ) + + def tearDown(self): + FreeCAD.closeDocument(self.doc_name) + pass