MOAB: Mesh Oriented datABase  (version 5.4.1)
TShapeSize3DB2.cpp
Go to the documentation of this file.
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 TShapeSize3DB2.cpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "Mesquite.hpp"
00033 #include "TShapeSize3DB2.hpp"
00034 #include "TMPDerivs.hpp"
00035 #include "MsqError.hpp"
00036 
00037 namespace MBMesquite
00038 {
00039 
00040 std::string TShapeSize3DB2::get_name() const
00041 {
00042     return "TShapeSize3DB2";
00043 }
00044 
00045 TShapeSize3DB2::~TShapeSize3DB2() {}
00046 
00047 bool TShapeSize3DB2::evaluate( const MsqMatrix< 3, 3 >& T, double& result, MsqError& err )
00048 {
00049     const double tau = det( T );
00050     if( invalid_determinant( tau ) )
00051     {  // barrier
00052         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00053         return false;
00054     }
00055 
00056     const double f = sqr_Frobenius( T );
00057     const double g = sqr_Frobenius( adj( T ) );
00058     result         = ( f + g ) / ( 6 * tau ) - 1;
00059     return true;
00060 }
00061 
00062 bool TShapeSize3DB2::evaluate_with_grad( const MsqMatrix< 3, 3 >& T,
00063                                          double& result,
00064                                          MsqMatrix< 3, 3 >& deriv_wrt_T,
00065                                          MsqError& err )
00066 {
00067     const double tau = det( T );
00068     if( invalid_determinant( tau ) )
00069     {  // barrier
00070         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00071         return false;
00072     }
00073 
00074     const double f = sqr_Frobenius( T );
00075     const double g = sqr_Frobenius( adj( T ) );
00076     result         = ( f + g ) / ( 6 * tau );
00077 
00078     deriv_wrt_T = -transpose( T ) * T;
00079     deriv_wrt_T( 0, 0 ) += 1 + f;
00080     deriv_wrt_T( 1, 1 ) += 1 + f;
00081     deriv_wrt_T( 2, 2 ) += 1 + f;
00082     deriv_wrt_T = T * deriv_wrt_T;
00083     deriv_wrt_T -= 3 * result * transpose_adj( T );
00084     deriv_wrt_T *= 1.0 / ( 3 * tau );
00085 
00086     result -= 1.0;
00087     return true;
00088 }
00089 
00090 bool TShapeSize3DB2::evaluate_with_hess( const MsqMatrix< 3, 3 >& T,
00091                                          double& result,
00092                                          MsqMatrix< 3, 3 >& wrt_T,
00093                                          MsqMatrix< 3, 3 > second[6],
00094                                          MsqError& err )
00095 {
00096     const double tau = det( T );
00097     if( invalid_determinant( tau ) )
00098     {  // barrier
00099         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00100         return false;
00101     }
00102 
00103     const double f = sqr_Frobenius( T );
00104     const double g = sqr_Frobenius( adj( T ) );
00105     result         = ( f + g ) / ( 6 * tau );
00106 
00107     MsqMatrix< 3, 3 > dtau = transpose_adj( T );
00108     MsqMatrix< 3, 3 > dg   = -transpose( T ) * T;
00109     dg( 0, 0 ) += f;
00110     dg( 1, 1 ) += f;
00111     dg( 2, 2 ) += f;
00112     dg = T * dg;
00113     dg *= 2;
00114 
00115     wrt_T = T;
00116     wrt_T += 0.5 * dg;
00117     wrt_T *= 1.0 / 3.0;
00118     wrt_T -= result * dtau;
00119     wrt_T *= 1.0 / tau;
00120 
00121     set_scaled_2nd_deriv_norm_sqr_adj( second, 1.0 / 6.0, T );
00122     pluseq_scaled_I( second, 1.0 / 3.0 );
00123     pluseq_scaled_sum_outer_product( second, -1. / 3. / tau, T, dtau );
00124     pluseq_scaled_sum_outer_product( second, -1. / 6. / tau, dg, dtau );
00125     pluseq_scaled_outer_product( second, 2 * result / tau, dtau );
00126     pluseq_scaled_2nd_deriv_of_det( second, -result, T );
00127     hess_scale( second, 1.0 / tau );
00128 
00129     result -= 1.0;
00130     return true;
00131 }
00132 
00133 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines