CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Printing mesh details (https://www.cfd-online.com/Forums/openfoam/89465-printing-mesh-details.html)

jabhiji June 13, 2011 16:28

Printing mesh details
 
Hi all,

This question is about the OpenFOAM source code. Perhaps some experienced OpenFOAM user can point me in the right direction.

I am trying to print out the X, Y and Z coordinates of the mesh for (say) a simple 2-D cavity flow problem using 20 x 20 control volumes (400 cells, 882 vertices). Suppose I add in the following for loop inside icoFoam.C:

for(label dummy=0; dummy < mesh.nPoints(); dummy++)
{
Info << SOMETHING GOES HERE;
}


What I want this loop to print is something like this:

indx = 1 X(1) = ..... Y(1) = ..... Z(1) = ....
indx = 2 X(2) = ..... Y(2) = ..... Z(2) = ....
.
.
.
and so on, for all 882 vertices.

What is the OpenFOAM function to print something like this ?

Thanks in advance,

- jabhiji

Logan Page June 13, 2011 17:40

For the element cell centres it would be something like

forAll(mesh.C(), cellI)
{
X = mesh.C()[cellI].component(0);
Y = mesh.C()[cellI].component(1);
Z = mesh.C()[cellI].component(2);

Info << "Ind = " << cellI << "X(" << cellI << ") = " << X << ... etc ... << endl;
}

or you can save all X, Y and Z values without the for loop like

scalarField CX = mesh.C().component(0);
scalarField CY = mesh.C().component(1);
scalarField CZ = mesh.C().component(2);

jabhiji June 13, 2011 18:14

Thanks, Logan ! This is exactly what I was looking for. What is a good place to search for thing like this within the OpenFOAM documentation ? I am new to C++ and would like to get familiar with the overall design of this code but the online C++ documentation is a little intimidating...

Logan Page June 13, 2011 19:30

Unfortunately i cant help with that, im also new to C++ and i find the documentation rather confusing. What ive learnt so far has been from playing around and hours of googleing :P
Sorry

jabhiji June 27, 2011 18:52

Hi Logan,

This is a follow-up question to the one you answered a few weeks ago, related to accessing information about the mesh and printing it out. The syntax worked perfectly fine when I was printing everything from the solver file (say, "pisoFoam.C").

But if we want to access the mesh information from inside one of the LES models (say, the file "DeardorffDiffStress.C", how can we make sure that the "mesh" object is in scope inside the "DeardorffDiffStress.C" file ? I assume that once a program begins to run, the mesh information is stored in a global location, which should then be accessible to all functions / classes etc.

Should one use

Foam::meshTools::mesh.C()

or something of that sort ? If I use the exact expression I wrote above, OpenFOAM gives me the following error during compile time:

Foam::meshTools’ has not been declared.

All I am doing is adding the following line inside "DeardorffStress.C"

const int total_cells = Foam::meshTools::mesh.nCells(); // total number of cells

Thanks and Regards,

- jabhiji

Logan Page June 28, 2011 07:50

I'm not 100% sure on the answer to this.

If I look at a post processing tool I use, there are the following lines.

#include "createMesh.H"
runTime.setTime(timeDirs[timeI], timeI);
mesh.readUpdate();

from what I understand the 1st line is the Mesh header file and this should include the mesh tools you need
the next 2 lines point to the required time directory and read the the variable information from there.


All times are GMT -4. The time now is 13:58.