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