Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
refinedsimplexgeometry.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNE_FUFEM_GEOMETRY_REFINEDSIMPLEXGEOMETRY_HH
5#define DUNE_FUFEM_GEOMETRY_REFINEDSIMPLEXGEOMETRY_HH
6
10
11#include <dune/geometry/type.hh>
13
14template <class ct, int localdim, int worlddim>
16 public:
17 typedef ct ctype;
19
20 template <class VertexContainerType>
21 RefinedSimplexGeometry(const VertexContainerType& vertices):
22 vertices_(vertices)
23 {
24 DUNE_THROW(Dune::NotImplemented, "RefinedSimplexGeometry is implemented only for dim=2.");
25 }
26
27 private:
28 const std::array<GlobalCoordinate,2*(worlddim+1)> vertices_;
29};
30
41template <class ct>
43 public:
44
45 typedef ct ctype;
48
50 class JacobianInverseTransposed;
51
70 template <class VertexContainerType>
71 RefinedSimplexGeometry(const VertexContainerType& vertices):
72 vertices_(vertices)
73 {
74 indexMap_[0][0] = 0;
75 indexMap_[0][1] = 3;
76 indexMap_[0][2] = 4;
77
78 indexMap_[1][0] = 3;
79 indexMap_[1][1] = 1;
80 indexMap_[1][2] = 5;
81
82 indexMap_[2][0] = 4;
83 indexMap_[2][1] = 5;
84 indexMap_[2][2] = 2;
85
86 indexMap_[3][0] = 5;
87 indexMap_[3][1] = 4;
88 indexMap_[3][2] = 3;
89
90 for (std::size_t i = 0; i<4; ++i)
91 {
92 translation_[i] = vertices_[indexMap_[i][0]];
93 jacobianTransposed_[i][0] = linearMapSubElementLocalToWorldTransposed_[i][0] = vertices_[indexMap_[i][1]] - translation_[i];
94 jacobianTransposed_[i][1] = linearMapSubElementLocalToWorldTransposed_[i][1] = vertices_[indexMap_[i][2]] - translation_[i];
95
96 jacobianTransposed_[i] *= std::pow(-1,int(i==3))*2;
97
98 jacobianInverseTransposed_[i].setup(jacobianTransposed_[i]);
99
100 integrationElement_[i] = jacobianInverseTransposed_[i].detInv();
101 }
102 }
103
105 {
106 LocalCoordinate subElementLocal;
107 int subElement=-1;
108
109 getSubElement(local,subElement,subElementLocal);
110
111 //std::cout << "local: " << local << ", subElement= " << subElement << ", subElementlocal: " << subElementLocal << std::endl;
112
113 GlobalCoordinate returnValue = translation_[subElement];
114 //std::cout << "translation: " << returnValue << ", jacobianTransposed: " << jacobianTransposed_[subElement] << std::endl;
115 linearMapSubElementLocalToWorldTransposed_[subElement].umtv(subElementLocal,returnValue);
116
117 //std::cout << "global= " << returnValue << std::endl;
118
119 return returnValue;
120 }
121
122 bool affine() const
123 {
124 return false;
125 }
126
128 {
129 DUNE_THROW(Dune::NotImplemented,"Method type() not implemented for RefinedSimplexGeometry");
130 }
131
132 int corners() const
133 {
134 return 6;
135 }
136
138 {
139 return vertices_[i];
140 }
141
143 {
144 DUNE_THROW(Dune::NotImplemented,"Method local() not implemented for RefinedSimplexGeometry<ctype,2,3>");
145 }
146
148 {
149 DUNE_THROW(Dune::NotImplemented,"Method center() not implemented for RefinedSimplexGeometry<ctype,2,3>");
150 }
151
152 ctype volume() const
153 {
154 DUNE_THROW(Dune::NotImplemented,"Method volume() not implemented for RefinedSimplexGeometry<ctype,2,3>");
155 }
156
158 {
159 return integrationElement_[getSubElement(local)];
160 }
161
163 {
164 return jacobianTransposed_[getSubElement(local)];
165 }
166
167 JacobianInverseTransposed jacobianInverseTransposed(const LocalCoordinate& local) const
168 {
169 return jacobianInverseTransposed_[getSubElement(local)];
170 }
171
172 class JacobianInverseTransposed
173 : public Dune::FieldMatrix< ctype, 3, 2 >
174 {
175 public:
177
178 void setup ( const JacobianTransposed &jt )
179 {
180 detInv_ = Dune::Impl::FieldMatrixHelper< ctype >::template rightInvA< 2, 3 >( jt, static_cast< Base & >( *this ) );
181 }
182
184 {
185 detInv_ = Dune::Impl::FieldMatrixHelper< ctype >::template sqrtDetAAT< 2, 3 >( jt );
186 }
187
188 ctype det () const { return ctype( 1 ) / detInv_; }
189 ctype detInv () const { return detInv_; }
190
191 private:
192 ctype detInv_;
193 };
194
195 private:
196 const std::array<GlobalCoordinate,6> vertices_;
197 std::array<JacobianTransposed,4> linearMapSubElementLocalToWorldTransposed_;
198 std::array<JacobianTransposed,4> jacobianTransposed_;
199 std::array<JacobianInverseTransposed,4> jacobianInverseTransposed_;
201 std::array<ctype,4> integrationElement_;
202
218 static int getSubElement(const LocalCoordinate& local)
219 {
220 if (local[0] + local[1] <= 0.5)
221 return 0;
222 else if (local[0] >= 0.5)
223 return 1;
224 else if (local[1] >= 0.5)
225 return 2;
226
227 return 3;
228 }
229
236 static void getSubElement(const LocalCoordinate& local,
237 int& subElement,
238 LocalCoordinate& subElementLocal)
239 {
240 if (local[0] + local[1] <= 0.5) {
241 subElement = 0;
242 subElementLocal[0] = 2*local[0];
243 subElementLocal[1] = 2*local[1];
244 return;
245 } else if (local[0] >= 0.5) {
246 subElement = 1;
247 subElementLocal[0] = 2*local[0]-1;
248 subElementLocal[1] = 2*local[1];
249 return;
250 } else if (local[1] >= 0.5) {
251 subElement = 2;
252 subElementLocal[0] = 2*local[0];
253 subElementLocal[1] = 2*local[1]-1;
254 return;
255 }
256
257 subElement = 3;
258 subElementLocal[0] = -2 * local[0] + 1;
259 subElementLocal[1] = -2 * local[1] + 1;
260
261 }
262};
263
272template <class Element, class Transformation>
273RefinedSimplexGeometry<typename Element::Geometry::ctype,2,3> makeRefinedSimplexGeometry(const Element& element, const Transformation& transformation)
274{
275 if(not element.type().isTriangle())
276 DUNE_THROW(Dune::NotImplemented, "Free method makeRefinedSimplexGeometry(.,.) is only implemented for 2D simplex elements");
277
279
280 typename Element::Geometry eltGeometry = element.geometry();
281
282 for (std::size_t i=0; i<(std::size_t)eltGeometry.corners(); ++i)
283 movedVirtualVertices[i] = eltGeometry.corner(i);
284
285 for (std::size_t i=0; i<(std::size_t)element.subEntities(Element::dimension - 1); ++i)
286 {
287 auto y = transformation(element.template subEntity<Element::dimension -1>(i).geometry().center());
288 movedVirtualVertices[eltGeometry.corners() + i] = y;
289 }
290
292}
293
294#endif
RefinedSimplexGeometry< typename Element::Geometry::ctype, 2, 3 > makeRefinedSimplexGeometry(const Element &element, const Transformation &transformation)
Create RefinedSimplexGeometry with transformed geometry.
Definition refinedsimplexgeometry.hh:273
#define DUNE_THROW(E,...)
LocalIndex & local()
Definition refinedsimplexgeometry.hh:15
ct ctype
Definition refinedsimplexgeometry.hh:17
Dune::FieldVector< ctype, worlddim > GlobalCoordinate
Definition refinedsimplexgeometry.hh:18
RefinedSimplexGeometry(const VertexContainerType &vertices)
Definition refinedsimplexgeometry.hh:21
Dune::GeometryType type() const
Definition refinedsimplexgeometry.hh:127
GlobalCoordinate global(const LocalCoordinate &local) const
Definition refinedsimplexgeometry.hh:104
bool affine() const
Definition refinedsimplexgeometry.hh:122
JacobianTransposed jacobianTransposed(const LocalCoordinate &local) const
Definition refinedsimplexgeometry.hh:162
GlobalCoordinate corner(int i) const
Definition refinedsimplexgeometry.hh:137
Dune::FieldMatrix< ctype, 2, 3 > JacobianTransposed
Definition refinedsimplexgeometry.hh:49
LocalCoordinate local(const GlobalCoordinate &) const
Definition refinedsimplexgeometry.hh:142
Dune::FieldVector< ctype, 2 > LocalCoordinate
Definition refinedsimplexgeometry.hh:46
ctype volume() const
Definition refinedsimplexgeometry.hh:152
ctype integrationElement(const LocalCoordinate &local) const
Definition refinedsimplexgeometry.hh:157
int corners() const
Definition refinedsimplexgeometry.hh:132
GlobalCoordinate center() const
Definition refinedsimplexgeometry.hh:147
Dune::FieldVector< ctype, 3 > GlobalCoordinate
Definition refinedsimplexgeometry.hh:47
JacobianInverseTransposed jacobianInverseTransposed(const LocalCoordinate &local) const
Definition refinedsimplexgeometry.hh:167
ct ctype
Definition refinedsimplexgeometry.hh:45
RefinedSimplexGeometry(const VertexContainerType &vertices)
constructor taking the global coordinates of the "refined" vertices
Definition refinedsimplexgeometry.hh:71
void setup(const JacobianTransposed &jt)
Definition refinedsimplexgeometry.hh:178
void setupDeterminant(const JacobianTransposed &jt)
Definition refinedsimplexgeometry.hh:183
Dune::FieldMatrix< ctype, 3, 2 > Base
Definition refinedsimplexgeometry.hh:176
ctype detInv() const
Definition refinedsimplexgeometry.hh:189
ctype det() const
Definition refinedsimplexgeometry.hh:188
T pow(T... args)