1 // Copyright (C) 2007-2013 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_IndexedMapOfShape;
52 class NETGENPlugin_Hypothesis;
53 class NETGENPlugin_SimpleHypothesis_2D;
54 class NETGENPlugin_Internals;
59 //=============================================================================
61 * \brief Struct storing nb of entities in netgen mesh
63 //=============================================================================
65 struct NETGENPlugin_ngMeshInfo
67 int _nbNodes, _nbSegments, _nbFaces, _nbVolumes;
69 NETGENPlugin_ngMeshInfo( netgen::Mesh* ngMesh=0);
70 void transferLocalH( netgen::Mesh* fromMesh, netgen::Mesh* toMesh );
71 void restoreLocalH ( netgen::Mesh* ngMesh);
74 //================================================================================
76 * \brief It correctly initializes netgen library at constructor and
77 * correctly finishes using netgen library at destructor
79 //================================================================================
81 struct NETGENPLUGIN_EXPORT NETGENPlugin_NetgenLibWrapper
84 nglib::Ng_Mesh * _ngMesh;
86 NETGENPlugin_NetgenLibWrapper();
87 ~NETGENPlugin_NetgenLibWrapper();
88 void setMesh( nglib::Ng_Mesh* mesh );
91 std::string getOutputFileName();
92 void removeOutputFile();
93 std::string _outputFileName;
96 //=============================================================================
98 * \brief This class calls the NETGEN mesher of OCC geometry
100 //=============================================================================
102 class NETGENPLUGIN_EXPORT NETGENPlugin_Mesher
105 // ---------- PUBLIC METHODS ----------
107 NETGENPlugin_Mesher (SMESH_Mesh* mesh, const TopoDS_Shape& aShape,
108 const bool isVolume);
110 void SetParameters(const NETGENPlugin_Hypothesis* hyp);
111 void SetParameters(const NETGENPlugin_SimpleHypothesis_2D* hyp);
112 void SetViscousLayers2DAssigned(bool isAssigned) { _isViscousLayers2D = isAssigned; }
116 bool Evaluate(MapShapeNbElems& aResMap);
118 static void PrepareOCCgeometry(netgen::OCCGeometry& occgeom,
119 const TopoDS_Shape& shape,
121 std::list< SMESH_subMesh* > * meshedSM=0,
122 NETGENPlugin_Internals* internalShapes=0);
124 static double GetDefaultMinSize(const TopoDS_Shape& shape,
125 const double maxSize);
127 static void RestrictLocalSize(netgen::Mesh& ngMesh, const gp_XYZ& p, const double size);
129 static int FillSMesh(const netgen::OCCGeometry& occgeom,
130 netgen::Mesh& ngMesh,
131 const NETGENPlugin_ngMeshInfo& initState,
133 std::vector<const SMDS_MeshNode*>& nodeVec,
134 SMESH_Comment& comment);
136 bool FillNgMesh(netgen::OCCGeometry& occgeom,
137 netgen::Mesh& ngMesh,
138 std::vector<const SMDS_MeshNode*>& nodeVec,
139 const std::list< SMESH_subMesh* > & meshedSM,
140 SMESH_ProxyMesh::Ptr proxyMesh=SMESH_ProxyMesh::Ptr());
142 static void FixIntFaces(const netgen::OCCGeometry& occgeom,
143 netgen::Mesh& ngMesh,
144 NETGENPlugin_Internals& internalShapes);
146 static void AddIntVerticesInFaces(const netgen::OCCGeometry& occgeom,
147 netgen::Mesh& ngMesh,
148 std::vector<const SMDS_MeshNode*>& nodeVec,
149 NETGENPlugin_Internals& internalShapes);
151 static void AddIntVerticesInSolids(const netgen::OCCGeometry& occgeom,
152 netgen::Mesh& ngMesh,
153 std::vector<const SMDS_MeshNode*>& nodeVec,
154 NETGENPlugin_Internals& internalShapes);
156 static SMESH_ComputeErrorPtr
157 AddSegmentsToMesh(netgen::Mesh& ngMesh,
158 netgen::OCCGeometry& geom,
159 const TSideVector& wires,
160 SMESH_MesherHelper& helper,
161 std::vector< const SMDS_MeshNode* > & nodeVec);
163 void SetDefaultParameters();
165 static void RemoveTmpFiles();
167 static SMESH_ComputeErrorPtr ReadErrors(const std::vector< const SMDS_MeshNode* >& nodeVec);
170 static void toPython( const netgen::Mesh* ngMesh,
171 const std::string& pyFile); // debug
176 const TopoDS_Shape& _shape;
180 bool _isViscousLayers2D;
182 const NETGENPlugin_SimpleHypothesis_2D * _simpleHyp;
185 //=============================================================================
187 * \brief Container of info needed to solve problems with internal shapes.
189 * Issue 0020676. It is made up as a class to be ready to extract from NETGEN
190 * and put in SMESH as soon as the same solution is needed somewhere else.
191 * The approach is to precompute internal edges in 2D and internal faces in 3D
192 * and put their mesh correctly (twice) into netgen mesh.
193 * In 2D, this class finds internal edges in faces and their vertices.
194 * In 3D, it additionally finds internal faces, their edges shared with other faces,
195 * and their vertices shared by several internal edges. Nodes built on the found
196 * shapes and mesh faces built on the found internal faces are to be doubled in
197 * netgen mesh to emulate a "crack"
199 * For internal faces a more simple solution is found, which is just to duplicate
200 * mesh faces on internal geom faces without modeling a "real crack". For this
201 * reason findBorderElements() is no more used anywhere.
203 //=============================================================================
205 class NETGENPLUGIN_EXPORT NETGENPlugin_Internals
210 std::map<int,int> _e2face;//!<edges and their vertices in faces where they are TopAbs_INTERNAL
211 std::map<int,std::list<int> > _f2v;//!<faces with internal vertices
213 std::set<int> _intShapes;
214 std::set<int> _borderFaces; //!< non-internal faces sharing the internal edge
215 std::map<int,std::list<int> > _s2v;//!<solids with internal vertices
218 NETGENPlugin_Internals( SMESH_Mesh& mesh, const TopoDS_Shape& shape, bool is3D );
220 SMESH_Mesh& getMesh() const;
222 bool isShapeToPrecompute(const TopoDS_Shape& s);
226 bool hasInternalEdges() const { return !_e2face.empty(); }
227 bool isInternalEdge( int id ) const { return _e2face.count( id ); }
228 const std::map<int,int>& getEdgesAndVerticesWithFaces() const { return _e2face; }
229 void getInternalEdges( TopTools_IndexedMapOfShape& fmap,
230 TopTools_IndexedMapOfShape& emap,
231 TopTools_IndexedMapOfShape& vmap,
232 std::list< SMESH_subMesh* > smToPrecompute[]);
234 bool hasInternalVertexInFace() const { return !_f2v.empty(); }
235 const std::map<int,std::list<int> >& getFacesWithVertices() const { return _f2v; }
239 bool hasInternalFaces() const { return !_intShapes.empty(); }
240 bool isInternalShape( int id ) const { return _intShapes.count( id ); }
241 void findBorderElements( std::set< const SMDS_MeshElement*, TIDCompare > & borderElems );
242 bool isBorderFace( int faceID ) const { return _borderFaces.count( faceID ); }
243 void getInternalFaces( TopTools_IndexedMapOfShape& fmap,
244 TopTools_IndexedMapOfShape& emap,
245 std::list< SMESH_subMesh* >& facesSM,
246 std::list< SMESH_subMesh* >& boundarySM);
248 bool hasInternalVertexInSolid() const { return !_s2v.empty(); }
249 bool hasInternalVertexInSolid(int soID ) const { return _s2v.count(soID); }
250 const std::map<int,std::list<int> >& getSolidsWithVertices() const { return _s2v; }