CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

simpleMatrix code

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By sharonyue
  • 2 Post By Pedro24

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 21, 2013, 05:23
Default simpleMatrix code
  #1
Senior Member
 
Dongyue Li
Join Date: Jun 2012
Location: Beijing, China
Posts: 838
Rep Power: 17
sharonyue is on a distinguished road
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))
Kummi likes this.
sharonyue is offline   Reply With Quote

Old   May 21, 2013, 10:18
Default
  #2
Member
 
Pierre HORGUE
Join Date: May 2009
Posts: 33
Rep Power: 16
Pedro24 is on a distinguished road
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
sharonyue and bahedov379 like this.
Pedro24 is offline   Reply With Quote

Old   August 21, 2014, 23:46
Default
  #3
Senior Member
 
Freedom
Join Date: May 2014
Posts: 209
Rep Power: 12
wenxu is on a distinguished road
Quote:
Originally Posted by Pedro24 View Post
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!!!
wenxu is offline   Reply With Quote

Old   September 17, 2017, 02:10
Default
  #4
New Member
 
Big Orange
Join Date: Mar 2016
Posts: 11
Rep Power: 10
bigorange is on a distinguished road
Quote:
Originally Posted by wenxu View Post
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!!!
Hi wenxu, have you gotten the answer for this problem?
bigorange is offline   Reply With Quote

Old   September 20, 2017, 06:06
Default
  #5
Member
 
Pierre HORGUE
Join Date: May 2009
Posts: 33
Rep Power: 16
Pedro24 is on a distinguished road
Quote:
Originally Posted by bigorange View Post
Hi wenxu, have you gotten the answer for this problem?
Hi all,

I didn't see this message few years ago but you cannot separate one solution vector from the others (the system has 9 dependent unknowns, and not 3 x 3 unknwowns). When you run the code, you get :
Code:
3((-0.452599 1.12232 -0.149847) (0.125382 0.452599 0.345566) (0.152905 0.0397554 0.2263))
as solution. I you multiply :
Code:
A =

   -3   10   -4
    2    3   10
    2    6    1
with the given solution :
Code:
x =

  -0.452599   1.122320  -0.149847
   0.125382   0.452599   0.345566
   0.152905   0.039755   0.226300
you will get the source term (which is also a matrix, i.e. a vector of vectors) :
Code:
A * x =

   2.0000e+00   1.0000e+00   3.0000e+00
   1.0000e+00   4.0000e+00   3.0000e+00
  -1.0000e-06   5.0000e+00   2.0000e+00
Sincerely,

Pierre
Pedro24 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The FOAM Documentation Project - SHUT-DOWN holger_marschall OpenFOAM 242 March 7, 2013 12:30
How to make code run in parallel? cwang5 OpenFOAM Programming & Development 1 May 30, 2011 04:47
Open Source Vs Commercial Software MechE OpenFOAM 28 May 16, 2011 11:02
Small 3-D code Zdravko Stojanovic Main CFD Forum 2 July 19, 2010 10:11
public CFD Code development Heinz Wilkening Main CFD Forum 38 March 5, 1999 11:44


All times are GMT -4. The time now is 05:01.