CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Extracting cell index from x y z coordinates

Register Blogs Community New Posts Updated Threads Search

Like Tree20Likes
  • 16 Post By hjasak
  • 1 Post By kdarc
  • 3 Post By dmoroian

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 30, 2007, 12:20
Default for the purposes of matching s
  #1
Member
 
Ken Darcovich
Join Date: Mar 2009
Location: Ottawa, Canada
Posts: 34
Rep Power: 17
kdarc is on a distinguished road
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.
kdarc is offline   Reply With Quote

Old   August 30, 2007, 12:24
Default Have a look at Probe and relat
  #2
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
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
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   August 30, 2007, 12:26
Default what I wanted to add to the ab
  #3
Member
 
Ken Darcovich
Join Date: Mar 2009
Location: Ottawa, Canada
Posts: 34
Rep Power: 17
kdarc is on a distinguished road
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 is offline   Reply With Quote

Old   August 30, 2007, 12:49
Default probe seems to extract FIELD v
  #4
Member
 
Ken Darcovich
Join Date: Mar 2009
Location: Ottawa, Canada
Posts: 34
Rep Power: 17
kdarc is on a distinguished road
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??
kdarc is offline   Reply With Quote

Old   August 30, 2007, 13:20
Default Much easier: mesh.findCell(
  #5
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
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?
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   August 30, 2007, 14:15
Default Thanks! back on the rails,
  #6
Member
 
Ken Darcovich
Join Date: Mar 2009
Location: Ottawa, Canada
Posts: 34
Rep Power: 17
kdarc is on a distinguished road
Thanks!

back on the rails, headed for the next crash...
Ramkumar21194 likes this.
kdarc is offline   Reply With Quote

Old   March 5, 2010, 13:51
Default
  #7
Senior Member
 
Join Date: Dec 2009
Posts: 112
Rep Power: 17
heavy_user is on a distinguished road
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
heavy_user is offline   Reply With Quote

Old   March 23, 2010, 08:20
Default coordonate -> cell index
  #8
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
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 is offline   Reply With Quote

Old   March 23, 2010, 10:01
Default
  #9
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
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

Last edited by dmoroian; March 24, 2010 at 05:34.
dmoroian is offline   Reply With Quote

Old   February 2, 2013, 12:07
Default
  #10
New Member
 
---
Join Date: Jan 2013
Posts: 17
Rep Power: 13
gironidegirona is on a distinguished road
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.
gironidegirona is offline   Reply With Quote

Old   February 2, 2013, 13:06
Default
  #11
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Quote:
Originally Posted by gironidegirona View Post
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
dmoroian is offline   Reply With Quote

Old   February 2, 2013, 13:35
Default
  #12
New Member
 
---
Join Date: Jan 2013
Posts: 17
Rep Power: 13
gironidegirona is on a distinguished road
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
gironidegirona is offline   Reply With Quote

Old   February 2, 2013, 13:50
Default
  #13
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
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
dmoroian is offline   Reply With Quote

Old   February 2, 2013, 13:54
Default
  #14
New Member
 
---
Join Date: Jan 2013
Posts: 17
Rep Power: 13
gironidegirona is on a distinguished road
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
gironidegirona is offline   Reply With Quote

Old   June 1, 2017, 23:54
Default
  #15
Member
 
Dominic
Join Date: Jan 2017
Posts: 41
Rep Power: 9
DominicTNC is on a distinguished road
Dear dmoroian,

How about inputting the cell index and getting the cell center's coordinates returned ?

Any comments are appreciated. Thanks.

Dominic
DominicTNC is offline   Reply With Quote

Old   June 2, 2017, 01:42
Default
  #16
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
It's a long time since I've touched any openFoam codes, but I think it should be something like:
Code:
mesh.C().internalField()[i].component(0)
where "i" is the cell index and "0" is specifying the x coordinate. The mesh is one example, you could use instead any vector field you have in your calculation, usually is the velocity "U".
dmoroian is offline   Reply With Quote

Old   June 2, 2017, 03:59
Default
  #17
Member
 
Dominic
Join Date: Jan 2017
Posts: 41
Rep Power: 9
DominicTNC is on a distinguished road
Thank you for your quick reply!
I will give it a try!
DominicTNC is offline   Reply With Quote

Old   June 7, 2017, 00:30
Default
  #18
Member
 
Dominic
Join Date: Jan 2017
Posts: 41
Rep Power: 9
DominicTNC is on a distinguished road
Dear dmoroian,

It really works! Thanks so much!
DominicTNC is offline   Reply With Quote

Old   May 8, 2020, 00:08
Default
  #19
New Member
 
Fan
Join Date: Apr 2020
Posts: 5
Rep Power: 6
Fann is on a distinguished road
Quote:
Originally Posted by dmoroian View Post
It's a long time since I've touched any openFoam codes, but I think it should be something like:
Code:
mesh.C().internalField()[i].component(0)
where "i" is the cell index and "0" is specifying the x coordinate. The mesh is one example, you could use instead any vector field you have in your calculation, usually is the velocity "U".
Dear DominicTNC,
How do you enter the velocity U in this code to get the grid center coordinates?

Thanks,
Fann
Fann is offline   Reply With Quote

Old   February 18, 2021, 13:56
Default
  #20
New Member
 
Aaron Luchko
Join Date: Feb 2021
Posts: 1
Rep Power: 0
aluchko is on a distinguished road
In parallel one can get find the processor (or processors) containing a cell using the following snippet.


Note this code runs on every processor, but only processor 0 will print Info statements.


Code:

    List<int> containing_cells(Pstream::nProcs());

    int cell_index = mesh.findCell(point(10, .5, 0));
    containing_cells[Pstream::myProcNo()] = cell_index;
    Pstream::gatherList(containing_cells);

    for (int proc = 0; proc < Pstream::nProcs(); proc++)
    {
        if (containing_cells[proc] != -1)
        {
            Info << "Proc " << proc << " has cell " << containing_cells[cell_index] << endl;
        }
    }
aluchko is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF: Given coordinates, How to identify the cell? Zhang Fluent UDF and Scheme Programming 26 August 15, 2022 06:54
Cell index in fluent Naresh FLUENT 0 May 9, 2007 16:56
?? How to get cell center coordinates? erica FLUENT 0 May 11, 2005 23:02
How to get index of a cell by user subroutine? windhair CFX 1 November 19, 2003 11:30
How to get nodes coordinates for a certain cell ? mikhail FLUENT 2 November 1, 2000 11:18


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