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/)
-   -   Particle property UDF (https://www.cfd-online.com/Forums/fluent-udf/215877-particle-property-udf.html)

LesegoM March 20, 2019 04:36

Particle property UDF
 
Hi guys, I am trying to use a UDF to represent particle scattering but I am getting this error in fluent.

Node 0: Process 1828: Received signal SIGSEGV.

I understand that this means something is wrong with my code. Can I kindly get some assistance. My code is like this:

DEFINE_DPM_PROPERTY(coal_scattering, c, t, tp, T)
{
real mp0;
real mp;
real cf, vf;
real *f;

if (NULLP(tp->pp) ||
NULLP(TP_CELL_THREAD(tp)))
*f = 0.9; /* initial value */

mp0 = TP_INIT_MASS(tp);
mp = TP_MASS(tp);

/* get the original char and volatile fractions
/* and store them in vf and cf:*/
vf = DPM_VOLATILE_FRACTION(tp);
cf = DPM_CHAR_FRACTION(tp);
*f = 0.9*vf - 0.6*(1-vf);

if (!(((mp / mp0) >= 1) ||
((mp / mp0) <= 0)))
{

if ((mp / mp0) < (1 - vf - cf))
{
/* only ash left */
/* vf = cf = 0 */

*f = 0.9*vf - 0.6*(1-vf);
return *f; /*use ash scattering*/
}
else if ((mp / mp0) < (1 - vf))
{
/* only ash and char left */
/* cf = 1 - (1 - vf - cf) / (mp / mp0) */
/* vf = 0 */
*f = 0.9*vf - 0.6*(1-vf);
return *f; /*use char scattering*/
}
else
{
/* volatiles, char, and ash left */
/* cf = cf / (mp / mp0) */
/* vf = 1 - (1 - vf) / (mp / mp0) */
*f = 0.9*vf - 0.6*(1-vf);
return *f; /*use coal scattering*/
}
}
return 0.9;
}

AlexanderZ March 20, 2019 21:42

I recommend you to use Message macro to find, which line leads to error (analog of printf )

Code:

Message("i'm here 1");
best regards

pakk March 21, 2019 04:57

I would be highly suspicious of your use of pointers.
Why do you use *f? As far as I see, you never use it as a pointer.


When you initialize it as "real *f", pointer f points to a random memory address. When you then do "*f = 0.9;", you set the value of that random address to 0.9.


I don't know if you had a reason to use pointers, but my first guess would be that replacing "*f" by "f" would not hurt your program, and might solve the problem.

LesegoM March 21, 2019 23:46

Quote:

Originally Posted by pakk (Post 728435)
I would be highly suspicious of your use of pointers.
Why do you use *f? As far as I see, you never use it as a pointer.


When you initialize it as "real *f", pointer f points to a random memory address. When you then do "*f = 0.9;", you set the value of that random address to 0.9.


I don't know if you had a reason to use pointers, but my first guess would be that replacing "*f" by "f" would not hurt your program, and might solve the problem.

Thank you, I am very new to UDFs and C coding in general. I had seen the *f on the Fluent UDF manual. I did replace *f with just f and the code is now working. Thank you very much.


All times are GMT -4. The time now is 23:43.