|
[Sponsors] |
March 6, 2015, 01:11 |
How does FLUENT process an UDF!!!!????
|
#1 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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?? |
|
March 6, 2015, 04:43 |
|
#2 | |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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. |
||
March 6, 2015, 04:52 |
|
#3 | |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
||
March 6, 2015, 05:11 |
|
#4 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Yes.
Local: only your function can use m, and it is reset every time. Code:
int f(){ real m = 1.0; ... } Code:
real m = 1.0; int f(){ ... } Code:
int f(){ static real m = 1.0; ... } |
|
March 6, 2015, 06:41 |
Solution
|
#5 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 6, 2015, 07:30 |
|
#6 | |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Quote:
Perhaps you don't even need a loop. |
||
March 6, 2015, 07:43 |
Looping
|
#7 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 6, 2015, 08:16 |
|
#8 | |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Quote:
Code:
m=m-0.05; |
||
March 6, 2015, 08:38 |
Thanks
|
#9 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 6, 2015, 08:50 |
UDF for mass flow from surface
|
#10 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 6, 2015, 09:08 |
|
#11 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
I guess you want something like:
Code:
#include "udf.h" DEFINE_PROFILE(flux, t, i) { int ID = 13; static float source = 1.0; Domain *d; face_t f; Thread *t; float a = - 0.05; float b = 0.05; source = source - b; if (source>0) { d = Get_Domain(1); t = Lookup_Thread(d, ID); begin_f_loop(f, t) { F_PROFILE(f, t, i) = -a; } end_f_loop(f,t); } } |
|
March 6, 2015, 09:13 |
Thanks a ton
|
#12 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 6, 2015, 09:25 |
|
#13 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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! |
|
March 6, 2015, 09:32 |
Right.
|
#14 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 6, 2015, 10:07 |
Not working
|
#15 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 6, 2015, 12:01 |
|
#16 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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. |
|
March 7, 2015, 01:07 |
Decrement
|
#17 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
March 9, 2015, 04:18 |
|
#18 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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. |
|
March 9, 2015, 04:43 |
m >= 0
|
#19 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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. |
|
March 9, 2015, 05:20 |
Current udf
|
#20 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
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 |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
looking for a smart interface matlab fluent | chary | FLUENT | 24 | June 18, 2021 10:07 |
solving a conduction problem in FLUENT using UDF | Avin2407 | Fluent UDF and Scheme Programming | 1 | March 13, 2015 03:02 |
Consulting for some issues of FLUENT UDF and UDS | wjl163 | Fluent UDF and Scheme Programming | 2 | November 12, 2012 04:24 |
fluent UDF external library lapack problem | Rick | FLUENT | 0 | May 7, 2008 11:16 |
UDF of Zimont model in fluent | Z | Main CFD Forum | 0 | February 17, 2005 04:07 |