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

Access cell face center / cell vertices

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By fumiya

Reply
 
LinkBack Thread Tools Display Modes
Old   July 19, 2011, 06:10
Question Access cell face center / cell vertices
  #1
New Member
 
Lorenzo A. Ricciardi
Join Date: Mar 2011
Posts: 27
Rep Power: 5
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, 07:05
Red face
  #2
New Member
 
Lorenzo A. Ricciardi
Join Date: Mar 2011
Posts: 27
Rep Power: 5
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, 09:50
Default
  #3
New Member
 
Lorenzo A. Ricciardi
Join Date: Mar 2011
Posts: 27
Rep Power: 5
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, 15:25
Default
  #4
Member
 
Pablo
Join Date: Mar 2009
Posts: 95
Rep Power: 7
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, 06:42
Default
  #5
New Member
 
Lorenzo A. Ricciardi
Join Date: Mar 2011
Posts: 27
Rep Power: 5
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, 10:39
Default
  #6
Member
 
Claudio
Join Date: Mar 2010
Posts: 57
Rep Power: 6
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, 16:46
Default Did anyone find a solution to this?
  #7
Member
 
Eric Bryant
Join Date: Sep 2013
Location: Texas
Posts: 40
Rep Power: 2
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, 02:31
Default
  #8
Senior Member
 
Fumiya Nozaki
Join Date: Jun 2010
Location: Yokohama, Japan
Posts: 160
Rep Power: 6
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 likes this.
__________________
My slides about OpenFOAM(http://www.slideshare.net/fumiyanozaki96)
Sorry for writing almost in Japanese
fumiya is offline   Reply With Quote

Reply

Tags
cell vertices, face cells

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import problem ARC Open Source Meshers: Gmsh, Netgen, CGNS, ... 0 February 27, 2010 10:56
FATAL ERROR: face 6 in patch 2 does not have neighbour cell face: 4(8 9 21 20) robingilbert OpenFOAM 2 January 18, 2010 20:10
interpolation from cell center to vertices Zhang Main CFD Forum 3 August 22, 2003 07:31
calculate cell volume, center...? Paul Main CFD Forum 5 June 21, 2003 12:55
About Cell Center Harry FLUENT 0 December 3, 2000 04:33


All times are GMT -4. The time now is 21:42.