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

,newbie C++: how to print a matrix?

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 2 Post By santiagomarquezd

Reply
 
LinkBack Thread Tools Display Modes
Old   August 30, 2011, 10:08
Default ,newbie C++: how to print a matrix?
  #1
Senior Member
 
Mirko Vukovic
Join Date: Mar 2009
Posts: 159
Rep Power: 8
mirko is on a distinguished road
Hi

I am trying to debug the viewFactor radiation model introduced in OF2.0 - it gives me a different surface flux Qr from the fvDOM model by a factor of 2.

I would like to insert print statements to output matrix and rhs vectors CLU_ and q in viewFactor.C . CLU_ is a templated scalar matrix and q is a scalarField.

Can someone post a code snippet that can get me going?

Thank you very much.

Mirko
mirko is offline   Reply With Quote

Old   August 30, 2011, 17:52
Default
  #2
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 397
Rep Power: 12
marupio is on a distinguished road
Hmmm... quick and dirty. I forget how to get matrix size - you can find it.

Code:
fileName outputFile(runTime.path()/"outputFile");
OFstream os(outputFile);

// This might work
os << "My scalarMatrix object is:" << endl;
os << scalarMatrixObject << endl;
os << "And my scalarVector object is:" << endl;
os << scalarVectorObject << endl;

// Otherwise, iterate:

os << "My scalarMatrix object is:" << endl;
for (label i(0); i < xsize; i++)
{
    for (label j(0); j < ysize; j++)
    {
        os << i << "," << j << "," << scalarMatrixObject[i][j];
    }
    os << endl;
}
// etc..
marupio is offline   Reply With Quote

Old   September 2, 2011, 09:32
Default
  #3
Senior Member
 
Mirko Vukovic
Join Date: Mar 2009
Posts: 159
Rep Power: 8
mirko is on a distinguished road
Quote:
Originally Posted by marupio View Post
Hmmm... quick and dirty. I forget how to get matrix size - you can find it.

Code:
fileName outputFile(runTime.path()/"outputFile");
OFstream os(outputFile);

// This might work
os << "My scalarMatrix object is:" << endl;
os << scalarMatrixObject << endl;
os << "And my scalarVector object is:" << endl;
os << scalarVectorObject << endl;

// Otherwise, iterate:

os << "My scalarMatrix object is:" << endl;
for (label i(0); i < xsize; i++)
{
    for (label j(0); j < ysize; j++)
    {
        os << i << "," << j << "," << scalarMatrixObject[i][j];
    }
    os << endl;
}
// etc..

Thanks, that will get me going. Ordering my C++ book today.

Mirko
mirko is offline   Reply With Quote

Old   September 6, 2011, 19:15
Default
  #4
Senior Member
 
santiagomarquezd's Avatar
 
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 418
Rep Power: 15
santiagomarquezd will become famous soon enough
Mirko, if you are at debugging stage I would recommend to use gdbOF a tool we've developed to make easier the work with gdb and OpenFOAM. It can show matrices in human readable format at any debugging point and export them to MatLab to do further work,

gdbOF

for any questions and suggestions we're open to chat by the mails published in the OFWiki page.

Enjoy it
mirko and elvis like this.
__________________
Santiago MÁRQUEZ DAMIÁN, Ph.D.
Post-doctoral Fellow
Research Center for Computational Mechanics (CIMEC) - CONICET/FICH-UNL
T.E.: 54-342-4511594 Ext. 1005
Güemes 3450 - (3000) Santa Fe
Santa Fe - Argentina
http://www.cimec.org.ar
santiagomarquezd is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find the product of A+ matrix and A- matrix arjun shanker Main CFD Forum 0 November 12, 2010 23:12
Linearized NS euqations: how to solve them?(problem with Matrix operations..) matteoL OpenFOAM Running, Solving & CFD 0 November 18, 2009 07:58
OpenFOAM version 1.6 details lakeat OpenFOAM Running, Solving & CFD 42 August 26, 2009 21:47
Matrix solver Yang Main CFD Forum 5 May 13, 2006 22:20
Elemtary matrix to CSR global matrix xueying Main CFD Forum 2 September 24, 2002 09:44


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