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) kraftche@cae.wisc.edu
24 
25   ***************************************************************** */
26 
27 
28 /** \file TRel2DShapeSizeOrient.cpp
29  *  \brief
30  *  \author Jason Kraftcheck
31  */
32 
33 #include "Mesquite.hpp"
34 #include "TShapeSizeOrientNB1.hpp"
35 #include "MsqMatrix.hpp"
36 #include "TMPCommon.hpp"
37 #include "TMPDerivs.hpp"
38 
39 namespace MBMesquite {
40 
get_name() const41 std::string TShapeSizeOrientNB1::get_name() const
42   { return "TShapeSizeOrientNB1"; }
43 
~TShapeSizeOrientNB1()44 TShapeSizeOrientNB1::~TShapeSizeOrientNB1() {}
45 
46 template <unsigned DIM> static inline
eval(const MsqMatrix<DIM,DIM> & T,double & result)47 bool eval( const MsqMatrix<DIM,DIM>& T, double& result)
48 {
49   MsqMatrix<DIM,DIM> T_I(T);
50   pluseq_scaled_I( T_I, -1 );
51   result = sqr_Frobenius( T_I );
52   return true;
53 }
54 
55 template <unsigned DIM> static inline
grad(const MsqMatrix<DIM,DIM> & T,double & result,MsqMatrix<DIM,DIM> & deriv)56 bool grad( const MsqMatrix<DIM,DIM>& T,
57            double& result,
58            MsqMatrix<DIM,DIM>& deriv )
59 {
60   deriv = T;
61   pluseq_scaled_I( deriv, -1 );
62   result = sqr_Frobenius( deriv );
63   deriv *= 2.0;
64   return true;
65 }
66 
67 template <unsigned DIM> static inline
hess(const MsqMatrix<DIM,DIM> & T,double & result,MsqMatrix<DIM,DIM> & deriv,MsqMatrix<DIM,DIM> * second)68 bool hess( const MsqMatrix<DIM,DIM>& T,
69            double& result,
70            MsqMatrix<DIM,DIM>& deriv,
71            MsqMatrix<DIM,DIM>* second )
72 {
73   deriv = T;
74   pluseq_scaled_I( deriv, -1 );
75   result = sqr_Frobenius( deriv );
76   deriv *= 2.0;
77   set_scaled_I( second, 2.0 );
78   return true;
79 }
80 
81 TMP_T_TEMPL_IMPL_COMMON(TShapeSizeOrientNB1)
82 
83 } // namespace MBMesquite
84