From 47f21309dd4b85afb2e1758c898c9e96aee874c1 Mon Sep 17 00:00:00 2001 From: Jean-Marie Verdun Date: Sat, 14 May 2016 14:27:42 +0200 Subject: [PATCH] FEM: Make FEM compatible with SMESH7 --- CMakeLists.txt | 2 + cMake/FindMEDFile.cmake | 54 ++++++++++++++++++++ src/Mod/Fem/App/CMakeLists.txt | 5 +- src/Mod/Fem/App/FemMesh.cpp | 24 ++++----- src/Mod/Fem/App/FemMesh.h | 9 ++-- src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp | 41 +++++++++------ src/Mod/Fem/Gui/CMakeLists.txt | 3 ++ src/Mod/Fem/TestFem.py | 3 +- src/Mod/MeshPart/App/Mesher.cpp | 4 +- 9 files changed, 107 insertions(+), 38 deletions(-) create mode 100644 cMake/FindMEDFile.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f61a54987..696d94cf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,8 @@ include(cMake/FreeCadMacros.cmake) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cMake") +find_package(VTK REQUIRED) +include(${VTK_USE_FILE}) #if(CMAKE_CFG_INTDIR STREQUAL .) # No Debug/Release output paths diff --git a/cMake/FindMEDFile.cmake b/cMake/FindMEDFile.cmake new file mode 100644 index 000000000..21e2afa03 --- /dev/null +++ b/cMake/FindMEDFile.cmake @@ -0,0 +1,54 @@ +# - Find MED file installation +# +# The following variable are set: +# MEDFILE_INCLUDE_DIRS +# MEDFILE_LIBRARIES +# MEDFILE_C_LIBRARIES +# MEDFILE_F_LIBRARIES +# +# The CMake (or environment) variable MEDFILE_ROOT_DIR can be set to +# guide the detection and indicate a root directory to look into. +# +############################################################################ +# Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +# ------ + +MESSAGE(STATUS "Check for medfile (libmed and libmedc) ...") + +# ------ + +SET(MEDFILE_ROOT_DIR $ENV{MEDFILE_ROOT_DIR} CACHE PATH "Path to the MEDFile.") +IF(MEDFILE_ROOT_DIR) + LIST(APPEND CMAKE_PREFIX_PATH "${MEDFILE_ROOT_DIR}") +ENDIF(MEDFILE_ROOT_DIR) + +FIND_PATH(MEDFILE_INCLUDE_DIRS med.h) +#FIND_PROGRAM(MDUMP mdump) +FIND_LIBRARY(MEDFILE_C_LIBRARIES NAMES medC) +FIND_LIBRARY(MEDFILE_F_LIBRARIES NAMES med) +IF(MEDFILE_F_LIBRARIES) + SET(MEDFILE_LIBRARIES ${MEDFILE_C_LIBRARIES} ${MEDFILE_F_LIBRARIES}) +ELSE(MEDFILE_F_LIBRARIES) + SET(MEDFILE_LIBRARIES ${MEDFILE_C_LIBRARIES}) +ENDIF(MEDFILE_F_LIBRARIES) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(MEDFile REQUIRED_VARS MEDFILE_INCLUDE_DIRS MEDFILE_LIBRARIES) diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index 72467bb27..fbe91eaba 100755 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -8,6 +8,8 @@ if(BUILD_FEM_NETGEN) add_definitions(-DFCWithNetgen ${NETGEN_DEFINITIONS}) endif(BUILD_FEM_NETGEN) +find_package(VTK REQUIRED) +include(${VTK_USE_FILE}) include_directories( ${CMAKE_BINARY_DIR} @@ -22,6 +24,7 @@ include_directories( ${ZLIB_INCLUDE_DIR} ${XercesC_INCLUDE_DIRS} ${SMESH_INCLUDE_DIR} + ${VTK_INCLUDE_DIR} ) link_directories(${OCC_LIBRARY_DIR}) @@ -227,7 +230,7 @@ SET(Fem_SRCS ) add_library(Fem SHARED ${Fem_SRCS}) -target_link_libraries(Fem ${Fem_LIBS}) +target_link_libraries(Fem ${Fem_LIBS} ${VTK_LIBRARIES}) fc_target_copy_resource(Fem diff --git a/src/Mod/Fem/App/FemMesh.cpp b/src/Mod/Fem/App/FemMesh.cpp index 6533de6e3..2cc75704b 100644 --- a/src/Mod/Fem/App/FemMesh.cpp +++ b/src/Mod/Fem/App/FemMesh.cpp @@ -68,6 +68,8 @@ #include # include +# include +# include //to simplify parsing input files we use the boost lib #include @@ -115,6 +117,8 @@ FemMesh::~FemMesh() FemMesh &FemMesh::operator=(const FemMesh& mesh) { if (this != &mesh) { + myGen = new SMESH_Gen(); + myMesh = myGen->CreateMesh(0,true); copyMeshData(mesh); } return *this; @@ -122,26 +126,18 @@ FemMesh &FemMesh::operator=(const FemMesh& mesh) void FemMesh::copyMeshData(const FemMesh& mesh) { - //const SMDS_MeshInfo& info = mesh.myMesh->GetMeshDS()->GetMeshInfo(); - //int numPoly = info.NbPolygons(); - //int numVolu = info.NbVolumes(); - //int numTetr = info.NbTetras(); - //int numHexa = info.NbHexas(); - //int numPyrd = info.NbPyramids(); - //int numPris = info.NbPrisms(); - //int numHedr = info.NbPolyhedrons(); - + SMESH_Mesh *test; _Mtrx = mesh._Mtrx; SMESHDS_Mesh* meshds = this->myMesh->GetMeshDS(); - meshds->ClearMesh(); - + SMDS_NodeIteratorPtr aNodeIter = mesh.myMesh->GetMeshDS()->nodesIterator(); for (;aNodeIter->more();) { const SMDS_MeshNode* aNode = aNodeIter->next(); - meshds->AddNodeWithID(aNode->X(),aNode->Y(),aNode->Z(), aNode->GetID()); + double temp[3]; + aNode->GetXYZ(temp); + meshds->AddNodeWithID(temp[0],temp[1],temp[2], aNode->GetID()); } - SMDS_EdgeIteratorPtr aEdgeIter = mesh.myMesh->GetMeshDS()->edgesIterator(); for (;aEdgeIter->more();) { const SMDS_MeshEdge* aEdge = aEdgeIter->next(); @@ -559,7 +555,6 @@ std::set FemMesh::getNodesBySolid(const TopoDS_Solid &solid) const result.insert(aNode->GetID()); } } - return result; } @@ -873,6 +868,7 @@ void FemMesh::read(const char *FileName) } else if (File.hasExtension("dat") ) { // read brep-file + // vejmarie disable myMesh->DATToMesh(File.filePath().c_str()); } else if (File.hasExtension("bdf") ) { diff --git a/src/Mod/Fem/App/FemMesh.h b/src/Mod/Fem/App/FemMesh.h index 2717096e7..b7fb4fcd8 100644 --- a/src/Mod/Fem/App/FemMesh.h +++ b/src/Mod/Fem/App/FemMesh.h @@ -143,6 +143,9 @@ public: void read(const char *FileName); void write(const char *FileName) const; void writeABAQUS(const std::string &Filename) const; + Base::Matrix4D _Mtrx; + SMESH_Gen *myGen; + SMESH_Mesh *myMesh; private: void copyMeshData(const FemMesh&); @@ -150,9 +153,9 @@ private: private: /// positioning matrix - Base::Matrix4D _Mtrx; - SMESH_Gen *myGen; - SMESH_Mesh *myMesh; +// Base::Matrix4D _Mtrx; +// SMESH_Gen *myGen; +// SMESH_Mesh *myMesh; std::list hypoth; }; diff --git a/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp b/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp index b4b665940..e2ed7f429 100644 --- a/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp +++ b/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp @@ -34,6 +34,7 @@ #include #include + #include #include #include @@ -76,32 +77,37 @@ App::DocumentObjectExecReturn *FemMeshShapeNetgenObject::execute(void) #ifdef FCWithNetgen Fem::FemMesh newMesh; - + // SMESH_Gen *myGen = newMesh.getGenerator(); +// vejmarie NEEDED TO MAKE IT WORK + newMesh.myMesh = newMesh.myGen->CreateMesh(0, true); Part::Feature *feat = Shape.getValue(); TopoDS_Shape shape = feat->Shape.getValue(); - newMesh.getSMesh()->ShapeToMesh(shape); - SMESH_Gen *myGen = newMesh.getGenerator(); +// newMesh.myMesh->ShapeToMesh(shape); +// SMESH_Gen *myGen = newMesh.getGenerator(); +// meshgen->CreateMesh(0, true); int hyp=0; NETGENPlugin_Mesher myNetGenMesher(newMesh.getSMesh(),shape,true); +/* + NETGENPlugin_SimpleHypothesis_2D * tet2 = new NETGENPlugin_SimpleHypothesis_2D(hyp++,1,myGen); + static_cast(tet2.get())->SetNumberOfSegments(5); + static_cast(tet2.get())->SetLocalLength(0.1); + static_cast(tet2.get())->LengthFromEdges(); + myNetGenMesher.SetParameters(tet2); +*/ +/* + NETGENPlugin_SimpleHypothesis_3D* tet= new NETGENPlugin_SimpleHypothesis_3D(hyp++,1,myGen); + static_cast(tet.get())->LengthFromFaces(); + static_cast(tet.get())->SetMaxElementVolume(0.1); + myNetGenMesher.SetParameters( tet); +*/ - //NETGENPlugin_SimpleHypothesis_2D * tet2 = new NETGENPlugin_SimpleHypothesis_2D(hyp++,1,myGen); - //static_cast(tet2.get())->SetNumberOfSegments(5); - //static_cast(tet2.get())->SetLocalLength(0.1); - //static_cast(tet2.get())->LengthFromEdges(); - //myNetGenMesher.SetParameters(tet2); - - //NETGENPlugin_SimpleHypothesis_3D* tet= new NETGENPlugin_SimpleHypothesis_3D(hyp++,1,myGen); - //static_cast(tet.get())->LengthFromFaces(); - //static_cast(tet.get())->SetMaxElementVolume(0.1); - //myNetGenMesher.SetParameters( tet); - - NETGENPlugin_Hypothesis* tet= new NETGENPlugin_Hypothesis(hyp++,1,myGen); + NETGENPlugin_Hypothesis* tet= new NETGENPlugin_Hypothesis(hyp++,1,newMesh.myGen); tet->SetMaxSize(MaxSize.getValue()); tet->SetSecondOrder(SecondOrder.getValue()); tet->SetOptimize(Optimize.getValue()); @@ -113,9 +119,11 @@ App::DocumentObjectExecReturn *FemMeshShapeNetgenObject::execute(void) tet->SetNbSegPerRadius(NbSegsPerRadius.getValue()); } myNetGenMesher.SetParameters( tet); + newMesh.myMesh->ShapeToMesh(shape); myNetGenMesher.Compute(); + // throw Base::Exception("Compute Done\n"); SMESHDS_Mesh* data = const_cast(newMesh.getSMesh())->GetMeshDS(); const SMDS_MeshInfo& info = data->GetMeshInfo(); @@ -134,8 +142,7 @@ App::DocumentObjectExecReturn *FemMeshShapeNetgenObject::execute(void) Base::Console().Log("NetgenMesh: %i Nodes, %i Volumes, %i Faces\n",numNode,numVolu,numFaces); // set the value to the object - FemMesh.setValue(newMesh); - + FemMesh.setValue(newMesh); return App::DocumentObject::StdReturn; #else return new App::DocumentObjectExecReturn("The FEM module is built without NETGEN support. Meshing will not work!!!", this); diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 25304bb34..1ef743919 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -7,6 +7,8 @@ endif(MSVC) if(BUILD_FEM_NETGEN) add_definitions(-DFCWithNetgen) endif(BUILD_FEM_NETGEN) +find_package(VTK REQUIRED) +include(${VTK_USE_FILE}) include_directories( ${CMAKE_BINARY_DIR} @@ -20,6 +22,7 @@ include_directories( ${PYTHON_INCLUDE_DIRS} ${XercesC_INCLUDE_DIRS} ${SMESH_INCLUDE_DIR} + ${VTK_INCLUDE_DIR} ) link_directories(${OCC_LIBRARY_DIR}) diff --git a/src/Mod/Fem/TestFem.py b/src/Mod/Fem/TestFem.py index a75a7e212..d7078109b 100644 --- a/src/Mod/Fem/TestFem.py +++ b/src/Mod/Fem/TestFem.py @@ -84,13 +84,14 @@ class FemTest(unittest.TestCase): reader = csv.reader(points_file) for p in reader: self.mesh.addNode(float(p[1]), float(p[2]), float(p[3]), int(p[0])) - + with open(mesh_volumes_file, 'r') as volumes_file: reader = csv.reader(volumes_file) for v in reader: self.mesh.addVolume([int(v[2]), int(v[1]), int(v[3]), int(v[4]), int(v[5]), int(v[7]), int(v[6]), int(v[9]), int(v[8]), int(v[10])], int(v[0])) + self.mesh_object.FemMesh = self.mesh self.active_doc.recompute() diff --git a/src/Mod/MeshPart/App/Mesher.cpp b/src/Mod/MeshPart/App/Mesher.cpp index c78d3d8ec..dc80ec4f6 100644 --- a/src/Mod/MeshPart/App/Mesher.cpp +++ b/src/Mod/MeshPart/App/Mesher.cpp @@ -362,8 +362,6 @@ Mesh::MeshObject* Mesher::createMesh() const } // clean up - delete meshgen; - TopoDS_Shape aNull; mesh->ShapeToMesh(aNull); mesh->Clear(); @@ -371,6 +369,8 @@ Mesh::MeshObject* Mesher::createMesh() const for (std::list::iterator it = hypoth.begin(); it != hypoth.end(); ++it) delete *it; + delete meshgen; + MeshCore::MeshKernel kernel; kernel.Adopt(verts, faces, true);