|
[Sponsors] |
Issues with iterating in TRANSIENT state "UDF" |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 16, 2015, 00:57 |
Issues with iterating in TRANSIENT state "UDF"
|
#1 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 16, 2015, 01:03 |
Udf
|
#2 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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) } } } |
|
March 16, 2015, 03:14 |
|
#3 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
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). |
|
March 16, 2015, 03:32 |
Errors
|
#4 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 16, 2015, 04:15 |
|
#5 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
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? |
|
March 16, 2015, 04:56 |
Clarification
|
#6 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 16, 2015, 05:53 |
|
#7 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
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. |
|
March 16, 2015, 07:01 |
Right.
|
#8 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 16, 2015, 17:13 |
|
#9 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
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. |
|
March 17, 2015, 04:41 |
Mistake
|
#10 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
The difference between steady state and transient | JuPa | CFX | 36 | December 9, 2019 23:50 |
Fluent transient solver keeps iterating, although residual is reached on first iter | r61514 | FLUENT | 0 | February 10, 2014 04:24 |
Steady state simulation with transient partilcle tracking | mali28 | FLUENT | 2 | February 7, 2013 15:25 |
transient simulations vs steady state for bouyancy | Drauss | Main CFD Forum | 8 | October 29, 2005 14:31 |
Transient state | ado | Main CFD Forum | 2 | July 21, 2000 01:33 |