MOAB: Mesh Oriented datABase  (version 5.4.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) [email protected]
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,
00077                                          PatchData& pd,
00078                                          double& value_out,
00079                                          std::vector< Vector3D >& grad_out,
00080                                          MsqError& err );
00081 
00082     MESQUITE_EXPORT
00083     virtual bool evaluate_with_Hessian_diagonal( EvalType type,
00084                                                  PatchData& pd,
00085                                                  double& value_out,
00086                                                  std::vector< Vector3D >& grad_out,
00087                                                  std::vector< SymMatrix3D >& hess_diag_out,
00088                                                  MsqError& err );
00089 
00090     MESQUITE_EXPORT
00091     virtual ObjectiveFunction* clone() const;
00092 
00093     MESQUITE_EXPORT
00094     virtual void clear();
00095 
00096   private:
00097     /**\brief Handle EvalType for all eval functions, return OF value
00098      *
00099      * This function implements the common handling of the EvalType
00100      * argument for all forms of the 'evaluate' method.
00101      *
00102      * NOTE:  This function modifies accumulated values depenending
00103      *        on the value of EvalType.
00104      *\param sum        The sum over the current patch
00105      *\param sqr_sum    The sum of squares over the current patch
00106      *\param count      The number of qm evaluations for the current patch
00107      *\param type       The evaluation type passed to 'evaluate'
00108      *\param global_count The total, accumulated number of QM evaluations
00109      *\param result_sum The sum term of the variance
00110      *\param result_sqr The sum of squares term of the variance
00111      */
00112     void accumulate( double sum,
00113                      double sqr_sum,
00114                      size_t count,
00115                      EvalType type,
00116                      double& result_sum,
00117                      double& result_sqr,
00118                      size_t& global_count );
00119 
00120     size_t mCount;     /**< The number of accumulated entires */
00121     double mSum;       /**< The runnnig sum of the qualtiy metric valuse */
00122     double mSqrSum;    /**< The running sum of the square of QM values */
00123     size_t saveCount;  /**< Saved count from previous patch */
00124     double saveSum;    /**< Saved sum from previous patch */
00125     double saveSqrSum; /**< Saved sum from previous patch */
00126 
00127     /** Temporary storage for qm sample handles */
00128     mutable std::vector< size_t > qmHandles;
00129     /** Temporary storage for qm vertex indices */
00130     mutable std::vector< size_t > mIndices;
00131     /** Temporary storage for qm gradient */
00132     mutable std::vector< Vector3D > mGradient, gradSum;
00133     /** Temporary storage for qm Hessian diagonal data */
00134     mutable std::vector< SymMatrix3D > mHessDiag, hessSum;
00135 };
00136 
00137 }  // namespace MBMesquite
00138 
00139 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines