MOAB: Mesh Oriented datABase  (version 5.2.1)
TShape2DNB2.cpp
Go to the documentation of this file.
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) kraftche@cae.wisc.edu
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, double& result, MsqMatrix< 2, 2 >& deriv_wrt_T,
00058                                       MsqError& /*err*/ )
00059 {
00060     const MsqMatrix< 2, 2 > TtT = transpose( T ) * T;
00061     const double tau            = det( T );
00062     const double nTtT           = sqr_Frobenius( TtT );
00063     const double nT             = sqr_Frobenius( T );
00064     result                      = nTtT + 2 * tau * ( tau - nT );
00065 
00066     deriv_wrt_T = T * TtT;
00067     deriv_wrt_T -= tau * T;
00068     deriv_wrt_T += ( tau - 0.5 * nT ) * transpose_adj( T );
00069     deriv_wrt_T *= 4;
00070 
00071     return true;
00072 }
00073 
00074 bool TShape2DNB2::evaluate_with_hess( const MsqMatrix< 2, 2 >& T, double& result, MsqMatrix< 2, 2 >& deriv_wrt_T,
00075                                       MsqMatrix< 2, 2 > second_wrt_T[3], MsqError& /*err*/ )
00076 {
00077     const MsqMatrix< 2, 2 > TtT = transpose( T ) * T;
00078     const double tau            = det( T );
00079     const double nTtT           = sqr_Frobenius( TtT );
00080     const double nT             = sqr_Frobenius( T );
00081     result                      = nTtT + 2 * tau * ( tau - nT );
00082 
00083     const MsqMatrix< 2, 2 > adjt = transpose_adj( T );
00084     deriv_wrt_T                  = T * TtT;
00085     deriv_wrt_T -= tau * T;
00086     deriv_wrt_T += ( tau - 0.5 * nT ) * adjt;
00087     deriv_wrt_T *= 4;
00088 
00089     set_scaled_outer_product( second_wrt_T, 1, T );
00090     second_wrt_T[1] = transpose( second_wrt_T[1] );
00091     second_wrt_T[0] += TtT;
00092     second_wrt_T[2] += TtT;
00093     const MsqMatrix< 2, 2 > TTt = T * transpose( T );
00094     second_wrt_T[0]( 0, 0 ) += TTt( 0, 0 );
00095     second_wrt_T[0]( 1, 1 ) += TTt( 0, 0 );
00096     second_wrt_T[1]( 0, 0 ) += TTt( 0, 1 );
00097     second_wrt_T[1]( 1, 1 ) += TTt( 0, 1 );
00098     second_wrt_T[2]( 0, 0 ) += TTt( 1, 1 );
00099     second_wrt_T[2]( 1, 1 ) += TTt( 1, 1 );
00100 
00101     pluseq_scaled_I( second_wrt_T, -tau );
00102     pluseq_scaled_2nd_deriv_of_det( second_wrt_T, -0.5 * nT );
00103     pluseq_scaled_sum_outer_product( second_wrt_T, -1, T, adjt );
00104 
00105     pluseq_scaled_2nd_deriv_of_det( second_wrt_T, tau );
00106     pluseq_scaled_outer_product( second_wrt_T, 1, adjt );
00107 
00108     second_wrt_T[1] *= 4;
00109     second_wrt_T[0] *= 4;
00110     second_wrt_T[2] *= 4;
00111 
00112     return true;
00113 }
00114 
00115 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines