Back to index

salome-smesh  6.5.0
Public Member Functions | Private Member Functions | Private Attributes
VISCOUS::_ViscousBuilder Class Reference

Builder of viscous layers. More...

Collaboration diagram for VISCOUS::_ViscousBuilder:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 _ViscousBuilder ()
 Constructor of _ViscousBuilder.
SMESH_ComputeErrorPtr Compute (SMESH_Mesh &mesh, const TopoDS_Shape &shape)
 Does its job.
void RestoreListeners ()
 At study restoration, restore event listeners used to clear an inferior dim sub-mesh modified by viscous layers.
bool MakeN2NMap (_MeshOfSolid *pm)
 computes SMESH_ProxyMesh::SubMesh::_n2n

Private Member Functions

bool findSolidsWithLayers ()
 Finds SOLIDs to compute using viscous layers.
bool findFacesWithLayers ()
bool makeLayer (_SolidData &data)
 Create the inner surface of the viscous layer and prepare data for infation.
bool setEdgeData (_LayerEdge &edge, const set< TGeomID > &subIds, SMESH_MesherHelper &helper, _SolidData &data)
 Set data of _LayerEdge needed for smoothing.
bool findNeiborsOnEdge (const _LayerEdge *edge, const SMDS_MeshNode *&n1, const SMDS_MeshNode *&n2, _SolidData &data)
 Find 2 neigbor nodes of a node on EDGE.
void getSimplices (const SMDS_MeshNode *node, vector< _Simplex > &simplices, const set< TGeomID > &ingnoreShapes, const _SolidData *dataToCheckOri=0, const bool toSort=false)
 Fills a vector<_Simplex >
bool sortEdges (_SolidData &data, vector< vector< _LayerEdge * > > &edgesByGeom)
 Separate shapes (and _LayerEdge's on them) to smooth from the rest ones.
void limitStepSize (_SolidData &data, const SMDS_MeshElement *face, const double cosin)
 Compute inflation step size by min size of element on a convex surface.
void limitStepSize (_SolidData &data, const double minSize)
 Compute inflation step size by min size of element on a convex surface.
bool inflate (_SolidData &data)
 Increase length of _LayerEdge's to reach the required thickness of layers.
bool smoothAndCheck (_SolidData &data, const int nbSteps, double &distToIntersection)
 Improve quality of layer inner surface and check intersection.
bool smoothAnalyticEdge (_SolidData &data, const int iFrom, const int iTo, Handle(Geom_Surface)&surface, const TopoDS_Face &F, SMESH_MesherHelper &helper)
 smooth _LayerEdge's on a staight EDGE or circular EDGE
bool updateNormals (_SolidData &data, SMESH_MesherHelper &helper)
 Modify normals of _LayerEdge's on EDGE's to avoid intersection with _LayerEdge's on neighbor EDGE's.
bool refine (_SolidData &data)
 Create layers of prisms.
bool shrink ()
 Shrink 2D mesh on faces to let space for inflated layers.
bool prepareEdgeToShrink (_LayerEdge &edge, const TopoDS_Face &F, SMESH_MesherHelper &helper, const SMESHDS_SubMesh *faceSubMesh)
 Computes 2d shrink direction and finds nodes limiting shrinking.
void fixBadFaces (const TopoDS_Face &F, SMESH_MesherHelper &helper)
 Try to fix triangles with high aspect ratio by swaping diagonals.
bool addBoundaryElements ()
 Creates 2D and 1D elements on boundaries of new prisms.
bool error (const string &text, int solidID=-1)
 Stores error description and returns false.
SMESHDS_Mesh * getMeshDS ()
void makeGroupOfLE ()
 DEBUG.

Private Attributes

SMESH_Mesh * _mesh
SMESH_ComputeErrorPtr _error
vector< _SolidData_sdVec
set< TGeomID_ignoreShapeIds
int _tmpFaceID

Detailed Description

Builder of viscous layers.

Definition at line 433 of file StdMeshers_ViscousLayers.cxx.


Constructor & Destructor Documentation

Constructor of _ViscousBuilder.

Definition at line 859 of file StdMeshers_ViscousLayers.cxx.

Here is the call graph for this function:


Member Function Documentation

Creates 2D and 1D elements on boundaries of new prisms.

Definition at line 4377 of file StdMeshers_ViscousLayers.cxx.

{
  SMESH_MesherHelper helper( *_mesh );

  for ( unsigned i = 0; i < _sdVec.size(); ++i )
  {
    _SolidData& data = _sdVec[i];
    TopTools_IndexedMapOfShape geomEdges;
    TopExp::MapShapes( data._solid, TopAbs_EDGE, geomEdges );
    for ( int iE = 1; iE <= geomEdges.Extent(); ++iE )
    {
      const TopoDS_Edge& E = TopoDS::Edge( geomEdges(iE));

      // Get _LayerEdge's based on E

      map< double, const SMDS_MeshNode* > u2nodes;
      if ( !SMESH_Algo::GetSortedNodesOnEdge( getMeshDS(), E, /*ignoreMedium=*/false, u2nodes))
        continue;

      vector< _LayerEdge* > ledges; ledges.reserve( u2nodes.size() );
      TNode2Edge & n2eMap = data._n2eMap;
      map< double, const SMDS_MeshNode* >::iterator u2n = u2nodes.begin();
      {
        //check if 2D elements are needed on E
        TNode2Edge::iterator n2e = n2eMap.find( u2n->second );
        if ( n2e == n2eMap.end() ) continue; // no layers on vertex
        ledges.push_back( n2e->second );
        u2n++;
        if (( n2e = n2eMap.find( u2n->second )) == n2eMap.end() )
          continue; // no layers on E
        ledges.push_back( n2eMap[ u2n->second ]);

        const SMDS_MeshNode* tgtN0 = ledges[0]->_nodes.back();
        const SMDS_MeshNode* tgtN1 = ledges[1]->_nodes.back();
        int nbSharedPyram = 0;
        SMDS_ElemIteratorPtr vIt = tgtN0->GetInverseElementIterator(SMDSAbs_Volume);
        while ( vIt->more() )
        {
          const SMDS_MeshElement* v = vIt->next();
          nbSharedPyram += int( v->GetNodeIndex( tgtN1 ) >= 0 );
        }
        if ( nbSharedPyram > 1 )
          continue; // not free border of the pyramid

        if ( getMeshDS()->FindFace( ledges[0]->_nodes[0], ledges[0]->_nodes[1],
                                    ledges[1]->_nodes[0], ledges[1]->_nodes[1]))
          continue; // faces already created
      }
      for ( ++u2n; u2n != u2nodes.end(); ++u2n )
        ledges.push_back( n2eMap[ u2n->second ]);

      // Find out orientation and type of face to create

      bool reverse = false, isOnFace;
      
      map< TGeomID, TopoDS_Shape >::iterator e2f =
        data._shrinkShape2Shape.find( getMeshDS()->ShapeToIndex( E ));
      TopoDS_Shape F;
      if (( isOnFace = ( e2f != data._shrinkShape2Shape.end() )))
      {
        F = e2f->second.Oriented( TopAbs_FORWARD );
        reverse = ( helper.GetSubShapeOri( F, E ) == TopAbs_REVERSED );
        if ( helper.GetSubShapeOri( data._solid, F ) == TopAbs_REVERSED )
          reverse = !reverse;
      }
      else
      {
        // find FACE with layers sharing E
        PShapeIteratorPtr fIt = helper.GetAncestors( E, *_mesh, TopAbs_FACE );
        while ( fIt->more() && F.IsNull() )
        {
          const TopoDS_Shape* pF = fIt->next();
          if ( helper.IsSubShape( *pF, data._solid) &&
               !_ignoreShapeIds.count( e2f->first ))
            F = *pF;
        }
      }
      // Find the sub-mesh to add new faces
      SMESHDS_SubMesh* sm = 0;
      if ( isOnFace )
        sm = getMeshDS()->MeshElements( F );
      else
        sm = data._proxyMesh->getFaceSubM( TopoDS::Face(F), /*create=*/true );
      if ( !sm )
        return error("error in addBoundaryElements()", data._index);

      // Make faces
      const int dj1 = reverse ? 0 : 1;
      const int dj2 = reverse ? 1 : 0;
      for ( unsigned j = 1; j < ledges.size(); ++j )
      {
        vector< const SMDS_MeshNode*>&  nn1 = ledges[j-dj1]->_nodes;
        vector< const SMDS_MeshNode*>&  nn2 = ledges[j-dj2]->_nodes;
        if ( isOnFace )
          for ( unsigned z = 1; z < nn1.size(); ++z )
            sm->AddElement( getMeshDS()->AddFace( nn1[z-1], nn2[z-1], nn2[z], nn1[z] ));
        else
          for ( unsigned z = 1; z < nn1.size(); ++z )
            sm->AddElement( new SMDS_FaceOfNodes( nn1[z-1], nn2[z-1], nn2[z], nn1[z]));
      }
    }
  }

  return true;
}

Here is the call graph for this function:

SMESH_ComputeErrorPtr _ViscousBuilder::Compute ( SMESH_Mesh &  mesh,
const TopoDS_Shape &  shape 
)

Does its job.

Definition at line 950 of file StdMeshers_ViscousLayers.cxx.

{
  // TODO: set priority of solids during Gen::Compute()

  _mesh = & theMesh;

  // check if proxy mesh already computed
  TopExp_Explorer exp( theShape, TopAbs_SOLID );
  if ( !exp.More() )
    return error("No SOLID's in theShape"), _error;

  if ( _ViscousListener::GetSolidMesh( _mesh, exp.Current(), /*toCreate=*/false))
    return SMESH_ComputeErrorPtr(); // everything already computed

  PyDump debugDump;

  // TODO: ignore already computed SOLIDs 
  if ( !findSolidsWithLayers())
    return _error;

  if ( !findFacesWithLayers() )
    return _error;

  for ( unsigned i = 0; i < _sdVec.size(); ++i )
  {
    if ( ! makeLayer(_sdVec[i]) )
      return _error;
    
    if ( ! inflate(_sdVec[i]) )
      return _error;

    if ( ! refine(_sdVec[i]) )
      return _error;
  }
  if ( !shrink() )
    return _error;

  addBoundaryElements();

  makeGroupOfLE(); // debug
  debugDump.Finish();

  return _error;
}

Here is the call graph for this function:

bool _ViscousBuilder::error ( const string &  text,
int  solidID = -1 
) [private]

Stores error description and returns false.

Definition at line 871 of file StdMeshers_ViscousLayers.cxx.

{
  _error->myName    = COMPERR_ALGO_FAILED;
  _error->myComment = string("Viscous layers builder: ") + text;
  if ( _mesh )
  {
    SMESH_subMesh* sm = _mesh->GetSubMeshContaining( solidId );
    if ( !sm && !_sdVec.empty() )
      sm = _mesh->GetSubMeshContaining( _sdVec[0]._index );
    if ( sm && sm->GetSubShape().ShapeType() == TopAbs_SOLID )
    {
      SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
      if ( smError && smError->myAlgo )
        _error->myAlgo = smError->myAlgo;
      smError = _error;
    }
  }
  makeGroupOfLE(); // debug

  return false;
}

Definition at line 1044 of file StdMeshers_ViscousLayers.cxx.

{
  // collect all faces to ignore defined by hyp
  vector<TopoDS_Shape> ignoreFaces;
  for ( unsigned i = 0; i < _sdVec.size(); ++i )
  {
    vector<TGeomID> ids = _sdVec[i]._hyp->GetIgnoreFaces();
    for ( unsigned i = 0; i < ids.size(); ++i )
    {
      const TopoDS_Shape& s = getMeshDS()->IndexToShape( ids[i] );
      if ( !s.IsNull() && s.ShapeType() == TopAbs_FACE )
      {
        _ignoreShapeIds.insert( ids[i] );
        ignoreFaces.push_back( s );
      }
    }
  }

  // ignore internal faces
  SMESH_MesherHelper helper( *_mesh );
  TopExp_Explorer exp;
  for ( unsigned i = 0; i < _sdVec.size(); ++i )
  {
    exp.Init( _sdVec[i]._solid.Oriented( TopAbs_FORWARD ), TopAbs_FACE );
    for ( ; exp.More(); exp.Next() )
    {
      TGeomID faceInd = getMeshDS()->ShapeToIndex( exp.Current() );
      if ( helper.NbAncestors( exp.Current(), *_mesh, TopAbs_SOLID ) > 1 )
      {     
        _ignoreShapeIds.insert( faceInd );
        ignoreFaces.push_back( exp.Current() );
        if ( SMESH_Algo::IsReversedSubMesh( TopoDS::Face( exp.Current() ), getMeshDS()))
          _sdVec[i]._reversedFaceIds.insert( faceInd );
      }
    }
  }

  // Find faces to shrink mesh on (solution 2 in issue 0020832);
  TopTools_IndexedMapOfShape shapes;
  for ( unsigned i = 0; i < _sdVec.size(); ++i )
  {
    shapes.Clear();
    TopExp::MapShapes(_sdVec[i]._solid, TopAbs_EDGE, shapes);
    for ( int iE = 1; iE <= shapes.Extent(); ++iE )
    {
      const TopoDS_Shape& edge = shapes(iE);
      // find 2 faces sharing an edge
      TopoDS_Shape FF[2];
      PShapeIteratorPtr fIt = helper.GetAncestors(edge, *_mesh, TopAbs_FACE);
      while ( fIt->more())
      {
        const TopoDS_Shape* f = fIt->next();
        if ( helper.IsSubShape( *f, _sdVec[i]._solid))
          FF[ int( !FF[0].IsNull()) ] = *f;
      }
      if( FF[1].IsNull() ) continue; // seam edge can be shared by 1 FACE only
      // check presence of layers on them
      int ignore[2];
      for ( int j = 0; j < 2; ++j )
        ignore[j] = _ignoreShapeIds.count ( getMeshDS()->ShapeToIndex( FF[j] ));
      if ( ignore[0] == ignore[1] ) continue; // nothing interesting
      TopoDS_Shape fWOL = FF[ ignore[0] ? 0 : 1 ];
      // add edge to maps
      TGeomID edgeInd = getMeshDS()->ShapeToIndex( edge );
      _sdVec[i]._shrinkShape2Shape.insert( make_pair( edgeInd, fWOL ));
    }
  }
  // Exclude from _shrinkShape2Shape FACE's that can't be shrinked since
  // the algo of the SOLID sharing the FACE does not support it
  set< string > notSupportAlgos; notSupportAlgos.insert("Hexa_3D");
  for ( unsigned i = 0; i < _sdVec.size(); ++i )
  {
    TopTools_MapOfShape noShrinkVertices;
    map< TGeomID, TopoDS_Shape >::iterator e2f = _sdVec[i]._shrinkShape2Shape.begin();
    for ( ; e2f != _sdVec[i]._shrinkShape2Shape.end(); ++e2f )
    {
      const TopoDS_Shape& fWOL = e2f->second;
      TGeomID           edgeID = e2f->first;
      bool notShrinkFace = false;
      PShapeIteratorPtr soIt = helper.GetAncestors(fWOL, *_mesh, TopAbs_SOLID);
      while ( soIt->more())
      {
        const TopoDS_Shape* solid = soIt->next();
        if ( _sdVec[i]._solid.IsSame( *solid )) continue;
        SMESH_Algo* algo = _mesh->GetGen()->GetAlgo( *_mesh, *solid );
        if ( !algo || !notSupportAlgos.count( algo->GetName() )) continue;
        notShrinkFace = true;
        for ( unsigned j = 0; j < _sdVec.size(); ++j )
        {
          if ( _sdVec[j]._solid.IsSame( *solid ) )
            if ( _sdVec[j]._shrinkShape2Shape.count( edgeID ))
              notShrinkFace = false;
        }
      }
      if ( notShrinkFace )
      {
        _sdVec[i]._noShrinkFaces.insert( getMeshDS()->ShapeToIndex( fWOL ));
        for ( TopExp_Explorer vExp( fWOL, TopAbs_VERTEX ); vExp.More(); vExp.Next() )
          noShrinkVertices.Add( vExp.Current() );
      }
    }
    // erase from _shrinkShape2Shape all srink EDGE's of a SOLID connected
    // to the found not shrinked fWOL's
    e2f = _sdVec[i]._shrinkShape2Shape.begin();
    for ( ; e2f != _sdVec[i]._shrinkShape2Shape.end(); )
    {
      TGeomID edgeID = e2f->first;
      TopoDS_Vertex VV[2];
      TopExp::Vertices( TopoDS::Edge( getMeshDS()->IndexToShape( edgeID )),VV[0],VV[1]);
      if ( noShrinkVertices.Contains( VV[0] ) || noShrinkVertices.Contains( VV[1] ))
      {
        _sdVec[i]._noShrinkFaces.insert( getMeshDS()->ShapeToIndex( e2f->second ));
        _sdVec[i]._shrinkShape2Shape.erase( e2f++ );
      }
      else
      {
        e2f++;
      }
    }
  }
      
  // Find the SHAPE along which to inflate _LayerEdge based on VERTEX

  for ( unsigned i = 0; i < _sdVec.size(); ++i )
  {
    shapes.Clear();
    TopExp::MapShapes(_sdVec[i]._solid, TopAbs_VERTEX, shapes);
    for ( int iV = 1; iV <= shapes.Extent(); ++iV )
    {
      const TopoDS_Shape& vertex = shapes(iV);
      // find faces WOL sharing the vertex
      vector< TopoDS_Shape > facesWOL;
      int totalNbFaces = 0;
      PShapeIteratorPtr fIt = helper.GetAncestors(vertex, *_mesh, TopAbs_FACE);
      while ( fIt->more())
      {
        const TopoDS_Shape* f = fIt->next();
        const int         fID = getMeshDS()->ShapeToIndex( *f );
        if ( helper.IsSubShape( *f, _sdVec[i]._solid ) )
        {
          totalNbFaces++;
          if ( _ignoreShapeIds.count ( fID ) && ! _sdVec[i]._noShrinkFaces.count( fID ))
            facesWOL.push_back( *f );
        }
      }
      if ( facesWOL.size() == totalNbFaces || facesWOL.empty() )
        continue; // no layers at this vertex or no WOL
      TGeomID vInd = getMeshDS()->ShapeToIndex( vertex );
      switch ( facesWOL.size() )
      {
      case 1:
        {
          helper.SetSubShape( facesWOL[0] );
          if ( helper.IsRealSeam( vInd )) // inflate along a seam edge?
          {
            TopoDS_Shape seamEdge;
            PShapeIteratorPtr eIt = helper.GetAncestors(vertex, *_mesh, TopAbs_EDGE);
            while ( eIt->more() && seamEdge.IsNull() )
            {
              const TopoDS_Shape* e = eIt->next();
              if ( helper.IsRealSeam( *e ) )
                seamEdge = *e;
            }
            if ( !seamEdge.IsNull() )
            {
              _sdVec[i]._shrinkShape2Shape.insert( make_pair( vInd, seamEdge ));
              break;
            }
          }
          _sdVec[i]._shrinkShape2Shape.insert( make_pair( vInd, facesWOL[0] ));
          break;
        }
      case 2:
        {
          // find an edge shared by 2 faces
          PShapeIteratorPtr eIt = helper.GetAncestors(vertex, *_mesh, TopAbs_EDGE);
          while ( eIt->more())
          {
            const TopoDS_Shape* e = eIt->next();
            if ( helper.IsSubShape( *e, facesWOL[0]) &&
                 helper.IsSubShape( *e, facesWOL[1]))
            {
              _sdVec[i]._shrinkShape2Shape.insert( make_pair( vInd, *e )); break;
            }
          }
          break;
        }
      default:
        return error("Not yet supported case", _sdVec[i]._index);
      }
    }
  }

  return true;
}
bool _ViscousBuilder::findNeiborsOnEdge ( const _LayerEdge edge,
const SMDS_MeshNode *&  n1,
const SMDS_MeshNode *&  n2,
_SolidData data 
) [private]

Find 2 neigbor nodes of a node on EDGE.

Definition at line 1785 of file StdMeshers_ViscousLayers.cxx.

{
  const SMDS_MeshNode* node = edge->_nodes[0];
  const int shapeInd = node->getshapeId();
  SMESHDS_SubMesh* edgeSM = 0;
  if ( node->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE )
  {
    
    edgeSM = getMeshDS()->MeshElements( shapeInd );
    if ( !edgeSM || edgeSM->NbElements() == 0 )
      return error(SMESH_Comment("Not meshed EDGE ") << shapeInd, data._index);
  }
  int iN = 0;
  n2 = 0;
  SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator(SMDSAbs_Edge);
  while ( eIt->more() && !n2 )
  {
    const SMDS_MeshElement* e = eIt->next();
    const SMDS_MeshNode*   nNeibor = e->GetNode( 0 );
    if ( nNeibor == node ) nNeibor = e->GetNode( 1 );
    if ( edgeSM )
    {
      if (!edgeSM->Contains(e)) continue;
    }
    else
    {
      TopoDS_Shape s = SMESH_MesherHelper::GetSubShapeByNode(nNeibor, getMeshDS() );
      if ( !SMESH_MesherHelper::IsSubShape( s, edge->_sWOL )) continue;
    }
    ( iN++ ? n2 : n1 ) = nNeibor;
  }
  if ( !n2 )
    return error(SMESH_Comment("Wrongly meshed EDGE ") << shapeInd, data._index);
  return true;
}

Here is the call graph for this function:

Finds SOLIDs to compute using viscous layers.

Fills _sdVec

Definition at line 1002 of file StdMeshers_ViscousLayers.cxx.

{
  // get all solids
  TopTools_IndexedMapOfShape allSolids;
  TopExp::MapShapes( _mesh->GetShapeToMesh(), TopAbs_SOLID, allSolids );
  _sdVec.reserve( allSolids.Extent());

  SMESH_Gen* gen = _mesh->GetGen();
  for ( int i = 1; i <= allSolids.Extent(); ++i )
  {
    // find StdMeshers_ViscousLayers hyp assigned to the i-th solid
    SMESH_Algo* algo = gen->GetAlgo( *_mesh, allSolids(i) );
    if ( !algo ) continue;
    // TODO: check if algo is hidden
    const list <const SMESHDS_Hypothesis *> & allHyps =
      algo->GetUsedHypothesis(*_mesh, allSolids(i), /*ignoreAuxiliary=*/false);
    list< const SMESHDS_Hypothesis *>::const_iterator hyp = allHyps.begin();
    const StdMeshers_ViscousLayers* viscHyp = 0;
    for ( ; hyp != allHyps.end() && !viscHyp; ++hyp )
      viscHyp = dynamic_cast<const StdMeshers_ViscousLayers*>( *hyp );
    if ( viscHyp )
    {
      _MeshOfSolid* proxyMesh = _ViscousListener::GetSolidMesh( _mesh,
                                                                allSolids(i),
                                                                /*toCreate=*/true);
      _sdVec.push_back( _SolidData( allSolids(i), viscHyp, proxyMesh ));
      _sdVec.back()._index = getMeshDS()->ShapeToIndex( allSolids(i));
    }
  }
  if ( _sdVec.empty() )
    return error
      ( SMESH_Comment(StdMeshers_ViscousLayers::GetHypType()) << " hypothesis not found",0);

  return true;
}

Here is the call graph for this function:

void _ViscousBuilder::fixBadFaces ( const TopoDS_Face &  F,
SMESH_MesherHelper &  helper 
) [private]

Try to fix triangles with high aspect ratio by swaping diagonals.

Definition at line 3869 of file StdMeshers_ViscousLayers.cxx.

{
  SMESH::Controls::AspectRatio qualifier;
  SMESH::Controls::TSequenceOfXYZ points(3), points1(3), points2(3);
  const double maxAspectRatio = 4.;

  // find bad triangles

  vector< const SMDS_MeshElement* > badTrias;
  vector< double >                  badAspects;
  SMESHDS_SubMesh* sm = helper.GetMeshDS()->MeshElements( F );
  SMDS_ElemIteratorPtr fIt = sm->GetElements();
  while ( fIt->more() )
  {
    const SMDS_MeshElement * f = fIt->next();
    if ( f->NbCornerNodes() != 3 ) continue;
    for ( int iP = 0; iP < 3; ++iP ) points(iP+1) = SMESH_TNodeXYZ( f->GetNode(iP));
    double aspect = qualifier.GetValue( points );
    if ( aspect > maxAspectRatio )
    {
      badTrias.push_back( f );
      badAspects.push_back( aspect );
    }
  }
  if ( badTrias.empty() )
    return;

  // find couples of faces to swap diagonal

  typedef pair < const SMDS_MeshElement* , const SMDS_MeshElement* > T2Trias;
  vector< T2Trias > triaCouples; 

  TIDSortedElemSet involvedFaces, emptySet;
  for ( size_t iTia = 0; iTia < badTrias.size(); ++iTia )
  {
    T2Trias trias    [3];
    double  aspRatio [3];
    int i1, i2, i3;

    involvedFaces.insert( badTrias[iTia] );
    for ( int iP = 0; iP < 3; ++iP )
      points(iP+1) = SMESH_TNodeXYZ( badTrias[iTia]->GetNode(iP));

    // find triangles adjacent to badTrias[iTia] with better aspect ratio after diag-swaping
    int bestCouple = -1;
    for ( int iSide = 0; iSide < 3; ++iSide )
    {
      const SMDS_MeshNode* n1 = badTrias[iTia]->GetNode( iSide );
      const SMDS_MeshNode* n2 = badTrias[iTia]->GetNode(( iSide+1 ) % 3 );
      trias [iSide].first  = badTrias[iTia];
      trias [iSide].second = SMESH_MeshEditor::FindFaceInSet( n1, n2, emptySet, involvedFaces,
                                                              & i1, & i2 );
      if ( ! trias[iSide].second || trias[iSide].second->NbCornerNodes() != 3 )
        continue;

      // aspect ratio of an adjacent tria
      for ( int iP = 0; iP < 3; ++iP )
        points2(iP+1) = SMESH_TNodeXYZ( trias[iSide].second->GetNode(iP));
      double aspectInit = qualifier.GetValue( points2 );

      // arrange nodes as after diag-swaping
      if ( helper.WrapIndex( i1+1, 3 ) == i2 )
        i3 = helper.WrapIndex( i1-1, 3 );
      else
        i3 = helper.WrapIndex( i1+1, 3 );
      points1 = points;
      points1( 1+ iSide ) = points2( 1+ i3 );
      points2( 1+ i2    ) = points1( 1+ ( iSide+2 ) % 3 );

      // aspect ratio after diag-swaping
      aspRatio[ iSide ] = qualifier.GetValue( points1 ) + qualifier.GetValue( points2 );
      if ( aspRatio[ iSide ] > aspectInit + badAspects[ iTia ] )
        continue;

      if ( bestCouple < 0 || aspRatio[ bestCouple ] > aspRatio[ iSide ] )
        bestCouple = iSide;
    }

    if ( bestCouple >= 0 )
    {
      triaCouples.push_back( trias[bestCouple] );
      involvedFaces.insert ( trias[bestCouple].second );
    }
    else
    {
      involvedFaces.erase( badTrias[iTia] );
    }
  }
  if ( triaCouples.empty() )
    return;

  // swap diagonals

  SMESH_MeshEditor editor( helper.GetMesh() );
  dumpFunction(SMESH_Comment("beforeSwapDiagonals_F")<<helper.GetSubShapeID());
  for ( size_t i = 0; i < triaCouples.size(); ++i )
  {
    dumpChangeNodes( triaCouples[i].first );
    dumpChangeNodes( triaCouples[i].second );
    editor.InverseDiag( triaCouples[i].first, triaCouples[i].second );
  }
  dumpFunctionEnd();

  // just for debug dump resulting triangles
  dumpFunction(SMESH_Comment("swapDiagonals_F")<<helper.GetSubShapeID());
  for ( size_t i = 0; i < triaCouples.size(); ++i )
  {
    dumpChangeNodes( triaCouples[i].first );
    dumpChangeNodes( triaCouples[i].second );
  }
}
SMESHDS_Mesh* VISCOUS::_ViscousBuilder::getMeshDS ( ) [inline, private]

Definition at line 486 of file StdMeshers_ViscousLayers.cxx.

{ return _mesh->GetMeshDS(); }
void _ViscousBuilder::getSimplices ( const SMDS_MeshNode *  node,
vector< _Simplex > &  simplices,
const set< TGeomID > &  ingnoreShapes,
const _SolidData dataToCheckOri = 0,
const bool  toSort = false 
) [private]

Fills a vector<_Simplex >

Definition at line 1924 of file StdMeshers_ViscousLayers.cxx.

{
  SMDS_ElemIteratorPtr fIt = node->GetInverseElementIterator(SMDSAbs_Face);
  while ( fIt->more() )
  {
    const SMDS_MeshElement* f = fIt->next();
    const TGeomID shapeInd = f->getshapeId();
    if ( ingnoreShapes.count( shapeInd )) continue;
    const int nbNodes = f->NbCornerNodes();
    int srcInd = f->GetNodeIndex( node );
    const SMDS_MeshNode* nPrev = f->GetNode( SMESH_MesherHelper::WrapIndex( srcInd-1, nbNodes ));
    const SMDS_MeshNode* nNext = f->GetNode( SMESH_MesherHelper::WrapIndex( srcInd+1, nbNodes ));
    if ( dataToCheckOri && dataToCheckOri->_reversedFaceIds.count( shapeInd ))
      std::swap( nPrev, nNext );
    simplices.push_back( _Simplex( nPrev, nNext ));
  }

  if ( toSort )
  {
    vector<_Simplex> sortedSimplices( simplices.size() );
    sortedSimplices[0] = simplices[0];
    int nbFound = 0;
    for ( size_t i = 1; i < simplices.size(); ++i )
    {
      for ( size_t j = 1; j < simplices.size(); ++j )
        if ( sortedSimplices[i-1]._nNext == simplices[j]._nPrev )
        {
          sortedSimplices[i] = simplices[j];
          nbFound++;
          break;
        }
    }
    if ( nbFound == simplices.size() - 1 )
      simplices.swap( sortedSimplices );
  }
}
bool _ViscousBuilder::inflate ( _SolidData data) [private]

Increase length of _LayerEdge's to reach the required thickness of layers.

Definition at line 2039 of file StdMeshers_ViscousLayers.cxx.

{
  SMESH_MesherHelper helper( *_mesh );

  // Limit inflation step size by geometry size found by itersecting
  // normals of _LayerEdge's with mesh faces
  double geomSize = Precision::Infinite(), intersecDist;
  SMESH_MeshEditor editor( _mesh );
  auto_ptr<SMESH_ElementSearcher> searcher
    ( editor.GetElementSearcher( data._proxyMesh->GetFaces( data._solid )) );
  for ( unsigned i = 0; i < data._edges.size(); ++i )
  {
    if ( data._edges[i]->IsOnEdge() ) continue;
    data._edges[i]->FindIntersection( *searcher, intersecDist, data._epsilon );
    if ( geomSize > intersecDist )
      geomSize = intersecDist;
  }
  if ( data._stepSize > 0.3 * geomSize )
    limitStepSize( data, 0.3 * geomSize );

  const double tgtThick = data._hyp->GetTotalThickness();
  if ( data._stepSize > tgtThick )
    limitStepSize( data, tgtThick );

  if ( data._stepSize < 1. )
    data._epsilon = data._stepSize * 1e-7;

#ifdef __myDEBUG
  cout << "-- geomSize = " << geomSize << ", stepSize = " << data._stepSize << endl;
#endif

  double avgThick = 0, curThick = 0, distToIntersection = Precision::Infinite();
  int nbSteps = 0, nbRepeats = 0;
  while ( 1.01 * avgThick < tgtThick )
  {
    // new target length
    curThick += data._stepSize;
    if ( curThick > tgtThick )
    {
      curThick = tgtThick + ( tgtThick-avgThick ) * nbRepeats;
      nbRepeats++;
    }

    // Elongate _LayerEdge's
    dumpFunction(SMESH_Comment("inflate")<<data._index<<"_step"<<nbSteps); // debug
    for ( unsigned i = 0; i < data._edges.size(); ++i )
    {
      data._edges[i]->SetNewLength( curThick, helper );
    }
    dumpFunctionEnd();

    if ( !nbSteps )
      if ( !updateNormals( data, helper ) )
        return false;

    // Improve and check quality
    if ( !smoothAndCheck( data, nbSteps, distToIntersection ))
    {
      if ( nbSteps > 0 )
      {
        dumpFunction(SMESH_Comment("invalidate")<<data._index<<"_step"<<nbSteps); // debug
        for ( unsigned i = 0; i < data._edges.size(); ++i )
        {
          data._edges[i]->InvalidateStep( nbSteps+1 );
        }
        dumpFunctionEnd();
      }
      break; // no more inflating possible
    }
    nbSteps++;

    // Evaluate achieved thickness
    avgThick = 0;
    for ( unsigned i = 0; i < data._edges.size(); ++i )
      avgThick += data._edges[i]->_len;
    avgThick /= data._edges.size();
#ifdef __myDEBUG
    cout << "-- Thickness " << avgThick << " reached" << endl;
#endif

    if ( distToIntersection < avgThick*1.5 )
    {
#ifdef __myDEBUG
      cout << "-- Stop inflation since distToIntersection( "<<distToIntersection<<" ) < avgThick( "
           << avgThick << " ) * 1.5" << endl;
#endif
      break;
    }
    // new step size
    limitStepSize( data, 0.25 * distToIntersection );
    if ( data._stepSizeNodes[0] )
      data._stepSize = data._stepSizeCoeff *
        SMESH_TNodeXYZ(data._stepSizeNodes[0]).Distance(data._stepSizeNodes[1]);
  }

  if (nbSteps == 0 )
    return error("failed at the very first inflation step", data._index);

  return true;
}

Here is the call graph for this function:

void _ViscousBuilder::limitStepSize ( _SolidData data,
const SMDS_MeshElement *  face,
const double  cosin 
) [private]

Compute inflation step size by min size of element on a convex surface.

Definition at line 1409 of file StdMeshers_ViscousLayers.cxx.

{
  int iN = 0;
  double minSize = 10 * data._stepSize;
  const int nbNodes = face->NbCornerNodes();
  for ( int i = 0; i < nbNodes; ++i )
  {
    const SMDS_MeshNode* nextN = face->GetNode( SMESH_MesherHelper::WrapIndex( i+1, nbNodes ));
    const SMDS_MeshNode* curN = face->GetNode( i );
    if ( nextN->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ||
         curN->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE )
    {
      double dist = SMESH_TNodeXYZ( face->GetNode(i)).Distance( nextN );
      if ( dist < minSize )
        minSize = dist, iN = i;
    }
  }
  double newStep = 0.8 * minSize / cosin;
  if ( newStep < data._stepSize )
  {
    data._stepSize = newStep;
    data._stepSizeCoeff = 0.8 / cosin;
    data._stepSizeNodes[0] = face->GetNode( iN );
    data._stepSizeNodes[1] = face->GetNode( SMESH_MesherHelper::WrapIndex( iN+1, nbNodes ));
  }
}
void _ViscousBuilder::limitStepSize ( _SolidData data,
const double  minSize 
) [private]

Compute inflation step size by min size of element on a convex surface.

Definition at line 1444 of file StdMeshers_ViscousLayers.cxx.

{
  if ( minSize < data._stepSize )
  {
    data._stepSize = minSize;
    if ( data._stepSizeNodes[0] )
    {
      double dist =
        SMESH_TNodeXYZ(data._stepSizeNodes[0]).Distance(data._stepSizeNodes[1]);
      data._stepSizeCoeff = data._stepSize / dist;
    }
  }
}

Here is the call graph for this function:

void _ViscousBuilder::makeGroupOfLE ( ) [private]

DEBUG.

Create groups contating temorary data of _LayerEdge's

Definition at line 1971 of file StdMeshers_ViscousLayers.cxx.

{
#ifdef _DEBUG_
  for ( unsigned i = 0 ; i < _sdVec.size(); ++i )
  {
    if ( _sdVec[i]._edges.empty() ) continue;
//     string name = SMESH_Comment("_LayerEdge's_") << i;
//     int id;
//     SMESH_Group* g = _mesh->AddGroup(SMDSAbs_Edge, name.c_str(), id );
//     SMESHDS_Group* gDS = (SMESHDS_Group*)g->GetGroupDS();
//     SMESHDS_Mesh* mDS = _mesh->GetMeshDS();

    dumpFunction( SMESH_Comment("make_LayerEdge_") << i );
    for ( unsigned j = 0 ; j < _sdVec[i]._edges.size(); ++j )
    {
      _LayerEdge* le = _sdVec[i]._edges[j];
      for ( unsigned iN = 1; iN < le->_nodes.size(); ++iN )
        dumpCmd(SMESH_Comment("mesh.AddEdge([ ") <<le->_nodes[iN-1]->GetID()
                << ", " << le->_nodes[iN]->GetID() <<"])");
      //gDS->SMDSGroup().Add( mDS->AddEdge( le->_nodes[iN-1], le->_nodes[iN]));
    }
    dumpFunctionEnd();

    dumpFunction( SMESH_Comment("makeNormals") << i );
    for ( unsigned j = 0 ; j < _sdVec[i]._edges.size(); ++j )
    {
      _LayerEdge& edge = *_sdVec[i]._edges[j];
      SMESH_TNodeXYZ nXYZ( edge._nodes[0] );
      nXYZ += edge._normal * _sdVec[i]._stepSize;
      dumpCmd(SMESH_Comment("mesh.AddEdge([ ") <<edge._nodes[0]->GetID()
              << ", mesh.AddNode( " << nXYZ.X()<<","<< nXYZ.Y()<<","<< nXYZ.Z()<<")])");
    }
    dumpFunctionEnd();

//     name = SMESH_Comment("tmp_faces ") << i;
//     g = _mesh->AddGroup(SMDSAbs_Face, name.c_str(), id );
//     gDS = (SMESHDS_Group*)g->GetGroupDS();
//     SMESH_MeshEditor editor( _mesh );
    dumpFunction( SMESH_Comment("makeTmpFaces_") << i );
    TopExp_Explorer fExp( _sdVec[i]._solid, TopAbs_FACE );
    for ( ; fExp.More(); fExp.Next() )
    {
      if (const SMESHDS_SubMesh* sm = _sdVec[i]._proxyMesh->GetProxySubMesh( fExp.Current()))
      {
        SMDS_ElemIteratorPtr fIt = sm->GetElements();
        while ( fIt->more())
        {
          const SMDS_MeshElement* e = fIt->next();
          SMESH_Comment cmd("mesh.AddFace([");
          for ( int j=0; j < e->NbCornerNodes(); ++j )
            cmd << e->GetNode(j)->GetID() << (j+1<e->NbCornerNodes() ? ",": "])");
          dumpCmd( cmd );
          //vector<const SMDS_MeshNode*> nodes( e->begin_nodes(), e->end_nodes() );
          //gDS->SMDSGroup().Add( editor.AddElement( nodes, e->GetType(), e->IsPoly()));
        }
      }
    }
    dumpFunctionEnd();
  }
#endif
}
bool _ViscousBuilder::makeLayer ( _SolidData data) [private]

Create the inner surface of the viscous layer and prepare data for infation.

Definition at line 1246 of file StdMeshers_ViscousLayers.cxx.

{
  // get all sub-shapes to make layers on
  set<TGeomID> subIds, faceIds;
  subIds = data._noShrinkFaces;
  TopExp_Explorer exp( data._solid, TopAbs_FACE );
  for ( ; exp.More(); exp.Next() )
    if ( ! _ignoreShapeIds.count( getMeshDS()->ShapeToIndex( exp.Current() )))
    {
      SMESH_subMesh* fSubM = _mesh->GetSubMesh( exp.Current() );
      faceIds.insert( fSubM->GetId() );
      SMESH_subMeshIteratorPtr subIt =
        fSubM->getDependsOnIterator(/*includeSelf=*/true, /*complexShapeFirst=*/false);
      while ( subIt->more() )
        subIds.insert( subIt->next()->GetId() );
    }

  // make a map to find new nodes on sub-shapes shared with other SOLID
  map< TGeomID, TNode2Edge* > s2neMap;
  map< TGeomID, TNode2Edge* >::iterator s2ne;
  map< TGeomID, TopoDS_Shape >::iterator s2s = data._shrinkShape2Shape.begin();
  for (; s2s != data._shrinkShape2Shape.end(); ++s2s )
  {
    TGeomID shapeInd = s2s->first;
    for ( unsigned i = 0; i < _sdVec.size(); ++i )
    {
      if ( _sdVec[i]._index == data._index ) continue;
      map< TGeomID, TopoDS_Shape >::iterator s2s2 = _sdVec[i]._shrinkShape2Shape.find( shapeInd );
      if ( s2s2 != _sdVec[i]._shrinkShape2Shape.end() &&
           *s2s == *s2s2 && !_sdVec[i]._n2eMap.empty() )
      {
        s2neMap.insert( make_pair( shapeInd, &_sdVec[i]._n2eMap ));
        break;
      }
    }
  }

  // Create temporary faces and _LayerEdge's

  dumpFunction(SMESH_Comment("makeLayers_")<<data._index); 

  data._stepSize = Precision::Infinite();
  data._stepSizeNodes[0] = 0;

  SMESH_MesherHelper helper( *_mesh );
  helper.SetSubShape( data._solid );
  helper.SetElementsOnShape(true);

  vector< const SMDS_MeshNode*> newNodes; // of a mesh face
  TNode2Edge::iterator n2e2;

  // collect _LayerEdge's of shapes they are based on
  const int nbShapes = getMeshDS()->MaxShapeIndex();
  vector< vector<_LayerEdge*> > edgesByGeom( nbShapes+1 );

  for ( set<TGeomID>::iterator id = faceIds.begin(); id != faceIds.end(); ++id )
  {
    SMESHDS_SubMesh* smDS = getMeshDS()->MeshElements( *id );
    if ( !smDS ) return error(SMESH_Comment("Not meshed face ") << *id, data._index );

    const TopoDS_Face& F = TopoDS::Face( getMeshDS()->IndexToShape( *id ));
    SMESH_ProxyMesh::SubMesh* proxySub =
      data._proxyMesh->getFaceSubM( F, /*create=*/true);

    SMDS_ElemIteratorPtr eIt = smDS->GetElements();
    while ( eIt->more() )
    {
      const SMDS_MeshElement* face = eIt->next();
      newNodes.resize( face->NbCornerNodes() );
      double faceMaxCosin = -1;
      for ( int i = 0 ; i < face->NbCornerNodes(); ++i )
      {
        const SMDS_MeshNode* n = face->GetNode(i);
        TNode2Edge::iterator n2e = data._n2eMap.insert( make_pair( n, (_LayerEdge*)0 )).first;
        if ( !(*n2e).second )
        {
          // add a _LayerEdge
          _LayerEdge* edge = new _LayerEdge();
          n2e->second = edge;
          edge->_nodes.push_back( n );
          const int shapeID = n->getshapeId();
          edgesByGeom[ shapeID ].push_back( edge );

          // set edge data or find already refined _LayerEdge and get data from it
          if ( n->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE &&
               ( s2ne = s2neMap.find( shapeID )) != s2neMap.end() &&
               ( n2e2 = (*s2ne).second->find( n )) != s2ne->second->end())
          {
            _LayerEdge* foundEdge = (*n2e2).second;
            edge->Copy( *foundEdge, helper );
            // location of the last node is modified but we can restore
            // it by node position on _sWOL stored by the node
            const_cast< SMDS_MeshNode* >
              ( edge->_nodes.back() )->setXYZ( n->X(), n->Y(), n->Z() );
          }
          else
          {
            edge->_nodes.push_back( helper.AddNode( n->X(), n->Y(), n->Z() ));
            if ( !setEdgeData( *edge, subIds, helper, data ))
              return false;
          }
          dumpMove(edge->_nodes.back());
          if ( edge->_cosin > 0.01 )
          {
            if ( edge->_cosin > faceMaxCosin )
              faceMaxCosin = edge->_cosin;
          }
        }
        newNodes[ i ] = n2e->second->_nodes.back();
      }
      // create a temporary face
      const SMDS_MeshElement* newFace = new TmpMeshFace( newNodes, --_tmpFaceID );
      proxySub->AddElement( newFace );

      // compute inflation step size by min size of element on a convex surface
      if ( faceMaxCosin > 0.1 )
        limitStepSize( data, face, faceMaxCosin );
    } // loop on 2D elements on a FACE
  } // loop on FACEs of a SOLID

  data._epsilon = 1e-7;
  if ( data._stepSize < 1. )
    data._epsilon *= data._stepSize;

  // Put _LayerEdge's into a vector

  if ( !sortEdges( data, edgesByGeom ))
    return false;

  // Set target nodes into _Simplex and _2NearEdges
  TNode2Edge::iterator n2e;
  for ( unsigned i = 0; i < data._edges.size(); ++i )
  {
    if ( data._edges[i]->IsOnEdge())
      for ( int j = 0; j < 2; ++j )
      {
        if ( data._edges[i]->_nodes.back()->NbInverseElements(SMDSAbs_Volume) > 0 )
          break; // _LayerEdge is shared by two _SolidData's
        const SMDS_MeshNode* & n = data._edges[i]->_2neibors->_nodes[j];
        if (( n2e = data._n2eMap.find( n )) == data._n2eMap.end() )
          return error("_LayerEdge not found by src node", data._index);
        n = (*n2e).second->_nodes.back();
        data._edges[i]->_2neibors->_edges[j] = n2e->second;
      }
    else
      for ( unsigned j = 0; j < data._edges[i]->_simplices.size(); ++j )
      {
        _Simplex& s = data._edges[i]->_simplices[j];
        s._nNext = data._n2eMap[ s._nNext ]->_nodes.back();
        s._nPrev = data._n2eMap[ s._nPrev ]->_nodes.back();
      }
  }

  dumpFunctionEnd();
  return true;
}

Here is the call graph for this function:

computes SMESH_ProxyMesh::SubMesh::_n2n

Definition at line 911 of file StdMeshers_ViscousLayers.cxx.

{
  SMESH_subMesh* solidSM = pm->mySubMeshes.front();
  TopExp_Explorer fExp( solidSM->GetSubShape(), TopAbs_FACE );
  for ( ; fExp.More(); fExp.Next() )
  {
    SMESHDS_SubMesh* srcSmDS = pm->GetMeshDS()->MeshElements( fExp.Current() );
    const SMESH_ProxyMesh::SubMesh* prxSmDS = pm->GetProxySubMesh( fExp.Current() );

    if ( !srcSmDS || !prxSmDS || !srcSmDS->NbElements() || !prxSmDS->NbElements() )
      continue;
    if ( srcSmDS->GetElements()->next() == prxSmDS->GetElements()->next())
      continue;

    if ( srcSmDS->NbElements() != prxSmDS->NbElements() )
      return error( "Different nb elements in a source and a proxy sub-mesh", solidSM->GetId());

    SMDS_ElemIteratorPtr srcIt = srcSmDS->GetElements();
    SMDS_ElemIteratorPtr prxIt = prxSmDS->GetElements();
    while( prxIt->more() )
    {
      const SMDS_MeshElement* fSrc = srcIt->next();
      const SMDS_MeshElement* fPrx = prxIt->next();
      if ( fSrc->NbNodes() != fPrx->NbNodes())
        return error( "Different elements in a source and a proxy sub-mesh", solidSM->GetId());
      for ( int i = 0 ; i < fPrx->NbNodes(); ++i )
        pm->setNode2Node( fSrc->GetNode(i), fPrx->GetNode(i), prxSmDS );
    }
  }
  pm->_n2nMapComputed = true;
  return true;
}

Here is the call graph for this function:

bool _ViscousBuilder::prepareEdgeToShrink ( _LayerEdge edge,
const TopoDS_Face &  F,
SMESH_MesherHelper &  helper,
const SMESHDS_SubMesh *  faceSubMesh 
) [private]

Computes 2d shrink direction and finds nodes limiting shrinking.

Compute positions (UV) to set to a node on edge moved during shrinking

Definition at line 3695 of file StdMeshers_ViscousLayers.cxx.

{
  const SMDS_MeshNode* srcNode = edge._nodes[0];
  const SMDS_MeshNode* tgtNode = edge._nodes.back();

  edge._pos.clear();

  if ( edge._sWOL.ShapeType() == TopAbs_FACE )
  {
    gp_XY srcUV = helper.GetNodeUV( F, srcNode );
    gp_XY tgtUV = helper.GetNodeUV( F, tgtNode );
    gp_Vec2d uvDir( srcUV, tgtUV );
    double uvLen = uvDir.Magnitude();
    uvDir /= uvLen;
    edge._normal.SetCoord( uvDir.X(),uvDir.Y(), 0);

    // IMPORTANT to have src nodes NOT yet REPLACED by tgt nodes in shrinked faces
    vector<const SMDS_MeshElement*> faces;
    multimap< double, const SMDS_MeshNode* > proj2node;
    SMDS_ElemIteratorPtr fIt = srcNode->GetInverseElementIterator(SMDSAbs_Face);
    while ( fIt->more() )
    {
      const SMDS_MeshElement* f = fIt->next();
      if ( faceSubMesh->Contains( f ))
        faces.push_back( f );
    }
    for ( unsigned i = 0; i < faces.size(); ++i )
    {
      const int nbNodes = faces[i]->NbCornerNodes();
      for ( int j = 0; j < nbNodes; ++j )
      {
        const SMDS_MeshNode* n = faces[i]->GetNode(j);
        if ( n == srcNode ) continue;
        if ( n->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE &&
             ( faces.size() > 1 || nbNodes > 3 ))
          continue;
        gp_Pnt2d uv = helper.GetNodeUV( F, n );
        gp_Vec2d uvDirN( srcUV, uv );
        double proj = uvDirN * uvDir;
        proj2node.insert( make_pair( proj, n ));
      }
    }

    multimap< double, const SMDS_MeshNode* >::iterator p2n = proj2node.begin(), p2nEnd;
    const double minProj = p2n->first;
    const double projThreshold = 1.1 * uvLen;
    if ( minProj > projThreshold )
    {
      // tgtNode is located so that it does not make faces with wrong orientation
      return true;
    }
    edge._pos.resize(1);
    edge._pos[0].SetCoord( tgtUV.X(), tgtUV.Y(), 0 );

    // store most risky nodes in _simplices
    p2nEnd = proj2node.lower_bound( projThreshold );
    int nbSimpl = ( std::distance( p2n, p2nEnd ) + 1) / 2;
    edge._simplices.resize( nbSimpl );
    for ( int i = 0; i < nbSimpl; ++i )
    {
      edge._simplices[i]._nPrev = p2n->second;
      if ( ++p2n != p2nEnd )
        edge._simplices[i]._nNext = p2n->second;
    }
    // set UV of source node to target node
    SMDS_FacePosition* pos = static_cast<SMDS_FacePosition*>( tgtNode->GetPosition() );
    pos->SetUParameter( srcUV.X() );
    pos->SetVParameter( srcUV.Y() );
  }
  else // _sWOL is TopAbs_EDGE
  {
    TopoDS_Edge E = TopoDS::Edge( edge._sWOL);
    SMESHDS_SubMesh* edgeSM = getMeshDS()->MeshElements( E );
    if ( !edgeSM || edgeSM->NbElements() == 0 )
      return error(SMESH_Comment("Not meshed EDGE ") << getMeshDS()->ShapeToIndex( E ));

    const SMDS_MeshNode* n2 = 0;
    SMDS_ElemIteratorPtr eIt = srcNode->GetInverseElementIterator(SMDSAbs_Edge);
    while ( eIt->more() && !n2 )
    {
      const SMDS_MeshElement* e = eIt->next();
      if ( !edgeSM->Contains(e)) continue;
      n2 = e->GetNode( 0 );
      if ( n2 == srcNode ) n2 = e->GetNode( 1 );
    }
    if ( !n2 )
      return error(SMESH_Comment("Wrongly meshed EDGE ") << getMeshDS()->ShapeToIndex( E ));

    double uSrc = helper.GetNodeU( E, srcNode, n2 );
    double uTgt = helper.GetNodeU( E, tgtNode, srcNode );
    double u2   = helper.GetNodeU( E, n2,      srcNode );

    if ( fabs( uSrc-uTgt ) < 0.99 * fabs( uSrc-u2 ))
    {
      // tgtNode is located so that it does not make faces with wrong orientation
      return true;
    }
    edge._pos.resize(1);
    edge._pos[0].SetCoord( U_TGT, uTgt );
    edge._pos[0].SetCoord( U_SRC, uSrc );
    edge._pos[0].SetCoord( LEN_TGT, fabs( uSrc-uTgt ));

    edge._simplices.resize( 1 );
    edge._simplices[0]._nPrev = n2;

    // set UV of source node to target node
    SMDS_EdgePosition* pos = static_cast<SMDS_EdgePosition*>( tgtNode->GetPosition() );
    pos->SetUParameter( uSrc );
  }
  return true;

  //================================================================================
  //================================================================================
  
  // Compute UV to follow during shrinking

//   const SMDS_MeshNode* srcNode = edge._nodes[0];
//   const SMDS_MeshNode* tgtNode = edge._nodes.back();

//   gp_XY srcUV = helper.GetNodeUV( F, srcNode );
//   gp_XY tgtUV = helper.GetNodeUV( F, tgtNode );
//   gp_Vec2d uvDir( srcUV, tgtUV );
//   double uvLen = uvDir.Magnitude();
//   uvDir /= uvLen;

//   // Select shrinking step such that not to make faces with wrong orientation.
//   // IMPORTANT to have src nodes NOT yet REPLACED by tgt nodes in shrinked faces
//   const double minStepSize = uvLen / 20;
//   double stepSize = uvLen;
//   SMDS_ElemIteratorPtr fIt = srcNode->GetInverseElementIterator(SMDSAbs_Face);
//   while ( fIt->more() )
//   {
//     const SMDS_MeshElement* f = fIt->next();
//     if ( !faceSubMesh->Contains( f )) continue;
//     const int nbNodes = f->NbCornerNodes();
//     for ( int i = 0; i < nbNodes; ++i )
//     {
//       const SMDS_MeshNode* n = f->GetNode(i);
//       if ( n->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE || n == srcNode)
//         continue;
//       gp_XY uv = helper.GetNodeUV( F, n );
//       gp_Vec2d uvDirN( srcUV, uv );
//       double proj = uvDirN * uvDir;
//       if ( proj < stepSize && proj > minStepSize )
//         stepSize = proj;
//     }
//   }
//   stepSize *= 0.8;

//   const int nbSteps = ceil( uvLen / stepSize );
//   gp_XYZ srcUV0( srcUV.X(), srcUV.Y(), 0 );
//   gp_XYZ tgtUV0( tgtUV.X(), tgtUV.Y(), 0 );
//   edge._pos.resize( nbSteps );
//   edge._pos[0] = tgtUV0;
//   for ( int i = 1; i < nbSteps; ++i )
//   {
//     double r = i / double( nbSteps );
//     edge._pos[i] = (1-r) * tgtUV0 + r * srcUV0;
//   }
//   return true;
}
bool _ViscousBuilder::refine ( _SolidData data) [private]

Create layers of prisms.

Definition at line 3241 of file StdMeshers_ViscousLayers.cxx.

{
  SMESH_MesherHelper helper( *_mesh );
  helper.SetSubShape( data._solid );
  helper.SetElementsOnShape(false);

  Handle(Geom_Curve) curve;
  Handle(Geom_Surface) surface;
  TopoDS_Edge geomEdge;
  TopoDS_Face geomFace;
  TopLoc_Location loc;
  double f,l, u/*, distXYZ[4]*/;
  gp_XY uv;
  bool isOnEdge;

  for ( unsigned i = 0; i < data._edges.size(); ++i )
  {
    _LayerEdge& edge = *data._edges[i];

    // get accumulated length of segments
    vector< double > segLen( edge._pos.size() );
    segLen[0] = 0.0;
    for ( unsigned j = 1; j < edge._pos.size(); ++j )
      segLen[j] = segLen[j-1] + (edge._pos[j-1] - edge._pos[j] ).Modulus();

    // allocate memory for new nodes if it is not yet refined
    const SMDS_MeshNode* tgtNode = edge._nodes.back();
    if ( edge._nodes.size() == 2 )
    {
      edge._nodes.resize( data._hyp->GetNumberLayers() + 1, 0 );
      edge._nodes[1] = 0;
      edge._nodes.back() = tgtNode;
    }
    if ( !edge._sWOL.IsNull() )
    {
      isOnEdge = ( edge._sWOL.ShapeType() == TopAbs_EDGE );
      // restore position of the last node
//       gp_Pnt p;
      if ( isOnEdge )
      {
        geomEdge = TopoDS::Edge( edge._sWOL );
        curve = BRep_Tool::Curve( geomEdge, loc, f,l);
//         double u = helper.GetNodeU( tgtNode );
//         p = curve->Value( u );
      }
      else
      {
        geomFace = TopoDS::Face( edge._sWOL );
        surface = BRep_Tool::Surface( geomFace, loc );
//         gp_XY uv = helper.GetNodeUV( tgtNode );
//         p = surface->Value( uv.X(), uv.Y() );
      }
//       p.Transform( loc );
//       const_cast< SMDS_MeshNode* >( tgtNode )->setXYZ( p.X(), p.Y(), p.Z() );
    }
    // calculate height of the first layer
    double h0;
    const double T = segLen.back(); //data._hyp.GetTotalThickness();
    const double f = data._hyp->GetStretchFactor();
    const int    N = data._hyp->GetNumberLayers();
    const double fPowN = pow( f, N );
    if ( fPowN - 1 <= numeric_limits<double>::min() )
      h0 = T / N;
    else
      h0 = T * ( f - 1 )/( fPowN - 1 );

    const double zeroLen = std::numeric_limits<double>::min();

    // create intermediate nodes
    double hSum = 0, hi = h0/f;
    unsigned iSeg = 1;
    for ( unsigned iStep = 1; iStep < edge._nodes.size(); ++iStep )
    {
      // compute an intermediate position
      hi *= f;
      hSum += hi;
      while ( hSum > segLen[iSeg] && iSeg < segLen.size()-1)
        ++iSeg;
      int iPrevSeg = iSeg-1;
      while ( fabs( segLen[iPrevSeg] - segLen[iSeg]) <= zeroLen && iPrevSeg > 0 )
        --iPrevSeg;
      double r = ( segLen[iSeg] - hSum ) / ( segLen[iSeg] - segLen[iPrevSeg] );
      gp_Pnt pos = r * edge._pos[iPrevSeg] + (1-r) * edge._pos[iSeg];

      SMDS_MeshNode*& node = const_cast< SMDS_MeshNode*& >(edge._nodes[ iStep ]);
      if ( !edge._sWOL.IsNull() )
      {
        // compute XYZ by parameters <pos>
        if ( isOnEdge )
        {
          u = pos.X();
          pos = curve->Value( u ).Transformed(loc);
        }
        else
        {
          uv.SetCoord( pos.X(), pos.Y() );
          pos = surface->Value( pos.X(), pos.Y() ).Transformed(loc);
        }
      }
      // create or update the node
      if ( !node )
      {
        node = helper.AddNode( pos.X(), pos.Y(), pos.Z());
        if ( !edge._sWOL.IsNull() )
        {
          if ( isOnEdge )
            getMeshDS()->SetNodeOnEdge( node, geomEdge, u );
          else
            getMeshDS()->SetNodeOnFace( node, geomFace, uv.X(), uv.Y() );
        }
        else
        {
          getMeshDS()->SetNodeInVolume( node, helper.GetSubShapeID() );
        }
      }
      else
      {
        if ( !edge._sWOL.IsNull() )
        {
          // make average pos from new and current parameters
          if ( isOnEdge )
          {
            u = 0.5 * ( u + helper.GetNodeU( geomEdge, node ));
            pos = curve->Value( u ).Transformed(loc);
          }
          else
          {
            uv = 0.5 * ( uv + helper.GetNodeUV( geomFace, node ));
            pos = surface->Value( uv.X(), uv.Y()).Transformed(loc);
          }
        }
        node->setXYZ( pos.X(), pos.Y(), pos.Z() );
      }
    }
  }

  // TODO: make quadratic prisms and polyhedrons(?)

  helper.SetElementsOnShape(true);

  TopExp_Explorer exp( data._solid, TopAbs_FACE );
  for ( ; exp.More(); exp.Next() )
  {
    if ( _ignoreShapeIds.count( getMeshDS()->ShapeToIndex( exp.Current() )))
      continue;
    SMESHDS_SubMesh* fSubM = getMeshDS()->MeshElements( exp.Current() );
    SMDS_ElemIteratorPtr fIt = fSubM->GetElements();
    vector< vector<const SMDS_MeshNode*>* > nnVec;
    while ( fIt->more() )
    {
      const SMDS_MeshElement* face = fIt->next();
      int nbNodes = face->NbCornerNodes();
      nnVec.resize( nbNodes );
      SMDS_ElemIteratorPtr nIt = face->nodesIterator();
      for ( int iN = 0; iN < nbNodes; ++iN )
      {
        const SMDS_MeshNode* n = static_cast<const SMDS_MeshNode*>( nIt->next() );
        nnVec[ iN ] = & data._n2eMap[ n ]->_nodes;
      }

      int nbZ = nnVec[0]->size();
      switch ( nbNodes )
      {
      case 3:
        for ( int iZ = 1; iZ < nbZ; ++iZ )
          helper.AddVolume( (*nnVec[0])[iZ-1], (*nnVec[1])[iZ-1], (*nnVec[2])[iZ-1],
                            (*nnVec[0])[iZ],   (*nnVec[1])[iZ],   (*nnVec[2])[iZ]);
        break;
      case 4:
        for ( int iZ = 1; iZ < nbZ; ++iZ )
          helper.AddVolume( (*nnVec[0])[iZ-1], (*nnVec[1])[iZ-1],
                            (*nnVec[2])[iZ-1], (*nnVec[3])[iZ-1],
                            (*nnVec[0])[iZ],   (*nnVec[1])[iZ],
                            (*nnVec[2])[iZ],   (*nnVec[3])[iZ]);
        break;
      default:
        return error("Not supported type of element", data._index);
      }
    }
  }
  return true;
}

Here is the call graph for this function:

At study restoration, restore event listeners used to clear an inferior dim sub-mesh modified by viscous layers.

Definition at line 900 of file StdMeshers_ViscousLayers.cxx.

{
  // TODO
}
bool _ViscousBuilder::setEdgeData ( _LayerEdge edge,
const set< TGeomID > &  subIds,
SMESH_MesherHelper &  helper,
_SolidData data 
) [private]

Set data of _LayerEdge needed for smoothing.

Parameters:
subIds- ids of sub-shapes of a SOLID to take into account faces from

Definition at line 1583 of file StdMeshers_ViscousLayers.cxx.

{
  SMESH_MeshEditor editor(_mesh);

  const SMDS_MeshNode* node = edge._nodes[0]; // source node
  SMDS_TypeOfPosition posType = node->GetPosition()->GetTypeOfPosition();

  edge._len = 0;
  edge._2neibors = 0;
  edge._curvature = 0;

  // --------------------------
  // Compute _normal and _cosin
  // --------------------------

  edge._cosin = 0;
  edge._normal.SetCoord(0,0,0);

  int totalNbFaces = 0;
  gp_Pnt p;
  gp_Vec du, dv, geomNorm;
  bool normOK = true;

  TGeomID shapeInd = node->getshapeId();
  map< TGeomID, TopoDS_Shape >::const_iterator s2s = data._shrinkShape2Shape.find( shapeInd );
  bool onShrinkShape ( s2s != data._shrinkShape2Shape.end() );
  TopoDS_Shape vertEdge;

  if ( onShrinkShape ) // one of faces the node is on has no layers
  {
    vertEdge = getMeshDS()->IndexToShape( s2s->first ); // vertex or edge
    if ( s2s->second.ShapeType() == TopAbs_EDGE )
    {
      // inflate from VERTEX along EDGE
      edge._normal = getEdgeDir( TopoDS::Edge( s2s->second ), TopoDS::Vertex( vertEdge ));
    }
    else if ( vertEdge.ShapeType() == TopAbs_VERTEX )
    {
      // inflate from VERTEX along FACE
      edge._normal = getFaceDir( TopoDS::Face( s2s->second ), TopoDS::Vertex( vertEdge ),
                                 node, helper, normOK, &edge._cosin);
    }
    else
    {
      // inflate from EDGE along FACE
      edge._normal = getFaceDir( TopoDS::Face( s2s->second ), TopoDS::Edge( vertEdge ),
                                 node, helper, normOK);
    }
  }
  else // layers are on all faces of SOLID the node is on
  {
    // find indices of geom faces the node lies on
    set<TGeomID> faceIds;
    if  ( posType == SMDS_TOP_FACE )
    {
      faceIds.insert( node->getshapeId() );
    }
    else
    {
      SMDS_ElemIteratorPtr fIt = node->GetInverseElementIterator(SMDSAbs_Face);
      while ( fIt->more() )
        faceIds.insert( editor.FindShape(fIt->next()));
    }

    set<TGeomID>::iterator id = faceIds.begin();
    TopoDS_Face F;
    for ( ; id != faceIds.end(); ++id )
    {
      const TopoDS_Shape& s = getMeshDS()->IndexToShape( *id );
      if ( s.IsNull() || s.ShapeType() != TopAbs_FACE || !subIds.count( *id ))
        continue;
      totalNbFaces++;
      //nbLayerFaces += subIds.count( *id );
      F = TopoDS::Face( s );

      gp_XY uv = helper.GetNodeUV( F, node, 0, &normOK );
      Handle(Geom_Surface) surface = BRep_Tool::Surface( F );
      surface->D1( uv.X(),uv.Y(), p, du,dv );
      geomNorm = du ^ dv;
      double size2 = geomNorm.SquareMagnitude();
      if ( size2 > numeric_limits<double>::min() )
        geomNorm /= sqrt( size2 );
      else
        normOK = false;
      if ( helper.GetSubShapeOri( data._solid, F ) != TopAbs_REVERSED )
        geomNorm.Reverse();
      edge._normal += geomNorm.XYZ();
    }
    if ( totalNbFaces == 0 )
      return error(SMESH_Comment("Can't get normal to node ") << node->GetID(), data._index);

    edge._normal /= totalNbFaces;

    switch ( posType )
    {
    case SMDS_TOP_FACE:
      edge._cosin = 0; break;

    case SMDS_TOP_EDGE: {
      TopoDS_Edge E = TopoDS::Edge( helper.GetSubShapeByNode( node, getMeshDS()));
      gp_Vec inFaceDir = getFaceDir( F, E, node, helper, normOK);
      double angle = inFaceDir.Angle( edge._normal ); // [0,PI]
      edge._cosin = cos( angle );
      //cout << "Cosin on EDGE " << edge._cosin << " node " << node->GetID() << endl;
      break;
    }
    case SMDS_TOP_VERTEX: {
      TopoDS_Vertex V = TopoDS::Vertex( helper.GetSubShapeByNode( node, getMeshDS()));
      gp_Vec inFaceDir = getFaceDir( F, V, node, helper, normOK);
      double angle = inFaceDir.Angle( edge._normal ); // [0,PI]
      edge._cosin = cos( angle );
      //cout << "Cosin on VERTEX " << edge._cosin << " node " << node->GetID() << endl;
      break;
    }
    default:
      return error(SMESH_Comment("Invalid shape position of node ")<<node, data._index);
    }
  }

  double normSize = edge._normal.SquareModulus();
  if ( normSize < numeric_limits<double>::min() )
    return error(SMESH_Comment("Bad normal at node ")<< node->GetID(), data._index );

  edge._normal /= sqrt( normSize );

  // TODO: if ( !normOK ) then get normal by mesh faces

  // Set the rest data
  // --------------------
  if ( onShrinkShape )
  {
    edge._sWOL = (*s2s).second;

    SMDS_MeshNode* tgtNode = const_cast<SMDS_MeshNode*>( edge._nodes.back() );
    if ( SMESHDS_SubMesh* sm = getMeshDS()->MeshElements( data._solid ))
      sm->RemoveNode( tgtNode , /*isNodeDeleted=*/false );

    // set initial position which is parameters on _sWOL in this case
    if ( edge._sWOL.ShapeType() == TopAbs_EDGE )
    {
      double u = helper.GetNodeU( TopoDS::Edge( edge._sWOL ), node, 0, &normOK );
      edge._pos.push_back( gp_XYZ( u, 0, 0));
      getMeshDS()->SetNodeOnEdge( tgtNode, TopoDS::Edge( edge._sWOL ), u );
    }
    else // TopAbs_FACE
    {
      gp_XY uv = helper.GetNodeUV( TopoDS::Face( edge._sWOL ), node, 0, &normOK );
      edge._pos.push_back( gp_XYZ( uv.X(), uv.Y(), 0));
      getMeshDS()->SetNodeOnFace( tgtNode, TopoDS::Face( edge._sWOL ), uv.X(), uv.Y() );
    }
  }
  else
  {
    edge._pos.push_back( SMESH_TNodeXYZ( node ));

    if ( posType == SMDS_TOP_FACE )
    {
      getSimplices( node, edge._simplices, _ignoreShapeIds, &data );
      double avgNormProj = 0, avgLen = 0;
      for ( unsigned i = 0; i < edge._simplices.size(); ++i )
      {
        gp_XYZ vec = edge._pos.back() - SMESH_TNodeXYZ( edge._simplices[i]._nPrev );
        avgNormProj += edge._normal * vec;
        avgLen += vec.Modulus();
      }
      avgNormProj /= edge._simplices.size();
      avgLen /= edge._simplices.size();
      edge._curvature = _Curvature::New( avgNormProj, avgLen );
    }
  }

  // Set neighbour nodes for a _LayerEdge based on EDGE

  if ( posType == SMDS_TOP_EDGE /*||
       ( onShrinkShape && posType == SMDS_TOP_VERTEX && fabs( edge._cosin ) < 1e-10 )*/)
  {
    edge._2neibors = new _2NearEdges;
    // target node instead of source ones will be set later
    if ( ! findNeiborsOnEdge( &edge,
                              edge._2neibors->_nodes[0],
                              edge._2neibors->_nodes[1],
                              data))
      return false;
    edge.SetDataByNeighbors( edge._2neibors->_nodes[0],
                             edge._2neibors->_nodes[1],
                             helper);
  }

  edge.SetCosin( edge._cosin ); // to update edge._lenFactor

  return true;
}

Here is the call graph for this function:

bool _ViscousBuilder::shrink ( ) [private]

Shrink 2D mesh on faces to let space for inflated layers.

Definition at line 3430 of file StdMeshers_ViscousLayers.cxx.

{
  // make map of (ids of FACEs to shrink mesh on) to (_SolidData containing _LayerEdge's
  // inflated along FACE or EDGE)
  map< TGeomID, _SolidData* > f2sdMap;
  for ( unsigned i = 0 ; i < _sdVec.size(); ++i )
  {
    _SolidData& data = _sdVec[i];
    TopTools_MapOfShape FFMap;
    map< TGeomID, TopoDS_Shape >::iterator s2s = data._shrinkShape2Shape.begin();
    for (; s2s != data._shrinkShape2Shape.end(); ++s2s )
      if ( s2s->second.ShapeType() == TopAbs_FACE )
      {
        f2sdMap.insert( make_pair( getMeshDS()->ShapeToIndex( s2s->second ), &data ));

        if ( FFMap.Add( (*s2s).second ))
          // Put mesh faces on the shrinked FACE to the proxy sub-mesh to avoid
          // usage of mesh faces made in addBoundaryElements() by the 3D algo or
          // by StdMeshers_QuadToTriaAdaptor
          if ( SMESHDS_SubMesh* smDS = getMeshDS()->MeshElements( s2s->second ))
          {
            SMESH_ProxyMesh::SubMesh* proxySub =
              data._proxyMesh->getFaceSubM( TopoDS::Face( s2s->second ), /*create=*/true);
            SMDS_ElemIteratorPtr fIt = smDS->GetElements();
            while ( fIt->more() )
              proxySub->AddElement( fIt->next() );
            // as a result 3D algo will use elements from proxySub and not from smDS
          }
      }
  }

  SMESH_MesherHelper helper( *_mesh );

  // EDGE's to shrink
  map< int, _Shrinker1D > e2shrMap;

  // loop on FACES to srink mesh on
  map< TGeomID, _SolidData* >::iterator f2sd = f2sdMap.begin();
  for ( ; f2sd != f2sdMap.end(); ++f2sd )
  {
    _SolidData&     data = *f2sd->second;
    TNode2Edge&   n2eMap = data._n2eMap;
    const TopoDS_Face& F = TopoDS::Face( getMeshDS()->IndexToShape( f2sd->first ));

    Handle(Geom_Surface) surface = BRep_Tool::Surface(F);

    SMESH_subMesh*     sm = _mesh->GetSubMesh( F );
    SMESHDS_SubMesh* smDS = sm->GetSubMeshDS();

    helper.SetSubShape(F);

    // ===========================
    // Prepare data for shrinking
    // ===========================

    // Collect nodes to smooth, as src nodes are not yet replaced by tgt ones
    // and thus all nodes on a FACE connected to 2d elements are to be smoothed
    vector < const SMDS_MeshNode* > smoothNodes;
    {
      SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
      while ( nIt->more() )
      {
        const SMDS_MeshNode* n = nIt->next();
        if ( n->NbInverseElements( SMDSAbs_Face ) > 0 )
          smoothNodes.push_back( n );
      }
    }
    // Find out face orientation
    double refSign = 1;
    const set<TGeomID> ignoreShapes;
    bool isOkUV;
    if ( !smoothNodes.empty() )
    {
      vector<_Simplex> simplices;
      getSimplices( smoothNodes[0], simplices, ignoreShapes );
      helper.GetNodeUV( F, simplices[0]._nPrev, 0, &isOkUV ); // fix UV of silpmex nodes
      helper.GetNodeUV( F, simplices[0]._nNext, 0, &isOkUV );
      gp_XY uv = helper.GetNodeUV( F, smoothNodes[0], 0, &isOkUV );
      if ( !simplices[0].IsForward(uv, smoothNodes[0], F, helper,refSign) )
        refSign = -1;
    }

    // Find _LayerEdge's inflated along F
    vector< _LayerEdge* > lEdges;
    {
      SMESH_subMeshIteratorPtr subIt =
        sm->getDependsOnIterator(/*includeSelf=*/false, /*complexShapeFirst=*/false);
      while ( subIt->more() )
      {
        SMESH_subMesh* sub = subIt->next();
        SMESHDS_SubMesh* subDS = sub->GetSubMeshDS();
        if ( subDS->NbNodes() == 0 || !n2eMap.count( subDS->GetNodes()->next() ))
          continue;
        SMDS_NodeIteratorPtr nIt = subDS->GetNodes();
        while ( nIt->more() )
        {
          _LayerEdge* edge = n2eMap[ nIt->next() ];
          lEdges.push_back( edge );
          prepareEdgeToShrink( *edge, F, helper, smDS );
        }
      }
    }

    // Replace source nodes by target nodes in mesh faces to shrink
    const SMDS_MeshNode* nodes[20];
    for ( unsigned i = 0; i < lEdges.size(); ++i )
    {
      _LayerEdge& edge = *lEdges[i];
      const SMDS_MeshNode* srcNode = edge._nodes[0];
      const SMDS_MeshNode* tgtNode = edge._nodes.back();
      SMDS_ElemIteratorPtr fIt = srcNode->GetInverseElementIterator(SMDSAbs_Face);
      while ( fIt->more() )
      {
        const SMDS_MeshElement* f = fIt->next();
        if ( !smDS->Contains( f ))
          continue;
        SMDS_ElemIteratorPtr nIt = f->nodesIterator();
        for ( int iN = 0; iN < f->NbNodes(); ++iN )
        {
          const SMDS_MeshNode* n = static_cast<const SMDS_MeshNode*>( nIt->next() );
          nodes[iN] = ( n == srcNode ? tgtNode : n );
        }
        helper.GetMeshDS()->ChangeElementNodes( f, nodes, f->NbNodes() );
      }
    }

    // find out if a FACE is concave
    const bool isConcaveFace = isConcave( F, helper );

    // Create _SmoothNode's on face F
    vector< _SmoothNode > nodesToSmooth( smoothNodes.size() );
    {
      dumpFunction(SMESH_Comment("beforeShrinkFace")<<f2sd->first); // debug
      for ( unsigned i = 0; i < smoothNodes.size(); ++i )
      {
        const SMDS_MeshNode* n = smoothNodes[i];
        nodesToSmooth[ i ]._node = n;
        // src nodes must be replaced by tgt nodes to have tgt nodes in _simplices
        getSimplices( n, nodesToSmooth[ i ]._simplices, ignoreShapes, NULL, isConcaveFace );
        // fix up incorrect uv of nodes on the FACE
        helper.GetNodeUV( F, n, 0, &isOkUV);
        dumpMove( n );
      }
      dumpFunctionEnd();
    }
    //if ( nodesToSmooth.empty() ) continue;

    // Find EDGE's to shrink
    set< _Shrinker1D* > eShri1D;
    {
      for ( unsigned i = 0; i < lEdges.size(); ++i )
      {
        _LayerEdge* edge = lEdges[i];
        if ( edge->_sWOL.ShapeType() == TopAbs_EDGE )
        {
          TGeomID edgeIndex = getMeshDS()->ShapeToIndex( edge->_sWOL );
          _Shrinker1D& srinker = e2shrMap[ edgeIndex ];
          eShri1D.insert( & srinker );
          srinker.AddEdge( edge, helper );
          // restore params of nodes on EGDE if the EDGE has been already
          // srinked while srinking another FACE
          srinker.RestoreParams();
        }
      }
    }

    // ==================
    // Perform shrinking
    // ==================

    bool shrinked = true;
    int badNb, shriStep=0, smooStep=0;
    while ( shrinked )
    {
      // Move boundary nodes (actually just set new UV)
      // -----------------------------------------------
      dumpFunction(SMESH_Comment("moveBoundaryOnF")<<f2sd->first<<"_st"<<shriStep++ ); // debug
      shrinked = false;
      for ( unsigned i = 0; i < lEdges.size(); ++i )
      {
        shrinked |= lEdges[i]->SetNewLength2d( surface,F,helper );
      }
      dumpFunctionEnd();

      // Move nodes on EDGE's
      set< _Shrinker1D* >::iterator shr = eShri1D.begin();
      for ( ; shr != eShri1D.end(); ++shr )
        (*shr)->Compute( /*set3D=*/false, helper );

      // Smoothing in 2D
      // -----------------
      int nbNoImpSteps = 0;
      bool moved = true;
      badNb = 1;
      while (( nbNoImpSteps < 5 && badNb > 0) && moved)
      {
        dumpFunction(SMESH_Comment("shrinkFace")<<f2sd->first<<"_st"<<++smooStep); // debug

        int oldBadNb = badNb;
        badNb = 0;
        moved = false;
        for ( unsigned i = 0; i < nodesToSmooth.size(); ++i )
        {
          moved |= nodesToSmooth[i].Smooth( badNb,surface,helper,refSign,
                                            /*isCentroidal=*/isConcaveFace,/*set3D=*/false );
        }
        if ( badNb < oldBadNb )
          nbNoImpSteps = 0;
        else
          nbNoImpSteps++;

        dumpFunctionEnd();
      }
      if ( badNb > 0 )
        return error(SMESH_Comment("Can't shrink 2D mesh on face ") << f2sd->first );
    }
    // No wrongly shaped faces remain; final smooth. Set node XYZ.
    // First, find out a needed quality of smoothing (high for quadrangles only)
    bool highQuality;
    {
      const bool hasTria = _mesh->NbTriangles(), hasQuad = _mesh->NbQuadrangles();
      if ( hasTria != hasQuad )
      {
        highQuality = hasQuad;
      }
      else
      {
        set<int> nbNodesSet;
        SMDS_ElemIteratorPtr fIt = smDS->GetElements();
        while ( fIt->more() && nbNodesSet.size() < 2 )
          nbNodesSet.insert( fIt->next()->NbCornerNodes() );
        highQuality = ( *nbNodesSet.begin() == 4 );
      }
    }
    if ( !highQuality && isConcaveFace )
      fixBadFaces( F, helper ); // fix narrow faces by swaping diagonals
    for ( int st = highQuality ? 10 : 3; st; --st )
    {
      dumpFunction(SMESH_Comment("shrinkFace")<<f2sd->first<<"_st"<<++smooStep); // debug
      for ( unsigned i = 0; i < nodesToSmooth.size(); ++i )
        nodesToSmooth[i].Smooth( badNb,surface,helper,refSign,
                                 /*isCentroidal=*/isConcaveFace,/*set3D=*/st==1 );
      dumpFunctionEnd();
    }
    // Set an event listener to clear FACE sub-mesh together with SOLID sub-mesh
    _SrinkShapeListener::ToClearSubMeshWithSolid( sm, data._solid );

  } // loop on FACES to srink mesh on


  // Replace source nodes by target nodes in shrinked mesh edges

  map< int, _Shrinker1D >::iterator e2shr = e2shrMap.begin();
  for ( ; e2shr != e2shrMap.end(); ++e2shr )
    e2shr->second.SwapSrcTgtNodes( getMeshDS() );

  return true;
}

Here is the call graph for this function:

bool _ViscousBuilder::smoothAnalyticEdge ( _SolidData data,
const int  iFrom,
const int  iTo,
Handle(Geom_Surface)&  surface,
const TopoDS_Face &  F,
SMESH_MesherHelper &  helper 
) [private]

smooth _LayerEdge's on a staight EDGE or circular EDGE

Definition at line 2417 of file StdMeshers_ViscousLayers.cxx.

{
  TopoDS_Shape S = helper.GetSubShapeByNode( data._edges[ iFrom ]->_nodes[0],
                                             helper.GetMeshDS());
  TopoDS_Edge E = TopoDS::Edge( S );

  Handle(Geom_Curve) curve = data.CurveForSmooth( E, iFrom, iTo, surface, F, helper );
  if ( curve.IsNull() ) return false;

  // compute a relative length of segments
  vector< double > len( iTo-iFrom+1 );
  {
    double curLen, prevLen = len[0] = 1.0;
    for ( int i = iFrom; i < iTo; ++i )
    {
      curLen = prevLen * data._edges[i]->_2neibors->_wgt[0] / data._edges[i]->_2neibors->_wgt[1];
      len[i-iFrom+1] = len[i-iFrom] + curLen;
      prevLen = curLen;
    }
  }

  if ( curve->IsKind( STANDARD_TYPE( Geom_Line )))
  {
    if ( F.IsNull() ) // 3D
    {
      SMESH_TNodeXYZ p0( data._edges[iFrom]->_2neibors->_nodes[0]);
      SMESH_TNodeXYZ p1( data._edges[iTo-1]->_2neibors->_nodes[1]);
      for ( int i = iFrom; i < iTo; ++i )
      {
        double r = len[i-iFrom] / len.back();
        gp_XYZ newPos = p0 * ( 1. - r ) + p1 * r;
        data._edges[i]->_pos.back() = newPos;
        SMDS_MeshNode* tgtNode = const_cast<SMDS_MeshNode*>( data._edges[i]->_nodes.back() );
        tgtNode->setXYZ( newPos.X(), newPos.Y(), newPos.Z() );
        dumpMove( tgtNode );
      }
    }
    else
    {
      gp_XY uv0 = helper.GetNodeUV( F, data._edges[iFrom]->_2neibors->_nodes[0]);
      gp_XY uv1 = helper.GetNodeUV( F, data._edges[iTo-1]->_2neibors->_nodes[1]);
      if ( data._edges[iFrom]->_2neibors->_nodes[0] ==
           data._edges[iTo-1]->_2neibors->_nodes[1] ) // closed edge
      {
        int iPeriodic = helper.GetPeriodicIndex();
        if ( iPeriodic == 1 || iPeriodic == 2 )
        {
          uv1.SetCoord( iPeriodic, helper.GetOtherParam( uv1.Coord( iPeriodic )));
          if ( uv0.Coord( iPeriodic ) > uv1.Coord( iPeriodic ))
            std::swap( uv0, uv1 );
        }
      }
      const gp_XY rangeUV = uv1 - uv0;
      for ( int i = iFrom; i < iTo; ++i )
      {
        double r = len[i-iFrom] / len.back();
        gp_XY newUV = uv0 + r * rangeUV;
        data._edges[i]->_pos.back().SetCoord( newUV.X(), newUV.Y(), 0 );

        gp_Pnt newPos = surface->Value( newUV.X(), newUV.Y() );
        SMDS_MeshNode* tgtNode = const_cast<SMDS_MeshNode*>( data._edges[i]->_nodes.back() );
        tgtNode->setXYZ( newPos.X(), newPos.Y(), newPos.Z() );
        dumpMove( tgtNode );

        SMDS_FacePosition* pos = static_cast<SMDS_FacePosition*>( tgtNode->GetPosition() );
        pos->SetUParameter( newUV.X() );
        pos->SetVParameter( newUV.Y() );
      }
    }
    return true;
  }

  if ( curve->IsKind( STANDARD_TYPE( Geom_Circle )))
  {
    Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast( curve );
    gp_Pnt center3D = circle->Location();

    if ( F.IsNull() ) // 3D
    {
      return false; // TODO ???
    }
    else // 2D
    {
      const gp_XY center( center3D.X(), center3D.Y() );
      
      gp_XY uv0 = helper.GetNodeUV( F, data._edges[iFrom]->_2neibors->_nodes[0]);
      gp_XY uvM = helper.GetNodeUV( F, data._edges[iFrom]->_nodes.back());
      gp_XY uv1 = helper.GetNodeUV( F, data._edges[iTo-1]->_2neibors->_nodes[1]);
      gp_Vec2d vec0( center, uv0 );
      gp_Vec2d vecM( center, uvM);
      gp_Vec2d vec1( center, uv1 );
      double uLast = vec0.Angle( vec1 ); // -PI - +PI
      double uMidl = vec0.Angle( vecM );
      if ( uLast < 0 ) uLast += 2.*M_PI; // 0.0 - 2*PI
      if ( uMidl < 0 ) uMidl += 2.*M_PI;
      const bool sense = ( uMidl < uLast );
      const double radius = 0.5 * ( vec0.Magnitude() + vec1.Magnitude() );

      gp_Ax2d axis( center, vec0 );
      gp_Circ2d circ ( axis, radius, sense );
      for ( int i = iFrom; i < iTo; ++i )
      {
        double    newU = uLast * len[i-iFrom] / len.back();
        gp_Pnt2d newUV = ElCLib::Value( newU, circ );
        data._edges[i]->_pos.back().SetCoord( newUV.X(), newUV.Y(), 0 );

        gp_Pnt newPos = surface->Value( newUV.X(), newUV.Y() );
        SMDS_MeshNode* tgtNode = const_cast<SMDS_MeshNode*>( data._edges[i]->_nodes.back() );
        tgtNode->setXYZ( newPos.X(), newPos.Y(), newPos.Z() );
        dumpMove( tgtNode );

        SMDS_FacePosition* pos = static_cast<SMDS_FacePosition*>( tgtNode->GetPosition() );
        pos->SetUParameter( newUV.X() );
        pos->SetVParameter( newUV.Y() );
      }
    }
    return true;
  }

  return false;
}

Here is the call graph for this function:

bool _ViscousBuilder::smoothAndCheck ( _SolidData data,
const int  nbSteps,
double &  distToIntersection 
) [private]

Improve quality of layer inner surface and check intersection.

Definition at line 2146 of file StdMeshers_ViscousLayers.cxx.

{
  if ( data._endEdgeToSmooth.empty() )
    return true; // no shapes needing smoothing

  bool moved, improved;

  SMESH_MesherHelper helper(*_mesh);
  Handle(Geom_Surface) surface;
  TopoDS_Face F;

  int iBeg, iEnd = 0;
  for ( unsigned iS = 0; iS < data._endEdgeToSmooth.size(); ++iS )
  {
    iBeg = iEnd;
    iEnd = data._endEdgeToSmooth[ iS ];

    if ( !data._edges[ iBeg ]->_sWOL.IsNull() &&
         data._edges[ iBeg ]->_sWOL.ShapeType() == TopAbs_FACE )
    {
      if ( !F.IsSame( data._edges[ iBeg ]->_sWOL )) {
        F = TopoDS::Face( data._edges[ iBeg ]->_sWOL );
        helper.SetSubShape( F );
        surface = BRep_Tool::Surface( F );
      }
    }
    else
    {
      F.Nullify(); surface.Nullify();
    }
    TGeomID sInd = data._edges[ iBeg ]->_nodes[0]->getshapeId();

    if ( data._edges[ iBeg ]->IsOnEdge() )
    { 
      dumpFunction(SMESH_Comment("smooth")<<data._index << "_Ed"<<sInd <<"_InfStep"<<nbSteps);

      // try a simple solution on an analytic EDGE
      if ( !smoothAnalyticEdge( data, iBeg, iEnd, surface, F, helper ))
      {
        // smooth on EDGE's
        int step = 0;
        do {
          moved = false;
          for ( int i = iBeg; i < iEnd; ++i )
          {
            moved |= data._edges[i]->SmoothOnEdge(surface, F, helper);
          }
          dumpCmd( SMESH_Comment("# end step ")<<step);
        }
        while ( moved && step++ < 5 );
        //cout << " NB STEPS: " << step << endl;
      }
      dumpFunctionEnd();
    }
    else
    {
      // smooth on FACE's
      int step = 0, badNb = 0; moved = true;
      while (( ++step <= 5 && moved ) || improved )
      {
        dumpFunction(SMESH_Comment("smooth")<<data._index<<"_Fa"<<sInd
                     <<"_InfStep"<<nbSteps<<"_"<<step); // debug
        int oldBadNb = badNb;
        badNb = 0;
        moved = false;
        for ( int i = iBeg; i < iEnd; ++i )
          moved |= data._edges[i]->Smooth(badNb);
        improved = ( badNb < oldBadNb );

        dumpFunctionEnd();
      }
      if ( badNb > 0 )
      {
#ifdef __myDEBUG
        for ( int i = iBeg; i < iEnd; ++i )
        {
          _LayerEdge* edge = data._edges[i];
          SMESH_TNodeXYZ tgtXYZ( edge->_nodes.back() );
          for ( unsigned j = 0; j < edge->_simplices.size(); ++j )
            if ( !edge->_simplices[j].IsForward( edge->_nodes[0], &tgtXYZ ))
            {
              cout << "Bad simplex ( " << edge->_nodes[0]->GetID()<< " "<< tgtXYZ._node->GetID()
                   << " "<< edge->_simplices[j]._nPrev->GetID()
                   << " "<< edge->_simplices[j]._nNext->GetID() << " )" << endl;
              return false;
            }
        }
#endif
        return false;
      }
    }
  } // loop on shapes to smooth

  // Check if the last segments of _LayerEdge intersects 2D elements;
  // checked elements are either temporary faces or faces on surfaces w/o the layers

  SMESH_MeshEditor editor( _mesh );
  auto_ptr<SMESH_ElementSearcher> searcher
    ( editor.GetElementSearcher( data._proxyMesh->GetFaces( data._solid )) );

  distToIntersection = Precision::Infinite();
  double dist;
  const SMDS_MeshElement* intFace = 0;
#ifdef __myDEBUG
  const SMDS_MeshElement* closestFace = 0;
  int iLE = 0;
#endif
  for ( unsigned i = 0; i < data._edges.size(); ++i )
  {
    if ( data._edges[i]->FindIntersection( *searcher, dist, data._epsilon, &intFace ))
      return false;
    if ( distToIntersection > dist )
    {
      distToIntersection = dist;
#ifdef __myDEBUG
      iLE = i;
      closestFace = intFace;
#endif
    }
  }
#ifdef __myDEBUG
  if ( closestFace )
  {
    SMDS_MeshElement::iterator nIt = closestFace->begin_nodes();
    cout << "Shortest distance: _LayerEdge nodes: tgt " << data._edges[iLE]->_nodes.back()->GetID()
         << " src " << data._edges[iLE]->_nodes[0]->GetID()<< ", intersection with face ("
         << (*nIt++)->GetID()<<" "<< (*nIt++)->GetID()<<" "<< (*nIt++)->GetID()
         << ") distance = " << distToIntersection<< endl;
  }
#endif

  return true;
}

Here is the call graph for this function:

bool _ViscousBuilder::sortEdges ( _SolidData data,
vector< vector< _LayerEdge * > > &  edgesByGeom 
) [private]

Separate shapes (and _LayerEdge's on them) to smooth from the rest ones.

Definition at line 1464 of file StdMeshers_ViscousLayers.cxx.

{
  // Find shapes needing smoothing; such a shape has _LayerEdge._normal on it's
  // boundry inclined at a sharp angle to the shape

  list< TGeomID > shapesToSmooth;
  
  SMESH_MesherHelper helper( *_mesh );
  bool ok = true;

  for ( unsigned iS = 0; iS < edgesByGeom.size(); ++iS )
  {
    vector<_LayerEdge*>& eS = edgesByGeom[iS];
    if ( eS.empty() ) continue;
    TopoDS_Shape S = getMeshDS()->IndexToShape( iS );
    bool needSmooth = false;
    switch ( S.ShapeType() )
    {
    case TopAbs_EDGE: {

      bool isShrinkEdge = !eS[0]->_sWOL.IsNull();
      for ( TopoDS_Iterator vIt( S ); vIt.More() && !needSmooth; vIt.Next() )
      {
        TGeomID iV = getMeshDS()->ShapeToIndex( vIt.Value() );
        vector<_LayerEdge*>& eV = edgesByGeom[ iV ];
        if ( eV.empty() ) continue;
        double cosin = eV[0]->_cosin;
        bool badCosin =
          ( !eV[0]->_sWOL.IsNull() && ( eV[0]->_sWOL.ShapeType() == TopAbs_EDGE || !isShrinkEdge));
        if ( badCosin )
        {
          gp_Vec dir1, dir2;
          if ( eV[0]->_sWOL.ShapeType() == TopAbs_EDGE )
            dir1 = getEdgeDir( TopoDS::Edge( eV[0]->_sWOL ), TopoDS::Vertex( vIt.Value() ));
          else
            dir1 = getFaceDir( TopoDS::Face( eV[0]->_sWOL ), TopoDS::Vertex( vIt.Value() ),
                               eV[0]->_nodes[0], helper, ok);
          dir2 = getEdgeDir( TopoDS::Edge( S ), TopoDS::Vertex( vIt.Value() ));
          double angle = dir1.Angle( dir2 );
          cosin = cos( angle );
        }
        needSmooth = ( cosin > 0.1 );
      }
      break;
    }
    case TopAbs_FACE: {

      for ( TopExp_Explorer eExp( S, TopAbs_EDGE ); eExp.More() && !needSmooth; eExp.Next() )
      {
        TGeomID iE = getMeshDS()->ShapeToIndex( eExp.Current() );
        vector<_LayerEdge*>& eE = edgesByGeom[ iE ];
        if ( eE.empty() ) continue;
        if ( eE[0]->_sWOL.IsNull() )
        {
          for ( unsigned i = 0; i < eE.size() && !needSmooth; ++i )
            needSmooth = ( eE[i]->_cosin > 0.1 );
        }
        else
        {
          const TopoDS_Face& F1 = TopoDS::Face( S );
          const TopoDS_Face& F2 = TopoDS::Face( eE[0]->_sWOL );
          const TopoDS_Edge& E  = TopoDS::Edge( eExp.Current() );
          for ( unsigned i = 0; i < eE.size() && !needSmooth; ++i )
          {
            gp_Vec dir1 = getFaceDir( F1, E, eE[i]->_nodes[0], helper, ok );
            gp_Vec dir2 = getFaceDir( F2, E, eE[i]->_nodes[0], helper, ok );
            double angle = dir1.Angle( dir2 );
            double cosin = cos( angle );
            needSmooth = ( cosin > 0.1 );
          }
        }
      }
      break;
    }
    case TopAbs_VERTEX:
      continue;
    default:;
    }
    if ( needSmooth )
    {
      if ( S.ShapeType() == TopAbs_EDGE ) shapesToSmooth.push_front( iS );
      else                                shapesToSmooth.push_back ( iS );
    }

  } // loop on edgesByGeom

  data._edges.reserve( data._n2eMap.size() );
  data._endEdgeToSmooth.clear();

  // first we put _LayerEdge's on shapes to smooth
  list< TGeomID >::iterator gIt = shapesToSmooth.begin();
  for ( ; gIt != shapesToSmooth.end(); ++gIt )
  {
    vector<_LayerEdge*>& eVec = edgesByGeom[ *gIt ];
    if ( eVec.empty() ) continue;
    data._edges.insert( data._edges.end(), eVec.begin(), eVec.end() );
    data._endEdgeToSmooth.push_back( data._edges.size() );
    eVec.clear();
  }

  // then the rest _LayerEdge's
  for ( unsigned iS = 0; iS < edgesByGeom.size(); ++iS )
  {
    vector<_LayerEdge*>& eVec = edgesByGeom[iS];
    data._edges.insert( data._edges.end(), eVec.begin(), eVec.end() );
    eVec.clear();
  }

  return ok;
}
bool _ViscousBuilder::updateNormals ( _SolidData data,
SMESH_MesherHelper &  helper 
) [private]

Modify normals of _LayerEdge's on EDGE's to avoid intersection with _LayerEdge's on neighbor EDGE's.

Definition at line 2551 of file StdMeshers_ViscousLayers.cxx.

{
  // make temporary quadrangles got by extrusion of
  // mesh edges along _LayerEdge._normal's

  vector< const SMDS_MeshElement* > tmpFaces;
  {
    set< SMESH_TLink > extrudedLinks; // contains target nodes
    vector< const SMDS_MeshNode*> nodes(4); // of a tmp mesh face

    dumpFunction(SMESH_Comment("makeTmpFacesOnEdges")<<data._index);
    for ( unsigned i = 0; i < data._edges.size(); ++i )
    {
      _LayerEdge* edge = data._edges[i];
      if ( !edge->IsOnEdge() || !edge->_sWOL.IsNull() ) continue;
      const SMDS_MeshNode* tgt1 = edge->_nodes.back();
      for ( int j = 0; j < 2; ++j ) // loop on _2NearEdges
      {
        const SMDS_MeshNode* tgt2 = edge->_2neibors->_nodes[j];
        pair< set< SMESH_TLink >::iterator, bool > link_isnew =
          extrudedLinks.insert( SMESH_TLink( tgt1, tgt2 ));
        if ( !link_isnew.second )
        {
          extrudedLinks.erase( link_isnew.first );
          continue; // already extruded and will no more encounter
        }
        // look for a _LayerEdge containg tgt2
//         _LayerEdge* neiborEdge = 0;
//         unsigned di = 0; // check _edges[i+di] and _edges[i-di]
//         while ( !neiborEdge && ++di <= data._edges.size() )
//         {
//           if ( i+di < data._edges.size() && data._edges[i+di]->_nodes.back() == tgt2 )
//             neiborEdge = data._edges[i+di];
//           else if ( di <= i && data._edges[i-di]->_nodes.back() == tgt2 )
//             neiborEdge = data._edges[i-di];
//         }
//         if ( !neiborEdge )
//           return error("updateNormals(): neighbor _LayerEdge not found", data._index);
        _LayerEdge* neiborEdge = edge->_2neibors->_edges[j];

        TmpMeshFaceOnEdge* f = new TmpMeshFaceOnEdge( edge, neiborEdge, --_tmpFaceID );
        tmpFaces.push_back( f );

        dumpCmd(SMESH_Comment("mesh.AddFace([ ")
                <<f->_nn[0]->GetID()<<", "<<f->_nn[1]->GetID()<<", "
                <<f->_nn[2]->GetID()<<", "<<f->_nn[3]->GetID()<<" ])");
      }
    }
    dumpFunctionEnd();
  }
  // Check if _LayerEdge's based on EDGE's intersects tmpFaces.
  // Perform two loops on _LayerEdge on EDGE's:
  // 1) to find and fix intersection
  // 2) to check that no new intersection appears as result of 1)

  SMESH_MeshEditor editor( _mesh );
  SMDS_ElemIteratorPtr fIt( new SMDS_ElementVectorIterator( tmpFaces.begin(),
                                                            tmpFaces.end()));
  auto_ptr<SMESH_ElementSearcher> searcher ( editor.GetElementSearcher( fIt ));

  // 1) Find intersections
  double dist;
  const SMDS_MeshElement* face;
  typedef map< _LayerEdge*, set< _LayerEdge*, _LayerEdgeCmp >, _LayerEdgeCmp > TLEdge2LEdgeSet;
  TLEdge2LEdgeSet edge2CloseEdge;

  const double eps = data._epsilon * data._epsilon;
  for ( unsigned i = 0; i < data._edges.size(); ++i )
  {
    _LayerEdge* edge = data._edges[i];
    if ( !edge->IsOnEdge() || !edge->_sWOL.IsNull() ) continue;
    if ( edge->FindIntersection( *searcher, dist, eps, &face ))
    {
      const TmpMeshFaceOnEdge* f = (const TmpMeshFaceOnEdge*) face;
      set< _LayerEdge*, _LayerEdgeCmp > & ee = edge2CloseEdge[ edge ];
      ee.insert( f->_le1 );
      ee.insert( f->_le2 );
      if ( f->_le1->IsOnEdge() && f->_le1->_sWOL.IsNull() ) 
        edge2CloseEdge[ f->_le1 ].insert( edge );
      if ( f->_le2->IsOnEdge() && f->_le2->_sWOL.IsNull() ) 
        edge2CloseEdge[ f->_le2 ].insert( edge );
    }
  }

  // Set _LayerEdge._normal

  if ( !edge2CloseEdge.empty() )
  {
    dumpFunction(SMESH_Comment("updateNormals")<<data._index);

    TLEdge2LEdgeSet::iterator e2ee = edge2CloseEdge.begin();
    for ( ; e2ee != edge2CloseEdge.end(); ++e2ee )
    {
      _LayerEdge* edge1       = e2ee->first;
      _LayerEdge* edge2       = 0;
      set< _LayerEdge*, _LayerEdgeCmp >& ee  = e2ee->second;

      // find EDGEs the edges reside
      TopoDS_Edge E1, E2;
      TopoDS_Shape S = helper.GetSubShapeByNode( edge1->_nodes[0], getMeshDS() );
      if ( S.ShapeType() != TopAbs_EDGE )
        continue; // TODO: find EDGE by VERTEX
      E1 = TopoDS::Edge( S );
      set< _LayerEdge*, _LayerEdgeCmp >::iterator eIt = ee.begin();
      while ( E2.IsNull() && eIt != ee.end())
      {
        _LayerEdge* e2 = *eIt++;
        TopoDS_Shape S = helper.GetSubShapeByNode( e2->_nodes[0], getMeshDS() );
        if ( S.ShapeType() == TopAbs_EDGE )
          E2 = TopoDS::Edge( S ), edge2 = e2;
      }
      if ( E2.IsNull() ) continue; // TODO: find EDGE by VERTEX

      // find 3 FACEs sharing 2 EDGEs

      TopoDS_Face FF1[2], FF2[2];
      PShapeIteratorPtr fIt = helper.GetAncestors(E1, *_mesh, TopAbs_FACE);
      while ( fIt->more() && FF1[1].IsNull())
      {
        const TopoDS_Face *F = (const TopoDS_Face*) fIt->next();
        if ( helper.IsSubShape( *F, data._solid))
          FF1[ FF1[0].IsNull() ? 0 : 1 ] = *F;
      }
      fIt = helper.GetAncestors(E2, *_mesh, TopAbs_FACE);
      while ( fIt->more() && FF2[1].IsNull())
      {
        const TopoDS_Face *F = (const TopoDS_Face*) fIt->next();
        if ( helper.IsSubShape( *F, data._solid))
          FF2[ FF2[0].IsNull() ? 0 : 1 ] = *F;
      }
      // exclude a FACE common to E1 and E2 (put it at [1] in FF* )
      if ( FF1[0].IsSame( FF2[0]) || FF1[0].IsSame( FF2[1]))
        std::swap( FF1[0], FF1[1] );
      if ( FF2[0].IsSame( FF1[0]) )
        std::swap( FF2[0], FF2[1] );
      if ( FF1[0].IsNull() || FF2[0].IsNull() )
        continue;

//       // get a new normal for edge1
      bool ok;
      gp_Vec dir1 = edge1->_normal, dir2 = edge2->_normal;
      if ( edge1->_cosin < 0 )
        dir1 = getFaceDir( FF1[0], E1, edge1->_nodes[0], helper, ok ).Normalized();
      if ( edge2->_cosin < 0 )
        dir2 = getFaceDir( FF2[0], E2, edge2->_nodes[0], helper, ok ).Normalized();
      //      gp_Vec dir1 = getFaceDir( FF1[0], E1, edge1->_nodes[0], helper, ok );
//       gp_Vec dir2 = getFaceDir( FF2[0], E2, edge2->_nodes[0], helper, ok2 );
//       double wgt1 = ( edge1->_cosin + 1 ) / ( edge1->_cosin + edge2->_cosin + 2 );
//       double wgt2 = ( edge2->_cosin + 1 ) / ( edge1->_cosin + edge2->_cosin + 2 );
//       gp_Vec newNorm = wgt1 * dir1 + wgt2 * dir2;
//       newNorm.Normalize();

      double wgt1 = ( edge1->_cosin + 1 ) / ( edge1->_cosin + edge2->_cosin + 2 );
      double wgt2 = ( edge2->_cosin + 1 ) / ( edge1->_cosin + edge2->_cosin + 2 );
      gp_Vec newNorm = wgt1 * dir1 + wgt2 * dir2;
      newNorm.Normalize();

      edge1->_normal = newNorm.XYZ();

      // update data of edge1 depending on _normal
      const SMDS_MeshNode *n1, *n2;
      n1 = edge1->_2neibors->_edges[0]->_nodes[0];
      n2 = edge1->_2neibors->_edges[1]->_nodes[0];
      //if ( !findNeiborsOnEdge( edge1, n1, n2, data ))
      //continue;
      edge1->SetDataByNeighbors( n1, n2, helper );
      gp_Vec dirInFace;
      if ( edge1->_cosin < 0 )
        dirInFace = dir1;
      else
        getFaceDir( FF1[0], E1, edge1->_nodes[0], helper, ok );
      double angle = dir1.Angle( edge1->_normal ); // [0,PI]
      edge1->SetCosin( cos( angle ));

      // limit data._stepSize
      if ( edge1->_cosin > 0.1 )
      {
        SMDS_ElemIteratorPtr fIt = edge1->_nodes[0]->GetInverseElementIterator(SMDSAbs_Face);
        while ( fIt->more() )
          limitStepSize( data, fIt->next(), edge1->_cosin );
      }
      // set new XYZ of target node
      edge1->InvalidateStep( 1 );
      edge1->_len = 0;
      edge1->SetNewLength( data._stepSize, helper );
    }

    // Update normals and other dependent data of not intersecting _LayerEdge's
    // neighboring the intersecting ones

    for ( e2ee = edge2CloseEdge.begin(); e2ee != edge2CloseEdge.end(); ++e2ee )
    {
      _LayerEdge* edge1 = e2ee->first;
      if ( !edge1->_2neibors )
        continue;
      for ( int j = 0; j < 2; ++j ) // loop on 2 neighbors
      {
        _LayerEdge* neighbor = edge1->_2neibors->_edges[j];
        if ( edge2CloseEdge.count ( neighbor ))
          continue; // j-th neighbor is also intersected
        _LayerEdge* prevEdge = edge1;
        const int nbSteps = 6;
        for ( int step = nbSteps; step; --step ) // step from edge1 in j-th direction
        {
          if ( !neighbor->_2neibors )
            break; // neighbor is on VERTEX
          int iNext = 0;
          _LayerEdge* nextEdge = neighbor->_2neibors->_edges[iNext];
          if ( nextEdge == prevEdge )
            nextEdge = neighbor->_2neibors->_edges[ ++iNext ];
//           const double&  wgtPrev = neighbor->_2neibors->_wgt[1-iNext];
//           const double&  wgtNext = neighbor->_2neibors->_wgt[iNext];
          double r = double(step-1)/nbSteps;
          if ( !nextEdge->_2neibors )
            r = 0.5;

          gp_XYZ newNorm = prevEdge->_normal * r + nextEdge->_normal * (1-r);
          newNorm.Normalize();

          neighbor->_normal = newNorm;
          neighbor->SetCosin( prevEdge->_cosin * r + nextEdge->_cosin * (1-r) );
          neighbor->SetDataByNeighbors( prevEdge->_nodes[0], nextEdge->_nodes[0], helper );

          neighbor->InvalidateStep( 1 );
          neighbor->_len = 0;
          neighbor->SetNewLength( data._stepSize, helper );

          // goto the next neighbor
          prevEdge = neighbor;
          neighbor = nextEdge;
        }
      }
    }
    dumpFunctionEnd();
  }
  // 2) Check absence of intersections
  // TODO?

  for ( unsigned i = 0 ; i < tmpFaces.size(); ++i )
    delete tmpFaces[i];

  return true;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 492 of file StdMeshers_ViscousLayers.cxx.

Definition at line 495 of file StdMeshers_ViscousLayers.cxx.

SMESH_Mesh* VISCOUS::_ViscousBuilder::_mesh [private]

Definition at line 491 of file StdMeshers_ViscousLayers.cxx.

Definition at line 494 of file StdMeshers_ViscousLayers.cxx.

Definition at line 496 of file StdMeshers_ViscousLayers.cxx.


The documentation for this class was generated from the following file: