Salome HOME
Porting to MeshGems 2.10: additional correction to avoid crash
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.cxx
index 0300bdd4a5cc4381e8f987bbd7df6a55cd803701..b47c66e8c6a2bbc0112d5447d67cb82f22bd9b18 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
@@ -39,6 +39,8 @@
 #include CORBA_CLIENT_HEADER(SALOMEDS)
 #include CORBA_CLIENT_HEADER(GEOM_Gen)
 
+#include <meshgems/meshgems.h>
+
 namespace
 {
   struct GET_DEFAULT // struct used to get default value from GetOptionValue()
@@ -49,8 +51,8 @@ namespace
 }
 
 //=============================================================================
-BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen, bool hasgeom) :
-  SMESH_Hypothesis(hypId, studyId, gen), 
+BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, SMESH_Gen * gen, bool hasgeom) :
+  SMESH_Hypothesis(hypId, gen),
   _physicalMesh(GetDefaultPhysicalMesh()),
   _geometricMesh(GetDefaultGeometricMesh()),
   _phySize(GetDefaultPhySize()),
@@ -63,9 +65,9 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   _gradation(GetDefaultGradation()),
   _useVolumeGradation(GetDefaultUseVolumeGradation()),
   _volumeGradation(GetDefaultVolumeGradation()),
-  _quadAllowed(GetDefaultQuadAllowed()),
+  _elementType(GetDefaultElementType()),
   _angleMesh(GetDefaultAngleMesh()),
-  _chordalError(GetDefaultChordalError()), 
+  _chordalError(GetDefaultChordalError()),
   _anisotropic(GetDefaultAnisotropic()),
   _anisotropicRatio(GetDefaultAnisotropicRatio()),
   _removeTinyEdges(GetDefaultRemoveTinyEdges()),
@@ -80,6 +82,12 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   _quadraticMesh(GetDefaultQuadraticMesh()),
   _verb(GetDefaultVerbosity()),
   _topology(GetDefaultTopology()),
+  _useSurfaceProximity(GetDefaultUseSurfaceProximity()),
+  _nbSurfaceProximityLayers(GetDefaultNbSurfaceProximityLayers()),
+  _surfaceProximityRatio(GetDefaultSurfaceProximityRatio()),
+  _useVolumeProximity(GetDefaultUseVolumeProximity()),
+  _nbVolumeProximityLayers(GetDefaultNbVolumeProximityLayers()),
+  _volumeProximityRatio(GetDefaultVolumeProximityRatio()),
   _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
   _preCADRemoveDuplicateCADFaces(GetDefaultPreCADRemoveDuplicateCADFaces()),
   _preCADProcess3DTopology(GetDefaultPreCADProcess3DTopology()),
@@ -101,39 +109,35 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
 {
   _name = GetHypType(hasgeom);
   _param_algo_dim = 2;
-  
-//   _GMFFileMode = false; // GMF ascii mode
 
   // Advanced options with their defaults according to MG User Manual
 
-  const char* boolOptionNames[] = {         "enforce_cad_edge_sizes",                   // default = 0
-                                            // "correct_surface_intersections",            // default = 1
-                                            // "create_tag_on_collision",                  // default = 1
-                                            "jacobian_rectification_respect_geometry",  // default = 1
-                                            "rectify_jacobian",                         // default = 1
-                                            "respect_geometry",                         // default = 1
-                                            // "optimise_tiny_edges",                      // default = 0
-                                            // "remove_duplicate_cad_faces",               // default = 1
-                                            "tiny_edge_avoid_surface_intersections",    // default = 1
-                                            "debug",                                    // default = 0 
-                                            // "tiny_edge_respect_geometry",               // default = 0
-                                            "" // mark of end
-      };
+  const char* boolOptionNames[] = {
+    //"enforce_cad_edge_sizes",                 // default = 0 // Deprecated since MeshGems 2.10
+    "jacobian_rectification_respect_geometry",  // default = 1
+    "rectify_jacobian",                         // default = 1
+    "respect_geometry",                         // default = 1
+    "tiny_edge_avoid_surface_intersections",    // default = 1
+    "debug",                                    // default = 0
+    "allow_patch_independent",                   // false
+    "" // mark of end
+  };
 
-  const char* intOptionNames[] = {          "max_number_of_points_per_patch",           // default = 100000
-                                            "max_number_of_threads",                    // default = 4
-                                            "" // mark of end
-      };
+  const char* intOptionNames[] = {
+    //"max_number_of_points_per_patch",         // default = 100000 // Deprecated since MeshGems 2.10
+    "max_number_of_threads",                    // default = 4
+    "" // mark of end
+  };
   const char* doubleOptionNames[] = {       // "surface_intersections_processing_max_cost",// default = 15
                                             // "periodic_tolerance",                       // default = diag/100
                                             // "volume_gradation",
                                             // "tiny_edge_optimisation_length",            // default = diag * 1e-6
-                                            "" // mark of end
-      };
+    "" // mark of end
+  };
   const char* charOptionNames[] = {         // "required_entities",                        // default = "respect"
                                             // "tags",                                     // default = "respect"
-                                            "" // mark of end
-      };
+    "" // mark of end
+  };
 
   // PreCAD advanced options
   const char* preCADboolOptionNames[] = {   "closed_geometry",                          // default = 0
@@ -146,6 +150,7 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
                                             // remove_tiny_uv_edges option is not documented
                                             // but it is useful that the user can change it to disable all preprocessing options
                                             "remove_tiny_uv_edges",                        // default = 1
+                                            "compute_ridges",                             // true
                                             "" // mark of end
       };
   const char* preCADintOptionNames[] = {    // "manifold_geometry",                        // default = 0
@@ -204,14 +209,16 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
 
   // default values to be used while MG meshing
 
-  _defaultOptionValues["enforce_cad_edge_sizes"                 ] = "no";
+  // _defaultOptionValues["enforce_cad_edge_sizes"                 ] = "no";  // Deprecated since MeshGems 2.10
   _defaultOptionValues["jacobian_rectification_respect_geometry"] = "yes";
-  _defaultOptionValues["max_number_of_points_per_patch"         ] = "0";
+  // _defaultOptionValues["max_number_of_points_per_patch"         ] = "0";   // Deprecated since MeshGems 2.10
   _defaultOptionValues["max_number_of_threads"                  ] = "4";
   _defaultOptionValues["rectify_jacobian"                       ] = "yes";
   _defaultOptionValues["respect_geometry"                       ] = "yes";
   _defaultOptionValues["tiny_edge_avoid_surface_intersections"  ] = "yes";
+  //_defaultOptionValues["use_deprecated_patch_mesher"          ] = "no";
   _defaultOptionValues["debug"                                  ] = "no";
+  _defaultOptionValues["allow_patch_independent"                ] = "no";
   if ( hasgeom )
   {
     _defaultOptionValues["closed_geometry"                        ] = "no";
@@ -224,6 +231,15 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
     _defaultOptionValues["required_entities"                      ] = "respect";
     _defaultOptionValues["sewing_tolerance"                       ] = "5e-4*D";
     _defaultOptionValues["tags"                                   ] = "respect";
+    _defaultOptionValues["compute_ridges"                         ] = "yes";
+  }
+
+  if ( strcmp( MESHGEMS_VERSION_LONG, "2.9-6" ) < 0 )
+  {
+    std::string missingOption = "allow_patch_independent";
+    _defaultOptionValues.erase( missingOption );
+    _boolOptions.erase( missingOption );
+    _option2value.erase( missingOption );
   }
 
 #ifdef _DEBUG_
@@ -234,37 +250,21 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   ASSERT( _option2value.size() + _preCADoption2value.size() == _defaultOptionValues.size() );
 #endif
 
-  _sizeMap.clear();
-  _attractors.clear();
-  _faceEntryEnfVertexListMap.clear();
-  _enfVertexList.clear();
-  _faceEntryCoordsListMap.clear();
-  _coordsEnfVertexMap.clear();
-  _faceEntryEnfVertexEntryListMap.clear();
-  _enfVertexEntryEnfVertexMap.clear();
-  _groupNameNodeIDMap.clear();
-
-  /* TODO GROUPS
-   _groupNameEnfVertexListMap.clear();
-   _enfVertexGroupNameMap.clear();
-   */
 }
 
 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
 {
   GEOM::GEOM_Object_var aGeomObj;
-  SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
-  SALOMEDS::Study_ptr myStudy = smeshGen_i->GetCurrentStudy();
   
   TopoDS_Shape S = TopoDS_Shape();
-  SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
+  SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( entry.c_str() );
   if (!aSObj->_is_nil() ) {
     CORBA::Object_var obj = aSObj->GetObject();
     aGeomObj = GEOM::GEOM_Object::_narrow(obj);
     aSObj->UnRegister();
   }
   if ( !aGeomObj->_is_nil() )
-    S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
+    S = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aGeomObj.in() );
   return S;
 }
 
@@ -357,9 +357,9 @@ void BLSURFPlugin_Hypothesis::SetVolumeGradation(double theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal) {
-  if (theVal != _quadAllowed) {
-    _quadAllowed = theVal;
+void BLSURFPlugin_Hypothesis::SetElementType(ElementType theElementType) {
+  if (theElementType != _elementType) {
+    _elementType = theElementType;
     NotifySubMeshesHypothesisModification();
   }
 }
@@ -484,6 +484,66 @@ void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
   }
 }
 
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetUseSurfaceProximity( bool toUse )
+{
+  if ( _useSurfaceProximity != toUse )
+  {
+    _useSurfaceProximity = toUse;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetNbSurfaceProximityLayers( int nbLayers )
+{
+  if ( _nbSurfaceProximityLayers != nbLayers )
+  {
+    _nbSurfaceProximityLayers = nbLayers;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetSurfaceProximityRatio( double ratio )
+{
+  if ( _surfaceProximityRatio != ratio )
+  {
+    _surfaceProximityRatio = ratio;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetUseVolumeProximity( bool toUse )
+{
+  if ( _useVolumeProximity != toUse )
+  {
+    _useVolumeProximity = toUse;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetNbVolumeProximityLayers( int nbLayers )
+{
+  if ( _nbVolumeProximityLayers != nbLayers )
+  {
+    _nbVolumeProximityLayers = nbLayers;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetVolumeProximityRatio( double ratio )
+{
+  if ( _volumeProximityRatio != ratio )
+  {
+    _volumeProximityRatio = ratio;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
 //=============================================================================
 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
   if (theVal != _verb) {
@@ -495,16 +555,21 @@ void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
 //=============================================================================
 void BLSURFPlugin_Hypothesis::SetEnforceCadEdgesSize( bool toEnforce )
 {
+  /* Deprecated since MeshGems 2.10
   if ( GetEnforceCadEdgesSize() != toEnforce )
   {
     SetOptionValue( "enforce_cad_edge_sizes", toEnforce ? "yes" : "no" );
     NotifySubMeshesHypothesisModification();
   }
+  */
 }
 //=============================================================================
 bool BLSURFPlugin_Hypothesis::GetEnforceCadEdgesSize()
 {
+  /* Deprecated since MeshGems 2.10
   return ToBool( GetOptionValue( "enforce_cad_edge_sizes" ), GET_DEFAULT() );
+ */
+  return false;
 }
 //=============================================================================
 
@@ -538,9 +603,25 @@ bool BLSURFPlugin_Hypothesis::GetJacobianRectification()
 }
 //=============================================================================
 
+void BLSURFPlugin_Hypothesis::SetUseDeprecatedPatchMesher( bool useDeprecatedPatchMesher )
+{
+  // if ( GetUseDeprecatedPatchMesher() != useDeprecatedPatchMesher )
+  // {
+  //   SetOptionValue( "use_deprecated_patch_mesher", useDeprecatedPatchMesher ? "yes" : "no" );
+  //   NotifySubMeshesHypothesisModification();
+  // }
+}
+//=============================================================================
+bool BLSURFPlugin_Hypothesis::GetUseDeprecatedPatchMesher()
+{
+  return false;//ToBool( GetOptionValue("use_deprecated_patch_mesher", GET_DEFAULT()));
+}
+//=============================================================================
+
 void BLSURFPlugin_Hypothesis::SetMaxNumberOfPointsPerPatch( int nb )
   throw (std::invalid_argument)
 {
+  /* Deprecated since MeshGems 2.10
   if ( nb < 0 )
     throw std::invalid_argument( SMESH_Comment("Invalid number of points: ") << nb );
 
@@ -549,11 +630,15 @@ void BLSURFPlugin_Hypothesis::SetMaxNumberOfPointsPerPatch( int nb )
     SetOptionValue("max_number_of_points_per_patch", SMESH_Comment( nb ));
     NotifySubMeshesHypothesisModification();
   }
+  */
 }
 //=============================================================================
 int BLSURFPlugin_Hypothesis::GetMaxNumberOfPointsPerPatch()
 {
+  /* Deprecated since MeshGems 2.10
   return ToInt( GetOptionValue("max_number_of_points_per_patch", GET_DEFAULT()));
+  */
+  return 0;
 }
 //=============================================================================
 
@@ -1428,16 +1513,10 @@ bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry        theFaceEntry,
 //   //////// CREATE ////////////
   if (toCreate) {
     toNotify = true;
-    _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
-    _enfVertexList.insert(newEnfVertex);
-    if (theVertexEntry == "") {
-      _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
-      _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
-    }
-    else {
-      _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
-      _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
-    }
+    AddEnforcedVertex( theFaceEntry, newEnfVertex );
+  }
+  else {
+    delete newEnfVertex;
   }
 
   if (toNotify)
@@ -1446,6 +1525,27 @@ bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry        theFaceEntry,
   return toNotify;
 }
 
+//=======================================================================
+//function : AddEnforcedVertex
+//=======================================================================
+
+void BLSURFPlugin_Hypothesis::AddEnforcedVertex( const TEntry& faceEntry,
+                                                 TEnfVertex *  newEnfVertex )
+{
+  if ( newEnfVertex )
+  {
+    _faceEntryEnfVertexListMap[faceEntry].insert(newEnfVertex);
+    _enfVertexList.insert(newEnfVertex);
+    if ( newEnfVertex->geomEntry.empty() ) {
+      _faceEntryCoordsListMap[faceEntry].insert(newEnfVertex->coords);
+      _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
+    }
+    else {
+      _faceEntryEnfVertexEntryListMap[faceEntry].insert(newEnfVertex->geomEntry);
+      _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
+    }
+  }
+}
 
 //=======================================================================
 //function : GetEnforcedVertices
@@ -1690,18 +1790,25 @@ bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry)
 //=======================================================================
 //function : ClearAllEnforcedVertices
 //=======================================================================
-void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
+void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices()
+{
   _faceEntryEnfVertexListMap.clear();
-  _enfVertexList.clear();
   _faceEntryCoordsListMap.clear();
   _coordsEnfVertexMap.clear();
   _faceEntryEnfVertexEntryListMap.clear();
   _enfVertexEntryEnfVertexMap.clear();
+  
+  TEnfVertexList::iterator it_enfVertex = _enfVertexList.begin();
+  for ( ; it_enfVertex != _enfVertexList.end(); ++it_enfVertex )
+    delete *it_enfVertex;
+  _enfVertexList.clear();
+
 //  Enable internal enforced vertices on specific face if requested by user
 //  _faceEntryInternalVerticesList.clear();
   NotifySubMeshesHypothesisModification();
 }
 
+
 //================================================================================
 /*!
  * \brief Return the enforced vertices
@@ -1912,7 +2019,7 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
   }
 
   save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
-       << _angleMesh << " " << _gradation << " " << (int) _quadAllowed << " " << _decimesh;
+       << _angleMesh << " " << _gradation << " " << (int) _elementType << " " << _decimesh;
   save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
   save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
   save << " " << (int) _enforcedInternalVerticesAllFaces;
@@ -2059,6 +2166,14 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
       save << *tag << " ";
   }
 
+  // New options in 2.9.6 (issue #17784)
+  save << " " << _useSurfaceProximity;
+  save << " " << _nbSurfaceProximityLayers;
+  save << " " << _surfaceProximityRatio;
+  save << " " << _useVolumeProximity;
+  save << " " << _nbVolumeProximityLayers;
+  save << " " << _volumeProximityRatio;
+
   return save;
 }
 
@@ -2239,7 +2354,7 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
 
   isOK = static_cast<bool>(load >> i);
   if (isOK)
-    _quadAllowed = (bool) i;
+    _elementType = (ElementType) i;
   else
     load.clear(std::ios::badbit | load.rdstate());
 
@@ -2546,7 +2661,9 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
         break;
       isOK = static_cast<bool>(load >> optValue);
     }
-    if (isOK) {
+    // read the value of the advanced option
+    // unless this option is no more used
+    if (isOK && optName != "enforce_cad_edge_sizes" && optName != "max_number_of_points_per_patch") {
       std::string & value = _option2value[optName];
       value = optValue;
       int len = value.size();
@@ -2805,7 +2922,7 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
         break;
       isOK = static_cast<bool>(load >> newAtShapeEntry);
       if (!isOK)
-    break;
+        break;
       isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
     }
     if (isOK) {
@@ -2965,6 +3082,22 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
     }
   }
 
+  if ( hasEnforcedVertex ) {
+    isOK = static_cast<bool>(load >> option_or_sm);
+    if (isOK) {
+      if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
+        hasPreCADFacesPeriodicity = true;
+      else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
+        hasPreCADEdgesPeriodicity = true;
+      else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
+        hasFacesPeriodicity = true;
+      else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
+        hasEdgesPeriodicity = true;
+      else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
+        hasVerticesPeriodicity = true;
+    }
+  }
+
   // PERIODICITY
 
   if (hasPreCADFacesPeriodicity)
@@ -3056,6 +3189,16 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
     }
   }
 
+  // New options in 2.9.6 (issue #17784)
+  if ( static_cast<bool>( load >> _useSurfaceProximity ));
+  {
+    load >> _nbSurfaceProximityLayers;
+    load >> _surfaceProximityRatio;
+    load >> _useVolumeProximity;
+    load >> _nbVolumeProximityLayers;
+    isOK = static_cast<bool>( load >> _volumeProximityRatio );
+  }
+
   return load;
 }
 
@@ -3439,14 +3582,29 @@ double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diag
  */
 //=============================================================================
 
-bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
-  double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
-  _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
-  _minSize = GetDefaultMinSize(diagonal);
-  _maxSize = GetDefaultMaxSize(diagonal);
+bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  dflts,
+                                                      const SMESH_Mesh* theMesh)
+{
+  _phySize = GetDefaultPhySize(dflts._diagonal, _gen->GetBoundaryBoxSegmentation());
+  _minSize = GetDefaultMinSize(dflts._diagonal);
+  _maxSize = GetDefaultMaxSize(dflts._diagonal);
   _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
-  _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
-  _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
+
+  if ( dflts._way == SMESH_Hypothesis::BY_AVERAGE_LENGTH )
+  {
+    _phySize      = dflts._elemLength;
+    _minSize      = dflts._elemLength / 100.;
+    _maxSize      = dflts._elemLength * 2.;
+    _chordalError = dflts._elemLength / 2.;
+    _elementType  = dflts._quadDominated ? Quadrangles : Triangles;
+    _physicalMesh = PhysicalLocalSize; // to activate _enforcedInternalVerticesAllFaces
+    _enforcedInternalVerticesAllFaces = true;
+  }
+  else
+  {
+    _tinyEdgeLength = GetDefaultTinyEdgeLength(dflts._diagonal);
+    _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(dflts._diagonal);
+  }
 
   return true;
 }