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 TShapeOrientNB1.cpp
28 : : * \brief
29 : : * \author Jason Kraftcheck
30 : : */
31 : :
32 : : #include "Mesquite.hpp"
33 : : #include "TShapeOrientNB1.hpp"
34 : : #include "MsqMatrix.hpp"
35 : : #include "TMPDerivs.hpp"
36 : : #include "TMPCommon.hpp"
37 : :
38 : : namespace MBMesquite
39 : : {
40 : :
41 : 0 : std::string TShapeOrientNB1::get_name() const
42 : : {
43 [ # # ]: 0 : return "TShapeOrientNB1";
44 : : }
45 : :
46 [ # # ]: 0 : TShapeOrientNB1::~TShapeOrientNB1() {}
47 : :
48 : : template < unsigned DIM >
49 : 149653 : static inline bool eval( const MsqMatrix< DIM, DIM >& T, double& result )
50 : : {
51 : 149653 : result = Frobenius( T ) - trace( T ) / DimConst< DIM >::sqrt();
52 : 149653 : return true;
53 : : }
54 : :
55 : : template < unsigned DIM >
56 : 68056 : static inline bool grad( const MsqMatrix< DIM, DIM >& T, double& result, MsqMatrix< DIM, DIM >& deriv )
57 : : {
58 : 68056 : const double norm = Frobenius( T );
59 : 68056 : const double invroot = 1.0 / DimConst< DIM >::sqrt();
60 : 68056 : result = norm - invroot * trace( T );
61 : :
62 [ # # - + ]: 68056 : if( norm < 1e-50 )
63 : : {
64 : 0 : deriv = MsqMatrix< DIM, DIM >( 0.0 );
65 : 0 : return true;
66 : : }
67 : :
68 : 68056 : deriv = 1.0 / norm * T;
69 : 68056 : pluseq_scaled_I( deriv, -invroot );
70 : 68056 : return true;
71 : : }
72 : :
73 : : template < unsigned DIM >
74 : 0 : static inline bool hess( const MsqMatrix< DIM, DIM >& T, double& result, MsqMatrix< DIM, DIM >& deriv,
75 : : MsqMatrix< DIM, DIM >* second )
76 : : {
77 : 0 : const double norm = Frobenius( T );
78 : 0 : const double invroot = 1.0 / DimConst< DIM >::sqrt();
79 : 0 : result = norm - invroot * trace( T );
80 : :
81 [ # # # # ]: 0 : if( norm < 1e-50 )
82 : : {
83 : 0 : deriv = MsqMatrix< DIM, DIM >( 0.0 );
84 : 0 : set_scaled_I( second, 1.0 );
85 : 0 : return true;
86 : : }
87 : :
88 : 0 : const double invnorm = 1.0 / norm;
89 : 0 : deriv = invnorm * T;
90 : 0 : pluseq_scaled_I( deriv, -invroot );
91 : :
92 : 0 : set_scaled_outer_product( second, -invnorm * invnorm * invnorm, T );
93 : 0 : pluseq_scaled_I( second, invnorm );
94 : 0 : return true;
95 : : }
96 : :
97 : 435418 : TMP_T_TEMPL_IMPL_COMMON( TShapeOrientNB1 )
98 : :
99 : : } // namespace MBMesquite
|