Salome HOME
IPAL53863: MG-CADSurf + Viscous Layers 2D on a cylindrical face ==> crash
[modules/smesh.git] / src / StdMeshers / StdMeshers_ViscousLayers2D.cxx
index 585bcaf7164c2181e35fecb80b4cf8ca08f94f87..2de6e474c556a93f01fa94c5d496232c637a5a60 100644 (file)
@@ -30,6 +30,7 @@
 #include "SMDS_SetIterator.hxx"
 #include "SMESHDS_Group.hxx"
 #include "SMESHDS_Hypothesis.hxx"
+#include "SMESHDS_Mesh.hxx"
 #include "SMESH_Algo.hxx"
 #include "SMESH_ComputeError.hxx"
 #include "SMESH_ControlsDef.hxx"
@@ -113,6 +114,7 @@ namespace VISCOUS_2D
       //virtual int NbElements() const { return _elements.size()+1; }
       virtual int NbNodes() const { return Max( 0, _uvPtStructVec.size()-2 ); }
       void SetUVPtStructVec(UVPtStructVec& vec) { _uvPtStructVec.swap( vec ); }
+      UVPtStructVec& GetUVPtStructVec() { return _uvPtStructVec; }
     };
     _ProxyMeshOfFace(const SMESH_Mesh& mesh): SMESH_ProxyMesh(mesh) {}
     _EdgeSubMesh* GetEdgeSubMesh(int ID) { return (_EdgeSubMesh*) getProxySubMesh(ID); }
@@ -299,6 +301,8 @@ namespace VISCOUS_2D
     double   _D;               // _vec1.Crossed( _vec2 )
     double   _param1, _param2; // intersection param on _seg1 and _seg2
 
+    _SegmentIntersection(): _D(0), _param1(0), _param2(0) {}
+
     bool Compute(const _Segment& seg1, const _Segment& seg2, bool seg2IsRay = false )
     {
       // !!! If seg2IsRay, returns true at any _param2 !!!
@@ -515,29 +519,53 @@ SMESH_ProxyMesh::Ptr
 StdMeshers_ViscousLayers2D::Compute(SMESH_Mesh&        theMesh,
                                     const TopoDS_Face& theFace)
 {
-  SMESH_ProxyMesh::Ptr pm;
-
+  using namespace VISCOUS_2D;
   vector< const StdMeshers_ViscousLayers2D* > hyps;
   vector< TopoDS_Shape >                      hypShapes;
-  if ( VISCOUS_2D::findHyps( theMesh, theFace, hyps, hypShapes ))
+
+  SMESH_ProxyMesh::Ptr pm = _ProxyMeshHolder::FindProxyMeshOfFace( theFace, theMesh );
+  if ( !pm )
   {
-    VISCOUS_2D::_ViscousBuilder2D builder( theMesh, theFace, hyps, hypShapes );
-    pm = builder.Compute();
-    SMESH_ComputeErrorPtr error = builder.GetError();
-    if ( error && !error->IsOK() )
-      theMesh.GetSubMesh( theFace )->GetComputeError() = error;
-    else if ( !pm )
+    if ( findHyps( theMesh, theFace, hyps, hypShapes ))
+    {
+      VISCOUS_2D::_ViscousBuilder2D builder( theMesh, theFace, hyps, hypShapes );
+      pm = builder.Compute();
+      SMESH_ComputeErrorPtr error = builder.GetError();
+      if ( error && !error->IsOK() )
+        theMesh.GetSubMesh( theFace )->GetComputeError() = error;
+      else if ( !pm )
+        pm.reset( new SMESH_ProxyMesh( theMesh ));
+      if ( getenv("__ONLY__VL2D__"))
+        pm.reset();
+    }
+    else
+    {
       pm.reset( new SMESH_ProxyMesh( theMesh ));
-    if ( getenv("__ONLY__VL2D__"))
-      pm.reset();
-  }
-  else
-  {
-    pm.reset( new SMESH_ProxyMesh( theMesh ));
+    }
   }
   return pm;
 }
 // --------------------------------------------------------------------------------
+void StdMeshers_ViscousLayers2D::SetProxyMeshOfEdge( const StdMeshers_FaceSide& edgeNodes )
+{
+  using namespace VISCOUS_2D;
+  SMESH_ProxyMesh::Ptr pm =
+    _ProxyMeshHolder::FindProxyMeshOfFace( edgeNodes.Face(), *edgeNodes.GetMesh() );
+  if ( !pm ) {
+    _ProxyMeshOfFace* proxyMeshOfFace = new _ProxyMeshOfFace( *edgeNodes.GetMesh() );
+    pm.reset( proxyMeshOfFace );
+    new _ProxyMeshHolder( edgeNodes.Face(), pm );
+  }
+  _ProxyMeshOfFace*  proxyMeshOfFace = static_cast<_ProxyMeshOfFace*>( pm.get() );
+  _ProxyMeshOfFace::_EdgeSubMesh* sm = proxyMeshOfFace->GetEdgeSubMesh( edgeNodes.EdgeID(0) );
+  sm->GetUVPtStructVec() = edgeNodes.GetUVPtStruct();
+}
+// --------------------------------------------------------------------------------
+bool StdMeshers_ViscousLayers2D::HasProxyMesh( const TopoDS_Face& face, SMESH_Mesh& mesh )
+{
+  return VISCOUS_2D::_ProxyMeshHolder::FindProxyMeshOfFace( face, mesh ).get();
+}
+// --------------------------------------------------------------------------------
 SMESH_ComputeErrorPtr
 StdMeshers_ViscousLayers2D::CheckHypothesis(SMESH_Mesh&                          theMesh,
                                             const TopoDS_Shape&                  theShape,
@@ -1716,11 +1744,13 @@ bool _ViscousBuilder2D::shrink()
         }
       } // loop on FACEs sharing E
 
+    // Check if L is an already shrinked seam
+    if ( adjFace.IsNull() && _helper.IsRealSeam( edgeID ))
+      if ( L._wire->Edge( L._edgeInd ).Orientation() == TopAbs_FORWARD )
+        continue;
     // Commented as a case with a seam EDGE (issue 0052461) is hard to support
     // because SMESH_ProxyMesh can't hold different sub-meshes for two
     // 2D representations of the seam. But such a case is not a real practice one.
-    // Check if L is an already shrinked seam
-    // if ( adjFace.IsNull() && _helper.IsRealSeam( edgeID ))
     // {
     //   for ( int iL2 = iL1-1; iL2 > -1; --iL2 )
     //   {
@@ -1794,7 +1824,7 @@ bool _ViscousBuilder2D::shrink()
     //  x-x-x-x-----x-----x----
     //  | | | |  e1    e2    e3
 
-    int isRShrinkedForAdjacent;
+    int isRShrinkedForAdjacent = 0;
     UVPtStructVec nodeDataForAdjacent;
     for ( int isR = 0; isR < 2; ++isR )
     {
@@ -2410,6 +2440,19 @@ bool _ViscousBuilder2D::refine()
     nodeDataVec.front().param = L._wire->FirstU( L._edgeInd );
     nodeDataVec.back() .param = L._wire->LastU ( L._edgeInd );
 
+    if (( nodeDataVec[0].node == nodeDataVec.back().node ) &&
+        ( _helper.GetPeriodicIndex() == 1 || _helper.GetPeriodicIndex() == 2 )) // closed EDGE
+    {
+      const int iCoord = _helper.GetPeriodicIndex();
+      gp_XY uv = nodeDataVec[0].UV();
+      uv.SetCoord( iCoord, L._lEdges[0]._uvOut.Coord( iCoord ));
+      nodeDataVec[0].SetUV( uv );
+
+      uv = nodeDataVec.back().UV();
+      uv.SetCoord( iCoord, L._lEdges.back()._uvOut.Coord( iCoord ));
+      nodeDataVec.back().SetUV( uv );
+    }
+
     _ProxyMeshOfFace::_EdgeSubMesh* edgeSM
       = getProxyMesh()->GetEdgeSubMesh( L._wire->EdgeID( L._edgeInd ));
     edgeSM->SetUVPtStructVec( nodeDataVec );