FEM: inp mesh reader, add def to return the FemMesh only (no Document obj)

This commit is contained in:
Bernd Hahnebach
2018-12-11 13:54:59 +01:00
committed by Yorik van Havre
parent 5e9bfc012a
commit d317f64f06
2 changed files with 21 additions and 13 deletions

View File

@@ -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():

View File

@@ -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")