MOAB: Mesh Oriented datABase  (version 5.2.1)
CompareQM.hpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2010 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     (2010) kraftche@cae.wisc.edu
00024 
00025   ***************************************************************** */
00026 
00027 /** \file CompareQM.hpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #ifndef MSQ_COMPARE_QM_HPP
00033 #define MSQ_COMPARE_QM_HPP
00034 
00035 #include "Mesquite.hpp"
00036 #include "QualityMetric.hpp"
00037 #include "SimpleStats.hpp"
00038 
00039 namespace MBMesquite
00040 {
00041 
00042 /**\brief Compare values for two supposedly equivalent quality metrics
00043  *
00044  * Evaluate two different quality metrics during the evaluation,
00045  * comparing the results with each other and passing the results
00046  * of the primary one on to the objective function.
00047  *
00048  * Both metrics must be of the same "type", meaning that they must be
00049  * evaluated at the same sample locations in the mesh.  For example,
00050  * an error will be generated if one of the metrics is vertex based
00051  * and one is element based.  Further, both metrics must use the
00052  * same handle values to indicate their list of sample locations
00053  * such that the evaluation for a given same handle dependes on the
00054  * same vertices for both metrics.
00055  */
00056 class CompareQM : public QualityMetric
00057 {
00058   public:
00059     MESQUITE_EXPORT
00060     CompareQM( QualityMetric* primary, QualityMetric* other, const char* primary_name = 0, const char* other_name = 0 );
00061 
00062     MESQUITE_EXPORT
00063     void abort_on_mismatch( double tolerance_factor = 1e-6 );
00064 
00065     MESQUITE_EXPORT
00066     void do_not_abort();
00067 
00068     MESQUITE_EXPORT
00069     bool will_abort_on_mismatch() const;
00070 
00071     MESQUITE_EXPORT
00072     void print_stats() const;
00073 
00074     MESQUITE_EXPORT virtual ~CompareQM();
00075 
00076     MESQUITE_EXPORT virtual MetricType get_metric_type() const;
00077 
00078     MESQUITE_EXPORT virtual std::string get_name() const;
00079 
00080     MESQUITE_EXPORT virtual int get_negate_flag() const;
00081 
00082     MESQUITE_EXPORT virtual void get_evaluations( PatchData& pd, std::vector< size_t >& handles,
00083                                                   bool free_vertices_only, MsqError& err );
00084 
00085     MESQUITE_EXPORT virtual bool evaluate( PatchData& pd, size_t handle, double& value, MsqError& err );
00086 
00087     MESQUITE_EXPORT virtual bool evaluate_with_indices( PatchData& pd, size_t handle, double& value,
00088                                                         std::vector< size_t >& indices, MsqError& err );
00089 
00090     MESQUITE_EXPORT virtual bool evaluate_with_gradient( PatchData& pd, size_t handle, double& value,
00091                                                          std::vector< size_t >& indices,
00092                                                          std::vector< Vector3D >& gradient, MsqError& err );
00093 
00094     MESQUITE_EXPORT virtual bool evaluate_with_Hessian_diagonal( PatchData& pd, size_t handle, double& value,
00095                                                                  std::vector< size_t >& indices,
00096                                                                  std::vector< Vector3D >& gradient,
00097                                                                  std::vector< SymMatrix3D >& Hessian_diagonal,
00098                                                                  MsqError& err );
00099 
00100     MESQUITE_EXPORT virtual bool evaluate_with_Hessian( PatchData& pd, size_t handle, double& value,
00101                                                         std::vector< size_t >& indices,
00102                                                         std::vector< Vector3D >& gradient,
00103                                                         std::vector< Matrix3D >& Hessian, MsqError& err );
00104 
00105   private:
00106     double epsilon( double val1, double val2 );
00107 
00108     bool check_valid( size_t handle, bool valid1, bool valid2 );
00109 
00110     /** Compare values, add to stats, etc. */
00111     void check_value( size_t handle, double value1, double value2 );
00112 
00113     /** Check that two index lists are equivalent and return
00114      *  in \c map_out for each index in \c idx1 the position
00115      *  of the same index in \c idx2.
00116      */
00117     void check_indices( size_t handle, const std::vector< size_t >& idx1, const std::vector< size_t >& idx2,
00118                         std::vector< size_t >& map_out, MsqError& err );
00119 
00120     void check_grad( size_t handle, const std::vector< size_t >& indices, const std::vector< size_t >& index_map,
00121                      const std::vector< Vector3D >& grad1, const std::vector< Vector3D >& grad2 );
00122 
00123     void check_hess_diag( size_t handle, const std::vector< size_t >& indices, const std::vector< size_t >& index_map,
00124                           const std::vector< SymMatrix3D >& hess1, const std::vector< SymMatrix3D >& hess2 );
00125 
00126     void check_hess( size_t handle, const std::vector< size_t >& indices, const std::vector< size_t >& index_map,
00127                      const std::vector< Matrix3D >& hess1, const std::vector< Matrix3D >& hess2 );
00128 
00129     void index_mismatch( size_t handle, const std::vector< size_t >& idx1, const std::vector< size_t >& idx2,
00130                          MsqError& err );
00131 
00132     struct GradStat
00133     {
00134         SimpleStats x, y, z;
00135         void add( Vector3D grad );
00136         void add_diff( Vector3D grad1, Vector3D grad2 );
00137     };
00138     struct HessStat
00139     {
00140         SimpleStats xx, xy, xz, yy, yz, zz;
00141         void add_diag( Matrix3D hess );
00142         void add_diag( SymMatrix3D hess );
00143         void add_diag_diff( Matrix3D hess1, Matrix3D hess2 );
00144         void add_diag_diff( SymMatrix3D hess1, SymMatrix3D hess2 );
00145         void add_nondiag( Matrix3D hess );
00146         void add_nondiag_diff( Matrix3D hess1, Matrix3D hess2 );
00147     };
00148 
00149     std::string primaryName, otherName;
00150     QualityMetric *primaryMetric, *otherMetric;
00151     bool abortOnMismatch;
00152     double toleranceFactor;
00153     SimpleStats valPrimary, valOther, valDiff;
00154     GradStat gradPrimary, gradOther, gradDiff;
00155     HessStat hessPrimary, hessOther, hessDiff;
00156 };
00157 
00158 }  // namespace MBMesquite
00159 
00160 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines