CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Exporting Face Normal of a patch and some other values (https://www.cfd-online.com/Forums/openfoam-post-processing/108531-exporting-face-normal-patch-some-other-values.html)

fredo490 October 25, 2012 13:32

Exporting Face Normal of a patch and some other values
 
Dear all,
I want to do a post processing process of a patch (wall) where I need:
- Face center coordinate
- Normal to Face vector
- Face area
- Other data like density

1) I have tried first with a sampling but I cannot find a field "name" to get the face properties. Is it possible to get such a thing ? Here I put a "mesh.Sf()" as example of what I want.
Code:

interpolationScheme cellPointFace;

surfaceFormat        raw;

setFormat      raw;

surfaces
(
    wallTest
    {
        type            patch;
        patches        (wall);
        interpolate        true;
        triangulate        false;
    }
);       


fields          ( rho U mesh.Sf() );

2) I also have tried to create a "fake" solver to get the values directly from OpenFoam but I cannot find how to write/export those data. Is there any function or library able to write arbitrary files ? Ideally I would like a single file containing all my data but I can also accept an openfoam file format.

Code:

label wallPatch = mesh.boundaryMesh().findPatchID("wall");

rho.boundaryField()[wallPatch] // Density

U.boundaryField()[wallPatch] // Velocity

mesh.Sf().boundaryField()[wallPatch] // Face normal vector

mesh.Cf().boundaryField()[wallPatch] // Face Center

mesh.magSf().boundaryField()[wallPatch] // Face magnitude

// "Export" data in the consol
Info<< U.boundaryField()[wallPatch] << endl;

Do you have any suggestion ? Thank you in advance.

chegdan October 26, 2012 05:46

For the face centers on the patches, try something like

Code:


const fvPatchList& patches = mesh.boundary();
const surfaceVectorField& faceCenters = mesh.Cf();

scalar px;
scalar py;
scalar pz;

forAll(patches,patchi){

    label nFaces = mesh.boundaryMesh()[patchi].size();

    for(int facei = 0 ; facei<nFaces, facei++){
        px = faceCenters.boundaryField()[patchi][facei].x()
        py = faceCenters.boundaryField()[patchi][facei].x()
        pz = faceCenters.boundaryField()[patchi][facei].x()       
    }
}

I didn't compile this so there might be some errors, but you get the idea. You can look at the Doxygen documentation for more detail. Also, glance at the utilities for inspiration. good luck.

Edit: the next solution seems much more elegant :)

ngj October 26, 2012 05:54

Hi Heckmann,

The OpenFoam-formatted output can be achieved in the following way:

Code:

IOField<vector> cfOut
(
    IOobject
    (
        "cf",
        mesh.time().timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    mesh.Cf().boundaryField()[ patchID ]
);

cfOut.write();

This writes the face centres of a given boundary patch to the current time directory. Relevant with the time directory, if the outputted variables are changing in time. You can do the same thing with other variables. Merely rememeber to change "<vector>" to something else, if the data format differs.

Kind regards,

Niels

fredo490 October 26, 2012 06:38

Thank you for yours answer :)

@chegdan
Your function does something very similar to mesh.Cf().boundaryField()[wallPatch] but with each component separably. My question is more about how to export those data to a file in a convenient way. I don't really know how OpenFoam manage to write things on the hard drive.

@ngj
Your solution looks perfect ! I didn't know that we can use such direct coding into the solver. I will try your method this weekend and study the IOField.

Thanks guys.
(I'm still open to any other method)

ngj October 26, 2012 06:49

P.S. You could also add an if-statement around the above code, which looks like this

Code:

if ( runTime.write() )
{
    // The code above
}

where runTime.write() returns true, if data should be written during this time step. Otherwise it returns false. If you do not include it, the additional information you request is written each time step.

/ Niels

tfuwa November 9, 2012 09:56

Hi Niels,

Greetings. Can you please enlighten me on how to output the pressure integration along a slice of any patch. I would like to solve the sectional force along a certain structure. Thanks in advance!

Kind regards,
Albert


Quote:

Originally Posted by ngj (Post 388632)
Hi Heckmann,

The OpenFoam-formatted output can be achieved in the following way:

Code:

IOField<vector> cfOut
(
    IOobject
    (
        "cf",
        mesh.time().timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    mesh.Cf().boundaryField()[ patchID ]
);

cfOut.write();

This writes the face centres of a given boundary patch to the current time directory. Relevant with the time directory, if the outputted variables are changing in time. You can do the same thing with other variables. Merely rememeber to change "<vector>" to something else, if the data format differs.

Kind regards,

Niels


samiam1000 March 14, 2014 07:44

Hi All,

I am interested in such a problem.

I have a patch called "airfoil" and I would like to write the normals to each face on the patch in a text file.

Do you know how I can get this?

Thanks a lot,
Samuele

Moseli May 9, 2016 18:28

Hi Niels, with regards to the block of code you wrote above , does it have to be in the creatFields header file for the output to be exported for post processing. Or can it still be added in the main function of the solver. I will appreciate your help


All times are GMT -4. The time now is 11:31.