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 TShapeSize3DB4.cpp 00028 * \brief 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #include "Mesquite.hpp" 00033 #include "TShapeSize3DB4.hpp" 00034 #include "TMPDerivs.hpp" 00035 #include "MsqError.hpp" 00036 00037 #include <iostream> 00038 00039 namespace MBMesquite 00040 { 00041 00042 std::string TShapeSize3DB4::get_name() const 00043 { 00044 return "TShapeSize3DB4"; 00045 } 00046 00047 TShapeSize3DB4::~TShapeSize3DB4() {} 00048 00049 bool TShapeSize3DB4::evaluate( const MsqMatrix< 3, 3 >& T, double& result, MsqError& err ) 00050 { 00051 const double tau = det( T ); 00052 if( invalid_determinant( tau ) ) 00053 { // barrier 00054 MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED ); 00055 return false; 00056 } 00057 00058 const double norm = Frobenius( T ); 00059 result = norm * norm * norm / ( 3 * MSQ_SQRT_THREE * tau ) - 1 + mGamma * ( tau + 1 / tau - 2 ); 00060 return true; 00061 } 00062 00063 bool TShapeSize3DB4::evaluate_with_grad( const MsqMatrix< 3, 3 >& T, 00064 double& result, 00065 MsqMatrix< 3, 3 >& deriv, 00066 MsqError& err ) 00067 { 00068 const double tau = det( T ); 00069 if( invalid_determinant( tau ) ) 00070 { // barrier 00071 MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED ); 00072 return false; 00073 } 00074 00075 const double norm = Frobenius( T ); 00076 const double f = norm * norm / 3.0; 00077 const double g = norm / ( MSQ_SQRT_THREE * tau ); 00078 const double inv_tau = 1.0 / tau; 00079 result = f * g - 1 + mGamma * ( tau + inv_tau - 2 ); 00080 00081 deriv = g * T; 00082 deriv += ( mGamma * ( 1 - inv_tau * inv_tau ) - f * g * inv_tau ) * transpose_adj( T ); 00083 00084 return true; 00085 } 00086 00087 bool TShapeSize3DB4::evaluate_with_hess( const MsqMatrix< 3, 3 >& T, 00088 double& result, 00089 MsqMatrix< 3, 3 >& deriv, 00090 MsqMatrix< 3, 3 > second[6], 00091 MsqError& err ) 00092 { 00093 const double tau = det( T ); 00094 if( invalid_determinant( tau ) ) 00095 { // barrier 00096 MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED ); 00097 return false; 00098 } 00099 00100 const double norm = Frobenius( T ); 00101 const double f = norm * norm / 3.0; 00102 const double h = 1 / ( MSQ_SQRT_THREE * tau ); 00103 const double g = norm * h; 00104 const double inv_tau = 1.0 / tau; 00105 result = f * g - 1 + mGamma * ( tau + inv_tau - 2 ); 00106 00107 const double g1 = mGamma * ( 1 - inv_tau * inv_tau ); 00108 const MsqMatrix< 3, 3 > adjt = transpose_adj( T ); 00109 deriv = g * T; 00110 deriv += ( g1 - f * g * inv_tau ) * adjt; 00111 00112 if( norm > 1e-50 ) 00113 { 00114 const double inv_norm = 1 / norm; 00115 set_scaled_outer_product( second, h * inv_norm, T ); 00116 pluseq_scaled_I( second, norm * h ); 00117 pluseq_scaled_2nd_deriv_of_det( second, g1 - f * g * inv_tau, T ); 00118 pluseq_scaled_outer_product( second, ( f * g + mGamma * inv_tau ) * 2 * inv_tau * inv_tau, adjt ); 00119 pluseq_scaled_sum_outer_product( second, -g * inv_tau, T, adjt ); 00120 } 00121 else 00122 { 00123 std::cout << "Warning: Division by zero avoided in TShapeSize3DB4::evaluate_with_hess()" << std::endl; 00124 } 00125 00126 return true; 00127 } 00128 00129 } // namespace MBMesquite