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 TShape2DNB2.cpp 00028 * \brief 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #include "Mesquite.hpp" 00033 #include "TShape2DNB2.hpp" 00034 #include "MsqMatrix.hpp" 00035 #include "TMPDerivs.hpp" 00036 00037 namespace MBMesquite 00038 { 00039 00040 std::string TShape2DNB2::get_name() const 00041 { 00042 return "TShape2DNB2"; 00043 } 00044 00045 TShape2DNB2::~TShape2DNB2() {} 00046 00047 bool TShape2DNB2::evaluate( const MsqMatrix< 2, 2 >& T, double& result, MsqError& ) 00048 { 00049 const double tau = det( T ); 00050 MsqMatrix< 2, 2 > TT = transpose( T ) * T; 00051 TT( 0, 0 ) -= tau; 00052 TT( 1, 1 ) -= tau; 00053 result = sqr_Frobenius( TT ); 00054 return true; 00055 } 00056 00057 bool TShape2DNB2::evaluate_with_grad( const MsqMatrix< 2, 2 >& T, 00058 double& result, 00059 MsqMatrix< 2, 2 >& deriv_wrt_T, 00060 MsqError& /*err*/ ) 00061 { 00062 const MsqMatrix< 2, 2 > TtT = transpose( T ) * T; 00063 const double tau = det( T ); 00064 const double nTtT = sqr_Frobenius( TtT ); 00065 const double nT = sqr_Frobenius( T ); 00066 result = nTtT + 2 * tau * ( tau - nT ); 00067 00068 deriv_wrt_T = T * TtT; 00069 deriv_wrt_T -= tau * T; 00070 deriv_wrt_T += ( tau - 0.5 * nT ) * transpose_adj( T ); 00071 deriv_wrt_T *= 4; 00072 00073 return true; 00074 } 00075 00076 bool TShape2DNB2::evaluate_with_hess( const MsqMatrix< 2, 2 >& T, 00077 double& result, 00078 MsqMatrix< 2, 2 >& deriv_wrt_T, 00079 MsqMatrix< 2, 2 > second_wrt_T[3], 00080 MsqError& /*err*/ ) 00081 { 00082 const MsqMatrix< 2, 2 > TtT = transpose( T ) * T; 00083 const double tau = det( T ); 00084 const double nTtT = sqr_Frobenius( TtT ); 00085 const double nT = sqr_Frobenius( T ); 00086 result = nTtT + 2 * tau * ( tau - nT ); 00087 00088 const MsqMatrix< 2, 2 > adjt = transpose_adj( T ); 00089 deriv_wrt_T = T * TtT; 00090 deriv_wrt_T -= tau * T; 00091 deriv_wrt_T += ( tau - 0.5 * nT ) * adjt; 00092 deriv_wrt_T *= 4; 00093 00094 set_scaled_outer_product( second_wrt_T, 1, T ); 00095 second_wrt_T[1] = transpose( second_wrt_T[1] ); 00096 second_wrt_T[0] += TtT; 00097 second_wrt_T[2] += TtT; 00098 const MsqMatrix< 2, 2 > TTt = T * transpose( T ); 00099 second_wrt_T[0]( 0, 0 ) += TTt( 0, 0 ); 00100 second_wrt_T[0]( 1, 1 ) += TTt( 0, 0 ); 00101 second_wrt_T[1]( 0, 0 ) += TTt( 0, 1 ); 00102 second_wrt_T[1]( 1, 1 ) += TTt( 0, 1 ); 00103 second_wrt_T[2]( 0, 0 ) += TTt( 1, 1 ); 00104 second_wrt_T[2]( 1, 1 ) += TTt( 1, 1 ); 00105 00106 pluseq_scaled_I( second_wrt_T, -tau ); 00107 pluseq_scaled_2nd_deriv_of_det( second_wrt_T, -0.5 * nT ); 00108 pluseq_scaled_sum_outer_product( second_wrt_T, -1, T, adjt ); 00109 00110 pluseq_scaled_2nd_deriv_of_det( second_wrt_T, tau ); 00111 pluseq_scaled_outer_product( second_wrt_T, 1, adjt ); 00112 00113 second_wrt_T[1] *= 4; 00114 second_wrt_T[0] *= 4; 00115 second_wrt_T[2] *= 4; 00116 00117 return true; 00118 } 00119 00120 } // namespace MBMesquite