MOAB: Mesh Oriented datABase  (version 5.4.1)
TMPCommon.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 TMPCommon.hpp
00028  *  \brief Common utility stuff for implementing target metrics
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #ifndef MSQ_TMP_COMMON_HPP
00033 #define MSQ_TMP_COMMON_HPP
00034 
00035 #include "Mesquite.hpp"
00036 
00037 namespace MBMesquite
00038 {
00039 
00040 /**\def TMP_T_TEMPL_IMPL_COMMON(N)
00041  * \brief A macro that declares virtual evaluation functions for a \c TMetric subclass \c N
00042  *
00043  * IF a \c TMetric class provides template functions named \c eval, \c grad,
00044  * and \c hess, then this macro can be used to provide the trivial implementations
00045  * of the 2D and 3D \c evaluate, \c evaluate_with_grad, and \c evaluate_with_hess virtual
00046  * member functions in terms of those macros.
00047  */
00048 
00049 #define TMP_T_TEMPL_IMPL_DIM( N, D )                                                                                 \
00050     bool N::evaluate( const MsqMatrix< D, D >& T, double& r, MsqError& )                                             \
00051     {                                                                                                                \
00052         return eval( T, r );                                                                                         \
00053     }                                                                                                                \
00054     bool N::evaluate_with_grad( const MsqMatrix< D, D >& T, double& r, MsqMatrix< D, D >& d1, MsqError& )            \
00055     {                                                                                                                \
00056         return grad( T, r, d1 );                                                                                     \
00057     }                                                                                                                \
00058     bool N::evaluate_with_hess( const MsqMatrix< D, D >& T, double& r, MsqMatrix< D, D >& d1, MsqMatrix< D, D >* d2, \
00059                                 MsqError& )                                                                          \
00060     {                                                                                                                \
00061         return hess( T, r, d1, d2 );                                                                                 \
00062     }
00063 
00064 #define TMP_T_TEMPL_IMPL_COMMON( N ) \
00065     TMP_T_TEMPL_IMPL_DIM( N, 2 )     \
00066     TMP_T_TEMPL_IMPL_DIM( N, 3 )
00067 
00068 /**\def TMP_T_TEMPL_IMPL_COMMON_ERR(N)
00069  * \brief A macro that declares virtual evaluation functions for a \c TMetric subclass \c N
00070  *
00071  * IF a \c TMetric class provides template functions named \c eval, \c grad,
00072  * and \c hess, then this macro can be used to provide the trivial implementations
00073  * of the 2D and 3D \c evaluate, \c evaluate_with_grad, and \c evaluate_with_hess virtual
00074  * member functions in terms of those macros.
00075  *
00076  * The difference between this macro and \c TMP_AW_TEMPL_IMPL_COMMON is that this
00077  * variation expects the \c eval, \c grad, and \c hess to accept an \c MsqError
00078  * as their last argument.  This variation is typically used for metrics that are
00079  * a function of some other metric.
00080  */
00081 
00082 #define TMP_T_TEMPL_IMPL_ERR_DIM( N, D )                                                                             \
00083     bool N::evaluate( const MsqMatrix< D, D >& T, double& r, MsqError& err )                                         \
00084     {                                                                                                                \
00085         return eval( T, r, err );                                                                                    \
00086     }                                                                                                                \
00087     bool N::evaluate_with_grad( const MsqMatrix< D, D >& T, double& r, MsqMatrix< D, D >& d1, MsqError& err )        \
00088     {                                                                                                                \
00089         return grad( T, r, d1, err );                                                                                \
00090     }                                                                                                                \
00091     bool N::evaluate_with_hess( const MsqMatrix< D, D >& T, double& r, MsqMatrix< D, D >& d1, MsqMatrix< D, D >* d2, \
00092                                 MsqError& err )                                                                      \
00093     {                                                                                                                \
00094         return hess( T, r, d1, d2, err );                                                                            \
00095     }
00096 
00097 #define TMP_T_TEMPL_IMPL_COMMON_ERR( N ) \
00098     TMP_T_TEMPL_IMPL_ERR_DIM( N, 2 )     \
00099     TMP_T_TEMPL_IMPL_ERR_DIM( N, 3 )
00100 
00101 /**\def TMP_AW_TEMPL_IMPL_COMMON(N)
00102  * \brief A macro that declares virtual evaluation functions for a \c AWMetric subclass \c N
00103  *
00104  * IF a \c AWMetric class provides template functions named \c eval, \c grad,
00105  * and \c hess, then this macro can be used to provide the trivial implementations
00106  * of the 2D and 3D \c evaluate, \c evaluate_with_grad, and \c evaluate_with_hess virtual
00107  * member functions in terms of those macros.
00108  */
00109 
00110 #define TMP_AW_TEMPL_IMPL_DIM( N, D )                                                                \
00111     bool N::evaluate( const MsqMatrix< D, D >& A, const MsqMatrix< D, D >& W, double& r, MsqError& ) \
00112     {                                                                                                \
00113         return eval( A, W, r );                                                                      \
00114     }                                                                                                \
00115     bool N::evaluate_with_grad( const MsqMatrix< D, D >& A, const MsqMatrix< D, D >& W, double& r,   \
00116                                 MsqMatrix< D, D >& d1, MsqError& )                                   \
00117     {                                                                                                \
00118         return grad( A, W, r, d1 );                                                                  \
00119     }                                                                                                \
00120     bool N::evaluate_with_hess( const MsqMatrix< D, D >& A, const MsqMatrix< D, D >& W, double& r,   \
00121                                 MsqMatrix< D, D >& d1, MsqMatrix< D, D >* d2, MsqError& )            \
00122     {                                                                                                \
00123         return hess( A, W, r, d1, d2 );                                                              \
00124     }
00125 
00126 #define TMP_AW_TEMPL_IMPL_COMMON( N ) \
00127     TMP_AW_TEMPL_IMPL_DIM( N, 2 )     \
00128     TMP_AW_TEMPL_IMPL_DIM( N, 3 )
00129 
00130 /**\def TMP_AW_TEMPL_IMPL_COMMON(N)
00131  * \brief Like TMP_AW_TEMPL_IMPL_COMMON, except no implementation of 2nd derivs
00132  */
00133 
00134 #define TMP_AW_TEMPL_IMPL_NO2ND_DIM( N, D )                                                          \
00135     bool N::evaluate( const MsqMatrix< D, D >& A, const MsqMatrix< D, D >& W, double& r, MsqError& ) \
00136     {                                                                                                \
00137         return eval( A, W, r );                                                                      \
00138     }                                                                                                \
00139     bool N::evaluate_with_grad( const MsqMatrix< D, D >& A, const MsqMatrix< D, D >& W, double& r,   \
00140                                 MsqMatrix< D, D >& d1, MsqError& )                                   \
00141     {                                                                                                \
00142         return grad( A, W, r, d1 );                                                                  \
00143     }
00144 
00145 #define TMP_AW_TEMPL_IMPL_COMMON_NO2ND( N ) \
00146     TMP_AW_TEMPL_IMPL_NO2ND_DIM( N, 2 )     \
00147     TMP_AW_TEMPL_IMPL_NO2ND_DIM( N, 3 )
00148 
00149 /**\brief Dimension-specific constants
00150  *
00151  * Provide constants that depend on a template dimension parameter.
00152  * For use in implementing targe metrics for which the target metric
00153  * implementation is templatized on the dimension of of the matrix.
00154  *
00155  * In optimized code these should reduce to literal constants.
00156  */
00157 template < unsigned D >
00158 struct DimConst
00159 {
00160 };
00161 template <>
00162 struct DimConst< 2 >
00163 {
00164     static inline double sqrt()
00165     {
00166         return MSQ_SQRT_TWO;
00167     }
00168     static inline double inv()
00169     {
00170         return 0.5;
00171     }
00172 };
00173 template <>
00174 struct DimConst< 3 >
00175 {
00176     static inline double sqrt()
00177     {
00178         return MSQ_SQRT_THREE;
00179     }
00180     static inline double inv()
00181     {
00182         return MSQ_ONE_THIRD;
00183     }
00184 };
00185 
00186 }  // namespace MBMesquite
00187 
00188 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines