-// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#include "NETGENPlugin_SimpleHypothesis_3D.hxx"
#include <SMDS_FaceOfNodes.hxx>
+#include <SMDS_LinearEdge.hxx>
#include <SMDS_MeshElement.hxx>
#include <SMDS_MeshNode.hxx>
#include <SMESHDS_Mesh.hxx>
#include <SMESH_Block.hxx>
#include <SMESH_Comment.hxx>
#include <SMESH_ComputeError.hxx>
+#include <SMESH_ControlPnt.hxx>
#include <SMESH_File.hxx>
#include <SMESH_Gen_i.hxx>
#include <SMESH_Mesh.hxx>
extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, int, int, char*);
#endif
//extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh);
+#if defined(NETGEN_V5) && defined(WIN32)
+ DLL_HEADER
+#endif
extern MeshingParameters mparam;
+#if defined(NETGEN_V5) && defined(WIN32)
+ DLL_HEADER
+#endif
extern volatile multithreadt multithread;
+
+#if defined(NETGEN_V5) && defined(WIN32)
+ DLL_HEADER
+#endif
extern bool merge_solids;
// values used for occgeo.facemeshstatus
std::map<int,double> VertexId2LocalSize;
std::map<int,double> EdgeId2LocalSize;
std::map<int,double> FaceId2LocalSize;
+std::map<int,double> SolidId2LocalSize;
+
+std::vector<SMESHUtils::ControlPnt> ControlPoints;
+std::set<int> ShapesWithControlPoints; // <-- allows calling SetLocalSize() several times w/o recomputing ControlPoints
//=============================================================================
/*!
_progressTic(1),
_totalTime(1.0),
_simpleHyp(NULL),
+ _viscousLayersHyp(NULL),
_ptrToMe(NULL)
{
SetDefaultParameters();
VertexId2LocalSize.clear();
EdgeId2LocalSize.clear();
FaceId2LocalSize.clear();
+ SolidId2LocalSize.clear();
+ ControlPoints.clear();
+ ShapesWithControlPoints.clear();
}
//================================================================================
EdgeId2LocalSize[key] = LocalSize;
} else if (GeomType == TopAbs_FACE) {
FaceId2LocalSize[key] = LocalSize;
+ } else if (GeomType == TopAbs_SOLID) {
+ SolidId2LocalSize[key] = LocalSize;
}
}
// create elements of second order
mparams.secondorder = hyp->GetSecondOrder() ? 1 : 0;
// quad-dominated surface meshing
- // only triangles are allowed for volumic mesh (before realizing IMP 0021676)
- //if (!_isVolume)
- mparams.quad = hyp->GetQuadAllowed() ? 1 : 0;
+ mparams.quad = hyp->GetQuadAllowed() ? 1 : 0;
_optimize = hyp->GetOptimize();
_fineness = hyp->GetFineness();
mparams.uselocalh = hyp->GetSurfaceCurvature();
netgen::merge_solids = hyp->GetFuseEdges();
- _simpleHyp = NULL;
+ _simpleHyp = NULL;
+ // mesh size file
+ mparams.meshsizefilename= hyp->GetMeshSizeFile().empty() ? 0 : hyp->GetMeshSizeFile().c_str();
- SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
- CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/myStudyManager");
- SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
- SALOMEDS::Study_var myStudy = aStudyMgr->GetStudyByID(hyp->GetStudyId());
-
- const NETGENPlugin_Hypothesis::TLocalSize localSizes = hyp->GetLocalSizesAndEntries();
+ SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
+
+ const NETGENPlugin_Hypothesis::TLocalSize localSizes = hyp->GetLocalSizesAndEntries();
NETGENPlugin_Hypothesis::TLocalSize::const_iterator it = localSizes.begin();
for ( ; it != localSizes.end() ; it++)
- {
- std::string entry = (*it).first;
- double val = (*it).second;
- // --
- GEOM::GEOM_Object_var aGeomObj;
- TopoDS_Shape S = TopoDS_Shape();
- SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
- if (!aSObj->_is_nil()) {
- CORBA::Object_var obj = aSObj->GetObject();
- aGeomObj = GEOM::GEOM_Object::_narrow(obj);
- aSObj->UnRegister();
- }
- if ( !aGeomObj->_is_nil() )
- S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
- // --
- SetLocalSize(S, val);
+ {
+ std::string entry = (*it).first;
+ double val = (*it).second;
+ // --
+ GEOM::GEOM_Object_var aGeomObj;
+ SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( entry.c_str() );
+ if ( !aSObj->_is_nil() ) {
+ CORBA::Object_var obj = aSObj->GetObject();
+ aGeomObj = GEOM::GEOM_Object::_narrow(obj);
+ aSObj->UnRegister();
}
+ TopoDS_Shape S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
+ ::SetLocalSize(S, val);
+ }
}
}
SetDefaultParameters();
}
+//================================================================================
+/*!
+ * \brief Store a Viscous Layers hypothesis
+ */
+//================================================================================
+
+void NETGENPlugin_Mesher::SetParameters(const StdMeshers_ViscousLayers* hyp )
+{
+ _viscousLayersHyp = hyp;
+}
+
//=============================================================================
/*!
* Link - a pair of integer numbers
*/
//================================================================================
- void makeQuadratic( const TopTools_IndexedMapOfShape& shapes,
- SMESH_Mesh* mesh )
+ // void makeQuadratic( const TopTools_IndexedMapOfShape& shapes,
+ // SMESH_Mesh* mesh )
+ // {
+ // for ( int i = 1; i <= shapes.Extent(); ++i )
+ // {
+ // SMESHDS_SubMesh* smDS = mesh->GetMeshDS()->MeshElements( shapes(i) );
+ // if ( !smDS ) continue;
+ // SMDS_ElemIteratorPtr elemIt = smDS->GetElements();
+ // if ( !elemIt->more() ) continue;
+ // const SMDS_MeshElement* e = elemIt->next();
+ // if ( !e || e->IsQuadratic() )
+ // continue;
+
+ // TIDSortedElemSet elems;
+ // elems.insert( e );
+ // while ( elemIt->more() )
+ // elems.insert( elems.end(), elemIt->next() );
+
+ // SMESH_MeshEditor( mesh ).ConvertToQuadratic( /*3d=*/false, elems, /*biQuad=*/false );
+ // }
+ // }
+
+ //================================================================================
+ /*!
+ * \brief Restrict size of elements on the given edge
+ */
+ //================================================================================
+
+ void setLocalSize(const TopoDS_Edge& edge,
+ double size,
+ netgen::Mesh& mesh)
{
- for ( int i = 1; i <= shapes.Extent(); ++i )
+ if ( size <= std::numeric_limits<double>::min() )
+ return;
+ Standard_Real u1, u2;
+ Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, u1, u2);
+ if ( curve.IsNull() )
{
- SMESHDS_SubMesh* smDS = mesh->GetMeshDS()->MeshElements( shapes(i) );
- if ( !smDS ) continue;
- SMDS_ElemIteratorPtr elemIt = smDS->GetElements();
- if ( !elemIt->more() ) continue;
- const SMDS_MeshElement* e = elemIt->next();
- if ( !e || e->IsQuadratic() )
- continue;
+ TopoDS_Iterator vIt( edge );
+ if ( !vIt.More() ) return;
+ gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vIt.Value() ));
+ NETGENPlugin_Mesher::RestrictLocalSize( mesh, p.XYZ(), size );
+ }
+ else
+ {
+ const int nb = (int)( 1.5 * SMESH_Algo::EdgeLength( edge ) / size );
+ Standard_Real delta = (u2-u1)/nb;
+ for(int i=0; i<nb; i++)
+ {
+ Standard_Real u = u1 + delta*i;
+ gp_Pnt p = curve->Value(u);
+ NETGENPlugin_Mesher::RestrictLocalSize( mesh, p.XYZ(), size );
+ netgen::Point3d pi(p.X(), p.Y(), p.Z());
+ double resultSize = mesh.GetH(pi);
+ if ( resultSize - size > 0.1*size )
+ // netgen does restriction iff oldH/newH > 1.2 (localh.cpp:136)
+ NETGENPlugin_Mesher::RestrictLocalSize( mesh, p.XYZ(), resultSize/1.201 );
+ }
+ }
+ }
+} // namespace
- TIDSortedElemSet elems;
- elems.insert( e );
- while ( elemIt->more() )
- elems.insert( elems.end(), elemIt->next() );
+//================================================================================
+/*!
+ * \brief Set local size on shapes defined by SetParameters()
+ */
+//================================================================================
- SMESH_MeshEditor( mesh ).ConvertToQuadratic( /*3d=*/false, elems, /*biQuad=*/false );
+void NETGENPlugin_Mesher::SetLocalSize( netgen::OCCGeometry& occgeo,
+ netgen::Mesh& ngMesh )
+{
+ for(std::map<int,double>::const_iterator it=EdgeId2LocalSize.begin(); it!=EdgeId2LocalSize.end(); it++)
+ {
+ int key = (*it).first;
+ double hi = (*it).second;
+ const TopoDS_Shape& shape = ShapesWithLocalSize.FindKey(key);
+ setLocalSize( TopoDS::Edge(shape), hi, ngMesh );
+ }
+ for(std::map<int,double>::const_iterator it=VertexId2LocalSize.begin(); it!=VertexId2LocalSize.end(); it++)
+ {
+ int key = (*it).first;
+ double hi = (*it).second;
+ const TopoDS_Shape& shape = ShapesWithLocalSize.FindKey(key);
+ gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex(shape) );
+ NETGENPlugin_Mesher::RestrictLocalSize( ngMesh, p.XYZ(), hi );
+ }
+ for(map<int,double>::const_iterator it=FaceId2LocalSize.begin(); it!=FaceId2LocalSize.end(); it++)
+ {
+ int key = (*it).first;
+ double val = (*it).second;
+ const TopoDS_Shape& shape = ShapesWithLocalSize.FindKey(key);
+ int faceNgID = occgeo.fmap.FindIndex(shape);
+ if ( faceNgID >= 1 )
+ {
+ occgeo.SetFaceMaxH(faceNgID, val);
+ for ( TopExp_Explorer edgeExp( shape, TopAbs_EDGE ); edgeExp.More(); edgeExp.Next() )
+ setLocalSize( TopoDS::Edge( edgeExp.Current() ), val, ngMesh );
+ }
+ else if ( !ShapesWithControlPoints.count( key ))
+ {
+ SMESHUtils::createPointsSampleFromFace( TopoDS::Face( shape ), val, ControlPoints );
+ ShapesWithControlPoints.insert( key );
+ }
+ }
+ for(map<int,double>::const_iterator it=SolidId2LocalSize.begin(); it!=SolidId2LocalSize.end(); it++)
+ {
+ int key = (*it).first;
+ double val = (*it).second;
+ if ( !ShapesWithControlPoints.count( key ))
+ {
+ const TopoDS_Shape& shape = ShapesWithLocalSize.FindKey(key);
+ SMESHUtils::createPointsSampleFromSolid( TopoDS::Solid( shape ), val, ControlPoints );
+ ShapesWithControlPoints.insert( key );
}
}
+ if ( !ControlPoints.empty() )
+ {
+ for ( size_t i = 0; i < ControlPoints.size(); ++i )
+ NETGENPlugin_Mesher::RestrictLocalSize( ngMesh, ControlPoints[i].XYZ(), ControlPoints[i].Size() );
+ }
}
//================================================================================
BRepBndLib::Add (shape, bb);
double x1,y1,z1,x2,y2,z2;
bb.Get (x1,y1,z1,x2,y2,z2);
- MESSAGE("shape bounding box:\n" <<
- "(" << x1 << " " << y1 << " " << z1 << ") " <<
- "(" << x2 << " " << y2 << " " << z2 << ")");
netgen::Point<3> p1 = netgen::Point<3> (x1,y1,z1);
netgen::Point<3> p2 = netgen::Point<3> (x2,y2,z2);
occgeo.boundingbox = netgen::Box<3> (p1,p2);
}
else
{
- minh = 3 * sqrt( minh ); // triangulation for visualization is rather fine
+ minh = sqrt( minh ); // triangulation for visualization is rather fine
//cout << "TRIANGULATION minh = " <<minh << endl;
}
if ( minh > 0.5 * maxSize )
// get all nodes from connected <edges>
const bool isQuad = smDS->IsQuadratic();
- StdMeshers_FaceSide fSide( face, edges, _mesh, isForwad, isQuad );
+ StdMeshers_FaceSide fSide( face, edges, _mesh, isForwad, isQuad, &helper );
const vector<UVPtStruct>& points = fSide.GetUVPtStruct();
if ( points.empty() )
return false; // invalid node params?
seg.epgeominfo[ 1 ].v = otherSeamParam;
swap (seg.epgeominfo[0].u, seg.epgeominfo[1].u);
}
- swap (seg[0], seg[1]);
- swap (seg.epgeominfo[0].dist, seg.epgeominfo[1].dist);
+ swap( seg[0], seg[1] );
+ swap( seg.epgeominfo[0].dist, seg.epgeominfo[1].dist );
seg.edgenr = ngMesh.GetNSeg() + 1; // segment id
- ngMesh.AddSegment (seg);
+ ngMesh.AddSegment( seg );
#ifdef DUMP_SEGMENTS
cout << "Segment: " << seg.edgenr << endl
<< "\t is SEAM (reverse) of the previous. "
}
else if ( fOri == TopAbs_INTERNAL )
{
- swap (seg[0], seg[1]);
+ swap( seg[0], seg[1] );
swap( seg.epgeominfo[0], seg.epgeominfo[1] );
seg.edgenr = ngMesh.GetNSeg() + 1; // segment id
- ngMesh.AddSegment (seg);
+ ngMesh.AddSegment( seg );
#ifdef DUMP_SEGMENTS
cout << "Segment: " << seg.edgenr << endl << "\t is REVERSE of the previous" << endl;
#endif
// Find solids the geomFace bounds
int solidID1 = 0, solidID2 = 0;
- StdMeshers_QuadToTriaAdaptor* quadAdaptor =
- dynamic_cast<StdMeshers_QuadToTriaAdaptor*>( proxyMesh.get() );
- if ( quadAdaptor )
{
- solidID1 = occgeom.somap.FindIndex( quadAdaptor->GetShape() );
- }
- else
- {
PShapeIteratorPtr solidIt = helper.GetAncestors( geomFace, *sm->GetFather(), TopAbs_SOLID);
while ( const TopoDS_Shape * solid = solidIt->next() )
{
else solidID1 = id;
}
}
+ if ( proxyMesh && proxyMesh->GetProxySubMesh( geomFace ))
+ {
+ // if a proxy sub-mesh contains temporary faces, then these faces
+ // should be used to mesh only one SOLID
+ bool hasTmp = false;
+ smDS = proxyMesh->GetSubMesh( geomFace );
+ SMDS_ElemIteratorPtr faces = smDS->GetElements();
+ while ( faces->more() )
+ {
+ const SMDS_MeshElement* f = faces->next();
+ if ( proxyMesh->IsTemporary( f ))
+ {
+ hasTmp = true;
+ std::vector<const SMDS_MeshNode*> fNodes( f->begin_nodes(), f->end_nodes() );
+ std::vector<const SMDS_MeshElement*> vols;
+ if ( _mesh->GetMeshDS()->GetElementsByNodes( fNodes, vols, SMDSAbs_Volume ) == 1 )
+ {
+ int geomID = vols[0]->getshapeId();
+ const TopoDS_Shape& solid = helper.GetMeshDS()->IndexToShape( geomID );
+ if ( !solid.IsNull() )
+ solidID1 = occgeom.somap.FindIndex ( solid );
+ solidID2 = 0;
+ break;
+ }
+ }
+ }
+ // exclude faces generated by NETGEN from computation of 3D mesh
+ const int fID = occgeom.fmap.FindIndex( geomFace );
+ if ( !hasTmp ) // shrunk mesh
+ {
+ // move netgen points according to moved nodes
+ SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true);
+ while ( smIt->more() )
+ {
+ SMESH_subMesh* sub = smIt->next();
+ if ( !sub->GetSubMeshDS() ) continue;
+ SMDS_NodeIteratorPtr nodeIt = sub->GetSubMeshDS()->GetNodes();
+ while ( nodeIt->more() )
+ {
+ const SMDS_MeshNode* n = nodeIt->next();
+ int ngID = ngNodeId( n, ngMesh, nodeNgIdMap );
+ netgen::MeshPoint& ngPoint = ngMesh.Point( ngID );
+ ngPoint(0) = n->X();
+ ngPoint(1) = n->Y();
+ ngPoint(2) = n->Z();
+ }
+ }
+ // remove faces near boundary to avoid their overlapping
+ // with shrunk faces
+ for ( int i = 1; i <= ngMesh.GetNSE(); ++i )
+ {
+ const netgen::Element2d& elem = ngMesh.SurfaceElement(i);
+ if ( elem.GetIndex() == fID )
+ {
+ for ( int iN = 0; iN < elem.GetNP(); ++iN )
+ if ( ngMesh[ elem[ iN ]].Type() != netgen::SURFACEPOINT )
+ {
+ ngMesh.DeleteSurfaceElement( i );
+ break;
+ }
+ }
+ }
+ }
+ //if ( hasTmp )
+ {
+ faceNgID++;
+ ngMesh.AddFaceDescriptor( netgen::FaceDescriptor( faceNgID,/*solid1=*/0,/*solid2=*/0,0 ));
+ for (int i = 1; i <= ngMesh.GetNSE(); ++i )
+ {
+ const netgen::Element2d& elem = ngMesh.SurfaceElement(i);
+ if ( elem.GetIndex() == fID )
+ const_cast< netgen::Element2d& >( elem ).SetIndex( faceNgID );
+ }
+ }
+ }
// Add ng face descriptors of meshed faces
faceNgID++;
- ngMesh.AddFaceDescriptor (netgen::FaceDescriptor(faceNgID, solidID1, solidID2, 0));
+ ngMesh.AddFaceDescriptor( netgen::FaceDescriptor( faceNgID, solidID1, solidID2, 0 ));
// if second oreder is required, even already meshed faces must be passed to NETGEN
int fID = occgeom.fmap.Add( geomFace );
+ if ( occgeom.facemeshstatus.Size() < fID ) occgeom.facemeshstatus.SetSize( fID );
occgeom.facemeshstatus[ fID-1 ] = netgen::FACE_MESHED_OK;
- while ( fID < faceNgID ) { // geomFace is already in occgeom.fmap, add a copy
+ while ( fID < faceNgID ) // geomFace is already in occgeom.fmap, add a copy
+ {
fID = occgeom.fmap.Add( BRepBuilderAPI_Copy( geomFace, /*copyGeom=*/false ));
+ if ( occgeom.facemeshstatus.Size() < fID ) occgeom.facemeshstatus.SetSize( fID );
occgeom.facemeshstatus[ fID-1 ] = netgen::FACE_MESHED_OK;
}
// Problem with the second order in a quadrangular mesh remains.
// by FillSMesh() (find "AddFaceDescriptor")
// 2) Temporary triangles generated by StdMeshers_QuadToTriaAdaptor
// are on faces where quadrangles were.
- // Due to these 2 points, wrong geom faces are used while conversion to qudratic
+ // Due to these 2 points, wrong geom faces are used while conversion to quadratic
// of the mentioned above quadrangles and triangles
// Orient the face correctly in solidID1 (issue 0020206)
// Add surface elements
netgen::Element2d tri(3);
- tri.SetIndex ( faceNgID );
+ tri.SetIndex( faceNgID );
SMESH_TNodeXYZ xyz[3];
#ifdef DUMP_TRIANGLES
cout << "SMESH face " << helper.GetMeshDS()->ShapeToIndex( geomFace )
<< " internal="<<isInternalFace << endl;
#endif
- if ( proxyMesh )
- smDS = proxyMesh->GetSubMesh( geomFace );
SMDS_ElemIteratorPtr faces = smDS->GetElements();
while ( faces->more() )
int ngIdCloseN; //!< ng id of closest node of the closest 2d mesh element
};
- inline double dist2(const netgen::MeshPoint& p1, const netgen::MeshPoint& p2)
+ inline double dist2( const netgen::MeshPoint& p1, const netgen::MeshPoint& p2 )
{
return gp_Pnt( NGPOINT_COORDS(p1)).SquareDistance( gp_Pnt( NGPOINT_COORDS(p2)));
}
+
+ // inline double dist2(const netgen::MeshPoint& p, const SMDS_MeshNode* n )
+ // {
+ // return gp_Pnt( NGPOINT_COORDS(p)).SquareDistance( SMESH_NodeXYZ(n));
+ // }
}
//================================================================================
ngMesh.AddSegment (seg);
// add reverse segment
- swap (seg[0], seg[1]);
+ swap( seg[0], seg[1] );
swap( seg.epgeominfo[0], seg.epgeominfo[1] );
seg.edgenr = ngMesh.GetNSeg() + 1; // segment id
ngMesh.AddSegment (seg);
ofstream py(DUMP_TRIANGLES_SCRIPT);
py << "import SMESH"<< endl
<< "from salome.smesh import smeshBuilder"<<endl
- << "smesh = smeshBuilder.New(salome.myStudy)"<<endl
+ << "smesh = smeshBuilder.New()"<<endl
<< "m = smesh.Mesh(name='triangles')" << endl;
#endif
if ((int) nodeVec.size() < ngMesh.GetNP() )
else
{
double segLenHint = ngMesh.GetH( ngMesh.Point( vData.ngId ));
- bool avgLenOK = ( avgSegLen < 0.75 * distN1 );
- bool hintLenOK = ( segLenHint < 0.75 * distN1 );
+ bool avgLenOK = ( avgSegLen < 0.75 * distN1 );
+ bool hintLenOK = ( segLenHint < 0.75 * distN1 );
createNew = (createNew || avgLenOK || hintLenOK );
// we create a new node not closer than 0.5 to the closest face
// in order not to clash with other close face
const int solidID = 0, faceID = geom.fmap.FindIndex( helper.GetSubShape() );
if ( ngMesh.GetNFD() < 1 )
- ngMesh.AddFaceDescriptor (netgen::FaceDescriptor(faceID, solidID, solidID, 0));
+ ngMesh.AddFaceDescriptor( netgen::FaceDescriptor( faceID, solidID, solidID, 0 ));
for ( size_t iW = 0; iW < wires.size(); ++iW )
{
- StdMeshers_FaceSidePtr wire = wires[ iW ];
+ StdMeshers_FaceSidePtr wire = wires[ iW ];
const vector<UVPtStruct>& uvPtVec = wire->GetUVPtStruct();
- const int nbSegments = wire->NbPoints() - 1;
+ const int nbSegments = wire->NbPoints() - 1;
// assure the 1st node to be in node2ngID, which is needed to correctly
// "close chain of segments" (see below) in case if the 1st node is not
int edgeID = 1, posID = -2;
bool isInternalWire = false;
double vertexNormPar = 0;
- //const int prevNbNGSeg = ngMesh.GetNSeg();
+ const int prevNbNGSeg = ngMesh.GetNSeg();
for ( int i = 0; i < nbSegments; ++i ) // loop on segments
{
// Add the first point of a segment
// close chain of segments
if ( nbSegments > 0 )
{
- netgen::Segment& lastSeg = ngMesh.LineSegment( ngMesh.GetNSeg() - int( isInternalWire));
+ netgen::Segment& lastSeg = ngMesh.LineSegment( ngMesh.GetNSeg() - int( isInternalWire ));
const SMDS_MeshNode * lastNode = uvPtVec.back().node;
lastSeg[1] = node2ngID.insert( make_pair( lastNode, lastSeg[1] )).first->second;
if ( lastSeg[1] > ngMesh.GetNP() )
<< "\tp1 edge: " << seg.epgeominfo[ 1 ].edgenr << endl;
}
cout << "--END WIRE " << iW << endl;
+#else
+ SMESH_Comment __not_unused_variable( prevNbNGSeg );
#endif
} // loop on WIREs of a FACE
if ( quadHelper && !quadHelper->GetIsQuadratic() && quadHelper->GetTLinkNodeMap().empty() )
quadHelper = 0;
+ int i, nbInitNod = initState._nbNodes;
+ if ( initState._elementsRemoved )
+ {
+ // PAL23427. Update nodeVec to track removal of netgen free points as a result
+ // of removal of faces in FillNgMesh() in the case of a shrunk sub-mesh
+ int ngID, nodeVecSize = nodeVec.size();
+ const double eps = std::numeric_limits<double>::min();
+ for ( ngID = i = 1; i < nodeVecSize; ++ngID, ++i )
+ {
+ gp_Pnt ngPnt( NGPOINT_COORDS( ngMesh.Point( ngID )));
+ gp_Pnt node ( SMESH_NodeXYZ ( nodeVec[ i ]));
+ if ( ngPnt.SquareDistance( node ) < eps )
+ {
+ nodeVec[ ngID ] = nodeVec[ i ];
+ }
+ else
+ {
+ --ngID;
+ }
+ }
+ nodeVec.resize( ngID );
+ nbInitNod = ngID - 1;
+ }
// -------------------------------------
// Create and insert nodes into nodeVec
// -------------------------------------
nodeVec.resize( nbNod + 1 );
- int i, nbInitNod = initState._nbNodes;
- for (i = nbInitNod+1; i <= nbNod; ++i )
+ for ( i = nbInitNod+1; i <= nbNod; ++i )
{
const netgen::MeshPoint& ngPoint = ngMesh.Point(i);
SMDS_MeshNode* node = NULL;
for (i = nbInitFac+1; i <= nbFac; ++i )
{
const netgen::Element2d& elem = ngMesh.SurfaceElement(i);
- int aGeomFaceInd = elem.GetIndex();
+ const int aGeomFaceInd = elem.GetIndex();
TopoDS_Face aFace;
if (aGeomFaceInd > 0 && aGeomFaceInd <= occgeo.fmap.Extent())
aFace = TopoDS::Face(occgeo.fmap(aGeomFaceInd));
nodes.clear();
- for (int j=1; j <= elem.GetNP(); ++j)
+ for ( int j = 1; j <= elem.GetNP(); ++j )
{
int pind = elem.PNum(j);
if ( pind < 1 || pind >= (int) nodeVec.size() )
MESSAGE("NETGEN created a face of unexpected type, ignoring");
continue;
}
- if (!face)
+ if ( !face )
{
if ( comment.empty() ) comment << "Cannot create a mesh face";
MESSAGE("Cannot create a mesh face");
nbSeg = nbFac = nbVol = 0;
break;
}
- if (!aFace.IsNull())
- meshDS->SetMeshElementOnShape(face, aFace);
+ if ( !aFace.IsNull() )
+ meshDS->SetMeshElementOnShape( face, aFace );
}
// ------------------
// Create tetrahedra
// ------------------
- for (i = 1; i <= nbVol; ++i)
+ for ( i = 1; i <= nbVol; ++i )
{
const netgen::Element& elem = ngMesh.VolumeElement(i);
int aSolidInd = elem.GetIndex();
TopoDS_Solid aSolid;
- if (aSolidInd > 0 && aSolidInd <= occgeo.somap.Extent())
+ if ( aSolidInd > 0 && aSolidInd <= occgeo.somap.Extent() )
aSolid = TopoDS::Solid(occgeo.somap(aSolidInd));
nodes.clear();
- for (int j=1; j <= elem.GetNP(); ++j)
+ for ( int j = 1; j <= elem.GetNP(); ++j )
{
int pind = elem.PNum(j);
if ( pind < 1 || pind >= (int)nodeVec.size() )
continue;
}
SMDS_MeshVolume* vol = NULL;
- switch (elem.GetType())
+ switch ( elem.GetType() )
{
case netgen::TET:
vol = meshDS->AddVolume(nodes[0],nodes[1],nodes[2],nodes[3]);
namespace
{
- //================================================================================
- /*!
- * \brief Restrict size of elements on the given edge
- */
- //================================================================================
-
- void setLocalSize(const TopoDS_Edge& edge,
- double size,
- netgen::Mesh& mesh)
- {
- if ( size <= std::numeric_limits<double>::min() )
- return;
- Standard_Real u1, u2;
- Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, u1, u2);
- if ( curve.IsNull() )
- {
- TopoDS_Iterator vIt( edge );
- if ( !vIt.More() ) return;
- gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( vIt.Value() ));
- NETGENPlugin_Mesher::RestrictLocalSize( mesh, p.XYZ(), size );
- }
- else
- {
- const int nb = (int)( 1.5 * SMESH_Algo::EdgeLength( edge ) / size );
- Standard_Real delta = (u2-u1)/nb;
- for(int i=0; i<nb; i++)
- {
- Standard_Real u = u1 + delta*i;
- gp_Pnt p = curve->Value(u);
- NETGENPlugin_Mesher::RestrictLocalSize( mesh, p.XYZ(), size );
- netgen::Point3d pi(p.X(), p.Y(), p.Z());
- double resultSize = mesh.GetH(pi);
- if ( resultSize - size > 0.1*size )
- // netgen does restriction iff oldH/newH > 1.2 (localh.cpp:136)
- NETGENPlugin_Mesher::RestrictLocalSize( mesh, p.XYZ(), resultSize/1.201 );
- }
- }
- }
-
//================================================================================
/*!
* \brief Convert error into text
NETGENPlugin_NetgenLibWrapper ngLib;
netgen::MeshingParameters& mparams = netgen::mparam;
- MESSAGE("Compute with:\n"
- " max size = " << mparams.maxh << "\n"
- " segments per edge = " << mparams.segmentsperedge);
- MESSAGE("\n"
- " growth rate = " << mparams.grading << "\n"
- " elements per radius = " << mparams.curvaturesafety << "\n"
- " second order = " << mparams.secondorder << "\n"
- " quad allowed = " << mparams.quad << "\n"
- " surface curvature = " << mparams.uselocalh << "\n"
- " fuse edges = " << netgen::merge_solids);
SMESH_ComputeErrorPtr error = SMESH_ComputeError::New();
SMESH_MesherHelper quadHelper( *_mesh );
quadHelper.SetIsQuadratic( mparams.secondorder );
- static string debugFile = "/tmp/ngMesh.py"; /* to call toPython( _ngMesh, debugFile )
- while debugging netgen */
// -------------------------
// Prepare OCC geometry
// -------------------------
{
comment << text(ex);
}
+ catch (netgen::NgException & ex)
+ {
+ comment << text(ex);
+ if ( mparams.meshsizefilename )
+ throw SMESH_ComputeError(COMPERR_BAD_PARMETERS, comment );
+ }
err = 0; //- MESHCONST_ANALYSE isn't so important step
if ( !_ngMesh )
return false;
_ngMesh->ClearFaceDescriptors(); // we make descriptors our-self
+ if ( !mparams.uselocalh ) // mparams.grading is not taken into account yet
+ _ngMesh->LocalHFunction().SetGrading( mparams.grading );
+
if ( _simpleHyp )
{
// Pass 1D simple parameters to NETGEN
}
else // if ( ! _simpleHyp )
{
- // Local size on vertices and edges
- // --------------------------------
- for(std::map<int,double>::const_iterator it=EdgeId2LocalSize.begin(); it!=EdgeId2LocalSize.end(); it++)
- {
- int key = (*it).first;
- double hi = (*it).second;
- const TopoDS_Shape& shape = ShapesWithLocalSize.FindKey(key);
- const TopoDS_Edge& e = TopoDS::Edge(shape);
- setLocalSize( e, hi, *_ngMesh );
- }
- for(std::map<int,double>::const_iterator it=VertexId2LocalSize.begin(); it!=VertexId2LocalSize.end(); it++)
- {
- int key = (*it).first;
- double hi = (*it).second;
- const TopoDS_Shape& shape = ShapesWithLocalSize.FindKey(key);
- const TopoDS_Vertex& v = TopoDS::Vertex(shape);
- gp_Pnt p = BRep_Tool::Pnt(v);
- NETGENPlugin_Mesher::RestrictLocalSize( *_ngMesh, p.XYZ(), hi );
- }
- for(map<int,double>::const_iterator it=FaceId2LocalSize.begin();
- it!=FaceId2LocalSize.end(); it++)
- {
- int key = (*it).first;
- double val = (*it).second;
- const TopoDS_Shape& shape = ShapesWithLocalSize.FindKey(key);
- int faceNgID = occgeo.fmap.FindIndex(shape);
- occgeo.SetFaceMaxH(faceNgID, val);
- for ( TopExp_Explorer edgeExp( shape, TopAbs_EDGE ); edgeExp.More(); edgeExp.Next() )
- setLocalSize( TopoDS::Edge( edgeExp.Current() ), val, *_ngMesh );
- }
+ // Local size on shapes
+ SetLocalSize( occgeo, *_ngMesh );
}
// Precompute internal edges (issue 0020676) in order to
}
// Build viscous layers
- if ( _isViscousLayers2D )
+ if ( _isViscousLayers2D ||
+ StdMeshers_ViscousLayers2D::HasProxyMesh( TopoDS::Face( occgeo.fmap(1) ), *_mesh ))
{
if ( !internals.hasInternalVertexInFace() ) {
FillSMesh( occgeo, *_ngMesh, initState, *_mesh, nodeVec, comment );
viscousMesh = StdMeshers_ViscousLayers2D::Compute( *_mesh, F );
if ( !viscousMesh )
return false;
+ if ( viscousMesh->NbProxySubMeshes() == 0 )
+ continue;
// exclude from computation ng segments built on EDGEs of F
for (int i = 1; i <= _ngMesh->GetNSeg(); i++)
{
helper.SetSubShape( F );
TSideVector wires =
StdMeshers_FaceSide::GetFaceWires( F, *_mesh, /*skipMediumNodes=*/true,
- error, viscousMesh );
+ error, &helper, viscousMesh );
error = AddSegmentsToMesh( *_ngMesh, occgeo, wires, helper, nodeVec );
if ( !error ) error = SMESH_ComputeError::New();
// generate volume mesh
// ---------------------
// Fill _ngMesh with nodes and faces of computed 2D submeshes
- if ( !err && _isVolume && ( !meshedSM[ MeshDim_2D ].empty() || mparams.quad ))
+ if ( !err && _isVolume &&
+ ( !meshedSM[ MeshDim_2D ].empty() || mparams.quad || _viscousLayersHyp ))
{
// load SMESH with computed segments and faces
FillSMesh( occgeo, *_ngMesh, initState, *_mesh, nodeVec, comment, &quadHelper );
+ // compute prismatic boundary volumes
+ int nbQuad = _mesh->NbQuadrangles();
+ SMESH_ProxyMesh::Ptr viscousMesh;
+ if ( _viscousLayersHyp )
+ {
+ viscousMesh = _viscousLayersHyp->Compute( *_mesh, _shape );
+ if ( !viscousMesh )
+ return false;
+ }
// compute pyramids on quadrangles
- SMESH_ProxyMesh::Ptr proxyMesh;
- if ( _mesh->NbQuadrangles() > 0 )
+ vector<SMESH_ProxyMesh::Ptr> pyramidMeshes( occgeo.somap.Extent() );
+ if ( nbQuad > 0 )
for ( int iS = 1; iS <= occgeo.somap.Extent(); ++iS )
{
- StdMeshers_QuadToTriaAdaptor* Adaptor = new StdMeshers_QuadToTriaAdaptor;
- proxyMesh.reset( Adaptor );
-
- int nbPyrams = _mesh->NbPyramids();
- Adaptor->Compute( *_mesh, occgeo.somap(iS) );
- if ( nbPyrams != _mesh->NbPyramids() )
+ StdMeshers_QuadToTriaAdaptor* adaptor = new StdMeshers_QuadToTriaAdaptor;
+ pyramidMeshes[ iS-1 ].reset( adaptor );
+ bool ok = adaptor->Compute( *_mesh, occgeo.somap(iS), viscousMesh.get() );
+ if ( !ok )
+ return false;
+ }
+ // add proxy faces to NG mesh
+ list< SMESH_subMesh* > viscousSM;
+ for ( int iS = 1; iS <= occgeo.somap.Extent(); ++iS )
+ {
+ list< SMESH_subMesh* > quadFaceSM;
+ for (TopExp_Explorer face(occgeo.somap(iS), TopAbs_FACE); face.More(); face.Next())
+ if ( pyramidMeshes[iS-1] && pyramidMeshes[iS-1]->GetProxySubMesh( face.Current() ))
{
- list< SMESH_subMesh* > quadFaceSM;
- for (TopExp_Explorer face(occgeo.somap(iS), TopAbs_FACE); face.More(); face.Next())
- if ( Adaptor->GetProxySubMesh( face.Current() ))
- {
- quadFaceSM.push_back( _mesh->GetSubMesh( face.Current() ));
- meshedSM[ MeshDim_2D ].remove( quadFaceSM.back() );
- }
- FillNgMesh(occgeo, *_ngMesh, nodeVec, quadFaceSM, &quadHelper, proxyMesh);
+ quadFaceSM.push_back( _mesh->GetSubMesh( face.Current() ));
+ meshedSM[ MeshDim_2D ].remove( quadFaceSM.back() );
}
- }
+ else if ( viscousMesh && viscousMesh->GetProxySubMesh( face.Current() ))
+ {
+ viscousSM.push_back( _mesh->GetSubMesh( face.Current() ));
+ meshedSM[ MeshDim_2D ].remove( viscousSM.back() );
+ }
+ if ( !quadFaceSM.empty() )
+ FillNgMesh(occgeo, *_ngMesh, nodeVec, quadFaceSM, &quadHelper, pyramidMeshes[iS-1]);
+ }
+ if ( !viscousSM.empty() )
+ FillNgMesh(occgeo, *_ngMesh, nodeVec, viscousSM, &quadHelper, viscousMesh );
+
// fill _ngMesh with faces of sub-meshes
err = ! ( FillNgMesh(occgeo, *_ngMesh, nodeVec, meshedSM[ MeshDim_2D ], &quadHelper));
- initState = NETGENPlugin_ngMeshInfo(_ngMesh);
- //toPython( _ngMesh, "/tmp/ngPython.py");
+ initState = NETGENPlugin_ngMeshInfo(_ngMesh, /*checkRemovedElems=*/true);
+ // toPython( _ngMesh );
}
if (!err && _isVolume)
{
_ticTime = 0.98 / _progressTic;
- int nbNod = _ngMesh->GetNP();
- int nbSeg = _ngMesh->GetNSeg();
+ //int nbNod = _ngMesh->GetNP();
+ //int nbSeg = _ngMesh->GetNSeg();
int nbFac = _ngMesh->GetNSE();
int nbVol = _ngMesh->GetNE();
bool isOK = ( !err && (_isVolume ? (nbVol > 0) : (nbFac > 0)) );
- MESSAGE((err ? "Mesh Generation failure" : "End of Mesh Generation") <<
- ", nb nodes: " << nbNod <<
- ", nb segments: " << nbSeg <<
- ", nb faces: " << nbFac <<
- ", nb volumes: " << nbVol);
-
// Feed back the SMESHDS with the generated Nodes and Elements
if ( true /*isOK*/ ) // get whatever built
{
}
else // if ( ! _simpleHyp )
{
- // Local size on vertices and edges
- // --------------------------------
- for(std::map<int,double>::const_iterator it=EdgeId2LocalSize.begin(); it!=EdgeId2LocalSize.end(); it++)
- {
- int key = (*it).first;
- double hi = (*it).second;
- const TopoDS_Shape& shape = ShapesWithLocalSize.FindKey(key);
- const TopoDS_Edge& e = TopoDS::Edge(shape);
- setLocalSize( e, hi, *ngMesh );
- }
- for(std::map<int,double>::const_iterator it=VertexId2LocalSize.begin(); it!=VertexId2LocalSize.end(); it++)
- {
- int key = (*it).first;
- double hi = (*it).second;
- const TopoDS_Shape& shape = ShapesWithLocalSize.FindKey(key);
- const TopoDS_Vertex& v = TopoDS::Vertex(shape);
- gp_Pnt p = BRep_Tool::Pnt(v);
- NETGENPlugin_Mesher::RestrictLocalSize( *ngMesh, p.XYZ(), hi );
- }
- for(map<int,double>::const_iterator it=FaceId2LocalSize.begin();
- it!=FaceId2LocalSize.end(); it++)
- {
- int key = (*it).first;
- double val = (*it).second;
- const TopoDS_Shape& shape = ShapesWithLocalSize.FindKey(key);
- int faceNgID = occgeo.fmap.FindIndex(shape);
- occgeo.SetFaceMaxH(faceNgID, val);
- for ( TopExp_Explorer edgeExp( shape, TopAbs_EDGE ); edgeExp.More(); edgeExp.Next() )
- setLocalSize( TopoDS::Edge( edgeExp.Current() ), val, *ngMesh );
- }
+ // Local size on shapes
+ SetLocalSize( occgeo, *ngMesh );
}
// calculate total nb of segments and length of edges
double fullLen = 0.0;
// << " " << doneTime / _totalTime / _progressTic << endl;
}
}
+
if ( _ticTime > 0 )
progress = Max( *algoProgressTic * _ticTime, *algoProgress );
+
if ( progress > 0 )
{
+ if ( _isVolume &&
+ netgen::multithread.task[0] == 'D'/*elaunay meshing*/ &&
+ progress > voluMeshingTime )
+ {
+ progress = voluMeshingTime;
+ ((double&) _ticTime) = voluMeshingTime / _totalTime / _progressTic;
+ }
((int&) *algoProgressTic )++;
((double&) *algoProgress) = progress;
}
return Min( progress, 0.99 );
}
-//================================================================================
-/*!
- * \brief Remove "test.out" and "problemfaces" files in current directory
- */
-//================================================================================
-
-void NETGENPlugin_Mesher::RemoveTmpFiles()
-{
- bool rm = SMESH_File("test.out").remove() ;
-#ifndef WIN32
- if (rm && netgen::testout)
- {
- delete netgen::testout;
- netgen::testout = 0;
- }
-#endif
- SMESH_File("problemfaces").remove();
- SMESH_File("occmesh.rep").remove();
-}
-
//================================================================================
/*!
* \brief Read mesh entities preventing successful computation from "test.out" file
#ifdef _DEBUG_
size_t nbBadElems = err->myBadElements.size();
- nbBadElems = 0;
+ if ( nbBadElems ) nbBadElems++; // avoid warning: variable set but not used
#endif
return err;
*/
//================================================================================
-void NETGENPlugin_Mesher::toPython( const netgen::Mesh* ngMesh,
- const std::string& pyFile)
+void NETGENPlugin_Mesher::toPython( const netgen::Mesh* ngMesh )
{
- ofstream outfile(pyFile.c_str(), ios::out);
+ const char* pyFile = "/tmp/ngMesh.py";
+ ofstream outfile( pyFile, ios::out );
if ( !outfile ) return;
- outfile << "import SMESH" << endl
+ outfile << "import salome, SMESH" << endl
<< "from salome.smesh import smeshBuilder" << endl
- << "smesh = smeshBuilder.New(salome.myStudy)" << endl
+ << "smesh = smeshBuilder.New()" << endl
<< "mesh = smesh.Mesh()" << endl << endl;
using namespace netgen;
*/
//================================================================================
-NETGENPlugin_ngMeshInfo::NETGENPlugin_ngMeshInfo( netgen::Mesh* ngMesh):
- _copyOfLocalH(0)
+NETGENPlugin_ngMeshInfo::NETGENPlugin_ngMeshInfo( netgen::Mesh* ngMesh,
+ bool checkRemovedElems):
+ _elementsRemoved( false ), _copyOfLocalH(0)
{
if ( ngMesh )
{
_nbSegments = ngMesh->GetNSeg();
_nbFaces = ngMesh->GetNSE();
_nbVolumes = ngMesh->GetNE();
+
+ if ( checkRemovedElems )
+ for ( int i = 1; i <= ngMesh->GetNSE() && !_elementsRemoved; ++i )
+ _elementsRemoved = ngMesh->SurfaceElement(i).IsDeleted();
}
else
{
return const_cast<SMESH_Mesh&>( _mesh );
}
+//================================================================================
+/*!
+ * \brief Access to a counter of NETGENPlugin_NetgenLibWrapper instances
+ */
+//================================================================================
+
+int& NETGENPlugin_NetgenLibWrapper::instanceCounter()
+{
+ static int theCouner = 0;
+ return theCouner;
+}
+
//================================================================================
/*!
* \brief Initialize netgen library
NETGENPlugin_NetgenLibWrapper::NETGENPlugin_NetgenLibWrapper()
{
- Ng_Init();
+ if ( instanceCounter() == 0 )
+ Ng_Init();
+
+ ++instanceCounter();
_isComputeOk = false;
_coutBuffer = NULL;
+ _ngcout = NULL;
+ _ngcerr = NULL;
if ( !getenv( "KEEP_NETGEN_OUTPUT" ))
{
// redirect all netgen output (mycout,myerr,cout) to _outputFileName
_outputFileName = getOutputFileName();
+ _ngcout = netgen::mycout;
+ _ngcerr = netgen::myerr;
netgen::mycout = new ofstream ( _outputFileName.c_str() );
netgen::myerr = netgen::mycout;
_coutBuffer = std::cout.rdbuf();
NETGENPlugin_NetgenLibWrapper::~NETGENPlugin_NetgenLibWrapper()
{
+ --instanceCounter();
+
Ng_DeleteMesh( _ngMesh );
Ng_Exit();
- NETGENPlugin_Mesher::RemoveTmpFiles();
+ RemoveTmpFiles();
if ( _coutBuffer )
std::cout.rdbuf( _coutBuffer );
#ifdef _DEBUG_
return aGenericName.ToCString();
}
+//================================================================================
+/*!
+ * \brief Remove "test.out" and "problemfaces" files in current directory
+ */
+//================================================================================
+
+void NETGENPlugin_NetgenLibWrapper::RemoveTmpFiles()
+{
+ bool rm = SMESH_File("test.out").remove() ;
+#ifndef WIN32
+ if ( rm && netgen::testout && instanceCounter() == 0 )
+ {
+ delete netgen::testout;
+ netgen::testout = 0;
+ }
+#endif
+ SMESH_File("problemfaces").remove();
+ SMESH_File("occmesh.rep").remove();
+}
+
//================================================================================
/*!
* \brief Remove file with netgen output
{
if ( !_outputFileName.empty() )
{
- if ( netgen::mycout )
+ if ( _ngcout )
{
delete netgen::mycout;
- netgen::mycout = 0;
- netgen::myerr = 0;
+ netgen::mycout = _ngcout;
+ netgen::myerr = _ngcerr;
+ _ngcout = 0;
}
string tmpDir = SALOMEDS_Tool::GetDirFromPath ( _outputFileName );
string aFileName = SALOMEDS_Tool::GetNameFromPath( _outputFileName ) + ".out";
- SALOMEDS::ListOfFileNames_var aFiles = new SALOMEDS::ListOfFileNames;
- aFiles->length(1);
- aFiles[0] = aFileName.c_str();
+ SALOMEDS_Tool::ListOfFiles aFiles;
+ aFiles.reserve(1);
+ aFiles.push_back(aFileName.c_str());
- SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.c_str(), aFiles.in(), true );
+ SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.c_str(), aFiles, true );
}
}