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

Summing phi over all faces in patch

Register Blogs Community New Posts Updated Threads Search

Like Tree9Likes
  • 7 Post By ngj
  • 2 Post By NewtoFOAM

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 7, 2013, 15:26
Default Summing phi over all faces in patch
  #1
New Member
 
David
Join Date: May 2013
Posts: 9
Rep Power: 13
NewtoFOAM is on a distinguished road
Hey,

I am writing a boundary condition and I need to access (not modify) the values of Phi over all the faces in a patch in updateCoeffs()

I went along with something like

const surfaceScalarField& phi = this->db().objectRegistry::lookupObject<surfaceScalarFi eld>("phi");

I thought this might grab the phi field from the openfoam database and i'd be able to just find the faces on my patch....and just sum over the corresponding face entries in the phi list.

I thought this might be good...however this would be for the values of phi everywhere not just in my patch right? so i'd be storing a lot of values I do not need. Also when I check my phi list it doesn't match the Phi files that are created in each timestep directory.

There must be an easy and nice way of just finding the sum(phi) over the faces of my patch.

Thanks in advance. I'm brand new to programming so sometimes this stuff makes me weep.

I'll be combing doxygen and google in the mean time.

David
NewtoFOAM is offline   Reply With Quote

Old   May 7, 2013, 16:17
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hi David,

Welcome to the Forum. You are actually on the right track here, and before I suggest a solution, then please allow me to bring your attention to the "&" in

Code:
const surfaceScalarField & phi = this->db().objectRegistry().lookupObject<surfaceScalarField>("phi");
the "&" means that it is a reference to the object, and if you have not heard about them before, then it is similar to pointer, though much safer to work with. The fact that the object is a reference means, that you are not handling a copy of the entire field, but are being told where the original is placed in the memory, and you are allowed to access this memory as long as you do not alter it; the last part is were the "const" statement in front comes into play.

I hope this helped a bit, and then on to your problem at hand:

Code:
// This line gather the index of the patch
label patchIndex = this->patch().index();

// This is what we already talked about above
const surfaceScalarField & phi = this->db().objectRegistry().lookupObject<surfaceScalarField>("phi");

// This is a reference to the boundaryField of phi, where I am
// using the patch index from above
const scalarField & phiw = phi.boundaryField()[patchIndex];

// Initialise the sumFlux variable
scalar sumFlux = 0.0;

// Sum all of the face values and assign it to sumFlux
sumFlux = Foam::sum(phiw);

// Now, to handle potential parallel computing, this statement sums
// the flux contributions from different processors in case your 
// boundary has been divided by one or more processors.
reduce( sumFlux, sumOp<scalar>() );

// Now you have the complete flux across your boundary for serial and
// parallel computations.
I hope this have helped, and please bare with me, if I elaborated too much on some of the points in the code segment above.

Have a nice evening,

Niels
ngj is offline   Reply With Quote

Old   May 8, 2013, 06:37
Default
  #3
New Member
 
David
Join Date: May 2013
Posts: 9
Rep Power: 13
NewtoFOAM is on a distinguished road
Hi,

perfect ! This was exactly what I was looking for!

I have just one question. When I use
Code:
const surfaceScalarField & phi = this->db().objectRegistry().lookupObject<surfaceScalarField>("phi");
I get this message "error: expected primary-expression before ‘>’ token"

However I noticed that changing it to this works perfectly and matches what I expect

Code:
    const surfaceScalarField & phi = this->db().objectRegistry::lookupObject<surfaceScalarField>("phi");
Thanks again!

David
ngj and Zhiheng Wang like this.
NewtoFOAM 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
y+ and u+ values with low-Re RANS turbulence models: utility + testcase florian_krause OpenFOAM 114 August 23, 2023 06:37
[snappyHexMesh] Add Mesh Layers doesnt work on the whole surface Kryo OpenFOAM Meshing & Mesh Conversion 13 February 17, 2022 08:34
[Other] Mesh Importing Problem cuteapathy ANSYS Meshing & Geometry 2 June 24, 2017 06:29
[snappyHexMesh] No layers in a small gap bobburnquist OpenFOAM Meshing & Mesh Conversion 6 August 26, 2015 10:38
mixerVesselAMI2D's mass is not balancing sharonyue OpenFOAM Running, Solving & CFD 6 June 10, 2013 10:34


All times are GMT -4. The time now is 01:26.