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

Access cell face center / cell vertices

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By fumiya

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 19, 2011, 07:10
Question Access cell face center / cell vertices
  #1
New Member
 
Lorenzo A. Ricciardi
Join Date: Mar 2011
Posts: 27
Rep Power: 15
lichmaster is on a distinguished road
Hi all,

I'm back again with one question
If I'm inside a cell loop like

Code:
for (label i = 0; i < iMesh.C().size(); i ++) {
...
}
Is there a way to gain access to that specific cell face centers list or cell vertices list?

I need to control weather I'm inside a moving region that I've defined from dictionary...
lichmaster is offline   Reply With Quote

Old   July 19, 2011, 08:05
Red face
  #2
New Member
 
Lorenzo A. Ricciardi
Join Date: Mar 2011
Posts: 27
Rep Power: 15
lichmaster is on a distinguished road
Searching deeper in the huge list of files I found a
Code:
Foam::label Foam::primitiveMesh::findCell(const point& location) const
It should do what I need
lichmaster is offline   Reply With Quote

Old   July 19, 2011, 10:50
Default
  #3
New Member
 
Lorenzo A. Ricciardi
Join Date: Mar 2011
Posts: 27
Rep Power: 15
lichmaster is on a distinguished road
Sadly it's not a good solution.

I really need to cycle through all the cells and gain access to it's vertices or to it's face centers, any help?
lichmaster is offline   Reply With Quote

Old   July 19, 2011, 16:25
Default
  #4
Senior Member
 
Pablo
Join Date: Mar 2009
Posts: 102
Rep Power: 17
pablodecastillo is on a distinguished road
Look this;


00074 void Foam:rimitiveMesh::makeFaceCentresAndAreas
00075 (
00076 const pointField& p,
00077 vectorField& fCtrs,
00078 vectorField& fAreas
00079 ) const
00080 {
00081 const faceList& fs = faces();
00082
00083 forAll (fs, facei)
00084 {
00085 const labelList& f = fs[facei];
00086 label nPoints = f.size();
00087
00088 // If the face is a triangle, do a direct calculation for efficiency
00089 // and to avoid round-off error-related problems
00090 if (nPoints == 3)
00091 {
00092 fCtrs[facei] = (1.0/3.0)*(p[f[0]] + p[f[1]] + p[f[2]]);
00093 fAreas[facei] = 0.5*((p[f[1]] - p[f[0]])^(p[f[2]] - p[f[0]]));
00094 }
00095 else
00096 {
00097 vector sumN = vector::zero;
00098 scalar sumA = 0.0;
00099 vector sumAc = vector::zero;
00100
00101 point fCentre = p[f[0]];
00102 for (label pi = 1; pi < nPoints; pi++)
00103 {
00104 fCentre += p[f[pi]];
00105 }
00106
00107 fCentre /= nPoints;
00108
00109 for (label pi = 0; pi < nPoints; pi++)
00110 {
00111 const point& nextPoint = p[f[(pi + 1) % nPoints]];
00112
00113 vector c = p[f[pi]] + nextPoint + fCentre;
00114 vector n = (nextPoint - p[f[pi]])^(fCentre - p[f[pi]]);
00115 scalar a = mag(n);
00116
00117 sumN += n;
00118 sumA += a;
00119 sumAc += a*c;
00120 }
00121
00122 fCtrs[facei] = (1.0/3.0)*sumAc/(sumA + VSMALL);
00123 fAreas[facei] = 0.5*sumN;
00124 }
00125 }
00126 }
00127
pablodecastillo is offline   Reply With Quote

Old   July 20, 2011, 07:42
Default
  #5
New Member
 
Lorenzo A. Ricciardi
Join Date: Mar 2011
Posts: 27
Rep Power: 15
lichmaster is on a distinguished road
Hi Pablo
thanks for your reply.

I had already seen the function you're suggesting, but is not what i'm looking for: i'd like to access from a fvMesh.C()[i] (center of cell) to the label of the cell itself to gain direct access to its vertices or the centers of it's faces, without having to pass entire pointFields and receiving vectFields...

findCell does what I need, but it searches on the entire domain to find a cell which contains a generic point, I was hoping to find a much simpler (and faster!) solution...
lichmaster is offline   Reply With Quote

Old   July 21, 2011, 11:39
Default
  #6
Member
 
Claudio
Join Date: Mar 2010
Posts: 57
Rep Power: 16
claco is on a distinguished road
Dear All,

I would like to know if there is a C++ script (also a piece of code, or the post of the needed code lines would be appreciated) that can allow me to store in a file the coordinates of cell centres along with the areas of each cells, for every patch (or the one user specified) of my mesh. In fact, I need these informations for post processing purposes.

I thank You in advance.

Yours Sincerely.

Claudio
claco is offline   Reply With Quote

Old   May 29, 2014, 17:46
Default Did anyone find a solution to this?
  #7
Member
 
Eric Bryant
Join Date: Sep 2013
Location: Texas
Posts: 44
Rep Power: 13
codder is on a distinguished road
Is it possible to list vertices along a patch, like faceCells() gets cell numbers?
codder is offline   Reply With Quote

Old   May 31, 2014, 03:31
Default
  #8
Senior Member
 
fumiya's Avatar
 
Fumiya Nozaki
Join Date: Jun 2010
Location: Yokohama, Japan
Posts: 266
Blog Entries: 1
Rep Power: 19
fumiya is on a distinguished road
Hi,

You can use meshPoints():

Code:
const fvBoundaryMesh& patches = mesh.boundary();
const polyPatch& pp = patches[patchI].patch();
labelList meshPoints(pp.meshPoints()); //label of vertices

forAll(meshPoints, i)
{
    label pointI = meshPoints[i];
    //Write what you want to do
}
Hope this helps,
Fumiya
codder and AnthonyP like this.
__________________
[Personal]
fumiya is offline   Reply With Quote

Reply

Tags
cell vertices, face cells


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
[blockMesh] FATAL ERROR: face 6 in patch 2 does not have neighbour cell face: 4(8 9 21 20) robingilbert OpenFOAM Meshing & Mesh Conversion 28 November 23, 2023 07:32
[Gmsh] Import problem ARC OpenFOAM Meshing & Mesh Conversion 0 February 27, 2010 11:56
interpolation from cell center to vertices Zhang Main CFD Forum 3 August 22, 2003 08:31
calculate cell volume, center...? Paul Main CFD Forum 5 June 21, 2003 13:55
About Cell Center Harry FLUENT 0 December 3, 2000 05:33


All times are GMT -4. The time now is 05:27.