MOAB: Mesh Oriented datABase  (version 5.2.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) kraftche@cae.wisc.edu
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, double& result, MsqMatrix< 3, 3 >& deriv_wrt_T,
00063                                          MsqError& err )
00064 {
00065     const double tau = det( T );
00066     if( invalid_determinant( tau ) )
00067     {  // barrier
00068         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00069         return false;
00070     }
00071 
00072     const double f = sqr_Frobenius( T );
00073     const double g = sqr_Frobenius( adj( T ) );
00074     result         = ( f + g ) / ( 6 * tau );
00075 
00076     deriv_wrt_T = -transpose( T ) * T;
00077     deriv_wrt_T( 0, 0 ) += 1 + f;
00078     deriv_wrt_T( 1, 1 ) += 1 + f;
00079     deriv_wrt_T( 2, 2 ) += 1 + f;
00080     deriv_wrt_T = T * deriv_wrt_T;
00081     deriv_wrt_T -= 3 * result * transpose_adj( T );
00082     deriv_wrt_T *= 1.0 / ( 3 * tau );
00083 
00084     result -= 1.0;
00085     return true;
00086 }
00087 
00088 bool TShapeSize3DB2::evaluate_with_hess( const MsqMatrix< 3, 3 >& T, double& result, MsqMatrix< 3, 3 >& wrt_T,
00089                                          MsqMatrix< 3, 3 > second[6], MsqError& err )
00090 {
00091     const double tau = det( T );
00092     if( invalid_determinant( tau ) )
00093     {  // barrier
00094         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00095         return false;
00096     }
00097 
00098     const double f = sqr_Frobenius( T );
00099     const double g = sqr_Frobenius( adj( T ) );
00100     result         = ( f + g ) / ( 6 * tau );
00101 
00102     MsqMatrix< 3, 3 > dtau = transpose_adj( T );
00103     MsqMatrix< 3, 3 > dg   = -transpose( T ) * T;
00104     dg( 0, 0 ) += f;
00105     dg( 1, 1 ) += f;
00106     dg( 2, 2 ) += f;
00107     dg = T * dg;
00108     dg *= 2;
00109 
00110     wrt_T = T;
00111     wrt_T += 0.5 * dg;
00112     wrt_T *= 1.0 / 3.0;
00113     wrt_T -= result * dtau;
00114     wrt_T *= 1.0 / tau;
00115 
00116     set_scaled_2nd_deriv_norm_sqr_adj( second, 1.0 / 6.0, T );
00117     pluseq_scaled_I( second, 1.0 / 3.0 );
00118     pluseq_scaled_sum_outer_product( second, -1. / 3. / tau, T, dtau );
00119     pluseq_scaled_sum_outer_product( second, -1. / 6. / tau, dg, dtau );
00120     pluseq_scaled_outer_product( second, 2 * result / tau, dtau );
00121     pluseq_scaled_2nd_deriv_of_det( second, -result, T );
00122     hess_scale( second, 1.0 / tau );
00123 
00124     result -= 1.0;
00125     return true;
00126 }
00127 
00128 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines