LCOV - code coverage report
Current view: top level - src/mesquite/QualityImprover/OptSolvers - NonGradient.hpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 21 21 100.0 %
Date: 2020-07-18 00:09:26 Functions: 8 8 100.0 %
Branches: 1 2 50.0 %

           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                 :            : /*!
      28                 :            :   \file   NonGradient.hpp
      29                 :            :   \brief
      30                 :            :   The NonGradient class is also a concrete vertex mover
      31                 :            :   which performs derivative free minimization
      32                 :            :   based on the Amoeba Method, as implemented in Numerical Recipes in C.
      33                 :            : */
      34                 :            : 
      35                 :            : #ifndef Mesquite_NonGradient_hpp
      36                 :            : #define Mesquite_NonGradient_hpp
      37                 :            : 
      38                 :            : #include "Mesquite.hpp"
      39                 :            : #include "VertexMover.hpp"
      40                 :            : #include "PatchSetUser.hpp"
      41                 :            : 
      42                 :            : namespace MBMesquite
      43                 :            : {
      44                 :            : class ObjectiveFunction;
      45                 :            : 
      46                 :            : /*! \class NonGradient
      47                 :            : 
      48                 :            :     This is an implementation of  a derivative-free optimization algorithm
      49                 :            :     Commonly referred to as the 'amoeba'.  This implementation only works
      50                 :            :     on patches containing one free vertex. */
      51                 :            : 
      52                 :            : class NonGradient : public VertexMover, public PatchSetUser
      53                 :            : {
      54                 :            :   public:
      55                 :            :     MESQUITE_EXPORT
      56                 :            :     NonGradient( ObjectiveFunction* of );
      57                 :            : 
      58                 :            :     MESQUITE_EXPORT
      59                 :            :     NonGradient( ObjectiveFunction* of, MsqError& err );
      60                 :            : 
      61         [ -  + ]:          6 :     MESQUITE_EXPORT virtual ~NonGradient() {}
      62                 :            : 
      63                 :            :     MESQUITE_EXPORT virtual std::string get_name() const;
      64                 :            : 
      65                 :            :     MESQUITE_EXPORT virtual PatchSet* get_patch_set();
      66                 :            : 
      67                 :            :     MESQUITE_EXPORT
      68                 :            :     bool project_gradient() const
      69                 :            :     {
      70                 :            :         return projectGradient;
      71                 :            :     }
      72                 :            : 
      73                 :            :     MESQUITE_EXPORT
      74                 :            :     void project_gradient( bool yesno )
      75                 :            :     {
      76                 :            :         projectGradient = yesno;
      77                 :            :     }
      78                 :            : 
      79                 :      16144 :     int getDimension()
      80                 :            :     {
      81                 :      16144 :         return ( mDimension );
      82                 :            :     }
      83                 :            :     double getThreshold()
      84                 :            :     {
      85                 :            :         return ( mThreshold );
      86                 :            :     }
      87                 :            :     //    double getTolerance()
      88                 :            :     //    {
      89                 :            :     //      return(mTolerance);
      90                 :            :     //    }
      91                 :            :     int getMaxNumEval()
      92                 :            :     {
      93                 :            :         return ( mMaxNumEval );
      94                 :            :     }
      95                 :            :     double getSimplexDiameterScale()
      96                 :            :     {
      97                 :            :         return ( mScaleDiameter );
      98                 :            :     }
      99                 :        850 :     void setDimension( int dimension )
     100                 :            :     {
     101                 :        850 :         mDimension = dimension;
     102                 :        850 :     }
     103                 :        850 :     void setThreshold( double threshold )
     104                 :            :     {
     105                 :        850 :         mThreshold = threshold;
     106                 :        850 :     }
     107                 :            :     //    void setTolerance(double ftol)
     108                 :            :     //    {
     109                 :            :     //      mTolerance = ftol;
     110                 :            :     //    }
     111                 :        850 :     void setMaxNumEval( int maxNumEval )
     112                 :            :     {
     113                 :        850 :         mMaxNumEval = maxNumEval;
     114                 :        850 :     }
     115                 :          1 :     void setExactPenaltyFunction( bool exactPenalty )
     116                 :            :     {
     117                 :          1 :         mUseExactPenaltyFunction = exactPenalty;
     118                 :          1 :     }
     119                 :          1 :     void setSimplexDiameterScale( double newScaleDiameter )
     120                 :            :     {
     121                 :          1 :         mScaleDiameter = newScaleDiameter;
     122                 :          1 :     }
     123                 :            :     void getRowSum( int numRow, int numCol, std::vector< double >& matrix, std::vector< double >& rowSum );
     124                 :            :     bool testRowSum( int numRow, int numCol, double* matrix, double* rowSum );
     125                 :            :     double evaluate( double localArray[], PatchData& pd, MsqError& err );
     126                 :            :     //! edgeLenght is a length scale for the initial polytope.
     127                 :            :     int initSimplex( double edgeLength );
     128                 :            :     //! matrix stored by column as a std::vector
     129                 :            :     std::vector< double > simplex;
     130                 :            :     std::vector< double > height;
     131                 :            :     //! Generic patch helper function only used by NonGradient
     132                 :            :     void printPatch( const PatchData& pd, MsqError& err );
     133                 :            :     //! Generic patch helper function only used by NonGradient
     134                 :            :     int getPatchDimension( const PatchData& pd, MsqError& err );
     135                 :            :     //! Obtain diagnostic data during optimization
     136                 :            :     //! off=level 0, ... level 3 = maximal
     137                 :          5 :     MESQUITE_EXPORT void set_debugging_level( int level )
     138                 :            :     {
     139                 :          5 :         mNonGradDebug = level;
     140                 :          5 :     }
     141                 :            : 
     142                 :            :   protected:
     143                 :            :     MESQUITE_EXPORT virtual void initialize( PatchData& pd, MsqError& err );
     144                 :            :     MESQUITE_EXPORT virtual void optimize_vertex_positions( PatchData& pd, MsqError& err );
     145                 :            :     MESQUITE_EXPORT virtual void initialize_mesh_iteration( PatchData& pd, MsqError& err );
     146                 :            :     MESQUITE_EXPORT virtual void terminate_mesh_iteration( PatchData& pd, MsqError& err );
     147                 :            :     MESQUITE_EXPORT virtual void cleanup();
     148                 :            : 
     149                 :            :   private:
     150                 :            :     bool projectGradient;
     151                 :            :     int mDimension;
     152                 :            :     double mThreshold;  // stop if       2(heightMax-heightMin)
     153                 :            :     double mTolerance;  //          ---------------------------------- < mTolerance
     154                 :            :     int mMaxNumEval;    //          |heightMax|+|heightMin|+mThreshold
     155                 :            :                         //      or numEval >= mMaxNumEval
     156                 :            :     double amotry( std::vector< double >&, std::vector< double >&, double*, int, double, PatchData&, MsqError& err );
     157                 :            :     int mNonGradDebug;
     158                 :            :     bool mUseExactPenaltyFunction;
     159                 :            :     double mScaleDiameter;
     160                 :            :     void printSimplex( std::vector< double >&, std::vector< double >& );
     161                 :            : 
     162                 :            :     NonGradient( const NonGradient& pd );             // disable copying
     163                 :            :     NonGradient& operator=( const NonGradient& pd );  // disable assignment
     164                 :            : };
     165                 :            : 
     166                 :            : }  // namespace MBMesquite
     167                 :            : 
     168                 :            : #endif

Generated by: LCOV version 1.11