1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_GEOMETRY_REFERENCEELEMENT_HH
#define DUNE_GEOMETRY_REFERENCEELEMENT_HH
#include <dune/geometry/type.hh>
namespace Dune {
namespace Geo {
namespace Impl {
// forward declaration for friend declaration
template<typename ctype, int dim>
class ReferenceElementContainer;
}
// forward declaration for constructing default reference element type
template<typename ctype, int dim>
class ReferenceElementImplementation;
// forward declaration for backwards compatibility conversion
template<typename ctype, int dim>
struct ReferenceElements;
// ReferenceElement
// ----------------
/** \class ReferenceElement
* \ingroup GeometryReferenceElements
* \brief This class provides access to geometric and topological
* properties of a reference element.
*
* This includes its type,
* the number of subentities, the volume, and a method for checking
* if a point is contained in the reference element.
* The embedding of each subentity into the reference element is also
* provided.
*
* This class has value semantics, i.e. you can (and should) pass it
* around by value and not by reference and store a copy of it.
*
* Instances of this object for a given geometry type can be retrieved
* from the ReferenceElements class.
*
*/
template<typename Implementation>
class ReferenceElement
{
public:
#ifndef DOXYGEN
/** \brief Collection of types depending on the codimension */
template<int codim>
using Codim = typename Implementation::template Codim<codim>;
#else
/** \brief Collection of types depending on the codimension */
template< int codim >
struct Codim
{
//! type of geometry embedding a subentity into the reference element
using Geometry = implementation-defined;
};
#endif // DOXYGEN
//! The coordinate field type.
using ctype = typename Implementation::ctype;
//! The coordinate field type.
using CoordinateField = ctype;
//! The coordinate type.
using Coordinate = typename Implementation::Coordinate;
/** \brief Type used for volume */
typedef ctype Volume;
//! The dimension of the reference element.
static constexpr int dimension = Implementation::dimension;
/** \brief number of subentities of codimension c
*
* \param[in] c codimension whose size is desired
*/
int size(int c) const
{
return _impl->size(c);
}
/** \brief number of subentities of codimension cc of subentity (i,c)
*
* Denote by E the i-th subentity of codimension c of the current
* reference element. This method returns the number of subentities
* of codimension cc of the current reference element, that are also
* a subentity of E. If cc<c this number is zero.
*
* \param[in] i number of subentity E (0 <= i < size( c ))
* \param[in] c codimension of subentity E (0 <= c <= dim)
* \param[in] cc codimension whose size is desired (0 <= cc <= dim)
*/
int size(int i, int c, int cc) const
{
return _impl->size(i,c,cc);
}
/** \brief obtain number of ii-th subentity with codim cc of (i,c)
*
* Denote by E the i-th subentity of codimension c of the current
* reference element. And denote by S the ii-th subentity of codimension
* (cc-c) of E. Then, S is a also a subentity of codimension cc of the current
* reference element. This method returns the number of S with respect
* to the current reference element.
*
* \param[in] i number of subentity E (0 <= i < size( c ))
* \param[in] c codimension of subentity E
* \param[in] ii number of subentity S (with respect to E)
* \param[in] cc codimension of subentity S (c <= cc <= dim)
*/
int subEntity(int i, int c, int ii, int cc) const
{
return _impl->subEntity(i,c,ii,cc);
}
/** \brief Obtain the range of numbers of subentities with codim cc of (i,c)
*
* Denote by E the i-th subentity of codimension c of the current
* reference element. This method returns a range of numbers of
* all subentities of E with codimension cc. Notice that the sub-subentity
* codimension as well as the numbers in the returned range are
* given with respect to the reference element itself and not with
* respect to E. For 0<=cc<c this will return an empty range.
* The returned range r provide the methods r.begin(), r.end(),
* r.contains(std::size_t) and r.size() mimicking an immutable
* iterable set.
*
* \param[in] i number of subentity E (0 <= i < size( c ))
* \param[in] c codimension of subentity E
* \param[in] cc codimension of subentity S (0 <= cc <= dim)
*
* \returns An iterable range of numbers of the sub-subentities.
*/
auto subEntities ( int i, int c, int cc ) const
{
return _impl->subEntities(i,c,cc);
}
/** \brief obtain the type of subentity (i,c)
*
* Denote by E the i-th subentity of codimension c of the current
* reference element. This method returns the GeometryType of E.
*
* \param[in] i number of subentity E (0 <= i < size( c ))
* \param[in] c codimension of subentity E
*/
GeometryType type(int i, int c) const
{
return _impl->type(i,c);
}
/** \brief obtain the type of this reference element
*/
GeometryType type() const
{
return _impl->type();
}
/** \brief position of the barycenter of entity (i,c)
*
* Denote by E the i-th subentity of codimension c of the current
* reference element. This method returns the coordinates of
* the center of gravity of E within the current reference element.
*
* \param[in] i number of subentity E (0 <= i < size( c ))
* \param[in] c codimension of subentity E
*/
Coordinate position(int i, int c) const
{
return _impl->position(i,c);
}
/** \brief check if a coordinate is in the reference element
*
* This method returns true if the given local coordinate is within this
* reference element.
*
* \param[in] local coordinates of the point
*/
bool checkInside(const Coordinate& local) const
{
return _impl->checkInside(local);
}
/** \brief obtain the embedding of subentity (i,codim) into the reference
* element
*
* Denote by E the i-th subentity of codimension codim of the current
* reference element. This method returns a \ref Dune::AffineGeometry
* that maps the reference element of E into the current reference element.
*
* \tparam codim codimension of subentity E
*
* \param[in] i number of subentity E (0 <= i < size( codim ))
*/
template<int codim>
typename Codim<codim>::Geometry geometry(int i) const
{
return _impl->template geometry<codim>(i);
}
/** \brief obtain the volume of the reference element */
CoordinateField volume() const
{
return _impl->volume();
}
/** \brief obtain the integration outer normal of the reference element
*
* The integration outer normal is the outer normal whose length coincides
* with the face's integration element.
*
* \param[in] face index of the face, whose normal is desired
*/
Coordinate integrationOuterNormal(int face) const
{
return _impl->integrationOuterNormal(face);
}
/** \brief Constructs an empty reference element.
*
* This constructor creates an empty (invalid) reference element. This element may not be
* used in any way except for assigning other reference elements to it. After
* assigning a valid reference element (obtained from ReferenceElements), it may
* be used without restrictions.
*/
ReferenceElement()
: _impl(nullptr)
{}
/** \brief Returns a reference to the internal implementation object.
*
* \warning This method may only be called on valid reference elements.
* \warning This method exposes undocumented internals that may change without notice!
*/
const Implementation& impl() const
{
return *_impl;
}
//! Compares for equality with another reference element.
bool operator==(const ReferenceElement& r) const
{
return _impl == r._impl;
}
//! Compares for inequality with another reference element.
bool operator!=(const ReferenceElement& r) const
{
return not (*this == r);
}
//! Yields a hash value suitable for storing the reference element a in hash table
friend std::size_t hash_value(const ReferenceElement& r)
{
return reinterpret_cast<std::size_t>(r._impl);
}
private:
// The implementation must be a friend to construct a wrapper around itself.
friend Implementation;
// The reference container is a friend to be able to call setImplementation.
friend class Impl::ReferenceElementContainer<ctype,dimension>;
// Constructor for wrapping an implementation reference (required internally by the default implementation)
ReferenceElement(const Implementation& impl)
: _impl(&impl)
{}
void setImplementation(const Implementation& impl)
{
_impl = &impl;
}
const Implementation* _impl;
};
}
}
#endif // DUNE_GEOMETRY_REFERENCEELEMENT_HH
|