MOAB: Mesh Oriented datABase  (version 5.2.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) kraftche@cae.wisc.edu
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, double& result, MsqMatrix< 2, 2 >& deriv_wrt_T,
00056                                     MsqError& /*err*/ )
00057 {
00058     result      = sqr_Frobenius( T ) - 2.0 * det( T );
00059     deriv_wrt_T = T;
00060     deriv_wrt_T -= transpose_adj( T );
00061     deriv_wrt_T *= 2;
00062     return true;
00063 }
00064 
00065 bool TShapeNB1::evaluate_with_hess( const MsqMatrix< 2, 2 >& T, double& result, MsqMatrix< 2, 2 >& deriv_wrt_T,
00066                                     MsqMatrix< 2, 2 > second_wrt_T[3], MsqError& /*err*/ )
00067 {
00068     result      = sqr_Frobenius( T ) - 2.0 * det( T );
00069     deriv_wrt_T = T;
00070     deriv_wrt_T -= transpose_adj( T );
00071     deriv_wrt_T *= 2;
00072     set_scaled_I( second_wrt_T, 2.0 );
00073     pluseq_scaled_2nd_deriv_of_det( second_wrt_T, -2.0 );
00074     return true;
00075 }
00076 
00077 bool TShapeNB1::evaluate( const MsqMatrix< 3, 3 >& T, double& result, MsqError& /*err*/ )
00078 {
00079     double f = Frobenius( T );
00080     double d = det( T );
00081     result   = f * f * f - 3 * MSQ_SQRT_THREE * d;
00082     return true;
00083 }
00084 
00085 bool TShapeNB1::evaluate_with_grad( const MsqMatrix< 3, 3 >& T, double& result, MsqMatrix< 3, 3 >& deriv_wrt_T,
00086                                     MsqError& /*err*/ )
00087 {
00088     double f = Frobenius( T );
00089     double d = det( T );
00090     result   = f * f * f - 3 * MSQ_SQRT_THREE * d;
00091 
00092     deriv_wrt_T = T;
00093     deriv_wrt_T *= f;
00094     deriv_wrt_T -= MSQ_SQRT_THREE * transpose_adj( T );
00095     deriv_wrt_T *= 3;
00096     return true;
00097 }
00098 
00099 bool TShapeNB1::evaluate_with_hess( const MsqMatrix< 3, 3 >& T, double& result, MsqMatrix< 3, 3 >& deriv_wrt_T,
00100                                     MsqMatrix< 3, 3 > second_wrt_T[6], MsqError& /*err*/ )
00101 {
00102     double f = Frobenius( T );
00103     double d = det( T );
00104     result   = f * f * f - 3 * MSQ_SQRT_THREE * d;
00105 
00106     deriv_wrt_T = T;
00107     deriv_wrt_T *= f;
00108     deriv_wrt_T -= MSQ_SQRT_THREE * transpose_adj( T );
00109     deriv_wrt_T *= 3;
00110 
00111     set_scaled_2nd_deriv_of_det( second_wrt_T, -3 * MSQ_SQRT_THREE, T );
00112     if( f > 1e-50 )
00113         pluseq_scaled_outer_product( second_wrt_T, 3.0 / f, T );
00114     else
00115         std::cout << "Warning: Division by zero avoided in TShapeNB1::evaluate_with_hess()" << std::endl;
00116     pluseq_scaled_I( second_wrt_T, 3.0 * f );
00117     return true;
00118 }
00119 
00120 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines