Branch data Line data Source code
1 : : /* *****************************************************************
2 : : MESQUITE -- The Mesh Quality Improvement Toolkit
3 : :
4 : : Copyright 2006 Sandia National Laboratories. Developed at the
5 : : University of Wisconsin--Madison under SNL contract number
6 : : 624796. The U.S. Government and the University of Wisconsin
7 : : retain certain rights to this software.
8 : :
9 : : This library is free software; you can redistribute it and/or
10 : : modify it under the terms of the GNU Lesser General Public
11 : : License as published by the Free Software Foundation; either
12 : : version 2.1 of the License, or (at your option) any later version.
13 : :
14 : : This library is distributed in the hope that it will be useful,
15 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : : Lesser General Public License for more details.
18 : :
19 : : You should have received a copy of the GNU Lesser General Public License
20 : : (lgpl.txt) along with this library; if not, write to the Free Software
21 : : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 : :
23 : : (2006) [email protected]
24 : :
25 : : ***************************************************************** */
26 : :
27 : : /** \file TShapeOrientNB2.cpp
28 : : * \brief
29 : : * \author Jason Kraftcheck
30 : : */
31 : :
32 : : #include "Mesquite.hpp"
33 : : #include "TShapeOrientNB2.hpp"
34 : : #include "MsqMatrix.hpp"
35 : : #include "TMPDerivs.hpp"
36 : : #include "TMPCommon.hpp"
37 : :
38 : : namespace MBMesquite
39 : : {
40 : :
41 : 0 : std::string TShapeOrientNB2::get_name() const
42 : : {
43 [ # # ]: 0 : return "TShapeOrientNB2";
44 : : }
45 : :
46 [ # # ]: 0 : TShapeOrientNB2::~TShapeOrientNB2() {}
47 : :
48 : : template < unsigned DIM >
49 : 0 : static inline bool eval( const MsqMatrix< DIM, DIM >& T, double& result )
50 : : {
51 : 0 : const double tr = trace( T );
52 : 0 : result = sqr_Frobenius( T ) - DimConst< DIM >::inv() * tr * fabs( tr );
53 : 0 : return true;
54 : : }
55 : :
56 : : template < unsigned DIM >
57 : 0 : static inline bool grad( const MsqMatrix< DIM, DIM >& T, double& result, MsqMatrix< DIM, DIM >& deriv_wrt_T )
58 : : {
59 : 0 : const double tr = trace( T );
60 : 0 : const double f = DimConst< DIM >::inv() * fabs( tr );
61 : 0 : result = sqr_Frobenius( T ) - f * tr;
62 : 0 : deriv_wrt_T = T;
63 : 0 : pluseq_scaled_I( deriv_wrt_T, -f );
64 : 0 : deriv_wrt_T *= 2;
65 : 0 : return true;
66 : : }
67 : :
68 : : template < unsigned DIM >
69 : 0 : static inline bool hess( const MsqMatrix< DIM, DIM >& T, double& result, MsqMatrix< DIM, DIM >& deriv_wrt_T,
70 : : MsqMatrix< DIM, DIM >* second_wrt_T )
71 : : {
72 : 0 : const double tr = trace( T );
73 : 0 : const double f = DimConst< DIM >::inv() * fabs( tr );
74 : 0 : result = sqr_Frobenius( T ) - f * tr;
75 : 0 : deriv_wrt_T = T;
76 : 0 : pluseq_scaled_I( deriv_wrt_T, -f );
77 : 0 : deriv_wrt_T *= 2;
78 : 0 : set_scaled_I( second_wrt_T, 2.0 );
79 [ # # ][ # # ]: 0 : pluseq_scaled_outer_product_I_I( second_wrt_T, DimConst< DIM >::inv() * ( tr < 0 ? 2 : -2 ) );
80 : 0 : return true;
81 : : }
82 : :
83 : 0 : TMP_T_TEMPL_IMPL_COMMON( TShapeOrientNB2 )
84 : :
85 : : } // namespace MBMesquite
|