| 1 |
// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE |
| 2 |
// |
| 3 |
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, |
| 4 |
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS |
| 5 |
// |
| 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, or (at your option) any later version. |
| 10 |
// |
| 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. |
| 15 |
// |
| 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 |
| 19 |
// |
| 20 |
// See http://www.salome-platform.org/ or email : [email protected] |
| 21 |
// |
| 22 |
|
| 23 |
// NETGENPlugin : C++ implementation |
| 24 |
// File : NETGENPlugin_Mesher.hxx |
| 25 |
// Author : Michael Sazonov (OCN) |
| 26 |
// Date : 31/03/2006 |
| 27 |
// Project : SALOME |
| 28 |
// |
| 29 |
#ifndef _NETGENPlugin_Mesher_HXX_ |
| 30 |
#define _NETGENPlugin_Mesher_HXX_ |
| 31 |
#include <TopTools_IndexedMapOfShape.hxx> |
| 32 |
#include "NETGENPlugin_Defs.hxx" |
| 33 |
|
| 34 |
#include <StdMeshers_FaceSide.hxx> |
| 35 |
#include <SMDS_MeshElement.hxx> |
| 36 |
#include <SMESH_Algo.hxx> |
| 37 |
#include <SMESH_ProxyMesh.hxx> |
| 38 |
|
| 39 |
#define NETGEN_VERSION_STRING(a,b,c) (a << 16) + (b << 8) + (c) |
| 40 |
|
| 41 |
namespace nglib { |
| 42 |
#include <nglib.h> |
| 43 |
} |
| 44 |
|
| 45 |
#include <map> |
| 46 |
#include <vector> |
| 47 |
#include <set> |
| 48 |
#include <memory> |
| 49 |
|
| 50 |
class SMESHDS_Mesh; |
| 51 |
class SMESH_Comment; |
| 52 |
class SMESH_Mesh; |
| 53 |
class SMESH_MesherHelper; |
| 54 |
class TopoDS_Shape; |
| 55 |
// class TopTools_IndexedMapOfShape; |
| 56 |
class NETGENPlugin_Hypothesis; |
| 57 |
class NETGENPlugin_SimpleHypothesis_2D; |
| 58 |
class NETGENPlugin_Internals; |
| 59 |
namespace netgen { |
| 60 |
class OCCGeometry; |
| 61 |
class Mesh; |
| 62 |
} |
| 63 |
//============================================================================= |
| 64 |
/*! |
| 65 |
* \brief Struct storing nb of entities in netgen mesh |
| 66 |
*/ |
| 67 |
//============================================================================= |
| 68 |
|
| 69 |
struct NETGENPlugin_ngMeshInfo |
| 70 |
{ |
| 71 |
int _nbNodes, _nbSegments, _nbFaces, _nbVolumes; |
| 72 |
char* _copyOfLocalH; |
| 73 |
NETGENPlugin_ngMeshInfo( netgen::Mesh* ngMesh=0); |
| 74 |
void transferLocalH( netgen::Mesh* fromMesh, netgen::Mesh* toMesh ); |
| 75 |
void restoreLocalH ( netgen::Mesh* ngMesh); |
| 76 |
}; |
| 77 |
|
| 78 |
//================================================================================ |
| 79 |
/*! |
| 80 |
* \brief It correctly initializes netgen library at constructor and |
| 81 |
* correctly finishes using netgen library at destructor |
| 82 |
*/ |
| 83 |
//================================================================================ |
| 84 |
|
| 85 |
struct NETGENPLUGIN_EXPORT NETGENPlugin_NetgenLibWrapper |
| 86 |
{ |
| 87 |
bool _isComputeOk; |
| 88 |
#if NETGEN_VERSION < NETGEN_VERSION_STRING(6,0,0) |
| 89 |
nglib::Ng_Mesh * _ngMesh; |
| 90 |
#else |
| 91 |
std::shared_ptr<nglib::Ng_Mesh> _ngMesh; |
| 92 |
#endif |
| 93 |
|
| 94 |
NETGENPlugin_NetgenLibWrapper(); |
| 95 |
~NETGENPlugin_NetgenLibWrapper(); |
| 96 |
void setMesh( nglib::Ng_Mesh* mesh ); |
| 97 |
|
| 98 |
private: |
| 99 |
std::string getOutputFileName(); |
| 100 |
void removeOutputFile(); |
| 101 |
std::string _outputFileName; |
| 102 |
|
| 103 |
std::streambuf* _coutBuffer; // to re-/store cout.rdbuf() |
| 104 |
}; |
| 105 |
|
| 106 |
//============================================================================= |
| 107 |
/*! |
| 108 |
* \brief This class calls the NETGEN mesher of OCC geometry |
| 109 |
*/ |
| 110 |
//============================================================================= |
| 111 |
|
| 112 |
class NETGENPLUGIN_EXPORT NETGENPlugin_Mesher |
| 113 |
{ |
| 114 |
public: |
| 115 |
// ---------- PUBLIC METHODS ---------- |
| 116 |
|
| 117 |
NETGENPlugin_Mesher (SMESH_Mesh* mesh, const TopoDS_Shape& aShape, |
| 118 |
const bool isVolume); |
| 119 |
~NETGENPlugin_Mesher(); |
| 120 |
void SetSelfPointer( NETGENPlugin_Mesher ** ptr ); |
| 121 |
|
| 122 |
void SetParameters(const NETGENPlugin_Hypothesis* hyp); |
| 123 |
void SetParameters(const NETGENPlugin_SimpleHypothesis_2D* hyp); |
| 124 |
void SetViscousLayers2DAssigned(bool isAssigned) { _isViscousLayers2D = isAssigned; } |
| 125 |
|
| 126 |
bool Compute(); |
| 127 |
|
| 128 |
bool Evaluate(MapShapeNbElems& aResMap); |
| 129 |
|
| 130 |
double GetProgress(const SMESH_Algo* holder, |
| 131 |
const int * algoProgressTic, |
| 132 |
const double * algoProgress) const; |
| 133 |
|
| 134 |
static void PrepareOCCgeometry(netgen::OCCGeometry& occgeom, |
| 135 |
const TopoDS_Shape& shape, |
| 136 |
SMESH_Mesh& mesh, |
| 137 |
std::list< SMESH_subMesh* > * meshedSM=0, |
| 138 |
NETGENPlugin_Internals* internalShapes=0); |
| 139 |
|
| 140 |
static double GetDefaultMinSize(const TopoDS_Shape& shape, |
| 141 |
const double maxSize); |
| 142 |
|
| 143 |
static void RestrictLocalSize(netgen::Mesh& ngMesh, |
| 144 |
const gp_XYZ& p, |
| 145 |
double size, |
| 146 |
const bool overrideMinH=true); |
| 147 |
|
| 148 |
static int FillSMesh(const netgen::OCCGeometry& occgeom, |
| 149 |
netgen::Mesh& ngMesh, |
| 150 |
const NETGENPlugin_ngMeshInfo& initState, |
| 151 |
SMESH_Mesh& sMesh, |
| 152 |
std::vector<const SMDS_MeshNode*>& nodeVec, |
| 153 |
SMESH_Comment& comment, |
| 154 |
SMESH_MesherHelper* quadHelper=0); |
| 155 |
|
| 156 |
bool FillNgMesh(netgen::OCCGeometry& occgeom, |
| 157 |
netgen::Mesh& ngMesh, |
| 158 |
std::vector<const SMDS_MeshNode*>& nodeVec, |
| 159 |
const std::list< SMESH_subMesh* > & meshedSM, |
| 160 |
SMESH_MesherHelper* quadHelper=0, |
| 161 |
SMESH_ProxyMesh::Ptr proxyMesh=SMESH_ProxyMesh::Ptr()); |
| 162 |
|
| 163 |
static void FixIntFaces(const netgen::OCCGeometry& occgeom, |
| 164 |
netgen::Mesh& ngMesh, |
| 165 |
NETGENPlugin_Internals& internalShapes); |
| 166 |
|
| 167 |
static bool FixFaceMesh(const netgen::OCCGeometry& occgeom, |
| 168 |
netgen::Mesh& ngMesh, |
| 169 |
const int faceID); |
| 170 |
|
| 171 |
static void AddIntVerticesInFaces(const netgen::OCCGeometry& occgeom, |
| 172 |
netgen::Mesh& ngMesh, |
| 173 |
std::vector<const SMDS_MeshNode*>& nodeVec, |
| 174 |
NETGENPlugin_Internals& internalShapes); |
| 175 |
|
| 176 |
static void AddIntVerticesInSolids(const netgen::OCCGeometry& occgeom, |
| 177 |
netgen::Mesh& ngMesh, |
| 178 |
std::vector<const SMDS_MeshNode*>& nodeVec, |
| 179 |
NETGENPlugin_Internals& internalShapes); |
| 180 |
|
| 181 |
static SMESH_ComputeErrorPtr |
| 182 |
AddSegmentsToMesh(netgen::Mesh& ngMesh, |
| 183 |
netgen::OCCGeometry& geom, |
| 184 |
const TSideVector& wires, |
| 185 |
SMESH_MesherHelper& helper, |
| 186 |
std::vector< const SMDS_MeshNode* > & nodeVec, |
| 187 |
const bool overrideMinH=true); |
| 188 |
|
| 189 |
void SetDefaultParameters(); |
| 190 |
|
| 191 |
static void RemoveTmpFiles(); |
| 192 |
|
| 193 |
static SMESH_ComputeErrorPtr ReadErrors(const std::vector< const SMDS_MeshNode* >& nodeVec); |
| 194 |
|
| 195 |
|
| 196 |
static void toPython( const netgen::Mesh* ngMesh, |
| 197 |
const std::string& pyFile); // debug |
| 198 |
|
| 199 |
private: |
| 200 |
|
| 201 |
SMESH_Mesh* _mesh; |
| 202 |
const TopoDS_Shape& _shape; |
| 203 |
bool _isVolume; |
| 204 |
bool _optimize; |
| 205 |
int _fineness; |
| 206 |
bool _isViscousLayers2D; |
| 207 |
#if NETGEN_VERSION < NETGEN_VERSION_STRING(6,0,0) |
| 208 |
netgen::Mesh* _ngMesh; |
| 209 |
#else |
| 210 |
std::shared_ptr<netgen::Mesh> _ngMesh; |
| 211 |
#endif |
| 212 |
netgen::OCCGeometry* _occgeom; |
| 213 |
|
| 214 |
int _curShapeIndex; |
| 215 |
volatile int _progressTic; |
| 216 |
volatile double _ticTime; // normalized [0,1] compute time per a SMESH_Algo::_progressTic |
| 217 |
volatile double _totalTime; |
| 218 |
|
| 219 |
const NETGENPlugin_SimpleHypothesis_2D * _simpleHyp; |
| 220 |
|
| 221 |
// a pointer to NETGENPlugin_Mesher* field of the holder, that will be |
| 222 |
// nullified at destruction of this |
| 223 |
NETGENPlugin_Mesher ** _ptrToMe; |
| 224 |
}; |
| 225 |
|
| 226 |
//============================================================================= |
| 227 |
/*! |
| 228 |
* \brief Container of info needed to solve problems with internal shapes. |
| 229 |
* |
| 230 |
* Issue 0020676. It is made up as a class to be ready to extract from NETGEN |
| 231 |
* and put in SMESH as soon as the same solution is needed somewhere else. |
| 232 |
* The approach is to precompute internal edges in 2D and internal faces in 3D |
| 233 |
* and put their mesh correctly (twice) into netgen mesh. |
| 234 |
* In 2D, this class finds internal edges in faces and their vertices. |
| 235 |
* In 3D, it additionally finds internal faces, their edges shared with other faces, |
| 236 |
* and their vertices shared by several internal edges. Nodes built on the found |
| 237 |
* shapes and mesh faces built on the found internal faces are to be doubled in |
| 238 |
* netgen mesh to emulate a "crack" |
| 239 |
* |
| 240 |
* For internal faces a more simple solution is found, which is just to duplicate |
| 241 |
* mesh faces on internal geom faces without modeling a "real crack". For this |
| 242 |
* reason findBorderElements() is no more used anywhere. |
| 243 |
*/ |
| 244 |
//============================================================================= |
| 245 |
|
| 246 |
class NETGENPLUGIN_EXPORT NETGENPlugin_Internals |
| 247 |
{ |
| 248 |
SMESH_Mesh& _mesh; |
| 249 |
bool _is3D; |
| 250 |
//2D |
| 251 |
std::map<int,int> _e2face;//!<edges and their vertices in faces where they are TopAbs_INTERNAL |
| 252 |
std::map<int,std::list<int> > _f2v;//!<faces with internal vertices |
| 253 |
// 3D |
| 254 |
std::set<int> _intShapes; |
| 255 |
std::set<int> _borderFaces; //!< non-internal faces sharing the internal edge |
| 256 |
std::map<int,std::list<int> > _s2v;//!<solids with internal vertices |
| 257 |
|
| 258 |
public: |
| 259 |
NETGENPlugin_Internals( SMESH_Mesh& mesh, const TopoDS_Shape& shape, bool is3D ); |
| 260 |
|
| 261 |
SMESH_Mesh& getMesh() const; |
| 262 |
|
| 263 |
bool isShapeToPrecompute(const TopoDS_Shape& s); |
| 264 |
|
| 265 |
// 2D meshing |
| 266 |
// edges |
| 267 |
bool hasInternalEdges() const { return !_e2face.empty(); } |
| 268 |
bool isInternalEdge( int id ) const { return _e2face.count( id ); } |
| 269 |
const std::map<int,int>& getEdgesAndVerticesWithFaces() const { return _e2face; } |
| 270 |
void getInternalEdges( TopTools_IndexedMapOfShape& fmap, |
| 271 |
TopTools_IndexedMapOfShape& emap, |
| 272 |
TopTools_IndexedMapOfShape& vmap, |
| 273 |
std::list< SMESH_subMesh* > smToPrecompute[]); |
| 274 |
// vertices |
| 275 |
bool hasInternalVertexInFace() const { return !_f2v.empty(); } |
| 276 |
const std::map<int,std::list<int> >& getFacesWithVertices() const { return _f2v; } |
| 277 |
|
| 278 |
// 3D meshing |
| 279 |
// faces |
| 280 |
bool hasInternalFaces() const { return !_intShapes.empty(); } |
| 281 |
bool isInternalShape( int id ) const { return _intShapes.count( id ); } |
| 282 |
void findBorderElements( std::set< const SMDS_MeshElement*, TIDCompare > & borderElems ); |
| 283 |
bool isBorderFace( int faceID ) const { return _borderFaces.count( faceID ); } |
| 284 |
void getInternalFaces( TopTools_IndexedMapOfShape& fmap, |
| 285 |
TopTools_IndexedMapOfShape& emap, |
| 286 |
std::list< SMESH_subMesh* >& facesSM, |
| 287 |
std::list< SMESH_subMesh* >& boundarySM); |
| 288 |
// vertices |
| 289 |
bool hasInternalVertexInSolid() const { return !_s2v.empty(); } |
| 290 |
bool hasInternalVertexInSolid(int soID ) const { return _s2v.count(soID); } |
| 291 |
const std::map<int,std::list<int> >& getSolidsWithVertices() const { return _s2v; } |
| 292 |
|
| 293 |
|
| 294 |
}; |
| 295 |
|
| 296 |
#endif |