CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Access cell face center / cell vertices (http://www.cfd-online.com/Forums/openfoam-programming-development/90708-access-cell-face-center-cell-vertices.html)

lichmaster July 19, 2011 06:10

Access cell face center / cell vertices
 
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 July 19, 2011 07:05

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 July 19, 2011 09:50

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?

pablodecastillo July 19, 2011 15:25

Look this;


00074 void Foam::primitiveMesh::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

lichmaster July 20, 2011 06:42

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...

claco July 21, 2011 10:39

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

codder May 29, 2014 16:46

Did anyone find a solution to this?
 
Is it possible to list vertices along a patch, like faceCells() gets cell numbers?

fumiya May 31, 2014 02:31

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


All times are GMT -4. The time now is 17:13.