CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing & Mesh Conversion (https://www.cfd-online.com/Forums/openfoam-meshing/)
-   -   [Technical] is there any way to get cell surface area? (https://www.cfd-online.com/Forums/openfoam-meshing/244099-there-any-way-get-cell-surface-area.html)

AbhishekTAMU July 21, 2022 13:18

is there any way to get cell surface area?
 
I know that magSf() function can calculate individual face area. However, I want to know the surface area of a cell just like we can get cell volume by using mesh.V().

Does anyone know how to get the cell surface area?

Thanks in advance !

olesen July 22, 2022 05:43

I don't know where that would normally be needed, so there is no such functionality. However, writing it yourself is not actually too hard I think.


The basic algorithm would entail the following:
  • create a scalarField with size nCells, initialized to zero everywhere.
  • get a const ref to the magSf() field and face owner/face neighbour lists
  • loop over magSf field for faces 0 to nInternalFaces. Add in area contributions to owner and neighbour cells
  • loop over magSf field for faces nInternalFaces to nFaces. Add in area contributions to the owner cells.
  • Done

AbhishekTAMU July 22, 2022 13:35

Hello olesen,

Thank you for your response !

I just want to know where I would need to write this code?

in src/OpenFOAM/meshes/primitiveMesh/ there are two files namely primitiveMeshCellCentresAndVols.C and primitiveMeshFaceCentresAndAreas.C . Do I need to write the code in one of these files or I have to create separate .C file.

AbhishekTAMU July 31, 2022 12:17

Foam::tmp<Foam::scalarField> Foam::cellQuality::cellSurfaceArea() const
{
tmp<scalarField> tresult
(
new scalarField
(
mesh_.nCells(), 0.0
)
);
scalarField& result = tresult.ref();

scalar sumCellArea;
forAll(result,celli)
{
const labelList& cellFaces = mesh_.cells()[celli]; //with this line, I expect to access the faces belonging to cell under consideration.

const vectorField& areas = mesh_.faceAreas();

forAll(cellFaces,facei)
{
sumCellArea=0;
sumCellArea+=mag(areas[facei]);
}
result[celli]=sumCellArea;
}
return tresult;
}

I am trying to find cell surface area. For this, I am trying to access faces belonging to the particular cell and sum their face areas and assign the sum value to 'result' scalar Field whose size is equal to nCells.
Please let me know, if the way I have written code is correct logically.


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