| 1 |
#include "gtest/gtest.h" |
| 2 |
|
| 3 |
#include "stk_middle_mesh/distortion_metric.hpp" |
| 4 |
#include "stk_middle_mesh/regularized_distortion_metric.hpp" |
| 5 |
|
| 6 |
#include <fstream> |
| 7 |
|
| 8 |
namespace stk { |
| 9 |
namespace middle_mesh { |
| 10 |
namespace impl { |
| 11 |
|
| 12 |
using namespace mesh::impl; |
| 13 |
|
| 14 |
TriPts<double> convert_pts(std::array<double, 6> pts) |
| 15 |
{ |
| 16 |
return {utils::Point(pts[0], pts[1]), utils::Point(pts[2], pts[3]), utils::Point(pts[4], pts[5])}; |
| 17 |
} |
| 18 |
|
| 19 |
std::array<double, 6> convert_pts(const TriPts<double>& pts) |
| 20 |
{ |
| 21 |
return {pts[0].x, pts[0].y, pts[1].x, pts[1].y, pts[2].x, pts[2].y}; |
| 22 |
} |
| 23 |
|
| 24 |
utils::impl::Mat2x2<double> compute_w_fd(std::array<double, 6> pts, int idx) |
| 25 |
{ |
| 26 |
auto ptsAos = convert_pts(pts); |
| 27 |
auto w = DistortionMetric<double>::compute_w(ptsAos); |
| 28 |
|
| 29 |
double eps = 1e-7; |
| 30 |
pts[idx] += eps; |
| 31 |
auto wPert = DistortionMetric<double>::compute_w(convert_pts(pts)); |
| 32 |
auto dWDpt = (wPert - w) / eps; |
| 33 |
pts[idx] -= eps; |
| 34 |
|
| 35 |
return dWDpt; |
| 36 |
} |
| 37 |
|
| 38 |
TEST(DistortionMetric, ComputeW) |
| 39 |
{ |
| 40 |
TriPts<double> pts{utils::Point(0, 0), utils::Point(1, 0), utils::Point(0.5, std::sqrt(3) / 2.0)}; |
| 41 |
auto w = DistortionMetric<double>::compute_w(pts); |
| 42 |
|
| 43 |
EXPECT_FLOAT_EQ(w(0, 0), 1.0); |
| 44 |
EXPECT_FLOAT_EQ(w(0, 1), 0.5); |
| 45 |
EXPECT_FLOAT_EQ(w(1, 0), 0.0); |
| 46 |
EXPECT_FLOAT_EQ(w(1, 1), std::sqrt(3) / 2.0); |
| 47 |
|
| 48 |
TriPts<double> ptsBar; |
| 49 |
utils::impl::Mat2x2<double> wBar{1, 2, 3, 4}; |
| 50 |
DistortionMetric<double>::compute_w_rev(pts, ptsBar, wBar); |
| 51 |
|
| 52 |
// compute finite difference |
| 53 |
std::vector<utils::impl::Mat2x2<double>> dWDptsFd(6); |
| 54 |
std::array<double, 6> ptsArr{pts[0].x, pts[0].y, pts[1].x, pts[1].y, pts[2].x, pts[2].y}; |
| 55 |
for (int i = 0; i < 6; ++i) |
| 56 |
dWDptsFd[i] = compute_w_fd(ptsArr, i); |
| 57 |
|
| 58 |
std::array<double, 6> ptsBarFd; |
| 59 |
for (int i = 0; i < 6; ++i) |
| 60 |
{ |
| 61 |
ptsBarFd[i] = 0; |
| 62 |
for (int j = 0; j < 2; ++j) |
| 63 |
for (int k = 0; k < 2; ++k) |
| 64 |
ptsBarFd[i] += dWDptsFd[i](j, k) * wBar(j, k); |
| 65 |
} |
| 66 |
|
| 67 |
EXPECT_FLOAT_EQ(ptsBar[0].x, ptsBarFd[0]); |
| 68 |
EXPECT_FLOAT_EQ(ptsBar[0].y, ptsBarFd[1]); |
| 69 |
EXPECT_FLOAT_EQ(ptsBar[1].x, ptsBarFd[2]); |
| 70 |
EXPECT_FLOAT_EQ(ptsBar[1].y, ptsBarFd[3]); |
| 71 |
EXPECT_FLOAT_EQ(ptsBar[2].x, ptsBarFd[4]); |
| 72 |
EXPECT_FLOAT_EQ(ptsBar[2].y, ptsBarFd[5]); |
| 73 |
} |
| 74 |
|
| 75 |
TEST(DistortionMetric, ComputeW_dot) |
| 76 |
{ |
| 77 |
TriPts<double> pts{utils::Point(0, 0), utils::Point(1, 0), utils::Point(0.5, std::sqrt(3) / 2.0)}; |
| 78 |
auto w = DistortionMetric<double>::compute_w(pts); |
| 79 |
|
| 80 |
std::array<std::array<double, 2>, 6> ptsDot; |
| 81 |
for (int i = 0; i < 6; ++i) |
| 82 |
ptsDot[i] = std::array<double, 2>{2.0 * i, 2.0 * i + 1}; |
| 83 |
|
| 84 |
auto wDot = DistortionMetric<double>::compute_w_dot(pts, ptsDot); |
| 85 |
|
| 86 |
// finite difference |
| 87 |
double eps = 1e-7; |
| 88 |
for (int i = 0; i < 2; ++i) |
| 89 |
{ |
| 90 |
auto ptsArr = convert_pts(pts); |
| 91 |
for (int j = 0; j < 6; ++j) |
| 92 |
ptsArr[j] += ptsDot[j][i] * eps; |
| 93 |
|
| 94 |
auto wp = DistortionMetric<double>::compute_w(convert_pts(ptsArr)); |
| 95 |
|
| 96 |
for (int j = 0; j < 2; ++j) |
| 97 |
for (int k = 0; k < 2; ++k) |
| 98 |
EXPECT_NEAR((wp(j, k) - w(j, k)) / eps, wDot(j, k)[i], 1e-6); |
| 99 |
|
| 100 |
// pts_arr gets re-created every iteration, no need to reset it |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
TEST(DistortionMetric, ComputeW_rev_dot) |
| 105 |
{ |
| 106 |
TriPts<double> pts{utils::Point(0, 0), utils::Point(1, 0), utils::Point(0.5, std::sqrt(3) / 2.0)}; |
| 107 |
|
| 108 |
utils::impl::Mat2x2<DistortionMetric<double>::DotVec<double>> wBarDot; |
| 109 |
for (int i = 0; i < 2; ++i) |
| 110 |
for (int j = 0; j < 2; ++j) |
| 111 |
{ |
| 112 |
int offset = 2 * i + j; |
| 113 |
wBarDot(i, j) = DistortionMetric<double>::DotVec<double>{2.0 * offset + 1, 2.0 * offset + 1 + 1}; |
| 114 |
} |
| 115 |
|
| 116 |
DistortionMetric<double>::PtsDot<double> ptsBarDot; |
| 117 |
DistortionMetric<double>::compute_w_rev_dot(pts, wBarDot, ptsBarDot); |
| 118 |
|
| 119 |
// finite difference |
| 120 |
TriPts<double> ptsBar; |
| 121 |
utils::impl::Mat2x2<double> wBar = {1, 2, 3, 4}; // this value is arbitrary because |
| 122 |
// compute_w_rev_dot does not depend |
| 123 |
// on it |
| 124 |
DistortionMetric<double>::compute_w_rev(pts, ptsBar, wBar); |
| 125 |
double eps = 1e-7; |
| 126 |
for (int i = 0; i < 2; ++i) |
| 127 |
{ |
| 128 |
for (int j = 0; j < 2; ++j) |
| 129 |
for (int k = 0; k < 2; ++k) |
| 130 |
wBar(j, k) += wBarDot(j, k)[i] * eps; |
| 131 |
|
| 132 |
TriPts<double> ptspBar; |
| 133 |
DistortionMetric<double>::compute_w_rev(pts, ptspBar, wBar); |
| 134 |
|
| 135 |
for (int j = 0; j < 3; ++j) |
| 136 |
{ |
| 137 |
EXPECT_NEAR((ptspBar[j].x - ptsBar[j].x) / eps, ptsBarDot[2 * j][i], 1e-6); |
| 138 |
EXPECT_NEAR((ptspBar[j].y - ptsBar[j].y) / eps, ptsBarDot[2 * j + 1][i], 1e-6); |
| 139 |
} |
| 140 |
|
| 141 |
for (int j = 0; j < 2; ++j) |
| 142 |
for (int k = 0; k < 2; ++k) |
| 143 |
wBar(j, k) -= wBarDot(j, k)[i] * eps; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
void compute_distortion_fd(DistortionMetric<double>& metric, TriPts<double>& pts, TriPts<double>& ptsBar, TriPts<double>& ptsBarFd) |
| 148 |
{ |
| 149 |
double qBar = 0.816497, eps = 1e-7; |
| 150 |
utils::impl::Mat2x2<double> w{0.5, 0, 0, 0.5}; |
| 151 |
metric.get_deriv(pts, w, ptsBar, qBar); |
| 152 |
|
| 153 |
auto qVal = metric.get_value(pts, w); |
| 154 |
for (int i = 0; i < 3; ++i) |
| 155 |
{ |
| 156 |
pts[i].x += eps; |
| 157 |
ptsBarFd[i].x = qBar * (metric.get_value(pts, w) - qVal) / eps; |
| 158 |
pts[i].x -= eps; |
| 159 |
|
| 160 |
pts[i].y += eps; |
| 161 |
ptsBarFd[i].y = qBar * (metric.get_value(pts, w) - qVal) / eps; |
| 162 |
pts[i].y -= eps; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
TEST(RegularizedDistortionMetric, Gamma0) |
| 167 |
{ |
| 168 |
RegularizedDistortionMetric<double> metric(0); |
| 169 |
TriPts<double> ptsIdeal{utils::Point(0, 0), utils::Point(1, 0), utils::Point(0.5, std::sqrt(3) / 2.0)}; |
| 170 |
auto w = DistortionMetric<double>::compute_w(ptsIdeal); |
| 171 |
|
| 172 |
EXPECT_FLOAT_EQ(metric.get_value(ptsIdeal, w), 1.0); |
| 173 |
|
| 174 |
// test scale invariance |
| 175 |
{ |
| 176 |
TriPts<double> pts{ptsIdeal[0] * 2, ptsIdeal[1] * 2, ptsIdeal[2] * 2}; |
| 177 |
EXPECT_FLOAT_EQ(metric.get_value(pts, w), 1.0); |
| 178 |
} |
| 179 |
|
| 180 |
// test that value increases for lower quality elements |
| 181 |
{ |
| 182 |
TriPts<double> pts{utils::Point(0, 0), utils::Point(1, 0), utils::Point(0.5, std::sqrt(3))}; |
| 183 |
EXPECT_GE(metric.get_value(pts, w), 1.0); |
| 184 |
} |
| 185 |
|
| 186 |
// test invalid element |
| 187 |
{ |
| 188 |
TriPts<double> pts{utils::Point(0, 0), utils::Point(1, 0), utils::Point(0.5, -std::sqrt(3))}; |
| 189 |
EXPECT_FALSE(std::isfinite(metric.get_value(pts, w))); |
| 190 |
} |
| 191 |
|
| 192 |
// test derivative |
| 193 |
{ |
| 194 |
TriPts<double> pts{utils::Point(0.6, 0.6), utils::Point(1, 0.5), utils::Point(0.5, 1)}; |
| 195 |
TriPts<double> ptsBar, ptsBarFd; |
| 196 |
compute_distortion_fd(metric, pts, ptsBar, ptsBarFd); |
| 197 |
for (int i = 0; i < 3; ++i) |
| 198 |
{ |
| 199 |
EXPECT_NEAR(ptsBar[i].x, ptsBarFd[i].x, 5e-6); |
| 200 |
EXPECT_NEAR(ptsBar[i].y, ptsBarFd[i].y, 5e-6); |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
TEST(RegularizedDistortionMetric, Gamma01) |
| 206 |
{ |
| 207 |
RegularizedDistortionMetric<double> metric(0.01); |
| 208 |
TriPts<double> ptsIdeal{utils::Point(0, 0), utils::Point(1, 0), utils::Point(0.5, std::sqrt(3) / 2.0)}; |
| 209 |
auto w = DistortionMetric<double>::compute_w(ptsIdeal); |
| 210 |
|
| 211 |
EXPECT_FLOAT_EQ(metric.get_value(ptsIdeal, w), 1.0); |
| 212 |
|
| 213 |
// test derivative |
| 214 |
{ |
| 215 |
TriPts<double> pts{ptsIdeal[0] * 2, ptsIdeal[1] * 2, ptsIdeal[2] * 2}; |
| 216 |
TriPts<double> ptsBar, ptsBarFd; |
| 217 |
compute_distortion_fd(metric, pts, ptsBar, ptsBarFd); |
| 218 |
for (int i = 0; i < 3; ++i) |
| 219 |
{ |
| 220 |
EXPECT_NEAR(ptsBar[i].x, ptsBarFd[i].x, 1e-6); |
| 221 |
EXPECT_NEAR(ptsBar[i].y, ptsBarFd[i].y, 1e-6); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
// test derivative on invalid element |
| 226 |
{ |
| 227 |
TriPts<double> pts{ptsIdeal[0] * 2, ptsIdeal[1] * 2, ptsIdeal[2] * 2}; |
| 228 |
pts[1].y = -pts[1].y; |
| 229 |
TriPts<double> ptsBar, ptsBarFd; |
| 230 |
compute_distortion_fd(metric, pts, ptsBar, ptsBarFd); |
| 231 |
for (int i = 0; i < 3; ++i) |
| 232 |
{ |
| 233 |
EXPECT_NEAR(ptsBar[i].x, ptsBarFd[i].x, 1e-6); |
| 234 |
EXPECT_NEAR(ptsBar[i].y, ptsBarFd[i].y, 1e-6); |
| 235 |
} |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
TEST(RegularizedDistortionMetric, HessianProduct) |
| 240 |
{ |
| 241 |
using PtsDot = DistortionMetric<double>::PtsDot<double>; |
| 242 |
using DotVec = DistortionMetric<double>::DotVec<double>; |
| 243 |
|
| 244 |
RegularizedDistortionMetric<double> metric(0.2); |
| 245 |
TriPts<double> ptsIdeal{utils::Point(0, 0), utils::Point(1, 0), utils::Point(0.5, std::sqrt(3) / 2.0)}; |
| 246 |
auto w = DistortionMetric<double>::compute_w(ptsIdeal); |
| 247 |
|
| 248 |
EXPECT_FLOAT_EQ(metric.get_value(ptsIdeal, w), 1.0); |
| 249 |
|
| 250 |
// test derivative |
| 251 |
{ |
| 252 |
TriPts<double> pts{ptsIdeal[0], ptsIdeal[1], ptsIdeal[2]}; |
| 253 |
// make element invalid |
| 254 |
pts[2].y = -pts[2].y; |
| 255 |
|
| 256 |
double minDenominator = metric.compute_denominator(pts, w); |
| 257 |
metric.set_min_denominator(minDenominator); |
| 258 |
|
| 259 |
PtsDot ptsDot, ptsBarDot; |
| 260 |
double qBar = 2; |
| 261 |
DotVec qBarDot = {13.0, 14.0}; |
| 262 |
for (int i = 0; i < 6; ++i) |
| 263 |
ptsDot[i] = DistortionMetric<double>::DotVec<double>{2.0 * i + 1, 2.0 * i + 2}; |
| 264 |
|
| 265 |
metric.get_value_rev_dot(pts, w, ptsDot, qBar, qBarDot, ptsBarDot); |
| 266 |
|
| 267 |
// finite difference get_deriv |
| 268 |
TriPts<double> derivs0; |
| 269 |
double eps = 1e-7; |
| 270 |
metric.get_deriv(pts, w, derivs0, qBar); |
| 271 |
auto derivs0Arr = convert_pts(derivs0); |
| 272 |
for (int i = 0; i < 2; ++i) |
| 273 |
{ |
| 274 |
auto ptsArr = convert_pts(pts); |
| 275 |
for (int j = 0; j < 6; ++j) |
| 276 |
ptsArr[j] += eps * ptsDot[j][i]; |
| 277 |
qBar += eps * qBarDot[i]; |
| 278 |
|
| 279 |
TriPts<double> derivs; |
| 280 |
metric.get_deriv(convert_pts(ptsArr), w, derivs, qBar); |
| 281 |
|
| 282 |
auto derivsArr = convert_pts(derivs); |
| 283 |
for (int j = 0; j < 6; ++j) |
| 284 |
{ |
| 285 |
double valFd = (derivsArr[j] - derivs0Arr[j]) / eps; |
| 286 |
double scale = std::min(std::abs(valFd), std::abs(ptsBarDot[j][i])); |
| 287 |
EXPECT_NEAR(valFd, ptsBarDot[j][i], 5e-6 * scale); |
| 288 |
} |
| 289 |
|
| 290 |
qBar -= eps * qBarDot[i]; |
| 291 |
} |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
TEST(RegularizedDistortionMetric, Regression) |
| 297 |
{ |
| 298 |
TriPts<double> pts = { utils::Point(0.875, 0.875, 0), utils::Point(1, 0.75, 0), utils::Point(0.75, 1, 0) }; |
| 299 |
utils::impl::Mat2x2<double> W = {0.25, 0, 0, 0.25}; |
| 300 |
double gamma = 1e-1; |
| 301 |
int localidx = 0; |
| 302 |
|
| 303 |
RegularizedDistortionMetric<double> metric(gamma); |
| 304 |
metric.set_min_denominator(metric.compute_denominator(pts, W)); |
| 305 |
|
| 306 |
TriPts<double> derivs; |
| 307 |
metric.get_deriv(pts, W, derivs, 1); |
| 308 |
|
| 309 |
EXPECT_GT(std::abs(derivs[localidx][0]), 0.01); |
| 310 |
EXPECT_GT(std::abs(derivs[localidx][1]), 0.01); |
| 311 |
} |
| 312 |
|
| 313 |
TEST(RegularizedDistortionMetric, Regression2) |
| 314 |
{ |
| 315 |
using Complex = std::complex<double>; |
| 316 |
|
| 317 |
TriPts<double> pts = { utils::Point(1.456521739130435, 0, 0), |
| 318 |
utils::Point(1.288338373852929, 0.2913272354863573, 0), |
| 319 |
utils::Point(1.402509962006577, 0.3929648623374049, 0)}; |
| 320 |
|
| 321 |
utils::impl::Mat2x2<double> w({-0.012145808108736, -0.05401177712385752, 0.4046951567355364, 0.3929648623374049}); |
| 322 |
|
| 323 |
double gamma = 1e-3; |
| 324 |
int localidx = 0; |
| 325 |
|
| 326 |
RegularizedDistortionMetric<double> metric(gamma); |
| 327 |
metric.set_min_denominator(metric.compute_denominator(pts, w)); |
| 328 |
RegularizedDistortionMetric<Complex> metricC(metric); |
| 329 |
|
| 330 |
|
| 331 |
TriPts<double> derivs; |
| 332 |
metric.get_deriv(pts, w, derivs, 1); |
| 333 |
|
| 334 |
utils::Point grad = derivs[localidx]; |
| 335 |
|
| 336 |
// complex step |
| 337 |
TriPts<Complex> ptsC; |
| 338 |
ptsC[0] = pts[0]; |
| 339 |
ptsC[1] = pts[1]; |
| 340 |
ptsC[2] = pts[2]; |
| 341 |
|
| 342 |
double h = 1e-40; |
| 343 |
Complex pert(0, h); |
| 344 |
ptsC[localidx].x += pert; |
| 345 |
Complex qx = metricC.get_value(ptsC, w); |
| 346 |
ptsC[localidx].x -= pert; |
| 347 |
|
| 348 |
ptsC[localidx].y += pert; |
| 349 |
Complex qy = metricC.get_value(ptsC, w); |
| 350 |
ptsC[localidx].y -= pert; |
| 351 |
|
| 352 |
utils::Point gradC(qx.imag()/h, qy.imag()/h); |
| 353 |
|
| 354 |
for (int i=0; i < 2; ++i) |
| 355 |
{ |
| 356 |
double minMagnitude = std::min(std::abs(grad[i]), std::abs(gradC[i])); |
| 357 |
double errRelative = std::abs(grad[i] - gradC[i])/minMagnitude; |
| 358 |
double errAbs = std::abs(grad[i] - gradC[i]); |
| 359 |
double err = std::min(errAbs, errRelative); |
| 360 |
EXPECT_LT(err, 1e-12); |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
TEST(RegularizedDistortionMetric, Regression3) |
| 365 |
{ |
| 366 |
using Complex = std::complex<double>; |
| 367 |
using DotVec = DistortionMetric<double>::DotVec<double>; |
| 368 |
using PtsDot = DistortionMetric<double>::PtsDot<double>; |
| 369 |
|
| 370 |
TriPts<double> pts = { utils::Point(1.456521739130435, 0, 0), |
| 371 |
utils::Point(1.288338373852929, 0.2913272354863573, 0 ), |
| 372 |
utils::Point(1.402509962006577, 0.3929648623374049, 0)}; |
| 373 |
|
| 374 |
utils::impl::Mat2x2<double> w({-0.012145808108736, -0.05401177712385752, 0.4046951567355364, 0.3929648623374049}); |
| 375 |
double qIBar = 0.2041241452319302; |
| 376 |
DotVec qIBarDot = {6.661338147750939e-15, -0.5597855687575399}; |
| 377 |
|
| 378 |
double gamma = 1e-3; |
| 379 |
int localidx = 0; |
| 380 |
|
| 381 |
RegularizedDistortionMetric<double> metric(gamma); |
| 382 |
metric.set_min_denominator(metric.compute_denominator(pts, w)); |
| 383 |
RegularizedDistortionMetric<Complex> metricC(metric); |
| 384 |
|
| 385 |
|
| 386 |
PtsDot ptsBarDot; |
| 387 |
PtsDot ptsIDot; |
| 388 |
for (int j = 0; j < 6; ++j) |
| 389 |
for (int k = 0; k < 2; ++k) |
| 390 |
ptsIDot[j][k] = 0; |
| 391 |
|
| 392 |
ptsIDot[2 * localidx][0] = 1; |
| 393 |
ptsIDot[2 * localidx + 1][1] = 1; |
| 394 |
|
| 395 |
metric.get_value_rev_dot(pts, w, ptsIDot, qIBar, qIBarDot, ptsBarDot); |
| 396 |
|
| 397 |
utils::impl::Mat2x2<double> hess; |
| 398 |
hess(0, 0) = ptsBarDot[2 * localidx][0]; |
| 399 |
hess(0, 1) = ptsBarDot[2 * localidx][1]; |
| 400 |
hess(1, 0) = ptsBarDot[2 * localidx + 1][0]; |
| 401 |
hess(1, 1) = ptsBarDot[2 * localidx + 1][1]; |
| 402 |
|
| 403 |
|
| 404 |
// complex step |
| 405 |
TriPts<Complex> ptsC; |
| 406 |
ptsC[0] = pts[0]; |
| 407 |
ptsC[1] = pts[1]; |
| 408 |
ptsC[2] = pts[2]; |
| 409 |
|
| 410 |
double h = 1e-40; |
| 411 |
Complex pert(0, h); |
| 412 |
|
| 413 |
Complex qBarx(qIBar, h*qIBarDot[0]); |
| 414 |
TriPts<Complex> derivsx; |
| 415 |
ptsC[localidx].x += pert; |
| 416 |
metricC.get_deriv(ptsC, w, derivsx, qBarx); |
| 417 |
ptsC[localidx].x -= pert; |
| 418 |
|
| 419 |
ptsC[localidx].y += pert; |
| 420 |
Complex qBary(qIBar, h*qIBarDot[1]); |
| 421 |
TriPts<Complex> derivsy; |
| 422 |
metricC.get_deriv(ptsC, w, derivsy, qBary); |
| 423 |
ptsC[localidx].y -= pert; |
| 424 |
|
| 425 |
utils::impl::Mat2x2<double> hessC; |
| 426 |
hessC(0, 0) = derivsx[localidx].x.imag()/h; |
| 427 |
hessC(1, 0) = derivsx[localidx].y.imag()/h; |
| 428 |
hessC(0, 1) = derivsy[localidx].x.imag()/h; |
| 429 |
hessC(1, 1) = derivsy[localidx].y.imag()/h; |
| 430 |
|
| 431 |
for (int i=0; i < 2; ++i) |
| 432 |
for (int j=0; j < 2; ++j) |
| 433 |
{ |
| 434 |
double minMagnitude = std::min(std::abs(hess(i, j)), std::abs(hessC(i, j))); |
| 435 |
double errRelative = std::abs(hess(i, j) - hessC(i, j))/minMagnitude; |
| 436 |
double errAbs = std::abs(hess(i, j) - hessC(i, j)); |
| 437 |
double err = std::min(errAbs, errRelative); |
| 438 |
EXPECT_LT(err, 1e-12); |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
} // namespace impl |
| 443 |
} // namespace middle_mesh |
| 444 |
} // namespace stk |