CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Loop over face pressure values

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 18, 2019, 08:36
Default Loop over face pressure values
  #1
Member
 
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7
sippanspojk is on a distinguished road
Hi all,

I am writing my own functionObject where I want to loop over each face in a specified patch and do some computations on the pressure values.

I generated a new file with foamNewFunctionObject. Then I found online the following code snippet that is almost doing what I want:

Code:
const polyBoundaryMesh& boundaryMesh = mesh.boundaryMesh();             // Boundary mesh

forAll(mesh.boundary(), patch)
{
    const word& patchName = mesh.boundary()[patch].name();              // Boundary patch name
    forAll(mesh.boundary()[patch], facei)
    {
        const label& face = boundaryMesh[patch].start() + facei;        // FaceID
    }
}
I would like to add a new variable myPressureField and extract the pressure value in the center of each face in the inner loop. Somthing like this:

Code:
const surfaceScalarField& myPressureField = p.boundaryMesh(); 


forAll(mesh.boundary()[patch], facei)
    {
        const scalar& faceP = myPressureField[patch][facei]
    }

I am new to programming in OpenFOAM so I am more or less guessing how I should do it based on what I can find online.

I would be thankful for some guidance with this.

Cheers,
David
sippanspojk is offline   Reply With Quote

Old   November 19, 2019, 01:09
Default
  #2
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
Here's a bit of code I've used in the past for T values on a patch -- changing for p should be trivial.

Code:
    const volScalarField& Temp = mesh().lookupObject<volScalarField>("T");
    Foam::label patchLabel = mesh().boundaryMesh().findPatchID("myName");
    const Foam::fvPatch& patch = mesh().boundary()[patchLabel];

    forAll(currPatch,facei)
    {
        Foam::label faceCelli = currPatch.faceCells()[facei];
        Foam::scalar Tempi = Temp[faceCelli];
    }
Caelan
clapointe is offline   Reply With Quote

Old   November 19, 2019, 03:21
Default
  #3
Member
 
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7
sippanspojk is on a distinguished road
Thank you Caelan for your answer!

Am I right when I say I should define this directly in my .C file?

At the moment I am just trying out the first row where I define my field, like this:

Code:
    const volScalarField& myPressure= mesh_.lookupObject<volScalarField>("p");
and it doesn't work. I also tried with volVectorFiled and "U" but the same problem.

Do I need to #include some special library(ies) to be able to access the fields?

//David
sippanspojk is offline   Reply With Quote

Old   November 19, 2019, 11:40
Default
  #4
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
Yes, it'll go in the .C file for your function object.

Caelan
clapointe is offline   Reply With Quote

Old   November 19, 2019, 11:56
Default
  #5
Member
 
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7
sippanspojk is on a distinguished road
I finally got it to work when I included "fvcGrad.H". Does that make sense? What is in that library?
sippanspojk is offline   Reply With Quote

Old   November 19, 2019, 12:09
Default
  #6
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
Ultimately you'd need to link in something like fvCFD.H, which most function objects would do (I hope you didn't start from scratch, and copied an existing function object to work from!). That said, while the code I pasted doesn't need fvcGrad.H, it might need something that the .H file loops in. It is used to compute gradients of a volume field. Without seeing the compilation error it is hard to tell.

Caelan
clapointe is offline   Reply With Quote

Old   June 13, 2024, 08:03
Default
  #7
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 281
Rep Power: 22
klausb will become famous soon enough
@sippanspojk


Would you please share your implementation?
klausb is offline   Reply With Quote

Reply

Tags
pressure field, programming


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
question regarding LES of pipe flow - pimpleFoam Dan1788 OpenFOAM Running, Solving & CFD 37 December 26, 2017 15:42
Periodic flow using Cyclic - comparison with Fluent nusivares OpenFOAM Running, Solving & CFD 30 December 12, 2017 06:35
lid-driven cavity in matlab using BiCGStab Don456 Main CFD Forum 1 January 19, 2012 16:00
[blockMesh] Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Meshing & Mesh Conversion 10 April 2, 2007 15:00
what the result is negatif pressure at inlet chong chee nan FLUENT 0 December 29, 2001 06:13


All times are GMT -4. The time now is 18:28.