1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // NETGENPlugin : C++ implementation
24 // File : NETGENPlugin_Mesher.hxx
25 // Author : Michael Sazonov (OCN)
29 #ifndef _NETGENPlugin_Mesher_HXX_
30 #define _NETGENPlugin_Mesher_HXX_
32 #include "NETGENPlugin_Defs.hxx"
34 #include <StdMeshers_FaceSide.hxx>
35 #include <SMDS_MeshElement.hxx>
36 #include <SMESH_Algo.hxx>
37 #include <SMESH_ProxyMesh.hxx>
51 class TopTools_DataMapOfShapeShape;
52 class TopTools_IndexedMapOfShape;
53 class NETGENPlugin_Hypothesis;
54 class NETGENPlugin_SimpleHypothesis_2D;
55 class NETGENPlugin_Internals;
60 //=============================================================================
62 * \brief Struct storing nb of entities in netgen mesh
64 //=============================================================================
66 struct NETGENPlugin_ngMeshInfo
68 int _nbNodes, _nbSegments, _nbFaces, _nbVolumes;
70 NETGENPlugin_ngMeshInfo( netgen::Mesh* ngMesh=0);
71 void transferLocalH( netgen::Mesh* fromMesh, netgen::Mesh* toMesh );
72 void restoreLocalH ( netgen::Mesh* ngMesh);
75 //=============================================================================
77 * \brief This class calls the NETGEN mesher of OCC geometry
79 //=============================================================================
81 class NETGENPLUGIN_EXPORT NETGENPlugin_Mesher
84 // ---------- PUBLIC METHODS ----------
86 NETGENPlugin_Mesher (SMESH_Mesh* mesh, const TopoDS_Shape& aShape,
89 void SetParameters(const NETGENPlugin_Hypothesis* hyp);
90 void SetParameters(const NETGENPlugin_SimpleHypothesis_2D* hyp);
94 bool Evaluate(MapShapeNbElems& aResMap);
96 static void PrepareOCCgeometry(netgen::OCCGeometry& occgeom,
97 const TopoDS_Shape& shape,
99 std::list< SMESH_subMesh* > * meshedSM=0,
100 NETGENPlugin_Internals* internalShapes=0);
102 static double GetDefaultMinSize(const TopoDS_Shape& shape,
103 const double maxSize);
105 static void RestrictLocalSize(netgen::Mesh& ngMesh, const gp_XYZ& p, const double size);
107 static int FillSMesh(const netgen::OCCGeometry& occgeom,
108 netgen::Mesh& ngMesh,
109 const NETGENPlugin_ngMeshInfo& initState,
111 std::vector<const SMDS_MeshNode*>& nodeVec,
112 SMESH_Comment& comment);
114 bool fillNgMesh(netgen::OCCGeometry& occgeom,
115 netgen::Mesh& ngMesh,
116 std::vector<const SMDS_MeshNode*>& nodeVec,
117 const std::list< SMESH_subMesh* > & meshedSM,
118 SMESH_ProxyMesh::Ptr proxyMesh=SMESH_ProxyMesh::Ptr());
120 static void fixIntFaces(const netgen::OCCGeometry& occgeom,
121 netgen::Mesh& ngMesh,
122 NETGENPlugin_Internals& internalShapes);
124 static void addIntVerticesInFaces(const netgen::OCCGeometry& occgeom,
125 netgen::Mesh& ngMesh,
126 std::vector<const SMDS_MeshNode*>& nodeVec,
127 NETGENPlugin_Internals& internalShapes);
129 static void addIntVerticesInSolids(const netgen::OCCGeometry& occgeom,
130 netgen::Mesh& ngMesh,
131 std::vector<const SMDS_MeshNode*>& nodeVec,
132 NETGENPlugin_Internals& internalShapes);
134 void defaultParameters();
136 static void RemoveTmpFiles();
138 static SMESH_ComputeErrorPtr readErrors(const std::vector< const SMDS_MeshNode* >& nodeVec);
141 static void toPython( const netgen::Mesh* ngMesh,
142 const std::string& pyFile); // debug
146 const TopoDS_Shape& _shape;
151 const NETGENPlugin_SimpleHypothesis_2D * _simpleHyp;
152 std::map< int, std::pair<int,int> > _faceDescriptors;
155 //=============================================================================
157 * \brief Container of info needed to solve problems with internal shapes.
159 * Issue 0020676. It is made up as a class to be ready to extract from NETGEN
160 * and put in SMESH as soon as the same solution is needed somewhere else.
161 * The approach is to precompute internal edges in 2D and internal faces in 3D
162 * and put their mesh correctly (twice) into netgen mesh.
163 * In 2D, this class finds internal edges in faces and their vertices.
164 * In 3D, it additionally finds internal faces, their edges shared with other faces,
165 * and their vertices shared by several internal edges. Nodes built on the found
166 * shapes and mesh faces built on the found internal faces are to be doubled in
167 * netgen mesh to emulate a "crack"
169 * For internal faces a more simple solution is found, which is just to duplicate
170 * mesh faces on internal geom faces without modeling a "real crack". For this
171 * reason findBorderElements() is no more used anywhere.
173 //=============================================================================
175 class NETGENPLUGIN_EXPORT NETGENPlugin_Internals
180 std::map<int,int> _e2face;//!<edges and their vertices in faces where they are TopAbs_INTERNAL
181 std::map<int,std::list<int> > _f2v;//!<faces with internal vertices
183 std::set<int> _intShapes;
184 std::set<int> _borderFaces; //!< non-internal faces sharing the internal edge
185 std::map<int,std::list<int> > _s2v;//!<solids with internal vertices
188 NETGENPlugin_Internals( SMESH_Mesh& mesh, const TopoDS_Shape& shape, bool is3D );
190 SMESH_Mesh& getMesh() const;
192 bool isShapeToPrecompute(const TopoDS_Shape& s);
196 bool hasInternalEdges() const { return !_e2face.empty(); }
197 bool isInternalEdge( int id ) const { return _e2face.count( id ); }
198 const std::map<int,int>& getEdgesAndVerticesWithFaces() const { return _e2face; }
199 void getInternalEdges( TopTools_IndexedMapOfShape& fmap,
200 TopTools_IndexedMapOfShape& emap,
201 TopTools_IndexedMapOfShape& vmap,
202 std::list< SMESH_subMesh* > smToPrecompute[]);
204 bool hasInternalVertexInFace() const { return !_f2v.empty(); }
205 const std::map<int,std::list<int> >& getFacesWithVertices() const { return _f2v; }
209 bool hasInternalFaces() const { return !_intShapes.empty(); }
210 bool isInternalShape( int id ) const { return _intShapes.count( id ); }
211 void findBorderElements( std::set< const SMDS_MeshElement*, TIDCompare > & borderElems );
212 bool isBorderFace( int faceID ) const { return _borderFaces.count( faceID ); }
213 void getInternalFaces( TopTools_IndexedMapOfShape& fmap,
214 TopTools_IndexedMapOfShape& emap,
215 std::list< SMESH_subMesh* >& facesSM,
216 std::list< SMESH_subMesh* >& boundarySM);
218 bool hasInternalVertexInSolid() const { return !_s2v.empty(); }
219 bool hasInternalVertexInSolid(int soID ) const { return _s2v.count(soID); }
220 const std::map<int,std::list<int> >& getSolidsWithVertices() const { return _s2v; }
225 //================================================================================
227 * \brief It correctly initializes netgen library at constructor and
228 * correctly finishes using netgen library at destructor
230 //================================================================================
232 struct NETGENPLUGIN_EXPORT NETGENPlugin_NetgenLibWrapper
234 nglib::Ng_Mesh * _ngMesh;
235 NETGENPlugin_NetgenLibWrapper();
236 ~NETGENPlugin_NetgenLibWrapper();
237 void setMesh( nglib::Ng_Mesh* mesh );