MOAB: Mesh Oriented datABase
(version 5.4.1)
|
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) [email protected] 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, 00065 const MsqMatrix< 2, 2 >& W, 00066 double& result, 00067 MsqError& err ); 00068 00069 /**\brief Evaluate \f$\mu(A,W)\f$ 00070 * 00071 *\param A 3x3 active matrix 00072 *\param W 3x3 target matrix 00073 *\param result Output: value of function 00074 *\return false if function cannot be evaluated for given A and W 00075 * (e.g. division by zero, etc.), true otherwise. 00076 */ 00077 MESQUITE_EXPORT virtual bool evaluate( const MsqMatrix< 3, 3 >& A, 00078 const MsqMatrix< 3, 3 >& W, 00079 double& result, 00080 MsqError& err ); 00081 00082 /**\brief Gradient of \f$\mu(A,W)\f$ with respect to components of A 00083 * 00084 *\param A 2x2 active matrix 00085 *\param W 2x2 target matrix 00086 *\param result Output: value of function 00087 *\param deriv_wrt_A Output: partial deriviatve of \f$\mu\f$ wrt each term of A, 00088 * evaluated at passed A. 00089 * \f[\left[\begin{array}{cc} 00090 * \frac{\partial\mu}{\partial A_{0,0}} & 00091 * \frac{\partial\mu}{\partial A_{0,1}} \\ 00092 * \frac{\partial\mu}{\partial A_{1,0}} & 00093 * \frac{\partial\mu}{\partial A_{1,1}} \\ 00094 * \end{array}\right]\f] 00095 *\return false if function cannot be evaluated for given A and W 00096 * (e.g. division by zero, etc.), true otherwise. 00097 */ 00098 MESQUITE_EXPORT virtual bool evaluate_with_grad( const MsqMatrix< 2, 2 >& A, 00099 const MsqMatrix< 2, 2 >& W, 00100 double& result, 00101 MsqMatrix< 2, 2 >& deriv_wrt_A, 00102 MsqError& err ); 00103 00104 /**\brief Gradient of \f$\mu(A,W)\f$ with respect to components of A 00105 * 00106 *\param A 3x3 active matrix 00107 *\param W 3x3 target matrix 00108 *\param result Output: value of function 00109 *\param deriv_wrt_A Output: partial deriviatve of \f$\mu\f$ wrt each term of A, 00110 * evaluated at passed A. 00111 * \f[\left[\begin{array}{ccc} 00112 * \frac{\partial\mu}{\partial A_{0,0}} & 00113 * \frac{\partial\mu}{\partial A_{0,1}} & 00114 * \frac{\partial\mu}{\partial A_{0,2}} \\ 00115 * \frac{\partial\mu}{\partial A_{1,0}} & 00116 * \frac{\partial\mu}{\partial A_{1,1}} & 00117 * \frac{\partial\mu}{\partial A_{1,2}} \\ 00118 * \frac{\partial\mu}{\partial A_{2,0}} & 00119 * \frac{\partial\mu}{\partial A_{2,1}} & 00120 * \frac{\partial\mu}{\partial A_{2,2}} 00121 * \end{array}\right]\f] 00122 *\return false if function cannot be evaluated for given A and W 00123 * (e.g. division by zero, etc.), true otherwise. 00124 */ 00125 MESQUITE_EXPORT virtual bool evaluate_with_grad( const MsqMatrix< 3, 3 >& A, 00126 const MsqMatrix< 3, 3 >& W, 00127 double& result, 00128 MsqMatrix< 3, 3 >& deriv_wrt_A, 00129 MsqError& err ); 00130 00131 /**\brief Hessian of \f$\mu(A,W)\f$ with respect to components of A 00132 * 00133 *\param A 2x2 active matrix 00134 *\param W 2x2 target matrix 00135 *\param result Output: value of function 00136 *\param deriv_wrt_A Output: partial deriviatve of \f$\mu\f$ wrt each term of A, 00137 * evaluated at passed A. 00138 *\param second_wrt_A Output: 4x4 matrix of second partial deriviatve of \f$\mu\f$ wrt 00139 * each term of A, in row-major order. The symmetric 00140 * matrix is decomposed into 2x2 blocks and only the upper diagonal 00141 * blocks, in row-major order, are returned. 00142 * \f[\left[\begin{array}{cc|cc} 00143 * \frac{\partial^{2}\mu}{\partial A_{0,0}^2} & 00144 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,1}} & 00145 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{1,0}} & 00146 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{1,1}} \\ 00147 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,1}} & 00148 * \frac{\partial^{2}\mu}{\partial A_{0,1}^2} & 00149 * \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{1,0}} & 00150 * \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{1,1}} \\ 00151 * \hline & & 00152 * \frac{\partial^{2}\mu}{\partial A_{1,0}^2} & 00153 * \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,1}} \\ 00154 * & & 00155 * \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,1}} & 00156 * \frac{\partial^{2}\mu}{\partial A_{1,1}^2} \\ 00157 * \end{array}\right]\f] 00158 * 00159 *\return false if function cannot be evaluated for given A and W 00160 * (e.g. division by zero, etc.), true otherwise. 00161 */ 00162 MESQUITE_EXPORT virtual bool evaluate_with_hess( const MsqMatrix< 2, 2 >& A, 00163 const MsqMatrix< 2, 2 >& W, 00164 double& result, 00165 MsqMatrix< 2, 2 >& deriv_wrt_A, 00166 MsqMatrix< 2, 2 > second_wrt_A[3], 00167 MsqError& err ); 00168 00169 /**\brief Hessian of \f$\mu(A,W)\f$ with respect to components of A 00170 * 00171 *\param A 3x3 active matrix 00172 *\param W 3x3 target matrix 00173 *\param result Output: value of function 00174 *\param deriv_wrt_A Output: partial deriviatve of \f$\mu\f$ wrt each term of A, 00175 * evaluated at passed A. 00176 *\param second_wrt_A Output: 9x9 matrix of second partial deriviatve of \f$\mu\f$ wrt 00177 * each term of A, in row-major order. The symmetric 00178 * matrix is decomposed into 3x3 blocks and only the upper diagonal 00179 * blocks, in row-major order, are returned. 00180 * \f[\left[\begin{array}{ccc|ccc|ccc} 00181 * \frac{\partial^{2}\mu}{\partial A_{0,0}^2} & 00182 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,1}} & 00183 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,2}} & 00184 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{1,0}} & 00185 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{1,1}} & 00186 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{1,2}} & 00187 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{2,0}} & 00188 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{2,1}} & 00189 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{2,2}} \\ 00190 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,1}} & 00191 * \frac{\partial^{2}\mu}{\partial A_{0,1}^2} & 00192 * \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{0,2}} & 00193 * \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{1,0}} & 00194 * \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{1,1}} & 00195 * \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{1,2}} & 00196 * \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{2,0}} & 00197 * \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{2,1}} & 00198 * \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{2,2}} \\ 00199 * \frac{\partial^{2}\mu}{\partial A_{0,0}\partial A_{0,2}} & 00200 * \frac{\partial^{2}\mu}{\partial A_{0,1}\partial A_{0,2}} & 00201 * \frac{\partial^{2}\mu}{\partial A_{0,2}^2} & 00202 * \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{1,0}} & 00203 * \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{1,1}} & 00204 * \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{1,2}} & 00205 * \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{2,0}} & 00206 * \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{2,1}} & 00207 * \frac{\partial^{2}\mu}{\partial A_{0,2}\partial A_{2,2}} \\ 00208 * \hline & & & 00209 * \frac{\partial^{2}\mu}{\partial A_{1,0}^2} & 00210 * \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,1}} & 00211 * \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,2}} & 00212 * \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{2,0}} & 00213 * \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{2,1}} & 00214 * \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{2,2}} \\ 00215 * & & & 00216 * \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,1}} & 00217 * \frac{\partial^{2}\mu}{\partial A_{1,1}^2} & 00218 * \frac{\partial^{2}\mu}{\partial A_{1,1}\partial A_{1,2}} & 00219 * \frac{\partial^{2}\mu}{\partial A_{1,1}\partial A_{2,0}} & 00220 * \frac{\partial^{2}\mu}{\partial A_{1,1}\partial A_{2,1}} & 00221 * \frac{\partial^{2}\mu}{\partial A_{1,1}\partial A_{2,2}} \\ 00222 * & & & 00223 * \frac{\partial^{2}\mu}{\partial A_{1,0}\partial A_{1,2}} & 00224 * \frac{\partial^{2}\mu}{\partial A_{1,1}\partial A_{1,2}} & 00225 * \frac{\partial^{2}\mu}{\partial A_{1,2}^2} & 00226 * \frac{\partial^{2}\mu}{\partial A_{1,2}\partial A_{2,0}} & 00227 * \frac{\partial^{2}\mu}{\partial A_{1,2}\partial A_{2,1}} & 00228 * \frac{\partial^{2}\mu}{\partial A_{1,2}\partial A_{2,2}} \\ 00229 * \hline & & & & & & 00230 * \frac{\partial^{2}\mu}{\partial A_{2,0}^2} & 00231 * \frac{\partial^{2}\mu}{\partial A_{2,0}\partial A_{2,1}} & 00232 * \frac{\partial^{2}\mu}{\partial A_{2,0}\partial A_{2,2}} \\ 00233 * & & & & & & 00234 * \frac{\partial^{2}\mu}{\partial A_{2,0}\partial A_{2,1}} & 00235 * \frac{\partial^{2}\mu}{\partial A_{2,1}^2} & 00236 * \frac{\partial^{2}\mu}{\partial A_{2,1}\partial A_{2,2}} \\ 00237 * & & & & & & 00238 * \frac{\partial^{2}\mu}{\partial A_{2,0}\partial A_{2,2}} & 00239 * \frac{\partial^{2}\mu}{\partial A_{2,1}\partial A_{2,2}} & 00240 * \frac{\partial^{2}\mu}{\partial A_{2,2}^2} \\ 00241 * \end{array}\right]\f] 00242 * 00243 *\return false if function cannot be evaluated for given A and W 00244 * (e.g. division by zero, etc.), true otherwise. 00245 */ 00246 MESQUITE_EXPORT virtual bool evaluate_with_hess( const MsqMatrix< 3, 3 >& A, 00247 const MsqMatrix< 3, 3 >& W, 00248 double& result, 00249 MsqMatrix< 3, 3 >& deriv_wrt_A, 00250 MsqMatrix< 3, 3 > second_wrt_A[6], 00251 MsqError& err ); 00252 00253 static inline bool invalid_determinant( double d ) 00254 { 00255 return d < 1e-12; 00256 } 00257 }; 00258 00259 class AWMetric2D : public AWMetric 00260 { 00261 public: 00262 MESQUITE_EXPORT virtual ~AWMetric2D(); 00263 00264 /**\brief Evaluate \f$\mu(A,W)\f$ 00265 * 00266 * This method always returns an error for 2D-only metrics 00267 */ 00268 MESQUITE_EXPORT virtual bool evaluate( const MsqMatrix< 3, 3 >& A, 00269 const MsqMatrix< 3, 3 >& W, 00270 double& result, 00271 MsqError& err ); 00272 }; 00273 00274 class AWMetric3D : public AWMetric 00275 { 00276 public: 00277 MESQUITE_EXPORT virtual ~AWMetric3D(); 00278 00279 /**\brief Evaluate \f$\mu(A,W)\f$ 00280 * 00281 * This method always returns an error for 3D-only metrics 00282 */ 00283 MESQUITE_EXPORT virtual bool evaluate( const MsqMatrix< 2, 2 >& A, 00284 const MsqMatrix< 2, 2 >& W, 00285 double& result, 00286 MsqError& err ); 00287 }; 00288 00289 } // namespace MBMesquite 00290 00291 #endif