Salome HOME
typo-fix by Kunda
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_NETGEN_2D_ONLY.cxx
index 9d6d9868a091f3d677cb736dc907561d6d0574e2..5f2b88fc9a0c5b8804e5c248a086b72f48b37cca 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -67,6 +67,9 @@ namespace netgen {
   extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, MeshingParameters&, int, int);
 #else
   extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, int, int, char*);
+#endif
+#if defined(NETGEN_V5) && defined(WIN32)
+  DLL_HEADER 
 #endif
   extern MeshingParameters mparam;
   extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh);
@@ -112,7 +115,7 @@ NETGENPlugin_NETGEN_2D_ONLY::NETGENPlugin_NETGEN_2D_ONLY(int        hypId,
 
 NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY()
 {
-  MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY");
+  //MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY");
 }
 
 //=============================================================================
@@ -167,7 +170,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::CheckHypothesis (SMESH_Mesh&         aMesh,
 
   int nbHyps = bool(_hypMaxElementArea) + bool(_hypLengthFromEdges) + bool(_hypParameters );
   if ( nbHyps > 1 )
-    aStatus = HYP_CONCURENT;
+    aStatus = HYP_CONCURRENT;
   else if ( hasVL )
     error( StdMeshers_ViscousLayers2D::CheckHypothesis( aMesh, aShape, aStatus ));
   else
@@ -184,6 +187,42 @@ bool NETGENPlugin_NETGEN_2D_ONLY::CheckHypothesis (SMESH_Mesh&         aMesh,
   return ( aStatus == HYP_OK );
 }
 
+// namespace
+// {
+//   void limitSize( netgen::Mesh* ngMesh,
+//                   const double  maxh )
+//   {
+//     // get bnd box
+//     netgen::Point3d pmin, pmax;
+//     ngMesh->GetBox( pmin, pmax, 0 );
+//     const double dx = pmax.X() - pmin.X();
+//     const double dy = pmax.Y() - pmin.Y();
+//     const double dz = pmax.Z() - pmin.Z();
+
+//     const int nbX = Max( 2, int( dx / maxh * 3 ));
+//     const int nbY = Max( 2, int( dy / maxh * 3 ));
+//     const int nbZ = Max( 2, int( dz / maxh * 3 ));
+
+//     if ( ! & ngMesh->LocalHFunction() )
+//       ngMesh->SetLocalH( pmin, pmax, 0.1 );
+
+//     netgen::Point3d p;
+//     for ( int i = 0; i <= nbX; ++i )
+//     {
+//       p.X() = pmin.X() +  i * dx / nbX;
+//       for ( int j = 0; j <= nbY; ++j )
+//       {
+//         p.Y() = pmin.Y() +  j * dy / nbY;
+//         for ( int k = 0; k <= nbZ; ++k )
+//         {
+//           p.Z() = pmin.Z() +  k * dz / nbZ;
+//           ngMesh->RestrictLocalH( p, maxh );
+//         }
+//       }
+//     }
+//   }
+// }
+
 //=============================================================================
 /*!
  *Here we are going to use the NETGEN mesher
@@ -227,9 +266,11 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh&         aMesh,
   {
     netgen::mparam.maxh = sqrt( 2. * _hypMaxElementArea->GetMaxArea() / sqrt(3.0) );
   }
+  if ( _hypQuadranglePreference )
+    netgen::mparam.quad = true;
 
   // local size is common for all FACEs in aShape?
-  const bool isCommonLocalSize = ( !_hypLengthFromEdges && netgen::mparam.uselocalh );
+  const bool isCommonLocalSize = ( !_hypLengthFromEdges && !_hypMaxElementArea && netgen::mparam.uselocalh );
   const bool isDefaultHyp = ( !_hypLengthFromEdges && !_hypMaxElementArea && !_hypParameters );
 
   if ( isCommonLocalSize ) // compute common local size in ngMeshes[0]
@@ -241,7 +282,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh&         aMesh,
     // minh, face_maxh, grading and curvaturesafety; find minh if not set by the user
     if ( !_hypParameters || netgen::mparam.minh < DBL_MIN )
     {
-      if ( !_hypMaxElementArea )
+      if ( !_hypParameters )
         netgen::mparam.maxh = occgeoComm.GetBoundingBox().Diam() / 3.;
       netgen::mparam.minh = aMesher.GetDefaultMinSize( aShape, netgen::mparam.maxh );
     }
@@ -260,8 +301,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh&         aMesh,
     for ( int iE = 1; iE <= edgeMap.Extent(); ++iE )
     {
       const TopoDS_Shape& edge = edgeMap( iE );
-      if ( SMESH_Algo::isDegenerated( TopoDS::Edge( edge ))/* ||
-           helper.IsSubShape( edge, aShape )*/)
+      if ( SMESH_Algo::isDegenerated( TopoDS::Edge( edge )))
         continue;
       SMESHDS_SubMesh* smDS = meshDS->MeshElements( edge );
       if ( !smDS ) continue;
@@ -276,6 +316,15 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh&         aMesh,
         ngMeshes[0]->RestrictLocalH( pi, factor * ( n1 - n2 ).Modulus() );
       }
     }
+
+    // set local size defined on shapes
+    aMesher.SetLocalSize( occgeoComm, *ngMeshes[0] );
+    aMesher.SetLocalSizeForChordalError( occgeoComm, *ngMeshes[0] );
+    try {
+      ngMeshes[0]->LoadLocalMeshSize( mparam.meshsizefilename );
+    } catch (NgException & ex) {
+      return error( COMPERR_BAD_PARMETERS, ex.What() );
+    }
   }
   netgen::mparam.uselocalh = toOptimize; // restore as it is used at surface optimization
 
@@ -289,7 +338,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh&         aMesh,
   for ( int iF = 0; fExp.More(); fExp.Next(), ++iF )
   {
     TopoDS_Face F = TopoDS::Face( fExp.Current() /*.Oriented( TopAbs_FORWARD )*/);
-    int    faceID = meshDS->ShapeToIndex( aShape );
+    int    faceID = meshDS->ShapeToIndex( F );
     SMESH_ComputeErrorPtr& faceErr = aMesh.GetSubMesh( F )->GetComputeError();
 
     _quadraticMesh = helper.IsQuadraticSubMesh( F );
@@ -307,7 +356,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh&         aMesh,
     // get all EDGEs of a FACE
     // ------------------------
     TSideVector wires =
-      StdMeshers_FaceSide::GetFaceWires( F, aMesh, ignoreMediumNodes, faceErr, proxyMesh );
+      StdMeshers_FaceSide::GetFaceWires( F, aMesh, ignoreMediumNodes, faceErr, &helper, proxyMesh );
     if ( faceErr && !faceErr->IsOK() )
       continue;
     int nbWires = wires.size();
@@ -353,6 +402,8 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh&         aMesh,
         for ( int iW = 0; iW < nbWires; ++iW )
         {
           const UVPtStructVec& points = wires[ iW ]->GetUVPtStruct();
+          if ( points.empty() )
+            return error( COMPERR_BAD_INPUT_MESH );
           gp_Pnt pPrev = SMESH_TNodeXYZ( points[0].node );
           for ( size_t i = 1; i < points.size(); ++i )
           {
@@ -409,6 +460,13 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh&         aMesh,
         Box<3> bb = occgeom.GetBoundingBox();
         bb.Increase (bb.Diam()/10);
         ngMesh->SetLocalH (bb.PMin(), bb.PMax(), mparam.grading);
+        aMesher.SetLocalSize( occgeom, *ngMesh );
+        aMesher.SetLocalSizeForChordalError( occgeoComm, *ngMesh );
+        try {
+          ngMesh->LoadLocalMeshSize( mparam.meshsizefilename );
+        } catch (NgException & ex) {
+          return error( COMPERR_BAD_PARMETERS, ex.What() );
+        }
       }
 
       nodeVec.clear();
@@ -417,6 +475,9 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh&         aMesh,
       if ( faceErr && !faceErr->IsOK() )
         break;
 
+      //if ( !isCommonLocalSize )
+      //limitSize( ngMesh, mparam.maxh * 0.8);
+
       // -------------------------
       // Generate surface mesh
       // -------------------------
@@ -455,11 +516,13 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh&         aMesh,
       }
       if ( err )
       {
+        if ( aMesher.FixFaceMesh( occgeom, *ngMesh, 1 ))
+          break;
         if ( iLoop == LOC_SIZE )
         {
           netgen::mparam.minh = netgen::mparam.maxh;
           netgen::mparam.maxh = 0;
-          for ( int iW = 0; iW < wires.size(); ++iW )
+          for ( size_t iW = 0; iW < wires.size(); ++iW )
           {
             StdMeshers_FaceSidePtr wire = wires[ iW ];
             const vector<UVPtStruct>& uvPtVec = wire->GetUVPtStruct();
@@ -524,11 +587,10 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh&         aMesh,
         }
         if ( j > elem.GetNP() )
         {
-          SMDS_MeshFace* face = 0;
           if ( elem.GetType() == TRIG )
-            face = helper.AddFace(nodes[0],nodes[1],nodes[2]);
+            helper.AddFace(nodes[0],nodes[1],nodes[2]);
           else
-            face = helper.AddFace(nodes[0],nodes[1],nodes[2],nodes[3]);
+            helper.AddFace(nodes[0],nodes[1],nodes[2],nodes[3]);
         }
       }
 
@@ -623,7 +685,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Evaluate(SMESH_Mesh& aMesh,
 
   // compute edge length
   double ELen = 0;
-  if (_hypLengthFromEdges || !_hypLengthFromEdges && !_hypMaxElementArea) {
+  if (( _hypLengthFromEdges ) || ( !_hypLengthFromEdges && !_hypMaxElementArea )) {
     if ( nb1d > 0 )
       ELen = fullLen / nb1d;
   }