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

How to access the Cell numbers OpenFOAM framework?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By chrisb2244

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 20, 2014, 23:09
Default How to access the Cell numbers OpenFOAM framework?
  #1
New Member
 
Delstat
Join Date: Apr 2013
Posts: 15
Rep Power: 13
pradeepramesh is on a distinguished road
Dear All,

How to access the Cell numbers in OpenFOAM framework?

I am working on a benchmark case, where i am interested to find the cell numbers. I have to apply "Influx boundary condition" at the right wall (Bold-Red-Line). Hence i m very keen to access the cell numbers of the described domain.

Please find the attached snapshot for a quick reference. Would be great to hear your views on this.

Thank you very much

Pradeep
Attached Images
File Type: jpg OpenFOAM Cell Numbers.jpg (83.2 KB, 184 views)
pradeepramesh is offline   Reply With Quote

Old   August 21, 2014, 03:18
Default
  #2
Senior Member
 
Jens Höpken
Join Date: Apr 2009
Location: Duisburg, Germany
Posts: 159
Rep Power: 17
jhoepken is on a distinguished road
Send a message via Skype™ to jhoepken
Why do you need to access the cell ids (I think that this is what you are after), from the boundary condition?
__________________
Blog: sourceflux.de/blog
"The OpenFOAM Technology Primer": sourceflux.de/book
Twitter: @sourceflux_de
Interested in courses on OpenFOAM?
jhoepken is offline   Reply With Quote

Old   August 21, 2014, 21:10
Default
  #3
New Member
 
Delstat
Join Date: Apr 2013
Posts: 15
Rep Power: 13
pradeepramesh is on a distinguished road
I am trying to find a way to access the mesh information of the domain:
(Mesh - Cells - Faces - Edges - Points - Coordinates )

I am interested to assign source (Influx) on the cells at the boundary. Hence i am keen to know the Cell IDs.

Thank you Jens
pradeepramesh is offline   Reply With Quote

Old   August 22, 2014, 00:12
Default
  #4
New Member
 
Delstat
Join Date: Apr 2013
Posts: 15
Rep Power: 13
pradeepramesh is on a distinguished road
One more aspect is to verify the cell IDs that are extracted from ParaView (SpreadSheet View) with the Cell IDs from the OpenFOAM framework.
pradeepramesh is offline   Reply With Quote

Old   August 22, 2014, 03:53
Default
  #5
Senior Member
 
Jens Höpken
Join Date: Apr 2009
Location: Duisburg, Germany
Posts: 159
Rep Power: 17
jhoepken is on a distinguished road
Send a message via Skype™ to jhoepken
So you need the coordinates of the vertices on the boundary?
__________________
Blog: sourceflux.de/blog
"The OpenFOAM Technology Primer": sourceflux.de/book
Twitter: @sourceflux_de
Interested in courses on OpenFOAM?
jhoepken is offline   Reply With Quote

Old   August 24, 2014, 20:48
Default
  #6
New Member
 
Delstat
Join Date: Apr 2013
Posts: 15
Rep Power: 13
pradeepramesh is on a distinguished road
Yes, coordinate of the vertices at the boundary.

As i mentioned previously, I am keen to apply a source term on a cell (ID xyz) in the domain.

Thank you Jens
pradeepramesh is offline   Reply With Quote

Old   August 24, 2014, 22:20
Default
  #7
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 12
chrisb2244 is on a distinguished road
Firstly, boundary faces have the highest values for the faces. You can iterate through them using something like

Code:
labelList boundaryFaceList(mesh_.nFaces() - mesh_.nInternalFaces());
forAll(boundaryFaceList, faceI)
{
    // Do whatever. For example, to find the cell ID, use
    cellI = mesh_.faceOwner()[faceI + mesh_.nInternalFaces()];
}

This will only get you the list of all faces, however. If you know the physical boundary values of your mesh, you could compare using mesh_.cellCentres()[cellI] or similar, or if you don't know the size of your mesh (as in, for example, 0 left wall -> 10 cm on right wall), you can calculate the normals of the faces using something a little bit like:


Code:
Foam::vector Foam::hexRef4::calcSingleFaceNormal(const pointField& p, const label& faceI) const
{
    const labelList& f = mesh_.faces()[faceI];
    point fCentre = p[f[0]];
 
    vector sumN = vector::zero;
    scalar sumA = 0.0;
 
    label nPoints = f.size();
 
 
    for (label pi = 1; pi < nPoints; pi++)
    {
        fCentre += p[f[pi]];
    }
    fCentre /= nPoints;
 
    for (label pi = 0; pi < nPoints; pi++)
    {
        const point& nextPoint = p[f[(pi + 1) % nPoints]];
        vector n = (nextPoint - p[f[pi]])^(fCentre - p[f[pi]]);
        scalar a = mag(n);
        sumN += n;
        sumA += a;
    }
    // This is to deal with zero-area faces. Mark very small faces
    // to be detected in e.g., processorPolyPatch.
    if (sumA < ROOTVSMALL)
    {
        return vector::zero;
    }
    else
    {
        return 0.5*sumN;
    }
}

The section above takes a pointField and a face index as arguments. faceI is pretty obvious, but for a pointField you want something like mesh_.points().


In all of these examples/sections, mesh_ is a reference to your polyMesh object. See http://www.openfoam.org/docs/cpp/ and search for 'polyMesh' (case sensitive). If it doesn't load a sensible list, refresh the page - that usually helps me.


Once you have the face normal, you can compare it to the direction you expect to be on your right wall. Should work fine. No idea how 'efficient' it is though, so consider that if you're conscious of such things.


(p.s. - you will need to change the class that that function belongs to when you place it where you need it - it is largely copied from an existing OF function, but if I recall correctly, it's from one of the applications, not a library, so copy-pasting and editing as needed into your own code, whilst causing duplication, is probably best. At least, it's what seemed easiest to me)
Kummi likes this.
chrisb2244 is offline   Reply With Quote

Old   August 24, 2014, 22:24
Default
  #8
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 12
chrisb2244 is on a distinguished road
For bonus points, ignore the long section I pasted and instead use

Code:
mesh_.faceAreas()[faceI + mesh_.nInternalFaces()];
// or
mesh_.faceAreas()[faceI];
// as appropriate

since that seems to have a lot of the same code. Can't remember why I didn't just use that, although I suspect it relates to being able to pass a different pointField. (For sub-sections, and new parts of the mesh being generated)
chrisb2244 is offline   Reply With Quote

Old   August 25, 2014, 22:32
Default
  #9
New Member
 
Delstat
Join Date: Apr 2013
Posts: 15
Rep Power: 13
pradeepramesh is on a distinguished road
Thank you very much Christian
pradeepramesh 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
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 05:36
Journal file error magicalmarshmallow FLUENT 3 April 4, 2014 12:25
How can I use complex numbers in OpenFOAM. zola OpenFOAM 1 November 21, 2009 13:54
Modified OpenFOAM Forum Structure and New Mailing-List pete Site News & Announcements 0 June 29, 2009 05:56
how to access each cell of a face? (user fortran) Katariina CFX 3 January 28, 2008 09:16


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