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