MOAB: Mesh Oriented datABase  (version 5.4.1)
TShapeNB1.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 TShapeNB1.cpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "Mesquite.hpp"
00033 #include "TShapeNB1.hpp"
00034 #include "MsqMatrix.hpp"
00035 #include "TMPDerivs.hpp"
00036 
00037 #include <iostream>
00038 
00039 namespace MBMesquite
00040 {
00041 
00042 std::string TShapeNB1::get_name() const
00043 {
00044     return "TShapeNB1";
00045 }
00046 
00047 TShapeNB1::~TShapeNB1() {}
00048 
00049 bool TShapeNB1::evaluate( const MsqMatrix< 2, 2 >& T, double& result, MsqError& /*err*/ )
00050 {
00051     result = sqr_Frobenius( T ) - 2.0 * det( T );
00052     return true;
00053 }
00054 
00055 bool TShapeNB1::evaluate_with_grad( const MsqMatrix< 2, 2 >& T,
00056                                     double& result,
00057                                     MsqMatrix< 2, 2 >& deriv_wrt_T,
00058                                     MsqError& /*err*/ )
00059 {
00060     result      = sqr_Frobenius( T ) - 2.0 * det( T );
00061     deriv_wrt_T = T;
00062     deriv_wrt_T -= transpose_adj( T );
00063     deriv_wrt_T *= 2;
00064     return true;
00065 }
00066 
00067 bool TShapeNB1::evaluate_with_hess( const MsqMatrix< 2, 2 >& T,
00068                                     double& result,
00069                                     MsqMatrix< 2, 2 >& deriv_wrt_T,
00070                                     MsqMatrix< 2, 2 > second_wrt_T[3],
00071                                     MsqError& /*err*/ )
00072 {
00073     result      = sqr_Frobenius( T ) - 2.0 * det( T );
00074     deriv_wrt_T = T;
00075     deriv_wrt_T -= transpose_adj( T );
00076     deriv_wrt_T *= 2;
00077     set_scaled_I( second_wrt_T, 2.0 );
00078     pluseq_scaled_2nd_deriv_of_det( second_wrt_T, -2.0 );
00079     return true;
00080 }
00081 
00082 bool TShapeNB1::evaluate( const MsqMatrix< 3, 3 >& T, double& result, MsqError& /*err*/ )
00083 {
00084     double f = Frobenius( T );
00085     double d = det( T );
00086     result   = f * f * f - 3 * MSQ_SQRT_THREE * d;
00087     return true;
00088 }
00089 
00090 bool TShapeNB1::evaluate_with_grad( const MsqMatrix< 3, 3 >& T,
00091                                     double& result,
00092                                     MsqMatrix< 3, 3 >& deriv_wrt_T,
00093                                     MsqError& /*err*/ )
00094 {
00095     double f = Frobenius( T );
00096     double d = det( T );
00097     result   = f * f * f - 3 * MSQ_SQRT_THREE * d;
00098 
00099     deriv_wrt_T = T;
00100     deriv_wrt_T *= f;
00101     deriv_wrt_T -= MSQ_SQRT_THREE * transpose_adj( T );
00102     deriv_wrt_T *= 3;
00103     return true;
00104 }
00105 
00106 bool TShapeNB1::evaluate_with_hess( const MsqMatrix< 3, 3 >& T,
00107                                     double& result,
00108                                     MsqMatrix< 3, 3 >& deriv_wrt_T,
00109                                     MsqMatrix< 3, 3 > second_wrt_T[6],
00110                                     MsqError& /*err*/ )
00111 {
00112     double f = Frobenius( T );
00113     double d = det( T );
00114     result   = f * f * f - 3 * MSQ_SQRT_THREE * d;
00115 
00116     deriv_wrt_T = T;
00117     deriv_wrt_T *= f;
00118     deriv_wrt_T -= MSQ_SQRT_THREE * transpose_adj( T );
00119     deriv_wrt_T *= 3;
00120 
00121     set_scaled_2nd_deriv_of_det( second_wrt_T, -3 * MSQ_SQRT_THREE, T );
00122     if( f > 1e-50 )
00123         pluseq_scaled_outer_product( second_wrt_T, 3.0 / f, T );
00124     else
00125         std::cout << "Warning: Division by zero avoided in TShapeNB1::evaluate_with_hess()" << std::endl;
00126     pluseq_scaled_I( second_wrt_T, 3.0 * f );
00127     return true;
00128 }
00129 
00130 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines