19 #include "../general/table.hpp"
20 #include "../general/globals.hpp"
27 #if defined(_MSC_VER) && (_MSC_VER < 1800)
29 #define copysign _copysign
33 #ifdef MFEM_USE_LAPACK
35 dgemm_(
char *,
char *,
int *,
int *,
int *,
double *,
double *,
36 int *,
double *,
int *,
double *,
double *,
int *);
38 dgetrf_(
int *,
int *,
double *,
int *,
int *,
int *);
40 dgetrs_(
char *,
int *,
int *,
double *,
int *,
int *,
double *,
int *,
int *);
42 dgetri_(
int *N,
double *A,
int *LDA,
int *IPIV,
double *WORK,
43 int *LWORK,
int *INFO);
45 dsyevr_(
char *JOBZ,
char *RANGE,
char *UPLO,
int *N,
double *A,
int *LDA,
46 double *VL,
double *VU,
int *IL,
int *IU,
double *ABSTOL,
int *M,
47 double *W,
double *Z,
int *LDZ,
int *ISUPPZ,
double *WORK,
int *LWORK,
48 int *IWORK,
int *LIWORK,
int *INFO);
50 dsyev_(
char *JOBZ,
char *UPLO,
int *N,
double *A,
int *LDA,
double *W,
51 double *WORK,
int *LWORK,
int *INFO);
53 dgesvd_(
char *JOBU,
char *JOBVT,
int *M,
int *N,
double *A,
int *LDA,
54 double *S,
double *U,
int *LDU,
double *VT,
int *LDVT,
double *WORK,
55 int *LWORK,
int *INFO);
75 MFEM_ASSERT(m.data,
"invalid source matrix");
76 data =
new double[hw];
78 std::memcpy(data, m.data,
sizeof(
double)*hw);
89 MFEM_ASSERT(s >= 0,
"invalid DenseMatrix size: " << s);
93 data =
new double[capacity]();
103 MFEM_ASSERT(m >= 0 && n >= 0,
104 "invalid DenseMatrix size: " << m <<
" x " << n);
108 data =
new double[capacity]();
117 :
Matrix(mat.width, mat.height)
122 data =
new double[capacity];
124 for (
int i = 0; i <
height; i++)
125 for (
int j = 0; j <
width; j++)
127 (*this)(i,j) = mat(j,i);
138 MFEM_ASSERT(h >= 0 && w >= 0,
139 "invalid DenseMatrix size: " << h <<
" x " << w);
147 if (hw > std::abs(capacity))
154 data =
new double[hw]();
172 for (
int row = 0; row <
height; row++)
178 double *d_col = data;
180 for (
int row = 0; row <
height; row++)
182 y[row] = x_col*d_col[row];
185 for (
int col = 1; col <
width; col++)
188 for (
int row = 0; row <
height; row++)
190 y[row] += x_col*d_col[row];
199 "incompatible dimensions");
201 Mult((
const double *)x, (
double *)y);
207 "incompatible dimensions");
211 for (
int i = 0; i < hw; i++)
213 a += data[i] * m.data[i];
221 double *d_col = data;
222 for (
int col = 0; col <
width; col++)
225 for (
int row = 0; row <
height; row++)
227 y_col += x[row]*d_col[row];
237 "incompatible dimensions");
245 "incompatible dimensions");
247 const double *xp = x;
248 double *d_col = data, *yp = y;
249 for (
int col = 0; col <
width; col++)
251 double x_col = xp[col];
252 for (
int row = 0; row <
height; row++)
254 yp[row] += x_col*d_col[row];
263 "incompatible dimensions");
265 double *d_col = data;
266 for (
int col = 0; col <
width; col++)
269 for (
int row = 0; row <
height; row++)
271 y_col += x[row]*d_col[row];
281 "incompatible dimensions");
283 const double *xp = x;
284 double *d_col = data, *yp = y;
285 for (
int col = 0; col <
width; col++)
287 double x_col = a*xp[col];
288 for (
int row = 0; row <
height; row++)
290 yp[row] += x_col*d_col[row];
300 "incompatible dimensions");
302 double *d_col = data;
303 for (
int col = 0; col <
width; col++)
306 for (
int row = 0; row <
height; row++)
308 y_col += x[row]*d_col[row];
319 for (
int i = 0; i <
height; i++)
322 for (
int j = 0; j <
width; j++)
324 Axi += (*this)(i,j) * x[j];
335 double * it_data = data;
336 for (
int j = 0; j <
width; ++j)
337 for (
int i = 0; i <
height; ++i)
339 *(it_data++) *= s(i);
346 double * it_data = data;
347 for (
int j = 0; j <
width; ++j)
348 for (
int i = 0; i <
height; ++i)
350 *(it_data++) /= s(i);
358 double * it_data = data;
359 for (
int j = 0; j <
width; ++j)
362 for (
int i = 0; i <
height; ++i)
373 double * it_data = data;
374 for (
int j = 0; j <
width; ++j)
377 for (
int i = 0; i <
height; ++i)
392 double * ss =
new double[
width];
395 for (
double * end_s = it_s +
width; it_s != end_s; ++it_s)
397 *(it_ss++) = sqrt(*it_s);
400 double * it_data = data;
401 for (
int j = 0; j <
width; ++j)
402 for (
int i = 0; i <
height; ++i)
404 *(it_data++) *= ss[i]*ss[j];
418 double * ss =
new double[
width];
421 for (
double * end_s = it_s +
width; it_s != end_s; ++it_s)
423 *(it_ss++) = 1./sqrt(*it_s);
426 double * it_data = data;
427 for (
int j = 0; j <
width; ++j)
428 for (
int i = 0; i <
height; ++i)
430 *(it_data++) *= ss[i]*ss[j];
441 mfem_error(
"DenseMatrix::Trace() : not a square matrix!");
447 for (
int i = 0; i <
width; i++)
463 "The matrix must be square and "
464 <<
"sized larger than zero to compute the determinant."
465 <<
" Height() = " <<
Height()
466 <<
", Width() = " <<
Width());
474 return data[0] * data[3] - data[1] * data[2];
478 const double *d = data;
480 d[0] * (d[4] * d[8] - d[5] * d[7]) +
481 d[3] * (d[2] * d[7] - d[1] * d[8]) +
482 d[6] * (d[1] * d[5] - d[2] * d[4]);
486 const double *d = data;
488 d[ 0] * (d[ 5] * (d[10] * d[15] - d[11] * d[14]) -
489 d[ 9] * (d[ 6] * d[15] - d[ 7] * d[14]) +
490 d[13] * (d[ 6] * d[11] - d[ 7] * d[10])
492 d[ 4] * (d[ 1] * (d[10] * d[15] - d[11] * d[14]) -
493 d[ 9] * (d[ 2] * d[15] - d[ 3] * d[14]) +
494 d[13] * (d[ 2] * d[11] - d[ 3] * d[10])
496 d[ 8] * (d[ 1] * (d[ 6] * d[15] - d[ 7] * d[14]) -
497 d[ 5] * (d[ 2] * d[15] - d[ 3] * d[14]) +
498 d[13] * (d[ 2] * d[ 7] - d[ 3] * d[ 6])
500 d[12] * (d[ 1] * (d[ 6] * d[11] - d[ 7] * d[10]) -
501 d[ 5] * (d[ 2] * d[11] - d[ 3] * d[10]) +
502 d[ 9] * (d[ 2] * d[ 7] - d[ 3] * d[ 6])
511 return lu_factors.
Det();
526 return sqrt(data[0] * data[0] + data[1] * data[1]);
530 return sqrt(data[0] * data[0] + data[1] * data[1] + data[2] * data[2]);
534 const double *d = data;
535 double E = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
536 double G = d[3] * d[3] + d[4] * d[4] + d[5] * d[5];
537 double F = d[0] * d[3] + d[1] * d[4] + d[2] * d[5];
538 return sqrt(E * G - F * F);
547 for (
int i = 0; i < s; i++)
549 data[i] = alpha*A[i];
555 for (
int j = 0; j <
Width(); j++)
556 for (
int i = 0; i <
Height(); i++)
558 (*this)(i,j) += c * A(i,j);
565 for (
int i = 0; i < s; i++)
575 for (
int i = 0; i < s; i++)
587 for (
int i = 0; i < hw; i++)
598 for (
int i = 0; i < hw; i++)
608 "incompatible matrix sizes.");
614 for (
int j = 0; j <
width; j++)
615 for (
int i = 0; i <
height; i++)
617 (*this)(i, j) -= m(i, j);
626 for (
int i = 0; i < s; i++)
636 for (
int i = 0; i < hw; i++)
651 #ifdef MFEM_USE_LAPACK
652 int *ipiv =
new int[
width];
661 mfem_error(
"DenseMatrix::Invert() : Error in DGETRF");
667 work =
new double[lwork];
673 mfem_error(
"DenseMatrix::Invert() : Error in DGETRI");
679 int c, i, j, n =
Width();
683 for (c = 0; c < n; c++)
685 a = fabs((*
this)(c, c));
687 for (j = c + 1; j < n; j++)
689 b = fabs((*
this)(j, c));
698 mfem_error(
"DenseMatrix::Invert() : singular matrix");
701 for (j = 0; j < n; j++)
703 Swap<double>((*this)(c, j), (*
this)(i, j));
706 a = (*this)(c, c) = 1.0 / (*
this)(c, c);
707 for (j = 0; j < c; j++)
711 for (j++; j < n; j++)
715 for (i = 0; i < c; i++)
717 (*this)(i, c) = a * (b = -(*
this)(i, c));
718 for (j = 0; j < c; j++)
720 (*this)(i, j) += b * (*
this)(c, j);
722 for (j++; j < n; j++)
724 (*this)(i, j) += b * (*
this)(c, j);
727 for (i++; i < n; i++)
729 (*this)(i, c) = a * (b = -(*
this)(i, c));
730 for (j = 0; j < c; j++)
732 (*this)(i, j) += b * (*
this)(c, j);
734 for (j++; j < n; j++)
736 (*this)(i, j) += b * (*
this)(c, j);
741 for (c = n - 1; c >= 0; c--)
744 for (i = 0; i < n; i++)
746 Swap<double>((*this)(i, c), (*
this)(i, j));
758 mfem_error(
"DenseMatrix::SquareRootInverse() matrix not square.");
768 for (
int v = 0; v <
Height() ; v++) { (*this)(v,v) = 1.0; }
770 for (
int j = 0; j < 10; j++)
772 for (
int i = 0; i < 10; i++)
787 for (
int v = 0; v <
Height() ; v++) { tmp2(v,v) -= 1.0; }
788 if (tmp2.FNorm() < 1e-10) {
break; }
791 if (tmp2.FNorm() > 1e-10)
793 mfem_error(
"DenseMatrix::SquareRootInverse not converged");
799 for (
int j = 0; j <
Width(); j++)
802 for (
int i = 0; i <
Height(); i++)
804 v[j] += (*this)(i,j)*(*
this)(i,j);
813 const double *d = data;
814 double norm = 0.0, abs_entry;
816 for (
int i = 0; i < hw; i++)
818 abs_entry = fabs(d[i]);
819 if (norm < abs_entry)
831 double max_norm = 0.0, entry, fnorm2;
833 for (i = 0; i < hw; i++)
835 entry = fabs(data[i]);
836 if (entry > max_norm)
844 scale_factor = scaled_fnorm2 = 0.0;
849 for (i = 0; i < hw; i++)
851 entry = data[i] / max_norm;
852 fnorm2 += entry * entry;
855 scale_factor = max_norm;
856 scaled_fnorm2 = fnorm2;
862 #ifdef MFEM_USE_LAPACK
870 double *A =
new double[N*N];
881 int *ISUPPZ =
new int[2*N];
900 double *data = a.
Data();
902 for (
int i = 0; i < hw; i++)
907 dsyevr_( &JOBZ, &RANGE, &UPLO, &N, A, &LDA, &VL, &VU, &IL, &IU,
908 &ABSTOL, &M, W, Z, &LDZ, ISUPPZ, &QWORK, &LWORK,
909 &QIWORK, &LIWORK, &INFO );
914 WORK =
new double[LWORK];
915 IWORK =
new int[LIWORK];
917 dsyevr_( &JOBZ, &RANGE, &UPLO, &N, A, &LDA, &VL, &VU, &IL, &IU,
918 &ABSTOL, &M, W, Z, &LDZ, ISUPPZ, WORK, &LWORK,
919 IWORK, &LIWORK, &INFO );
923 mfem::err <<
"dsyevr_Eigensystem(...): DSYEVR error code: "
931 mfem::err <<
"dsyevr_Eigensystem(...):\n"
932 <<
" DSYEVR did not find all eigenvalues "
933 << M <<
"/" << N << endl;
938 mfem_error(
"dsyevr_Eigensystem(...): inf/nan values in W");
942 mfem_error(
"dsyevr_Eigensystem(...): inf/nan values in Z");
945 for (IL = 0; IL < N; IL++)
946 for (IU = 0; IU <= IL; IU++)
949 for (M = 0; M < N; M++)
951 VL += Z[M+IL*N] * Z[M+IU*N];
968 <<
" Z^t Z - I deviation = " << VU
969 <<
"\n W[max] = " << W[N-1] <<
", W[min] = "
970 << W[0] <<
", N = " << N << endl;
977 <<
" Z^t Z - I deviation = " << VU
978 <<
"\n W[max] = " << W[N-1] <<
", W[min] = "
979 << W[0] <<
", N = " << N << endl;
983 mfem_error(
"dsyevr_Eigensystem(...): ERROR: ...");
986 for (IL = 0; IL < N; IL++)
987 for (IU = 0; IU < N; IU++)
990 for (M = 0; M < N; M++)
992 VL += Z[IL+M*N] * W[M] * Z[IU+M*N];
994 VL = fabs(VL-data[IL+N*IU]);
1003 <<
" max matrix deviation = " << VU
1004 <<
"\n W[max] = " << W[N-1] <<
", W[min] = "
1005 << W[0] <<
", N = " << N << endl;
1009 mfem_error(
"dsyevr_Eigensystem(...): ERROR: ...");
1024 #ifdef MFEM_USE_LAPACK
1037 double *WORK = NULL;
1048 A =
new double[N*N];
1052 double *data = a.
Data();
1053 for (
int i = 0; i < hw; i++)
1058 dsyev_(&JOBZ, &UPLO, &N, A, &LDA, W, &QWORK, &LWORK, &INFO);
1060 LWORK = (int) QWORK;
1061 WORK =
new double[LWORK];
1063 dsyev_(&JOBZ, &UPLO, &N, A, &LDA, W, WORK, &LWORK, &INFO);
1067 mfem::err <<
"dsyev_Eigensystem: DSYEV error code: " << INFO << endl;
1072 if (evect == NULL) {
delete [] A; }
1077 void DenseMatrix::Eigensystem(Vector &ev, DenseMatrix *evect)
1079 #ifdef MFEM_USE_LAPACK
1094 #ifdef MFEM_USE_LAPACK
1100 double *a = copy_of_this.data;
1105 double *work = NULL;
1110 dgesvd_(&jobu, &jobvt, &m, &n, a, &m,
1111 s, u, &m, vt, &n, &qwork, &lwork, &info);
1113 lwork = (int) qwork;
1114 work =
new double[lwork];
1116 dgesvd_(&jobu, &jobvt, &m, &n, a, &m,
1117 s, u, &m, vt, &n, work, &lwork, &info);
1122 mfem::err <<
"DenseMatrix::SingularValues : info = " << info << endl;
1137 for (
int i=0; i < sv.
Size(); ++i)
1153 double t, zeta = (d2 - d1)/(2*d12);
1154 if (fabs(zeta) < sqrt_1_eps)
1156 t = d12*copysign(1./(fabs(zeta) + sqrt(1. + zeta*zeta)), zeta);
1160 t = d12*copysign(0.5/fabs(zeta), zeta);
1168 double &c,
double &s)
1178 double t, zeta = (d2 - d1)/(2*d12);
1179 if (fabs(zeta) < sqrt_1_eps)
1181 t = copysign(1./(fabs(zeta) + sqrt(1. + zeta*zeta)), zeta);
1185 t = copysign(0.5/fabs(zeta), zeta);
1188 c = sqrt(1./(1. + t*t));
1197 const double &x1,
const double &x2,
const double &x3,
1198 double &n1,
double &n2,
double &n3)
1206 t = sqrt(1./(t + r*r));
1207 n1 = copysign(t, x1);
1214 double &n1,
double &n2,
double &n3)
1218 if (fabs(x1) >= fabs(x2))
1220 if (fabs(x1) >= fabs(x3))
1233 else if (fabs(x2) >= fabs(x3))
1243 double &d1,
double &d12,
double &d21,
double &d2)
1254 double n1 = fabs(d1) + fabs(d21);
1255 double n2 = fabs(d2) + fabs(d12);
1257 bool swap_columns = (n2 > n1);
1269 if (fabs(d1) > fabs(d21))
1277 if (fabs(d1) < fabs(d21))
1289 if (fabs(d12) > fabs(d2))
1302 if (fabs(d12) < fabs(d2))
1315 n1 = hypot(d1, d21);
1321 mu = copysign(n1, d1);
1322 n1 = -d21*(d21/(d1 + mu));
1326 if (fabs(n1) <= fabs(d21))
1330 mu = (2./(1. + n1*n1))*(n1*d12 + d2);
1338 mu = (2./(1. + n2*n2))*(d12 + n2*d2);
1360 n2 = 1./(1. + fabs(mu));
1362 if (fabs(d1) <= n2*fabs(d2))
1384 double &d1,
double &d2,
double &d3,
double &c12,
double &c13,
double &c23,
1385 double &c21,
double &c31,
double &c32)
1388 double mu, n1, n2, n3, s1, s2, s3;
1390 s1 = hypot(c21, c31);
1397 mu = copysign(n1, d1);
1398 n1 = -s1*(s1/(d1 + mu));
1403 if (fabs(n1) >= fabs(c21))
1405 if (fabs(n1) >= fabs(c31))
1410 mu = 2./(1. + s2*s2 + s3*s3);
1411 n2 = mu*(c12 + s2*d2 + s3*c32);
1412 n3 = mu*(c13 + s2*c23 + s3*d3);
1422 else if (fabs(c21) >= fabs(c31))
1427 mu = 2./(1. + s1*s1 + s3*s3);
1428 n2 = mu*(s1*c12 + d2 + s3*c32);
1429 n3 = mu*(s1*c13 + c23 + s3*d3);
1441 mu = 2./(1. + s1*s1 + s2*s2);
1442 n2 = mu*(s1*c12 + s2*d2 + c32);
1443 n3 = mu*(s1*c13 + s2*c23 + d3);
1478 d1 = -(c12*d2 + c13*d3)/d1;
1489 const double &d12,
const double &d13,
const double &d23,
1490 double &d1,
double &d2,
double &d3)
1503 double c12 = d12, c13 = d13, c23 = d23;
1504 double c21, c31, c32;
1508 c32 = fabs(d1) + fabs(c12) + fabs(c13);
1509 c31 = fabs(d2) + fabs(c12) + fabs(c23);
1510 c21 = fabs(d3) + fabs(c13) + fabs(c23);
1515 col = (c32 >= c31) ? 1 : 2;
1519 col = (c31 >= c21) ? 2 : 3;
1551 if (fabs(d1) <= fabs(c13))
1553 row = (fabs(d1) <= fabs(c12)) ? 1 : 2;
1557 row = (fabs(c12) <= fabs(c13)) ? 2 : 3;
1562 if (fabs(d1) >= fabs(c13))
1564 row = (fabs(d1) >= fabs(c12)) ? 1 : 2;
1568 row = (fabs(c12) >= fabs(c13)) ? 2 : 3;
1618 double &d1,
double &d2,
double &d3,
double &d12,
double &d13,
double &d23,
1619 double &z1,
double &z2,
double &z3,
double &v1,
double &v2,
double &v3,
1639 double s, w1, w2, w3;
1645 if (fabs(z1) <= fabs(z3))
1647 k = (fabs(z1) <= fabs(z2)) ? 1 : 2;
1651 k = (fabs(z2) <= fabs(z3)) ? 2 : 3;
1657 if (fabs(z1) >= fabs(z3))
1659 k = (fabs(z1) >= fabs(z2)) ? 1 : 2;
1663 k = (fabs(z2) >= fabs(z3)) ? 2 : 3;
1690 g = copysign(1., z1);
1691 v1 = -s*(s/(z1 + g));
1694 if (fabs(z2) > g) { g = fabs(z2); }
1695 if (fabs(z3) > g) { g = fabs(z3); }
1699 g = 2./(v1*v1 + v2*v2 + v3*v3);
1704 w1 = g*( d1*v1 + d12*v2 + d13*v3);
1705 w2 = g*(d12*v1 + d2*v2 + d23*v3);
1706 w3 = g*(d13*v1 + d23*v2 + d3*v3);
1708 s = (g/2)*(v1*w1 + v2*w2 + v3*w3);
1715 d23 -= v2*w3 + v3*w2;
1720 s = d12 - v1*w2 - v2*w1;
1721 s = d13 - v1*w3 - v3*w1;
1743 mult = frexp(d_max, &d_exp);
1744 if (d_exp == numeric_limits<double>::max_exponent)
1746 mult *= numeric_limits<double>::radix;
1761 "The matrix must be square and sized 1, 2, or 3 to compute the"
1763 <<
" Height() = " <<
Height()
1764 <<
", Width() = " <<
Width());
1767 const double *d = data;
1775 double d0, d1, d2, d3;
1782 double d_max = fabs(d0);
1783 if (d_max < fabs(d1)) { d_max = fabs(d1); }
1784 if (d_max < fabs(d2)) { d_max = fabs(d2); }
1785 if (d_max < fabs(d3)) { d_max = fabs(d3); }
1799 double t = 0.5*((d0+d2)*(d0-d2)+(d1-d3)*(d1+d3));
1801 double s = d0*d2 + d1*d3;
1802 s = sqrt(0.5*(d0*d0 + d1*d1 + d2*d2 + d3*d3) + sqrt(t*t + s*s));
1807 t = fabs(d0*d3 - d1*d2) / s;
1824 double d0, d1, d2, d3, d4, d5, d6, d7, d8;
1825 d0 = d[0]; d3 = d[3]; d6 = d[6];
1826 d1 = d[1]; d4 = d[4]; d7 = d[7];
1827 d2 = d[2]; d5 = d[5]; d8 = d[8];
1830 double d_max = fabs(d0);
1831 if (d_max < fabs(d1)) { d_max = fabs(d1); }
1832 if (d_max < fabs(d2)) { d_max = fabs(d2); }
1833 if (d_max < fabs(d3)) { d_max = fabs(d3); }
1834 if (d_max < fabs(d4)) { d_max = fabs(d4); }
1835 if (d_max < fabs(d5)) { d_max = fabs(d5); }
1836 if (d_max < fabs(d6)) { d_max = fabs(d6); }
1837 if (d_max < fabs(d7)) { d_max = fabs(d7); }
1838 if (d_max < fabs(d8)) { d_max = fabs(d8); }
1843 d0 /= mult; d1 /= mult; d2 /= mult;
1844 d3 /= mult; d4 /= mult; d5 /= mult;
1845 d6 /= mult; d7 /= mult; d8 /= mult;
1847 double b11 = d0*d0 + d1*d1 + d2*d2;
1848 double b12 = d0*d3 + d1*d4 + d2*d5;
1849 double b13 = d0*d6 + d1*d7 + d2*d8;
1850 double b22 = d3*d3 + d4*d4 + d5*d5;
1851 double b23 = d3*d6 + d4*d7 + d5*d8;
1852 double b33 = d6*d6 + d7*d7 + d8*d8;
1871 double aa = (b11 + b22 + b33)/3;
1877 double b11_b22 = ((d0-d3)*(d0+d3)+(d1-d4)*(d1+d4)+(d2-d5)*(d2+d5));
1878 double b22_b33 = ((d3-d6)*(d3+d6)+(d4-d7)*(d4+d7)+(d5-d8)*(d5+d8));
1879 double b33_b11 = ((d6-d0)*(d6+d0)+(d7-d1)*(d7+d1)+(d8-d2)*(d8+d2));
1880 c1 = (b11_b22 - b33_b11)/3;
1881 c2 = (b22_b33 - b11_b22)/3;
1882 c3 = (b33_b11 - b22_b33)/3;
1885 Q = (2*(b12*b12 + b13*b13 + b23*b23) + c1*c1 + c2*c2 + c3*c3)/6;
1886 R = (c1*(b23*b23 - c2*c3)+ b12*(b12*c3 - 2*b13*b23) +b13*b13*c2)/2;
1919 double sqrtQ = sqrt(Q);
1920 double sqrtQ3 = Q*sqrtQ;
1925 if (fabs(R) >= sqrtQ3)
1947 aa -= 2*sqrtQ*cos(acos(R)/3);
1951 aa -= 2*sqrtQ*cos((acos(R) + 2.0*M_PI)/3);
1955 aa -= 2*sqrtQ*cos((acos(R) - 2.0*M_PI)/3);
1962 r = -2*sqrtQ*cos((acos(R) + 2.0*M_PI)/3);
1971 r = -2*sqrtQ*cos(acos(R)/3);
2018 double v1, v2, v3, g;
2019 Reduce3S(mode, b11, b22, b33, b12, b13, b23,
2020 c1, c2, c3, v1, v2, v3, g);
2031 aa = std::min(std::min(b11, b22), b33);
2037 aa = (b22 <= b33) ? b22 : std::max(b11, b33);
2041 aa = (b11 <= b33) ? b11 : std::max(b33, b22);
2046 aa = std::max(std::max(b11, b22), b33);
2052 return sqrt(fabs(aa))*mult;
2066 const double *d = data;
2106 double d_max = fabs(d11);
2107 if (d_max < fabs(d22)) { d_max = fabs(d22); }
2108 if (d_max < fabs(d33)) { d_max = fabs(d33); }
2109 if (d_max < fabs(d12)) { d_max = fabs(d12); }
2110 if (d_max < fabs(d13)) { d_max = fabs(d13); }
2111 if (d_max < fabs(d23)) { d_max = fabs(d23); }
2116 d11 /= mult; d22 /= mult; d33 /= mult;
2117 d12 /= mult; d13 /= mult; d23 /= mult;
2119 double aa = (d11 + d22 + d33)/3;
2120 double c1 = d11 - aa;
2121 double c2 = d22 - aa;
2122 double c3 = d33 - aa;
2126 Q = (2*(d12*d12 + d13*d13 + d23*d23) + c1*c1 + c2*c2 + c3*c3)/6;
2127 R = (c1*(d23*d23 - c2*c3)+ d12*(d12*c3 - 2*d13*d23) + d13*d13*c2)/2;
2131 lambda[0] = lambda[1] = lambda[2] = aa;
2132 vec[0] = 1.; vec[3] = 0.; vec[6] = 0.;
2133 vec[1] = 0.; vec[4] = 1.; vec[7] = 0.;
2134 vec[2] = 0.; vec[5] = 0.; vec[8] = 1.;
2138 double sqrtQ = sqrt(Q);
2139 double sqrtQ3 = Q*sqrtQ;
2143 if (fabs(R) >= sqrtQ3)
2162 r = -2*sqrtQ*cos((acos(R) + 2.0*M_PI)/3);
2166 r = -2*sqrtQ*cos(acos(R)/3);
2194 lambda[0] = lambda[1] = lambda[2] = aa;
2195 vec[0] = 1.; vec[3] = 0.; vec[6] = 0.;
2196 vec[1] = 0.; vec[4] = 1.; vec[7] = 0.;
2197 vec[2] = 0.; vec[5] = 0.; vec[8] = 1.;
2211 double v1, v2, v3, g;
2212 int k =
Reduce3S(mode, d11, d22, d33, d12, d13, d23,
2213 c1, c2, c3, v1, v2, v3, g);
2224 double *vec_1, *vec_2, *vec_3;
2229 lambda[0] = d11; vec_1 = vec;
2230 lambda[1] = d22; vec_2 = vec + 3;
2231 lambda[2] = d33; vec_3 = vec + 6;
2233 else if (d11 <= d33)
2235 lambda[0] = d11; vec_1 = vec;
2236 lambda[1] = d33; vec_3 = vec + 3;
2237 lambda[2] = d22; vec_2 = vec + 6;
2241 lambda[0] = d33; vec_3 = vec;
2242 lambda[1] = d11; vec_1 = vec + 3;
2243 lambda[2] = d22; vec_2 = vec + 6;
2250 lambda[0] = d22; vec_2 = vec;
2251 lambda[1] = d11; vec_1 = vec + 3;
2252 lambda[2] = d33; vec_3 = vec + 6;
2254 else if (d22 <= d33)
2256 lambda[0] = d22; vec_2 = vec;
2257 lambda[1] = d33; vec_3 = vec + 3;
2258 lambda[2] = d11; vec_1 = vec + 6;
2262 lambda[0] = d33; vec_3 = vec;
2263 lambda[1] = d22; vec_2 = vec + 3;
2264 lambda[2] = d11; vec_1 = vec + 6;
2271 d22 = g*(v2*c - v3*s);
2272 d33 = g*(v2*s + v3*c);
2273 vec_2[0] = - v1*d22; vec_3[0] = - v1*d33;
2274 vec_2[1] = c - v2*d22; vec_3[1] = s - v2*d33;
2275 vec_2[2] = -s - v3*d22; vec_3[2] = c - v3*d33;
2279 Swap(vec_2[0], vec_2[1]);
2280 Swap(vec_3[0], vec_3[1]);
2284 Swap(vec_2[0], vec_2[2]);
2285 Swap(vec_3[0], vec_3[2]);
2302 const double* rp = data + r;
2305 for (
int i = 0; i < n; i++)
2317 double *cp = data + c * m;
2320 for (
int i = 0; i < m; i++)
2334 for (
int i = 0; i <
height; ++i)
2336 d(i) = (*this)(i,i);
2350 for (
int j = 0; j <
width; ++j)
2351 for (
int i = 0; i <
height; ++i)
2353 l(i) += fabs((*
this)(i,j));
2360 for (
int i = 0; i <
height; i++)
2363 for (
int j = 0; j <
width; j++)
2376 for (i = 0; i < N; i++)
2380 for (i = 0; i < n; i++)
2391 for (i = 0; i < N; i++)
2395 for (i = 0; i < n; i++)
2397 data[i*(n+1)] = diag[i];
2408 for (i = 0; i <
Height(); i++)
2409 for (j = i+1; j <
Width(); j++)
2412 (*this)(i,j) = (*
this)(j,i);
2427 for (
int i = 0; i <
Height(); i++)
2428 for (
int j = 0; j <
Width(); j++)
2430 (*this)(i,j) = A(j,i);
2439 mfem_error(
"DenseMatrix::Symmetrize() : not a square matrix!");
2443 for (
int i = 0; i <
Height(); i++)
2444 for (
int j = 0; j < i; j++)
2446 double a = 0.5 * ((*this)(i,j) + (*
this)(j,i));
2447 (*this)(j,i) = (*
this)(i,j) = a;
2453 for (
int i = 0; i <
Height(); i++)
2456 for (
int j = 0; j <
Width(); j++)
2459 (*this)(i, j) = 0.0;
2479 for (
int i = 0; i < n; i++)
2482 double x = (*this)(i,0);
2483 double y = (*this)(i,1);
2496 for (
int i = 0; i < n; i++)
2499 double x = (*this)(i,0);
2500 double y = (*this)(i,1);
2501 double z = (*this)(i,2);
2537 double *ddata = div.
GetData();
2539 for (
int i = 0; i < n; i++)
2549 for (
int j = 0; j <
Width(); j++)
2550 for (
int i = row1; i <= row2; i++)
2552 (*this)(i-row1,j) = A(i,j);
2560 for (
int j = col1; j <= col2; j++)
2561 for (
int i = 0; i <
Height(); i++)
2563 (*this)(i,j-col1) = A(i,j);
2573 for (j = 0; j < n; j++)
2574 for (i = 0; i < m; i++)
2576 (*this)(i,j) = A(Aro+i,Aco+j);
2585 for (j = 0; j < A.
Width(); j++)
2586 for (i = 0; i < A.
Height(); i++)
2588 (*this)(row_offset+i,col_offset+j) = *(v++);
2597 for (i = 0; i < A.
Width(); i++)
2598 for (j = 0; j < A.
Height(); j++)
2600 (*this)(row_offset+i,col_offset+j) = *(v++);
2605 int row_offset,
int col_offset)
2609 MFEM_VERIFY(row_offset+m <= this->
Height() && col_offset+n <= this->
Width(),
2610 "this DenseMatrix is too small to accomodate the submatrix. "
2611 <<
"row_offset = " << row_offset
2613 <<
", this->Height() = " << this->
Height()
2614 <<
", col_offset = " << col_offset
2616 <<
", this->Width() = " << this->
Width()
2618 MFEM_VERIFY(Aro+m <= A.
Height() && Aco+n <= A.
Width(),
2619 "The A DenseMatrix is too small to accomodate the submatrix. "
2622 <<
", A.Height() = " << A.
Height()
2623 <<
", Aco = " << Aco
2625 <<
", A.Width() = " << A.
Width()
2628 for (j = 0; j < n; j++)
2629 for (i = 0; i < m; i++)
2631 (*this)(row_offset+i,col_offset+j) = A(Aro+i,Aco+j);
2639 for (i = 0; i < n; i++)
2640 for (j = i+1; j < n; j++)
2641 (*
this)(row_offset+i,col_offset+j) =
2642 (*
this)(row_offset+j,col_offset+i) = 0.0;
2644 for (i = 0; i < n; i++)
2646 (*this)(row_offset+i,col_offset+i) = c;
2655 for (i = 0; i < n; i++)
2656 for (j = i+1; j < n; j++)
2657 (*
this)(row_offset+i,col_offset+j) =
2658 (*
this)(row_offset+j,col_offset+i) = 0.0;
2660 for (i = 0; i < n; i++)
2662 (*this)(row_offset+i,col_offset+i) = diag[i];
2670 int i, j, i_off = 0, j_off = 0;
2672 for (j = 0; j < A.
Width(); j++)
2679 for (i = 0; i < A.
Height(); i++)
2686 (*this)(i-i_off,j-j_off) = A(i,j);
2702 if (co+aw >
Width() || ro+ah > h)
2708 p = data + ro + co * h;
2711 for (
int c = 0; c < aw; c++)
2713 for (
int r = 0; r < ah; r++)
2732 if (co+aw >
Width() || ro+ah > h)
2738 p = data + ro + co * h;
2741 for (
int c = 0; c < aw; c++)
2743 for (
int r = 0; r < ah; r++)
2755 double *vdata = v.
GetData() + offset;
2757 for (i = 0; i < n; i++)
2759 vdata[i] += data[i];
2766 const double *vdata = v.
GetData() + offset;
2768 for (i = 0; i < n; i++)
2781 mfem_error(
"DenseMatrix::AdjustDofDirection(...)");
2786 for (
int i = 0; i < n-1; i++)
2788 int s = (dof[i] < 0) ? (-1) : (1);
2789 for (
int j = i+1; j < n; j++)
2791 int t = (dof[j] < 0) ? (-s) : (s);
2794 (*this)(i,j) = -(*
this)(i,j);
2795 (*this)(j,i) = -(*
this)(j,i);
2803 for (
int j = 0; j <
Width(); j++)
2805 (*this)(row, j) = value;
2811 for (
int i = 0; i <
Height(); i++)
2813 (*this)(i, col) = value;
2819 for (
int j = 0; j <
Width(); j++)
2821 (*this)(r, j) = row[j];
2827 for (
int i = 0; i <
Height(); i++)
2829 (*this)(i, c) = col[i];
2835 for (
int col = 0; col <
Width(); col++)
2837 for (
int row = 0; row <
Height(); row++)
2839 if (std::abs(
operator()(row,col)) <= eps)
2850 ios::fmtflags old_flags = out.flags();
2852 out << setiosflags(ios::scientific | ios::showpos);
2853 for (
int i = 0; i <
height; i++)
2855 out <<
"[row " << i <<
"]\n";
2856 for (
int j = 0; j <
width; j++)
2858 out << (*this)(i,j);
2859 if (j+1 == width || (j+1) % width_ == 0)
2870 out.flags(old_flags);
2876 ios::fmtflags old_flags = out.flags();
2878 out << setiosflags(ios::scientific | ios::showpos);
2879 for (
int i = 0; i <
height; i++)
2881 for (
int j = 0; j <
width; j++)
2883 out << (*this)(i,j);
2889 out.flags(old_flags);
2895 ios::fmtflags old_flags = out.flags();
2897 out << setiosflags(ios::scientific | ios::showpos);
2898 for (
int j = 0; j <
width; j++)
2900 out <<
"[col " << j <<
"]\n";
2901 for (
int i = 0; i <
height; i++)
2903 out << (*this)(i,j);
2904 if (i+1 == height || (i+1) % width_ == 0)
2915 out.flags(old_flags);
2924 for (
int i = 0; i <
width; i++)
2929 <<
", cond_F = " <<
FNorm()*copy.FNorm() << endl;
2945 for (
int j = 0; j < C.
Width(); j++)
2946 for (
int i = 0; i < C.
Height(); i++)
2948 C(i,j) = A(i,j) + alpha * B(i,j);
2957 for (
int i = 0; i < m; i++)
2959 C_data[i] = alpha*A[i] + beta*B[i];
2977 b.
Width() == c.
Height(),
"incompatible dimensions");
2979 #ifdef MFEM_USE_LAPACK
2980 static char transa =
'N', transb =
'N';
2981 static double alpha = 1.0, beta = 0.0;
2984 dgemm_(&transa, &transb, &m, &n, &k, &alpha, b.
Data(), &m,
2985 c.
Data(), &k, &beta, a.
Data(), &m);
2987 const int ah = a.
Height();
2988 const int aw = a.
Width();
2989 const int bw = b.
Width();
2990 double *ad = a.
Data();
2991 const double *bd = b.
Data();
2992 const double *cd = c.
Data();
2993 for (
int i = 0; i < ah*aw; i++)
2997 for (
int j = 0; j < aw; j++)
2999 for (
int k = 0; k < bw; k++)
3001 for (
int i = 0; i < ah; i++)
3003 ad[i+j*ah] += bd[i+k*ah] * cd[k+j*bw];
3013 b.
Width() == c.
Height(),
"incompatible dimensions");
3015 #ifdef MFEM_USE_LAPACK
3016 static char transa =
'N', transb =
'N';
3017 static double alpha = 1.0, beta = 1.0;
3020 dgemm_(&transa, &transb, &m, &n, &k, &alpha, b.
Data(), &m,
3021 c.
Data(), &k, &beta, a.
Data(), &m);
3023 const int ah = a.
Height();
3024 const int aw = a.
Width();
3025 const int bw = b.
Width();
3026 double *ad = a.
Data();
3027 const double *bd = b.
Data();
3028 const double *cd = c.
Data();
3029 for (
int j = 0; j < aw; j++)
3031 for (
int k = 0; k < bw; k++)
3033 for (
int i = 0; i < ah; i++)
3035 ad[i+j*ah] += bd[i+k*ah] * cd[k+j*bw];
3057 const double *d = a.
Data();
3058 double *ad = adja.
Data();
3073 e = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
3074 g = d[3]*d[3] + d[4]*d[4] + d[5]*d[5];
3075 f = d[0]*d[3] + d[1]*d[4] + d[2]*d[5];
3077 ad[0] = d[0]*g - d[3]*f;
3078 ad[1] = d[3]*e - d[0]*f;
3079 ad[2] = d[1]*g - d[4]*f;
3080 ad[3] = d[4]*e - d[1]*f;
3081 ad[4] = d[2]*g - d[5]*f;
3082 ad[5] = d[5]*e - d[2]*f;
3091 else if (a.
Width() == 2)
3094 adja(0,1) = -a(0,1);
3095 adja(1,0) = -a(1,0);
3100 adja(0,0) = a(1,1)*a(2,2)-a(1,2)*a(2,1);
3101 adja(0,1) = a(0,2)*a(2,1)-a(0,1)*a(2,2);
3102 adja(0,2) = a(0,1)*a(1,2)-a(0,2)*a(1,1);
3104 adja(1,0) = a(1,2)*a(2,0)-a(1,0)*a(2,2);
3105 adja(1,1) = a(0,0)*a(2,2)-a(0,2)*a(2,0);
3106 adja(1,2) = a(0,2)*a(1,0)-a(0,0)*a(1,2);
3108 adja(2,0) = a(1,0)*a(2,1)-a(1,1)*a(2,0);
3109 adja(2,1) = a(0,1)*a(2,0)-a(0,0)*a(2,1);
3110 adja(2,2) = a(0,0)*a(1,1)-a(0,1)*a(1,0);
3127 else if (a.
Width() == 2)
3129 adjat(0,0) = a(1,1);
3130 adjat(1,0) = -a(0,1);
3131 adjat(0,1) = -a(1,0);
3132 adjat(1,1) = a(0,0);
3136 adjat(0,0) = a(1,1)*a(2,2)-a(1,2)*a(2,1);
3137 adjat(1,0) = a(0,2)*a(2,1)-a(0,1)*a(2,2);
3138 adjat(2,0) = a(0,1)*a(1,2)-a(0,2)*a(1,1);
3140 adjat(0,1) = a(1,2)*a(2,0)-a(1,0)*a(2,2);
3141 adjat(1,1) = a(0,0)*a(2,2)-a(0,2)*a(2,0);
3142 adjat(2,1) = a(0,2)*a(1,0)-a(0,0)*a(1,2);
3144 adjat(0,2) = a(1,0)*a(2,1)-a(1,1)*a(2,0);
3145 adjat(1,2) = a(0,1)*a(2,0)-a(0,0)*a(2,1);
3146 adjat(2,2) = a(0,0)*a(1,1)-a(0,1)*a(1,0);
3153 MFEM_ASSERT(inva.
Height() == a.
Width(),
"incorrect dimensions");
3154 MFEM_ASSERT(inva.
Width() == a.
Height(),
"incorrect dimensions");
3160 const double *d = a.
Data();
3161 double *
id = inva.
Data();
3164 t = 1.0 / (d[0]*d[0] + d[1]*d[1]);
3172 t = 1.0 / (d[0]*d[0] + d[1]*d[1] + d[2]*d[2]);
3180 e = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
3181 g = d[3]*d[3] + d[4]*d[4] + d[5]*d[5];
3182 f = d[0]*d[3] + d[1]*d[4] + d[2]*d[5];
3183 t = 1.0 / (e*g - f*f);
3184 e *= t; g *= t; f *= t;
3186 id[0] = d[0]*g - d[3]*f;
3187 id[1] = d[3]*e - d[0]*f;
3188 id[2] = d[1]*g - d[4]*f;
3189 id[3] = d[4]*e - d[1]*f;
3190 id[4] = d[2]*g - d[5]*f;
3191 id[5] = d[5]*e - d[2]*f;
3199 MFEM_ASSERT(std::abs(t) > 1.0e-14 * pow(a.FNorm()/a.
Width(), a.
Width()),
3200 "singular matrix!");
3212 inva(0,0) = a(1,1) * t ;
3213 inva(0,1) = -a(0,1) * t ;
3214 inva(1,0) = -a(1,0) * t ;
3215 inva(1,1) = a(0,0) * t ;
3218 inva(0,0) = (a(1,1)*a(2,2)-a(1,2)*a(2,1))*t;
3219 inva(0,1) = (a(0,2)*a(2,1)-a(0,1)*a(2,2))*t;
3220 inva(0,2) = (a(0,1)*a(1,2)-a(0,2)*a(1,1))*t;
3222 inva(1,0) = (a(1,2)*a(2,0)-a(1,0)*a(2,2))*t;
3223 inva(1,1) = (a(0,0)*a(2,2)-a(0,2)*a(2,0))*t;
3224 inva(1,2) = (a(0,2)*a(1,0)-a(0,0)*a(1,2))*t;
3226 inva(2,0) = (a(1,0)*a(2,1)-a(1,1)*a(2,0))*t;
3227 inva(2,1) = (a(0,1)*a(2,0)-a(0,0)*a(2,1))*t;
3228 inva(2,2) = (a(0,0)*a(1,1)-a(0,1)*a(1,0))*t;
3243 double t = 1. / a.
Det() ;
3248 inva(0,0) = 1.0 / a(0,0);
3251 inva(0,0) = a(1,1) * t ;
3252 inva(1,0) = -a(0,1) * t ;
3253 inva(0,1) = -a(1,0) * t ;
3254 inva(1,1) = a(0,0) * t ;
3257 inva(0,0) = (a(1,1)*a(2,2)-a(1,2)*a(2,1))*t;
3258 inva(1,0) = (a(0,2)*a(2,1)-a(0,1)*a(2,2))*t;
3259 inva(2,0) = (a(0,1)*a(1,2)-a(0,2)*a(1,1))*t;
3261 inva(0,1) = (a(1,2)*a(2,0)-a(1,0)*a(2,2))*t;
3262 inva(1,1) = (a(0,0)*a(2,2)-a(0,2)*a(2,0))*t;
3263 inva(2,1) = (a(0,2)*a(1,0)-a(0,0)*a(1,2))*t;
3265 inva(0,2) = (a(1,0)*a(2,1)-a(1,1)*a(2,0))*t;
3266 inva(1,2) = (a(0,1)*a(2,0)-a(0,0)*a(2,1))*t;
3267 inva(2,2) = (a(0,0)*a(1,1)-a(0,1)*a(1,0))*t;
3277 "Matrix must be 3x2 or 2x1, "
3278 <<
"and the Vector must be sized with the rows. "
3279 <<
" J.Height() = " << J.
Height()
3280 <<
", J.Width() = " << J.
Width()
3281 <<
", n.Size() = " << n.
Size()
3284 const double *d = J.
Data();
3292 n(0) = d[1]*d[5] - d[2]*d[4];
3293 n(1) = d[2]*d[3] - d[0]*d[5];
3294 n(2) = d[0]*d[4] - d[1]*d[3];
3300 for (
int i = 0; i < a.
Height(); i++)
3301 for (
int j = 0; j <= i; j++)
3304 for (
int k = 0; k < a.
Width(); k++)
3306 temp += a(i,k) * a(j,k);
3308 aat(j,i) = aat(i,j) = temp;
3314 for (
int i = 0; i < A.
Height(); i++)
3316 for (
int j = 0; j < i; j++)
3319 for (
int k = 0; k < A.
Width(); k++)
3321 t += D(k) * A(i, k) * A(j, k);
3329 for (
int i = 0; i < A.
Height(); i++)
3332 for (
int k = 0; k < A.
Width(); k++)
3334 t += D(k) * A(i, k) * A(i, k);
3342 for (
int i = 0; i < A.
Height(); i++)
3344 for (
int j = 0; j <= i; j++)
3347 for (
int k = 0; k < A.
Width(); k++)
3349 t += D(k) * A(i, k) * A(j, k);
3351 ADAt(j, i) = ADAt(i, j) = t;
3366 #ifdef MFEM_USE_LAPACK
3367 static char transa =
'N', transb =
'T';
3368 static double alpha = 1.0, beta = 0.0;
3371 dgemm_(&transa, &transb, &m, &n, &k, &alpha, A.
Data(), &m,
3372 B.
Data(), &n, &beta, ABt.
Data(), &m);
3374 const int ah = A.
Height();
3375 const int bh = B.
Height();
3376 const int aw = A.
Width();
3377 const double *ad = A.
Data();
3378 const double *bd = B.
Data();
3379 double *cd = ABt.
Data();
3381 for (
int i = 0, s = ah*bh; i < s; i++)
3385 for (
int k = 0; k < aw; k++)
3388 for (
int j = 0; j < bh; j++)
3390 const double bjk = bd[j];
3391 for (
int i = 0; i < ah; i++)
3393 cp[i] += ad[i] * bjk;
3401 const int ah = A.
Height();
3402 const int bh = B.
Height();
3403 const int aw = A.
Width();
3404 const double *ad = A.
Data();
3405 const double *bd = B.
Data();
3406 double *cd = ABt.
Data();
3408 for (
int j = 0; j < bh; j++)
3409 for (
int i = 0; i < ah; i++)
3412 const double *ap = ad + i;
3413 const double *bp = bd + j;
3414 for (
int k = 0; k < aw; k++)
3426 for (i = 0; i < A.
Height(); i++)
3427 for (j = 0; j < B.
Height(); j++)
3430 for (k = 0; k < A.
Width(); k++)
3432 d += A(i, k) * B(j, k);
3450 const int ah = A.
Height();
3451 const int bh = B.
Height();
3452 const int aw = A.
Width();
3453 const double *ad = A.
Data();
3454 const double *bd = B.
Data();
3455 const double *dd = D.
GetData();
3456 double *cd = ADBt.
Data();
3458 for (
int i = 0, s = ah*bh; i < s; i++)
3462 for (
int k = 0; k < aw; k++)
3465 for (
int j = 0; j < bh; j++)
3467 const double dk_bjk = dd[k] * bd[j];
3468 for (
int i = 0; i < ah; i++)
3470 cp[i] += ad[i] * dk_bjk;
3489 #ifdef MFEM_USE_LAPACK
3490 static char transa =
'N', transb =
'T';
3491 static double alpha = 1.0, beta = 1.0;
3494 dgemm_(&transa, &transb, &m, &n, &k, &alpha, A.
Data(), &m,
3495 B.
Data(), &n, &beta, ABt.
Data(), &m);
3497 const int ah = A.
Height();
3498 const int bh = B.
Height();
3499 const int aw = A.
Width();
3500 const double *ad = A.
Data();
3501 const double *bd = B.
Data();
3502 double *cd = ABt.
Data();
3504 for (
int k = 0; k < aw; k++)
3507 for (
int j = 0; j < bh; j++)
3509 const double bjk = bd[j];
3510 for (
int i = 0; i < ah; i++)
3512 cp[i] += ad[i] * bjk;
3523 for (i = 0; i < A.
Height(); i++)
3524 for (j = 0; j < B.
Height(); j++)
3527 for (k = 0; k < A.
Width(); k++)
3529 d += A(i, k) * B(j, k);
3547 const int ah = A.
Height();
3548 const int bh = B.
Height();
3549 const int aw = A.
Width();
3550 const double *ad = A.
Data();
3551 const double *bd = B.
Data();
3552 const double *dd = D.
GetData();
3553 double *cd = ADBt.
Data();
3555 for (
int k = 0; k < aw; k++)
3558 for (
int j = 0; j < bh; j++)
3560 const double dk_bjk = dd[k] * bd[j];
3561 for (
int i = 0; i < ah; i++)
3563 cp[i] += ad[i] * dk_bjk;
3583 #ifdef MFEM_USE_LAPACK
3584 static char transa =
'N', transb =
'T';
3586 static double beta = 1.0;
3589 dgemm_(&transa, &transb, &m, &n, &k, &alpha, A.
Data(), &m,
3590 B.
Data(), &n, &beta, ABt.
Data(), &m);
3592 const int ah = A.
Height();
3593 const int bh = B.
Height();
3594 const int aw = A.
Width();
3595 const double *ad = A.
Data();
3596 const double *bd = B.
Data();
3597 double *cd = ABt.
Data();
3599 for (
int k = 0; k < aw; k++)
3602 for (
int j = 0; j < bh; j++)
3604 const double bjk = a * bd[j];
3605 for (
int i = 0; i < ah; i++)
3607 cp[i] += ad[i] * bjk;
3618 for (i = 0; i < A.
Height(); i++)
3619 for (j = 0; j < B.
Height(); j++)
3622 for (k = 0; k < A.
Width(); k++)
3624 d += A(i, k) * B(j, k);
3641 #ifdef MFEM_USE_LAPACK
3642 static char transa =
'T', transb =
'N';
3643 static double alpha = 1.0, beta = 0.0;
3646 dgemm_(&transa, &transb, &m, &n, &k, &alpha, A.
Data(), &k,
3647 B.
Data(), &k, &beta, AtB.
Data(), &m);
3649 const int ah = A.
Height();
3650 const int aw = A.
Width();
3651 const int bw = B.
Width();
3652 const double *ad = A.
Data();
3653 const double *bd = B.
Data();
3654 double *cd = AtB.
Data();
3656 for (
int j = 0; j < bw; j++)
3658 const double *ap = ad;
3659 for (
int i = 0; i < aw; i++)
3662 for (
int k = 0; k < ah; k++)
3675 for (i = 0; i < A.
Width(); i++)
3676 for (j = 0; j < B.
Width(); j++)
3679 for (k = 0; k < A.
Height(); k++)
3681 d += A(k, i) * B(k, j);
3692 for (
int i = 0; i < A.
Height(); i++)
3694 for (
int j = 0; j < i; j++)
3697 for (
int k = 0; k < A.
Width(); k++)
3699 d += A(i,k) * A(j,k);
3701 AAt(i, j) += (d *= a);
3705 for (
int k = 0; k < A.
Width(); k++)
3707 d += A(i,k) * A(i,k);
3715 for (
int i = 0; i < A.
Height(); i++)
3716 for (
int j = 0; j <= i; j++)
3719 for (
int k = 0; k < A.
Width(); k++)
3721 d += A(i,k) * A(j,k);
3723 AAt(i, j) = AAt(j, i) = a * d;
3729 for (
int i = 0; i < v.
Size(); i++)
3730 for (
int j = 0; j <= i; j++)
3732 vvt(i,j) = vvt(j,i) = v(i) * v(j);
3748 for (i = 0; i < v.
Size(); i++)
3751 for (j = 0; j < w.
Size(); j++)
3753 VWt(i, j) = vi * w(j);
3769 for (
int i = 0; i < m; i++)
3772 for (
int j = 0; j < n; j++)
3774 VWt(i, j) += vi * w(j);
3790 for (
int i = 0; i < n; i++)
3793 for (
int j = 0; j < i; j++)
3795 double vivj = vi * v(j);
3799 VVt(i, i) += vi * v(i);
3815 for (
int j = 0; j < n; j++)
3817 const double awj = a * w(j);
3818 for (
int i = 0; i < m; i++)
3820 VWt(i, j) += v(i) * awj;
3836 for (
int i = 0; i < n; i++)
3838 double avi = a * v(i);
3839 for (
int j = 0; j < i; j++)
3841 double avivj = avi * v(j);
3845 VVt(i, i) += avi * v(i);
3852 #ifdef MFEM_USE_LAPACK
3855 MFEM_VERIFY(!info,
"LAPACK: error in DGETRF");
3859 for (
int i = 0; i < m; i++)
3864 double a = std::abs(data[piv+i*m]);
3865 for (
int j = i+1; j < m; j++)
3867 const double b = std::abs(data[j+i*m]);
3878 for (
int j = 0; j < m; j++)
3880 Swap<double>(data[i+j*m], data[piv+j*m]);
3884 MFEM_ASSERT(data[i+i*m] != 0.0,
"division by zero");
3885 const double a_ii_inv = 1.0/data[i+i*m];
3886 for (
int j = i+1; j < m; j++)
3888 data[j+i*m] *= a_ii_inv;
3890 for (
int k = i+1; k < m; k++)
3892 const double a_ik = data[i+k*m];
3893 for (
int j = i+1; j < m; j++)
3895 data[j+k*m] -= a_ik * data[j+i*m];
3905 for (
int i=0; i<m; i++)
3909 det *= -
data[m * i + i];
3913 det *=
data[m * i + i];
3924 for (
int k = 0; k < n; k++)
3927 for (
int i = 0; i < m; i++)
3929 double x_i = x[i] * data[i+i*m];
3930 for (
int j = i+1; j < m; j++)
3932 x_i += x[j] * data[i+j*m];
3937 for (
int i = m-1; i >= 0; i--)
3940 for (
int j = 0; j < i; j++)
3942 x_i += x[j] * data[i+j*m];
3947 for (
int i = m-1; i >= 0; i--)
3949 Swap<double>(x[i], x[ipiv[i]-
ipiv_base]);
3960 for (
int k = 0; k < n; k++)
3963 for (
int i = 0; i < m; i++)
3965 Swap<double>(x[i], x[ipiv[i]-
ipiv_base]);
3968 for (
int j = 0; j < m; j++)
3970 const double x_j = x[j];
3971 for (
int i = j+1; i < m; i++)
3973 x[i] -= data[i+j*m] * x_j;
3985 for (
int k = 0; k < n; k++)
3987 for (
int j = m-1; j >= 0; j--)
3989 const double x_j = ( x[j] /= data[j+j*m] );
3990 for (
int i = 0; i < j; i++)
3992 x[i] -= data[i+j*m] * x_j;
4001 #ifdef MFEM_USE_LAPACK
4004 if (m > 0 && n > 0) {
dgetrs_(&trans, &m, &n,
data, &m,
ipiv, X, &m, &info); }
4005 MFEM_VERIFY(!info,
"LAPACK: error in DGETRS");
4020 for (
int k = 0; k < m; k++)
4022 const double minus_x_k = -( x[k] = 1.0/data[k+k*m] );
4023 for (
int i = 0; i < k; i++)
4025 x[i] = data[i+k*m] * minus_x_k;
4027 for (
int j = k-1; j >= 0; j--)
4029 const double x_j = ( x[j] /= data[j+j*m] );
4030 for (
int i = 0; i < j; i++)
4032 x[i] -= data[i+j*m] * x_j;
4040 for (
int j = 0; j < k; j++)
4042 const double minus_L_kj = -data[k+j*m];
4043 for (
int i = 0; i <= j; i++)
4045 X[i+j*m] += X[i+k*m] * minus_L_kj;
4047 for (
int i = j+1; i < m; i++)
4049 X[i+j*m] = X[i+k*m] * minus_L_kj;
4053 for (
int k = m-2; k >= 0; k--)
4055 for (
int j = 0; j < k; j++)
4057 const double L_kj = data[k+j*m];
4058 for (
int i = 0; i < m; i++)
4060 X[i+j*m] -= X[i+k*m] * L_kj;
4065 for (
int k = m-1; k >= 0; k--)
4070 for (
int i = 0; i < m; i++)
4072 Swap<double>(X[i+k*m], X[i+piv_k*m]);
4079 const double *X1,
double *X2)
4082 for (
int k = 0; k < r; k++)
4084 for (
int j = 0; j < m; j++)
4086 const double x1_jk = X1[j+k*m];
4087 for (
int i = 0; i < n; i++)
4089 X2[i+k*n] -= A21[i+j*n] * x1_jk;
4096 int m,
int n,
double *A12,
double *A21,
double *A22)
const
4102 for (
int j = 0; j < m; j++)
4104 const double u_jj_inv = 1.0/data[j+j*m];
4105 for (
int i = 0; i < n; i++)
4107 A21[i+j*n] *= u_jj_inv;
4109 for (
int k = j+1; k < m; k++)
4111 const double u_jk = data[j+k*m];
4112 for (
int i = 0; i < n; i++)
4114 A21[i+k*n] -= A21[i+j*n] * u_jk;
4119 SubMult(m, n, n, A21, A12, A22);
4123 double *B1,
double *B2)
const
4128 SubMult(m, n, r, L21, B1, B2);
4132 const double *X2,
double *Y1)
const
4135 SubMult(n, m, r, U12, X2, Y1);
4144 MFEM_ASSERT(
height ==
width,
"not a square matrix");
4154 MFEM_ASSERT(
height ==
width,
"not a square matrix");
4162 MFEM_ASSERT(a,
"DenseMatrix is not given");
4163 const double *adata = a->data;
4166 lu.
data[i] = adata[i];
4173 MFEM_VERIFY(mat.
height == mat.
width,
"DenseMatrix is not square!");
4189 MFEM_VERIFY(p != NULL,
"Operator is not a DenseMatrix!");
4209 for (
int i = 0; i <
width; i++)
4231 #ifdef MFEM_USE_LAPACK
4237 &qwork, &lwork, &info);
4239 lwork = (int) qwork;
4240 work =
new double[lwork];
4246 : mat(other.mat), EVal(other.EVal), EVect(other.EVect), ev(NULL, other.n),
4249 #ifdef MFEM_USE_LAPACK
4252 lwork = other.lwork;
4254 work =
new double[lwork];
4261 if (mat.
Width() != n)
4263 mfem_error(
"DenseMatrixEigensystem::Eval()");
4267 #ifdef MFEM_USE_LAPACK
4270 work, &lwork, &info);
4274 mfem::err <<
"DenseMatrixEigensystem::Eval(): DSYEV error code: "
4279 mfem_error(
"DenseMatrixEigensystem::Eval(): Compiled without LAPACK");
4285 #ifdef MFEM_USE_LAPACK
4305 void DenseMatrixSVD::Init()
4307 #ifdef MFEM_USE_LAPACK
4316 NULL, &n, &qwork, &lwork, &info);
4318 lwork = (int) qwork;
4319 work =
new double[lwork];
4321 mfem_error(
"DenseMatrixSVD::Init(): Compiled without LAPACK");
4334 #ifdef MFEM_USE_LAPACK
4336 NULL, &n, work, &lwork, &info);
4340 mfem::err <<
"DenseMatrixSVD::Eval() : info = " << info << endl;
4344 mfem_error(
"DenseMatrixSVD::Eval(): Compiled without LAPACK");
4350 #ifdef MFEM_USE_LAPACK
4360 const int *I = elem_dof.
GetI(), *J = elem_dof.
GetJ(), *dofs;
4361 double *d_col = tdata, *yp = y, x_col;
4362 const double *xp = x;
4366 for (
int i = 0; i < ne; i++)
4369 for (
int col = 0; col < n; col++)
4371 x_col = xp[dofs[col]];
4372 for (
int row = 0; row < n; row++)
4374 yp[dofs[row]] += x_col*d_col[row];
4383 for (
int i = 0; i < ne; i++)
4386 x_col = xp[dofs[0]];
4387 for (
int row = 0; row < n; row++)
4389 ye(row) = x_col*d_col[row];
4392 for (
int col = 1; col < n; col++)
4394 x_col = xp[dofs[col]];
4395 for (
int row = 0; row < n; row++)
4397 ye(row) += x_col*d_col[row];
4401 for (
int row = 0; row < n; row++)
4403 yp[dofs[row]] += ye(row);
4412 for (
int i=0; i<s; i++)
void Symmetrize()
(*this) = 1/2 ((*this) + (*this)^t)
void dsyevr_Eigensystem(DenseMatrix &a, Vector &ev, DenseMatrix *evect)
void MultABt(const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &ABt)
Multiply a matrix A with the transpose of a matrix B: A*Bt.
int Size() const
Logical size of the array.
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.
bool KernelVector2G(const int &mode, double &d1, double &d12, double &d21, double &d2)
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);.
void Eigenvalues2S(const double &d12, double &d1, double &d2)
void GetScalingFactor(const double &d_max, double &mult)
void SingularValues(Vector &sv) const
void dsyev_Eigensystem(DenseMatrix &a, Vector &ev, DenseMatrix *evect)
void SetSize(int s)
Resize the vector to size s.
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 dgetri_(int *N, double *A, int *LDA, int *IPIV, double *WORK, int *LWORK, int *INFO)
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.
int Size() const
Returns the size of the vector.
void CopyRows(const DenseMatrix &A, int row1, int row2)
Copy rows row1 through row2 from A to *this.
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 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.
double * GetData() const
Return a pointer to the beginning of the Vector data.
void CalcOrtho(const DenseMatrix &J, Vector &n)
DenseMatrix & operator=(double c)
Sets the matrix elements equal to constant c.
void vec_normalize3_aux(const double &x1, const double &x2, const double &x3, double &n1, double &n2, double &n3)
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.
void dgesvd_(char *JOBU, char *JOBVT, int *M, int *N, double *A, int *LDA, double *S, double *U, int *LDU, double *VT, int *LDVT, double *WORK, int *LWORK, int *INFO)
static void SubMult(int m, int n, int r, const double *A21, const double *X1, double *X2)
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.
int KernelVector3G_aux(const int &mode, double &d1, double &d2, double &d3, double &c12, double &c13, double &c23, double &c21, double &c31, double &c32)
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)
friend class DenseMatrixInverse
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)
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 mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
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.
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.
void vec_normalize3(const double &x1, const double &x2, const double &x3, double &n1, double &n2, double &n3)
void dgetrf_(int *, int *, double *, int *, int *, int *)
~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
int KernelVector3S(const int &mode, const double &d12, const double &d13, const double &d23, double &d1, double &d2, double &d3)
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'.
void GetColumn(int c, Vector &col) const
void AddMult(const Vector &x, Vector &y) const
y += A.x
void dgemm_(char *, char *, int *, int *, int *, double *, double *, int *, double *, int *, double *, double *, int *)
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||.
void Eigensystem2S(const double &d12, double &d1, double &d2, double &c, double &s)
double MaxMaxNorm() const
Compute the norm ||A|| = max_{ij} |A_{ij}|.
double * Data() const
Returns the matrix data array.
void Swap(Array< T > &, Array< T > &)
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.
void dgetrs_(char *, int *, int *, double *, int *, int *, double *, int *, int *)
OutStream err(std::cerr)
Global stream used by the library for standard error output. Initially it uses the same std::streambu...
int Reduce3S(const int &mode, double &d1, double &d2, double &d3, double &d12, double &d13, double &d23, double &z1, double &z2, double &z3, double &v1, double &v2, double &v3, double &g)
void MultAAt(const DenseMatrix &a, DenseMatrix &aat)
Calculate the matrix A.At.
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.
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.
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
DenseMatrixEigensystem(DenseMatrix &m)
double epsilon(const Vector &x)
void dsyevr_(char *JOBZ, char *RANGE, char *UPLO, int *N, double *A, int *LDA, double *VL, double *VU, int *IL, int *IU, double *ABSTOL, int *M, double *W, double *Z, int *LDZ, int *ISUPPZ, double *WORK, int *LWORK, int *IWORK, int *LIWORK, int *INFO)
int Rank(double tol) const
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);.
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 SetCol(int c, const Vector &col)
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...
Rank 3 tensor (array of matrices)
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.
void dsyev_(char *JOBZ, char *UPLO, int *N, double *A, int *LDA, double *W, double *WORK, int *LWORK, int *INFO)
virtual void PrintMatlab(std::ostream &out=mfem::out) const
DenseMatrix & operator+=(const double *m)