KASKADE 7 development version
Loading...
Searching...
No Matches
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-2025 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/fmatrix.hh"
21#include "dune/common/fvector.hh"
22#include "dune/geometry/type.hh"
23
24#include "fem/boundaryFace.hh"
25#include "utilities/timing.hh"
26
27namespace Kaskade
28{
30 // forward declaration for PIMPL idiome
32 {
33 template <class GridView, class Function, int dimw>
35
36 // Dummy implementation for FE function, just to be syntactically correct
37 // TODO: replace this by void type and use constexpr if.
39 {
40 template <class Cell>
41 int order(Cell const&) const { return 0; }
42
43 template <class Cell, class B>
44 B value(Cell, B b) const { return B(0.0); }
45
46 template <class Cell, class B>
48 };
49
50 }
51
52
53 // ----------------------------------------------------------------------------------------------
54
55
56
76 template <class GridView,
77 class Function=BoundaryLocatorDetail::ZeroDisplacement,
78 int dimw=GridView::Grid::dimension>
80 {
82 using Grid = typename GridView::Grid;
83
84 public:
85 static int const dimension = GridView::Grid::dimension;
86 static int const dimension_world = dimw;
87 using ctype = typename GridView::ctype;
90 using Face = std::conditional_t<dimension==dimension_world,
91 typename GridView::Intersection,
92 typename GridView::template Codim<0>::Entity>;
93
99
100
104 BoundaryLocator(GridView const& gridView);
105
112 BoundaryLocator(GridView const& gridView, std::vector<bool> const& boundarySegments);
113
120 template <class... Args>
121 BoundaryLocator(GridView const& gridView, Args&&... args)
122 : BoundaryLocator(gridView)
123 {
124 f = std::make_unique<Function>(std::forward<Args>(args)...);
125 }
126
127 // we need this because the default destructor doesn't know about the size of SpatialIndex
128 // when deallocating via unique_ptr
130
141 template <class Update>
142 void updateDisplacement(Update const& update)
143 {
144 // Extract the faces from the spatial index. This is much faster than running through the whole
145 // grid (O(n^(1-1/d)) vs O(n)). Moreover, faces on periodic boundaries and on not considered
146 // boundary segments are already filtered out.
147 auto& timer = Timings::instance();
148 timer.start("boundary faces from rtree");
149 auto fs = faces();
150 timer.stop("boundary faces from rtree");
151
152 if (f)
153 *f = update; // register new displacement
154 else
155 f = std::make_unique<Function>(update);
156
157 enterFaces(fs); // recreate the spatial tree with newly displaced faces
158 }
159
160
178 std::optional<std::tuple<typename BoundaryLocator<GridView,Function,dimw>::DisplacedFace,
180 typename GridView::ctype>>
181 byLineSegment(Position const& from, Position const& to, ctype minAngle=-0.5) const;
182
199 std::optional<std::tuple<typename BoundaryLocator<GridView,Function,dimw>::DisplacedFace,
201 typename GridView::ctype>>
202 byRay(Position const& from, Position const& direction, ctype minAngle=-0.5) const
203 {
204 return byLineSegment(from,from+(diam/direction.two_norm())*direction, minAngle);
205 }
206
215 {
216 return diam;
217 }
218
224 Position global(Face const& face, LocalPosition const& xi) const;
225
229 Position unitOuterNormal(Face const& face, LocalPosition const& xi) const;
230
236 Function const* displacement() const
237 {
238 return f.get();
239 }
240
247 std::vector<Face> faces() const;
248
255 std::vector<DisplacedFace> displacedFaces() const;
256
257 private:
258 std::unique_ptr<BoundaryLocatorDetail::SpatialIndex<GridView,Function,dimension_world>> spatialIndex;
259 std::unique_ptr<Function> f;
260 ctype diam;
261
262 using IntersectionSet = std::vector<std::tuple<BoundaryFace<Grid,Face,Function>,
264
265 void init(GridView const& gridView, std::vector<bool> const& boundarySegments);
266
272 IntersectionSet getIntersectingFaces(Position const& from, Position const& to, ctype minAngle) const;
273
279 void enterFaces(std::vector<Face> const& fs);
280 };
281}
282
283#endif
Function is the interface for evaluatable functions .
Definition concepts.hh:324
A class for representing displaced/deformed boundary faces.
BoundaryFace< Grid, Face, Function, dimw > DisplacedFace
the type of boundary faces in the (optionally displaced) grid, used for returning found intersections...
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::conditional_t< dimension==dimension_world, typename GridView::Intersection, typename GridView::template Codim< 0 >::Entity > Face
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.
Dune::FieldVector< ctype, dimension_world > Position
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.
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