MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2006 Lawrence Livermore National Laboratory. Under 00005 the terms of Contract B545069 with the University of Wisconsin -- 00006 Madison, Lawrence Livermore National Laboratory 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 (2006) [email protected] 00024 00025 ***************************************************************** */ 00026 00027 /** \file PMeanPTemplate.hpp 00028 * \brief previous name: PowerMeanP.hpp 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #ifndef MSQ_P_MEAN_P_TEMPLATE_HPP 00033 #define MSQ_P_MEAN_P_TEMPLATE_HPP 00034 00035 #include "Mesquite.hpp" 00036 #include "ObjectiveFunctionTemplate.hpp" 00037 #include "Exponent.hpp" 00038 #include "Matrix3D.hpp" 00039 00040 namespace MBMesquite 00041 { 00042 00043 /**\brief \f$\frac{1}{n}\sum_{i=1}^n\mu(s_i)^p\f$ 00044 * 00045 * This class implements an objective function that is the 00046 * power-mean of the quality metric evalutations raised to the 00047 * power-mean power. That is, the sum of each quality metric value 00048 * raised to a power, divided by the totoal number of quality metric 00049 * values. 00050 */ 00051 class PMeanPTemplate : public ObjectiveFunctionTemplate 00052 { 00053 public: 00054 /** 00055 *\param power The exponent to use for the power-mean 00056 *\param qm The quality metric. 00057 */ 00058 MESQUITE_EXPORT 00059 PMeanPTemplate( double power, QualityMetric* qm = 0 ) : ObjectiveFunctionTemplate( qm ) 00060 { 00061 clear(); 00062 set_power( power ); 00063 } 00064 00065 /**\brief copy constructor 00066 * 00067 * Define a copy constructor because the compiler-provided 00068 * default one would also copy the temporary arrays, which 00069 * would be a waste of time. 00070 */ 00071 MESQUITE_EXPORT 00072 PMeanPTemplate( const PMeanPTemplate& copy ) 00073 : ObjectiveFunctionTemplate( copy ), mPower( copy.mPower ), mPowerMinus1( copy.mPowerMinus1 ), 00074 mPowerMinus2( copy.mPowerMinus2 ), mCount( copy.mCount ), mPowSum( copy.mPowSum ), 00075 saveCount( copy.saveCount ), savePowSum( copy.savePowSum ) 00076 { 00077 } 00078 00079 MESQUITE_EXPORT 00080 virtual ~PMeanPTemplate() {} 00081 00082 MESQUITE_EXPORT 00083 double get_power() const 00084 { 00085 return mPower.value(); 00086 } 00087 00088 MESQUITE_EXPORT 00089 void set_power( double p ) 00090 { 00091 mPower = p; 00092 mPowerMinus1 = p - 1; 00093 mPowerMinus2 = p - 2; 00094 } 00095 00096 MESQUITE_EXPORT 00097 virtual bool evaluate( EvalType type, PatchData& pd, double& value_out, bool free, MsqError& err ); 00098 00099 MESQUITE_EXPORT 00100 virtual bool evaluate_with_gradient( EvalType type, 00101 PatchData& pd, 00102 double& value_out, 00103 std::vector< Vector3D >& grad_out, 00104 MsqError& err ); 00105 00106 MESQUITE_EXPORT 00107 virtual bool evaluate_with_Hessian_diagonal( EvalType type, 00108 PatchData& pd, 00109 double& value_out, 00110 std::vector< Vector3D >& grad_out, 00111 std::vector< SymMatrix3D >& hess_diag_out, 00112 MsqError& err ); 00113 00114 MESQUITE_EXPORT 00115 virtual bool evaluate_with_Hessian( EvalType type, 00116 PatchData& pd, 00117 double& value_out, 00118 std::vector< Vector3D >& grad_out, 00119 MsqHessian& Hessian_out, 00120 MsqError& err ); 00121 00122 MESQUITE_EXPORT 00123 virtual ObjectiveFunction* clone() const; 00124 00125 MESQUITE_EXPORT 00126 virtual void clear(); 00127 00128 protected: 00129 /**\brief Handle EvalType for all eval functions, return OF value 00130 * 00131 * This function implements the common handling of the EvalType 00132 * argument for all forms of the 'evaluate' method. 00133 * 00134 * NOTE: This function modifies accumulated values depenending 00135 * on the value of EvalType. 00136 *\param power_sum The sum over the current patch 00137 *\param count The number of qm evaluations for the current patch 00138 *\param type The evaluation type passed to 'evaluate' 00139 *\param global_count The total, accumulated number of QM evaluations 00140 *\return The objective function value to return from 'evaluate' 00141 */ 00142 double get_value( double power_sum, size_t count, EvalType type, size_t& global_count ); 00143 00144 Exponent mPower; /**< The power to use */ 00145 Exponent mPowerMinus1; /**< mPower - 1.0 */ 00146 Exponent mPowerMinus2; /**< mPower - 2.0 */ 00147 00148 private: 00149 size_t mCount; /**< The number of accumulated entires */ 00150 double mPowSum; /**< The accumulated sum of values to the mPower */ 00151 size_t saveCount; /**< Saved count from previous patch */ 00152 double savePowSum; /**< Saved sum from previous patch */ 00153 00154 protected: 00155 /** Temporary storage for qm sample handles */ 00156 mutable std::vector< size_t > qmHandles; 00157 /** Temporary storage for qm vertex indices */ 00158 mutable std::vector< size_t > mIndices; 00159 /** Temporary storage for qm gradient */ 00160 mutable std::vector< Vector3D > mGradient; 00161 /** Temporary storage for qm hessian diagonal */ 00162 mutable std::vector< SymMatrix3D > mDiag; 00163 /** Temporary storage for qm Hessian */ 00164 mutable std::vector< Matrix3D > mHessian; 00165 }; 00166 00167 } // namespace MBMesquite 00168 00169 #endif