/usr/include/dune/pdelab/finiteelementmap/finiteelementmap.hh is in libdune-pdelab-dev 2.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_PDELAB_FINITELEMENTMAP_HH
#define DUNE_PDELAB_FINITELEMENTMAP_HH
#include <dune/common/deprecated.hh>
#include <dune/pdelab/common/exceptions.hh>
#include <dune/geometry/referenceelements.hh>
namespace Dune {
namespace PDELab {
//! \ingroup FiniteElementMap
//! \{
//! \brief general FiniteElementMap exception
class FiniteElementMapError : public Exception {};
//! \brief FiniteElementMap exception concerning the computation of the FiniteElementMap size
class VariableElementSize : public FiniteElementMapError {};
//! \brief FiniteElementMap exception raised when trying to obtain a finite element for an unsupported GeometryType.
class InvalidGeometryType : public FiniteElementMapError {};
//! \brief collect types exported by a finite element map
template<class T>
struct FiniteElementMapTraits
{
//! Type of finite element from local functions
typedef T FiniteElementType;
//! Type of finite element from local functions
typedef T FiniteElement;
};
//! \brief collect types exported by a finite element map
template<class T>
struct LocalFiniteElementMapTraits : FiniteElementMapTraits<T> {};
//! \brief interface for a finite element map
template<class T, class Imp>
class LocalFiniteElementMapInterface
{
public:
//! \brief Export traits
typedef T Traits;
/** \brief Return local basis for the given entity.
The return value is a reference to Traits::LocalBasisType. If
there is a different local basis for two elements then this
type must be polymorphic.
*/
template<class EntityType>
const typename Traits::FiniteElementType& find (const EntityType& e) const
{
return asImp().find(e);
}
/** @name Size calculation
* The FiniteElementMap provides different methods to compute
* the size of the GridFunctionSpace (if possible) without
* iterating the grid. The approach is as follows (pseudo code):
*
* \code
* computeNumberOfDofs(GridView, FEM):
* if(FEM.fixedSize()):
* sum(FEM.size(gt)*GridView.size(gt) for gt in GeometryTypes)
* else
* sum(FEM.find(E).basis().size() for E in GridView.entities<0>())
* \endcode
*/
/** @{ */
/** \brief a FiniteElementMap is fixedSize iif the size of the local
* functions space for each GeometryType is fixed.
*/
bool fixedSize() const
{
return asImp().fixedSize();
}
/** \brief if the FiniteElementMap is fixedSize, the size
* methods computes the number of DOFs for given GeometryType.
*/
std::size_t size(GeometryType gt) const
{
return asImp().size();
}
/** @} */
/** \brief compute an upper bound for the local number of DOFs.
*
* this upper bound is used to avoid reallocations in
* std::vectors used during the assembly.
*/
std::size_t maxLocalSize() const
{
return asImp().maxLocalSize();
}
private:
Imp& asImp () {return static_cast<Imp &> (*this);}
const Imp& asImp () const {return static_cast<const Imp &>(*this);}
};
//! simple implementation where all entities have the same finite element
template<class Imp>
class SimpleLocalFiniteElementMap :
public LocalFiniteElementMapInterface<LocalFiniteElementMapTraits<Imp>,
SimpleLocalFiniteElementMap<Imp> >
{
public:
//! \brief export type of the signature
typedef LocalFiniteElementMapTraits<Imp> Traits;
//! \brief Use when Imp has a standard constructor
SimpleLocalFiniteElementMap ()
{}
//! \brief Constructor where an instance of Imp can be provided
SimpleLocalFiniteElementMap (const Imp& imp_) : imp(imp_)
{}
//! \brief get local basis functions for entity
template<class EntityType>
const typename Traits::FiniteElementType& find (const EntityType& e) const
{
return imp;
}
private:
Imp imp; // create once
};
/** \brief implementation for finite elements requiring oriented edges
*
* This is for edge elements. It works for one type of Geometry only, and
* the requirements for the local finite element are:
*
* - The default orientation of the shape functions on the edges must be
* from the vertex with the lower index within the reference element to
* the vertex with the higher index.
* - The local finite element must allow assignment.
* - The local finite element must have a default constructor.
* - the local finite element hust have a constructor of the form
* FE(unsigned int orientation), where orientation is a bitfield. If
* bit i in orientation is set it means that the orientation of the
* shape function corresponding to the edge with id i in the reference
* element is inverted.
*
* \tparam GV Type of gridview to work with
* \tparam FE Type of local finite element
* \tparam Imp Type of the final LocalFiniteElementMap implementation
*/
template<typename GV, typename FE, typename Imp>
class EdgeS0LocalFiniteElementMap
: public LocalFiniteElementMapInterface<
LocalFiniteElementMapTraits<FE>,
Imp
>
{
typedef typename GV::IndexSet IndexSet;
static const int dim = GV::dimension;
public:
//! \brief export type of the signature
typedef LocalFiniteElementMapTraits<FE> Traits;
//! \brief construct EdgeSLocalFiniteElementMap
EdgeS0LocalFiniteElementMap (const GV& gv_)
: gv(gv_), orient(gv_.size(0))
{
typedef typename GV::Grid::ctype ct;
const ReferenceElement<ct, dim> &refElem =
ReferenceElements<ct, dim>::general(FE().type());
const typename GV::Grid::GlobalIdSet &idSet = gv.grid().globalIdSet();
// create all variants
variant.resize(1 << refElem.size(dim-1));
for (unsigned int i=0; i<variant.size(); i++)
variant[i] = FE(i);
// compute orientation for all elements
typedef typename GV::Traits::template Codim<0>::Iterator ElementIterator;
const typename GV::IndexSet& indexSet = gv.indexSet();
// loop once over the grid
for (ElementIterator it = gv.template begin<0>(); it!=gv.template end<0>(); ++it)
{
unsigned int elemid = indexSet.template index<0>(*it);
orient[elemid] = 0;
std::vector<typename GV::Grid::GlobalIdSet::IdType> vid(refElem.size(dim));
for(unsigned int i = 0; i < vid.size(); ++i)
vid[i] = idSet.subId(*it, i, dim);
// loop over all edges of the element
for(int i = 0; i < refElem.size(dim-1); ++i) {
int v0 = refElem.subEntity(i, dim-1, 0, dim);
int v1 = refElem.subEntity(i, dim-1, 1, dim);
// if (edge orientation in refelement) != (edge orientation in indexset)
if((v0 > v1) != (vid[v0] > vid[v1]))
orient[elemid] |= 1 << i;
}
}
}
//! \brief get local basis functions for entity
template<class EntityType>
const typename Traits::FiniteElementType& find (const EntityType& e) const
{
return variant[orient[gv.indexSet().template index<0>(e)]];
}
private:
GV gv;
std::vector<FE> variant;
std::vector<unsigned char> orient;
};
//! \} group FiniteElementMap
} // namespace PDELab
} // namespace Dune
#endif
|