Salome HOME
Update copyrights
[plugins/hybridplugin.git] / src / HYBRIDPlugin / HYBRIDPlugin_Hypothesis.cxx
index 4d2f0222ed6e0c5795bc338d27147059c8ff22db..fb18c5958dd3c3e15b98ce24448c8a6f99a3f5b5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -38,8 +38,8 @@
 //function : HYBRIDPlugin_Hypothesis
 //=======================================================================
 
-HYBRIDPlugin_Hypothesis::HYBRIDPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen)
-  : SMESH_Hypothesis(hypId, studyId, gen),
+HYBRIDPlugin_Hypothesis::HYBRIDPlugin_Hypothesis(int hypId, SMESH_Gen * gen)
+  : SMESH_Hypothesis(hypId, gen),
   myToMeshHoles(DefaultMeshHoles()),
   myLayersOnAllWrap(DefaultLayersOnAllWrap()),
   myToMakeGroupsOfDomains(DefaultToMakeGroupsOfDomains()),
@@ -62,6 +62,7 @@ HYBRIDPlugin_Hypothesis::HYBRIDPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   mySmoothNormals(DefaultSmoothNormals()),
   myHeightFirstLayer(DefaultHeightFirstLayer()),
   myBoundaryLayersProgression(DefaultBoundaryLayersProgression()),
+  myCoreSize(DefaultCoreSize()),
   myMultinormalsAngle(DefaultMultinormalsAngle()),
   myNbOfBoundaryLayers(DefaultNbOfBoundaryLayers()),
   _enfVertexList(DefaultHYBRIDEnforcedVertexList()),
@@ -128,6 +129,58 @@ const std::vector<int>& HYBRIDPlugin_Hypothesis::GetFacesWithLayers() const
   return myFacesWithLayers;
 }
 
+//=======================================================================
+//function : SetFacesWithImprinting
+//purpose  : Set IDs of faces to grow the layers on
+//=======================================================================
+
+bool HYBRIDPlugin_Hypothesis::SetFacesWithImprinting(const std::vector<int>& theVal)
+{
+  if ( myFacesWithImprinting != theVal )
+  {
+    myFacesWithImprinting = theVal;
+    NotifySubMeshesHypothesisModification();
+    return true;
+  }
+  return false;
+}
+
+//=======================================================================
+//function : GetFacesWithImprinting
+//purpose  : Return IDs of faces to grow the layers on
+//=======================================================================
+
+const std::vector<int>& HYBRIDPlugin_Hypothesis::GetFacesWithImprinting() const
+{
+  return myFacesWithImprinting;
+}
+
+//=======================================================================
+//function : SetFacesWithSnapping
+//purpose  : Set IDs of faces that already have surface layers
+//=======================================================================
+
+bool HYBRIDPlugin_Hypothesis::SetFacesWithSnapping(const std::vector<int>& theVal)
+{
+  if ( myFacesWithSnapping != theVal )
+  {
+    myFacesWithSnapping = theVal;
+    NotifySubMeshesHypothesisModification();
+    return true;
+  }
+  return false;
+}
+
+//=======================================================================
+//function : GetFacesWithSnapping
+//purpose  : Return IDs of faces that already have surface layers
+//=======================================================================
+
+const std::vector<int>& HYBRIDPlugin_Hypothesis::GetFacesWithSnapping() const
+{
+  return myFacesWithSnapping;
+}
+
 //=======================================================================
 //function : SetToMeshHoles
 //=======================================================================
@@ -391,6 +444,27 @@ double HYBRIDPlugin_Hypothesis::GetBoundaryLayersProgression() const
   return myBoundaryLayersProgression;
 }
 
+//=======================================================================
+//function : SetCoreSize
+//=======================================================================
+
+void HYBRIDPlugin_Hypothesis::SetCoreSize(double toCoreSize)
+{
+  if ( myCoreSize != toCoreSize ) {
+    myCoreSize = toCoreSize;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : GetCoreSize
+//=======================================================================
+
+double HYBRIDPlugin_Hypothesis::GetCoreSize() const
+{
+  return myCoreSize;
+}
+
 //=======================================================================
 //function : SetMultinormalsAngle
 //=======================================================================
@@ -425,7 +499,7 @@ void HYBRIDPlugin_Hypothesis::SetNbOfBoundaryLayers(short toNbOfBoundaryLayers)
 }
 
 //=======================================================================
-//function : GetMultinormalsAngle
+//function : GetCoreSize
 //=======================================================================
 
 short HYBRIDPlugin_Hypothesis::GetNbOfBoundaryLayers() const
@@ -858,14 +932,6 @@ bool HYBRIDPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, S
           elemRet = _enfEdges.insert(make_pair(elem,groupName));
           added = added && elemRet.second;
         }
-        else if (elem->GetType() > SMDSAbs_Edge) {
-          SMDS_ElemIteratorPtr it = elem->edgesIterator();
-          for (;it->more();) {
-            const SMDS_MeshElement* anEdge = it->next();
-            elemRet = _enfEdges.insert(make_pair(anEdge,groupName));
-            added = added && elemRet.second;
-          }
-        }
         break;
       case SMESH::FACE:
         if (elem->GetType() == SMDSAbs_Face)
@@ -875,16 +941,6 @@ bool HYBRIDPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, S
             added = added && elemRet.second;
           }
         }
-        else if (elem->GetType() > SMDSAbs_Face) { // Group of faces
-          SMDS_ElemIteratorPtr it = elem->facesIterator();
-          for (;it->more();) {
-            const SMDS_MeshElement* aFace = it->next();
-            if (aFace->NbCornerNodes() == 3) {
-              elemRet = _enfTriangles.insert(make_pair(aFace,groupName));
-              added = added && elemRet.second;
-            }
-          }
-        }
         break;
       default:
         break;
@@ -1293,6 +1349,14 @@ double HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersProgression()
   return 1.0;
 }
 
+//=======================================================================
+//function : DefaultCoreSize
+//=======================================================================
+double HYBRIDPlugin_Hypothesis::DefaultCoreSize()
+{
+  return 0.0;
+}
+
 //=======================================================================
 //function : DefaultMultinormalsAngle
 //=======================================================================
@@ -1329,6 +1393,8 @@ std::ostream & HYBRIDPlugin_Hypothesis::SaveTo(std::ostream & save)
   save << (int) myKeepFiles << " ";
   save << myWorkingDirectory << " ";
   save << myVerboseLevel << " ";
+  save << myCoreSize << " ";
+
   if (!myTextOption.empty()) {
     save << "__OPTIONS_BEGIN__ ";
     save << myTextOption << " ";
@@ -1408,6 +1474,14 @@ std::ostream & HYBRIDPlugin_Hypothesis::SaveTo(std::ostream & save)
   for ( size_t i = 0; i < myFacesWithLayers.size(); ++i )
     save << " " << myFacesWithLayers[i];
 
+  save << " " << myFacesWithImprinting.size();
+  for ( size_t i = 0; i < myFacesWithImprinting.size(); ++i )
+    save << " " << myFacesWithImprinting[i];
+
+  save << " " << myFacesWithSnapping.size();
+  for ( size_t i = 0; i < myFacesWithSnapping.size(); ++i )
+    save << " " << myFacesWithSnapping[i];
+
   return save;
 }
 
@@ -1501,6 +1575,11 @@ std::istream & HYBRIDPlugin_Hypothesis::LoadFrom(std::istream & load)
   else
     load.clear(ios::badbit | load.rdstate());
 
+  isOK = static_cast<bool>(load >> d);
+  if (isOK)
+    myCoreSize = d;
+  else
+    load.clear(ios::badbit | load.rdstate());
 
   std::string separator;
   bool hasOptions = false;
@@ -1733,6 +1812,35 @@ std::istream & HYBRIDPlugin_Hypothesis::LoadFrom(std::istream & load)
         myFacesWithLayers.push_back( i );
     }
   }
+
+  isOK = static_cast<bool>(load >> separator);
+  if ( isOK )
+  {
+    i = atoi( separator.c_str() );
+    isOK = ( i >= 0 );
+    if ( isOK )
+    {
+      myFacesWithImprinting.reserve( i );
+      while (( myFacesWithImprinting.size() < myFacesWithImprinting.capacity() ) &&
+             ( isOK = static_cast<bool>(load >> i)) )
+        myFacesWithImprinting.push_back( i );
+    }
+  }
+
+  isOK = static_cast<bool>(load >> separator);
+  if ( isOK )
+  {
+    i = atoi( separator.c_str() );
+    isOK = ( i >= 0 );
+    if ( isOK )
+    {
+      myFacesWithSnapping.reserve( i );
+      while (( myFacesWithSnapping.size() < myFacesWithSnapping.capacity() ) &&
+             ( isOK = static_cast<bool>(load >> i)) )
+        myFacesWithSnapping.push_back( i );
+    }
+  }
+
   return load;
 }
 
@@ -1784,13 +1892,11 @@ std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis*
   bool p_eg    = ( hyp && hyp->myTextOption.find("--element_generation ") != std::string::npos );
   bool p_cm    = ( hyp && hyp->myTextOption.find("--collision_mode ") != std::string::npos );
   bool p_am    = ( hyp && hyp->myTextOption.find("--add_multinormals ") != std::string::npos );
+  bool p_cs    = ( hyp && hyp->myTextOption.find("--global_physical_size ") != std::string::npos );
   bool p_mat   = ( hyp && hyp->myTextOption.find("--multinormal_angle_threshold ") != std::string::npos );
   bool p_sn    = ( hyp && hyp->myTextOption.find("--smooth_normals ") != std::string::npos );
 
   //missing options :
-  //- global_physical_size
-  //- boundary_layer_size_mode
-  //- boundary_layer_initial_height_on_surface_tags
   //- boundary_layer_max_element_angle
 
   bool nolayers = false;
@@ -1842,32 +1948,49 @@ std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis*
   if ( !nolayers && hyp )
   {
     cmd << " --boundary_layer_size_mode " << ( layersOnAllWrap ? "global" : "local" );
-    cmd << " --boundary_layer_surface_tags ";
-    if ( layersOnAllWrap )
-    {
-      cmd << " 3 ";
-    }
-    else
+    
+    if ( !layersOnAllWrap )
     {
-      const std::vector<int>& faceIDs = hyp->GetFacesWithLayers();
-      const bool      hasEnforcedTria = !HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(hyp).empty();
-      for ( size_t i = 0; i < faceIDs.size(); ++i )
-        cmd << faceIDs[i] << ",";
-      if ( hasEnforcedTria )
-        cmd << EnforcedTag();
-      cmd << " --boundary_layer_initial_height_on_surface_tags ";
-      for ( size_t i = 0; i < faceIDs.size() + hasEnforcedTria; ++i )
+      // faces with layers
+      const std::vector<int>& faceLayersIDs = hyp->GetFacesWithLayers();
+      if ( !faceLayersIDs.empty() )
+        cmd << " --boundary_layer_surface_tags ";
+      for ( size_t i = 0; i < faceLayersIDs.size(); ++i )
+        cmd << faceLayersIDs[i] << ",";
+      if ( !faceLayersIDs.empty() )
+        cmd << " --boundary_layer_initial_height_on_surface_tags ";
+      for ( size_t i = 0; i < faceLayersIDs.size(); ++i )
         cmd << hyp->myHeightFirstLayer << ",";
+
+      // faces with imprinting
+      const std::vector<int>& faceImprintingIDs = hyp->GetFacesWithImprinting();
+      if ( !faceImprintingIDs.empty() )
+        cmd << " --boundary_layer_imprinting yes --boundary_layer_imprinting_tags ";
+      for ( size_t i = 0; i < faceImprintingIDs.size(); ++i )
+        cmd << faceImprintingIDs[i] << ",";
+
+      // faces with snapping
+      const std::vector<int>& faceSnappingIDs = hyp->GetFacesWithSnapping();
+      if ( !faceSnappingIDs.empty() )
+        cmd << " --boundary_layer_snapping yes --boundary_layer_snapping_tags ";
+      for ( size_t i = 0; i < faceSnappingIDs.size(); ++i )
+        cmd << faceSnappingIDs[i] << ",";
     }
   }
 
   if ( !p_eg && hyp ) {
-    if ( hyp->myElementGeneration >= 0 && hyp->myElementGeneration <= 1 ) {
-      const char* value[] = { "tetra-dominant" , "hexa-dominant" };
+    if ( hyp->myElementGeneration >= 0 && hyp->myElementGeneration <= 2 ) {
+      const char* value[] = { "tetra-dominant" , "hexa-dominant", "cartesian_core" };
       cmd << " --element_generation " << value[ hyp->myElementGeneration ];
     }
   }
-  
+
+  if ( !p_cs && hyp ) {
+    if ( hyp->myCoreSize >= 0 ) {
+      cmd << " --global_physical_size " << hyp->myCoreSize;
+    }
+  }
+
   if ( !p_cm && hyp ) {
     if ( hyp->myCollisionMode >= 0 && hyp->myCollisionMode <= 1 ) {
       const char* value[] = { "decrease" , "stop" };
@@ -1890,7 +2013,11 @@ std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis*
     const char* value[] = { "yes" , "no" };
     cmd << " --smooth_normals " << value[ res ];
   }
-  
+
+  // options as text
+  if ( hyp && !hyp->myTextOption.empty() ) {
+    cmd += " " + hyp->myTextOption;
+  }
 #ifdef WIN32
   cmd << " < NUL";
 #endif