KASKADE 7 development version
boundaryLocator.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2017-2020 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef BOUNDARYLOCATOR_HH
14#define BOUNDARYLOCATOR_HH
15
16#include <memory>
17#include <optional>
18#include <tuple>
19
20#include "dune/common/fvector.hh"
21#include "dune/geometry/type.hh"
22
23#include "fem/boundaryFace.hh"
24#include "utilities/timing.hh"
25
26namespace Kaskade
27{
29 // forward declaration for PIMPL idiome
30 namespace BoundaryLocatorDetail
31 {
32 template <class GridView, class Function, int dimw>
34
35 // Dummy implementation for FE function, just to be syntactically correct
36 // TODO: replace this by void type and use constexpr if.
38 {
39 template <class Cell>
40 int order(Cell const&) const { return 0; }
41
42 template <class Cell, class B>
43 B value(Cell, B b) const { return B(0.0); }
44
45 template <class Cell, class B>
47 };
48
49 }
51
52 // ----------------------------------------------------------------------------------------------
53
54
55
74 template <class GridView, class Function=BoundaryLocatorDetail::ZeroDisplacement, int dimw=GridView::Grid::dimension>
76 {
78 using Grid = typename GridView::Grid;
79
80 public:
81 static int const dimension = GridView::Grid::dimension;
82 static int const dimension_world = dimw;
83 using ctype = typename GridView::ctype;
86 using Face = std::conditional_t<dimension==dimension_world,
87 typename GridView::Intersection,
88 typename GridView::template Codim<0>::Entity>;
90
91
95 BoundaryLocator(GridView const& gridView);
96
103 BoundaryLocator(GridView const& gridView, std::vector<bool> const& boundarySegments);
104
110 template <class... Args>
111 BoundaryLocator(GridView const& gridView, Args&&... args)
112 : BoundaryLocator(gridView)
113 {
114 f = std::make_unique<Function>(std::forward<Args>(args)...);
115 }
116
117 // we need this because the default destructor doesn't know about the size of SpatialIndex when deallocating via unique_ptr
119
129 template <class Update>
130 void updateDisplacement(Update const& update)
131 {
132 // Extract the faces from the spatial index. This is much faster than running through the whole
133 // grid (O(n^(1-1/d)) vs O(n)). Moreover, faces on periodic boundaries and on not considered
134 // boundary segments are already filtered out.
135 auto& timer = Timings::instance();
136 timer.start("boundary faces from rtree");
137 auto fs = faces();
138 timer.stop("boundary faces from rtree");
139
140 if (f)
141 *f = update; // register new displacement
142 else
143 f = std::make_unique<Function>(update);
144
145 enterFaces(fs); // recreate the spatial tree with newly displaced faces
146 }
147
148
164 std::optional<std::tuple<typename BoundaryLocator<GridView,Function,dimw>::DisplacedFace,
166 typename GridView::ctype>>
167 byLineSegment(Position const& from, Position const& to, ctype minAngle=-0.5) const;
168
184 std::optional<std::tuple<typename BoundaryLocator<GridView,Function,dimw>::DisplacedFace,
186 typename GridView::ctype>>
187 byRay(Position const& from, Position const& direction, ctype minAngle=-0.5) const
188 {
189 return byLineSegment(from,from+(diam/direction.two_norm())*direction, minAngle);
190 }
191
200 {
201 return diam;
202 }
203
209 Position global(Face const& face, LocalPosition const& xi) const;
210
214 Position unitOuterNormal(Face const& face, LocalPosition const& xi) const;
215
221 Function const* displacement() const
222 {
223 return f.get();
224 }
225
232 std::vector<Face> faces() const;
233
240 std::vector<DisplacedFace> displacedFaces() const;
241
242 private:
243 std::unique_ptr<BoundaryLocatorDetail::SpatialIndex<GridView,Function,dimension_world>> spatialIndex;
244 std::unique_ptr<Function> f;
245 ctype diam;
246
247 using IntersectionSet = std::vector<std::tuple<BoundaryFace<Grid,Face,Function>,
249
250 void init(GridView const& gridView, std::vector<bool> const& boundarySegments);
251
257 IntersectionSet getIntersectingFaces(Position const& from, Position const& to, ctype minAngle) const;
258
264 void enterFaces(std::vector<Face> const& fs);
265 };
266}
267
268#endif
Function is the interface for evaluatable functions .
Definition: concepts.hh:324
A class for representing displaced/deformed boundary faces.
Definition: boundaryFace.hh:45
BoundaryLocator(GridView const &gridView)
Constructs a locator, optionally providing a displacement.
Dune::FieldVector< ctype, dimension_world-1 > LocalPosition
Function const * displacement() const
Returns the current displacement of the mesh.
typename GridView::ctype ctype
std::vector< DisplacedFace > displacedFaces() const
Returns a sequence of all deformed faces.
std::optional< std::tuple< typename BoundaryLocator< GridView, Function, dimw >::DisplacedFace, typename BoundaryLocator< GridView, Function, dimw >::LocalPosition, typename GridView::ctype > > byRay(Position const &from, Position const &direction, ctype minAngle=-0.5) const
Finds the first boundary face that is intersected by the given ray from outside towards inside.
std::conditional_t< dimension==dimension_world, typename GridView::Intersection, typename GridView::template Codim< 0 >::Entity > Face
Position unitOuterNormal(Face const &face, LocalPosition const &xi) const
DEPRECATED use BoundaryFace::unitOuterNormal() instead.
ctype diameter() const
The diagonal length of the grid's cartesian bounding box.
std::optional< std::tuple< typename BoundaryLocator< GridView, Function, dimw >::DisplacedFace, typename BoundaryLocator< GridView, Function, dimw >::LocalPosition, typename GridView::ctype > > byLineSegment(Position const &from, Position const &to, ctype minAngle=-0.5) const
Finds the first boundary face that is intersected by the given line segment from outside towards insi...
Position global(Face const &face, LocalPosition const &xi) const
Returns the global position of a boundary point.
BoundaryLocator(GridView const &gridView, Args &&... args)
Constructs a locator, constructing the displacement function with the given argument.
static int const dimension_world
void updateDisplacement(Update const &update)
Creates or updates the displacement function.
static int const dimension
std::vector< Face > faces() const
Returns a sequence of all faces.
BoundaryLocator(GridView const &gridView, std::vector< bool > const &boundarySegments)
Constructor.
static Timings & instance()
Returns a reference to a single default instance.
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
Definition: gridBasics.hh:35
Dune::FieldMatrix< typename B::field_type, B::dimension, B::dimension > derivative(Cell, B) const