CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for Polydispersed Particles (https://www.cfd-online.com/Forums/fluent-udf/165883-udf-polydispersed-particles.html)

souria January 28, 2016 09:52

UDF for Polydispersed Particles
 
Dear everyone, I try to write an UDF to introduce my own particle size distribution, which is a log-normal distribution : I write this few lines and I need some help or remarks to make my UDF works. Thanks a lot.

This is the UDF :

******************************************
#include "dpm.h"


#include "udf.h"
#include "dpm.h"



DEFINE_DPM_INJECTION_INIT(Polydisperse_Particle, I)
{
static Injection *injcetion;
nbdiam = I->number_diameters;
static int nbdiam = 2600; /* nombre de diamètres par injection*/
real Yd(real d, real dMed, real Etype, real dmin, real dmax, real dmoy){
/*Yd(diamétre, diamètre median, ecart type)*/
/*Xm(diametre,I->min_diam,I->max_diam,I->mean_diam,I->spread_parameter,I->number_diameters);*/

real diam=d;
real dmin=2;
real dmax=220;
real dmoy=5;
real a=1; /* coefficient*/
real b=2; /* coefficient*/
real c=3; /* coefficient*/
real Etype=2.5; /* ecart type*/
real dMed=19; /* diamter median*/
real term1, term2, term3;
term1=pow(log(d/dMed),2);
term2=exp(-pow(1/2*Etype,2)*terme1);


return 1/d*e*(squart(2*pi))*term2;
}




}

****************************************
Souria
Cheers

`e` January 31, 2016 22:50

What errors are you receiving (if any)? What is your expected distribution of particle diameters and what distribution are you actually getting? Lastly, add a trailing dot for all real numbers (for example "1./d" instead of "1/d" to avoid type casting errors).

souria February 1, 2016 06:00

Quote:

Originally Posted by `e` (Post 583157)
What errors are you receiving (if any)? What is your expected distribution of particle diameters and what distribution are you actually getting? Lastly, add a trailing dot for all real numbers (for example "1./d" instead of "1/d" to avoid type casting errors).

Thanks for yoour reply.
Here is my new version :

#include "udf.h"
#include "dpm.h"



DEFINE_DPM_INJECTION_INIT(Polydisperse_Particle, I)
{
static Injection *injcetion;
static int nbdiam = 20; /* diameternumber*/


real Yd(real d, real dmoy, real sp, real c, real p); {
/*Yd(diamétre, diamètre median, ecart type)*/
/*Xm(diametre,I->min_diam,I->max_diam,I->mean_diam,I->spread_parameter,I->number_diameters);*/
real c=1019;
real sp=1.46;
real dmoy=93.24;
real d=P_DIAM(p);
return c*sp*(pow(d,(sp-1))/pow(dmoy,sp))*exp(-pow(d,sp)/pow(dmoy,sp));
}

real Xm(real d, real dmin, real dmax, real dmoy, real sp, int n);{
real Q1, Q2;
real dmin=200;
real dmax=233;
real sp=1.46;
real d=P_DIAM(p);

Q1=d+(dmax-dmin)/((real)n-1);
Q2=d-(dmax-dmin)/((real)n-1);
if(d<=dmin){
return (1-Yd((dmin+Q1)/2, dmoy,sp));
}
else{
if(d>=dmax){
return Yd((dmax+Q2)/2,dmoy,sp);
}
else{
return (Yd((Q1+d)/2,dmoy,sp)-Yd((d+Q1)/2,dmoy,sp));
}
}
}

I got these errors :
* undeclared identifier : n, dmoy, p
*Error 'Yd' too few arguent to call.


Thanks for your help.

Souria

`e` February 1, 2016 06:14

I'm not sure what you're trying to achieve with the Yd() functions etc. To modify the diameters of particle parcels, you can loop over the injection streams and change the diameter. For example (steady particle simulation):

Code:

DEFINE_DPM_INJECTION_INIT(polydisperse_particles,I)
{
    Particle *p;
    loop(p, I->p)
    {
        P_DIAM(p) = 20.; // apply a polydispersed distribution function here
    }
}


souria February 1, 2016 06:44

I try to apply a distribution to the diameter size , according to this functin (A modified Rosin-Rammler distribution) :

Y(d) = c*sp*(pow(d,(sp-1))/pow(dmoy,sp))*exp(-pow(d,sp)/pow(dmoy,sp));

c= constant
sp=spread number =constant
dmoy=constant
d=particle diametre

but I don't know how to decalare this in the begining of my UDF!

`e` February 1, 2016 19:55

If you're having trouble coding the distribution then use existing code online, for example a C++ code is available here and you could change the code to fit your modified distribution.

souria February 2, 2016 04:09

Quote:

Originally Posted by `e` (Post 583307)
If you're having trouble coding the distribution then use existing code online, for example a C++ code is available here and you could change the code to fit your modified distribution.

Thanks for the information. :)

Souria

tbraun84 January 28, 2019 15:50

Quote:

Originally Posted by souria (Post 583336)
Thanks for the information. :)

Souria

I'm sorry but I'm very new to C language and UDF's. How did you (or how can I) get from the distribution function [Cumulative %wt =y(d)] to the actual assignment of P_DIAM for each stream, ensuring that the final distribution matches?

Could you post an elementary example (e.g. 20 diameters each at 5%-mass perhaps)?


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