19 #include "../general/table.hpp"
20 #include "../general/globals.hpp"
27 #if defined(_MSC_VER) && (_MSC_VER < 1800)
29 #define copysign _copysign
48 data =
new double[hw];
50 for (
int i = 0; i < hw; i++)
64 MFEM_ASSERT(s >= 0,
"invalid DenseMatrix size: " << s);
68 data =
new double[capacity]();
78 MFEM_ASSERT(m >= 0 && n >= 0,
79 "invalid DenseMatrix size: " << m <<
" x " << n);
83 data =
new double[capacity]();
92 :
Matrix(mat.width, mat.height)
97 data =
new double[capacity];
99 for (
int i = 0; i <
height; i++)
100 for (
int j = 0; j <
width; j++)
102 (*this)(i,j) = mat(j,i);
113 MFEM_ASSERT(h >= 0 && w >= 0,
114 "invalid DenseMatrix size: " << h <<
" x " << w);
122 if (hw > std::abs(capacity))
129 data =
new double[hw]();
147 for (
int row = 0; row <
height; row++)
153 double *d_col = data;
155 for (
int row = 0; row <
height; row++)
157 y[row] = x_col*d_col[row];
160 for (
int col = 1; col <
width; col++)
163 for (
int row = 0; row <
height; row++)
165 y[row] += x_col*d_col[row];
174 "incompatible dimensions");
176 Mult((
const double *)x, (
double *)y);
182 "incompatible dimensions");
186 for (
int i = 0; i < hw; i++)
188 a += data[i] * m.data[i];
196 double *d_col = data;
197 for (
int col = 0; col <
width; col++)
200 for (
int row = 0; row <
height; row++)
202 y_col += x[row]*d_col[row];
212 "incompatible dimensions");
220 "incompatible dimensions");
222 const double *xp = x;
223 double *d_col = data, *yp = y;
224 for (
int col = 0; col <
width; col++)
226 double x_col = xp[col];
227 for (
int row = 0; row <
height; row++)
229 yp[row] += x_col*d_col[row];
238 "incompatible dimensions");
240 double *d_col = data;
241 for (
int col = 0; col <
width; col++)
244 for (
int row = 0; row <
height; row++)
246 y_col += x[row]*d_col[row];
256 "incompatible dimensions");
258 const double *xp = x;
259 double *d_col = data, *yp = y;
260 for (
int col = 0; col <
width; col++)
262 double x_col = a*xp[col];
263 for (
int row = 0; row <
height; row++)
265 yp[row] += x_col*d_col[row];
275 "incompatible dimensions");
277 double *d_col = data;
278 for (
int col = 0; col <
width; col++)
281 for (
int row = 0; row <
height; row++)
283 y_col += x[row]*d_col[row];
294 for (
int i = 0; i <
height; i++)
297 for (
int j = 0; j <
width; j++)
299 Axi += (*this)(i,j) * x[j];
310 double * it_data = data;
311 for (
int j = 0; j <
width; ++j)
312 for (
int i = 0; i <
height; ++i)
314 *(it_data++) *= s(i);
321 double * it_data = data;
322 for (
int j = 0; j <
width; ++j)
323 for (
int i = 0; i <
height; ++i)
325 *(it_data++) /= s(i);
333 double * it_data = data;
334 for (
int j = 0; j <
width; ++j)
337 for (
int i = 0; i <
height; ++i)
348 double * it_data = data;
349 for (
int j = 0; j <
width; ++j)
352 for (
int i = 0; i <
height; ++i)
367 double * ss =
new double[
width];
370 for (
double * end_s = it_s +
width; it_s != end_s; ++it_s)
372 *(it_ss++) = sqrt(*it_s);
375 double * it_data = data;
376 for (
int j = 0; j <
width; ++j)
377 for (
int i = 0; i <
height; ++i)
379 *(it_data++) *= ss[i]*ss[j];
393 double * ss =
new double[
width];
396 for (
double * end_s = it_s +
width; it_s != end_s; ++it_s)
398 *(it_ss++) = 1./sqrt(*it_s);
401 double * it_data = data;
402 for (
int j = 0; j <
width; ++j)
403 for (
int i = 0; i <
height; ++i)
405 *(it_data++) *= ss[i]*ss[j];
416 mfem_error(
"DenseMatrix::Trace() : not a square matrix!");
422 for (
int i = 0; i <
width; i++)
438 "The matrix must be square and "
439 <<
"sized larger than zero to compute the determinant."
440 <<
" Height() = " <<
Height()
441 <<
", Width() = " <<
Width());
449 return data[0] * data[3] - data[1] * data[2];
453 const double *d = data;
455 d[0] * (d[4] * d[8] - d[5] * d[7]) +
456 d[3] * (d[2] * d[7] - d[1] * d[8]) +
457 d[6] * (d[1] * d[5] - d[2] * d[4]);
461 const double *d = data;
463 d[ 0] * (d[ 5] * (d[10] * d[15] - d[11] * d[14]) -
464 d[ 9] * (d[ 6] * d[15] - d[ 7] * d[14]) +
465 d[13] * (d[ 6] * d[11] - d[ 7] * d[10])
467 d[ 4] * (d[ 1] * (d[10] * d[15] - d[11] * d[14]) -
468 d[ 9] * (d[ 2] * d[15] - d[ 3] * d[14]) +
469 d[13] * (d[ 2] * d[11] - d[ 3] * d[10])
471 d[ 8] * (d[ 1] * (d[ 6] * d[15] - d[ 7] * d[14]) -
472 d[ 5] * (d[ 2] * d[15] - d[ 3] * d[14]) +
473 d[13] * (d[ 2] * d[ 7] - d[ 3] * d[ 6])
475 d[12] * (d[ 1] * (d[ 6] * d[11] - d[ 7] * d[10]) -
476 d[ 5] * (d[ 2] * d[11] - d[ 3] * d[10]) +
477 d[ 9] * (d[ 2] * d[ 7] - d[ 3] * d[ 6])
486 return lu_factors.
Det();
501 return sqrt(data[0] * data[0] + data[1] * data[1]);
505 return sqrt(data[0] * data[0] + data[1] * data[1] + data[2] * data[2]);
509 const double *d = data;
510 double E = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
511 double G = d[3] * d[3] + d[4] * d[4] + d[5] * d[5];
512 double F = d[0] * d[3] + d[1] * d[4] + d[2] * d[5];
513 return sqrt(E * G - F * F);
522 for (
int i = 0; i < s; i++)
524 data[i] = alpha*A[i];
530 for (
int j = 0; j <
Width(); j++)
531 for (
int i = 0; i <
Height(); i++)
533 (*this)(i,j) += c * A(i,j);
540 for (
int i = 0; i < s; i++)
550 for (
int i = 0; i < s; i++)
562 for (
int i = 0; i < hw; i++)
573 for (
int i = 0; i < hw; i++)
583 "incompatible matrix sizes.");
589 for (
int j = 0; j <
width; j++)
590 for (
int i = 0; i <
height; i++)
592 (*this)(i, j) -= m(i, j);
601 for (
int i = 0; i < s; i++)
611 for (
int i = 0; i < hw; i++)
617 #ifdef MFEM_USE_LAPACK
619 dgetrf_(
int *,
int *,
double *,
int *,
int *,
int *);
621 dgetrs_(
char *,
int *,
int *,
double *,
int *,
int *,
double *,
int *,
int *);
623 dgetri_(
int *N,
double *A,
int *LDA,
int *IPIV,
double *WORK,
624 int *LWORK,
int *INFO);
636 #ifdef MFEM_USE_LAPACK
637 int *ipiv =
new int[
width];
646 mfem_error(
"DenseMatrix::Invert() : Error in DGETRF");
652 work =
new double[lwork];
658 mfem_error(
"DenseMatrix::Invert() : Error in DGETRI");
664 int c, i, j, n =
Width();
668 for (c = 0; c < n; c++)
670 a = fabs((*
this)(c, c));
672 for (j = c + 1; j < n; j++)
674 b = fabs((*
this)(j, c));
683 mfem_error(
"DenseMatrix::Invert() : singular matrix");
686 for (j = 0; j < n; j++)
688 Swap<double>((*this)(c, j), (*
this)(i, j));
691 a = (*this)(c, c) = 1.0 / (*
this)(c, c);
692 for (j = 0; j < c; j++)
696 for (j++; j < n; j++)
700 for (i = 0; i < c; i++)
702 (*this)(i, c) = a * (b = -(*
this)(i, c));
703 for (j = 0; j < c; j++)
705 (*this)(i, j) += b * (*
this)(c, j);
707 for (j++; j < n; j++)
709 (*this)(i, j) += b * (*
this)(c, j);
712 for (i++; i < n; i++)
714 (*this)(i, c) = a * (b = -(*
this)(i, c));
715 for (j = 0; j < c; j++)
717 (*this)(i, j) += b * (*
this)(c, j);
719 for (j++; j < n; j++)
721 (*this)(i, j) += b * (*
this)(c, j);
726 for (c = n - 1; c >= 0; c--)
729 for (i = 0; i < n; i++)
731 Swap<double>((*this)(i, c), (*
this)(i, j));
743 mfem_error(
"DenseMatrix::SquareRootInverse() matrix not square.");
753 for (
int v = 0; v <
Height() ; v++) { (*this)(v,v) = 1.0; }
755 for (
int j = 0; j < 10; j++)
757 for (
int i = 0; i < 10; i++)
772 for (
int v = 0; v <
Height() ; v++) { tmp2(v,v) -= 1.0; }
773 if (tmp2.FNorm() < 1e-10) {
break; }
776 if (tmp2.FNorm() > 1e-10)
778 mfem_error(
"DenseMatrix::SquareRootInverse not converged");
784 for (
int j = 0; j <
Width(); j++)
787 for (
int i = 0; i <
Height(); i++)
789 v[j] += (*this)(i,j)*(*
this)(i,j);
798 const double *d = data;
799 double norm = 0.0, abs_entry;
801 for (
int i = 0; i < hw; i++)
803 abs_entry = fabs(d[i]);
804 if (norm < abs_entry)
816 double max_norm = 0.0, entry, fnorm2;
818 for (i = 0; i < hw; i++)
820 entry = fabs(data[i]);
821 if (entry > max_norm)
829 scale_factor = scaled_fnorm2 = 0.0;
834 for (i = 0; i < hw; i++)
836 entry = data[i] / max_norm;
837 fnorm2 += entry * entry;
840 scale_factor = max_norm;
841 scaled_fnorm2 = fnorm2;
844 #ifdef MFEM_USE_LAPACK
846 dsyevr_(
char *JOBZ,
char *RANGE,
char *UPLO,
int *N,
double *A,
int *LDA,
847 double *VL,
double *VU,
int *IL,
int *IU,
double *ABSTOL,
int *M,
848 double *W,
double *Z,
int *LDZ,
int *ISUPPZ,
double *WORK,
int *LWORK,
849 int *IWORK,
int *LIWORK,
int *INFO);
851 dsyev_(
char *JOBZ,
char *UPLO,
int *N,
double *A,
int *LDA,
double *W,
852 double *WORK,
int *LWORK,
int *INFO);
854 dgesvd_(
char *JOBU,
char *JOBVT,
int *M,
int *N,
double *A,
int *LDA,
855 double *S,
double *U,
int *LDU,
double *VT,
int *LDVT,
double *WORK,
856 int *LWORK,
int *INFO);
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)
1146 static const double sqrt_1_eps = sqrt(1./numeric_limits<double>::epsilon());
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 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];
2974 #ifdef MFEM_USE_LAPACK
2976 dgemm_(
char *,
char *,
int *,
int *,
int *,
double *,
double *,
2977 int *,
double *,
int *,
double *,
double *,
int *);
2983 b.
Width() == c.
Height(),
"incompatible dimensions");
2985 #ifdef MFEM_USE_LAPACK
2986 static char transa =
'N', transb =
'N';
2987 static double alpha = 1.0, beta = 0.0;
2990 dgemm_(&transa, &transb, &m, &n, &k, &alpha, b.
Data(), &m,
2991 c.
Data(), &k, &beta, a.
Data(), &m);
2993 const int ah = a.
Height();
2994 const int aw = a.
Width();
2995 const int bw = b.
Width();
2996 double *ad = a.
Data();
2997 const double *bd = b.
Data();
2998 const double *cd = c.
Data();
2999 for (
int i = 0; i < ah*aw; i++)
3003 for (
int j = 0; j < aw; j++)
3005 for (
int k = 0; k < bw; k++)
3007 for (
int i = 0; i < ah; i++)
3009 ad[i+j*ah] += bd[i+k*ah] * cd[k+j*bw];
3019 b.
Width() == c.
Height(),
"incompatible dimensions");
3021 #ifdef MFEM_USE_LAPACK
3022 static char transa =
'N', transb =
'N';
3023 static double alpha = 1.0, beta = 1.0;
3026 dgemm_(&transa, &transb, &m, &n, &k, &alpha, b.
Data(), &m,
3027 c.
Data(), &k, &beta, a.
Data(), &m);
3029 const int ah = a.
Height();
3030 const int aw = a.
Width();
3031 const int bw = b.
Width();
3032 double *ad = a.
Data();
3033 const double *bd = b.
Data();
3034 const double *cd = c.
Data();
3035 for (
int j = 0; j < aw; j++)
3037 for (
int k = 0; k < bw; k++)
3039 for (
int i = 0; i < ah; i++)
3041 ad[i+j*ah] += bd[i+k*ah] * cd[k+j*bw];
3063 const double *d = a.
Data();
3064 double *ad = adja.
Data();
3079 e = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
3080 g = d[3]*d[3] + d[4]*d[4] + d[5]*d[5];
3081 f = d[0]*d[3] + d[1]*d[4] + d[2]*d[5];
3083 ad[0] = d[0]*g - d[3]*f;
3084 ad[1] = d[3]*e - d[0]*f;
3085 ad[2] = d[1]*g - d[4]*f;
3086 ad[3] = d[4]*e - d[1]*f;
3087 ad[4] = d[2]*g - d[5]*f;
3088 ad[5] = d[5]*e - d[2]*f;
3097 else if (a.
Width() == 2)
3100 adja(0,1) = -a(0,1);
3101 adja(1,0) = -a(1,0);
3106 adja(0,0) = a(1,1)*a(2,2)-a(1,2)*a(2,1);
3107 adja(0,1) = a(0,2)*a(2,1)-a(0,1)*a(2,2);
3108 adja(0,2) = a(0,1)*a(1,2)-a(0,2)*a(1,1);
3110 adja(1,0) = a(1,2)*a(2,0)-a(1,0)*a(2,2);
3111 adja(1,1) = a(0,0)*a(2,2)-a(0,2)*a(2,0);
3112 adja(1,2) = a(0,2)*a(1,0)-a(0,0)*a(1,2);
3114 adja(2,0) = a(1,0)*a(2,1)-a(1,1)*a(2,0);
3115 adja(2,1) = a(0,1)*a(2,0)-a(0,0)*a(2,1);
3116 adja(2,2) = a(0,0)*a(1,1)-a(0,1)*a(1,0);
3133 else if (a.
Width() == 2)
3135 adjat(0,0) = a(1,1);
3136 adjat(1,0) = -a(0,1);
3137 adjat(0,1) = -a(1,0);
3138 adjat(1,1) = a(0,0);
3142 adjat(0,0) = a(1,1)*a(2,2)-a(1,2)*a(2,1);
3143 adjat(1,0) = a(0,2)*a(2,1)-a(0,1)*a(2,2);
3144 adjat(2,0) = a(0,1)*a(1,2)-a(0,2)*a(1,1);
3146 adjat(0,1) = a(1,2)*a(2,0)-a(1,0)*a(2,2);
3147 adjat(1,1) = a(0,0)*a(2,2)-a(0,2)*a(2,0);
3148 adjat(2,1) = a(0,2)*a(1,0)-a(0,0)*a(1,2);
3150 adjat(0,2) = a(1,0)*a(2,1)-a(1,1)*a(2,0);
3151 adjat(1,2) = a(0,1)*a(2,0)-a(0,0)*a(2,1);
3152 adjat(2,2) = a(0,0)*a(1,1)-a(0,1)*a(1,0);
3159 MFEM_ASSERT(inva.
Height() == a.
Width(),
"incorrect dimensions");
3160 MFEM_ASSERT(inva.
Width() == a.
Height(),
"incorrect dimensions");
3166 const double *d = a.
Data();
3167 double *
id = inva.
Data();
3170 t = 1.0 / (d[0]*d[0] + d[1]*d[1]);
3178 t = 1.0 / (d[0]*d[0] + d[1]*d[1] + d[2]*d[2]);
3186 e = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
3187 g = d[3]*d[3] + d[4]*d[4] + d[5]*d[5];
3188 f = d[0]*d[3] + d[1]*d[4] + d[2]*d[5];
3189 t = 1.0 / (e*g - f*f);
3190 e *= t; g *= t; f *= t;
3192 id[0] = d[0]*g - d[3]*f;
3193 id[1] = d[3]*e - d[0]*f;
3194 id[2] = d[1]*g - d[4]*f;
3195 id[3] = d[4]*e - d[1]*f;
3196 id[4] = d[2]*g - d[5]*f;
3197 id[5] = d[5]*e - d[2]*f;
3205 MFEM_ASSERT(std::abs(t) > 1.0e-14 * pow(a.FNorm()/a.
Width(), a.
Width()),
3206 "singular matrix!");
3218 inva(0,0) = a(1,1) * t ;
3219 inva(0,1) = -a(0,1) * t ;
3220 inva(1,0) = -a(1,0) * t ;
3221 inva(1,1) = a(0,0) * t ;
3224 inva(0,0) = (a(1,1)*a(2,2)-a(1,2)*a(2,1))*t;
3225 inva(0,1) = (a(0,2)*a(2,1)-a(0,1)*a(2,2))*t;
3226 inva(0,2) = (a(0,1)*a(1,2)-a(0,2)*a(1,1))*t;
3228 inva(1,0) = (a(1,2)*a(2,0)-a(1,0)*a(2,2))*t;
3229 inva(1,1) = (a(0,0)*a(2,2)-a(0,2)*a(2,0))*t;
3230 inva(1,2) = (a(0,2)*a(1,0)-a(0,0)*a(1,2))*t;
3232 inva(2,0) = (a(1,0)*a(2,1)-a(1,1)*a(2,0))*t;
3233 inva(2,1) = (a(0,1)*a(2,0)-a(0,0)*a(2,1))*t;
3234 inva(2,2) = (a(0,0)*a(1,1)-a(0,1)*a(1,0))*t;
3249 double t = 1. / a.
Det() ;
3254 inva(0,0) = 1.0 / a(0,0);
3257 inva(0,0) = a(1,1) * t ;
3258 inva(1,0) = -a(0,1) * t ;
3259 inva(0,1) = -a(1,0) * t ;
3260 inva(1,1) = a(0,0) * t ;
3263 inva(0,0) = (a(1,1)*a(2,2)-a(1,2)*a(2,1))*t;
3264 inva(1,0) = (a(0,2)*a(2,1)-a(0,1)*a(2,2))*t;
3265 inva(2,0) = (a(0,1)*a(1,2)-a(0,2)*a(1,1))*t;
3267 inva(0,1) = (a(1,2)*a(2,0)-a(1,0)*a(2,2))*t;
3268 inva(1,1) = (a(0,0)*a(2,2)-a(0,2)*a(2,0))*t;
3269 inva(2,1) = (a(0,2)*a(1,0)-a(0,0)*a(1,2))*t;
3271 inva(0,2) = (a(1,0)*a(2,1)-a(1,1)*a(2,0))*t;
3272 inva(1,2) = (a(0,1)*a(2,0)-a(0,0)*a(2,1))*t;
3273 inva(2,2) = (a(0,0)*a(1,1)-a(0,1)*a(1,0))*t;
3283 "Matrix must be 3x2 or 2x1, "
3284 <<
"and the Vector must be sized with the rows. "
3285 <<
" J.Height() = " << J.
Height()
3286 <<
", J.Width() = " << J.
Width()
3287 <<
", n.Size() = " << n.
Size()
3290 const double *d = J.
Data();
3298 n(0) = d[1]*d[5] - d[2]*d[4];
3299 n(1) = d[2]*d[3] - d[0]*d[5];
3300 n(2) = d[0]*d[4] - d[1]*d[3];
3306 for (
int i = 0; i < a.
Height(); i++)
3307 for (
int j = 0; j <= i; j++)
3310 for (
int k = 0; k < a.
Width(); k++)
3312 temp += a(i,k) * a(j,k);
3314 aat(j,i) = aat(i,j) = temp;
3320 for (
int i = 0; i < A.
Height(); i++)
3322 for (
int j = 0; j < i; j++)
3325 for (
int k = 0; k < A.
Width(); k++)
3327 t += D(k) * A(i, k) * A(j, k);
3335 for (
int i = 0; i < A.
Height(); i++)
3338 for (
int k = 0; k < A.
Width(); k++)
3340 t += D(k) * A(i, k) * A(i, k);
3348 for (
int i = 0; i < A.
Height(); i++)
3350 for (
int j = 0; j <= i; j++)
3353 for (
int k = 0; k < A.
Width(); k++)
3355 t += D(k) * A(i, k) * A(j, k);
3357 ADAt(j, i) = ADAt(i, j) = t;
3372 #ifdef MFEM_USE_LAPACK
3373 static char transa =
'N', transb =
'T';
3374 static double alpha = 1.0, beta = 0.0;
3377 dgemm_(&transa, &transb, &m, &n, &k, &alpha, A.
Data(), &m,
3378 B.
Data(), &n, &beta, ABt.
Data(), &m);
3380 const int ah = A.
Height();
3381 const int bh = B.
Height();
3382 const int aw = A.
Width();
3383 const double *ad = A.
Data();
3384 const double *bd = B.
Data();
3385 double *cd = ABt.
Data();
3387 for (
int i = 0, s = ah*bh; i < s; i++)
3391 for (
int k = 0; k < aw; k++)
3394 for (
int j = 0; j < bh; j++)
3396 const double bjk = bd[j];
3397 for (
int i = 0; i < ah; i++)
3399 cp[i] += ad[i] * bjk;
3407 const int ah = A.
Height();
3408 const int bh = B.
Height();
3409 const int aw = A.
Width();
3410 const double *ad = A.
Data();
3411 const double *bd = B.
Data();
3412 double *cd = ABt.
Data();
3414 for (
int j = 0; j < bh; j++)
3415 for (
int i = 0; i < ah; i++)
3418 const double *ap = ad + i;
3419 const double *bp = bd + j;
3420 for (
int k = 0; k < aw; k++)
3432 for (i = 0; i < A.
Height(); i++)
3433 for (j = 0; j < B.
Height(); j++)
3436 for (k = 0; k < A.
Width(); k++)
3438 d += A(i, k) * B(j, k);
3456 const int ah = A.
Height();
3457 const int bh = B.
Height();
3458 const int aw = A.
Width();
3459 const double *ad = A.
Data();
3460 const double *bd = B.
Data();
3461 const double *dd = D.
GetData();
3462 double *cd = ADBt.
Data();
3464 for (
int i = 0, s = ah*bh; i < s; i++)
3468 for (
int k = 0; k < aw; k++)
3471 for (
int j = 0; j < bh; j++)
3473 const double dk_bjk = dd[k] * bd[j];
3474 for (
int i = 0; i < ah; i++)
3476 cp[i] += ad[i] * dk_bjk;
3495 #ifdef MFEM_USE_LAPACK
3496 static char transa =
'N', transb =
'T';
3497 static double alpha = 1.0, beta = 1.0;
3500 dgemm_(&transa, &transb, &m, &n, &k, &alpha, A.
Data(), &m,
3501 B.
Data(), &n, &beta, ABt.
Data(), &m);
3503 const int ah = A.
Height();
3504 const int bh = B.
Height();
3505 const int aw = A.
Width();
3506 const double *ad = A.
Data();
3507 const double *bd = B.
Data();
3508 double *cd = ABt.
Data();
3510 for (
int k = 0; k < aw; k++)
3513 for (
int j = 0; j < bh; j++)
3515 const double bjk = bd[j];
3516 for (
int i = 0; i < ah; i++)
3518 cp[i] += ad[i] * bjk;
3529 for (i = 0; i < A.
Height(); i++)
3530 for (j = 0; j < B.
Height(); j++)
3533 for (k = 0; k < A.
Width(); k++)
3535 d += A(i, k) * B(j, k);
3553 const int ah = A.
Height();
3554 const int bh = B.
Height();
3555 const int aw = A.
Width();
3556 const double *ad = A.
Data();
3557 const double *bd = B.
Data();
3558 const double *dd = D.
GetData();
3559 double *cd = ADBt.
Data();
3561 for (
int k = 0; k < aw; k++)
3564 for (
int j = 0; j < bh; j++)
3566 const double dk_bjk = dd[k] * bd[j];
3567 for (
int i = 0; i < ah; i++)
3569 cp[i] += ad[i] * dk_bjk;
3589 #ifdef MFEM_USE_LAPACK
3590 static char transa =
'N', transb =
'T';
3592 static double beta = 1.0;
3595 dgemm_(&transa, &transb, &m, &n, &k, &alpha, A.
Data(), &m,
3596 B.
Data(), &n, &beta, ABt.
Data(), &m);
3598 const int ah = A.
Height();
3599 const int bh = B.
Height();
3600 const int aw = A.
Width();
3601 const double *ad = A.
Data();
3602 const double *bd = B.
Data();
3603 double *cd = ABt.
Data();
3605 for (
int k = 0; k < aw; k++)
3608 for (
int j = 0; j < bh; j++)
3610 const double bjk = a * bd[j];
3611 for (
int i = 0; i < ah; i++)
3613 cp[i] += ad[i] * bjk;
3624 for (i = 0; i < A.
Height(); i++)
3625 for (j = 0; j < B.
Height(); j++)
3628 for (k = 0; k < A.
Width(); k++)
3630 d += A(i, k) * B(j, k);
3647 #ifdef MFEM_USE_LAPACK
3648 static char transa =
'T', transb =
'N';
3649 static double alpha = 1.0, beta = 0.0;
3652 dgemm_(&transa, &transb, &m, &n, &k, &alpha, A.
Data(), &k,
3653 B.
Data(), &k, &beta, AtB.
Data(), &m);
3655 const int ah = A.
Height();
3656 const int aw = A.
Width();
3657 const int bw = B.
Width();
3658 const double *ad = A.
Data();
3659 const double *bd = B.
Data();
3660 double *cd = AtB.
Data();
3662 for (
int j = 0; j < bw; j++)
3664 const double *ap = ad;
3665 for (
int i = 0; i < aw; i++)
3668 for (
int k = 0; k < ah; k++)
3681 for (i = 0; i < A.
Width(); i++)
3682 for (j = 0; j < B.
Width(); j++)
3685 for (k = 0; k < A.
Height(); k++)
3687 d += A(k, i) * B(k, j);
3698 for (
int i = 0; i < A.
Height(); i++)
3700 for (
int j = 0; j < i; j++)
3703 for (
int k = 0; k < A.
Width(); k++)
3705 d += A(i,k) * A(j,k);
3707 AAt(i, j) += (d *= a);
3711 for (
int k = 0; k < A.
Width(); k++)
3713 d += A(i,k) * A(i,k);
3721 for (
int i = 0; i < A.
Height(); i++)
3722 for (
int j = 0; j <= i; j++)
3725 for (
int k = 0; k < A.
Width(); k++)
3727 d += A(i,k) * A(j,k);
3729 AAt(i, j) = AAt(j, i) = a * d;
3735 for (
int i = 0; i < v.
Size(); i++)
3736 for (
int j = 0; j <= i; j++)
3738 vvt(i,j) = vvt(j,i) = v(i) * v(j);
3754 for (i = 0; i < v.
Size(); i++)
3757 for (j = 0; j < w.
Size(); j++)
3759 VWt(i, j) = vi * w(j);
3775 for (
int i = 0; i < m; i++)
3778 for (
int j = 0; j < n; j++)
3780 VWt(i, j) += vi * w(j);
3797 for (
int j = 0; j < n; j++)
3799 const double awj = a * w(j);
3800 for (
int i = 0; i < m; i++)
3802 VWt(i, j) += v(i) * awj;
3818 for (
int i = 0; i < n; i++)
3820 double avi = a * v(i);
3821 for (
int j = 0; j < i; j++)
3823 double avivj = avi * v(j);
3827 VVt(i, i) += avi * v(i);
3834 #ifdef MFEM_USE_LAPACK
3837 MFEM_VERIFY(!info,
"LAPACK: error in DGETRF");
3841 for (
int i = 0; i < m; i++)
3846 double a = std::abs(data[piv+i*m]);
3847 for (
int j = i+1; j < m; j++)
3849 const double b = std::abs(data[j+i*m]);
3860 for (
int j = 0; j < m; j++)
3862 Swap<double>(data[i+j*m], data[piv+j*m]);
3866 MFEM_ASSERT(data[i+i*m] != 0.0,
"division by zero");
3867 const double a_ii_inv = 1.0/data[i+i*m];
3868 for (
int j = i+1; j < m; j++)
3870 data[j+i*m] *= a_ii_inv;
3872 for (
int k = i+1; k < m; k++)
3874 const double a_ik = data[i+k*m];
3875 for (
int j = i+1; j < m; j++)
3877 data[j+k*m] -= a_ik * data[j+i*m];
3887 for (
int i=0; i<m; i++)
3891 det *= -
data[m * i + i];
3895 det *=
data[m * i + i];
3906 for (
int k = 0; k < n; k++)
3909 for (
int i = 0; i < m; i++)
3911 double x_i = x[i] * data[i+i*m];
3912 for (
int j = i+1; j < m; j++)
3914 x_i += x[j] * data[i+j*m];
3919 for (
int i = m-1; i >= 0; i--)
3922 for (
int j = 0; j < i; j++)
3924 x_i += x[j] * data[i+j*m];
3929 for (
int i = m-1; i >= 0; i--)
3931 Swap<double>(x[i], x[ipiv[i]-
ipiv_base]);
3942 for (
int k = 0; k < n; k++)
3945 for (
int i = 0; i < m; i++)
3947 Swap<double>(x[i], x[ipiv[i]-
ipiv_base]);
3950 for (
int j = 0; j < m; j++)
3952 const double x_j = x[j];
3953 for (
int i = j+1; i < m; i++)
3955 x[i] -= data[i+j*m] * x_j;
3967 for (
int k = 0; k < n; k++)
3969 for (
int j = m-1; j >= 0; j--)
3971 const double x_j = ( x[j] /= data[j+j*m] );
3972 for (
int i = 0; i < j; i++)
3974 x[i] -= data[i+j*m] * x_j;
3983 #ifdef MFEM_USE_LAPACK
3986 if (m > 0 && n > 0) {
dgetrs_(&trans, &m, &n,
data, &m,
ipiv, X, &m, &info); }
3987 MFEM_VERIFY(!info,
"LAPACK: error in DGETRS");
4002 for (
int k = 0; k < m; k++)
4004 const double minus_x_k = -( x[k] = 1.0/data[k+k*m] );
4005 for (
int i = 0; i < k; i++)
4007 x[i] = data[i+k*m] * minus_x_k;
4009 for (
int j = k-1; j >= 0; j--)
4011 const double x_j = ( x[j] /= data[j+j*m] );
4012 for (
int i = 0; i < j; i++)
4014 x[i] -= data[i+j*m] * x_j;
4022 for (
int j = 0; j < k; j++)
4024 const double minus_L_kj = -data[k+j*m];
4025 for (
int i = 0; i <= j; i++)
4027 X[i+j*m] += X[i+k*m] * minus_L_kj;
4029 for (
int i = j+1; i < m; i++)
4031 X[i+j*m] = X[i+k*m] * minus_L_kj;
4035 for (
int k = m-2; k >= 0; k--)
4037 for (
int j = 0; j < k; j++)
4039 const double L_kj = data[k+j*m];
4040 for (
int i = 0; i < m; i++)
4042 X[i+j*m] -= X[i+k*m] * L_kj;
4047 for (
int k = m-1; k >= 0; k--)
4052 for (
int i = 0; i < m; i++)
4054 Swap<double>(X[i+k*m], X[i+piv_k*m]);
4061 const double *X1,
double *X2)
4064 for (
int k = 0; k < r; k++)
4066 for (
int j = 0; j < m; j++)
4068 const double x1_jk = X1[j+k*m];
4069 for (
int i = 0; i < n; i++)
4071 X2[i+k*n] -= A21[i+j*n] * x1_jk;
4078 int m,
int n,
double *A12,
double *A21,
double *A22)
const
4084 for (
int j = 0; j < m; j++)
4086 const double u_jj_inv = 1.0/data[j+j*m];
4087 for (
int i = 0; i < n; i++)
4089 A21[i+j*n] *= u_jj_inv;
4091 for (
int k = j+1; k < m; k++)
4093 const double u_jk = data[j+k*m];
4094 for (
int i = 0; i < n; i++)
4096 A21[i+k*n] -= A21[i+j*n] * u_jk;
4101 SubMult(m, n, n, A21, A12, A22);
4105 double *B1,
double *B2)
const
4110 SubMult(m, n, r, L21, B1, B2);
4114 const double *X2,
double *Y1)
const
4117 SubMult(n, m, r, U12, X2, Y1);
4126 MFEM_ASSERT(
height ==
width,
"not a square matrix");
4136 MFEM_ASSERT(
height ==
width,
"not a square matrix");
4144 MFEM_ASSERT(a,
"DenseMatrix is not given");
4145 const double *adata = a->data;
4148 lu.
data[i] = adata[i];
4155 MFEM_VERIFY(mat.
height == mat.
width,
"DenseMatrix is not square!");
4171 MFEM_VERIFY(p != NULL,
"Operator is not a DenseMatrix!");
4191 for (
int i = 0; i <
width; i++)
4213 #ifdef MFEM_USE_LAPACK
4219 &qwork, &lwork, &info);
4221 lwork = (int) qwork;
4222 work =
new double[lwork];
4229 if (mat.
Width() != n)
4231 mfem_error(
"DenseMatrixEigensystem::Eval()");
4235 #ifdef MFEM_USE_LAPACK
4238 work, &lwork, &info);
4242 mfem::err <<
"DenseMatrixEigensystem::Eval(): DSYEV error code: "
4247 mfem_error(
"DenseMatrixEigensystem::Eval(): Compiled without LAPACK");
4253 #ifdef MFEM_USE_LAPACK
4273 void DenseMatrixSVD::Init()
4275 #ifdef MFEM_USE_LAPACK
4284 NULL, &n, &qwork, &lwork, &info);
4286 lwork = (int) qwork;
4287 work =
new double[lwork];
4289 mfem_error(
"DenseMatrixSVD::Init(): Compiled without LAPACK");
4302 #ifdef MFEM_USE_LAPACK
4304 NULL, &n, work, &lwork, &info);
4308 mfem::err <<
"DenseMatrixSVD::Eval() : info = " << info << endl;
4312 mfem_error(
"DenseMatrixSVD::Eval(): Compiled without LAPACK");
4318 #ifdef MFEM_USE_LAPACK
4328 const int *I = elem_dof.
GetI(), *J = elem_dof.
GetJ(), *dofs;
4329 double *d_col = tdata, *yp = y, x_col;
4330 const double *xp = x;
4334 for (
int i = 0; i < ne; i++)
4337 for (
int col = 0; col < n; col++)
4339 x_col = xp[dofs[col]];
4340 for (
int row = 0; row < n; row++)
4342 yp[dofs[row]] += x_col*d_col[row];
4351 for (
int i = 0; i < ne; i++)
4354 x_col = xp[dofs[0]];
4355 for (
int row = 0; row < n; row++)
4357 ye(row) = x_col*d_col[row];
4360 for (
int col = 1; col < n; col++)
4362 x_col = xp[dofs[col]];
4363 for (
int row = 0; row < n; row++)
4365 ye(row) += x_col*d_col[row];
4369 for (
int row = 0; row < n; row++)
4371 yp[dofs[row]] += ye(row);
4380 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 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 dgetrs_(char *, int *, int *, double *, int *, int *, double *, int *, int *)
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 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 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)
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)
virtual void Print(std::ostream &out=mfem::out, int width_=4) const
Prints matrix to stream out.
void dgetri_(int *N, double *A, int *LDA, int *IPIV, double *WORK, int *LWORK, int *INFO)
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 dgemm_(char *, char *, int *, int *, int *, double *, double *, int *, double *, int *, double *, double *, int *)
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 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 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 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)
~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 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}|.
void dsyev_(char *JOBZ, char *UPLO, int *N, double *A, int *LDA, double *W, double *WORK, int *LWORK, int *INFO)
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.
OutStream err(std::cerr)
Global stream used by the library for standard error output. Initially it uses the same std::streambu...
void mfem_error(const char *msg)
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 dgetrf_(int *, int *, double *, int *, int *, int *)
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)
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)
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 GetRow(int r, Vector &row)
void CalcEigenvalues(double *lambda, double *vec) const
DenseMatrixEigensystem(DenseMatrix &m)
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.
virtual void PrintMatlab(std::ostream &out=mfem::out) const
DenseMatrix & operator+=(const double *m)