MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2009 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 (2009) [email protected] 00024 00025 ***************************************************************** */ 00026 00027 /** \file TShape3DB2.cpp 00028 * \brief 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #include "Mesquite.hpp" 00033 #include "TShape3DB2.hpp" 00034 #include "MsqMatrix.hpp" 00035 #include "MsqError.hpp" 00036 #include "TMPDerivs.hpp" 00037 00038 namespace MBMesquite 00039 { 00040 00041 TShape3DB2::~TShape3DB2() {} 00042 00043 std::string TShape3DB2::get_name() const 00044 { 00045 return "TShape3DB2"; 00046 } 00047 00048 // \mu_3(T) = \frac{ |T|^2 |adj(T)|^2 } {9 \tau^2} - 1 00049 bool TShape3DB2::evaluate( const MsqMatrix< 3, 3 >& T, double& result, MsqError& err ) 00050 { 00051 double f = sqr_Frobenius( T ); 00052 double g = sqr_Frobenius( adj( T ) ); 00053 double d = det( T ); 00054 if( invalid_determinant( d ) ) 00055 { 00056 MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED ); 00057 return false; 00058 } 00059 result = ( f * g ) / ( 9 * d * d ) - 1; 00060 return true; 00061 } 00062 00063 bool TShape3DB2::evaluate_with_grad( const MsqMatrix< 3, 3 >& T, 00064 double& result, 00065 MsqMatrix< 3, 3 >& wrt_T, 00066 MsqError& err ) 00067 { 00068 double f = sqr_Frobenius( T ); 00069 double g = sqr_Frobenius( adj( T ) ); 00070 double d = det( T ); 00071 if( invalid_determinant( d ) ) 00072 { 00073 MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED ); 00074 return false; 00075 } 00076 result = ( f * g ) / ( 9 * d * d ) - 1; 00077 00078 wrt_T = T; 00079 wrt_T *= ( g + f * f ); 00080 wrt_T -= f * ( T * transpose( T ) * T ); 00081 wrt_T -= f * g / d * transpose_adj( T ); 00082 wrt_T *= 2 / ( 9 * d * d ); 00083 00084 return true; 00085 } 00086 00087 bool TShape3DB2::evaluate_with_hess( const MsqMatrix< 3, 3 >& T, 00088 double& result, 00089 MsqMatrix< 3, 3 >& wrt_T, 00090 MsqMatrix< 3, 3 > second[6], 00091 MsqError& err ) 00092 { 00093 double f = sqr_Frobenius( T ); 00094 double g = sqr_Frobenius( adj( T ) ); 00095 double d = det( T ); 00096 if( invalid_determinant( d ) ) 00097 { 00098 MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED ); 00099 return false; 00100 } 00101 const double den = 1.0 / ( 9 * d * d ); 00102 result = f * g * den - 1; 00103 00104 MsqMatrix< 3, 3 > dg = 2 * ( f * T - T * transpose( T ) * T ); 00105 MsqMatrix< 3, 3 > df = 2 * T; 00106 MsqMatrix< 3, 3 > dtau = transpose_adj( T ); 00107 00108 wrt_T = g * df + f * dg - 2 * f * g / d * transpose_adj( T ); 00109 wrt_T *= den; 00110 00111 set_scaled_2nd_deriv_norm_sqr_adj( second, den * f, T ); 00112 pluseq_scaled_I( second, 2 * den * g ); 00113 pluseq_scaled_sum_outer_product( second, den, dg, df ); 00114 pluseq_scaled_sum_outer_product( second, -2 * den * g / d, df, dtau ); 00115 pluseq_scaled_sum_outer_product( second, -2 * den * f / d, dg, dtau ); 00116 pluseq_scaled_outer_product( second, 6 * den * f * g / ( d * d ), dtau ); 00117 pluseq_scaled_2nd_deriv_of_det( second, -2 * den * f * g / d, T ); 00118 00119 return true; 00120 } 00121 00122 } // namespace MBMesquite