MOAB: Mesh Oriented datABase  (version 5.4.1)
TShapeSizeB1.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) [email protected]
00024 
00025   ***************************************************************** */
00026 
00027 /** \file TShapeSizeB1.cpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "Mesquite.hpp"
00033 #include "TShapeSizeB1.hpp"
00034 #include "TMPDerivs.hpp"
00035 #include "MsqError.hpp"
00036 
00037 namespace MBMesquite
00038 {
00039 
00040 std::string TShapeSizeB1::get_name() const
00041 {
00042     return "TShapeSizeB1";
00043 }
00044 
00045 TShapeSizeB1::~TShapeSizeB1() {}
00046 
00047 bool TShapeSizeB1::evaluate( const MsqMatrix< 2, 2 >& T, double& result, MsqError& /*err*/ )
00048 {
00049     const double tau = det( T );
00050     if( invalid_determinant( tau ) )
00051     {  // barrier
00052         return false;
00053     }
00054 
00055     const double nT = sqr_Frobenius( T );
00056     const double f  = 1 / ( tau * tau );
00057     result          = ( 1 + f ) * nT - 4;
00058     return true;
00059 }
00060 
00061 bool TShapeSizeB1::evaluate( const MsqMatrix< 3, 3 >& T, double& result, MsqError& /*err*/ )
00062 {
00063     const double tau = det( T );
00064     if( invalid_determinant( tau ) )
00065     {  // barrier
00066         return false;
00067     }
00068 
00069     const double nT   = sqr_Frobenius( T );
00070     const double nadj = sqr_Frobenius( transpose_adj( T ) );
00071     const double f    = 1 / ( tau * tau );
00072     result            = nT + f * nadj - 6;
00073     return true;
00074 }
00075 
00076 bool TShapeSizeB1::evaluate_with_grad( const MsqMatrix< 2, 2 >& T,
00077                                        double& result,
00078                                        MsqMatrix< 2, 2 >& deriv_wrt_T,
00079                                        MsqError& err )
00080 {
00081     const double tau = det( T );
00082     if( invalid_determinant( tau ) )
00083     {  // barrier
00084         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00085         return false;
00086     }
00087 
00088     const MsqMatrix< 2, 2 > adjt = transpose_adj( T );
00089     const double nT              = sqr_Frobenius( T );
00090     const double f               = 1 / ( tau * tau );
00091     result                       = ( 1 + f ) * nT - 4;
00092 
00093     deriv_wrt_T = T;
00094     deriv_wrt_T *= 2 + 2 * f;
00095     deriv_wrt_T -= 2 * f / tau * nT * adjt;
00096 
00097     return true;
00098 }
00099 
00100 bool TShapeSizeB1::evaluate_with_grad( const MsqMatrix< 3, 3 >& T,
00101                                        double& result,
00102                                        MsqMatrix< 3, 3 >& deriv_wrt_T,
00103                                        MsqError& err )
00104 {
00105     const double tau = det( T );
00106     if( invalid_determinant( tau ) )
00107     {  // barrier
00108         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00109         return false;
00110     }
00111 
00112     const MsqMatrix< 3, 3 > adjt = transpose_adj( T );
00113     const double nT              = sqr_Frobenius( T );
00114     const double nadj            = sqr_Frobenius( adjt );
00115     const double f               = 1 / ( tau * tau );
00116     result                       = nT + f * nadj - 6;
00117 
00118     deriv_wrt_T = T;
00119     deriv_wrt_T *= ( 1 + f * nT );
00120     deriv_wrt_T -= f * T * transpose( T ) * T;
00121     deriv_wrt_T -= f / tau * nadj * adjt;
00122     deriv_wrt_T *= 2;
00123 
00124     return true;
00125 }
00126 
00127 bool TShapeSizeB1::evaluate_with_hess( const MsqMatrix< 2, 2 >& T,
00128                                        double& result,
00129                                        MsqMatrix< 2, 2 >& deriv_wrt_T,
00130                                        MsqMatrix< 2, 2 > second_wrt_T[3],
00131                                        MsqError& err )
00132 {
00133     const double tau = det( T );
00134     if( invalid_determinant( tau ) )
00135     {  // barrier
00136         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00137         return false;
00138     }
00139 
00140     const MsqMatrix< 2, 2 > adjt = transpose_adj( T );
00141     const double nT              = sqr_Frobenius( T );
00142     const double f               = 1 / ( tau * tau );
00143     result                       = ( 1 + f ) * nT - 4;
00144 
00145     deriv_wrt_T = T;
00146     deriv_wrt_T *= 2 + 2 * f;
00147     deriv_wrt_T -= 2 * f / tau * nT * adjt;
00148 
00149     set_scaled_sum_outer_product( second_wrt_T, -4 * f / tau, T, adjt );
00150     pluseq_scaled_I( second_wrt_T, 2 + 2 * f );
00151     pluseq_scaled_outer_product( second_wrt_T, 6 * nT * f * f, adjt );
00152     pluseq_scaled_2nd_deriv_of_det( second_wrt_T, -2 * nT * f / tau );
00153 
00154     return true;
00155 }
00156 bool TShapeSizeB1::evaluate_with_hess( const MsqMatrix< 3, 3 >& T,
00157                                        double& result,
00158                                        MsqMatrix< 3, 3 >& deriv_wrt_T,
00159                                        MsqMatrix< 3, 3 > second_wrt_T[6],
00160                                        MsqError& err )
00161 {
00162     const double tau = det( T );
00163     if( invalid_determinant( tau ) )
00164     {  // barrier
00165         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00166         return false;
00167     }
00168 
00169     const MsqMatrix< 3, 3 > adjt = transpose_adj( T );
00170     const double nT              = sqr_Frobenius( T );
00171     const double nadj            = sqr_Frobenius( adjt );
00172     const double f               = 1 / ( tau * tau );
00173     result                       = nT + f * nadj - 6;
00174 
00175     //! \f$ \frac{\partial}{\partial T} |adj T|^2 \f$
00176     const MsqMatrix< 3, 3 > dNadj_dT = 2 * ( nT * T - T * transpose( T ) * T );
00177     deriv_wrt_T                      = T;
00178     deriv_wrt_T -= f / tau * nadj * adjt;
00179     deriv_wrt_T *= 2;
00180     deriv_wrt_T += f * dNadj_dT;
00181 
00182     // calculate negative of 2nd wrt T of (|adj T|^2 / tau^2) (sec 3.2.2)
00183     set_scaled_2nd_deriv_norm_sqr_adj( second_wrt_T, f, T );
00184     pluseq_scaled_2nd_deriv_of_det( second_wrt_T, -2 * f * f * nadj * tau, T );
00185     pluseq_scaled_outer_product( second_wrt_T, 6 * f * f * nadj, adjt );
00186     pluseq_scaled_sum_outer_product( second_wrt_T, -2 * f * f * tau, adjt, dNadj_dT );
00187     // calculate 2nd wrt T of this metric
00188     pluseq_scaled_I( second_wrt_T, 2.0 );
00189 
00190     return true;
00191 }
00192 
00193 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines