|
[Sponsors] |
August 30, 2011, 11:08 |
,newbie C++: how to print a matrix?
|
#1 |
Senior Member
Mirko Vukovic
Join Date: Mar 2009
Posts: 159
Rep Power: 17 |
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 |
|
August 30, 2011, 18:52 |
|
#2 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
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.. |
|
September 2, 2011, 10:32 |
|
#3 | |
Senior Member
Mirko Vukovic
Join Date: Mar 2009
Posts: 159
Rep Power: 17 |
Quote:
Thanks, that will get me going. Ordering my C++ book today. Mirko |
||
September 6, 2011, 20:15 |
|
#4 |
Senior Member
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 24 |
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
__________________
Santiago MÁRQUEZ DAMIÁN, Ph.D. Research Scientist Research Center for Computational Methods (CIMEC) - CONICET/UNL Tel: 54-342-4511594 Int. 7032 Colectora Ruta Nac. 168 / Paraje El Pozo (3000) Santa Fe - Argentina. http://www.cimec.org.ar |
|
|
|
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 22:47 |
Matrix solver | Yang | Main CFD Forum | 5 | May 13, 2006 23:20 |
Elemtary matrix to CSR global matrix | xueying | Main CFD Forum | 2 | September 24, 2002 10:44 |