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

question about mesh.sf[faceI]mesh.sf[faceI]

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By Friederike
  • 1 Post By Jerryfan
  • 1 Post By Jerryfan
  • 1 Post By Zeppo

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 12, 2015, 07:59
Default question about mesh.sf[faceI]mesh.sf[faceI]
  #1
New Member
 
Join Date: Nov 2010
Posts: 10
Rep Power: 15
Friederike is on a distinguished road
Hi FOAMers,
I need to loop over all faces of a cell and collect fluxes. I have a 2D case so i set the boundaries with face normal in y-direction to empty.

I use the following code:

PHP Code:
// loop over all cells:
forAll(mesh.C(), cellI
{
   
Info << "******* CellID: " << cellI << "*******"<< endl;

  
//Getting list of all faces of current cell
  
const labelListfaces mesh.cells()[cellI];

  
//loop over all faces of current cell
  
forAllfacesfaceI )
  {   
    if (
mesh.isInternalFace(faces[faceI]))
     {   
       
Info << "internal faceI: " << faceI << "    mesh.Sf()[faceI]: " << -mesh.Sf()[faceI] << "    mesh.magSf()[faceI]: " << mesh.magSf()[faceI] << endl;
     }   
     else
     {   
       
Info << "boundary faceI: " << faceI << "    mesh.Sf()[faceI]: " << -mesh.Sf()[faceI] << "    mesh.magSf()[faceI]: " << mesh.magSf()[faceI] << endl;
     }   

  } 
//move on to next face  
  
Info << " " << endl;
}
//move on to next cell 
The output of this is:
PHP Code:
******* CellID1*******
internal faceI0    mesh.Sf()[faceI]: (---0)    mesh.magSf()[faceI]: 1
internal faceI
1    mesh.Sf()[faceI]: (---1)    mesh.magSf()[faceI]: 1
boundary faceI
2    mesh.Sf()[faceI]: (---0)    mesh.magSf()[faceI]: 1
boundary faceI
3    mesh.Sf()[faceI]: (---1)    mesh.magSf()[faceI]: 1
boundary faceI
4    mesh.Sf()[faceI]: (---0)    mesh.magSf()[faceI]: 1
internal faceI
5    mesh.Sf()[faceI]: (---1)    mesh.magSf()[faceI]: 1

******* CellID2*******
internal faceI0    mesh.Sf()[faceI]: (---0)    mesh.magSf()[faceI]: 1
internal faceI
1    mesh.Sf()[faceI]: (---1)    mesh.magSf()[faceI]: 1
boundary faceI
2    mesh.Sf()[faceI]: (---0)    mesh.magSf()[faceI]: 1
boundary faceI
3    mesh.Sf()[faceI]: (---1)    mesh.magSf()[faceI]: 1
boundary faceI
4    mesh.Sf()[faceI]: (---0)    mesh.magSf()[faceI]: 1
internal faceI
5    mesh.Sf()[faceI]: (---1)    mesh.magSf()[faceI]: 1

******* CellID3*******
internal faceI0    mesh.Sf()[faceI]: (---0)    mesh.magSf()[faceI]: 1
internal faceI
1    mesh.Sf()[faceI]: (---1)    mesh.magSf()[faceI]: 1
boundary faceI
2    mesh.Sf()[faceI]: (---0)    mesh.magSf()[faceI]: 1
boundary faceI
3    mesh.Sf()[faceI]: (---1)    mesh.magSf()[faceI]: 1
boundary faceI
4    mesh.Sf()[faceI]: (---0)    mesh.magSf()[faceI]: 1
internal faceI
5    mesh.Sf()[faceI]: (---1)    mesh.magSf()[faceI]: 
My question now are:
Why are all vector components negative (it stays like that for the whole grid)?
Why are there no vectors with a y-Component? Is this because of the pseudo 2D grid?
I get the same output with a zeroGradient boundary condition for the third dimension.
I don't want to sum over the boundaries which are set to empty. I guess I could also use this as a condition but I still would like to know why mesh.Sf() behaves so wired.

I have looked for some time now but could not find an answer...

Thanks for any help and suggestions!!!
Cheers
friederike
SHUBHAM9595 likes this.
Friederike is offline   Reply With Quote

Old   July 23, 2016, 14:47
Default
  #2
New Member
 
stater's Avatar
 
H. Omar
Join Date: Mar 2013
Posts: 23
Rep Power: 13
stater is on a distinguished road
Hi Friederike,
I know it is an old thread, but actually i am stuck on the same issues, so I am interested to know if you have already found the answers to your questions
Thank you
stater is offline   Reply With Quote

