void Foam::multiply
(
    scalarRectangularMatrix& ans,         // value changed in return
    const scalarRectangularMatrix& A,
    const DiagonalMatrix<scalar>& B,
    const scalarRectangularMatrix& C
)
{
    if (A.m() != B.size())
    {
        FatalErrorIn
        (
            "multiply("
            "const scalarRectangularMatrix& A, "
            "const DiagonalMatrix<scalar>& B, "
            "const scalarRectangularMatrix& C, "
            "scalarRectangularMatrix& answer)"
        )   << "A and B must have identical inner dimensions but A.m = "
            << A.m() << " and B.n = " << B.size()
            << abort(FatalError);
    }

    if (B.size() != C.n())
    {
        FatalErrorIn
        (
            "multiply("
            "const scalarRectangularMatrix& A, "
            "const DiagonalMatrix<scalar>& B, "
            "const scalarRectangularMatrix& C, "
            "scalarRectangularMatrix& answer)"
        )   << "B and C must have identical inner dimensions but B.m = "
            << B.size() << " and C.n = " << C.n()
            << abort(FatalError);
    }

    ans = scalarRectangularMatrix(A.n(), C.m(), scalar(0));

    for(register label i = 0; i < A.n(); i++)
    {
        for(register label g = 0; g < C.m(); g++)
        {
            for(register label l = 0; l < C.n(); l++)
            {
                ans[i][g] += C[l][g] * A[i][l]*B[l];
            }
        }
    }
}
示例#2
0
TEST(CholeskyTest, testCholesky)
{
    Matrix A = Matrix(3,3,false);
    A.fillWithArgs(
             2.0,-1.0, 1.0,
            -1.0, 2.0,-1.0,
             1.0,-1.0, 2.0 );

/*    A.fillWithArgs(
      2.0, 0.0, 0.0,
      0.0, 2.0, 0.0,
      0.0, 0.0, 2.0 );*/


    cout << "Input Matrix:" << endl << A << endl;

    Matrix *U;
    DiagonalMatrix *D;
    Cholesky::udutDecompose(&A, &U, &D);
    cout << *U;

    cout << endl << "[";
    for (int i = 0; i < D->size(); i++)
    {
        cout << D->at(i) << " ";
    }
    cout << "]" << endl;

    UpperUnitaryMatrix *U1;
    DiagonalMatrix *D1;
    Cholesky::udutDecompose(&A,&U1,&D1);

    cout << *U1;

    cout << endl << "[";
    for (int i = 0; i < D->size(); i++)
    {
        cout << D->at(i) << " ";
    }
    cout << "]" << endl;

    delete U;
    delete U1;
    delete D;
    delete D1;
}