CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Distance between cell center and given patch (http://www.cfd-online.com/Forums/openfoam-programming-development/100076-distance-between-cell-center-given-patch.html)

ic3wall April 19, 2012 12:42

Distance between cell center and given patch
 
Hello,

I'm currently modifying a turbulence model and I'm looking for a way to calculate the distance between a cell center in my domain and the bottom patch. I need the vertical distance, not necessarily the shortest path.

It's probably a trivial question, but I can't find how to do it ..

Thanks

kmooney April 19, 2012 14:43

This will return a scalar field for each patch face. The value returned is one over the perpendicular distance between the cell center and the boundary face, that is (1/deltaX). You can check out the code at fvPatch.C/H


scalarField DnA = mesh.boundary()[myPatchID].deltaCoeffs();

I know its not exactly what you're looking for but it might be a start.

Cheers!

ic3wall April 19, 2012 14:55

Quote:

Originally Posted by kmooney (Post 355701)
This will return a scalar field for each patch face. The value returned is one over the perpendicular distance between the cell center and the boundary face, that is (1/deltaX). You can check out the code at fvPatch.C/H


scalarField DnA = mesh.boundary()[myPatchID].deltaCoeffs();

I know its not exactly what you're looking for but it might be a start.

Cheers!

Thank you for your contribution but as mentionned, I don't necessarily need the perpendicular distance (shortest path), I need the adress of the cell with the same X and Y, but the min(Z) coords of my domain, which correspond the cell on the lower patch. I hope the description is clear ..

So far I have this:

const volVectorField& cellCentres = mesh_.C(); //Coords of cellCentres of all cells
label patchID=mesh_.boundaryMesh().findPatchID("lowerBou ndary");
const vectorField& patchFaceCenters=mesh_.Cf().boundaryField()[patchID]; //Coords of cellCentres faces at lowerBoundary

[This statement will be in a loop over celli]
mesh_.findCell(point(mesh_.C()[celli].component(0),mesh_.C()[celli].component(1),0));

Instead of the 0 in the last statement for the z-coord, I would need something like min(Z)..

kmooney April 19, 2012 15:08

The findCell function will return a -1 label if you leave the mesh. You could take small steps towards the boundary (by changing the z value) until it returns a -1. Then the last non -1 hit was likely to be the boundary cell. I can only guess that this could get pretty expensive however.

ic3wall April 19, 2012 15:13

yeah, I thought about that too, but as you said it becomes computationnally demanding ..

Is there a kind of min() function that can be used with findCell ?

Or is it possible to find all cells with (X,Y,*), and then keep the one with min(Z) ?

ic3wall April 20, 2012 09:45

I just realized that my question would be more appropriate in the Programming and Development Section, it would be appreciated if a moderator could move it.

deepsterblue April 20, 2012 11:21

I think the cellDist functions in ($FOAM_SRC)/meshTools/cellDist is what you're looking for. Cell-distance calculations are integral to several turbulence models, so I would imagine the infrastructure is already in there...

Hope this helps.


All times are GMT -4. The time now is 17:47.