How does FLUENT process an UDF!!!!????
I have an UDF for providing mass flow rate from a surface. In that I have one "for loop" with initial value, condition and an DECREMENT.
Contions, m =1.0 (arbitary initial mass (1 kg)), this mass should reduce by 0.5 kg for next iteration and "m" should be greater than 0.0. When all this conditions are true it should go inside the loop and do the calculations for mass flow rate, for which I have used F_PROFILE and some constant value is assigned to it. NOW QUESTION: Whenever I run this UDF, for all time steps it is taking the conditions to be TRUE and goes into the loop and assigns the mass flow rate value, even though the loop is WRITTEN such that it should end by two TIME STEPS (because decrement is 0.5 (1-0.5)). Since this is taking the conditions always true, I get a doubt that FLUENT(compiler) is running the UDF every time fresh. i.e, once it completes reading the UDF, it goes back and when there is a need again, it is again reading the UDF, is this how FLUENT reads an UDF or am I wrong?? |
Quote:
It is hard to guess without seeing your code, but I think your question actually is: Does Fluent remember the value of "m" that I give, or does it reset this value every time? If Fluent resets the value of "m" every time to one, then the condition is always true, and you get the behavior what you said. But you don't want that. So make the variable global or static, depending on what you understand best. |
Quote:
Thanks for your speedy reply. Yes. I should have asked the question as you have mentioned. So if I just define the variable inside a function, it will be reset, right?? And how do I define it globally?? do you mean defining before the function?? Thanks in advance, Bharadwaj B S |
Yes.
Local: only your function can use m, and it is reset every time. Code:
int f(){ Code:
real m = 1.0; Code:
int f(){ |
Solution
Dear pakk,
Thanks a lot for your valuable suggestion. I will try this in my UDF. One more question, If I use for loop, I will have to give the initial value as a condition in braces. So do you recommend me using "for loop" or will the "while loop" serve the purpose for me??? Thanks in advance, Bharadwaj B S |
Quote:
Perhaps you don't even need a loop. |
Looping
Hi pakk,
I want that m to be reduced for every iteration by some value, say 0.05. So that whatever the flux calculations inside should stop when this "m" value is zero. That is at 20 iterations "m" will become zero. For this to work, from what I know, I should use a "if else" or "for" or a "while loop", for decrementing that "m" value with the conditions that "m>=0 and m<=1". Hope you got my point. Thanks in advance, Bharadwaj B S |
Quote:
Code:
m=m-0.05; |
Thanks
Hello pakk,
Thanks for bearing, I am very much new. I will send you my UDF. Please go through and tell me if there is any mistake and suggest me changes. I think that will be the right thing to do. Hope it makes sense. Thanks again, Bharadwaj B S |
UDF for mass flow from surface
Here is the UDF which I wrote, this is what I could do from my understanding, please go through and suggest me for modifications.
#include "udf.h" int ID = 13; float source; Domain *d; face_t f; Thread *t; Thread c_thread; cell_t c; real flx; float a; float b; float g; float h; DEFINE_PROFILE(flux, t, i) { Domain *d; d = Get_Domain(1); t = Lookup_Thread(d, ID); flx = 0.0; a = - 0.05; b = 0.05; g = 0.0; h = 1.0; begin_f_loop(f, t) { for(source = h; source >= g; source = source - b) { flx = - a; F_PROFILE(f, t, i) = flx; if(source == g) break; } } end_f_loop(f,t) } Thanks in advance, Bharadwaj B S |
I guess you want something like:
Code:
#include "udf.h" |
Thanks a ton
Hi pakk,
Thanks a lot for your time and suggestion. Definitely I am going to make changes and yes I started with that name source, I did not changed that, just kept it as it is. I was unaware of the fact of giving names instead of a,b,c. I thought it was simple, that's the whole thing behind that. Regards, Bharadwaj B S |
Yes, now it seems simple, but I promise you that if you read it back in a year, you will have a hard time finding out what the meaning of "a" and "b" is!
Good luck! |
Right.
Yeah absolutely. That I was unaware of these things. I have given a run with the changes. I will let you know once it is complete.
Regards, Bharadwaj B S |
Not working
Hi pakk,
I made the changes as you suggested and ran the case for a decrements of 0.5, so that I can complete the calculations fast. But after doing this, I was not able to obtain the result. i.e, according to this, there should not be any mass flow rate from the surface once the value of mass reduces to 0. It is clear, for second iteration itself "m' becomes zero(decrement is 0.5) and the mass flow rate (F_PROFILE) calculation should not be read (or considered), after this, right? Still it is giving out the flux from the surface (sphere in my case). Anything you know to make it stop once "m" becomes zero(0)???. Thanks in advance, Bharadwaj B S |
You should be more exact.
You never specified that the flux should become zero when m is below zero. That is why it is not in the code. And that is why the code does not do that. You never specified what should happen when m is below zero. So nothing happens. If you want something to happen when m is below zero, you should add it in the code. Fluent can not guess what you want. |
Decrement
Hello pakk,
Pardon for not mentioning it earlier. I thought just by decreasing the "m' by some decrements, I would get to stop the mass flow rate. In the earlier UDF, where I had used "for loop". I ran that in TURBO C, I was getting the decrements. So, that decremented value I thought of using it for condition. Thanks in advance, Bharadwaj B S |
I had the impression that I had already given you enough hints...
Currently, you program does the following: If the mass is larger than zero, make the massflux -a. Now you want to add the following: If the mass is smaller or equal to zero, make the massflux 0. Try to understand the code, then you should see what to add to the code to make it work. |
m >= 0
Hello pakk,
Thanks for your reply. I tried the same if(m>=0), if(m < 1 && m>0) and if(m>0), all three conditions are either taking the condition true or false. None of them are stopping at any instance. |
Current udf
Hi pakk,
This is the one which I tried, #include "udf.h" Thread *t; float mass = 10; DEFINE_PROFILE(flux, t, i) { Domain *d; int ID = 13; face_t f; float flwrt = -0.5; float decrement = 2; d = Get_Domain(1); t = Lookup_Thread(d, ID); mass = mass - decrement; if(mass <= 0) { begin_f_loop(f, t) F_PROFILE (f, t, i) = 0.0; end_f_loop(f,t) } else { begin_f_loop(f, t) F_PROFILE(f, t, i) = -flwrt; end_f_loop(f,t) } } Please go through and suggest me if there is any mistakes. Thanks in advance, Bharadwaj B S |
All times are GMT -4. The time now is 22:53. |