MOAB: Mesh Oriented datABase  (version 5.3.1)
VarianceTemplate.hpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2006 Sandia National Laboratories.  Developed at the
00005     University of Wisconsin--Madison under SNL contract number
00006     624796.  The U.S. Government and the University of Wisconsin
00007     retain certain rights to 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 VarianceTemplate.hpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #ifndef MSQ_VARIANCE_TEMPLATE_HPP
00033 #define MSQ_VARIANCE_TEMPLATE_HPP
00034 
00035 #include "Mesquite.hpp"
00036 #include "MsqHessian.hpp"
00037 #include "ObjectiveFunctionTemplate.hpp"
00038 
00039 namespace MBMesquite
00040 {
00041 
00042 /**\brief (variance)^2 template
00043  *
00044  * This class implements an objective function that is the
00045  * variance of the quality metric evalutations.
00046  */
00047 class VarianceTemplate : public ObjectiveFunctionTemplate
00048 {
00049   public:
00050     MESQUITE_EXPORT
00051     VarianceTemplate( QualityMetric* qm = 0 ) : ObjectiveFunctionTemplate( qm )
00052     {
00053         clear();
00054     }
00055 
00056     /**\brief copy constructor
00057      *
00058      * Define a copy constructor because the compiler-provided
00059      * default one would also copy the temporary arrays, which
00060      * would be a waste of time.
00061      */
00062     MESQUITE_EXPORT
00063     VarianceTemplate( const VarianceTemplate& copy )
00064         : ObjectiveFunctionTemplate( copy ), mCount( copy.mCount ), mSum( copy.mSum ), mSqrSum( copy.mSqrSum ),
00065           saveCount( copy.saveCount ), saveSum( copy.saveSum ), saveSqrSum( copy.saveSqrSum )
00066     {
00067     }
00068 
00069     MESQUITE_EXPORT
00070     virtual ~VarianceTemplate() {}
00071 
00072     MESQUITE_EXPORT
00073     virtual bool evaluate( EvalType type, PatchData& pd, double& value_out, bool free, MsqError& err );
00074 
00075     MESQUITE_EXPORT
00076     virtual bool evaluate_with_gradient( EvalType type, PatchData& pd, double& value_out,
00077                                          std::vector< Vector3D >& grad_out, MsqError& err );
00078 
00079     MESQUITE_EXPORT
00080     virtual bool evaluate_with_Hessian_diagonal( EvalType type, PatchData& pd, double& value_out,
00081                                                  std::vector< Vector3D >& grad_out,
00082                                                  std::vector< SymMatrix3D >& hess_diag_out, MsqError& err );
00083 
00084     MESQUITE_EXPORT
00085     virtual ObjectiveFunction* clone() const;
00086 
00087     MESQUITE_EXPORT
00088     virtual void clear();
00089 
00090   private:
00091     /**\brief Handle EvalType for all eval functions, return OF value
00092      *
00093      * This function implements the common handling of the EvalType
00094      * argument for all forms of the 'evaluate' method.
00095      *
00096      * NOTE:  This function modifies accumulated values depenending
00097      *        on the value of EvalType.
00098      *\param sum        The sum over the current patch
00099      *\param sqr_sum    The sum of squares over the current patch
00100      *\param count      The number of qm evaluations for the current patch
00101      *\param type       The evaluation type passed to 'evaluate'
00102      *\param global_count The total, accumulated number of QM evaluations
00103      *\param result_sum The sum term of the variance
00104      *\param result_sqr The sum of squares term of the variance
00105      */
00106     void accumulate( double sum, double sqr_sum, size_t count, EvalType type, double& result_sum, double& result_sqr,
00107                      size_t& global_count );
00108 
00109     size_t mCount;     /**< The number of accumulated entires */
00110     double mSum;       /**< The runnnig sum of the qualtiy metric valuse */
00111     double mSqrSum;    /**< The running sum of the square of QM values */
00112     size_t saveCount;  /**< Saved count from previous patch */
00113     double saveSum;    /**< Saved sum from previous patch */
00114     double saveSqrSum; /**< Saved sum from previous patch */
00115 
00116     /** Temporary storage for qm sample handles */
00117     mutable std::vector< size_t > qmHandles;
00118     /** Temporary storage for qm vertex indices */
00119     mutable std::vector< size_t > mIndices;
00120     /** Temporary storage for qm gradient */
00121     mutable std::vector< Vector3D > mGradient, gradSum;
00122     /** Temporary storage for qm Hessian diagonal data */
00123     mutable std::vector< SymMatrix3D > mHessDiag, hessSum;
00124 };
00125 
00126 }  // namespace MBMesquite
00127 
00128 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines