LCOV - code coverage report
Current view: top level - src/mesquite/Wrappers - ShapeImprovementWrapper.cpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 38 45 84.4 %
Date: 2020-07-18 00:09:26 Functions: 4 5 80.0 %
Branches: 72 176 40.9 %

           Branch data     Line data    Source code
       1                 :            : /* *****************************************************************
       2                 :            :     MESQUITE -- The Mesh Quality Improvement Toolkit
       3                 :            : 
       4                 :            :     Copyright 2004 Sandia Corporation and Argonne National
       5                 :            :     Laboratory.  Under the terms of Contract DE-AC04-94AL85000
       6                 :            :     with Sandia Corporation, the U.S. Government retains certain
       7                 :            :     rights in this software.
       8                 :            : 
       9                 :            :     This library is free software; you can redistribute it and/or
      10                 :            :     modify it under the terms of the GNU Lesser General Public
      11                 :            :     License as published by the Free Software Foundation; either
      12                 :            :     version 2.1 of the License, or (at your option) any later version.
      13                 :            : 
      14                 :            :     This library is distributed in the hope that it will be useful,
      15                 :            :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :            :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17                 :            :     Lesser General Public License for more details.
      18                 :            : 
      19                 :            :     You should have received a copy of the GNU Lesser General Public License
      20                 :            :     (lgpl.txt) along with this library; if not, write to the Free Software
      21                 :            :     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      22                 :            : 
      23                 :            :     [email protected], [email protected], [email protected],
      24                 :            :     [email protected], [email protected], [email protected]
      25                 :            : 
      26                 :            :   ***************************************************************** */
      27                 :            : // -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3
      28                 :            : // -*-
      29                 :            : 
      30                 :            : /*! \file ShapeImprovementWrapper.cpp
      31                 :            : 
      32                 :            : Member functions of the MBMesquite::ShapeImprovementWrapper class
      33                 :            : 
      34                 :            :   \author Michael Brewer
      35                 :            :   \date   June 6, 2003
      36                 :            :  */
      37                 :            : 
      38                 :            : #include "InstructionQueue.hpp"
      39                 :            : #include "ShapeImprovementWrapper.hpp"
      40                 :            : #include "MsqTimer.hpp"
      41                 :            : #include "MsqDebug.hpp"
      42                 :            : #include "UntangleBetaQualityMetric.hpp"
      43                 :            : #include "LPtoPTemplate.hpp"
      44                 :            : #include "ConjugateGradient.hpp"
      45                 :            : #include "TerminationCriterion.hpp"
      46                 :            : #include "IdealWeightInverseMeanRatio.hpp"
      47                 :            : #include "FeasibleNewton.hpp"
      48                 :            : #include "InstructionQueue.hpp"
      49                 :            : #include "QualityAssessor.hpp"
      50                 :            : 
      51                 :            : namespace MBMesquite
      52                 :            : {
      53                 :            : 
      54                 :            : const double DEF_UNT_BETA = 1e-8;
      55                 :            : const double DEF_SUC_EPS  = 1e-4;
      56                 :            : 
      57                 :            : /*! The consturctor allows for two values.  The first is a
      58                 :            :   time bound (in seconds) used as a termination criterion.  If
      59                 :            :   this value is non-positive, no time bound will be set.
      60                 :            :   By default, the value is set to zero and no time bound
      61                 :            :   is used.  The second value is the tolerance for the gradient
      62                 :            :   norm termination criteria.  The default value is 1.e-6.*/
      63                 :          0 : ShapeImprovementWrapper::ShapeImprovementWrapper( MsqError&, double cpu_time, double grad_norm,
      64                 :            :                                                   int parallel_iterations )
      65                 :            :     : maxTime( cpu_time ), gradNorm( grad_norm ), untBeta( DEF_UNT_BETA ), successiveEps( DEF_SUC_EPS ),
      66                 :          0 :       parallelIterations( parallel_iterations )
      67                 :            : {
      68                 :          0 : }
      69                 :            : 
      70                 :          2 : ShapeImprovementWrapper::ShapeImprovementWrapper( double cpu_time, double grad_norm, int parallel_iterations )
      71                 :            :     : maxTime( cpu_time ), gradNorm( grad_norm ), untBeta( DEF_UNT_BETA ), successiveEps( DEF_SUC_EPS ),
      72                 :          2 :       parallelIterations( parallel_iterations )
      73                 :            : {
      74                 :          2 : }
      75                 :            : 
      76                 :          2 : void ShapeImprovementWrapper::run_wrapper( MeshDomainAssoc* mesh_and_domain, ParallelMesh* pmesh, Settings* settings,
      77                 :            :                                            QualityAssessor* qa, MsqError& err )
      78                 :            : {
      79                 :            :     // Define an untangler
      80         [ +  - ]:          2 :     UntangleBetaQualityMetric untangle_metric( untBeta );
      81 [ +  - ][ +  - ]:          4 :     LPtoPTemplate untangle_func( 2, &untangle_metric );
      82 [ +  - ][ +  - ]:          4 :     ConjugateGradient untangle_global( &untangle_func );
      83 [ +  - ][ +  - ]:          4 :     TerminationCriterion untangle_inner, untangle_outer;
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      84         [ +  - ]:          2 :     untangle_global.use_global_patch();
      85         [ +  - ]:          2 :     untangle_inner.add_absolute_quality_improvement( 0.0 );
      86         [ +  - ]:          2 :     untangle_inner.add_absolute_successive_improvement( successiveEps );
      87         [ +  - ]:          2 :     untangle_outer.add_iteration_limit( 1 );
      88         [ +  - ]:          2 :     untangle_global.set_inner_termination_criterion( &untangle_inner );
      89         [ +  - ]:          2 :     untangle_global.set_outer_termination_criterion( &untangle_outer );
      90                 :            : 
      91                 :            :     // define shape improver
      92 [ +  - ][ +  - ]:          4 :     IdealWeightInverseMeanRatio inverse_mean_ratio;
      93         [ +  - ]:          2 :     inverse_mean_ratio.set_averaging_method( QualityMetric::LINEAR );
      94 [ +  - ][ +  - ]:          4 :     LPtoPTemplate obj_func( 2, &inverse_mean_ratio );
      95 [ +  - ][ +  - ]:          4 :     FeasibleNewton feas_newt( &obj_func );
      96 [ +  - ][ +  - ]:          4 :     TerminationCriterion term_inner, term_outer;
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      97         [ +  - ]:          2 :     feas_newt.use_global_patch();
      98         [ +  - ]:          2 :     qa->add_quality_assessment( &inverse_mean_ratio );
      99         [ +  - ]:          2 :     term_inner.add_absolute_gradient_L2_norm( gradNorm );
     100         [ +  - ]:          2 :     term_inner.add_relative_successive_improvement( successiveEps );
     101 [ -  + ][ +  - ]:          2 :     term_outer.add_iteration_limit( pmesh ? parallelIterations : 1 );
     102         [ +  - ]:          2 :     feas_newt.set_inner_termination_criterion( &term_inner );
     103         [ +  - ]:          2 :     feas_newt.set_outer_termination_criterion( &term_outer );
     104                 :            : 
     105                 :            :     // Apply CPU time limit to untangler
     106 [ -  + ][ #  # ]:          2 :     if( maxTime > 0.0 ) untangle_inner.add_cpu_time( maxTime );
     107                 :            : 
     108                 :            :     // Run untangler
     109 [ +  - ][ +  - ]:          4 :     InstructionQueue q1;
     110         [ +  - ]:          2 :     Timer totalTimer;
     111 [ +  - ][ +  - ]:          2 :     q1.set_master_quality_improver( &untangle_global, err );MSQ_ERRRTN( err );
         [ -  + ][ #  # ]
         [ #  # ][ -  + ]
     112 [ +  - ][ +  - ]:          2 :     q1.add_quality_assessor( qa, err );MSQ_ERRRTN( err );
         [ -  + ][ #  # ]
         [ #  # ][ -  + ]
     113 [ +  - ][ +  - ]:          2 :     q1.run_common( mesh_and_domain, pmesh, settings, err );MSQ_ERRRTN( err );
         [ -  + ][ #  # ]
         [ #  # ][ -  + ]
     114                 :            : 
     115                 :            :     // If limited by CPU time, limit next step to remaning time
     116         [ -  + ]:          2 :     if( maxTime > 0.0 )
     117                 :            :     {
     118         [ #  # ]:          0 :         double remaining = maxTime - totalTimer.since_birth();
     119         [ #  # ]:          0 :         if( remaining <= 0.0 )
     120                 :            :         {
     121                 :            :             MSQ_DBGOUT( 2 ) << "Optimization is terminating without perfoming shape improvement." << std::endl;
     122                 :          0 :             remaining = 0.0;
     123                 :            :         }
     124         [ #  # ]:          0 :         term_inner.add_cpu_time( remaining );
     125                 :            :     }
     126                 :            : 
     127                 :            :     // Run shape improver
     128 [ +  - ][ +  - ]:          4 :     InstructionQueue q2;
     129 [ +  - ][ +  - ]:          2 :     q2.set_master_quality_improver( &feas_newt, err );MSQ_ERRRTN( err );
         [ -  + ][ #  # ]
         [ #  # ][ -  + ]
     130 [ +  - ][ +  - ]:          2 :     q2.add_quality_assessor( qa, err );MSQ_ERRRTN( err );
         [ -  + ][ #  # ]
         [ #  # ][ -  + ]
     131 [ +  - ][ +  - ]:          4 :     q2.run_common( mesh_and_domain, pmesh, settings, err );MSQ_ERRRTN( err );
         [ -  + ][ #  # ]
         [ #  # ][ -  + ]
                 [ +  - ]
     132                 :            : }
     133                 :            : 
     134 [ +  - ][ +  - ]:          8 : }  // namespace MBMesquite

Generated by: LCOV version 1.11