13#ifndef NEDELECSPACE_HH
14#define NEDELECSPACE_HH
39 template <
class Gr
idView>
42 typedef typename GridView::template Codim<0>::Entity Cell;
43 static int const dim = GridView::dimension;
55 assert(
cell_->geometry().affine());
56 Btinv =
cell_->geometry().jacobianInverseTransposed(x);
61 template <
class Scalar>
68 template <
class Scalar>
84 template <
class Scalar>
95 assert(deriv<2 &&
"not yet implemented");
103 template <
class Scalar>
124 typedef typename GridView::ctype real;
126 for (
int i=0; i<dim-1; ++i) {
128 real
max = std::abs(A[i][i]);
130 for (
int k=i+1; k<dim; ++k)
131 if (std::abs(A[k][i])>
max) {
132 max = std::abs(A[k][i]);
136 for (
int j=i; j<dim; ++j)
137 std::swap(A[i][j],A[midx][j]);
138 std::swap(b[i],b[midx]);
140 for (
int k=i+1; k<dim; ++k) {
141 real p = A[k][i]/A[i][i];
142 for (
int j=i; j<dim; ++j)
143 A[k][j] -= p*A[i][j];
148 for (
int i=dim-1; i>=0; --i) {
149 for (
int k=i+1; k<dim; ++k)
150 b[i] -= A[i][k]*b[k];
176 template <
class Gr
idView>
185 virtual void update()
205 template <
class Gr
idView>
214 virtual void update()
219 C *= this->
Btinv.determinant();
233 template <
class ScalarType,
class GV>
240 typedef typename GridView::Grid
Grid;
243 static int const dim = Grid::dimension;
258 typedef typename Grid::template Codim<0>::Entity
Cell;
266 gridView(gridView_), indexSet(gridView_.indexSet()), order(order_),
269 auto const& simplex = Dune::ReferenceElements<typename Grid::ctype,dim>::simplex();
283 assert(cell.type().isSimplex());
331 static std::vector<IndexPair> dummy;
354 size_t size()
const {
return nDof; }
384 for (
auto fi=gv.ibegin(cell); fi!=gv.iend(cell); ++fi)
386 faceOrient[fi->indexInInside()] = is.index(*(fi->outside()))>index? 1.0: -1.0;
388 faceOrient[fi->indexInInside()] = 1.0;
391 for (
int i=0; i<
orient.size(); ++i)
393 auto loc = sfs[i].location();
394 int codim = std::get<1>(loc);
396 this->
orient[i] = faceOrient[std::get<2>(loc)];
410 assert(indexSet.index(cell)==index);
426 globIdx.resize(indexSet.size(0));
431 for (
int i=0; i<sfs.
size(); ++i)
432 if (std::get<1>(sfs[i].location()) == 0)
437 nCellF = indexSet.size(0) * nCellSf;
438 size_t const nFaceF = indexSet.size(1) * nFaceSf;
439 nDof = nCellF + nFaceF;
445 auto end = gridView.template end<0>() ;
446 for (
auto ci=gridView.template begin<0>(); ci!=end; ++ci)
448 size_t const cellIdx = indexSet.index(*ci);
449 auto& gidx = globIdx[cellIdx];
456 gidx.resize(sf.size());
457 sortedIdx[cellIdx].resize(gidx.size());
458 for (
int i=0; i<gidx.size(); ++i)
460 int nominalOrder, codim, entity, indexInEntity;
461 std::tie(nominalOrder,codim,entity,indexInEntity) = sf[i].location();
464 gidx[i] = cellIdx*nCellSf + indexInEntity;
471 std::array<int,dim+1> bc =
barycentric(SimplexLagrangeDetail::tupleIndex(order,sf[i].location()),order);
472 std::array<int,dim> subBc;
473 for (
int i=0; i<
dim; ++i)
474 subBc[i] = bc[pi[i]];
477 int k = SimplexLagrangeDetail::local(&subBc[0],
dim-1,order);
479 size_t faceIdx = indexSet.subIndex(*ci,entity,1);
480 gidx[i] = nCellF + faceIdx*nFaceSf + k;
482 sortedIdx[cellIdx][i] = std::make_pair(gidx[i],i);
484 std::sort(sortedIdx[cellIdx].begin(),sortedIdx[cellIdx].end());
497 std::vector<Scalar> orient;
502 std::vector<std::vector<size_t> > globIdx;
507 std::vector<std::vector<IndexPair> > sortedIdx;
522 template <
class ScalarType,
class GV>
531 typedef typename GridView::Grid
Grid;
534 static int const dim = Grid::dimension;
549 typedef typename Grid::template Codim<0>::Entity
Cell;
557 gridView(gridView_), indexSet(gridView_.indexSet())
559 Dune::ReferenceElement<typename Grid::ctype,dim>
const &simplex = Dune::ReferenceElements<typename Grid::ctype,dim>::simplex();
562 vertexIndex_.reserve(simplex.size(
dim-1));
564 for (
int e=0; e<simplex.size(
dim-1); ++e)
565 vertexIndex_.push_back(std::make_pair(simplex.subEntity(e,
dim-1,0,
dim),
566 simplex.subEntity(e,
dim-1,1,
dim)));
574 assert(cell.type().isSimplex());
575 return nedelecShapeFunctionSet<typename Grid::ctype,dim,Scalar>(cell.type(),1);
580 assert(cell.type().isSimplex());
581 return nedelecShapeFunctionSet<typename Grid::ctype,dim,Scalar>(Dune::GeometryType(Dune::GeometryType::simplex,
dim),1);
618 static std::vector<IndexPair> dummy;
641 size_t size()
const {
return indexSet.size(
dim-1); }
663 : orient(vertexIndex.
size())
666 int globalVertexIndex[
dim+1];
667 for (
int i=0; i<=
dim; ++i)
668 globalVertexIndex[i] = is.subIndex(cell,i,
dim);
673 for (
int i=0; i<vertexIndex.size(); ++i) {
674 int p0 = vertexIndex[i].first;
675 int p1 = vertexIndex[i].second;
676 orient[i] = globalVertexIndex[p0]<globalVertexIndex[p1]? 1: -1;
684 template <
class Matrix>
687 assert(A.M()==orient.size());
688 for (
int i=0; i<A.N(); ++i)
689 for (
int j=0; j<A.M(); ++j)
690 A[i][j] *= orient[j];
694 template <
int n,
int m>
696 assert(v.size()==orient.size());
697 for (
int i=0; i<v.size(); ++i) {
698 v[i].value *= orient[i];
699 v[i].gradient *= orient[i];
707 template <
class Matrix>
711 assert(A.N()==orient.size());
712 for (
int i=0; i<A.N(); ++i)
713 for (
int j=0; j<A.M(); ++j)
714 A[i][j] *= orient[i];
719 operator Dune::BCRSMatrix<Dune::FieldMatrix<Scalar,1,1> >()
const
721 int n = orient.size();
723 for (
int i=0; i<n; ++i)
724 K.incrementrowsize(i);
726 for (
int i=0; i<n; ++i)
729 for (
int i=0; i<n; ++i)
730 *K[i].begin() = orient[i];
736 std::vector<Scalar> orient;
746 assert(indexSet.index(cell)==index);
747 return Combiner(cell,indexSet,vertexIndex_);
758 globIdx.resize(indexSet.size(0));
763 typedef typename GridView::template Codim<0>::Iterator CellIterator;
765 CellIterator end = gridView.template end<0>() ;
768 for (CellIterator ci=gridView.template begin<0>(); ci!=end; ++ci) {
769 size_t const k = indexSet.index(*ci);
770 std::vector<size_t>& gidx = globIdx[k];
773 gidx.resize(sf.
size());
774 sortedIdx[k].resize(gidx.size());
775 for (
int i=0; i<gidx.size(); ++i)
777 gidx[i] = indexSet.subIndex(*ci,std::get<2>(sf[i].location()),
dim-1);
778 sortedIdx[k][i] = std::make_pair(gidx[i],i);
780 std::sort(sortedIdx[k].begin(),sortedIdx[k].end());
792 std::vector<std::vector<size_t> > globIdx;
797 std::vector<std::vector<IndexPair> > sortedIdx;
801 std::vector<std::pair<int,int> > vertexIndex_;
A base class for implementing combiners with diagonal structure.
std::vector< Scalar > orient
A class for computing permutations of local vertex numbers of simplex subentities to a globally uniqu...
std::array< int, dimension+1-codim > barycentricSubsetPermutation(int e) const
Computes a permutation of barycentric coordinates to globally unique ordering.
A class mapping local vectorial shape function values and gradients to global shape function values a...
HcurlConverter(typename GridView::template Codim< 0 >::Entity const &cell)
A class mapping local vectorial shape function values and gradients to global shape function values a...
HdivConverter(typename GridView::template Codim< 0 >::Entity const &cell)
A class implementing a matrix mapping a subset of global degrees of freedom (those given by globalIn...
Combiner(Cell const &cell, GridView const &gv, IndexSet const &is, size_t index, ShapeFunctionSet const &sfs)
Degrees of freedom manager for H(div) conforming elements.
Grid::template Codim< 0 >::Entity Cell
GlobalIndexRange globalIndices(Cell const &cell) const
Returns a const sequence containing the global indices of the shape functions associated to this cell...
RangeView< std::vector< size_t >::const_iterator > GlobalIndexRange
SortedIndexRange sortedIndices(Cell const &cell) const
Returns an immutable sequence of (global index, local index) pairs sorted in ascending global index o...
SortedIndexRange sortedIndices(size_t n) const
Returns an immutable sequence of (global index, local index) pairs sorted in ascending global index o...
size_t size() const
Returns the number of global degrees of freedom managed.
static SortedIndexRange initSortedIndexRange()
Returns an empty range just for initialization, since RangeView is not default constructible.
HdivShapeFunctionSetContainer< typenameGrid::ctype, dim, Scalar >::value_type ShapeFunctionSet
ShapeFunctionSet const & shapefunctions(size_t) const
static bool const globalSupport
Whether the ansatz functions have global support (i.e. lead to dense matrices).
void update()
(Re)computes the internal data.
HdivConverter< GridView > Converter
A class mapping local shape function values and derivatives to global shape function values and deriv...
std::pair< size_t, int > IndexPair
static int const continuity
HdivMapper(GridView const &gridView_, int order_)
Constructs an HdivMapper for a given grid view.
GridView::IndexSet IndexSet
int maxOrder() const
Returns the maximal polynomial order of shape functions encountered in any cell.
GlobalIndexRange initGlobalIndexRange() const
Returns an empty range just for initialization purposes, since RangeView is not default constructible...
ShapeFunctionSet const & shapefunctions(Cell const &cell, bool) const
Returns the set of shape functions defined on this cell.
GlobalIndexRange globalIndices(size_t n) const
Returns a const sequence containing the global indices of the shape functions associated to the cell ...
RangeView< SortedIndexIterator > SortedIndexRange
Combiner combiner(Cell const &cell, size_t index) const
Returns a combiner for the given cell.
std::vector< IndexPair >::const_iterator SortedIndexIterator
A class implementing a matrix mapping a subset of global degrees of freedom (those given by globalIn...
void rightTransform(std::vector< VariationalArg< Scalar, n, m > > &v) const
In-place computation of row vectors .
void leftPseudoInverse(Matrix &A) const
In-place computation of .
Combiner(Cell const &cell, IndexSet const &is, std::vector< std::pair< int, int > > const &vertexIndex)
void rightTransform(Matrix &A) const
In-place computation of .
Degrees of freedom manager for Nedelec edge elements.
std::vector< IndexPair >::const_iterator SortedIndexIterator
void update()
(Re)computes the internal data.
GlobalIndexRange globalIndices(size_t n) const
Grid::template Codim< 0 >::Entity Cell
static bool const globalSupport
Whether the ansatz functions have global support (i.e. lead to dense matrices).
SortedIndexRange sortedIndices(Cell const &cell) const
Returns an immutable sequence of (global index, local index) pairs sorted in ascending global index o...
ScalarType RT __attribute__((deprecated))
std::pair< size_t, int > IndexPair
static int const continuity
Combiner combiner(Cell const &cell, size_t index) const
RangeView< std::vector< size_t >::const_iterator > GlobalIndexRange
NedelecShapeFunctionSetContainer< typenameGrid::ctype, dim, Scalar >::value_type ShapeFunctionSet
HcurlConverter< Grid > Converter
A class mapping local shape function values and derivatives to global shape function values and deriv...
GlobalIndexRange initGlobalIndexRange() const
NedelecMapper(GridView const &gridView_, bool)
Constructs a NedelecMapper for a given grid view. The second parameter is unused and only specified f...
GlobalIndexRange globalIndices(Cell const &cell) const
GridView::IndexSet IndexSet
ShapeFunctionSet const & shapefunctions(size_t n) const
RangeView< SortedIndexIterator > SortedIndexRange
SortedIndexRange sortedIndices(size_t n) const
Returns an immutable sequence of (global index, local index) pairs sorted in ascending global index o...
static SortedIndexRange initSortedIndexRange()
Returns an empty range just for initialization, since RangeView is not default constructible.
ShapeFunctionSet const & shapefunctions(Cell const &cell) const
DEPRECATED. Use boost::iterator_range instead.
virtual int size() const
Number of shape functions in the set.
A class mapping local vectorial shape function values and gradients to global shape function values a...
Dune::FieldMatrix< Scalar, dim, 1 > global(Dune::FieldMatrix< Scalar, dim, 1 > const &sf) const
Applies the transformation to shape function value.
virtual void update()=0
Redefine this to set .
VariationalArg< Scalar, dim, dim > global(VariationalArg< Scalar, dim, dim > const &sf, int deriv) const
Applies the transformation to shape function value, derivative, and Hessian, returning a filled Vari...
void moveTo(Cell const &cell)
void solve(Dune::FieldMatrix< typename GridView::ctype, dim, dim > A, Dune::FieldVector< typename GridView::ctype, dim > &x, Dune::FieldVector< typename GridView::ctype, dim > b) const
VectorialConverterBase(Cell const &cell)
void setLocalPosition(Dune::FieldVector< typename GridView::ctype, dim > const &x)
Dune::FieldMatrix< Scalar, dim, 1 > local(Dune::FieldMatrix< Scalar, dim, 1 > const &glob) const
Applies the inverse transform to global shape function values, giving the local shape function value...
Dune::FieldMatrix< typename GridView::ctype, dim, dim > Btinv
VariationalArg< Scalar, dim, dim > global(std::pair< Dune::FieldVector< Scalar, dim >, Dune::FieldMatrix< Scalar, dim, dim > > const &sf) const
Applies the transformation to shape function value and derivative.
VectorialConverterBase()=default
Dune::FieldMatrix< typename GridView::ctype, dim, dim > C
FEFunctionSpace and FunctionSpaceElement and the like.
Dune::FieldVector< CoordType, dim+1 > barycentric(Dune::FieldVector< CoordType, dim > const &x)
Computes the barycentric coordinates of a point in the unit simplex.
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
typename GetScalar< Type >::type ScalarType
Extracts the scalar field type from linear algebra data types.
HdivShapeFunctionSetContainer< ctype, dimension, T >::value_type const & hdivShapeFunctionSet(Dune::GeometryType type, int order)
Returns a Hdiv shape function set for given reference element type and given polynomial order....
A class that stores values, gradients, and Hessians of evaluated shape functions.
ValueType value
The shape function's value, a vector of dimension components