MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2004 Sandia Corporation and Argonne National 00005 Laboratory. Under the terms of Contract DE-AC04-94AL85000 00006 with Sandia Corporation, the U.S. Government retains certain 00007 rights in this software. 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 (lgpl.txt) along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 [email protected], [email protected], [email protected], 00024 [email protected], [email protected], [email protected] 00025 00026 ***************************************************************** */ 00027 /*! 00028 \file NonGradient.hpp 00029 \brief 00030 The NonGradient class is also a concrete vertex mover 00031 which performs derivative free minimization 00032 based on the Amoeba Method, as implemented in Numerical Recipes in C. 00033 */ 00034 00035 #ifndef Mesquite_NonGradient_hpp 00036 #define Mesquite_NonGradient_hpp 00037 00038 #include "Mesquite.hpp" 00039 #include "VertexMover.hpp" 00040 #include "PatchSetUser.hpp" 00041 00042 namespace MBMesquite 00043 { 00044 class ObjectiveFunction; 00045 00046 /*! \class NonGradient 00047 00048 This is an implementation of a derivative-free optimization algorithm 00049 Commonly referred to as the 'amoeba'. This implementation only works 00050 on patches containing one free vertex. */ 00051 00052 class NonGradient : public VertexMover, public PatchSetUser 00053 { 00054 public: 00055 MESQUITE_EXPORT 00056 NonGradient( ObjectiveFunction* of ); 00057 00058 MESQUITE_EXPORT 00059 NonGradient( ObjectiveFunction* of, MsqError& err ); 00060 00061 MESQUITE_EXPORT virtual ~NonGradient() {} 00062 00063 MESQUITE_EXPORT virtual std::string get_name() const; 00064 00065 MESQUITE_EXPORT virtual PatchSet* get_patch_set(); 00066 00067 MESQUITE_EXPORT 00068 bool project_gradient() const 00069 { 00070 return projectGradient; 00071 } 00072 00073 MESQUITE_EXPORT 00074 void project_gradient( bool yesno ) 00075 { 00076 projectGradient = yesno; 00077 } 00078 00079 int getDimension() 00080 { 00081 return ( mDimension ); 00082 } 00083 double getThreshold() 00084 { 00085 return ( mThreshold ); 00086 } 00087 // double getTolerance() 00088 // { 00089 // return(mTolerance); 00090 // } 00091 int getMaxNumEval() 00092 { 00093 return ( mMaxNumEval ); 00094 } 00095 double getSimplexDiameterScale() 00096 { 00097 return ( mScaleDiameter ); 00098 } 00099 void setDimension( int dimension ) 00100 { 00101 mDimension = dimension; 00102 } 00103 void setThreshold( double threshold ) 00104 { 00105 mThreshold = threshold; 00106 } 00107 // void setTolerance(double ftol) 00108 // { 00109 // mTolerance = ftol; 00110 // } 00111 void setMaxNumEval( int maxNumEval ) 00112 { 00113 mMaxNumEval = maxNumEval; 00114 } 00115 void setExactPenaltyFunction( bool exactPenalty ) 00116 { 00117 mUseExactPenaltyFunction = exactPenalty; 00118 } 00119 void setSimplexDiameterScale( double newScaleDiameter ) 00120 { 00121 mScaleDiameter = newScaleDiameter; 00122 } 00123 void getRowSum( int numRow, int numCol, std::vector< double >& matrix, std::vector< double >& rowSum ); 00124 bool testRowSum( int numRow, int numCol, double* matrix, double* rowSum ); 00125 double evaluate( double localArray[], PatchData& pd, MsqError& err ); 00126 //! edgeLenght is a length scale for the initial polytope. 00127 int initSimplex( double edgeLength ); 00128 //! matrix stored by column as a std::vector 00129 std::vector< double > simplex; 00130 std::vector< double > height; 00131 //! Generic patch helper function only used by NonGradient 00132 void printPatch( const PatchData& pd, MsqError& err ); 00133 //! Generic patch helper function only used by NonGradient 00134 int getPatchDimension( const PatchData& pd, MsqError& err ); 00135 //! Obtain diagnostic data during optimization 00136 //! off=level 0, ... level 3 = maximal 00137 MESQUITE_EXPORT void set_debugging_level( int level ) 00138 { 00139 mNonGradDebug = level; 00140 } 00141 00142 protected: 00143 MESQUITE_EXPORT virtual void initialize( PatchData& pd, MsqError& err ); 00144 MESQUITE_EXPORT virtual void optimize_vertex_positions( PatchData& pd, MsqError& err ); 00145 MESQUITE_EXPORT virtual void initialize_mesh_iteration( PatchData& pd, MsqError& err ); 00146 MESQUITE_EXPORT virtual void terminate_mesh_iteration( PatchData& pd, MsqError& err ); 00147 MESQUITE_EXPORT virtual void cleanup(); 00148 00149 private: 00150 bool projectGradient; 00151 int mDimension; 00152 double mThreshold; // stop if 2(heightMax-heightMin) 00153 double mTolerance; // ---------------------------------- < mTolerance 00154 int mMaxNumEval; // |heightMax|+|heightMin|+mThreshold 00155 // or numEval >= mMaxNumEval 00156 double amotry( std::vector< double >&, std::vector< double >&, double*, int, double, PatchData&, MsqError& err ); 00157 int mNonGradDebug; 00158 bool mUseExactPenaltyFunction; 00159 double mScaleDiameter; 00160 void printSimplex( std::vector< double >&, std::vector< double >& ); 00161 00162 NonGradient( const NonGradient& pd ); // disable copying 00163 NonGradient& operator=( const NonGradient& pd ); // disable assignment 00164 }; 00165 00166 } // namespace MBMesquite 00167 00168 #endif