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

Accessing neighbor cells fields

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 3 Post By duongquaphim

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 11, 2012, 15:11
Default Accessing neighbor cells fields
  #1
New Member
 
Join Date: Oct 2011
Posts: 27
Rep Power: 14
antoniofct is on a distinguished road
Hello all,

I am trying to do an average of cells neighbors. For instance, if I want to get an average of Temperature in the internal field I can easily type

Code:
sum(T.internalField())/mesh.nCells()
.

What could be the function to do it just in cell neighbors? Could it be inside geometricField.C?

Thanks!

António
antoniofct is offline   Reply With Quote

Old   December 11, 2012, 15:37
Default
  #2
Member
 
Duong A. Hoang
Join Date: Apr 2009
Location: Delft, Netherlands
Posts: 93
Rep Power: 17
duongquaphim is on a distinguished road
Send a message via Yahoo to duongquaphim
I think you need to do a bit more for that:

const labelList& neighbour = mesh.cellCells()[celli]

scalar sum = scalar(0);

forAll(neighbour,i)
{
sum += T[neighbour[i]];
}

sum /= neighbour.size();

And loop over all the cells with that will give you an average of cell neighbours.

You can find more of functions relating to the mesh information in primitiveMesh class.

Duong
sina.s, JackW and mAlletto like this.
duongquaphim is offline   Reply With Quote

Old   December 11, 2012, 15:41
Default
  #3
New Member
 
Join Date: Oct 2011
Posts: 27
Rep Power: 14
antoniofct is on a distinguished road
thanks a lot, I will give it a try!

Antonio
antoniofct is offline   Reply With Quote

Old   May 13, 2015, 17:53
Default
  #4
New Member
 
Vitor Geraldes
Join Date: Dec 2009
Location: Lisbon, Portugal
Posts: 26
Rep Power: 16
vitor.geraldes@ist.utl.pt is on a distinguished road
This a nice implementation, but, in parallel, it does not recognize neighbour cells if they are in subdomains different from the one of the central cell. Is there a simple implementation to address this problem?
vitor.geraldes@ist.utl.pt is offline   Reply With Quote

Old   January 20, 2018, 14:45
Default find neighbours in parallel
  #5
Member
 
Thomas Flint
Join Date: Jan 2016
Posts: 60
Rep Power: 10
tom_flint2012 is on a distinguished road
I think if you use field.correctBoundaryConditions(); it will work OK. Where field is the new neighbour field you assign.

This works fine for me

All the best
tom_flint2012 is offline   Reply With Quote

Old   April 30, 2021, 13:55
Default
  #6
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
Hello everybody, for a new hybrid turbulence model I also need to calculate the mean of the current and neighboring cells. I am curious if there is a more efficient way doing the average instead of using a forAll loop?
CFDanielGER is offline   Reply With Quote

Old   May 3, 2021, 02:16
Default
  #7
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by CFDanielGER View Post
Hello everybody, for a new hybrid turbulence model I also need to calculate the mean of the current and neighboring cells. I am curious if there is a more efficient way doing the average instead of using a forAll loop?
It definitely needs a loop (actually more than one) , but if you are doing all cells (not just a single cell) then it makes much more sense to loop across the faces. You obviously need your output field for storing the result and an additional array for counting the number of neighbours.
Walk each internal face, get owner/neighbour locations and use that to add to the output (in two locations) and the neighbour count (again in two locations). After that walk the boundary faces (owner only). Finally, iterate across the boundary patches, adding in the off-processor information.

Finalise your output field by preforming the averaging operation.

Depending on what you need, interpolate cell vales to the faces and vol reconstruct from them could also be an interesting thing to look at.
olesen is offline   Reply With Quote

Old   May 3, 2021, 03:14
Default
  #8
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
Quote:
Originally Posted by olesen View Post
It definitely needs a loop (actually more than one) , but if you are doing all cells (not just a single cell) then it makes much more sense to loop across the faces. You obviously need your output field for storing the result and an additional array for counting the number of neighbours.
Walk each internal face, get owner/neighbour locations and use that to add to the output (in two locations) and the neighbour count (again in two locations). After that walk the boundary faces (owner only). Finally, iterate across the boundary patches, adding in the off-processor information.

Finalise your output field by preforming the averaging operation.

Depending on what you need, interpolate cell vales to the faces and vol reconstruct from them could also be an interesting thing to look at.
I think the last thing you mentioned is how I currently implemented it since I only need to average over the current cell and it's closest neighbors

Code:
volScalarField VTMav = fvc::surfaceSum(this->mesh().magSf() * fvc::interpolate(VTM(gradU))) / fvc::surfaceSum(this->mesh().magSf());
CFDanielGER 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
Time averaged fields on a defined time range Yann OpenFOAM Post-Processing 8 August 7, 2019 04:46
Accessing fields and dictionaries from within a BC implementation alberto OpenFOAM Running, Solving & CFD 12 December 6, 2011 09:30
Missing fields in reconstructPar flowris OpenFOAM 1 July 9, 2010 02:48
domainIntegrate, dieselFoam and Lagrangian Fields mturcios777 OpenFOAM 0 May 14, 2010 15:16
PostChannel maka OpenFOAM Post-Processing 5 July 22, 2009 09:15


All times are GMT -4. The time now is 12:46.