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,
class S,
50 class enable =
typename std::enable_if_t<std::is_arithmetic_v<S>>>
53 x *=
static_cast<T
>(s);
61 template <
class T,
int n,
class S,
62 class enable =
typename std::enable_if_t<std::is_arithmetic_v<S>>>
73 template <
class T,
int n>
84 template <
class T,
int n>
87 for (
int i=0; i<n; ++i)
97 template <
class T,
int n>
100 for (
int i=0; i<n; ++i)
109 template <
class T,
int n>
112 for (
int i=0; i<n; ++i)
121 template <
class T,
int n>
124 for (
int i=0; i<n; ++i)
134 template <
class T,
int n,
int m>
138 for (
int j=0; j<m; ++j)
139 for (
int i=0; i<n; ++i)
148 template <
int n,
int m,
class T>
152 for (
int j=0; j<m; ++j)
153 for (
int i=0; i<n; ++i)
163 template <
class T,
int n,
int m>
167 for (
int i=0; i<n; ++i)
168 for (
int j=0; j<m; ++j)
177 template <
class T,
int n>
190 template <
class T,
int n,
int m>
195 for (
int i=0; i<n; ++i)
197 for (
int i=0; i<m; ++i)
203#ifndef DUNE_ALBERTA_ALGEBRA_HH
211 return x[0]*y[1] - x[1]*y[0];
234 for (
int i=0; i<3; ++i)
235 t[i] = x[(i+1)%3]*y[(i+2)%3]-x[(i+2)%3]*y[(i+1)%3];
247 for (
int i=0; i<3; ++i)
249 A[i][(i+2)%3] = x[(i+1)%3];
250 A[i][(i+1)%3] = -x[(i+2)%3];
263 template <
class T,
class S,
int n,
int m>
269 for (
int i=0; i<n; ++i)
270 for (
int j=0; j<m; ++j)
271 b[i] += A[i][j]*x[j];
279 template <
class T,
int n,
int m>
283 for (
int i=0; i<n; ++i)
288 template <
class T,
int n,
int m>
291 if constexpr (n*m==1)
327 template <
class Scalar,
int n>
340 template <
class Scalar,
int n,
class ... Rest>
347 using B =
decltype(b);
352 if constexpr (rank<B> == 1)
355 for (
int i=0; i<n; ++i)
362 else if constexpr (rank<B> == 2)
365 for (
int i=0; i<n; ++i)
368 for (
int j=0; j<B::cols; ++j)
369 result[i][1+j] = b[i][j];
380 template <
class Scalar,
int n,
int m>
386 template <
class Scalar,
int n,
int m,
class ... Rest>
393 using B =
decltype(b);
396 if constexpr (rank<B> == 1)
399 for (
int i=0; i<n; ++i)
401 for (
int j=0; j<m; ++j)
402 result[i][j] = a[i][j];
407 else if constexpr (rank<B> == 2)
410 for (
int i=0; i<n; ++i)
412 for (
int j=0; j<m; ++j)
413 result[i][j] = a[i][j];
414 for (
int j=0; j<B::cols; ++j)
415 result[i][m+j] = b[i][j];
428 template <
class Scalar,
int n>
434 for (
int i=0; i<n; ++i)
436 A[i][0] = col1[i]; A[i][1] = col2[i]; A[i][2] = col3[i];
444 template <
class Scalar,
int n,
int m>
449 for (
int i=0; i<n; ++i)
458 template <
class Scalar,
int n>
463 for(
int i=0; i<n; ++i)
464 for(
int j=0; j<n; ++j)
465 result[i+j*n] = A[i][j];
474 template <
int n,
class Scalar>
479 for(
int i=0; i<n; ++i)
480 for(
int j=0; j<n; ++j)
481 result[i][j] = v[i+j*n];
493 template <
class T,
int n,
int m>
497 for (
int i=0; i<n; ++i)
498 for (
int j=0; j<m; ++j)
499 x += A[i][j] * B[i][j];
514 template <
class T,
int n>
518 for (
int i=0; i<n; ++i)
530template <
class T,
int n>
533 static Kaskade::Deprecated dummy(
"detrminant(A) is deprecated, use A.determinant() instead",2020);
534 return A.determinant();
541template <
class T,
int n>
545 for (
int i=0; i<n; ++i)
554template <
class T,
int n>
558 for (
int i=0; i<n; ++i)
584template <
class T,
int n>
596template <
class Matrix,
bool transposed>
599template <
class Scalar,
int n,
int m,
bool transposed>
613template <
class MatrixZ,
class Matrix>
614void MatMult(MatrixZ& z, Matrix
const& x, Matrix
const& y)
616 assert(((
void*)&z != (
void*)&x) && ((
void*)&z != (
void*)&y));
617 assert(x.M() == y.N());
619 z.setSize(x.N(),y.M());
621 for (
int i=0; i<z.N(); i++ ) {
622 for (
int j=0; j<z.M(); j++ ) {
623 typename MatrixZ::block_type temp = 0.0;
624 for (
int k=0; k<x.M(); k++)
625 temp += x[i][k]*y[k][j];
639namespace FixDuneDetail
644 struct GetIndexOfSubEntity
646 template <
class Cell,
class IS>
647 static int value(
Cell const& cell,
int codim,
int entity, IS
const& is)
651 return is.subIndex(cell,entity,Codim);
653 return GetIndexOfSubEntity<Codim-1>::value(cell,codim,entity,is);
658 struct GetIndexOfSubEntity<0>
660 template <
class Cell,
class IS>
661 static int value(
Cell const& cell,
int codim,
int entity, IS
const& is)
665 return is.subIndex(cell,entity,0);
670 struct GetNumberOfSubEntities
672 template <
class Cell>
673 static int value(
Cell const& cell,
int codim )
676 return cell.template count<Codim>() ;
678 return GetNumberOfSubEntities<Codim-1>::value(cell, codim) ;
683 struct GetNumberOfSubEntities<0>
685 template <
class Cell>
686 static int value(
Cell const& cell,
int codim )
689 return cell.template count<0>();
703template <
class IndexSet,
class Cell>
704size_t subIndex(IndexSet
const& is,
Cell const& cell,
int codim,
int subentity)
706 return FixDuneDetail::GetIndexOfSubEntity<Cell::dimension>::value(cell,codim,subentity,is);
718 return FixDuneDetail::GetNumberOfSubEntities<Cell::dimension>::value(cell, codim) ;
740template <
class LocalCoordinate>
741typename LocalCoordinate::field_type
checkInside(Dune::GeometryType
const& gt, LocalCoordinate
const& x)
746 return -
std::min(*std::min_element(x.begin(),x.end()),1-x.one_norm());
747 else if (gt.isCube())
749 return -
std::min(*std::min_element(x.begin(),x.end()),1-*std::max_element(x.begin(),x.end()));
752 return Dune::ReferenceElements<
typename LocalCoordinate::field_type,
753 LocalCoordinate::dimension>::general(gt).checkInside(x)? 0: 1;
770 auto geo = cell.geometry();
771 for(
int i=0; i<geo.corners(); ++i)
773 auto corner = geo.corner(i);
774 for(
int d=0; d<Cell::dimension; ++d)
776 boxmin[d] =
std::min(boxmin[d],corner[d]);
777 boxmax[d] =
std::max(boxmax[d],corner[d]);
780 return std::make_pair(boxmin,boxmax);
785template <
class Scalar,
int n,
int m,
class Allocator1,
class Allocator2>
788 to.resize(from.dim()*m);
789 for(
size_t i=0; i<from.N(); ++i)
790 for(
int j=0; j<n; ++j)
791 to[(i*n+j)/m][(i*n+j)%m] = from[i][j];
798template <
class Scalar,
int n,
int m,
class Allocator>
801 for(
size_t i0=0; i0<A.N(); ++i0)
802 for(
size_t i1=0; i1<n; ++i1)
804 for(
size_t j0=0; j0<A.M(); ++j0)
805 for(
size_t j1=0; j1<m; ++j1)
806 if(A.exists(i0,j0)) os << A[i0][j0][i1][j1] <<
" ";
816template <
class Scalar,
int n,
int m,
class Allocator>
Convenience class for marking deprecated functions. A static object of this class can be created insi...
std::ostream & operator<<(std::ostream &out, DynamicMatrix< Entry > const &A)
pretty output of dense matrices
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.
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
Dune::FieldVector< T, n > unitVector(int i)
Returns the unit vector with .
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.
T determinant(Dune::FieldMatrix< T, n, n > const &A)
Matrix determinant .
Dune::FieldVector< Scalar, n *n > vectorize(Dune::FieldMatrix< Scalar, n, n > const &A)
matrix entries as vector, concatenating columns
Dune::FieldVector< T, n > operator*(Dune::FieldVector< T, n > x, S s)
Scalar-vector multiplication .
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.