to perform this += T' * B * T
| 934 | |
| 935 | // to perform this += T' * B * T |
| 936 | int |
| 937 | Matrix::addMatrixTripleProduct(double thisFact, |
| 938 | const Matrix &T, |
| 939 | const Matrix &B, |
| 940 | double otherFact) |
| 941 | { |
| 942 | if (thisFact == 1.0 && otherFact == 0.0) |
| 943 | return 0; |
| 944 | #ifdef _G3DEBUG |
| 945 | if ((numCols != numRows) || (B.numCols != B.numRows) || (T.numCols != numRows) || |
| 946 | (T.numRows != B.numCols)) { |
| 947 | opserr << "Matrix::addMatrixTripleProduct() - incompatible matrices\n"; |
| 948 | return -1; |
| 949 | } |
| 950 | #endif |
| 951 | |
| 952 | // cheack work area can hold the temporary matrix |
| 953 | int dimB = B.numCols; |
| 954 | int sizeWork = dimB * numCols; |
| 955 | |
| 956 | if (sizeWork > sizeDoubleWork) { |
| 957 | this->addMatrix(thisFact, T^B*T, otherFact); |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | // zero out the work area |
| 962 | double *matrixWorkPtr = matrixWork; |
| 963 | for (int l=0; l<sizeWork; l++) |
| 964 | *matrixWorkPtr++ = 0.0; |
| 965 | |
| 966 | // now form B * T * fact store in matrixWork == A area |
| 967 | // NOTE: looping as per blas3 dgemm_: j,k,i |
| 968 | |
| 969 | double *tkjPtr = &(T.data)[0]; |
| 970 | for (int j=0; j<numCols; j++) { |
| 971 | double *aijPtrA = &matrixWork[j*dimB]; |
| 972 | for (int k=0; k<dimB; k++) { |
| 973 | double tmp = *tkjPtr++ * otherFact; |
| 974 | double *aijPtr = aijPtrA; |
| 975 | double *bikPtr = &(B.data)[k*dimB]; |
| 976 | for (int i=0; i<dimB; i++) |
| 977 | *aijPtr++ += *bikPtr++ * tmp; |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | // now form T' * matrixWork |
| 982 | // NOTE: looping as per blas3 dgemm_: j,i,k |
| 983 | if (thisFact == 1.0) { |
| 984 | double *dataPtr = &data[0]; |
| 985 | for (int j=0; j< numCols; j++) { |
| 986 | double *workkjPtrA = &matrixWork[j*dimB]; |
| 987 | for (int i=0; i<numRows; i++) { |
| 988 | double *ckiPtr = &(T.data)[i*dimB]; |
| 989 | double *workkjPtr = workkjPtrA; |
| 990 | double aij = 0.0; |
| 991 | for (int k=0; k< dimB; k++) |
| 992 | aij += *ckiPtr++ * *workkjPtr++; |
| 993 | *dataPtr++ += aij; |
no test coverage detected