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 // -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3 00028 // -*- 00029 00030 /*! \file LPtoPTemplate.hpp 00031 \brief Header file for the MBMesquite::LPtoPTemplate class 00032 \author Michael Brewer 00033 \author Thomas Leurent 00034 \date 2002-05-23 00035 */ 00036 00037 #ifndef LPtoPTemplate_hpp 00038 #define LPtoPTemplate_hpp 00039 00040 #include "Mesquite.hpp" 00041 #include "ObjectiveFunctionTemplate.hpp" 00042 00043 namespace MBMesquite 00044 { 00045 class Matrix3D; 00046 00047 /*! \class LPtoPTemplate 00048 \brief Calculates the L_p objective function raised to the pth 00049 power. That is, sums the p_th powers of (the absolute value of) 00050 the quality metric values. 00051 00052 \todo MB. Suggestions made by Todd Munson: 00053 a) There is an inconsistent use of fabs. The hessian evaluation 00054 when using the one norm does not take the absolute value, while the 00055 gradient does. 00056 b) The analytic gradient and hessian evaluations are incorrect when 00057 the quality metric changes sign due to taking the absolute value. 00058 The negative of the element gradient and hessian also needs to be 00059 taken. 00060 c) Done. The analytic gradient and hessian evaluations are 00061 incorrect when the negate flag is set to -1. The negative 00062 of the element gradient and hessian also needs to be taken 00063 in this case. 00064 d) The malloc in the concrete_eval routine should be removed. 00065 00066 */ 00067 class LPtoPTemplate : public ObjectiveFunctionTemplate 00068 { 00069 public: 00070 MESQUITE_EXPORT 00071 LPtoPTemplate( QualityMetric*, short, MsqError& ); 00072 MESQUITE_EXPORT 00073 LPtoPTemplate( short, QualityMetric* ); 00074 00075 MESQUITE_EXPORT 00076 virtual ~LPtoPTemplate(); 00077 00078 MESQUITE_EXPORT 00079 virtual void clear(); 00080 00081 MESQUITE_EXPORT 00082 virtual bool evaluate( EvalType type, PatchData& pd, double& value_out, bool free, MsqError& err ); 00083 00084 MESQUITE_EXPORT 00085 virtual bool evaluate_with_gradient( EvalType type, 00086 PatchData& pd, 00087 double& value_out, 00088 std::vector< Vector3D >& grad_out, 00089 MsqError& err ); 00090 00091 MESQUITE_EXPORT 00092 virtual bool evaluate_with_Hessian_diagonal( EvalType type, 00093 PatchData& pd, 00094 double& value_out, 00095 std::vector< Vector3D >& grad_out, 00096 std::vector< SymMatrix3D >& hess_diag_out, 00097 MsqError& err ); 00098 00099 MESQUITE_EXPORT 00100 virtual bool evaluate_with_Hessian( EvalType type, 00101 PatchData& pd, 00102 double& value_out, 00103 std::vector< Vector3D >& grad_out, 00104 MsqHessian& Hessian_out, 00105 MsqError& err ); 00106 00107 MESQUITE_EXPORT 00108 virtual ObjectiveFunction* clone() const; 00109 00110 /*!Use set_dividing_by_n to control whether this objective 00111 function divides it's final value by the number of 00112 metric values used to compute the objective function 00113 value. That is, if the associated metric is element 00114 based, the obejctive function value is divided by 00115 the number of elements. If it is vertex based, the 00116 objective function is divided by the number of vertices. 00117 If this function is passed 'true', the function value 00118 will be scale. If it is passed false, the function 00119 value will not be scaled.*/ 00120 MESQUITE_EXPORT 00121 void set_dividing_by_n( bool d_bool ) 00122 { 00123 dividingByN = d_bool; 00124 } 00125 00126 private: 00127 double get_value( double power_sum, size_t count, EvalType type, size_t& global_count, MsqError& err ); 00128 00129 //! The metric value entries are raised to the pVal power 00130 short pVal; 00131 //! dividingByN is true if we are dividing the objective function 00132 //! by the number of metric values. 00133 bool dividingByN; 00134 00135 size_t mCount; /**< The number of accumulated entires */ 00136 double mPowSum; /**< The accumulated sum of values */ 00137 size_t saveCount; /**< Saved count from previous patch */ 00138 double savePowSum; /**< Saved sum from previous patch */ 00139 00140 /** Temporary storage for qm sample handles */ 00141 mutable std::vector< size_t > qmHandles; 00142 /** Temporary storage for qm vertex indices */ 00143 mutable std::vector< size_t > mIndices; 00144 /** Temporary storage for qm gradient */ 00145 mutable std::vector< Vector3D > mGradient; 00146 /** Temporary storage for qm Hessian diagonal blocks */ 00147 mutable std::vector< SymMatrix3D > mDiag; 00148 /** Temporary storage for qm Hessian */ 00149 mutable std::vector< Matrix3D > mHessian; 00150 }; 00151 00152 } // namespace MBMesquite 00153 00154 #endif // LPtoPTemplate_hpp