MOAB: Mesh Oriented datABase  (version 5.2.1)
TShapeSizeOrientB1.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 TRel2DShapeSizeOrientBarrier.cpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "Mesquite.hpp"
00033 #include "TShapeSizeOrientB1.hpp"
00034 #include "MsqMatrix.hpp"
00035 #include "MsqError.hpp"
00036 #include "TMPDerivs.hpp"
00037 #include "TMPCommon.hpp"
00038 
00039 namespace MBMesquite
00040 {
00041 
00042 std::string TShapeSizeOrientB1::get_name() const
00043 {
00044     return "TShapeSizeOrientB1";
00045 }
00046 
00047 TShapeSizeOrientB1::~TShapeSizeOrientB1() {}
00048 
00049 bool TShapeSizeOrientB1::evaluate( const MsqMatrix< 2, 2 >& T, double& result, MsqError& err )
00050 {
00051     double tau = det( T );
00052     if( TMetric::invalid_determinant( tau ) )
00053     {
00054         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00055         return false;
00056     }
00057 
00058     MsqMatrix< 2, 2 > T_I( T );
00059     pluseq_scaled_I( T_I, -1 );
00060     result = sqr_Frobenius( T_I ) / ( 2 * tau );
00061     return true;
00062 }
00063 
00064 bool TShapeSizeOrientB1::evaluate_with_grad( const MsqMatrix< 2, 2 >& T, double& result, MsqMatrix< 2, 2 >& deriv_wrt_T,
00065                                              MsqError& err )
00066 {
00067     const double d = det( T );
00068     if( TMetric::invalid_determinant( d ) )
00069     {  // barrier
00070         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00071         return false;
00072     }
00073 
00074     deriv_wrt_T = T;
00075     pluseq_scaled_I( deriv_wrt_T, -1 );
00076     double inv_d = 1.0 / d;
00077     result       = 0.5 * sqr_Frobenius( deriv_wrt_T ) * inv_d;
00078 
00079     deriv_wrt_T -= result * transpose_adj( T );
00080     deriv_wrt_T *= inv_d;
00081 
00082     return true;
00083 }
00084 
00085 bool TShapeSizeOrientB1::evaluate_with_hess( const MsqMatrix< 2, 2 >& T, double& result, MsqMatrix< 2, 2 >& deriv_wrt_T,
00086                                              MsqMatrix< 2, 2 > second_wrt_T[3], MsqError& err )
00087 {
00088     const double d = det( T );
00089     if( TMetric::invalid_determinant( d ) )
00090     {  // barrier
00091         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00092         return false;
00093     }
00094 
00095     deriv_wrt_T = T;
00096     pluseq_scaled_I( deriv_wrt_T, -1.0 );
00097     double inv_d = 1.0 / d;
00098     result       = 0.5 * sqr_Frobenius( deriv_wrt_T ) * inv_d;
00099 
00100     MsqMatrix< 2, 2 > adjt = transpose_adj( T );
00101     set_scaled_outer_product( second_wrt_T, 2 * result * inv_d * inv_d, adjt );
00102     pluseq_scaled_sum_outer_product( second_wrt_T, -inv_d * inv_d, deriv_wrt_T, adjt );
00103     pluseq_scaled_2nd_deriv_of_det( second_wrt_T, -result * inv_d, T );
00104     pluseq_scaled_I( second_wrt_T, inv_d );
00105 
00106     deriv_wrt_T -= result * adjt;
00107     deriv_wrt_T *= inv_d;
00108 
00109     return true;
00110 }
00111 
00112 bool TShapeSizeOrientB1::evaluate( const MsqMatrix< 3, 3 >& T, double& result, MsqError& err )
00113 {
00114     double tau = det( T );
00115     if( TMetric::invalid_determinant( tau ) )
00116     {
00117         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00118         return false;
00119     }
00120 
00121     MsqMatrix< 3, 3 > T_I( T );
00122     pluseq_scaled_I( T_I, -1 );
00123     result = sqr_Frobenius( T_I ) / ( 2 * tau );
00124     return true;
00125 }
00126 
00127 bool TShapeSizeOrientB1::evaluate_with_grad( const MsqMatrix< 3, 3 >& T, double& result, MsqMatrix< 3, 3 >& deriv_wrt_T,
00128                                              MsqError& err )
00129 {
00130     const double d = det( T );
00131     if( TMetric::invalid_determinant( d ) )
00132     {  // barrier
00133         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00134         return false;
00135     }
00136 
00137     deriv_wrt_T = T;
00138     pluseq_scaled_I( deriv_wrt_T, -1 );
00139     double inv_d = 1.0 / d;
00140     result       = 0.5 * sqr_Frobenius( deriv_wrt_T ) * inv_d;
00141 
00142     deriv_wrt_T -= result * transpose_adj( T );
00143     deriv_wrt_T *= inv_d;
00144 
00145     return true;
00146 }
00147 
00148 bool TShapeSizeOrientB1::evaluate_with_hess( const MsqMatrix< 3, 3 >& T, double& result, MsqMatrix< 3, 3 >& deriv_wrt_T,
00149                                              MsqMatrix< 3, 3 > second_wrt_T[6], MsqError& err )
00150 {
00151     const double d = det( T );
00152     if( TMetric::invalid_determinant( d ) )
00153     {  // barrier
00154         MSQ_SETERR( err )( barrier_violated_msg, MsqError::BARRIER_VIOLATED );
00155         return false;
00156     }
00157 
00158     deriv_wrt_T = T;
00159     pluseq_scaled_I( deriv_wrt_T, -1.0 );
00160     double inv_d = 1.0 / d;
00161     result       = 0.5 * sqr_Frobenius( deriv_wrt_T ) * inv_d;
00162 
00163     MsqMatrix< 3, 3 > adjt = transpose_adj( T );
00164     set_scaled_outer_product( second_wrt_T, 2 * result * inv_d * inv_d, adjt );
00165     pluseq_scaled_sum_outer_product( second_wrt_T, -inv_d * inv_d, deriv_wrt_T, adjt );
00166     pluseq_scaled_2nd_deriv_of_det( second_wrt_T, -result * inv_d, T );
00167     pluseq_scaled_I( second_wrt_T, inv_d );
00168 
00169     deriv_wrt_T -= result * adjt;
00170     deriv_wrt_T *= inv_d;
00171 
00172     return true;
00173 }
00174 
00175 // TMP_T_TEMPL_IMPL_COMMON(TShapeSizeOrientB1)
00176 
00177 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines