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

Find a particle's distance to a wall

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 3 Post By niklas
  • 1 Post By michaelb

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 12, 2010, 11:23
Default Find a particle's distance to a wall
  #1
New Member
 
Michael Gruber
Join Date: Oct 2009
Location: Graz
Posts: 13
Rep Power: 17
gruber is on a distinguished road
Hello,

I am implementing an algorithm for particle movement. Therefore, I need to calculate the distance between a particle and the wall in the particle's velocity direction (if there is a wall).

I looked for the solution in the Particle and Cloud files but I couldn't find it.

Thank you for your help
gruber is offline   Reply With Quote

Old   May 14, 2010, 04:31
Default
  #2
New Member
 
Michael Gruber
Join Date: Oct 2009
Location: Graz
Posts: 13
Rep Power: 17
gruber is on a distinguished road
Maybe I should rephrase my question. How can three different points of one boundary patch be read out to describe a plane equation? And how can this be done for different boundary patches?

Thank you for your help
gruber is offline   Reply With Quote

Old   February 14, 2012, 09:34
Default
  #3
New Member
 
Michael Bruckner
Join Date: Apr 2009
Location: France
Posts: 27
Rep Power: 17
michaelb is on a distinguished road
Hi Michael,

I'm interested in doing the same thing ie finding particle distance to the wall. Did you come up with a solution to your problem ? I would be thankful if you could share any hints !

Best regards,

Michael
michaelb is offline   Reply With Quote

Old   February 14, 2012, 09:43
Default
  #4
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
Its quite easy, but
can I first ask why you need it?
niklas is offline   Reply With Quote

Old   February 14, 2012, 09:50
Default
  #5
New Member
 
Michael Bruckner
Join Date: Apr 2009
Location: France
Posts: 27
Rep Power: 17
michaelb is on a distinguished road
hi Niklas,

thanks for adressing the problem.
I'm glad you're saying that it is easy, although I'm not sure it will be for me.
I need to get the particle distance to the wall to get some statistics about particle repartition in a complex domain.
Have you done that before? What would be the starting point ? I was thinking about the wallDist function but it spits out a volScalarField which isn't very suitable here...

Cheers,

Michael
michaelb is offline   Reply With Quote

Old   February 14, 2012, 10:08
Default
  #6
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
ok, but just so you know it is an extremely time-consuming operation that you want to perform

first. the easy part

the general formula for the distance between a point and a plane/face

x = particle position
C = face centre (or arbitrary point on a face)
n = wall/face normal, where n must be normalized, i.e | n | = 1

distance = | n .dot. ( x - C) |

next is the time-consuming part.
in order to find the closest distance to a wall you need to extract all the wall-faces and calculate
the distance to each face and pick the closest one.

if you are doing this in parallel it will be slightly trickier, since you need to get the wall-faces on the
other processors and check those as well.

foam already have access functions that give you access to patches and their face normals and face centres,
which you should find quite easy with a little searching.
niklas is offline   Reply With Quote

Old   February 14, 2012, 13:33
Default
  #7
New Member
 
Michael Bruckner
Join Date: Apr 2009
Location: France
Posts: 27
Rep Power: 17
michaelb is on a distinguished road
thanks Niklas,

yep first part was clear,

the second part will require me to dive into the code, which I've pretty much avoided until now... I'll give it a try !

If you are used to deal with lagrangian particle simulation, would you please have a look here and advise ? :
http://www.cfd-online.com/Forums/ope...tml#post344331

Thanks

Michael
michaelb is offline   Reply With Quote

Old   February 14, 2012, 16:34
Default
  #8
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
I realized that the way I described above won't actually work.
Its probably better to just check the distance to all the points on the face.
Still, the code to do it might be of some help.

Code:
const polyBoundaryMesh& patches = mesh.boundaryMesh();

forAllConstIter
(
    typename Cloud<SprayParcel<ReactingParcel<ThermoParcel<KinematicParcel<particle> > > > >, 
    parcels, 
    iter
)
{
    // get the position for the particle                                                                                                                                            
    const vector& position = iter().position();

    scalar distance = GREAT;
    // loop over all patches                                                                                                                                                        
    forAll(patches, patchI)
    {
        if (isA<wallPolyPatch>(patches[patchI]))
        {
            const polyPatch& patch = patches[patchI];
            const vectorField& n = patch.faceNormals();
            const vectorField& C = patch.faceCentres();
            forAll(C, i)
            {
                vector normal = n[i]/mag(n[i]);
                //scalar di = mag(position - C[i]); // distance to face centre
                scalar di = mag( normal & ( position - C[i] ) );
                distance = min(distance, di);
            }
        }
    }
    Info << "distance to wall is " << distance << endl;
}
The reason it won't work is because of this...
in the 'figure' below, it will believe its closer to wall A than wall B

Code:
                                      wall A
                             --------------
         x                  |
                             |
                             |  wall B
Ebrahim, manu305 and AnthonyP like this.
niklas is offline   Reply With Quote

Old   February 15, 2012, 06:59
Default
  #9
New Member
 
Michael Bruckner
Join Date: Apr 2009
Location: France
Posts: 27
Rep Power: 17
michaelb is on a distinguished road
Hello Niklas,

I don't have such sharp edges in my domain, so I guess it will be ok for me...
I cannot get the following compiling though : I 've a problem with the wallDist[k] initialization.
wallDist[] here is the IOField I would like to write in timestep/lagrangian/kinematicCloud/wallDist.

Do you have a suggestion on how to do that correctly ?

Code:
#include "argList.H"
#include "Cloud.H"
#include "IOdictionary.H"
#include "fvMesh.H"
#include "Time.H"
#include "timeSelector.H"
#include "OFstream.H"
#include "passiveParticleCloud.H"
#include "IOPosition.H"

using namespace Foam;

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

int main(int argc, char *argv[])
{
    timeSelector::addOptions();
    #include "addRegionOption.H"

    #include "setRootCase.H"

    #include "createTime.H"
    instantList timeDirs = timeSelector::select0(runTime, args);
    #include "createNamedMesh.H"
    #include "createFields.H"

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

    Info<< "Scanning times to determine distance to wall for cloud " << cloudName
        << nl << endl;



    const polyBoundaryMesh& patches = mesh.boundaryMesh();
    
    forAll(timeDirs, timeI)
    {
        runTime.setTime(timeDirs[timeI], timeI);
        Info<< "Time = " << runTime.timeName() << endl;

        Info<< "    Reading particle positions" << endl;
        passiveParticleCloud myCloud(mesh, cloudName);
        label np = myCloud.size();
        Info<< "    Read " << returnReduce(np, sumOp<label>())
            << " particles" << endl;
            
        IOField<label> wallDist(myCloud.fieldIOobject("wallDist", IOobject::NO_READ), np);
        label k = 0;
        forAllConstIter(passiveParticleCloud, myCloud, iter)
        {
            // get the position for the particle                                                                                                                                            
            const vector& position = iter().position();

            wallDist[k] = GREAT;  //  <----- BAD LINE
            //loop over all patches                                                                                                                      
            forAll(patches, patchI)
            {
                if (isA<wallPolyPatch>(patches[patchI]))  
                {
                    const polyPatch& patch = patches[patchI];
                    const vectorField& n = patch.faceNormals();
                    const vectorField& C = patch.faceCentres();
                    forAll(C, i)
                        {
                            vector normal = n[i]/mag(n[i]);
                            scalar di = mag( normal & ( position - C[i] ) );
                            wallDist[k] = min(wallDist[k], di);
                        }
                }
            }
            //Info << "Distance to wall is " << wallDist[k] << endl;
            k++;
        }
        wallDist.write();
    }
    return 0;
}
Cheers,

Michael
AnthonyP likes this.
michaelb is offline   Reply With Quote

Old   February 15, 2012, 07:22
Default
  #10
New Member
 
Michael Bruckner
Join Date: Apr 2009
Location: France
Posts: 27
Rep Power: 17
michaelb is on a distinguished road
Got it !
The error wasn't where I expected it to be. I had to replace :
IOField<label> wallDist(myCloud.fieldIOobject("wallDist", IOobject::NO_READ), np);
by
IOField<scalar> wallDist(myCloud.fieldIOobject("wallDist", IOobject::NO_READ), np);

cheers,

Michael
michaelb 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
Wall distance volScalarField r2d2 OpenFOAM Running, Solving & CFD 3 October 10, 2018 13:54
UDF: Distance from the wall Gabor FLUENT 6 May 24, 2018 08:27
calculate distance from wall to neighbourig cell centroid rr123 Fluent UDF and Scheme Programming 39 March 14, 2017 02:41
MACRO FOR DIMENSIONLESS WALL DISTANCE Y+ ? Wael FLUENT 7 October 6, 2005 05:24
distance of first node to wall Thorsten CFX 0 August 30, 2005 03:53


All times are GMT -4. The time now is 16:06.