MOAB: Mesh Oriented datABase  (version 5.2.1)
AWMetric.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 AWMetric.hpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #ifndef MSQ_AW_METRIC_HPP
00033 #define MSQ_AW_METRIC_HPP
00034 
00035 #include "Mesquite.hpp"
00036 #include <string>
00037 
00038 namespace MBMesquite
00039 {
00040 
00041 class MsqError;
00042 template < unsigned R, unsigned C >
00043 class MsqMatrix;
00044 
00045 /**\brief A metric for comparing a matrix A with a target matrix W
00046  *
00047  * Implement a scalar function \f$\mu(A,W)\f$ where A and W are 2x2 or 3x3 matrices.
00048  */
00049 class AWMetric
00050 {
00051   public:
00052     MESQUITE_EXPORT virtual ~AWMetric();
00053 
00054     MESQUITE_EXPORT virtual std::string get_name() const = 0;
00055 
00056     /**\brief Evaluate \f$\mu(A,W)\f$
00057      *
00058      *\param A 2x2 active matrix
00059      *\param W 2x2 target matrix
00060      *\param result Output: value of function
00061      *\return false if function cannot be evaluated for given A and W
00062      *          (e.g. division by zero, etc.), true otherwise.
00063      */
00064     MESQUITE_EXPORT virtual bool evaluate( const MsqMatrix< 2, 2 >& A, const MsqMatrix< 2, 2 >& W, double& result,
00065                                            MsqError& err );
00066 
00067     /**\brief Evaluate \f$\mu(A,W)\f$
00068      *
00069      *\param A 3x3 active matrix
00070      *\param W 3x3 target matrix
00071      *\param result Output: value of function
00072      *\return false if function cannot be evaluated for given A and W
00073      *          (e.g. division by zero, etc.), true otherwise.
00074      */
00075     MESQUITE_EXPORT virtual bool evaluate( const MsqMatrix< 3, 3 >& A, const MsqMatrix< 3, 3 >& W, double& result,
00076                                            MsqError& err );
00077 
00078     /**\brief Gradient of \f$\mu(A,W)\f$ with respect to components of A
00079      *
00080      *\param A 2x2 active matrix
00081      *\param W 2x2 target matrix
00082      *\param result Output: value of function
00083      *\param deriv_wrt_A Output: partial deriviatve of \f$\mu\f$ wrt each term of A,
00084      *                           evaluated at passed A.
00085      *                           \f[\left[\begin{array}{cc}
00086      *                            \frac{\partial\mu}{\partial A_{0,0}} &
00087      *                            \frac{\partial\mu}{\partial A_{0,1}} \\
00088      *                            \frac{\partial\mu}{\partial A_{1,0}} &
00089      *                            \frac{\partial\mu}{\partial A_{1,1}} \\
00090      *                            \end{array}\right]\f]
00091      *\return false if function cannot be evaluated for given A and W
00092      *          (e.g. division by zero, etc.), true otherwise.
00093      */
00094     MESQUITE_EXPORT virtual bool evaluate_with_grad( const MsqMatrix< 2, 2 >& A, const MsqMatrix< 2, 2 >& W,
00095                                                      double& result, MsqMatrix< 2, 2 >& deriv_wrt_A, MsqError& err );
00096 
00097     /**\brief Gradient of \f$\mu(A,W)\f$ with respect to components of A
00098      *
00099      *\param A 3x3 active matrix
00100      *\param W 3x3 target matrix
00101      *\param result Output: value of function
00102      *\param deriv_wrt_A Output: partial deriviatve of \f$\mu\f$ wrt each term of A,
00103      *                           evaluated at passed A.
00104      *                           \f[\left[\begin{array}{ccc}
00105      *                            \frac{\partial\mu}{\partial A_{0,0}} &
00106      *                            \frac{\partial\mu}{\partial A_{0,1}} &
00107      *                            \frac{\partial\mu}{\partial A_{0,2}} \\
00108      *                            \frac{\partial\mu}{\partial A_{1,0}} &
00109      *                            \frac{\partial\mu}{\partial A_{1,1}} &
00110      *                            \frac{\partial\mu}{\partial A_{1,2}} \\
00111      *                            \frac{\partial\mu}{\partial A_{2,0}} &
00112      *                            \frac{\partial\mu}{\partial A_{2,1}} &
00113      *                            \frac{\partial\mu}{\partial A_{2,2}}
00114      *                            \end{array}\right]\f]
00115      *\return false if function cannot be evaluated for given A and W
00116      *          (e.g. division by zero, etc.), true otherwise.
00117      */
00118     MESQUITE_EXPORT virtual bool evaluate_with_grad( const MsqMatrix< 3, 3 >& A, const MsqMatrix< 3, 3 >& W,
00119                                                      double& result, MsqMatrix< 3, 3 >& deriv_wrt_A, MsqError& err );
00120 
00121     /**\brief Hessian of \f$\mu(A,W)\f$ with respect to components of A
00122      *
00123      *\param A 2x2 active matrix
00124      *\param W 2x2 target matrix
00125      *\param result Output: value of function
00126      *\param deriv_wrt_A Output: partial deriviatve of \f$\mu\f$ wrt each term of A,
00127      *                           evaluated at passed A.
00128      *\param second_wrt_A Output: 4x4 matrix of second partial deriviatve of \f$\mu\f$ wrt
00129      *                           each term of A, in row-major order.  The symmetric
00130      *                           matrix is decomposed into 2x2 blocks and only the upper diagonal
00131      *                           blocks, in row-major order, are returned.
00132      *                           \f[\left[\begin{array}{cc|cc}
00133      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}^2} &
00134      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,1}} &
00135      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{1,0}} &
00136      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{1,1}} \\
00137      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,1}} &
00138      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}^2} &
00139      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{1,0}} &
00140      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{1,1}} \\
00141      *                           \hline & &
00142      *                           \frac{\partial^{2}\mu}{\partial A_{1,0}^2} &
00143      *                           \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,1}} \\
00144      *                           & &
00145      *                           \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,1}} &
00146      *                           \frac{\partial^{2}\mu}{\partial A_{1,1}^2} \\
00147      *                            \end{array}\right]\f]
00148      *
00149      *\return false if function cannot be evaluated for given A and W
00150      *          (e.g. division by zero, etc.), true otherwise.
00151      */
00152     MESQUITE_EXPORT virtual bool evaluate_with_hess( const MsqMatrix< 2, 2 >& A, const MsqMatrix< 2, 2 >& W,
00153                                                      double& result, MsqMatrix< 2, 2 >& deriv_wrt_A,
00154                                                      MsqMatrix< 2, 2 > second_wrt_A[3], MsqError& err );
00155 
00156     /**\brief Hessian of \f$\mu(A,W)\f$ with respect to components of A
00157      *
00158      *\param A 3x3 active matrix
00159      *\param W 3x3 target matrix
00160      *\param result Output: value of function
00161      *\param deriv_wrt_A Output: partial deriviatve of \f$\mu\f$ wrt each term of A,
00162      *                           evaluated at passed A.
00163      *\param second_wrt_A Output: 9x9 matrix of second partial deriviatve of \f$\mu\f$ wrt
00164      *                           each term of A, in row-major order.  The symmetric
00165      *                           matrix is decomposed into 3x3 blocks and only the upper diagonal
00166      *                           blocks, in row-major order, are returned.
00167      *                           \f[\left[\begin{array}{ccc|ccc|ccc}
00168      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}^2} &
00169      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,1}} &
00170      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,2}} &
00171      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{1,0}} &
00172      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{1,1}} &
00173      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{1,2}} &
00174      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{2,0}} &
00175      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{2,1}} &
00176      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{2,2}} \\
00177      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,1}} &
00178      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}^2} &
00179      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{0,2}} &
00180      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{1,0}} &
00181      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{1,1}} &
00182      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{1,2}} &
00183      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{2,0}} &
00184      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{2,1}} &
00185      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{2,2}} \\
00186      *                           \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,2}} &
00187      *                           \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{0,2}} &
00188      *                           \frac{\partial^{2}\mu}{\partial A_{0,2}^2} &
00189      *                           \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{1,0}} &
00190      *                           \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{1,1}} &
00191      *                           \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{1,2}} &
00192      *                           \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{2,0}} &
00193      *                           \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{2,1}} &
00194      *                           \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{2,2}} \\
00195      *                           \hline & & &
00196      *                           \frac{\partial^{2}\mu}{\partial A_{1,0}^2} &
00197      *                           \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,1}} &
00198      *                           \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,2}} &
00199      *                           \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{2,0}} &
00200      *                           \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{2,1}} &
00201      *                           \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{2,2}} \\
00202      *                           & & &
00203      *                           \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,1}} &
00204      *                           \frac{\partial^{2}\mu}{\partial A_{1,1}^2} &
00205      *                           \frac{\partial^{2}\mu}{\partial A_{1,1}\partial A_{1,2}} &
00206      *                           \frac{\partial^{2}\mu}{\partial A_{1,1}\partial A_{2,0}} &
00207      *                           \frac{\partial^{2}\mu}{\partial A_{1,1}\partial A_{2,1}} &
00208      *                           \frac{\partial^{2}\mu}{\partial A_{1,1}\partial A_{2,2}} \\
00209      *                           & & &
00210      *                           \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,2}} &
00211      *                           \frac{\partial^{2}\mu}{\partial A_{1,1}\partial A_{1,2}} &
00212      *                           \frac{\partial^{2}\mu}{\partial A_{1,2}^2} &
00213      *                           \frac{\partial^{2}\mu}{\partial A_{1,2}\partial A_{2,0}} &
00214      *                           \frac{\partial^{2}\mu}{\partial A_{1,2}\partial A_{2,1}} &
00215      *                           \frac{\partial^{2}\mu}{\partial A_{1,2}\partial A_{2,2}} \\
00216      *                           \hline & & & & & &
00217      *                           \frac{\partial^{2}\mu}{\partial A_{2,0}^2} &
00218      *                           \frac{\partial^{2}\mu}{\partial A_{2,0}\partial A_{2,1}} &
00219      *                           \frac{\partial^{2}\mu}{\partial A_{2,0}\partial A_{2,2}} \\
00220      *                           & & & & & &
00221      *                           \frac{\partial^{2}\mu}{\partial A_{2,0}\partial A_{2,1}} &
00222      *                           \frac{\partial^{2}\mu}{\partial A_{2,1}^2} &
00223      *                           \frac{\partial^{2}\mu}{\partial A_{2,1}\partial A_{2,2}} \\
00224      *                           & & & & & &
00225      *                           \frac{\partial^{2}\mu}{\partial A_{2,0}\partial A_{2,2}} &
00226      *                           \frac{\partial^{2}\mu}{\partial A_{2,1}\partial A_{2,2}} &
00227      *                           \frac{\partial^{2}\mu}{\partial A_{2,2}^2} \\
00228      *                            \end{array}\right]\f]
00229      *
00230      *\return false if function cannot be evaluated for given A and W
00231      *          (e.g. division by zero, etc.), true otherwise.
00232      */
00233     MESQUITE_EXPORT virtual bool evaluate_with_hess( const MsqMatrix< 3, 3 >& A, const MsqMatrix< 3, 3 >& W,
00234                                                      double& result, MsqMatrix< 3, 3 >& deriv_wrt_A,
00235                                                      MsqMatrix< 3, 3 > second_wrt_A[6], MsqError& err );
00236 
00237     static inline bool invalid_determinant( double d )
00238     {
00239         return d < 1e-12;
00240     }
00241 };
00242 
00243 class AWMetric2D : public AWMetric
00244 {
00245   public:
00246     MESQUITE_EXPORT virtual ~AWMetric2D();
00247 
00248     /**\brief Evaluate \f$\mu(A,W)\f$
00249      *
00250      * This method always returns an error for 2D-only metrics
00251      */
00252     MESQUITE_EXPORT virtual bool evaluate( const MsqMatrix< 3, 3 >& A, const MsqMatrix< 3, 3 >& W, double& result,
00253                                            MsqError& err );
00254 };
00255 
00256 class AWMetric3D : public AWMetric
00257 {
00258   public:
00259     MESQUITE_EXPORT virtual ~AWMetric3D();
00260 
00261     /**\brief Evaluate \f$\mu(A,W)\f$
00262      *
00263      * This method always returns an error for 3D-only metrics
00264      */
00265     MESQUITE_EXPORT virtual bool evaluate( const MsqMatrix< 2, 2 >& A, const MsqMatrix< 2, 2 >& W, double& result,
00266                                            MsqError& err );
00267 };
00268 
00269 }  // namespace MBMesquite
00270 
00271 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines