CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   simpleMatrix code (http://www.cfd-online.com/Forums/openfoam-programming-development/118106-simplematrix-code.html)

sharonyue May 21, 2013 05:23

simpleMatrix code
 
Hi,

In OpenFOAM's test---simpleMatrix.I have this code:
Code:

int main(int argc, char *argv[])
{
    simpleMatrix<vector> hmm(3);

    hmm[0][0] = -3.0;
    hmm[0][1] = 10.0;
    hmm[0][2] = -4.0;
    hmm[1][0] = 2.0;
    hmm[1][1] = 3.0;
    hmm[1][2] = 10.0;
    hmm[2][0] = 2.0;
    hmm[2][1] = 6.0;
    hmm[2][2] = 1.0;

  hmm.source()[0] = vector(2.0, 1.0, 3.0);
    hmm.source()[1] = vector(1.0, 4.0, 3.0);
    hmm.source()[2] = vector(0.0, 5.0, 2.0);


    Info<< hmm << endl;
    //Info<< hmm.solve() << endl;
    //Info<< hmm << endl;
    //Info<< hmm.LUsolve() << endl;
    //Info<< hmm << endl;

    //Info<< "End\n" << endl;

    return 0;
}

What does the codes in red mean?Thanks in advance.

This is the result in terminal:
Code:

3 3((-3 10 -4)(2 3 10)(2 6 1))
3((2 1 3) (1 4 3) (0 5 2))


Pedro24 May 21, 2013 10:18

Your system "hmm" is a linear system of vectors

So you have A x = b

with :
- A the matrix
- "x" the solution and "b" the source term (both are vector of vectors).

The code in red fill the source vector "b" (composed by vector because your system is a simpleMatrix of vectors)

Code:

    hmm.source()[0] = vector(2.0, 1.0, 3.0);
    hmm.source()[1] = vector(1.0, 4.0, 3.0);
    hmm.source()[2] = vector(0.0, 5.0, 2.0);

Pierre

wenxu August 21, 2014 23:46

Quote:

Originally Posted by Pedro24 (Post 428920)
Your system "hmm" is a linear system of vectors

So you have A x = b

with :
- A the matrix
- "x" the solution and "b" the source term (both are vector of vectors).

The code in red fill the source vector "b" (composed by vector because your system is a simpleMatrix of vectors)

Code:

    hmm.source()[0] = vector(2.0, 1.0, 3.0);
    hmm.source()[1] = vector(1.0, 4.0, 3.0);
    hmm.source()[2] = vector(0.0, 5.0, 2.0);

Pierre

hi,Pedro24。but A=3 3((-3 10 -4)(2 3 10)(2 6 1)) multiply with x1=(-0.452599 1.12232 -0.149847) (the result got by the test code) do not equal to b1=(2 1 3). why? i have misunderstand this? please help me. Thank you!!!


All times are GMT -4. The time now is 14:33.