CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Cell minimum side length (https://www.cfd-online.com/Forums/openfoam-programming-development/127267-cell-minimum-side-length.html)

Moslem December 7, 2013 09:23

Cell minimum side length
 
Dear Foamers,
Does anybody know a simple way to determine the minimum edge length for a single cell an for the whole mesh?
Thanks.

ngj December 7, 2013 10:53

Hello,

Yes, you can do something along these lines:

Code:

// Get needed reference to the mesh
const edgeList& edges = mesh.edges();
const pointField& pp = mesh.points();
const labelListList& cEdges = mesh.cellEdges();

// Make a list with all the edge lenghts
scalarField eLengths(edges.size(), 0.0);

forAll (edges, edgei)
{
    eLengths[edgei] = edges[edgei].mag(pp);
}

// Find the minimum edge length in the whole mesh
scalar minLength = Foam::min(eLengths);

// Find the minimum per cell
scalarField minLengthCells(cEdges.size(), GREAT);

forAll (cEdges, celli)
{
    const labelList& ce = cEdges[celli];

    forAll (ce, edgei)
    {
        minLengthCells[celli] = Foam::min(minLengthCells[celli], eLengths[ce[edgei]]);
    }
}

That is it.

Kind regards,

Niels

P.S. Please note that I have not tried to compile it, so there might be minor blops, but the overall idea gives the requested result.

Moslem December 7, 2013 11:31

Thank you Niels!
I will try it.
Moslem

Naresh yathuru February 23, 2015 05:30

hi excuse me for restarting the thread after a long time. i m new to openfoam can some one tell me where to type this above code? i mean in which directory? or in controldict?

Thanks

Moslem February 23, 2015 13:16

It must be added to a source code.

mturcios777 February 23, 2015 13:41

This code would need to be implemented in a utility or solver, then compiled and run on the desired case. You will need to add some kind of output capability for your results, either as a logFile or some kind of field.


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