CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Meshing & Mesh Conversion

[Other] Point inside Cell

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 3, 2008, 08:49
Default Point inside Cell
  #1
New Member
 
Robert Manning
Join Date: Mar 2009
Posts: 12
Rep Power: 17
bobatpurdue is on a distinguished road
Is there a quick way to determine the volume of a cell that is cut by a surface? Also, is there a way to determine if an arbitrary point is in inside a cell?
bobatpurdue is offline   Reply With Quote

Old   November 3, 2008, 09:11
Default Hi Robert Please try mes
  #2
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 18
jaswi is on a distinguished road
Hi Robert

Please try

mesh.findCell(location);

where location is a point defined as:

point location(x y z);

Once you have the label of the cell where point is located you can get its volume as well.

Hope that helps

Regards
Jaswi
jaswi is offline   Reply With Quote

Old   November 4, 2008, 15:37
Default Thanks Jaswi for your help. H
  #3
New Member
 
Robert Manning
Join Date: Mar 2009
Posts: 12
Rep Power: 17
bobatpurdue is on a distinguished road
Thanks Jaswi for your help. How do I make a pointField structure from several individual vectors?
bobatpurdue is offline   Reply With Quote

Old   November 4, 2008, 16:02
Default Hi Robert Sorry I did not g
  #4
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 18
jaswi is on a distinguished road
Hi Robert

Sorry I did not get that question :-).

Well as far as I know pointField is a field of points and field itself is a List of a <type>.

So if you have certain number of individual vectors then you can create a pointField of certain size as you would do for an array and then assign your vectors as the elements of array . The code might look something like this:

pointField myField(size,vector::zero);
myField[0] = vector1(x,y,z);
myField[1] = vector2(x,y,z);

and so on.....

Please let me know if this doesn't works ...

Hope that helps

Regards
Jaswi
jaswi is offline   Reply With Quote

Old   November 6, 2008, 11:36
Default Thanks Jaswinder. It works we
  #5
New Member
 
Robert Manning
Join Date: Mar 2009
Posts: 12
Rep Power: 17
bobatpurdue is on a distinguished road
Thanks Jaswinder. It works well. I'm currently trying to debug a code that I wrote which initializes gamma based on an STL file. It is slightly different than "surfaceToCell" because it will set gamma to a fraction of the cell that is cut by the surface. It places hundreds of points within each cell that is cut by the surface. It then calculates the fraction that is interior using surfaceToPoint. However it seems that surfaceToPoint returns some false-negatives if the point is in the cell. Anyone willing to give me a hand? I can post or email you the code and STL file.

Thanks,
Bob
bobatpurdue is offline   Reply With Quote

Old   November 7, 2008, 11:20
Default Hi Robert I can give it a
  #6
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 18
jaswi is on a distinguished road
Hi Robert

I can give it a try

Regards
Jaswi
jaswi is offline   Reply With Quote

Old   November 8, 2008, 20:24
Default Thanks Jaswi. Is there anyway
  #7
New Member
 
Robert Manning
Join Date: Mar 2009
Posts: 12
Rep Power: 17
bobatpurdue is on a distinguished road
Thanks Jaswi. Is there anyway to post a compressed file? If not, email me at "BobatPurdue" at "yahoo.com".

Thanks,
Bob
bobatpurdue is offline   Reply With Quote

Old   November 11, 2008, 21:32
Default I attached a short code that s
  #8
New Member
 
Robert Manning
Join Date: Mar 2009
Posts: 12
Rep Power: 17
bobatpurdue is on a distinguished road
I attached a short code that sees if points are within a STL surface. It reads gamma.stl. However, there appears to be a bug. It reports that points are both interior and exterior to the surface when they are both inside the surface. Possible bug / limitation of the code / programmer error ? I can attach the gamma.stl if needed.

Thanks,
Bob

---- CODE -----

#include "argList.H"
#include "Time.H"
#include "fvMesh.H"
#include "topoSetSource.H"
#include "cellSet.H"
#include "volFields.H"
#include "triSurface.H"
#include "Random.H"
#include "triSurfaceSearch.H"

using namespace Foam;

int main(int argc, char *argv[])
{
//Random
Random rndGen(label(0));

// Temp variables
scalar currentx;
scalar currenty;
scalar currentz;
scalar randnum;

// Point list
pointField cellPoints(10,vector::zero);

// Random point in cell
vector currentpoint = vector::zero;

forAll(cellPoints,pointsi)
{
randnum = rndGen.scalar01();
currentx = (randnum-0.5)*0.57735*2;
randnum = rndGen.scalar01();
currenty = (randnum-0.5)*0.57735*2;
randnum = rndGen.scalar01();
currentz = (randnum-0.5)*0.57735*2;
currentpoint = Vector<scalar>(currentx,currenty,currentz);
cellPoints[pointsi] = currentpoint;
}

// Select Surface
triSurface surf("gamma.stl");
triSurfaceSearch querySurf(surf);

// determine if points inside surface
boolList pointInside(querySurf.calcInside(cellPoints));

forAll(pointInside, pointI)
{
bool isInside = pointInside[pointI];

cout << cellPoints[pointI].x() << " " << cellPoints[pointI].y() << " " << cellPoints[pointI].z();
if (isInside)
cout << " Inside\n";
else
cout << " Outside\n";
}
return 0;
}
bobatpurdue is offline   Reply With Quote

Old   April 25, 2019, 12:15
Default
  #9
Member
 
Join Date: Feb 2016
Posts: 41
Rep Power: 10
LeeRuns is on a distinguished road
Did this ever get resolved?
I am in need of the same utility but don't want to re-invent the wheel if this has already been done.
LeeRuns 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
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 12:04
decomposePar problem: Cell 0contains face labels out of range vaina74 OpenFOAM Pre-Processing 37 July 20, 2020 06:38
Fluent UDF wrong number of cells in parallel - correct in serial dralexpe Fluent UDF and Scheme Programming 7 May 17, 2018 09:26
Simulating fire in a tunnel luca1992 OpenFOAM 14 August 16, 2017 14:50
FvMatrix coefficients shrina OpenFOAM Running, Solving & CFD 10 October 3, 2013 15:38


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