CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

Exporting Face Normal of a patch and some other values

Register Blogs Community New Posts Updated Threads Search

Like Tree7Likes
  • 2 Post By fredo490
  • 3 Post By ngj
  • 2 Post By ngj

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 25, 2012, 13:32
Default Exporting Face Normal of a patch and some other values
  #1
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 16
fredo490 is on a distinguished road
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.
fredo490 is offline   Reply With Quote

Old   October 26, 2012, 05:46
Default
  #2
Senior Member
 
Daniel P. Combest
Join Date: Mar 2009
Location: St. Louis, USA
Posts: 621
Rep Power: 0
chegdan will become famous soon enoughchegdan will become famous soon enough
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

Last edited by chegdan; October 26, 2012 at 06:39.
chegdan is offline   Reply With Quote

Old   October 26, 2012, 05:54
Default
  #3
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
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
hua1015, rajibroy and constance13 like this.
ngj is offline   Reply With Quote

Old   October 26, 2012, 06:38
Default
  #4
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 16
fredo490 is on a distinguished road
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)
fredo490 is offline   Reply With Quote

Old   October 26, 2012, 06:49
Default
  #5
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
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
hua1015 and constance13 like this.
ngj is offline   Reply With Quote

Old   November 9, 2012, 09:56
Default
  #6
Member
 
Albert Tong
Join Date: Dec 2010
Location: Perth, WA, Australia
Posts: 76
Blog Entries: 1
Rep Power: 15
tfuwa is on a distinguished road
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 View Post
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
__________________
Kind regards,

Albert
tfuwa is offline   Reply With Quote

Old   March 14, 2014, 07:44
Default
  #7
Senior Member
 
Samuele Z
Join Date: Oct 2009
Location: Mozzate - Co - Italy
Posts: 520
Rep Power: 18
samiam1000 is on a distinguished road
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
samiam1000 is offline   Reply With Quote

Old   May 9, 2016, 18:28
Default
  #8
New Member
 
Ishmael
Join Date: Nov 2014
Posts: 2
Rep Power: 0
Moseli is on a distinguished road
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
Moseli is offline   Reply With Quote

Reply


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



All times are GMT -4. The time now is 02:00.