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