Salome HOME
IPAL21957: Max Element Area does not influence on resulting mesh for Triangle Mefisto
[modules/smesh.git] / src / StdMeshers / StdMeshers_Quadrangle_2D.cxx
index 3e917210f6b81a14ccb6e42be3fb4ff4d24c26ff..3589a7870609db0a94ccff51a622ac9595b32ff5 100644 (file)
@@ -1,23 +1,24 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 
 //  File   : StdMeshers_Quadrangle_2D.cxx
 //  Author : Paul RASCLE, EDF
@@ -2217,9 +2218,9 @@ bool StdMeshers_Quadrangle_2D::ComputeReduced (SMESH_Mesh &        aMesh,
     int nrows = nr1 - 1;
     int ncol_top = nt1 - 1;
     int ncol_bot = nb1 - 1;
-    // maximum number of bottom elements for "tree" simple reduce 3->1
-    int max_tree31 = ncol_top * pow(3.0, nrows);
-    if (ncol_bot > max_tree31)
+    // number of rows needed to reduce ncol_bot to ncol_top using simple 3->1 "tree" (see below)
+    int nrows_tree31 = int( log( ncol_bot / ncol_top ) / log( 3 )); // = log x base 3
+    if ( nrows < nrows_tree31 )
       MultipleReduce = true;
   }
 
@@ -2542,9 +2543,12 @@ bool StdMeshers_Quadrangle_2D::ComputeReduced (SMESH_Mesh &        aMesh,
     // maximum number of bottom elements for "linear" simple reduce 4->2
     int max_lin31 = ncol_top + ncol_top * 2 * nrows;
     // maximum number of bottom elements for "tree" simple reduce 4->2
-    int max_tree42 = npair_top * pow(2.0, nrows + 1);
-    if (ncol_top > npair_top * 2) {
-      int delta = ncol_bot - max_tree42;
+    int max_tree42 = 0;
+    // number of rows needed to reduce ncol_bot to ncol_top using simple 4->2 "tree"
+    int nrows_tree42 = int( log2( ncol_bot / ncol_top )); // needed to avoid overflow at pow(2)
+    if (ncol_top > npair_top * 2 && nrows_tree42 < nrows) {
+      max_tree42 = npair_top * pow(2.0, nrows + 1);
+      int delta = ncol_bot - int( max_tree42 );
       for (int irow = 1; irow < nrows; irow++) {
         int nfour = delta / 4;
         delta -= nfour * 2;