KASKADE 7 development version
deforminggridmanager.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-2017 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 DEFORMINGGRIDMANAGER_HH_
14#define DEFORMINGGRIDMANAGER_HH_
15
16#include "dune/common/fvector.hh"
17#include "dune/grid/geometrygrid/coordfunction.hh"
18#include "dune/grid/geometrygrid/grid.hh"
19#include "dune/grid/uggrid.hh"
20
21#include "fem/gridmanager.hh"
23#include "fem/spaces.hh"
24
25namespace Kaskade
26{
28 namespace DeformingGridManagerDetail
29 {
30 template <class Grid>
31 class Deformation: public Dune::DiscreteCoordFunction<typename Grid::ctype,
32 Grid::dimension,
33 Deformation<Grid>>
34 {
35 using ctype = typename Grid::ctype;
36 constexpr static int dim = Grid::dimension;
38 using LevelView = typename Grid::LevelGridView;
39 using Index = typename LevelView::IndexSet::IndexType;
40
41 public:
51 Deformation(Grid const& grid_, ctype featureEdgeAngle=0.5, ctype featureCurveAngle=1.0)
52 : grid(grid_), tangents_(grid,GridAngleFeatureDetector<LevelView>(featureCurveAngle,featureEdgeAngle))
53 {
54 adapt();
55 }
56
57 Deformation(Grid const& grid_, GeometricFeatureDetector<Index,ctype,dim> const& featureDetector)
58 : grid(grid_)
59 , tangents_(grid,featureDetector)
60 {
61 adapt();
62 }
63
64 void adapt()
65 {
66 vertexPositions_ = interpolateVertexPositions(grid.leafGridView(),tangents_);
67 }
68
69 void setFeatureAngles(ctype featureCurveAngle=1.0, ctype featureEdgeAngle=0.5)
70 {
71 GridAngleFeatureDetector<LevelView> features(featureCurveAngle,featureEdgeAngle);
72 tangents_ = GridBoundaryTangents<LevelView>(grid,features);
73 adapt();
74 }
75
76 void evaluate(typename Grid::template Codim<dim>::Entity const& vertex, unsigned int /* corner */,
77 Vector& y) const
78 {
79 y = vertexPositions_[grid.leafGridView().indexSet().index(vertex)];
80 }
81
82 void evaluate(typename Grid::template Codim<0>::Entity const& cell, unsigned int corner,
83 Vector& y) const
84 {
85 y = vertexPositions_[grid.leafGridView().indexSet().subIndex(cell,corner,dim)];
86 }
87
88 GridBoundaryTangents<typename Grid::LevelGridView> const& tangents() const
89 {
90 return tangents_;
91 }
92
93 std::vector<Vector> const& vertexPositions() const
94 {
95 return vertexPositions_;
96 }
97
98 private:
99 Grid const& grid;
100 GridBoundaryTangents<typename Grid::LevelGridView> tangents_;
101 std::vector<Vector> vertexPositions_;
102 };
103 }
105
106
107
116 template <class Grid>
118 : public GridManagerBase<Dune::GeometryGrid<Grid,DeformingGridManagerDetail::Deformation<Grid>>>
119 {
120 using Deformation = DeformingGridManagerDetail::Deformation<Grid>;
121 using DeformedGrid = Dune::GeometryGrid<Grid,Deformation>;
123 using ctype = typename Grid::ctype;
124 constexpr static int dim = Grid::dimension;
126 using LevelView = typename Grid::LevelGridView;
127 using Index = typename LevelView::IndexSet::IndexType;
128
129 public:
141 DeformingGridManager(std::unique_ptr<Grid>&& grid,
142 ctype featureCurveAngle=1.0, ctype featureEdgeAngle=0.5,
143 bool verbose=false, bool enforceConcurrentReads=false)
144 : Base(new DeformedGrid(std::shared_ptr<Grid>(grid.release())), // geometry grid takes ownership of grid, and
145 verbose,enforceConcurrentReads) // creates its own deformation function
146 {
147 this->gridptr->coordFunction().setFeatureAngles(featureCurveAngle,featureEdgeAngle);
148 }
149
150 DeformingGridManager(std::unique_ptr<Grid>&& grid,
151 GeometricFeatureDetector<Index,ctype,dim> const& featureDetector,
152 bool verbose=false, bool enforceConcurrentReads=false)
153 : Base(makeDeformedGrid(std::move(grid),featureDetector), // geometry grid takes ownership of grid and
154 verbose,enforceConcurrentReads) // deformation function
155 {
156 }
157
158 virtual void update()
159 {}
160
161 virtual void refineGrid(int refCount)
162 {
163 this->gridptr->globalRefine(refCount);
164 }
165
166 virtual bool adaptGrid()
167 {
168 return this->gridptr->adapt();
169 }
170
180 template <class Scalar>
182 {
183 if(&correction.space().gridManager() != this)
184 throw DetailedException("Correction has wrong underlying gridManager.",__FILE__,__LINE__);
185
186
187 if (correction.space().mapper().maxOrder()==1) // The boundary displacement function of order 1
188 { // just interpolates the vertex displacement (which is zero).
189 correction = static_cast<Scalar>(0.0);
190 return;
191 }
192
194 this->gridptr->coordFunction().tangents());
195 // Todo: This is quite inefficient, since expensive surface interpolation is performed for many points
196 // (those which lie on the cell boundary) several times
197 // Instead: Consider iterating over the shape function nodes in each cell and writing into the coefficient vector directly
198 // with computing surface interpolation only if coefficient was not already set previously
199 interpolateGloballyWeak(correction,u);
200
201 // here we have correction as displacement with respect to the undeformed grid
202 // but we want it with respect to the current deformed grid, therefore we do the following
203
204 H1Space<DeformedGrid, Scalar> firstOrderSpace(*this, this->gridptr->leafGridView(), 1);
205 FunctionSpaceElement<H1Space<DeformedGrid, Scalar>, dim> vertexAdjustment(firstOrderSpace);
206 vertexAdjustment = correction;
207
208 // vertexAdjustment is now exactly the displacement from the undefomed to the current deformed grid
209 // therefore we subtract it from the computed correction
210 correction -= vertexAdjustment;
211 }
212
213 private:
214 static DeformedGrid* makeDeformedGrid(std::unique_ptr<Grid>&& grid,
215 GeometricFeatureDetector<Index,ctype,dim> const& featureDetector)
216 {
217 std::shared_ptr<Deformation> deformation (new Deformation(*grid,featureDetector));
218 std::shared_ptr<Grid> g (grid.release());
219 return new DeformedGrid(g,deformation);
220 }
221 };
222}
223
224#endif /* DEFORMINGGRIDMANAGER_HH_ */
The BoundaryInterpolationDisplacement class provides a Kaskade WeakFunctionView on the displacement f...
A grid manager for asymptotically -continuous domains.
virtual void refineGrid(int refCount)
void correctingDisplacement(FunctionSpaceElement< H1Space< DeformedGrid, Scalar >, dim > &correction)
correctingDisplacement provides a displacement function which displaces the points on the boundary of...
virtual void update()
Must be overloaded by derived classes to adjust internal state immediately after mesh refinement.
DeformingGridManager(std::unique_ptr< Grid > &&grid, ctype featureCurveAngle=1.0, ctype featureEdgeAngle=0.5, bool verbose=false, bool enforceConcurrentReads=false)
Constructor.
DeformingGridManager(std::unique_ptr< Grid > &&grid, GeometricFeatureDetector< Index, ctype, dim > const &featureDetector, bool verbose=false, bool enforceConcurrentReads=false)
A wrapper class for conveniently providing exceptions with context information.
A representation of a finite element function space defined over a domain covered by a grid.
A class for representing finite element functions.
The interface for specifying feature edges and feature vertices.
Basic functionality for managing grids and their refinement.
Definition: gridmanager.hh:261
Dune::GeometryGrid< Grid, DeformingGridManagerDetail::Deformation< Grid > > Grid
the type of managed grid
Definition: gridmanager.hh:266
Self & enforceConcurrentReads(bool enforceConcurrentReads)
Tells the grid manager that concurrent reads of the grid are safe.
Definition: gridmanager.hh:484
void interpolateGloballyWeak(Target &target, Source const &fu)
Interpolates WeakFunctionViews to FunctionSpaceElement.
Definition: fetransfer.hh:946
std::vector< Dune::FieldVector< typename GridView::ctype, GridView::dimension > > interpolateVertexPositions(GridView const &gv, GridBoundaryTangents< GridView > const &tangents, bool computeDisplacements=false)
Computes a new position for each grid vertex based on boundary interpolation.
Dune::FieldVector< Scalar, dim > Vector
AngleFeatureDetector< typename GridView::IndexSet::IndexType, typename GridView::ctype, GridView::dimension > GridAngleFeatureDetector
Convenience typedefs and creation functions for common function spaces.