KASKADE 7 development version
hermite2D.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* see http://www.zib.de/Numerik/numsoft/kaskade7/ */
5/* */
6/* Copyright (C) 2002-2013 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
18#ifndef HERMITE_INTERPOLATION_2D
19#define HERMITE_INTERPOLATION_2D
20
23
27namespace Kaskade
28{
30 template<class Scalar_, class GridView, class InterpolationPolicy>
31 class HIPImpl<Scalar_, GridView, InterpolationPolicy, 2> : public HIPBase<Scalar_,2>
32 {
33 public:
34 typedef HIPBase<Scalar_,2> Base;
35 static int const dim = 2;
36 typedef typename Base::Scalar Scalar;
37 typedef typename Base::Vector Vector;
38 typedef typename GridView::template Codim<dim>::Iterator VertexIterator;
39 typedef typename GridView::template Codim<0>::Iterator::Entity Entity;
40 typedef InterpolationTools::NormalContainer<Scalar,dim> Container;
41 typedef typename Container::CollectionType NormalCollection;
42 typedef typename GridView::IntersectionIterator LocalFaceIterator;
43 typedef typename LocalFaceIterator::Intersection Face;
44
46
51 HIPImpl(int numberOfShapeFunctions) : Base(numberOfShapeFunctions){}
52
54 /*
55 * \param entity entity on which the polynomial is defined
56 * \param gridView grid view
57 * \param container container holding vertex normals in container.vertexNormals
58 * \param shapefunctionset shape function set of the reference codim 0 element
59 * \param policy policy object specifiying interpolation details
60 */
61 template <class ShapeFunctionSet>
62 HIPImpl(Entity const& entity, GridView const& gridView,
63 ShapeFunctionSet const& shapeFunctionSet, Container const& container,
64 InterpolationPolicy const& policy) :
65 Base(shapeFunctionSet.size())
66 {
67 init(entity, gridView, shapeFunctionSet, container, policy);
68 }
69
71
78 template <class ShapeFunctionSet>
79 void init(Entity const& entity, GridView const& gridView, ShapeFunctionSet const& shapeFunctionSet, Container const& container, InterpolationPolicy const& policy)
80 {
81 // get global vertex ids of entity
82 std::vector<int> vid = InterpolationTools::getGlobalVertexIds(entity,gridView);
83 // get directions of tangents associated with the entities vertices
84 std::vector<Vector> tangents(dim+1, Vector(0));
85 getVertexTangents(vid, container.vertexNormals, tangents);
86
87 // get material id
88 Scalar tissue = round(policy.phaseId(entity));
89 // affine coordinate mapping -> jacobian is constant on each entity
90 Dune::FieldMatrix<Scalar,dim,dim> jacobian = entity.geometry().jacobianInverseTransposed(Vector(0));
91
92 // iterate over edges
93 LocalFaceIterator fend = gridView.iend(entity);
94 for(LocalFaceIterator face = gridView.ibegin(entity); face!=fend; ++face){
95 // use policy to exclude interpolation on specific faces
96 if( face->boundary() ) if( policy.ignoreOuterBoundary(*face) ) continue;
97
98 Scalar tissueNeighbour = -1;
99 if( face->neighbor() ) tissueNeighbour = policy.phaseId(*face->outside());
100
101 // if no inner boundary exists (no intersection with cells associated with other materials) continue
102 if(fabs(tissue-tissueNeighbour) < 1e-9) continue;
103
104 // id of face in entity
105 int edgeId = face->indexInInside();
106 // get faces vertex ids wrt to entity
107 std::vector<int> localEdgeVertexIds = InterpolationTools::getEdgeCornerIdsInEntity(entity, edgeId),
108 globalEdgeVertexIds = InterpolationTools::getGlobalEdgeCornerIds(entity, edgeId, gridView),
109 shapeFunctionIds = getFacesShapeFunctionIds(edgeId);
110
111 VertexIterator iter = gridView.template begin<dim>(), iter2 = gridView.template begin<dim>();
112
113 for(int i=0; i<globalEdgeVertexIds[0]; ++i) ++iter;
114 for(int i=0; i<globalEdgeVertexIds[1]; ++i) ++iter2;
115 // get outer normal of face
116 Vector faceNormal = face->centerUnitOuterNormal();
117
118 // get face direction
119 Vector edgeDirection = face->geometry().corner(1) - face->geometry().corner(0);
120 GeomTools::normalize(edgeDirection);
121 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
122 /* fill right hand side */
123 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
124 // first determine the desired gradients and apply threshold
125 Vector desiredGradients;
126 for(int vertexIdInEdge = 0; vertexIdInEdge<dim; ++vertexIdInEdge){
127 if(container.vertexNormals[ globalEdgeVertexIds[vertexIdInEdge] ].isRelevant)
128 {
129 desiredGradients[vertexIdInEdge] = (tangents[localEdgeVertexIds[vertexIdInEdge]] * faceNormal) / (tangents[localEdgeVertexIds[vertexIdInEdge]] * edgeDirection);
130 policy.applyGradientThreshold(desiredGradients[vertexIdInEdge]);
131 }
132 else
133 desiredGradients[vertexIdInEdge] = 0;
134 }
135
136 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
137 /* fill Matrix */
138 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
139 // interpolate coefficients for the lagrange shape functions associated with the face
141
142 for(int vertexIdInFace=0; vertexIdInFace<dim; ++vertexIdInFace){
143 // std::cout << "corners: " << face->geometry().corner(vertexIdInFace) << std::endl;
144 for(int sfId=0; sfId<dim; ++sfId){
145 // get gradients on reference tetrahedron
146 Vector grad = ( (dim==2 && vertexIdInFace==0) ? shapeFunctionSet[ shapeFunctionIds[sfId] ].evaluateDerivative( entity.geometry().local(iter->geometry().corner(0)) )[0]
147 : shapeFunctionSet[ shapeFunctionIds[sfId] ].evaluateDerivative( entity.geometry().local(iter2->geometry().corner(0)) )[0] );
148 Vector chainRule(0);
149 // apply chain rule -> gradient on the actual tetrahedron
150 jacobian.mv(grad, chainRule);
151 // evaluate directional derivative in deformed surface
152 A[vertexIdInFace][sfId] = chainRule * edgeDirection;
153 }
154 }
155
156 Vector coefficients(0);
157 A.solve(coefficients, desiredGradients);
158
159 for(int sfId=0; sfId<dim; ++sfId){
160 Scalar orientation = 1;
161 if(tissueNeighbour+1e-9 < tissue && tissueNeighbour > -1e-9) orientation = -1;
162 this->insertEntry(orientation*coefficients[sfId], orientation*faceNormal, shapeFunctionIds[sfId]);
163 }
164 }
165 }
166
167 private:
169
177 void getVertexTangents(std::vector<int> const &vid, NormalCollection const& vertexNormals, std::vector<Vector> &tangents) const {
178 std::vector<Vector> normals(3,Vector());
179 normals[0] = vertexNormals[vid[0]].normals[0];
180 normals[1] = vertexNormals[vid[1]].normals[0];
181 normals[2] = vertexNormals[vid[2]].normals[0];
182 tangents[0][0] = normals[0][1];
183 tangents[0][1] = -normals[0][0];
184 tangents[1][0] = normals[1][1];
185 tangents[1][1] = -normals[1][0];
186 tangents[2][0] = normals[2][1];
187 tangents[2][1] = -normals[2][0];
188 }
189
191
195 std::vector<int> getFacesShapeFunctionIds(int edgeId){
196 std::vector<int> shapeFunctionIds(dim,-1);
197 switch(edgeId){
198 case 0:
199 shapeFunctionIds[0] = 4;
200 shapeFunctionIds[1] = 7;
201 break;
202 case 1:
203 shapeFunctionIds[0] = 2;
204 shapeFunctionIds[1] = 1;
205 break;
206 case 2:
207 shapeFunctionIds[0] = 8;
208 shapeFunctionIds[1] = 6;
209 default: break;
210 }
211 return shapeFunctionIds;
212 }
213 };
214} /* end namespace Kaskade */
218#endif
Some simple tools for geometric calculations. Please extend.
typename GridView::Intersection Face
The type of faces in the grid view.
Definition: gridBasics.hh:42
Vector normalize(Vector &vector)
Normalize vector.
Definition: geomtools.hh:48
std::vector< int > getEdgeCornerIdsInEntity(Entity const &entity, int edgeId)
Get local coordinates of the edges vertices in the codim<0> entity.
Definition: tools.hh:697
std::vector< int > getGlobalVertexIds(Entity const &entity, GridView const &gridView)
Get global vertex ids of the entities corners.
Definition: tools.hh:682
std::vector< int > getGlobalEdgeCornerIds(Entity const &entity, int edgeId, GridView const &gridView)
Get global indices of the edges vertices.
Definition: tools.hh:715
Dune::FieldVector< Scalar, dim > Vector