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/)
-   -   ,newbie C++: how to print a matrix? (http://www.cfd-online.com/Forums/openfoam-programming-development/92020-newbie-c-how-print-matrix.html)

mirko August 30, 2011 10:08

,newbie C++: how to print a matrix?
 
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

marupio August 30, 2011 17:52

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..


mirko September 2, 2011 09:32

Quote:

Originally Posted by marupio (Post 322318)
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

santiagomarquezd September 6, 2011 19:15

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


All times are GMT -4. The time now is 22:56.