CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   magSf() on boundaries (

lichmaster March 14, 2012 10:53

magSf() on boundaries
Hi FOAMers,

how do I get magSf() on bounday faces?

I noticed that mesh.magSf()[faceI] gives correct results on internal faces, but when faceI is on a face, it gives ~1e-320...


label startFace = mesh.boundaryMesh()[ib].start();
label nFaces    = mesh.boundaryMesh()[ib].size();
for (label faceI = startFace; faceI < startFace + nFaces; faceI++)
vector normal = mesh.Sf()[faceI]/mesh.magSf()[faceI]; \\floating point error

What's wrong ?

lichmaster March 15, 2012 05:22

I've solved this problem, simply taking


However, I really can't understand why there isn't a mesh.magSf() method for boundary faces when there is a mesh.Sf() method defined on them...

ngj March 15, 2012 05:30


You should be able to access the data in any of the following manners:


const scalarField magnitude0 = Foam::mag( mesh.Sf().boundaryField()[patchi] );
const scalarField & magnitude1 = mesh.magSf().boundaryField()[patchi];

This gives you the magnitude of the normal vectors on a given patch through its index patchi.

Best regards,


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