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/)
-   -   Issues with iterating in TRANSIENT state "UDF" (https://www.cfd-online.com/Forums/fluent-udf/150102-issues-iterating-transient-state-udf.html)

Bharadwaj B S March 15, 2015 23:57

Issues with iterating in TRANSIENT state "UDF"
 
Hello all,

I have written an UDF for providing mass flux from the surface of the sphere. In this UDF I have taken some variable called "mass"(mass = 1.0). This "mass" I will have to decrement it to zero by some value lets say 0.2 for every iteration.

Using this value of mass, I am thinking of giving a condition i.e, if "mass>0.0" and "mass<1.0", there should be mass flow rate from the surface. For providing flux there is a separate macro named "F_PROFILE" which is working fine.

In the next post I will post the UDF.

QUESTIONS

Anybody please go through the UDF and tell if I can make changes to decrement "mass", that mass is not reducing.

And if I use for iterations and decrements for(j=1.0;j>0.0;j=j-1). I think it is not decrementing the value of "j" at every iteration. Because the conditions given inside "for loop" is becoming true at every iteration and executing the statements within "for loop" every iteration.

Is there any other way in "TRANSIENT" case to go for next iteration(other than using "j")??????

Thanks in advance,
Bharadwaj B S

Bharadwaj B S March 16, 2015 00:03

Udf
 
Hi all,

The UDF which I have written. Please go through it and suggest me if I can modify this.

UDF:

#include "udf.h"

Thread *t;

DEFINE_PROFILE(flux, t, i)
{

Domain *d;
int ID = 13;
face_t f;
static float mass = 1.0;
int j;
real decrement = 0.2;
float flwrt = -0.5;

for(j=2;j>0;j=j-1)
{
mass=mass-(decrement);
if(mass>0.0&&mass<1.0)
{
begin_f_loop(f, t)/*for looping over the required sphere surface*/
{

d = Get_Domain(1);
t = Lookup_Thread(d, ID);
F_PROFILE(f, t, i) = -flwrt;

}
end_f_loop(f,t)
}
}
}

`e` March 16, 2015 02:14

Firstly, why are you finding out the pointer to the face's thread, t, when this variable is passed from begin_f_loop? Why is the mass variable static?

From the looks of your code, you're looping over the cell faces twice and applying the same constant value of 0.5; is this your intention?

You don't have any code that changes with time steps (your code gives the same output at every point in the simulation). The DEFINE_PROFILE macro is typically called at each time step (unless you change the frequency for which the profile is updated: say every 10 time steps or otherwise).

Bharadwaj B S March 16, 2015 02:32

Errors
 
Dear e,

My knowledge about basics of C programming is very less, I am trying by trial and error methods. First I tried declaring as "real" outside the function (global). It did not work. Fluent was giving mass flow rate (F_PROFILE) all the time.

And for the time step thing, yes I tried with the CURRENT_TIME macro and it worked smoothly with no issues(time b/w 10th second and 20th second).

Please pardon me if the basic rules of C is not followed. I have very less idea about it. Regarding static and other type of declarations.

Thank you,
Bharadwaj B S

`e` March 16, 2015 03:15

While having "static float mass" won't hurt in your case, the static declaration is redundant because you don't use the variable 'mass' inside another function. You should declare your variables inside the DEFINE_PROFILE; specifically, move "Thread *t" below the DEFINE_PROFILE line.

If the UDF is working with using the CURRENT_TIME macro, what would you like help with?

Bharadwaj B S March 16, 2015 03:56

Clarification
 
Dear e,

FIRST
I knew I should move that "Thread *t;" inside the function. But when I moved I was getting error, something related to declaration. So I declared it globally, it got solved.

And, yes in my case the evaporation/devolatilization of gases present inside the sphere(i.e sphere zone inside cylindrical flow zone, named by zone ID 13) should be based on the mass loss rate but not on "TIME" basis. I have the exact time at which devolatilization starts but if I use that it will become just a replica of the real process. So I am required to model it bassed on the loss of mass. That is the reason why I have taken "mass" as a variable and I am trying to reduce that every iteration.

But the mass is not getting decremented, it is always 1.0 or >0.0. I was thinking whether is there any other ways to reduce the variable "mass???

Thank you,
Bharadwaj B S

`e` March 16, 2015 04:53

The thread pointer is a variable passed by the Fluent solver to your UDF: you don't declare or evaluate this variable within your UDF. Have a read of the DEFINE_PROFILE section of the UDF manual.

Your variable 'mass' is created, modified and destroyed every time DEFINE_PROFILE is run by the Fluent solver. This 'mass' variable has no relation to the mass of the cells residing inside the sphere. You can specify density of cells using the C_R macro.

Bharadwaj B S March 16, 2015 06:01

Right.
 
Dear e,

Yes I tried to remove that Thread *t, it said undeclared symbol or something. So I kept it as it is.

Yes dear e, I know that variable "mass" will not anywhere related to the physical "mass" in fluent.

It is just used for calculations for where to stop the mass flow rate.

And my doubt was whether that "mass" gets initialized iterated and destroyed every iteration or not. And you have answered that very clearly.Thanks a ton.

Now do you know how I can retain that value of "mass" for every iteration and use that to decide when to give the mass flow rate from the surface of the sphere??

Thank you,
Bharadwaj B S

`e` March 16, 2015 16:13

I've answered the retaining variable question in this post (please try to keep your questions in one thread to avoid duplicates).

Instead of using the variable 'j', use the macro N_TIME to determine the current time step iteration number.

Bharadwaj B S March 17, 2015 03:41

Mistake
 
Dear e,

Sorry for the inconvenience caused. And thanks a lot for your suggestions.

By the way I was able to program with CURRENT_TIME as the basis for deciding when the mass flow rate should start and end.

I was not able to control(start or stop) mass flow rate based on reducing "mass" variable.

Thank you,
Bharadwaj B S


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