diff --git a/src/Mod/Fem/App/FemMesh.cpp b/src/Mod/Fem/App/FemMesh.cpp index 9089a0afaa..c7a9e36cd1 100644 --- a/src/Mod/Fem/App/FemMesh.cpp +++ b/src/Mod/Fem/App/FemMesh.cpp @@ -1169,6 +1169,42 @@ void FemMesh::readNastran(const std::string &Filename) } +void FemMesh::readAbaqus(const std::string &FileName) +{ + Base::TimeInfo Start; + Base::Console().Log("Start: FemMesh::readAbaqus() =================================\n"); + + /* + Python command to read Abaqus inp mesh file from test suite: + from feminout.importInpMesh import read as read_inp + femmesh = read_inp(FreeCAD.ConfigGet("AppHomePath") + 'Mod/Fem/femtest/testfiles/mesh/tetra10_mesh.inp') + */ + + PyObject* module = PyImport_ImportModule("feminout.importInpMesh"); + if (!module) + return; + try { + Py::Module abaqusmod(module, true); + Py::Callable method(abaqusmod.getAttr("read")); + Py::Tuple args(1); + args.setItem(0, Py::String(FileName)); + Py::Object mesh(method.apply(args)); + if (PyObject_TypeCheck(mesh.ptr(), &FemMeshPy::Type)) { + FemMeshPy* fempy = static_cast(mesh.ptr()); + FemMesh* fem = fempy->getFemMeshPtr(); + *this = *fem; // the deep copy should be avoided, a pointer swap method could be implemented + // see https://forum.freecadweb.org/viewtopic.php?f=10&t=31999&start=10#p274241 + } + else { + throw Base::FileException("Problems reading file"); + } + } + catch (Py::Exception& e) { + e.clear(); + } + Base::Console().Log(" %f: Done \n",Base::TimeInfo::diffTimeF(Start,Base::TimeInfo())); +} + void FemMesh::readZ88(const std::string &FileName) { Base::TimeInfo Start; @@ -1221,6 +1257,10 @@ void FemMesh::read(const char *FileName) else if (File.hasExtension("med") ) { myMesh->MEDToMesh(File.filePath().c_str(),File.fileNamePure().c_str()); } + else if (File.hasExtension("inp") ) { + // read Abaqus inp mesh file + readAbaqus(File.filePath()); + } else if (File.hasExtension("stl") ) { // read brep-file myMesh->STLToMesh(File.filePath().c_str()); diff --git a/src/Mod/Fem/App/FemMesh.h b/src/Mod/Fem/App/FemMesh.h index 28654fa4a5..e48fee2245 100644 --- a/src/Mod/Fem/App/FemMesh.h +++ b/src/Mod/Fem/App/FemMesh.h @@ -158,6 +158,7 @@ private: void copyMeshData(const FemMesh&); void readNastran(const std::string &Filename); void readZ88(const std::string &Filename); + void readAbaqus(const std::string &Filename); private: /// positioning matrix diff --git a/src/Mod/Fem/App/FemMeshPy.xml b/src/Mod/Fem/App/FemMeshPy.xml index fcd24c0057..a834a10fef 100755 --- a/src/Mod/Fem/App/FemMeshPy.xml +++ b/src/Mod/Fem/App/FemMeshPy.xml @@ -63,7 +63,7 @@ Read in a various FEM mesh file formats. read(file.endingToExportTo) - supported formats: DAT, MED, STL, UNV, VTK, Z88 + supported formats: DAT, INP, MED, STL, UNV, VTK, Z88 diff --git a/src/Mod/Fem/Init.py b/src/Mod/Fem/Init.py index c64760c0ca..4035e3c875 100644 --- a/src/Mod/Fem/Init.py +++ b/src/Mod/Fem/Init.py @@ -31,10 +31,9 @@ import FreeCAD FreeCAD.addExportType("FEM mesh TetGen (*.poly)", "feminout.convert2TetGen") # see FemMesh::read() and FemMesh::write() methods in src/Mod/Fem/App/FemMesh.cpp -FreeCAD.addImportType("FEM mesh formats (*.unv *.med *.dat *.bdf *.vtk *.vtu *.z88)", "Fem") +FreeCAD.addImportType("FEM mesh formats (*.unv *.med *.dat *.bdf *.inp *.vtk *.vtu *.z88)", "Fem") FreeCAD.addExportType("FEM mesh formats (*.unv *.med *.stl *.dat *.inp *.vtk *.vtu *.z88)", "Fem") -FreeCAD.addImportType("FEM mesh CalculiX/Abaqus (*.inp)", "feminout.importInpMesh") FreeCAD.addImportType("FEM result CalculiX (*.frd)", "feminout.importCcxFrdResults") FreeCAD.addImportType("FEM mesh Fenics (*.xml *.xdmf)", "feminout.importFenicsMesh") diff --git a/src/Mod/Fem/femtest/testmesh.py b/src/Mod/Fem/femtest/testmesh.py index 0c80d5fbbe..75bbd6f347 100644 --- a/src/Mod/Fem/femtest/testmesh.py +++ b/src/Mod/Fem/femtest/testmesh.py @@ -223,9 +223,8 @@ class TestMeshEleTetra10(unittest.TestCase): # fcc_print(outfile) # fcc_print(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 + 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 # fcc_print([femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])]) self.assertEqual(