dune-mmesh (unstable)

curvatureoperator.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
9#ifndef DUNE_MMESH_INTERFACE_CURVATUREOPERATOR_HH
10#define DUNE_MMESH_INTERFACE_CURVATUREOPERATOR_HH
11
12#include <algorithm>
13#include <dune/common/dynmatrix.hh>
14#include <dune/common/dynvector.hh>
15
16namespace Dune {
17
22enum CurvatureLayout { Vertex, Element };
23
35template <class IGridView, class IGridMapper, CurvatureLayout CL = Vertex>
37 public:
38 static constexpr int dim = IGridView::dimensionworld;
39 using Scalar = typename IGridView::ctype;
40 using Vector = Dune::FieldVector<Scalar, dim>;
41
49 CurvatureOperator(const IGridView& iGridView, const IGridMapper& iGridMapper)
50 : iGridView_(iGridView), iGridMapper_(iGridMapper){};
51
64 template <class Curvatures, class Centers, CurvatureLayout Layout = CL>
65 std::enable_if_t<Layout == Vertex, void> operator()(Curvatures& curvatures,
66 Centers& centers) const {
67 // storage for incident interface vertices
68 std::vector<Vector> vertexPoints;
69 Vector center;
70
71 for (const auto& vertex : vertices(iGridView_)) {
72 const int iVertexIdx = iGridMapper_.index(vertex);
73 vertexPoints.clear();
74 vertexPoints.push_back(vertex.geometry().center());
75
76 for (const auto& incidentVertex : incidentInterfaceVertices(vertex)) {
77 vertexPoints.push_back(incidentVertex.geometry().center());
78 }
79
80 // determine curvature associated with iVertexMapper (approximated by a
81 // sphere with center "center")
82 curvatures[iVertexIdx] = 1.0 / getRadius(vertexPoints, center);
83 centers[iVertexIdx] = center;
84 }
85 }
86
87 template <class Curvatures, class Centers, CurvatureLayout Layout = CL>
88 std::enable_if_t<Layout == Element, void> operator()(Curvatures& curvatures,
89 Centers& centers) const {
90 // storage for vertices of incident interface elements
91 std::vector<Vector> vertexPoints;
92 Vector center;
93
94 for (const auto& iElem : elements(iGridView_)) {
95 int iElemIdx = iGridMapper_.index(iElem);
96 vertexPoints.clear();
97
98 for (const auto& intersct : intersections(iGridView_, iElem)) {
99 const auto& neighborGeo = intersct.outside().geometry();
100
101 for (int i = 0; i < neighborGeo.corners(); i++) {
102 if (std::find(vertexPoints.begin(), vertexPoints.end(),
103 neighborGeo.corner(i)) == vertexPoints.end()) {
104 vertexPoints.push_back(neighborGeo.corner(i));
105 }
106 }
107 }
108
109 // determine curvature associated with iElem (approximated by a sphere
110 // with center "center")
111 curvatures[iElemIdx] = 1.0 / getRadius(vertexPoints, center);
112 centers[iElemIdx] = center;
113 }
114 }
115
116 private:
127 template <class Points>
128 double getRadius(const Points& points, Vector& center) const {
129 using LargeVector = Dune::FieldVector<Scalar, dim + 1>;
130 using Matrix = Dune::FieldMatrix<Scalar, dim + 1, dim + 1>;
131 using LargeDynVector = Dune::DynamicVector<Scalar>;
132 using DynMatrix = Dune::DynamicMatrix<Scalar>;
133
134 LargeDynVector b(points.size(), 0.0);
135 DynMatrix A(points.size(), dim + 1, 0.0);
136 LargeVector x(0.0);
137 LargeVector ATb(0.0); // A.transpose()*b
138 Matrix ATA(0.0); // A.transpose()*A
139
140 for (unsigned int i = 0; i < points.size(); i++) {
141 b[i] = -points[i].two_norm2();
142 A[i][0] = 1.0;
143
144 for (int j = 0; j < dim; j++) {
145 A[i][j + 1] = points[i][j];
146 }
147 }
148
149 A.mtv(b, ATb);
150
151 for (int i = 0; i <= dim; i++)
152 for (int j = 0; j <= dim; j++)
153 for (std::size_t k = 0; k < points.size(); k++)
154 ATA[i][j] += A[k][i] * A[k][j];
155
156 if (std::abs(ATA.determinant()) > epsilon) {
157 ATA.solve(x, ATb);
158
159 double r = 0.0;
160 for (int j = 1; j <= dim; j++) {
161 r += x[j] * x[j];
162 center[j - 1] = -0.5 * x[j];
163 }
164
165 r = sqrt(std::abs(0.25 * r - x[0]));
166
167 return r;
168 }
169
170 return std::numeric_limits<double>::infinity();
171 }
172
173 // The grid view of the interface grid
174 const IGridView& iGridView_;
175 // Element mapper for the interface grid
176 const IGridMapper& iGridMapper_;
177
178 // floating point accuracy
179 static constexpr double epsilon = std::numeric_limits<double>::epsilon();
180};
181
182} // end namespace Dune
183
184#endif
Class defining an operator that assigns a curvature to each element or each vertex of the interface g...
Definition: curvatureoperator.hh:36
std::enable_if_t< Layout==Vertex, void > operator()(Curvatures &curvatures, Centers &centers) const
Operator that assigns a curvature to each element or each vertex of the interface grid....
Definition: curvatureoperator.hh:65
CurvatureOperator(const IGridView &iGridView, const IGridMapper &iGridMapper)
Constructor.
Definition: curvatureoperator.hh:49
CurvatureLayout
used as template parameter that determines whether the curvature is approximated at the elemets or th...
Definition: curvatureoperator.hh:22
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Sep 4, 22:38, 2025)