Dune Core Modules (unstable)

mappedgeometry.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_MAPPEDGEOMETRY_HH
6#define DUNE_GEOMETRY_MAPPEDGEOMETRY_HH
7
8#include <cassert>
9#include <limits>
10#include <optional>
11#include <stdexcept>
12#include <type_traits>
13
14#include <dune/common/copyableoptional.hh>
18#include <dune/common/math.hh>
19#include <dune/common/transpose.hh>
20#include <dune/geometry/affinegeometry.hh> // for FieldMatrixHelper
22#include <dune/geometry/referenceelements.hh>
23#include <dune/geometry/type.hh>
24#include <dune/geometry/utility/algorithms.hh>
25#include <dune/geometry/utility/convergence.hh>
26
27namespace Dune {
28
63template <class Map, class Geo>
65{
66public:
68 using LocalCoordinate = typename Geo::LocalCoordinate;
69
71 using GlobalCoordinate = std::remove_reference_t<decltype(std::declval<Map>()(std::declval<typename Geo::GlobalCoordinate>()))>;
72
74 using ctype = typename Geo::ctype;
75
77 static constexpr int mydimension = LocalCoordinate::size();
78
80 static constexpr int coorddimension = GlobalCoordinate::size();
81
83 using Volume = std::remove_reference_t<decltype(Dune::power(std::declval<ctype>(),mydimension))>;
84
87
90
93
96
97private:
99 using ReferenceElement = typename ReferenceElements::ReferenceElement;
100
101protected:
102 using MatrixHelper = Impl::FieldMatrixHelper<ctype>;
103
104 // type of the mapping representation the geometry parametrization
105 using Mapping = Map;
106
107 // type of the geometry that is wrapped
108 using Geometry = Geo;
109
110 // type of a mapping representing the derivative of `Map` w.r.t. `GlobalCoordinate`
111 using DerivativeMapping = std::remove_reference_t<decltype(derivative(std::declval<Map>()))>;
112
113public:
122 template <class Geo_, class Map_,
123 std::enable_if_t<Dune::IsInteroperable<Map, Map_>::value, int> = 0,
124 std::enable_if_t<Dune::IsInteroperable<Geo, Geo_>::value, int> = 0>
125 MappedGeometry (Map_&& mapping, Geo_&& geometry, bool affine = false)
126 : mapping_(std::forward<Map_>(mapping))
127 , dMapping_(derivative(*mapping_))
128 , geometry_(std::forward<Geo_>(geometry))
129 , affine_(affine)
130 {}
131
137 bool affine () const
138 {
139 return affine_;
140 }
141
144 {
145 return geometry_.type();
146 }
147
149 int corners () const
150 {
151 return geometry_.corners();
152 }
153
156 {
157 assert( (i >= 0) && (i < corners()) );
158 return mapping()(geometry_.corner(i));
159 }
160
163 {
164 return mapping()(geometry_.center());
165 }
166
177 {
178 return mapping()(geometry_.global(local));
179 }
180
197 LocalCoordinate local (const GlobalCoordinate& y, Impl::GaussNewtonOptions<ctype> opts = {}) const
198 {
199 LocalCoordinate x = refElement().position(0,0);
200 Impl::GaussNewtonErrorCode err = Impl::gaussNewton(
201 [&](const LocalCoordinate& local) { return this->global(local); },
202 [&](const LocalCoordinate& local) { return this->jacobianTransposed(local); },
203 y, x, opts
204 );
205
206 if (err != Impl::GaussNewtonErrorCode::OK)
208 "Local coordinate can not be recovered from global coordinate, error code = " << int(err) << "\n"
209 << " (global(x) - y).two_norm() = " << (global(x) - y).two_norm()
210 << " > tol = " << opts.absTol);
211
212 return x;
213 }
214
226 {
227 return MatrixHelper::sqrtDetAAT(jacobianTransposed(local));
228 }
229
241 Volume volume (Impl::ConvergenceOptions<ctype> opts = {}) const
242 {
244 if (affine())
245 return vol0;
246
247 using std::abs;
248 for (int p = 2; p < opts.maxIt; ++p) {
250 if (abs(vol1 - vol0) < opts.absTol)
251 return vol1;
252
253 vol0 = vol1;
254 }
255 return vol0;
256 }
257
260 {
261 Volume vol(0);
262 for (const auto& qp : quadRule)
263 vol += integrationElement(qp.position()) * qp.weight();
264 return vol;
265 }
266
272 Jacobian jacobian (const LocalCoordinate& local) const
273 {
274 auto&& jLocal = geometry_.jacobian(local);
275 auto&& jMapping = (*dMapping_)(geometry_.global(local));
276 return jMapping * jLocal;
277 }
278
285 {
286 return transpose(jacobian(local));
287 }
288
297 {
298 JacobianInverse out;
299 MatrixHelper::leftInvA(jacobian(local), out);
300 return out;
301 }
302
311 {
312 return transpose(jacobianInverse(local));
313 }
314
316 friend ReferenceElement referenceElement (const MappedGeometry& geometry)
317 {
318 return geometry.refElement();
319 }
320
321protected:
322 // the internal stored reference element
323 ReferenceElement refElement () const
324 {
325 return referenceElement(geometry_);
326 }
327
328private:
329 // internal reference to the stored mapping
330 const Mapping& mapping () const
331 {
332 return *mapping_;
333 }
334
335 // internal reference to the wrapped geometry
336 const Geometry& geometry () const
337 {
338 return geometry_;
339 }
340
341private:
343 CopyableOptional<Mapping> mapping_;
344
346 CopyableOptional<DerivativeMapping> dMapping_;
347
349 Geometry geometry_;
350
352 bool affine_;
353};
354
355// deduction guides
356template <class Map, class Geo>
357MappedGeometry (const Map&, const Geo&)
358 -> MappedGeometry<Map,Geo>;
359
360template <class Map, class Geo>
361MappedGeometry (const Map&, const Geo&, bool)
362 -> MappedGeometry<Map,Geo>;
363
364} // end namespace Dune
365
366#endif // DUNE_GEOMETRY_MAPPEDGEOMETRY_HH
An implementation of the Geometry interface for affine geometries.
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
Geometry parametrized by a LocalFunction and a LocalGeometry.
Definition: mappedgeometry.hh:65
std::remove_reference_t< decltype(std::declval< Map >()(std::declval< typename Geo::GlobalCoordinate >()))> GlobalCoordinate
type of global coordinates
Definition: mappedgeometry.hh:71
GlobalCoordinate center() const
Map the center of the wrapped geometry.
Definition: mappedgeometry.hh:162
JacobianInverseTransposed jacobianInverseTransposed(const LocalCoordinate &local) const
Obtain the transposed of the Jacobian's inverse.
Definition: mappedgeometry.hh:310
JacobianInverse jacobianInverse(const LocalCoordinate &local) const
Obtain the Jacobian's inverse.
Definition: mappedgeometry.hh:296
JacobianTransposed jacobianTransposed(const LocalCoordinate &local) const
Obtain the transposed of the Jacobian.
Definition: mappedgeometry.hh:284
MappedGeometry(Map_ &&mapping, Geo_ &&geometry, bool affine=false)
Constructor from mapping to parametrize the geometry.
Definition: mappedgeometry.hh:125
static constexpr int mydimension
geometry dimension
Definition: mappedgeometry.hh:77
GeometryType type() const
Obtain the geometry type from the reference element.
Definition: mappedgeometry.hh:143
typename Geo::LocalCoordinate LocalCoordinate
type of local coordinates
Definition: mappedgeometry.hh:68
typename Geo::ctype ctype
coordinate type
Definition: mappedgeometry.hh:74
GlobalCoordinate corner(int i) const
Obtain coordinates of the i-th corner.
Definition: mappedgeometry.hh:155
static constexpr int coorddimension
coordinate dimension
Definition: mappedgeometry.hh:80
GlobalCoordinate global(const LocalCoordinate &local) const
Evaluate the coordinate mapping.
Definition: mappedgeometry.hh:176
Volume volume(const QuadratureRule< ctype, mydimension > &quadRule) const
Obtain the volume of the mapping's image by given quadrature rules.
Definition: mappedgeometry.hh:259
int corners() const
Obtain number of corners of the corresponding reference element.
Definition: mappedgeometry.hh:149
friend ReferenceElement referenceElement(const MappedGeometry &geometry)
Obtain the reference-element related to this geometry.
Definition: mappedgeometry.hh:316
Volume volume(Impl::ConvergenceOptions< ctype > opts={}) const
Obtain the volume of the mapping's image.
Definition: mappedgeometry.hh:241
std::remove_reference_t< decltype(Dune::power(std::declval< ctype >(), mydimension))> Volume
type of volume
Definition: mappedgeometry.hh:83
bool affine() const
Is this mapping affine? Not in general, since we don't know anything about the mapping....
Definition: mappedgeometry.hh:137
Jacobian jacobian(const LocalCoordinate &local) const
Obtain the Jacobian.
Definition: mappedgeometry.hh:272
ctype integrationElement(const LocalCoordinate &local) const
Obtain the integration element.
Definition: mappedgeometry.hh:225
Abstract base class for quadrature rules.
Definition: quadraturerules.hh:214
A container for all quadrature rules of dimension dim
Definition: quadraturerules.hh:260
A few common exception classes.
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Some useful basic math stuff.
Dune namespace.
Definition: alignedallocator.hh:13
auto transpose(const Matrix &matrix)
Return the transposed of the given matrix.
Definition: transpose.hh:183
STL namespace.
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:128
typename Container::ReferenceElement ReferenceElement
The reference element type.
Definition: referenceelements.hh:146
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)