15 #include "../config/config.hpp"
16 #include "../general/globals.hpp"
35 void FNorm(
double &scale_factor,
double &scaled_fnorm2)
const;
58 { data = d; capacity = -h*w; }
65 { data = d;
height = h;
width = w; capacity = -h*w; }
71 void Reset(
double *d,
int h,
int w)
92 inline double *
Data()
const {
return data; }
94 inline double *
GetData()
const {
return data; }
96 inline bool OwnsData()
const {
return (capacity > 0); }
102 inline const double &
operator()(
int i,
int j)
const;
108 double Trace()
const;
111 virtual double &
Elem(
int i,
int j);
114 virtual const double &
Elem(
int i,
int j)
const;
117 void Mult(
const double *x,
double *y)
const;
141 double InnerProduct(
const double *x,
const double *y)
const;
158 {
return InnerProduct((
const double *)x, (
const double *)y); }
177 void Set(
double alpha,
const double *A);
208 void Norm2(
double *v)
const;
214 double FNorm()
const {
double s, n2;
FNorm(s, n2);
return s*sqrt(n2); }
217 double FNorm2()
const {
double s, n2;
FNorm(s, n2);
return s*s*n2; }
223 { Eigensystem(ev, &evect); }
226 { Eigensystem(ev, &evect); }
229 int Rank(
double tol)
const;
250 void SetRow(
int row,
double value);
252 void SetCol(
int col,
double value);
262 void Diag(
double c,
int n);
264 void Diag(
double *diag,
int n);
299 int row_offset,
int col_offset);
301 void CopyMNDiag(
double c,
int n,
int row_offset,
int col_offset);
303 void CopyMNDiag(
double *diag,
int n,
int row_offset,
int col_offset);
336 long MemoryUsage()
const {
return std::abs(capacity) *
sizeof(double); }
343 void Add(
const DenseMatrix &A,
const DenseMatrix &B,
344 double alpha, DenseMatrix &C);
347 void Add(
double alpha,
const double *A,
348 double beta,
const double *B, DenseMatrix &C);
351 void Add(
double alpha,
const DenseMatrix &A,
352 double beta,
const DenseMatrix &B, DenseMatrix &C);
355 void Mult(
const DenseMatrix &b,
const DenseMatrix &c, DenseMatrix &a);
358 void AddMult(
const DenseMatrix &b,
const DenseMatrix &c, DenseMatrix &a);
363 void CalcAdjugate(
const DenseMatrix &a, DenseMatrix &adja);
370 void CalcInverse(
const DenseMatrix &a, DenseMatrix &inva);
378 void CalcOrtho(
const DenseMatrix &J, Vector &n);
381 void MultAAt(
const DenseMatrix &a, DenseMatrix &aat);
384 void MultADAt(
const DenseMatrix &A,
const Vector &D, DenseMatrix &ADAt);
387 void AddMultADAt(
const DenseMatrix &A,
const Vector &D, DenseMatrix &ADAt);
390 void MultABt(
const DenseMatrix &A,
const DenseMatrix &B, DenseMatrix &ABt);
393 void MultADBt(
const DenseMatrix &A,
const Vector &D,
394 const DenseMatrix &B, DenseMatrix &ADBt);
397 void AddMultABt(
const DenseMatrix &A,
const DenseMatrix &B, DenseMatrix &ABt);
400 void AddMultADBt(
const DenseMatrix &A,
const Vector &D,
401 const DenseMatrix &B, DenseMatrix &ADBt);
404 void AddMult_a_ABt(
double a,
const DenseMatrix &A,
const DenseMatrix &B,
408 void MultAtB(
const DenseMatrix &A,
const DenseMatrix &B, DenseMatrix &AtB);
411 void AddMult_a_AAt(
double a,
const DenseMatrix &A, DenseMatrix &AAt);
414 void Mult_a_AAt(
double a,
const DenseMatrix &A, DenseMatrix &AAt);
417 void MultVVt(
const Vector &v, DenseMatrix &vvt);
419 void MultVWt(
const Vector &v,
const Vector &w, DenseMatrix &VWt);
422 void AddMultVWt(
const Vector &v,
const Vector &w, DenseMatrix &VWt);
425 void AddMultVVt(
const Vector &v, DenseMatrix &VWt);
428 void AddMult_a_VWt(
const double a,
const Vector &v,
const Vector &w,
432 void AddMult_a_VVt(
const double a,
const Vector &v, DenseMatrix &VVt);
442 #ifdef MFEM_USE_LAPACK
461 double Det(
int m)
const;
465 void Mult(
int m,
int n,
double *X)
const;
469 void LSolve(
int m,
int n,
double *X)
const;
473 void USolve(
int m,
int n,
double *X)
const;
477 void Solve(
int m,
int n,
double *X)
const;
484 static void SubMult(
int m,
int n,
int r,
const double *A21,
485 const double *X1,
double *X2);
497 void BlockFactor(
int m,
int n,
double *A12,
double *A21,
double *A22)
const;
515 double *B1,
double *B2)
const;
524 const double *X2,
double *Y1)
const;
590 #ifdef MFEM_USE_LAPACK
618 #ifdef MFEM_USE_LAPACK
658 tdata =
new double[i*j*k];
664 : Mk(NULL, other.Mk.height, other.Mk.width), nk(other.nk), own_data(true)
669 tdata =
new double[size];
670 std::memcpy(tdata, other.tdata,
sizeof(
double) * size);
684 if (own_data) {
delete [] tdata; }
687 tdata =
new double[i*j*k];
693 if (own_data) {
delete [] tdata; }
714 double *
Data() {
return tdata; }
727 if (own_data) {
delete [] tdata; }
736 MFEM_ASSERT(data && i >= 0 && i < height && j >= 0 && j <
width,
"");
742 MFEM_ASSERT(data && i >= 0 && i < height && j >= 0 && j <
width,
"");
int Size() const
For backward compatibility define Size to be synonym of Width()
void Symmetrize()
(*this) = 1/2 ((*this) + (*this)^t)
void MultABt(const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &ABt)
Multiply a matrix A with the transpose of a matrix B: A*Bt.
DenseMatrix & operator-=(const DenseMatrix &m)
void SymmetricScaling(const Vector &s)
SymmetricScaling this = diag(sqrt(s)) * this * diag(sqrt(s))
void SquareRootInverse()
Replaces the current matrix with its square root inverse.
int CheckFinite(const double *v, const int n)
void AddMultVWt(const Vector &v, const Vector &w, DenseMatrix &VWt)
VWt += v w^t.
DenseMatrix & operator*=(double c)
void GetDiag(Vector &d) const
Returns the diagonal of the matrix.
void UseExternalData(double *ext_data, int i, int j, int k)
DenseTensor & operator=(double c)
Sets the tensor elements equal to constant c.
void MultVWt(const Vector &v, const Vector &w, DenseMatrix &VWt)
void InvRightScaling(const Vector &s)
InvRightScaling: this = this * diag(1./s);.
const DenseMatrix & operator()(int k) const
void Eigenvalues(Vector &ev)
void SingularValues(Vector &sv) const
DenseMatrix & operator()(int k)
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
void BlockFactor(int m, int n, double *A12, double *A21, double *A22) const
void BlockBackSolve(int m, int n, int r, const double *U12, const double *X2, double *Y1) const
double InnerProduct(const double *x, const double *y) const
Compute y^t A x.
void CalcAdjugate(const DenseMatrix &a, DenseMatrix &adja)
void AddMult(const Table &elem_dof, const Vector &x, Vector &y) const
void TestInversion()
Invert and print the numerical conditioning of the inversion.
Data type dense matrix using column-major storage.
void CopyRows(const DenseMatrix &A, int row1, int row2)
Copy rows row1 through row2 from A to *this.
void SetSize(int i, int j, int k)
void Eval(DenseMatrix &M)
Abstract data type for matrix inverse.
void AddMult_a_ABt(double a, const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &ABt)
ABt += a * A * B^t.
void GetInverseMatrix(DenseMatrix &Ainv) const
Compute and return the inverse matrix in Ainv.
void Factor()
Factor the current DenseMatrix, *a.
void GetInverseMatrix(int m, double *X) const
Assuming L.U = P.A factored data of size (m x m), compute X <- A^{-1}.
double * GetData() const
Returns the matrix data array.
void CalcOrtho(const DenseMatrix &J, Vector &n)
DenseMatrix & operator=(double c)
Sets the matrix elements equal to constant c.
void Set(double alpha, const double *A)
Set the matrix to alpha * A, assuming that A has the same dimensions as the matrix and uses column-ma...
void Mult_a_AAt(double a, const DenseMatrix &A, DenseMatrix &AAt)
AAt = a * A * A^t.
static void SubMult(int m, int n, int r, const double *A21, const double *X1, double *X2)
const Vector & Eigenvector(int i)
virtual void Print(std::ostream &out=mfem::out, int width_=4) const
Prints matrix to stream out.
virtual void Mult(const Vector &x, Vector &y) const
Matrix vector multiplication with the inverse of dense matrix.
const double & operator()(int i, int j, int k) const
void Set(double alpha, const DenseMatrix &A)
Set the matrix to alpha * A.
void Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
double & operator()(int i, int j)
Returns reference to a_{ij}.
void USolve(int m, int n, double *X) const
double FNorm() const
Compute the Frobenius norm of the matrix.
void MultTranspose(const double *x, double *y) const
Multiply a vector with the transpose matrix.
void CalcAdjugateTranspose(const DenseMatrix &a, DenseMatrix &adjat)
Calculate the transposed adjugate of a matrix (for NxN matrices, N=1,2,3)
double & operator()(int i, int j, int k)
void AddMult(const DenseMatrix &b, const DenseMatrix &c, DenseMatrix &a)
Matrix matrix multiplication. A += B * C.
double operator*(const DenseMatrix &m) const
Matrix inner product: tr(A^t B)
double Singularvalue(int i)
void Reset(double *d, int h, int w)
Change the data array and the size of the DenseMatrix.
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
void Add(const double c, const DenseMatrix &A)
Adds the matrix A multiplied by the number c to the matrix.
void AddMult_a_VWt(const double a, const Vector &v, const Vector &w, DenseMatrix &VWt)
VWt += a * v w^t.
void InvSymmetricScaling(const Vector &s)
InvSymmetricScaling this = diag(sqrt(1./s)) * this * diag(sqrt(1./s))
void GetRow(int r, Vector &row) const
void BlockForwSolve(int m, int n, int r, const double *L21, double *B1, double *B2) const
DenseMatrixSVD(DenseMatrix &M)
Abstract data type matrix.
const double * GetColumn(int col) const
void Norm2(double *v) const
Take the 2-norm of the columns of A and store in v.
void MultADBt(const DenseMatrix &A, const Vector &D, const DenseMatrix &B, DenseMatrix &ADBt)
ADBt = A D B^t, where D is diagonal.
void Invert()
Replaces the current matrix with its inverse.
virtual ~DenseMatrixInverse()
Destroys dense inverse matrix.
void LSolve(int m, int n, double *X) const
void LeftScaling(const Vector &s)
LeftScaling this = diag(s) * this.
double Det() const
Compute the determinant of the original DenseMatrix using the LU factors.
void AddMultVVt(const Vector &v, DenseMatrix &VVt)
VVt += v v^t.
void CopyMNDiag(double c, int n, int row_offset, int col_offset)
Copy c on the diagonal of size n to *this at row_offset, col_offset.
~DenseMatrixEigensystem()
void AddMult_a_VVt(const double a, const Vector &v, DenseMatrix &VVt)
VVt += a * v v^t.
void Neg()
(*this) = -(*this)
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
void Solve(int m, int n, double *X) const
void SetRow(int r, const Vector &row)
void Getl1Diag(Vector &l) const
Returns the l1 norm of the rows of the matrix v_i = sum_j |a_ij|.
void AddToVector(int offset, Vector &v) const
Add the matrix 'data' to the Vector 'v' at the given 'offset'.
DenseMatrix & Eigenvectors()
void GetColumn(int c, Vector &col) const
void AddMult(const Vector &x, Vector &y) const
y += A.x
void Threshold(double eps)
Replace small entries, abs(a_ij) <= eps, with zero.
void CalcInverse(const DenseMatrix &a, DenseMatrix &inva)
void TestInversion()
Print the numerical conditioning of the inversion: ||A^{-1} A - I||.
double MaxMaxNorm() const
Compute the norm ||A|| = max_{ij} |A_{ij}|.
double * Data() const
Returns the matrix data array.
void Transpose()
(*this) = (*this)^t
void MultVVt(const Vector &v, DenseMatrix &vvt)
Make a matrix from a vector V.Vt.
double Trace() const
Trace of a square matrix.
void AddMultABt(const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &ABt)
ABt += A * B^t.
DenseTensor(int i, int j, int k)
void MultAAt(const DenseMatrix &a, DenseMatrix &aat)
Calculate the matrix A.At.
void GetColumnReference(int c, Vector &col)
void AddMatrix(DenseMatrix &A, int ro, int co)
Perform (ro+i,co+j)+=A(i,j) for 0<=i<A.Height, 0<=j<A.Width.
DenseMatrix(double *d, int h, int w)
void Clear()
Delete the matrix data array (if owned) and reset the matrix state.
void CalcInverseTranspose(const DenseMatrix &a, DenseMatrix &inva)
Calculate the inverse transpose of a matrix (for NxN matrices, N=1,2,3)
void SetDataAndSize(double *d, int s)
Set the Vector data and size.
void MultADAt(const DenseMatrix &A, const Vector &D, DenseMatrix &ADAt)
ADAt = A D A^t, where D is diagonal.
int height
Dimension of the output / number of rows in the matrix.
virtual void PrintT(std::ostream &out=mfem::out, int width_=4) const
Prints the transpose matrix to stream out.
void CopyCols(const DenseMatrix &A, int col1, int col2)
Copy columns col1 through col2 from A to *this.
virtual MatrixInverse * Inverse() const
Returns a pointer to the inverse matrix.
double * GetColumn(int col)
void AddMultADBt(const DenseMatrix &A, const Vector &D, const DenseMatrix &B, DenseMatrix &ADBt)
ADBt = A D B^t, where D is diagonal.
virtual ~DenseMatrix()
Destroys dense matrix.
void CopyMNt(const DenseMatrix &A, int row_offset, int col_offset)
Copy matrix A^t to the location in *this at row_offset, col_offset.
void AddMultTranspose(const Vector &x, Vector &y) const
y += A^t x
void CopyExceptMN(const DenseMatrix &A, int m, int n)
Copy All rows and columns except m and n from A.
void Diag(double c, int n)
Creates n x n diagonal matrix with diagonal elements c.
void Mult(int m, int n, double *X) const
static const int ipiv_base
void GradToCurl(DenseMatrix &curl)
DenseMatrixInverse()
Default constructor.
double CalcSingularvalue(const int i) const
Return the i-th singular value (decreasing order) of NxN matrix, N=1,2,3.
void GetRowSums(Vector &l) const
Compute the row sums of the DenseMatrix.
void CalcEigenvalues(double *lambda, double *vec) const
void Eigenvalues(Vector &ev, DenseMatrix &evect)
DenseMatrixEigensystem(DenseMatrix &m)
int Rank(double tol) const
LUFactors(double *data_, int *ipiv_)
void AddMult_a(double a, const Vector &x, Vector &y) const
y += a * A.x
void RightScaling(const Vector &s)
RightScaling: this = this * diag(s);.
DenseTensor(const DenseTensor &other)
Copy constructor: deep copy.
void MultAtB(const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &AtB)
Multiply the transpose of a matrix A with a matrix B: At*B.
void Mult(const double *x, double *y) const
Matrix vector multiplication.
void AddMultTranspose_a(double a, const Vector &x, Vector &y) const
y += a * A^t x
void AddMultADAt(const DenseMatrix &A, const Vector &D, DenseMatrix &ADAt)
ADAt += A D A^t, where D is diagonal.
void GetFromVector(int offset, const Vector &v)
Get the matrix 'data' from the Vector 'v' at the given 'offset'.
void CopyMN(const DenseMatrix &A, int m, int n, int Aro, int Aco)
Copy the m x n submatrix of A at row/col offsets Aro/Aco to *this.
void InvLeftScaling(const Vector &s)
InvLeftScaling this = diag(1./s) * this.
void UseExternalData(double *d, int h, int w)
Change the data array and the size of the DenseMatrix.
void SetCol(int c, const Vector &col)
void Eigensystem(Vector &ev, DenseMatrix &evect)
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
int Size() const
Get the size of the inverse matrix.
Vector & Singularvalues()
Rank 3 tensor (array of matrices)
double InnerProduct(const Vector &x, const Vector &y) const
Compute y^t A x.
double FNorm2() const
Compute the square of the Frobenius norm of the matrix.
virtual double & Elem(int i, int j)
Returns reference to a_{ij}.
void AdjustDofDirection(Array< int > &dofs)
void GradToDiv(Vector &div)
void AddMult_a_AAt(double a, const DenseMatrix &A, DenseMatrix &AAt)
AAt += a * A * A^t.
int width
Dimension of the input / number of columns in the matrix.
virtual void PrintMatlab(std::ostream &out=mfem::out) const
DenseMatrix & operator+=(const double *m)