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/)
-   -   User define memory storage (https://www.cfd-online.com/Forums/fluent-udf/218700-user-define-memory-storage.html)

dhiraj.lote@gmail.com July 1, 2019 05:51

User define memory storage
 
Hello,

I have written UDF for the breakage rate of Coulaloglou and Tavlarides model and interpreted in fluent 17.2 (for population balance modeling).

However, I would like to store a memory of breakage rate. For the same I have used syntax C_UDMI (cell, thread, 0)=breakage rate. But, I am getting this stored value zero everywhere in the domain. Please suggest me the solution.

Here is my UDF,

************************************************** **********************

UDF that computes the particle breakage frequency

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

#include "udf.h"

#include "sg_pb.h"

#include "sg_mphase.h"





DEFINE_PB_BREAK_UP_RATE_FREQ(break_up_freq_tav, cell, thread, d_1)

{

real epsi, alpha, f1, f2, rho_d=1.225;

real C1 = 0.00481, C2 = 0.08, sigma = 0.072;

Thread *tm = THREAD_SUPER_THREAD(thread);/*passed thread is phase*/

epsi = C_D(cell, tm);

alpha = C_VOF(cell, thread);

rho_d = C_R(cell, thread);

f1 = C1*pow(epsi, 1./3.)/((1.+alpha)*pow(d_1, 2./3.));

f2 = -(C2*sigma*(1.+alpha)*(1.+alpha))/(rho_d*pow(epsi,2./3.)*pow(d_1, 5./3.));

C_UDMI(cell, thread, 0) = C1*f1*exp(f2);

return C1*f1*exp(f2);

}

AlexanderZ July 1, 2019 21:05

did you select the name that you specified in the DEFINE macro argument in the appropriate drop-down list under Phenomena in the Population Balance Model dialog box?

udf seems OK, most likely there is some problem with model settings
you may try to put Message macro inside to see what is calculated, but make small mesh for this
Code:

************************************************** **********************

UDF that computes the particle breakage frequency

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

#include "udf.h"

#include "sg_pb.h"

#include "sg_mphase.h"





DEFINE_PB_BREAK_UP_RATE_FREQ(break_up_freq_tav, cell, thread, d_1)

{

real epsi, alpha, f1, f2, rho_d=1.225;

real C1 = 0.00481, C2 = 0.08, sigma = 0.072;

Thread *tm = THREAD_SUPER_THREAD(thread);/*passed thread is phase*/

epsi = C_D(cell, tm);

alpha = C_VOF(cell, thread);

rho_d = C_R(cell, thread);

f1 = C1*pow(epsi, 1./3.)/((1.+alpha)*pow(d_1, 2./3.));

f2 = -(C2*sigma*(1.+alpha)*(1.+alpha))/(rho_d*pow(epsi,2./3.)*pow(d_1, 5./3.));

C_UDMI(cell, thread, 0) = C1*f1*exp(f2);

Message0("epsi = %f | alpha =%f | rho_d =%f | f1 =%f | f2 =%f \n ",alpha,epsi,rho_d,f1,f2);

return C1*f1*exp(f2);

}

best regards

dhiraj.lote@gmail.com July 2, 2019 00:03

Thank you so much for the reply, AlexanderZ.
By putting message macro inside, in fluent it gives error of "CX_Message0" not found (pc=211).

My mesh is just 60000 elements only.

AlexanderZ July 2, 2019 00:05

60000 elements means 60000 messages in console

change message to printf
or compile UDF

best regards

dhiraj.lote@gmail.com July 2, 2019 00:09

Thank you for the reply,
I am new to UDF, dont know much about UDF.
Can you please tell me how to change message to printf

pakk July 2, 2019 08:35

Put the cursor directly after "Message0", press backspace 8 times, and press 'p' on your keyboard, followed by 'r', 'i', 'n', 't' and 'f'.

dhiraj.lote@gmail.com July 3, 2019 06:27

Thank you pakk,
it worked.
But, still the calculated and stored value is zero everywhere, and lots of values (no. of values are more) are showing in fluent consol. how to tackle this.

pakk July 3, 2019 07:33

All those values are shown on your screen for a reason... Look at them!

AlexanderZ July 3, 2019 23:52

this UDF is example from Fluent manual, if it doesn't work, it means you've missed something in settings of your model (not UDF)
did you hook it properly?

best regards

pakk July 4, 2019 03:31

I think that dhiraj has no idea what we are trying to do here...


Dhiraj, the problem that you had was that you got zeros as result. AlexanderZ suggested to add some line that would help to know WHY you got zeros as result.


Look at the last line of your code:
Code:

return C1*f1*exp(f2);
When does this return a zero value? It can be in three cases:
  1. C1 = 0
  2. f1 = 0
  3. exp(f2) = 0 (which means f2 = minus infinity)
Which case are you in? The second or the third, but we don't know which. How to find out? Let the program print the values of f1 and f2!


And that is exactly what AlexanderZ suggested: he wanted you to print the values of f1 and f2 (and thinking ahead, he already added some more values to print). You say that you ran the code and saw many values on your screen. Great, look at them! What do they say for f1 and f2? Is f1 zero? Is f2 minus infinity?


If you see (for example) that f1 is always zero, then you have made the problem smaller! Because then you can find out why f1 is zero. Again, look at the place in your code where f1 is defined, see which values it depends on, and print these values. And you might for example find out that the real problem is that epsi is always zero, because you are not running a turbulent simulation. Or it is something else. But you have to look at the values on your screen, we can not do that for you.


All times are GMT -4. The time now is 04:05.