MOAB: Mesh Oriented datABase
(version 5.3.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 diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov, 00024 pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov 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, PatchData& pd, double& value_out, 00086 std::vector< Vector3D >& grad_out, MsqError& err ); 00087 00088 MESQUITE_EXPORT 00089 virtual bool evaluate_with_Hessian_diagonal( EvalType type, PatchData& pd, double& value_out, 00090 std::vector< Vector3D >& grad_out, 00091 std::vector< SymMatrix3D >& hess_diag_out, MsqError& err ); 00092 00093 MESQUITE_EXPORT 00094 virtual bool evaluate_with_Hessian( EvalType type, PatchData& pd, double& value_out, 00095 std::vector< Vector3D >& grad_out, MsqHessian& Hessian_out, MsqError& err ); 00096 00097 MESQUITE_EXPORT 00098 virtual ObjectiveFunction* clone() const; 00099 00100 /*!Use set_dividing_by_n to control whether this objective 00101 function divides it's final value by the number of 00102 metric values used to compute the objective function 00103 value. That is, if the associated metric is element 00104 based, the obejctive function value is divided by 00105 the number of elements. If it is vertex based, the 00106 objective function is divided by the number of vertices. 00107 If this function is passed 'true', the function value 00108 will be scale. If it is passed false, the function 00109 value will not be scaled.*/ 00110 MESQUITE_EXPORT 00111 void set_dividing_by_n( bool d_bool ) 00112 { 00113 dividingByN = d_bool; 00114 } 00115 00116 private: 00117 double get_value( double power_sum, size_t count, EvalType type, size_t& global_count, MsqError& err ); 00118 00119 //! The metric value entries are raised to the pVal power 00120 short pVal; 00121 //! dividingByN is true if we are dividing the objective function 00122 //! by the number of metric values. 00123 bool dividingByN; 00124 00125 size_t mCount; /**< The number of accumulated entires */ 00126 double mPowSum; /**< The accumulated sum of values */ 00127 size_t saveCount; /**< Saved count from previous patch */ 00128 double savePowSum; /**< Saved sum from previous patch */ 00129 00130 /** Temporary storage for qm sample handles */ 00131 mutable std::vector< size_t > qmHandles; 00132 /** Temporary storage for qm vertex indices */ 00133 mutable std::vector< size_t > mIndices; 00134 /** Temporary storage for qm gradient */ 00135 mutable std::vector< Vector3D > mGradient; 00136 /** Temporary storage for qm Hessian diagonal blocks */ 00137 mutable std::vector< SymMatrix3D > mDiag; 00138 /** Temporary storage for qm Hessian */ 00139 mutable std::vector< Matrix3D > mHessian; 00140 }; 00141 00142 } // namespace MBMesquite 00143 00144 #endif // LPtoPTemplate_hpp