MOAB: Mesh Oriented datABase  (version 5.3.1)
PMeanPTemplate.hpp
Go to the documentation of this file.
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) kraftche@cae.wisc.edu
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, PatchData& pd, double& value_out,
00101                                          std::vector< Vector3D >& grad_out, MsqError& err );
00102 
00103     MESQUITE_EXPORT
00104     virtual bool evaluate_with_Hessian_diagonal( EvalType type, PatchData& pd, double& value_out,
00105                                                  std::vector< Vector3D >& grad_out,
00106                                                  std::vector< SymMatrix3D >& hess_diag_out, MsqError& err );
00107 
00108     MESQUITE_EXPORT
00109     virtual bool evaluate_with_Hessian( EvalType type, PatchData& pd, double& value_out,
00110                                         std::vector< Vector3D >& grad_out, MsqHessian& Hessian_out, MsqError& err );
00111 
00112     MESQUITE_EXPORT
00113     virtual ObjectiveFunction* clone() const;
00114 
00115     MESQUITE_EXPORT
00116     virtual void clear();
00117 
00118   protected:
00119     /**\brief Handle EvalType for all eval functions, return OF value
00120      *
00121      * This function implements the common handling of the EvalType
00122      * argument for all forms of the 'evaluate' method.
00123      *
00124      * NOTE:  This function modifies accumulated values depenending
00125      *        on the value of EvalType.
00126      *\param power_sum  The sum over the current patch
00127      *\param count      The number of qm evaluations for the current patch
00128      *\param type       The evaluation type passed to 'evaluate'
00129      *\param global_count The total, accumulated number of QM evaluations
00130      *\return The objective function value to return from 'evaluate'
00131      */
00132     double get_value( double power_sum, size_t count, EvalType type, size_t& global_count );
00133 
00134     Exponent mPower;       /**< The power to use */
00135     Exponent mPowerMinus1; /**< mPower - 1.0 */
00136     Exponent mPowerMinus2; /**< mPower - 2.0 */
00137 
00138   private:
00139     size_t mCount;     /**< The number of accumulated entires */
00140     double mPowSum;    /**< The accumulated sum of values to the mPower */
00141     size_t saveCount;  /**< Saved count from previous patch */
00142     double savePowSum; /**< Saved sum from previous patch */
00143 
00144   protected:
00145     /** Temporary storage for qm sample handles */
00146     mutable std::vector< size_t > qmHandles;
00147     /** Temporary storage for qm vertex indices */
00148     mutable std::vector< size_t > mIndices;
00149     /** Temporary storage for qm gradient */
00150     mutable std::vector< Vector3D > mGradient;
00151     /** Temporary storage for qm hessian diagonal */
00152     mutable std::vector< SymMatrix3D > mDiag;
00153     /** Temporary storage for qm Hessian */
00154     mutable std::vector< Matrix3D > mHessian;
00155 };
00156 
00157 }  // namespace MBMesquite
00158 
00159 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines