From d317f64f0664db7ef06aee849e78eb35dbf5874c Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Tue, 11 Dec 2018 13:54:59 +0100 Subject: [PATCH] FEM: inp mesh reader, add def to return the FemMesh only (no Document obj) --- src/Mod/Fem/feminout/importInpMesh.py | 25 +++++++++++++++++-------- src/Mod/Fem/femtest/testmesh.py | 9 ++++----- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Mod/Fem/feminout/importInpMesh.py b/src/Mod/Fem/feminout/importInpMesh.py index f86dbbdfec..477605bc50 100644 --- a/src/Mod/Fem/feminout/importInpMesh.py +++ b/src/Mod/Fem/feminout/importInpMesh.py @@ -59,19 +59,28 @@ def insert(filename, docname): # ********* module specific methods ********* -def import_inp(filename): - "create imported objects in FreeCAD, currently only FemMesh" - - m = read_inp(filename) +def read(filename): + '''read a FemMesh from a inp mesh file and return the FemMesh + ''' + # no document object is created, just the FemMesh is returned + mesh_data = read_inp(filename) from . import importToolsFem - mesh = importToolsFem.make_femmesh(m) + return importToolsFem.make_femmesh(mesh_data) + + +def import_inp(filename): + '''read a FEM mesh from a Z88 mesh file and insert a FreeCAD FEM Mesh object in the ActiveDocument + ''' + femmesh = read(filename) mesh_name = os.path.splitext(os.path.basename(filename))[0] - mesh_object = FreeCAD.ActiveDocument.addObject('Fem::FemMeshObject', mesh_name) - mesh_object.FemMesh = mesh + if femmesh: + mesh_object = FreeCAD.ActiveDocument.addObject('Fem::FemMeshObject', mesh_name) + mesh_object.FemMesh = femmesh def read_inp(file_name): - "read .inp file, currently only the mesh" + '''read .inp file ''' + # ATM only mesh reading is supported (no boundary conditions) class elements(): diff --git a/src/Mod/Fem/femtest/testmesh.py b/src/Mod/Fem/femtest/testmesh.py index 8cfcd5b396..8ad10c72d6 100644 --- a/src/Mod/Fem/femtest/testmesh.py +++ b/src/Mod/Fem/femtest/testmesh.py @@ -136,11 +136,10 @@ class FemMeshTest(unittest.TestCase): 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.femmesh.writeABAQUS(outfile, 1, False) # write the mesh + from feminout.importInpMesh import read as read_inp + femmesh_outfile = read_inp(outfile) # read the mesh from written mesh + femmesh_testfile = read_inp(testfile) # read the mesh from test mesh 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")