CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Extracting cell index from x y z coordinates (http://www.cfd-online.com/Forums/openfoam-solving/59470-extracting-cell-index-x-y-z-coordinates.html)

 kdarc August 30, 2007 11:20

for the purposes of matching s

for the purposes of matching some reference points to data, I would like to be able to specify a geometrical point ie; (x,y,z) coordinate values, and have a cell index corresponding to that position returned.

Any ideas on how to do this would be most appreciated.

 hjasak August 30, 2007 11:24

Have a look at Probe and relat

Have a look at Probe and related classes - they will give you a data stream for selected field in a specified point in space.

Hrv

 kdarc August 30, 2007 11:26

what I wanted to add to the ab

what I wanted to add to the above message is something along the lines of:

the above question is surely a typical wish of a lot of new OF users, and it must have already been asked on this forum, but I'm NEVER able to find simple tips like this when I search this site. Same thing with
the simple thing like using Foam::pow(a,b) for real exponents, the manual just says pow(a,b) and doesn't make the explicit distinction between integer and real cases. As everyone knows, simple simple problems like this are enough to halt work, and I'm frustrated that I always know exactly WHAT to do, but often cannot find HOW to do it.

are there some tips on searching this site, or some kind of searchable archive of this kind of practical tips for OF??

thanks.

 kdarc August 30, 2007 11:49

probe seems to extract FIELD v

probe seems to extract FIELD values at points, I don't want that, I want the CELL NUMBER at a given point?

Is it possible to get the cell index with probe??

 hjasak August 30, 2007 12:20

Much easier: mesh.findCell(

Much easier:

mesh.findCell(point(1, 2, 3));

This gives you the cell index nearest to the point (1 2 3) or -1 if the point is outside of the mesh.

Enjoy,

Hrv

P.S. Fantastic code, huh?

 kdarc August 30, 2007 13:15

Thanks! back on the rails,

Thanks!

back on the rails, headed for the next crash...

 heavy_user March 5, 2010 13:51

Hi Kdarc,

if you stop by here once in a while...would you mind posting the file in which you used the "mesh.findCell(point(x,y,z));" command ?

regards

 dmoroian March 23, 2010 08:20

coordonate -> cell index

This was a need for me too, so here is the snippet:
Code:

#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
# include "setRootCase.H"
# include "createTime.H"
# include "createMesh.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Info<< "\nindex of the closest cell to (0,0,0): " << mesh.findCell(point(0,0,0)) << "\n" << endl;
return(0);
}

//************************************************************ //

 dmoroian March 23, 2010 10:01

How does the mesh.findCell(point(0,0,0)) work in parallel?
It returns -1 if the point is not inside the partition, which obviously will happen for all the partitions but one.
What is the usual way to set the reference pressure for a parallel computation?

Dragos

 gironidegirona February 2, 2013 12:07

Hi!

I'm quite new to on all this OpenFoAM thing and I need you help. When you talk about getting the cell index by the reference of a point, if it is contained in any cell, how do you send the command.

I've been working with python to execute the simulation, stop it, rewrite some files etc.. but I dunno how to launch the command to get those. Where do I have to put the lines you told?

Thank you in advantage, and sorry for that elementary question.

 dmoroian February 2, 2013 13:06

Quote:
 Originally Posted by gironidegirona (Post 405639) Hi! I'm quite new to on all this OpenFoAM thing and I need you help. When you talk about getting the cell index by the reference of a point, if it is contained in any cell, how do you send the command. I've been working with python to execute the simulation, stop it, rewrite some files etc.. but I dunno how to launch the command to get those. Where do I have to put the lines you told? Thank you in advantage, and sorry for that elementary question.
Hello... do you have a name?
The line "mesh.findCell(point(0,0,0))" is usually put in a solver or utility, then it is compiled, and finally executed. What you mention about python is usually related to the execution stage (and most likely not yet implemented).

Dragos

 gironidegirona February 2, 2013 13:35

Hi and thanks Dragos,

Sorry for not presenting myself, I'm Sergi.

Ok I see how it works, but what I was really looking for is a command to be thrown from the terminal like I say "setFields" or "icoFoam". Isthere anything like that??

Thanks again!

Sergi

 dmoroian February 2, 2013 13:50

Not as far as I'm aware, but just for that, I think it would be very easy to write your own utility. One that gets as input the coordinates and outputs the index. However, I'm not sure what would you do with that index.

Dragos

 gironidegirona February 2, 2013 13:54

Thanks again Dragos,

Actually I'm using interFoam to run a multiphase simulation, and i want to substract and add fluid to certain points. Adding it is easy, i've done it using setfields, but the thing substracting it. The alphas are ordered by cell index, if I know the coordinates from where I've to substract the fluid i can find the cell and it's index.

Maybe there other ways to sort it out.

Thanks anyway, I'll give another thought to all of that.

Thanks,
sergi

 All times are GMT -4. The time now is 15:41.