Branch data Line data Source code
1 : : /* *****************************************************************
2 : : MESQUITE -- The Mesh Quality Improvement Toolkit
3 : :
4 : : Copyright 2010 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 : : (2010) [email protected]
24 : :
25 : : ***************************************************************** */
26 : :
27 : : /** \file TMetric.hpp
28 : : * \brief
29 : : * \author Jason Kraftcheck
30 : : */
31 : :
32 : : #ifndef MSQ_T_METRIC_HPP
33 : : #define MSQ_T_METRIC_HPP
34 : :
35 : : #include "Mesquite.hpp"
36 : : #include <string>
37 : :
38 : : namespace MBMesquite
39 : : {
40 : :
41 : : class MsqError;
42 : : template < unsigned R, unsigned C >
43 : : class MsqMatrix;
44 : :
45 : 91 : class TMetric
46 : : {
47 : : public:
48 : : MESQUITE_EXPORT virtual ~TMetric();
49 : :
50 : : MESQUITE_EXPORT virtual std::string get_name() const = 0;
51 : :
52 : : /**\brief Evaluate \f$\mu(T)\f$
53 : : *
54 : : *\param T 2x2 relative measure matrix (typically A W^-1)
55 : : *\param result Output: value of function
56 : : *\return false if function cannot be evaluated for given T
57 : : * (e.g. division by zero, etc.), true otherwise.
58 : : */
59 : : MESQUITE_EXPORT virtual bool evaluate( const MsqMatrix< 2, 2 >& T, double& result, MsqError& err );
60 : :
61 : : /**\brief Evaluate \f$\mu(T)\f$
62 : : *
63 : : *\param T 3x3 relative measure matrix (typically A W^-1)
64 : : *\param result Output: value of function
65 : : *\return false if function cannot be evaluated for given T
66 : : * (e.g. division by zero, etc.), true otherwise.
67 : : */
68 : : MESQUITE_EXPORT virtual bool evaluate( const MsqMatrix< 3, 3 >& T, double& result, MsqError& err );
69 : :
70 : : /**\brief Gradient of \f$\mu(T)\f$ with respect to components of T
71 : : *
72 : : *\param T 2x2 relative measure matrix (typically A W^-1)
73 : : *\param result Output: value of function
74 : : *\param deriv_wrt_T Output: partial deriviatve of \f$\mu\f$ wrt each term of T,
75 : : * evaluated at passed T.
76 : : * \f[\left[\begin{array}{cc}
77 : : * \frac{\partial\mu}{\partial T_{0,0}} &
78 : : * \frac{\partial\mu}{\partial T_{0,1}} \\
79 : : * \frac{\partial\mu}{\partial T_{1,0}} &
80 : : * \frac{\partial\mu}{\partial T_{1,1}} \\
81 : : * \end{array}\right]\f]
82 : : *\return false if function cannot be evaluated for given T
83 : : * (e.g. division by zero, etc.), true otherwise.
84 : : */
85 : : MESQUITE_EXPORT virtual bool evaluate_with_grad( const MsqMatrix< 2, 2 >& T, double& result,
86 : : MsqMatrix< 2, 2 >& deriv_wrt_T, MsqError& err );
87 : :
88 : : /**\brief Gradient of \f$\mu(T)\f$ with respect to components of T
89 : : *
90 : : *\param T 3x3 relative measure matrix (typically A W^-1)
91 : : *\param result Output: value of function
92 : : *\param deriv_wrt_T Output: partial deriviatve of \f$\mu\f$ wrt each term of T,
93 : : * evaluated at passed T.
94 : : * \f[\left[\begin{array}{ccc}
95 : : * \frac{\partial\mu}{\partial T_{0,0}} &
96 : : * \frac{\partial\mu}{\partial T_{0,1}} &
97 : : * \frac{\partial\mu}{\partial T_{0,2}} \\
98 : : * \frac{\partial\mu}{\partial T_{1,0}} &
99 : : * \frac{\partial\mu}{\partial T_{1,1}} &
100 : : * \frac{\partial\mu}{\partial T_{1,2}} \\
101 : : * \frac{\partial\mu}{\partial T_{2,0}} &
102 : : * \frac{\partial\mu}{\partial T_{2,1}} &
103 : : * \frac{\partial\mu}{\partial T_{2,2}}
104 : : * \end{array}\right]\f]
105 : : *\return false if function cannot be evaluated for given T
106 : : * (e.g. division by zero, etc.), true otherwise.
107 : : */
108 : : MESQUITE_EXPORT virtual bool evaluate_with_grad( const MsqMatrix< 3, 3 >& T, double& result,
109 : : MsqMatrix< 3, 3 >& deriv_wrt_T, MsqError& err );
110 : :
111 : : /**\brief Hessian of \f$\mu(T)\f$ with respect to components of T
112 : : *
113 : : *\param T 3x3 relative measure matrix (typically A W^-1)
114 : : *\param result Output: value of function
115 : : *\param deriv_wrt_T Output: partial deriviatve of \f$\mu\f$ wrt each term of T,
116 : : * evaluated at passed T.
117 : : *\param second_wrt_T Output: 9x9 matrix of second partial deriviatve of \f$\mu\f$ wrt
118 : : * each term of T, in row-major order. The symmetric
119 : : * matrix is decomposed into 3x3 blocks and only the upper diagonal
120 : : * blocks, in row-major order, are returned.
121 : : * \f[\left[\begin{array}{cc|cc}
122 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}^2} &
123 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial A_{0,1}} &
124 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial A_{1,0}} &
125 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial A_{1,1}} \\
126 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial A_{0,1}} &
127 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}^2} &
128 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}\partial A_{1,0}} &
129 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}\partial A_{1,1}} \\
130 : : * \hline & &
131 : : * \frac{\partial^{2}\mu}{\partial T_{1,0}^2} &
132 : : * \frac{\partial^{2}\mu}{\partial T_{1,0}\partial A_{1,1}} \\
133 : : * & &
134 : : * \frac{\partial^{2}\mu}{\partial T_{1,0}\partial A_{1,1}} &
135 : : * \frac{\partial^{2}\mu}{\partial T_{1,1}^2} \\
136 : : * \end{array}\right]\f]
137 : : *
138 : : *\return false if function cannot be evaluated for given T
139 : : * (e.g. division by zero, etc.), true otherwise.
140 : : */
141 : : MESQUITE_EXPORT virtual bool evaluate_with_hess( const MsqMatrix< 2, 2 >& T, double& result,
142 : : MsqMatrix< 2, 2 >& deriv_wrt_T, MsqMatrix< 2, 2 > second_wrt_T[3],
143 : : MsqError& err );
144 : : /**\brief Hessian of \f$\mu(T)\f$ with respect to components of T
145 : : *
146 : : *\param T 3x3 relative measure matrix (typically A W^-1)
147 : : *\param result Output: value of function
148 : : *\param deriv_wrt_T Output: partial deriviatve of \f$\mu\f$ wrt each term of T,
149 : : * evaluated at passed T.
150 : : *\param second_wrt_T Output: 9x9 matrix of second partial deriviatve of \f$\mu\f$ wrt
151 : : * each term of T, in row-major order. The symmetric
152 : : * matrix is decomposed into 3x3 blocks and only the upper diagonal
153 : : * blocks, in row-major order, are returned.
154 : : * \f[\left[\begin{array}{ccc|ccc|ccc}
155 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}^2} &
156 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial T_{0,1}} &
157 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial T_{0,2}} &
158 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial T_{1,0}} &
159 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial T_{1,1}} &
160 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial T_{1,2}} &
161 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial T_{2,0}} &
162 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial T_{2,1}} &
163 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial T_{2,2}} \\
164 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial T_{0,1}} &
165 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}^2} &
166 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}\partial T_{0,2}} &
167 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}\partial T_{1,0}} &
168 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}\partial T_{1,1}} &
169 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}\partial T_{1,2}} &
170 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}\partial T_{2,0}} &
171 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}\partial T_{2,1}} &
172 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}\partial T_{2,2}} \\
173 : : * \frac{\partial^{2}\mu}{\partial T_{0,0}\partial T_{0,2}} &
174 : : * \frac{\partial^{2}\mu}{\partial T_{0,1}\partial T_{0,2}} &
175 : : * \frac{\partial^{2}\mu}{\partial T_{0,2}^2} &
176 : : * \frac{\partial^{2}\mu}{\partial T_{0,2}\partial T_{1,0}} &
177 : : * \frac{\partial^{2}\mu}{\partial T_{0,2}\partial T_{1,1}} &
178 : : * \frac{\partial^{2}\mu}{\partial T_{0,2}\partial T_{1,2}} &
179 : : * \frac{\partial^{2}\mu}{\partial T_{0,2}\partial T_{2,0}} &
180 : : * \frac{\partial^{2}\mu}{\partial T_{0,2}\partial T_{2,1}} &
181 : : * \frac{\partial^{2}\mu}{\partial T_{0,2}\partial T_{2,2}} \\
182 : : * \hline & & &
183 : : * \frac{\partial^{2}\mu}{\partial T_{1,0}^2} &
184 : : * \frac{\partial^{2}\mu}{\partial T_{1,0}\partial T_{1,1}} &
185 : : * \frac{\partial^{2}\mu}{\partial T_{1,0}\partial T_{1,2}} &
186 : : * \frac{\partial^{2}\mu}{\partial T_{1,0}\partial T_{2,0}} &
187 : : * \frac{\partial^{2}\mu}{\partial T_{1,0}\partial T_{2,1}} &
188 : : * \frac{\partial^{2}\mu}{\partial T_{1,0}\partial T_{2,2}} \\
189 : : * & & &
190 : : * \frac{\partial^{2}\mu}{\partial T_{1,0}\partial T_{1,1}} &
191 : : * \frac{\partial^{2}\mu}{\partial T_{1,1}^2} &
192 : : * \frac{\partial^{2}\mu}{\partial T_{1,1}\partial T_{1,2}} &
193 : : * \frac{\partial^{2}\mu}{\partial T_{1,1}\partial T_{2,0}} &
194 : : * \frac{\partial^{2}\mu}{\partial T_{1,1}\partial T_{2,1}} &
195 : : * \frac{\partial^{2}\mu}{\partial T_{1,1}\partial T_{2,2}} \\
196 : : * & & &
197 : : * \frac{\partial^{2}\mu}{\partial T_{1,0}\partial T_{1,2}} &
198 : : * \frac{\partial^{2}\mu}{\partial T_{1,1}\partial T_{1,2}} &
199 : : * \frac{\partial^{2}\mu}{\partial T_{1,2}^2} &
200 : : * \frac{\partial^{2}\mu}{\partial T_{1,2}\partial T_{2,0}} &
201 : : * \frac{\partial^{2}\mu}{\partial T_{1,2}\partial T_{2,1}} &
202 : : * \frac{\partial^{2}\mu}{\partial T_{1,2}\partial T_{2,2}} \\
203 : : * \hline & & & & & &
204 : : * \frac{\partial^{2}\mu}{\partial T_{2,0}^2} &
205 : : * \frac{\partial^{2}\mu}{\partial T_{2,0}\partial T_{2,1}} &
206 : : * \frac{\partial^{2}\mu}{\partial T_{2,0}\partial T_{2,2}} \\
207 : : * & & & & & &
208 : : * \frac{\partial^{2}\mu}{\partial T_{2,0}\partial T_{2,1}} &
209 : : * \frac{\partial^{2}\mu}{\partial T_{2,1}^2} &
210 : : * \frac{\partial^{2}\mu}{\partial T_{2,1}\partial T_{2,2}} \\
211 : : * & & & & & &
212 : : * \frac{\partial^{2}\mu}{\partial T_{2,0}\partial T_{2,2}} &
213 : : * \frac{\partial^{2}\mu}{\partial T_{2,1}\partial T_{2,2}} &
214 : : * \frac{\partial^{2}\mu}{\partial T_{2,2}^2} \\
215 : : * \end{array}\right]\f]
216 : : *\return false if function cannot be evaluated for given T
217 : : * (e.g. division by zero, etc.), true otherwise.
218 : : */
219 : : MESQUITE_EXPORT virtual bool evaluate_with_hess( const MsqMatrix< 3, 3 >& T, double& result,
220 : : MsqMatrix< 3, 3 >& deriv_wrt_T, MsqMatrix< 3, 3 > second_wrt_T[6],
221 : : MsqError& err );
222 : :
223 : 425698 : static inline bool invalid_determinant( double d )
224 : : {
225 : 425698 : return d < 1e-12;
226 : : }
227 : : };
228 : :
229 : : class TMetric2D : public TMetric
230 : : {
231 : : public:
232 : : MESQUITE_EXPORT virtual ~TMetric2D();
233 : :
234 : : /**\brief Evaluate \f$\mu(T)\f$
235 : : *
236 : : * This method always returns an error for 2D-only metrics
237 : : */
238 : : MESQUITE_EXPORT virtual bool evaluate( const MsqMatrix< 3, 3 >& T, double& result, MsqError& err );
239 : : };
240 : :
241 : : class TMetric3D : public TMetric
242 : : {
243 : : public:
244 : : MESQUITE_EXPORT virtual ~TMetric3D();
245 : :
246 : : /**\brief Evaluate \f$\mu(T)\f$
247 : : *
248 : : * This method always returns an error for 3D-only metrics
249 : : */
250 : : MESQUITE_EXPORT virtual bool evaluate( const MsqMatrix< 2, 2 >& T, double& result, MsqError& err );
251 : : };
252 : :
253 : : } // namespace MBMesquite
254 : :
255 : : #endif
|