Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (1.4)

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/dynvector.hh>
14#include <dune/common/dynmatrix.hh>
15
16namespace Dune
17{
18
24{
25 Vertex,
26 Element
27};
28
40template<class IGridView, class IGridMapper, CurvatureLayout CL = Vertex>
42{
43public:
44 static constexpr int dim = IGridView::dimensionworld;
45 using Scalar = typename IGridView::ctype;
46 using Vector = Dune::FieldVector<Scalar, dim>;
47
55 CurvatureOperator(const IGridView& iGridView, const IGridMapper& iGridMapper)
56 : iGridView_(iGridView), iGridMapper_(iGridMapper) {};
57
70 template<class Curvatures, class Centers, CurvatureLayout Layout = CL>
71 std::enable_if_t<Layout == Vertex, void>
72 operator() (Curvatures& curvatures, Centers& centers) const
73 {
74 //storage for incident interface vertices
75 std::vector<Vector> vertexPoints;
76 Vector center;
77
78 for (const auto& vertex : vertices(iGridView_))
79 {
80 const int iVertexIdx = iGridMapper_.index(vertex);
81 vertexPoints.clear();
82 vertexPoints.push_back(vertex.geometry().center());
83
84 for (const auto& incidentVertex : incidentInterfaceVertices(vertex))
85 {
86 vertexPoints.push_back(incidentVertex.geometry().center());
87 }
88
89 //determine curvature associated with iVertexMapper (approximated by a
90 //sphere with center "center")
91 curvatures[iVertexIdx] = 1.0 / getRadius(vertexPoints, center);
92 centers[iVertexIdx] = center;
93 }
94 }
95
96 template<class Curvatures, class Centers, CurvatureLayout Layout = CL>
97 std::enable_if_t<Layout == Element, void>
98 operator() (Curvatures& curvatures, Centers& centers) const
99 {
100 //storage for vertices of incident interface elements
101 std::vector<Vector> vertexPoints;
102 Vector center;
103
104 for (const auto& iElem : elements(iGridView_))
105 {
106 int iElemIdx = iGridMapper_.index(iElem);
107 vertexPoints.clear();
108
109 for (const auto& intersct : intersections(iGridView_, iElem))
110 {
111 const auto& neighborGeo = intersct.outside().geometry();
112
113 for (int i = 0; i < neighborGeo.corners(); i++)
114 {
115 if (std::find(vertexPoints.begin(), vertexPoints.end(),
116 neighborGeo.corner(i)) == vertexPoints.end())
117 {
118 vertexPoints.push_back(neighborGeo.corner(i));
119 }
120 }
121 }
122
123 //determine curvature associated with iElem (approximated by a sphere
124 //with center "center")
125 curvatures[iElemIdx] = 1.0 / getRadius(vertexPoints, center);
126 centers[iElemIdx] = center;
127 }
128 }
129
130private:
141 template< class Points >
142 double getRadius (const Points& points, Vector& center) const
143 {
144 using LargeVector = Dune::FieldVector<Scalar, dim+1>;
145 using Matrix = Dune::FieldMatrix<Scalar, dim+1, dim+1>;
146 using LargeDynVector = Dune::DynamicVector<Scalar>;
147 using DynMatrix = Dune::DynamicMatrix<Scalar>;
148
149 LargeDynVector b(points.size(), 0.0);
150 DynMatrix A(points.size(), dim+1, 0.0);
151 LargeVector x(0.0);
152 LargeVector ATb(0.0); //A.transpose()*b
153 Matrix ATA(0.0); //A.transpose()*A
154
155 for (unsigned int i = 0; i < points.size(); i++)
156 {
157 b[i] = -points[i].two_norm2();
158 A[i][0] = 1.0;
159
160 for (int j = 0; j < dim; j++)
161 {
162 A[i][j+1] = points[i][j];
163 }
164 }
165
166 A.mtv(b, ATb);
167
168 for (int i = 0; i <= dim; i++)
169 for (int j = 0; j <= dim; j++)
170 for (std::size_t k = 0; k < points.size(); k ++)
171 ATA[i][j] += A[k][i] * A[k][j];
172
173 if (std::abs( ATA.determinant() ) > epsilon)
174 {
175 ATA.solve(x, ATb);
176
177 double r = 0.0;
178 for (int j = 1; j <= dim; j++)
179 {
180 r += x[j]*x[j];
181 center[j-1] = -0.5*x[j];
182 }
183
184 r = sqrt(std::abs(0.25*r - x[0]));
185
186 return r;
187 }
188
189 return std::numeric_limits<double>::infinity();
190 }
191
192 //The grid view of the interface grid
193 const IGridView& iGridView_;
194 //Element mapper for the interface grid
195 const IGridMapper& iGridMapper_;
196
197 //floating point accuracy
198 static constexpr double epsilon = std::numeric_limits<double>::epsilon();
199};
200
201} // end namespace Dune
202
203#endif
Class defining an operator that assigns a curvature to each element or each vertex of the interface g...
Definition: curvatureoperator.hh:42
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:72
CurvatureOperator(const IGridView &iGridView, const IGridMapper &iGridMapper)
Constructor.
Definition: curvatureoperator.hh:55
CurvatureLayout
used as template parameter that determines whether the curvature is approximated at the elemets or th...
Definition: curvatureoperator.hh:24
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 13, 22:42, 2025)