|
[Sponsors] |
November 18, 2019, 08:36 |
Loop over face pressure values
|
#1 |
Member
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7 |
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 } } 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 |
|
November 19, 2019, 01:09 |
|
#2 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 |
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]; } |
|
November 19, 2019, 03:21 |
|
#3 |
Member
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7 |
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"); Do I need to #include some special library(ies) to be able to access the fields? //David |
|
November 19, 2019, 11:40 |
|
#4 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 |
Yes, it'll go in the .C file for your function object.
Caelan |
|
November 19, 2019, 11:56 |
|
#5 |
Member
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7 |
I finally got it to work when I included "fvcGrad.H". Does that make sense? What is in that library?
|
|
November 19, 2019, 12:09 |
|
#6 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 |
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 |
|
June 13, 2024, 08:03 |
|
#7 |
Senior Member
Klaus
Join Date: Mar 2009
Posts: 281
Rep Power: 22 |
||
Tags |
pressure field, programming |
|
|
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 |