|
[Sponsors] |
Can any tell me which is right for the below codes? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
December 23, 2020, 22:35 |
Can any tell me which is right for the below codes?
|
#1 |
Senior Member
Join Date: Dec 2017
Posts: 388
Rep Power: 10 |
Can any tell me which is right for the below codes?
The first one: #include "udf.h" DEFINE_PROFILE(hf_change,thread,position) { face_t f; real time,heat_flux1,heat_flux2; heat_flux1 = 0; heat_flux2 = 500; time=CURRENT_TIME; begin_f_loop(f,thread) { if (time<0.0001) { F_PROFILE(f,thread,position)=heat_flux1; } else if (time>=0.0001) { F_PROFILE(f,thread,position)=heat_flux2; } } end_f_loop(f,thread) } The second one: #include "udf.h" DEFINE_PROFILE(hf_change,thread,position) { face_t f; real time,heat_flux1,heat_flux2; heat_flux1 = 0; heat_flux2 = 500; begin_f_loop(f,thread) { time=CURRENT_TIME; if (time<0.0001) { F_PROFILE(f,thread,position)=heat_flux1; } else if (time>=0.0001) { F_PROFILE(f,thread,position)=heat_flux2; } } end_f_loop(f,thread) } |
|
December 24, 2020, 02:11 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
first one is better, cause you will execute macro CURRENT_TIME once (outside of the loop). So in case you have few hundred millions of finite cells in model, you will feel the effect.
But both wold give same result.
__________________
best regards ****************************** press LIKE if this message was helpful |
|
December 24, 2020, 04:47 |
|
#3 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
It's even possible that the compiler is smart enough to put it out of the loop, and give you identical compiled code.
So I would say: use the one you expect to still understand two years from now. My version would be like this: Code:
#include "udf.h" DEFINE_PROFILE(hf_change,thread,position) { face_t f; const real heat_flux1 = 0; const real heat_flux2 = 500; const real switch time = 0.0001; const real time = CURRENT_TIME; const real hf = time<switch_time?heat_flux1:heat_flux2; begin_f_loop(f,thread) { F_PROFILE(f,thread,position)=hf; } end_f_loop(f,thread) } |
|
December 24, 2020, 10:52 |
Thank you so much for your help. Sorry, the first one is better,you mean the two code
|
#4 | |
Senior Member
Join Date: Dec 2017
Posts: 388
Rep Power: 10 |
Quote:
Sorry, the first one is better,you mean the two codes can achieve the same function, there is no wrong in the code 2? But I have question, if the macro CURRENT_TIME once is put outside of the loop, I think the code will only execute only once, is that right? I do not understand your meaning of "So in case you have few hundred millions of finite cells in model, you will feel the effect. But both wold give same result." In the end, I use both these two codes, they do not work in my run, what is the reason? Last edited by hitzhwan; December 24, 2020 at 12:26. |
||
December 24, 2020, 11:00 |
Hi,pakk, thank you for your help, I have a question ,is there any wrong with the belo
|
#5 | |
Senior Member
Join Date: Dec 2017
Posts: 388
Rep Power: 10 |
Quote:
Hi,pakk, thank you for your help, I have a question ,is there any wrong with the below code, there is a "?" here, is that right? const real hf = time<switch_time?heat_flux1:heat_flux2; When I use your code to compile, it gives the following error, what is the reason? ************************************************** ************************** ************************************************** ************************** ** WARNING: Automatically switched to run in parallel -t1 mode. ** ** Detected non-parallelized UDF usage, enabling parallel usage. ** ** If you encounter any issues, please re-run with -t0 flag. ** ************************************************** ************************** ************************************************** **************************Creating user_nt.udf file for 2ddp_host ... (system "copy "D:\PROGRA~1\ANSYSI~1\v190\fluent"\fluent19.0.0\sr c\udf\makefile_nt.udf "libudf\win64\2ddp_host\makefile" ") ÒѸ´ÖÆ 1 ¸öÎļþ¡£ (chdir "libudf")(chdir "win64\2ddp_host")# Generating ud_io1.h wallheat.c ..\..\src\wallheat.c(8) : error C2143: Óï·¨´íÎó : ȱÉÙ¡°;¡±(ÔÚ¡°switch¡±µÄÇ°Ãæ) ..\..\src\wallheat.c(8) : error C2059: Óï·¨´íÎó:¡°¿ÕÉùÃ÷¡± ..\..\src\wallheat.c(8) : error C2061: Óï·¨´íÎó: ±êʶ·û¡°time¡± ..\..\src\wallheat.c(9) : error C2143: Óï·¨´íÎó : ȱÉÙ¡°;¡±(ÔÚ¡°const¡±µÄÇ°Ãæ) ..\..\src\wallheat.c(10) : error C2143: Óï·¨´íÎó : ȱÉÙ¡°;¡±(ÔÚ¡°ÀàÐÍ¡±µÄÇ°Ãæ) ..\..\src\wallheat.c(13) : error C2065: ¡°hf¡±: δÉùÃ÷µÄ±êʶ·û ************************************************** ************************** ************************************************** ************************** ** WARNING: Automatically switched to run in parallel -t1 mode. ** ** Detected non-parallelized UDF usage, enabling parallel usage. ** ** If you encounter any issues, please re-run with -t0 flag. ** ************************************************** ************************** ************************************************** **************************Creating user_nt.udf file for 2ddp_node ... (system "copy "D:\PROGRA~1\ANSYSI~1\v190\fluent"\fluent19.0.0\sr c\udf\makefile_nt.udf "libudf\win64\2ddp_node\makefile" ") ÒѸ´ÖÆ 1 ¸öÎļþ¡£ (chdir "libudf")(chdir "win64\2ddp_node")# Generating ud_io1.h wallheat.c ..\..\src\wallheat.c(8) : error C2143: Óï·¨´íÎó : ȱÉÙ¡°;¡±(ÔÚ¡°switch¡±µÄÇ°Ãæ) ..\..\src\wallheat.c(8) : error C2059: Óï·¨´íÎó:¡°¿ÕÉùÃ÷¡± ..\..\src\wallheat.c(8) : error C2061: Óï·¨´íÎó: ±êʶ·û¡°time¡± ..\..\src\wallheat.c(9) : error C2143: Óï·¨´íÎó : ȱÉÙ¡°;¡±(ÔÚ¡°const¡±µÄÇ°Ãæ) ..\..\src\wallheat.c(10) : error C2143: Óï·¨´íÎó : ȱÉÙ¡°;¡±(ÔÚ¡°ÀàÐÍ¡±µÄÇ°Ãæ) ..\..\src\wallheat.c(13) : error C2065: ¡°hf¡±: δÉùÃ÷µÄ±êʶ·û Done. Last edited by hitzhwan; December 24, 2020 at 12:21. |
||
December 24, 2020, 13:19 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
There should be an underscore between switch and time, sorry. Not in the line you quote, but in line 8.
But if you don't understand my code:don't use it. If you don't understand it, you can not maintain it. |
|
December 24, 2020, 13:45 |
Thank you ,Pakk, you are right , after I add a underscore, it has no error. But it s
|
#7 |
Senior Member
Join Date: Dec 2017
Posts: 388
Rep Power: 10 |
Thank you ,Pakk, you are right , after I add a underscore, it has no error. But it still cannot change the heat flux. I think the code is not too difficult to understand, does there has other thing should I do before I run? Would you please tell me how to process it, thank you so much.
|
|
December 24, 2020, 14:36 |
|
#8 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
How did you investigate that the heat Flux did not change?
|
|
December 24, 2020, 14:39 |
I monitor the heat flux in the wall and plot it in the console.
|
#9 |
Senior Member
Join Date: Dec 2017
Posts: 388
Rep Power: 10 |
||
December 24, 2020, 15:17 |
|
#10 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Change heatflux1 to 1000, just to see if you see a difference.
|
|
December 24, 2020, 17:11 |
There is no difference, the heat flux is still 0, it shows the codes does not work.
|
#11 |
Senior Member
Join Date: Dec 2017
Posts: 388
Rep Power: 10 |
||
December 24, 2020, 21:01 |
|
#12 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
No, it shows that
- the code is not used (did you really apply it to the BC? And really this version?) - OR your method to get heat flux is wrong. Do you see temperatures changing? |
|
December 24, 2020, 22:26 |
Yes,the code is applied on the BC,I use the compiled method, and I Hook it by the Dr
|
#13 |
Senior Member
Join Date: Dec 2017
Posts: 388
Rep Power: 10 |
Yes,the code is applied on the BC,I use the compiled method, and I Hook it by the Drop-down menu. Can you use it in your computer?
|
|
December 25, 2020, 15:57 |
|
#14 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
No, I don't have Fluent on my pc.
|
|
December 28, 2020, 00:36 |
|
#15 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
everything works well.
and monitor works well either: in surface report definition window area-weight average -> wall fluxes -> total surface heat flux
__________________
best regards ****************************** press LIKE if this message was helpful |
|
December 28, 2020, 12:33 |
|
#16 |
New Member
mostafa_Fx
Join Date: Dec 2020
Posts: 3
Rep Power: 5 |
first code is better
|
|
December 28, 2020, 13:56 |
Have you run it in your pc? which code do you use?
|
#17 |
Senior Member
Join Date: Dec 2017
Posts: 388
Rep Power: 10 |
||
December 29, 2020, 02:51 |
|
#18 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
I've used code of Pakk, but all of them works.
1. compile code 2. load compiled library 3. select any wall -> thermal tab -> heat flux -> select udf function instead of constant run transient simulation
__________________
best regards ****************************** press LIKE if this message was helpful |
|
December 29, 2020, 12:24 |
You mean the below code you load work? Why I have some errors when I load it by the s
|
#19 | |
Senior Member
Join Date: Dec 2017
Posts: 388
Rep Power: 10 |
Quote:
You mean the below code you load work? Why I have some errors when I load it by the same process, what fluent edition do you use? Would you please send me your case and udf to me, I want to try more, thank you so much . #include "udf.h" DEFINE_PROFILE(hf_change,thread,position) { face_t f; const real heat_flux1 = 0; const real heat_flux2 = 500; const real switch time = 0.0001; const real time = CURRENT_TIME; const real hf = time<switch_time?heat_flux1:heat_flux2; begin_f_loop(f,thread) { F_PROFILE(f,thread,position)=hf; } end_f_loop(f,thread) } |
||
December 30, 2020, 06:41 |
|
#20 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Unfortunately, I'm not able to send you any files.
This is not the problem of version, code is simple and should work in any version. I recommend you to make new test simple geometry: rectangular, make it solid, not fluid make new source file (with other name) and compile it again load and apply UDF, run transient simulation most likely, you didn't compile the code
__________________
best regards ****************************** press LIKE if this message was helpful |
|
Tags |
udf |
|
|