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

Locate a cell with a specific wall Distance value

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 28, 2013, 10:26
Post Locate a cell with a specific field value
  #1
Senior Member
 
M. Montero
Join Date: Mar 2009
Location: Madrid
Posts: 155
Rep Power: 17
be_inspired is on a distinguished road
Hi all,

My intention is know where is the cell with the lowest distance to the wall without using paraFoam. It would give me an indication about where is the problem in the mesh and where I have to change the mesh.

Code:
           Info<< "Calculating wall distance using wallDist function\n" << endl;
           wallDist y(mesh, true);
           Info<< "Writing wall distance to field zDistance" << endl;
           zDistance.internalField()= y;
           Info << " Minimum z Distance"<< min(zDistance) << endl;
           zDistance.write();
	   Info << "location"<< mesh.findCell(zDistance=??)<< endl;
I have looked for it around the forum but I do not know how to extract the cellID of that specific cell and so, to use the mesh.C() option.

Please, could someone help me.
Thanks.

Last edited by be_inspired; May 28, 2013 at 11:32.
be_inspired is offline   Reply With Quote

Old   May 28, 2013, 14:57
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hi Marcelino,

As far as I know, you have to do a search for the cell in question. The brute-force solution is simply to do the following (note, just written out, it might be adjusted for compilation):

Code:
label cellIndex = 0;

forAll( mesh.C(), celli )
{
    if ( y[celli] < y[cellIndex] )
        cellIndex = celli;
}

Info << "The cell index with smallest distance:" << tab << cellIndex << endl;
This will be a bit slow, so I would suggest simply to search all of the cells along the boundaries. You could e.g. do something like the following:

Code:
label cellIndex = 0;

forAll( y.boundaryField(), patchi )
{
    const labelList & faceCells = mesh.boundaryMesh()[patchi].patch().faceCells(); // Something like this, but might not compile.
    
    forAll( faceCells, celli )
    {
        if ( y[faceCells[celli]] < y[cellIndex] )
             cellIndex = faceCells[celli];
    }
}

Info << "The cell index with smallest distance:" << tab << cellIndex << endl;
Kind regards

Niels
ngj is offline   Reply With Quote

Old   May 29, 2013, 06:43
Default
  #3
Senior Member
 
M. Montero
Join Date: Mar 2009
Location: Madrid
Posts: 155
Rep Power: 17
be_inspired is on a distinguished road
Hi Niels,

Thank you very much.I have chosen the second option and works great in a mesh of 20 millions of elements. The only point is that, al least for OF2.1.1, I had to delete a patch() word in one of your code lines.

I post the last version here if someone needs the tool or has to modify it for other purposes.

Thanks a lot
Marcelino

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

           Info<< "Calculating wall distance using wallDist function\n" << endl;
           wallDist y(mesh, true);
           y.write();
           Info<< "Analyzing minimum cell Distance" << endl;
	   label cellIndex=0;
	   forAll ( y.boundaryField(),patchi)
{ 
		const labelList & faceCells = mesh.boundaryMesh()[patchi].faceCells();

		forAll (faceCells, celli)
	{
		if ( y[faceCells[celli]] < y[cellIndex] )
		cellIndex = faceCells[celli];
	}
}

	    Info << "The cell index with smallest distance:" << tab << cellIndex << endl;
	    Info << "Minimum wall distance" << tab << y[cellIndex] << endl;
 	 
	    Info << "Location of the cell with minimum wall distance (X Y Z)" << mesh.C()[cellIndex] << endl;
	
    

    return 0;
}
be_inspired 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
Natural convection in a closed domain STILL NEEDING help! Yr0gErG FLUENT 4 December 2, 2019 01:04
problem with cyclicAMI and wall distance Maff OpenFOAM Bugs 5 August 14, 2014 15:41
wall layer distance in ICEM HEXA F.K. CFX 0 November 3, 2004 04:48
Multicomponent fluid Andrea CFX 2 October 11, 2004 06:12
distance from the wall to the first grid point Wenqing Zhang CFX 0 August 9, 2004 11:08


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