MOAB: Mesh Oriented datABase  (version 5.4.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) [email protected]
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,
00083                                                   std::vector< size_t >& handles,
00084                                                   bool free_vertices_only,
00085                                                   MsqError& err );
00086 
00087     MESQUITE_EXPORT virtual bool evaluate( PatchData& pd, size_t handle, double& value, MsqError& err );
00088 
00089     MESQUITE_EXPORT virtual bool evaluate_with_indices( PatchData& pd,
00090                                                         size_t handle,
00091                                                         double& value,
00092                                                         std::vector< size_t >& indices,
00093                                                         MsqError& err );
00094 
00095     MESQUITE_EXPORT virtual bool evaluate_with_gradient( PatchData& pd,
00096                                                          size_t handle,
00097                                                          double& value,
00098                                                          std::vector< size_t >& indices,
00099                                                          std::vector< Vector3D >& gradient,
00100                                                          MsqError& err );
00101 
00102     MESQUITE_EXPORT virtual bool evaluate_with_Hessian_diagonal( PatchData& pd,
00103                                                                  size_t handle,
00104                                                                  double& value,
00105                                                                  std::vector< size_t >& indices,
00106                                                                  std::vector< Vector3D >& gradient,
00107                                                                  std::vector< SymMatrix3D >& Hessian_diagonal,
00108                                                                  MsqError& err );
00109 
00110     MESQUITE_EXPORT virtual bool evaluate_with_Hessian( PatchData& pd,
00111                                                         size_t handle,
00112                                                         double& value,
00113                                                         std::vector< size_t >& indices,
00114                                                         std::vector< Vector3D >& gradient,
00115                                                         std::vector< Matrix3D >& Hessian,
00116                                                         MsqError& err );
00117 
00118   private:
00119     double epsilon( double val1, double val2 );
00120 
00121     bool check_valid( size_t handle, bool valid1, bool valid2 );
00122 
00123     /** Compare values, add to stats, etc. */
00124     void check_value( size_t handle, double value1, double value2 );
00125 
00126     /** Check that two index lists are equivalent and return
00127      *  in \c map_out for each index in \c idx1 the position
00128      *  of the same index in \c idx2.
00129      */
00130     void check_indices( size_t handle,
00131                         const std::vector< size_t >& idx1,
00132                         const std::vector< size_t >& idx2,
00133                         std::vector< size_t >& map_out,
00134                         MsqError& err );
00135 
00136     void check_grad( size_t handle,
00137                      const std::vector< size_t >& indices,
00138                      const std::vector< size_t >& index_map,
00139                      const std::vector< Vector3D >& grad1,
00140                      const std::vector< Vector3D >& grad2 );
00141 
00142     void check_hess_diag( size_t handle,
00143                           const std::vector< size_t >& indices,
00144                           const std::vector< size_t >& index_map,
00145                           const std::vector< SymMatrix3D >& hess1,
00146                           const std::vector< SymMatrix3D >& hess2 );
00147 
00148     void check_hess( size_t handle,
00149                      const std::vector< size_t >& indices,
00150                      const std::vector< size_t >& index_map,
00151                      const std::vector< Matrix3D >& hess1,
00152                      const std::vector< Matrix3D >& hess2 );
00153 
00154     void index_mismatch( size_t handle,
00155                          const std::vector< size_t >& idx1,
00156                          const std::vector< size_t >& idx2,
00157                          MsqError& err );
00158 
00159     struct GradStat
00160     {
00161         SimpleStats x, y, z;
00162         void add( Vector3D grad );
00163         void add_diff( Vector3D grad1, Vector3D grad2 );
00164     };
00165     struct HessStat
00166     {
00167         SimpleStats xx, xy, xz, yy, yz, zz;
00168         void add_diag( Matrix3D hess );
00169         void add_diag( SymMatrix3D hess );
00170         void add_diag_diff( Matrix3D hess1, Matrix3D hess2 );
00171         void add_diag_diff( SymMatrix3D hess1, SymMatrix3D hess2 );
00172         void add_nondiag( Matrix3D hess );
00173         void add_nondiag_diff( Matrix3D hess1, Matrix3D hess2 );
00174     };
00175 
00176     std::string primaryName, otherName;
00177     QualityMetric *primaryMetric, *otherMetric;
00178     bool abortOnMismatch;
00179     double toleranceFactor;
00180     SimpleStats valPrimary, valOther, valDiff;
00181     GradStat gradPrimary, gradOther, gradDiff;
00182     HessStat hessPrimary, hessOther, hessDiff;
00183 };
00184 
00185 }  // namespace MBMesquite
00186 
00187 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines