KASKADE 7 development version
Loading...
Searching...
No Matches
cube.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) 2013-2026 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#ifndef KASKADE_CUBE_HH
13#define KASKADE_CUBE_HH
14
15#include <algorithm>
16#include <cmath>
17#include <utility>
18#include <vector>
19
20#include <dune/common/fvector.hh>
21
22namespace Kaskade
23{
24 template <class Real, int dim_>
26 {
27 public:
28 static constexpr int dim = dim_;
29
31
32 BasicGridElement(BasicGridElement const& other) = default;
33
35 {
36 *this = std::move(other);
37 }
38
40
42 {
43 vertices = std::move(other.vertices);
44 simplices = std::move(other.simplices);
45 return *this;
46 }
47
48 std::vector<Dune::FieldVector<Real,dim> > const& getVertices() const { return vertices; }
49 std::vector<std::vector<unsigned int> > const& getSimplices() const { return simplices; }
50
51 protected:
52 std::vector<Dune::FieldVector<Real,dim>> vertices;
53 std::vector<std::vector<unsigned int>> simplices;
54 };
55
56 // -----------------------------------------------------------------------------------------------
57 // -----------------------------------------------------------------------------------------------
58
59 template <class Real_=double>
60 class Square: public BasicGridElement<Real_,2>
61 {
62 public:
63 typedef Real_ Real;
64
65 explicit Square(bool symmetric=false)
66 : Square(Dune::FieldVector<Real,2>(0.0), Dune::FieldVector<Real,2>(1.0),symmetric)
67 {}
68
69 Square(Dune::FieldVector<Real,2> const& x0, Dune::FieldVector<Real,2> const& dx, bool symmetric=false)
70 {
71 if(!symmetric)
72 {
73 initVertices(x0[0],x0[1],dx[0],dx[1]);
74 initTriangles();
75 }
76 else
77 {
78 initSymmetricVertices(x0[0],x0[1],dx[0],dx[1]);
79 initSymmetricTriangles();
80 }
81 }
82
83 private:
86
87 void initVertices(Real x, Real y, Real dx, Real dy)
88 {
90 v[0] = x; v[1] = y; vertices.push_back(v);
91 v[0] = x+dx; v[1] = y; vertices.push_back(v);
92 v[0] = x; v[1] = y+dy; vertices.push_back(v);
93 v[0] = x+dx; v[1] = y+dy; vertices.push_back(v);
94 }
95
96 void initSymmetricVertices(Real x, Real y, Real dx, Real dy)
97 {
99 v[0] = x; v[1] = y; vertices.push_back(v);
100 v[0] = x+dx; v[1] = y; vertices.push_back(v);
101 v[0] = x+dx; v[1] = y+dy; vertices.push_back(v);
102 v[0] = x; v[1] = y+dy; vertices.push_back(v);
103 v[0] = x+0.5*dx; v[1] = y+0.5*dy; vertices.push_back(v);
104 }
105
106 void initTriangles()
107 {
108 std::vector<unsigned int> p(3,0);
109
110 p[0] = 0; p[1] = 1; p[2] = 3; simplices.push_back(p);
111 p[0] = 0; p[1] = 3; p[2] = 2; simplices.push_back(p);
112 }
113
114 void initSymmetricTriangles()
115 {
116 std::vector<unsigned int> p(3,0);
117
118 p[0] = 0; p[1] = 1; p[2] = 4; simplices.push_back(p);
119 p[0] = 1; p[1] = 2; p[2] = 4; simplices.push_back(p);
120 p[0] = 2; p[1] = 3; p[2] = 4; simplices.push_back(p);
121 p[0] = 3; p[1] = 0; p[2] = 4; simplices.push_back(p);
122 }
123 };
124
125 // -----------------------------------------------------------------------------------------------
126 // -----------------------------------------------------------------------------------------------
127
144 template <class Real_=double>
145 class Cube: public BasicGridElement<Real_,3>
146 {
147 public:
148 typedef Real_ Real;
149
153 explicit Cube(bool symmetric=false)
154 : Cube(Dune::FieldVector<Real,3>(0.0), Dune::FieldVector<Real,3>(1.0), symmetric)
155 {}
156
160 Cube(Dune::FieldVector<Real,3> const& x0, Dune::FieldVector<Real,3> const& dx, bool symmetric)
161 {
162 if (symmetric)
163 {
164 initSymmetricVertices(x0[0],x0[1],x0[2],dx[0],dx[1],dx[2]);
165 initSymmetricTetrahedra();
166 }
167 else
168 {
169 initVertices(x0[0],x0[1],x0[2],dx[0],dx[1],dx[2]);
170 initTetrahedra();
171 }
172 }
173
174 private:
177
178 void initVertices(Real x, Real y, Real z, Real dx, Real dy, Real dz)
179 {
180 vertices.reserve(9); // allocate space for 9 vertices
181
183 //points in the frontside
184 v[0]=x; v[1]=y; v[2]=z; vertices.push_back(v);
185 v[0]=x+dx; v[1]=y; v[2]=z; vertices.push_back(v);
186 v[0]=x+dx; v[1]=y; v[2]=z+dz; vertices.push_back(v);
187 v[0]=x; v[1]=y; v[2]=z+dz; vertices.push_back(v);
188
189 //points in the backside
190 v[0]=x; v[1]=y+dy; v[2]=z; vertices.push_back(v);
191 v[0]=x+dx; v[1]=y+dy; v[2]=z; vertices.push_back(v);
192 v[0]=x+dx; v[1]=y+dy; v[2]=z+dz; vertices.push_back(v);
193 v[0]=x; v[1]=y+dy; v[2]=z+dz; vertices.push_back(v);
194
195 //point in the center
196 v[0]=x+0.5*dx; v[1]=y+0.5*dy ;v[2]=z+0.5*dz; vertices.push_back(v);
197 }
198
199 void initSymmetricVertices(Real x, Real y, Real z, Real dx, Real dy, Real dz)
200 {
201 vertices.reserve(15); // allocate space for 15 vertices
202
204
205 // points on the frontside
206 v[0]=x; v[1]=y; v[2]=z; vertices.push_back(v); // 0
207 v[0]=x+dx; v[1]=y; v[2]=z; vertices.push_back(v); // 1
208 v[0]=x+dx; v[1]=y; v[2]=z+dz; vertices.push_back(v); // 2
209 v[0]=x; v[1]=y; v[2]=z+dz; vertices.push_back(v); // 3
210
211 // points on the backside
212 v[0]=x; v[1]=y+dy; v[2]=z; vertices.push_back(v); // 4
213 v[0]=x+dx; v[1]=y+dy; v[2]=z; vertices.push_back(v); // 5
214 v[0]=x+dx; v[1]=y+dy; v[2]=z+dz; vertices.push_back(v); // 6
215 v[0]=x; v[1]=y+dy; v[2]=z+dz; vertices.push_back(v); // 7
216
217 // point in the center
218 v[0]=x+0.5*dx; v[1]=y+0.5*dy; v[2]=z+0.5*dz; vertices.push_back(v); // 8
219
220 // points in the center of face
221 v[0]=x; v[1]=y+0.5*dy; v[2]=z+0.5*dz; vertices.push_back(v); // 9
222 v[0]=x+dx; v[1]=y+0.5*dy; v[2]=z+0.5*dz; vertices.push_back(v); // 10
223 v[0]=x+0.5*dx; v[1]=y; v[2]=z+0.5*dz; vertices.push_back(v); // 11
224 v[0]=x+0.5*dx; v[1]=y+dy; v[2]=z+0.5*dz; vertices.push_back(v); // 12
225 v[0]=x+0.5*dx; v[1]=y+0.5*dy; v[2]=z; vertices.push_back(v); // 13
226 v[0]=x+0.5*dx; v[1]=y+0.5*dy; v[2]=z+dz; vertices.push_back(v); // 14
227 }
228
229 void initSymmetricTetrahedra()
230 {
231 simplices.reserve(24);
232 std::vector<unsigned int> p(4,0);
233
234 // bottom
235 p[0]=13; p[1]=1; p[2]=5; p[3]=8; simplices.push_back(p);
236 p[0]=13; p[1]=5; p[2]=4; p[3]=8; simplices.push_back(p);
237 p[0]=13; p[1]=4; p[2]=0; p[3]=8; simplices.push_back(p);
238 p[0]=13; p[1]=0; p[2]=1; p[3]=8; simplices.push_back(p);
239
240 // top
241 p[0]=14; p[1]=3; p[2]=2; p[3]=8; simplices.push_back(p);
242 p[0]=14; p[1]=2; p[2]=6; p[3]=8; simplices.push_back(p);
243 p[0]=14; p[1]=6; p[2]=7; p[3]=8; simplices.push_back(p);
244 p[0]=14; p[1]=7; p[2]=3; p[3]=8; simplices.push_back(p);
245
246 // right
247 p[0]=10; p[1]=6; p[2]=5; p[3]=8; simplices.push_back(p);
248 p[0]=10; p[1]=5; p[2]=1; p[3]=8; simplices.push_back(p);
249 p[0]=10; p[1]=1; p[2]=2; p[3]=8; simplices.push_back(p);
250 p[0]=10; p[1]=2; p[2]=6; p[3]=8; simplices.push_back(p);
251
252 // left
253 p[0]=9; p[1]=3; p[2]=0; p[3]=8; simplices.push_back(p);
254 p[0]=9; p[1]=0; p[2]=4; p[3]=8; simplices.push_back(p);
255 p[0]=9; p[1]=4; p[2]=7; p[3]=8; simplices.push_back(p);
256 p[0]=9; p[1]=7; p[2]=3; p[3]=8; simplices.push_back(p);
257
258 // front
259 p[0]=11; p[1]=1; p[2]=0; p[3]=8; simplices.push_back(p);
260 p[0]=11; p[1]=0; p[2]=3; p[3]=8; simplices.push_back(p);
261 p[0]=11; p[1]=3; p[2]=2; p[3]=8; simplices.push_back(p);
262 p[0]=11; p[1]=2; p[2]=1; p[3]=8; simplices.push_back(p);
263
264 // back
265 p[0]=12; p[1]=4; p[2]=5; p[3]=8; simplices.push_back(p);
266 p[0]=12; p[1]=5; p[2]=6; p[3]=8; simplices.push_back(p);
267 p[0]=12; p[1]=6; p[2]=7; p[3]=8; simplices.push_back(p);
268 p[0]=12; p[1]=7; p[2]=4; p[3]=8; simplices.push_back(p);
269 }
270
271 void initTetrahedra()
272 {
273 simplices.reserve(12);
274 std::vector<unsigned int> p(4,0); // TODO: use std::array here, size is known
275
276 // front side
277 p[0]=0; p[1]=1; p[2]=2; p[3]=8; simplices.push_back(p);
278 p[0]=2; p[1]=3; p[2]=0; p[3]=8; simplices.push_back(p);
279
280 // back side
281 p[0]=6; p[1]=5; p[2]=4; p[3]=8; simplices.push_back(p);
282 p[0]=4; p[1]=6; p[2]=7; p[3]=8; simplices.push_back(p);
283
284 // right side
285 p[0]=6; p[1]=1; p[2]=5; p[3]=8; simplices.push_back(p);
286 p[0]=2; p[1]=1; p[2]=6; p[3]=8; simplices.push_back(p);
287
288 // left side
289 p[0]=0; p[1]=4; p[2]=7; p[3]=8; simplices.push_back(p);
290 p[0]=0; p[1]=7; p[2]=3; p[3]=8; simplices.push_back(p);
291
292 // bottom
293 p[0]=0; p[1]=1; p[2]=5; p[3]=8; simplices.push_back(p);
294 p[0]=0; p[1]=5; p[2]=4; p[3]=8; simplices.push_back(p);
295
296 // top
297 p[0]=3; p[1]=2; p[2]=6; p[3]=8; simplices.push_back(p);
298 p[0]=3; p[1]=6; p[2]=7; p[3]=8; simplices.push_back(p);
299 }
300 };
301
302} // end namespace Kaskade
303
304#endif
BasicGridElement(BasicGridElement &&other)
Definition cube.hh:34
std::vector< std::vector< unsigned int > > const & getSimplices() const
Definition cube.hh:49
BasicGridElement & operator=(BasicGridElement const &other)=default
BasicGridElement(BasicGridElement const &other)=default
std::vector< std::vector< unsigned int > > simplices
Definition cube.hh:53
static constexpr int dim
Definition cube.hh:28
std::vector< Dune::FieldVector< Real, dim > > const & getVertices() const
Definition cube.hh:48
std::vector< Dune::FieldVector< Real, dim > > vertices
Definition cube.hh:52
BasicGridElement & operator=(BasicGridElement &&other)
Definition cube.hh:41
Cube(bool symmetric=false)
Creates the unit cube .
Definition cube.hh:153
Cube(Dune::FieldVector< Real, 3 > const &x0, Dune::FieldVector< Real, 3 > const &dx, bool symmetric)
Creates the cube .
Definition cube.hh:160
Real_ Real
Definition cube.hh:148
Square(Dune::FieldVector< Real, 2 > const &x0, Dune::FieldVector< Real, 2 > const &dx, bool symmetric=false)
Definition cube.hh:69
Square(bool symmetric=false)
Definition cube.hh:65
Real_ Real
Definition cube.hh:63