13#if !defined(FIXDUNE_HH)
21#include "dune/grid/config.h"
23#include "dune/common/fmatrix.hh"
24#include "dune/common/fvector.hh"
25#include "dune/common/version.hh"
26#include "dune/geometry/type.hh"
27#include "dune/geometry/referenceelements.hh"
30#include "dune/istl/matrix.hh"
31#include "dune/istl/bvector.hh"
32#include "dune/istl/bcrsmatrix.hh"
49 template <
class T,
int n>
60 template <
class T,
int n>
63 for (
int i=0; i<n; ++i)
72 template <
class T,
int n>
75 for (
int i=0; i<n; ++i)
76 x[i] = std::max(x[i],y[i]);
84 template <
class T,
int n>
87 for (
int i=0; i<n; ++i)
88 x[i] = std::min(x[i],y[i]);
97 template <
class T,
int n,
int m>
101 for (
int j=0; j<m; ++j)
102 for (
int i=0; i<n; ++i)
111 template <
int n,
int m,
class T>
115 for (
int j=0; j<m; ++j)
116 for (
int i=0; i<n; ++i)
126 template <
class T,
int n,
int m>
130 for (
int i=0; i<n; ++i)
131 for (
int j=0; j<m; ++j)
140 template <
class T,
int n>
153 template <
class T,
int n,
int m>
158 for (
int i=0; i<n; ++i)
160 for (
int i=0; i<m; ++i)
166#ifndef DUNE_ALBERTA_ALGEBRA_HH
174 return x[0]*y[1] - x[1]*y[0];
197 for (
int i=0; i<3; ++i)
198 t[i] = x[(i+1)%3]*y[(i+2)%3]-x[(i+2)%3]*y[(i+1)%3];
210 for (
int i=0; i<3; ++i)
212 A[i][(i+2)%3] = x[(i+1)%3];
213 A[i][(i+1)%3] = -x[(i+2)%3];
226 template <
class T,
class S,
int n,
int m>
232 for (
int i=0; i<n; ++i)
233 for (
int j=0; j<m; ++j)
234 b[i] += A[i][j]*x[j];
242 template <
class T,
int n,
int m>
246 for (
int i=0; i<n; ++i)
251 template <
class T,
int n,
int m>
254 if constexpr (n*m==1)
290 template <
class Scalar,
int n>
303 template <
class Scalar,
int n,
class ... Rest>
310 using B =
decltype(b);
318 for (
int i=0; i<n; ++i)
325 else if constexpr (
rank<B> == 2)
328 for (
int i=0; i<n; ++i)
331 for (
int j=0; j<B::cols; ++j)
332 result[i][1+j] = b[i][j];
343 template <
class Scalar,
int n,
int m>
349 template <
class Scalar,
int n,
int m,
class ... Rest>
356 using B =
decltype(b);
362 for (
int i=0; i<n; ++i)
364 for (
int j=0; j<m; ++j)
365 result[i][j] = a[i][j];
370 else if constexpr (
rank<B> == 2)
373 for (
int i=0; i<n; ++i)
375 for (
int j=0; j<m; ++j)
376 result[i][j] = a[i][j];
377 for (
int j=0; j<B::cols; ++j)
378 result[i][m+j] = b[i][j];
391 template <
class Scalar,
int n>
397 for (
int i=0; i<n; ++i)
399 A[i][0] = col1[i]; A[i][1] = col2[i]; A[i][2] = col3[i];
407 template <
class Scalar,
int n,
int m>
412 for (
int i=0; i<n; ++i)
421 template <
class Scalar,
int n>
426 for(
int i=0; i<n; ++i)
427 for(
int j=0; j<n; ++j)
428 result[i+j*n] = A[i][j];
437 template <
int n,
class Scalar>
442 for(
int i=0; i<n; ++i)
443 for(
int j=0; j<n; ++j)
444 result[i][j] = v[i+j*n];
456 template <
class T,
int n,
int m>
460 for (
int i=0; i<n; ++i)
461 for (
int j=0; j<m; ++j)
462 x += A[i][j] * B[i][j];
477 template <
class T,
int n>
481 for (
int i=0; i<n; ++i)
492template <
class T,
int n>
496 for (
int i=0; i<n; ++i)
505template <
class T,
int n>
509 for (
int i=0; i<n; ++i)
535template <
class T,
int n>
547template <
class Matrix,
bool transposed>
550template <
class Scalar,
int n,
int m,
bool transposed>
564template <
class MatrixZ,
class Matrix>
565void MatMult(MatrixZ& z, Matrix
const& x, Matrix
const& y)
567 assert(((
void*)&z != (
void*)&x) && ((
void*)&z != (
void*)&y));
568 assert(x.M() == y.N());
570 z.setSize(x.N(),y.M());
572 for (
int i=0; i<z.N(); i++ ) {
573 for (
int j=0; j<z.M(); j++ ) {
574 typename MatrixZ::block_type temp = 0.0;
575 for (
int k=0; k<x.M(); k++)
576 temp += x[i][k]*y[k][j];
590namespace FixDuneDetail
595 struct GetIndexOfSubEntity
597 template <
class Cell,
class IS>
598 static int value(Cell
const& cell,
int codim,
int entity, IS
const& is)
602 return is.subIndex(cell,entity,Codim);
604 return GetIndexOfSubEntity<Codim-1>::value(cell,codim,entity,is);
609 struct GetIndexOfSubEntity<0>
611 template <
class Cell,
class IS>
612 static int value(Cell
const& cell,
int codim,
int entity, IS
const& is)
616 return is.subIndex(cell,entity,0);
621 struct GetNumberOfSubEntities
623 template <
class Cell>
624 static int value( Cell
const& cell,
int codim )
629 return GetNumberOfSubEntities<Codim-1>::value(cell, codim) ;
634 struct GetNumberOfSubEntities<0>
636 template <
class Cell>
637 static int value( Cell
const& cell,
int codim )
654template <
class IndexSet,
class Cell>
655size_t subIndex(IndexSet
const& is, Cell
const& cell,
int codim,
int subentity)
657 return FixDuneDetail::GetIndexOfSubEntity<Cell::dimension>::value(cell,codim,subentity,is);
667int count(Cell
const& cell,
int codim)
669 return FixDuneDetail::GetNumberOfSubEntities<Cell::dimension>::value(cell, codim) ;
691template <
class LocalCoordinate>
692typename LocalCoordinate::field_type
checkInside(Dune::GeometryType
const& gt,
693 LocalCoordinate
const& x)
698 return -std::min(*std::min_element(x.begin(),x.end()),1-x.one_norm());
699 else if (gt.isCube())
701 return -std::min(*std::min_element(x.begin(),x.end()),1-*std::max_element(x.begin(),x.end()));
704 return Dune::ReferenceElements<
typename LocalCoordinate::field_type,
705 LocalCoordinate::dimension>::general(gt).checkInside(x)? 0: 1;
723 boxmax(std::numeric_limits<double>::min());
725 auto geo = cell.geometry();
726 for(
int i=0; i<geo.corners(); ++i)
728 auto corner = geo.corner(i);
729 for(
int d=0; d<Cell::dimension; ++d)
731 boxmin[d] = std::min(boxmin[d],corner[d]);
732 boxmax[d] = std::max(boxmax[d],corner[d]);
735 return std::make_pair(boxmin,boxmax);
740template <
class Scalar,
int n,
int m,
class Allocator1,
class Allocator2>
743 to.resize(from.dim()*m);
744 for(
size_t i=0; i<from.N(); ++i)
745 for(
int j=0; j<n; ++j)
746 to[(i*n+j)/m][(i*n+j)%m] = from[i][j];
753template <
class Scalar,
int n,
int m,
class Allocator>
755 std::ostream& os=std::cout)
757 for(
size_t i0=0; i0<A.N(); ++i0)
758 for(
size_t i1=0; i1<n; ++i1)
760 for(
size_t j0=0; j0<A.M(); ++j0)
761 for(
size_t j1=0; j1<m; ++j1)
762 if(A.exists(i0,j0)) os << A[i0][j0][i1][j1] <<
" ";
772template <
class Scalar,
int n,
int m,
class Allocator>
void transferBlockVector(Dune::BlockVector< Dune::FieldVector< Scalar, n >, Allocator1 > const &from, Dune::BlockVector< Dune::FieldVector< Scalar, m >, Allocator2 > &to)
copy between two block vectors of different element lengths
int count(Cell const &cell, int codim)
Computes the number of subentities of codimension c of a given entity.
size_t subIndex(IndexSet const &is, Cell const &cell, int codim, int subentity)
void bcrsPrint(Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, n, m >, Allocator > const &A, std::ostream &os=std::cout)
Pretty prints the sparse matrix A to the given output stream.
std::ostream & operator<<(std::ostream &os, Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, n, m >, Allocator > const &A)
Pretty prints the sparse matrix A to the given output stream.
Dune::FieldVector< T, n > unitVector(int i)
Returns the unit vector with .
Dune::FieldVector< S, n > operator*(Dune::FieldMatrix< T, n, m > const &A, Dune::FieldVector< S, m > const &x)
Matrix-vector multiplication .
Dune::FieldMatrix< T, n, m > outerProduct(Dune::FieldVector< T, n > const &x, Dune::FieldVector< T, m > const &y)
outer vector product .
Dune::FieldMatrix< T, n, m > asMatrix(Dune::FieldVector< T, n *m > const &x)
Converts a vector of size nm to a matrix of size n x m by filling columns successively.
T trace(Dune::FieldMatrix< T, n, n > const &A)
Matrix trace .
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
Dune::FieldMatrix< T, n, n > unitMatrix()
Returns the identity matrix of size n .
Dune::FieldMatrix< T, 3, 3 > skewMatrix(Dune::FieldVector< T, 3 > v)
Returns the skew symmetric matrix related to the cross product with (3d) vector v.
Dune::FieldVector< T, n > operator+(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Vector addition .
Dune::FieldVector< T, n > normalize(Dune::FieldVector< T, n > x)
returns the normalized vector
Dune::FieldMatrix< T, 1, 2 > vectorProductMatrix(Dune::FieldVector< T, 2 > const &x)
the matrix satisfying for all
T vectorProduct(Dune::FieldVector< T, 2 > const &x, Dune::FieldVector< T, 2 > const &y)
vector product .
Dune::FieldVector< T, n > diag(Dune::FieldMatrix< T, n, n > const &A)
Matrix diagonal as a vector.
Dune::FieldVector< Scalar, n *n > vectorize(Dune::FieldMatrix< Scalar, n, n > const &A)
matrix entries as vector, concatenating columns
constexpr int rank
Reports the rank of vector, matrix, and tensor types of static size.
Dune::FieldVector< T, n > operator-(Dune::FieldVector< T, n > x)
Vector negation .
Dune::FieldMatrix< Scalar, n, n > unvectorize(Dune::FieldVector< Scalar, n *n > const &v)
forming quadratic matrix columns of vector segments
void MatMult(MatrixZ &z, Matrix const &x, Matrix const &y)
Computes Z = X*Y. X and Y need to be compatible, i.e. X.M()==Y.N() has to hold. No aliasing may occur...
Dune::FieldVector< T, n+m > vertcat(Dune::FieldVector< T, n > const &x, Dune::FieldVector< T, m > const &y)
Concatenation of vectors.
T contraction(Dune::FieldMatrix< T, n, m > const &A, Dune::FieldMatrix< T, n, m > const &B)
Matrix contraction (Frobenius product) .
Dune::FieldVector< T, n *m > asVector(Dune::FieldMatrix< T, n, m > const &x)
Converts a matrix of size n x m to a vector of size n*m by concatenating all the columns.
Dune::FieldVector< T, n > min(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise minimum.
std::pair< Dune::FieldVector< double, Cell::dimension >, Dune::FieldVector< double, Cell::dimension > > boundingBox(Cell const &cell)
Computes the bounding box of a cell.
LocalCoordinate::field_type checkInside(Dune::GeometryType const >, LocalCoordinate const &x)
Checks whether a point is inside or outside the reference element, and how much.
auto normalForm(Dune::FieldMatrix< T, n, m > const &A)
Dune::FieldVector< Scalar, n > column(Dune::FieldMatrix< Scalar, n, m > const &A, int j)
Extracts the j-th column of the given matrix A.
auto horzcat(Dune::FieldVector< Scalar, n > const &c1)
Dune::FieldMatrix< Scalar, transposed? m:n, transposed? n:m > type
Returns the matrix type or its transposed type, depending on the given transpose flag.