Old   July 25, 2016, 09:38
Default
  #3
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 12
Jerryfan is on a distinguished road
Hi Friederike,


Are you still stuck with this problem? I found at least two problems with the above code:
First of all, The index of
Quote:
mesh.Sf()[faceI]
shouldn't be faceI. It should be faces[faceI] so that you can get the global face index.
Secondly, you cannot get the surface area vector for boundary faces as Sf() only contains area vectors for internal faces.

As for why all the vector components stay negative, it is because of the mesh (all the surface normal directions are positive). For example, face 0 seems to be negative for cell 1 in x direction, but because of the owner and neighbor rule, it's always pointing from cell 0 (owner) to cell 1 (neighbor) such that it's still (-1, 0, 0).

As for why y-component is always 0, the reason is that you will not be able to get the surface vector based on Sf() even if you correct the index as suggested above. You have to access the boundary faces through the fvBoundaryMesh variable boundary_.

I hope it can help you.
LogiDF likes this.
Jerryfan is offline   Reply With Quote

Old   July 27, 2016, 13:00
Default
  #4
New Member
 
stater's Avatar
 
H. Omar
Join Date: Mar 2013
Posts: 23
Rep Power: 13
stater is on a distinguished road
Hi,

For the first question. I think the negative value of vector components is due to the presence of the "-" character in the code just near the mesh.Sf()[faceI]

Best regards
stater is offline   Reply With Quote

Old   July 27, 2016, 14:40
Default
  #5
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 12
Jerryfan is on a distinguished road
Hi stater,


You are right. As I mentioned above, all the surface normal directions are positive. After putting am "-" sign in front, all becomes negative. In addition to this, what I was trying to say above is that some surfaces "seem" to have negative direction, but because of the owner-neighbour convention, they are still positive.
D.R. likes this.
Jerryfan is offline   Reply With Quote

Old   May 14, 2017, 01:05
Default
  #6
Member
 
Ashish Kumar
Join Date: Jun 2015
Posts: 33
Rep Power: 10
ashish.svm is on a distinguished road
How to get area vector for boundary faces.

As mentioned in the first question in this thread, If a particular face is an internal face then only mesh.Sf() works.
ashish.svm is offline   Reply With Quote

Old   May 14, 2017, 11:23
Default
  #7
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
Zeppo will become famous soon enough
Quote:
Originally Posted by ashish.svm View Post
How to get area vector for boundary faces.
Code:
const fvBoundaryMesh& boundary = mesh.boundary();
forAll(boundary, i)
{
    const fvPatch& patch = boundary[i];
    const vectorField& patchSf = patch.Sf();
}
or
Code:
const volVectorField::GeometricBoundaryField& boundaryField = mesh().Sf().boundaryField();
forAll(boundaryField, i)
{
    const fvPatchVectorField& patchField = boundaryField[i];
    const vectorField& patchSf = patchField.internalField();
}
floquation likes this.
Zeppo is offline   Reply With Quote

Old   May 15, 2017, 00:17
Default
  #8
Member
 
Ashish Kumar
Join Date: Jun 2015
Posts: 33
Rep Power: 10
ashish.svm is on a distinguished road
Hi Sergie,

Thanks for your reply. I tried the following code

forAll( cellIfaces, i ) // loop over all faces in the cellIndex
{
if(mesh.isInternalFace(cellIfaces[i])) // If face is internalFace
{
vector faceNormal = mesh.Sf()[cellIfaces[i]] / mesh.magSf()[cellIfaces[i]];
}
else // If face is boundaryFace
{
label patchID = mesh.boundaryMesh().whichPatch(cellIfaces[i]);
label faceID = mesh.boundaryMesh()[patchID].whichFace(cellIfaces[i]);
vector faceNormal = mesh.Sf().boundaryField()[patchID][faceID] / mesh.magSf().boundaryField()[patchID][faceID];
}
}


This compiles successfully, but during case run, it shows an error because one of the patches was defined as empty patch type. I am getting the following error:

--> FOAM FATAL ERROR:
attempt to access element from zero sized list

Can you please suggest some way resolve or get around with this type of error.
ashish.svm 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
small question about the functionalities of topological changes in OpenFoam ngj OpenFOAM Running, Solving & CFD 2 February 28, 2013 10:02
Question Re Engineering Data Source imnull ANSYS 0 March 5, 2012 13:51
internal field question - PitzDaily Case atareen64 OpenFOAM Running, Solving & CFD 2 January 26, 2011 15:26
question on bounday layer modeling Wen Long Main CFD Forum 2 November 12, 2005 17:29
Poisson Solver question Suresh Main CFD Forum 3 August 12, 2005 04:37


All times are GMT -4. The time now is 04:58.