DUNE LocalFunctions (unstable)

geometries.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5
6// This header is not part of the official Dune API and might be subject
7// to change. You can use this header to test external finite element
8// implementations, but be warned that your tests might break with future
9// Dune versions.
10
11#ifndef DUNE_LOCALFUNCTIONS_TEST_GEOMETRIES_HH
12#define DUNE_LOCALFUNCTIONS_TEST_GEOMETRIES_HH
13
14#include <cstddef>
15#include <vector>
16
17#include <dune/common/exceptions.hh>
18#include <dune/common/fvector.hh>
19
20#include <dune/geometry/type.hh>
21#include <dune/geometry/multilineargeometry.hh>
22
23template<class ctype, std::size_t dim>
24class TestGeometries;
25
26template<class ctype>
27class TestGeometries<ctype, 0> :
28 public std::vector<Dune::MultiLinearGeometry<ctype, 0, 0> >
29{
30 static constexpr std::size_t dim = 0;
31
32public:
33 typedef Dune::MultiLinearGeometry<ctype, dim, dim> Geometry;
34
35 TestGeometries() {
36 Dune::GeometryType gt;
37 std::vector<Dune::FieldVector<ctype, dim> > coords;
38
39 gt = Dune::GeometryTypes::vertex;
40 coords.resize(1);
41 this->push_back(Geometry(gt, coords));
42 }
43
44 const Geometry &get(const Dune::GeometryType &gt) const {
45 for(std::size_t i = 0; i < this->size(); ++i)
46 if((*this)[i].type() == gt) return (*this)[i];
47 DUNE_THROW(Dune::NotImplemented, "No predefined test-geometry in "
48 "dimension " << dim << " for GeometryType " << gt);
49 }
50};
51
52template<class ctype>
53class TestGeometries<ctype, 1> :
54 public std::vector<Dune::MultiLinearGeometry<ctype, 1, 1> >
55{
56 static constexpr std::size_t dim = 1;
57
58public:
59 typedef Dune::MultiLinearGeometry<ctype, dim, dim> Geometry;
60
61 TestGeometries() {
62 Dune::GeometryType gt;
63 std::vector<Dune::FieldVector<ctype, dim> > coords;
64
65 gt = Dune::GeometryTypes::line;
66 coords.resize(2);
67 coords[0][0] = -.3;
68 coords[1][0] = .7;
69 this->push_back(Geometry(gt, coords));
70 }
71
72 const Geometry &get(const Dune::GeometryType &gt) const {
73 for(std::size_t i = 0; i < this->size(); ++i)
74 if((*this)[i].type() == gt) return (*this)[i];
75 DUNE_THROW(Dune::NotImplemented, "No predefined test-geometry in "
76 "dimension " << dim << " for GeometryType " << gt);
77 }
78};
79
80template<class ctype>
81class TestGeometries<ctype, 2> :
82 public std::vector<Dune::MultiLinearGeometry<ctype, 2, 2> >
83{
84 static constexpr std::size_t dim = 2;
85
86public:
87 typedef Dune::MultiLinearGeometry<ctype, dim, dim> Geometry;
88
89 TestGeometries() {
90 Dune::GeometryType gt;
91 std::vector<Dune::FieldVector<ctype, dim> > coords;
92
93 gt = Dune::GeometryTypes::triangle;
94 coords.resize(3);
95 coords[0][0] = -.5; coords[0][1] = -.5;
96 coords[1][0] = .5; coords[1][1] = -.5;
97 coords[2][0] = 0 ; coords[2][1] = .5;
98 this->push_back(Geometry(gt, coords));
99
100 gt = Dune::GeometryTypes::quadrilateral;
101 coords.resize(4);
102 coords[0][0] = -.5; coords[0][1] = 0;
103 coords[1][0] = 0 ; coords[1][1] = -.5;
104 coords[2][0] = .5; coords[2][1] = 0;
105 coords[3][0] = 0 ; coords[3][1] = .5;
106 this->push_back(Geometry(gt, coords));
107 }
108
109 const Geometry &get(const Dune::GeometryType &gt) const {
110 for(std::size_t i = 0; i < this->size(); ++i)
111 if((*this)[i].type() == gt) return (*this)[i];
112 DUNE_THROW(Dune::NotImplemented, "No predefined test-geometry in "
113 "dimension " << dim << " for GeometryType " << gt);
114 }
115};
116
117template<class ctype>
118class TestGeometries<ctype, 3> :
119 public std::vector<Dune::MultiLinearGeometry<ctype, 3, 3> >
120{
121 static constexpr std::size_t dim = 3;
122
123public:
124 typedef Dune::MultiLinearGeometry<ctype, dim, dim> Geometry;
125
126 TestGeometries() {
127 Dune::GeometryType gt;
128 std::vector<Dune::FieldVector<ctype, dim> > coords;
129
130 gt = Dune::GeometryTypes::tetrahedron;
131 coords.resize(4);
132 coords[0][0] = -.5; coords[0][1] = -.5; coords[0][2] = -.5;
133 coords[1][0] = .5; coords[1][1] = -.5; coords[1][2] = -.5;
134 coords[2][0] = 0 ; coords[2][1] = .5; coords[2][2] = -.5;
135 coords[3][0] = 0 ; coords[3][1] = 0 ; coords[3][2] = .5;
136 this->push_back(Geometry(gt, coords));
137
138 gt = Dune::GeometryTypes::pyramid;
139 coords.resize(5);
140 coords[0][0] = -.5; coords[0][1] = 0; coords[0][2] = -.5;
141 coords[1][0] = 0 ; coords[1][1] = -.5; coords[1][2] = -.5;
142 coords[2][0] = .5; coords[2][1] = 0; coords[2][2] = -.5;
143 coords[3][0] = 0 ; coords[3][1] = .5; coords[3][2] = -.5;
144 coords[4][0] = .1; coords[4][1] = .1; coords[4][2] = .1;
145 this->push_back(Geometry(gt, coords));
146
147 gt = Dune::GeometryTypes::prism;
148 coords.resize(6);
149 coords[0][0] = -.6; coords[0][1] = -.5; coords[0][2] = -.4;
150 coords[1][0] = .5; coords[1][1] = -.6; coords[1][2] = -.5;
151 coords[2][0] = .1; coords[2][1] = .5; coords[2][2] = -.6;
152 coords[3][0] = -.5; coords[3][1] = -.4; coords[3][2] = .5;
153 coords[4][0] = .4; coords[4][1] = -.5; coords[4][2] = .6;
154 coords[5][0] = 0 ; coords[5][1] = .4; coords[5][2] = .5;
155 this->push_back(Geometry(gt, coords));
156
157 gt = Dune::GeometryTypes::hexahedron;
158 coords.resize(8);
159 coords[0][0] = -.7; coords[0][1] = -.6; coords[0][2] = -.5;
160 coords[1][0] = .4; coords[1][1] = -.3; coords[1][2] = -.7;
161 coords[2][0] = -.6; coords[2][1] = .5; coords[2][2] = -.4;
162 coords[3][0] = .3; coords[3][1] = .7; coords[3][2] = -.6;
163 coords[4][0] = -.5; coords[4][1] = -.4; coords[4][2] = .3;
164 coords[5][0] = .7; coords[5][1] = -.6; coords[5][2] = .5;
165 coords[6][0] = -.4; coords[6][1] = .3; coords[6][2] = .7;
166 coords[7][0] = .6; coords[7][1] = .5; coords[7][2] = .4;
167 this->push_back(Geometry(gt, coords));
168 }
169
170 const Geometry &get(const Dune::GeometryType &gt) const {
171 for(std::size_t i = 0; i < this->size(); ++i)
172 if((*this)[i].type() == gt) return (*this)[i];
173 DUNE_THROW(Dune::NotImplemented, "No predefined test-geometry in "
174 "dimension " << dim << " for GeometryType " << gt);
175 }
176};
177
178#endif // DUNE_LOCALFUNCTIONS_TEST_GEOMETRIES_HH
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Jun 17, 23:05, 2026)