Dune Core Modules (unstable)

comparegeometries.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_GEOMETRY_TEST_COMPAREGEOMETRIES_HH
6#define DUNE_GEOMETRY_TEST_COMPAREGEOMETRIES_HH
7
8#include <cmath>
9#include <iostream>
10#include <limits>
11#include <type_traits>
12
13namespace Dune {
14
15template <class R>
16R defaultTolerance ()
17{
18 using std::sqrt;
19 return sqrt(std::numeric_limits<R>::epsilon());
20}
21
22template <class Geometry1, class Geometry2,
23 class R = std::common_type_t<typename Geometry1::ctype, typename Geometry2::ctype>>
24bool compareGeometries (const Geometry1& geo1, const Geometry2& geo2,
25 R tolerance = defaultTolerance<R>())
26{
27 if constexpr(Geometry1::mydimension != Geometry2::mydimension) {
28 std::cerr << "Error: Dimensions do not match." << std::endl;
29 return false;
30 }
31 else if constexpr(Geometry1::coorddimension != Geometry2::coorddimension) {
32 std::cerr << "Error: Coord-dimensions do not match." << std::endl;
33 return false;
34 }
35 else {
36 using std::abs;
37
38 if (geo1.affine() != geo2.affine()) {
39 std::cerr << "Error: Affine-property does not match." << std::endl;
40 return false;
41 }
42
43 if (geo1.type() != geo2.type()) {
44 std::cerr << "Error: GeometryType does not match." << std::endl;
45 return false;
46 }
47
48 if (geo1.corners() != geo2.corners()) {
49 std::cerr << "Error: Number of corners does not match." << std::endl;
50 return false;
51 }
52
53 for (int i = 0; i < geo1.corners(); ++i) {
54 if ((geo1.corner(i) - geo2.corner(i)).two_norm() > tolerance) {
55 std::cerr << "Error: Corner " << i << " does not match." << std::endl;
56 return false;
57 }
58 }
59
60 if ((geo1.center() - geo2.center()).two_norm() > tolerance) {
61 std::cerr << "Error: Center does not match." << std::endl;
62 return false;
63 }
64
65 if (abs(geo1.volume() - geo2.volume()) > tolerance) {
66 std::cerr << "Error: Volume does not match." << std::endl;
67 return false;
68 }
69
70 const auto& quadrature = Dune::QuadratureRules<R, Geometry1::mydimension>::rule(geo1.type(), 4);
71 for (auto&& [pos,weight] : quadrature)
72 {
73 if ((geo1.global(pos) - geo2.global(pos)).two_norm() > tolerance) {
74 std::cerr << "Error: global(" << pos << ") does not match." << std::endl;
75 return false;
76 }
77
78 if ((geo1.jacobian(pos) - geo2.jacobian(pos)).frobenius_norm() > tolerance) {
79 std::cerr << "Error: jacobian(" << pos << ") does not match." << std::endl;
80 return false;
81 }
82
83 if ((geo1.jacobianTransposed(pos) - geo2.jacobianTransposed(pos)).frobenius_norm() > tolerance) {
84 std::cerr << "Error: jacobianTransposed(" << pos << ") does not match." << std::endl;
85 return false;
86 }
87
88 if ((geo1.jacobianInverse(pos) - geo2.jacobianInverse(pos)).frobenius_norm() > tolerance) {
89 std::cerr << "Error: jacobianInverse(" << pos << ") does not match." << std::endl;
90 return false;
91 }
92
93 if ((geo1.jacobianInverseTransposed(pos) - geo2.jacobianInverseTransposed(pos)).frobenius_norm() > tolerance) {
94 std::cerr << "Error: jacobianInverse(" << pos << ") does not match." << std::endl;
95 return false;
96 }
97
98 if (abs(geo1.integrationElement(pos) - geo2.integrationElement(pos)) > tolerance) {
99 std::cerr << "Error: integrationElement(" << pos << ") does not match." << std::endl;
100 return false;
101 }
102 }
103
104 return true;
105 }
106}
107
108} // end namespace Dune
109
110#endif // DUNE_GEOMETRY_TEST_COMPAREGEOMETRIES_HH
static const QuadratureRule & rule(const GeometryType &t, int p, QuadratureType::Enum qt=QuadratureType::GaussLegendre)
select the appropriate QuadratureRule for GeometryType t and order p
Definition: quadraturerules.hh:326
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)