| 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 |
#ifndef DUNE_LOCALKEY_HH |
| 6 |
#define DUNE_LOCALKEY_HH |
| 7 |
|
| 8 |
#include <array> |
| 9 |
#include <cstddef> |
| 10 |
#include <ostream> |
| 11 |
|
| 12 |
namespace Dune |
| 13 |
{ |
| 14 |
/** |
| 15 |
* \ingroup LocalInterface |
| 16 |
\brief Describe position of one degree of freedom |
| 17 |
|
| 18 |
A LocalKey associates a degree of freedom with an index |
| 19 |
of a local basis function. |
| 20 |
|
| 21 |
\nosubgrouping |
| 22 |
*/ |
| 23 |
class LocalKey |
| 24 |
{ |
| 25 |
public: |
| 26 |
|
| 27 |
/** \brief Enumerate 'special values' for the codimension method */ |
| 28 |
enum { |
| 29 |
/** \brief Codimension returned by LocalKey::codim() for degrees of freedom attached to an intersection |
| 30 |
|
| 31 |
The standard interface of dune-localfunctions assumes that degrees of freedom are attached to subentities |
| 32 |
of an element. This subentities can be described by a codimension and a subentity number. |
| 33 |
However some elements, like the mimetic finite elements, attach their degrees of freedom to intersections. |
| 34 |
While intersections do have a codimension, namely 1, having the method codim() return 1 in this case |
| 35 |
would be ambiguous. Hence 'intersectionCodim' is returned instead. |
| 36 |
*/ |
| 37 |
intersectionCodim=666 |
| 38 |
}; |
| 39 |
|
| 40 |
//! \brief Standard constructor for uninitialized local index |
| 41 |
constexpr LocalKey () noexcept |
| 42 |
: values_{} |
| 43 |
{} |
| 44 |
|
| 45 |
/** \brief Initialize all components |
| 46 |
\param s Local number of the associated subentity |
| 47 |
\param c Codimension of the associated subentity |
| 48 |
\param i Index in the set of all functions associated to this subentity |
| 49 |
*/ |
| 50 |
constexpr LocalKey (unsigned int s, unsigned int c, unsigned int i) noexcept |
| 51 |
: values_{s,c,i} |
| 52 |
{} |
| 53 |
|
| 54 |
//! \brief Return number of associated subentity |
| 55 |
[[nodiscard]] |
| 56 |
constexpr unsigned int subEntity () const noexcept |
| 57 |
{ |
| 58 |
return values_[0]; |
| 59 |
} |
| 60 |
|
| 61 |
//! \brief Return codim of associated entity |
| 62 |
[[nodiscard]] |
| 63 |
constexpr unsigned int codim () const noexcept |
| 64 |
{ |
| 65 |
return values_[1]; |
| 66 |
} |
| 67 |
|
| 68 |
//! \brief Return offset within subentity |
| 69 |
[[nodiscard]] |
| 70 |
constexpr unsigned int index () const noexcept |
| 71 |
{ |
| 72 |
return values_[2]; |
| 73 |
} |
| 74 |
|
| 75 |
//! \brief Set index component |
| 76 |
constexpr void index (unsigned int i) noexcept |
| 77 |
{ |
| 78 |
values_[2] = i; |
| 79 |
} |
| 80 |
|
| 81 |
/** \brief Less-than operator so we can use this class as a key type in stl containers */ |
| 82 |
[[nodiscard]] |
| 83 |
bool operator< (const LocalKey& other) const noexcept |
| 84 |
{ |
| 85 |
return values_ < other.values_; |
| 86 |
} |
| 87 |
|
| 88 |
/** \brief Write LocalKey object to output stream */ |
| 89 |
friend std::ostream& operator<< (std::ostream& s, const LocalKey& localKey) |
| 90 |
{ |
| 91 |
return s << "[ subEntity: " << localKey.subEntity() |
| 92 |
<< ", codim: " << localKey.codim() |
| 93 |
<< ", index: " << localKey.index() << " ]"; |
| 94 |
} |
| 95 |
|
| 96 |
private: |
| 97 |
|
| 98 |
// We use an array to store the values in order to be able to use the array::operator< implementation |
| 99 |
std::array<unsigned int,3> values_; |
| 100 |
|
| 101 |
}; |
| 102 |
|
| 103 |
} |
| 104 |
#endif |