CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Can any tell me which is right for the below codes?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 23, 2020, 22:35
Default Can any tell me which is right for the below codes?
  #1
Senior Member
 
Join Date: Dec 2017
Posts: 388
Rep Power: 10
hitzhwan is on a distinguished road
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)
}
hitzhwan is offline   Reply With Quote

Old   December 24, 2020, 02:11
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Old   December 24, 2020, 04:47
Default
  #3
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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)
}
If you think your version is easier to understand, use yours.
pakk is offline   Reply With Quote

Old   December 24, 2020, 10:52
Default 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
hitzhwan is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
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.
Thank you so much for your help.
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.
hitzhwan is offline   Reply With Quote

Old   December 24, 2020, 11:00
Default 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
hitzhwan is on a distinguished road
Quote:
Originally Posted by pakk View Post
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)
}
If you think your version is easier to understand, use yours.

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.
hitzhwan is offline   Reply With Quote

Old   December 24, 2020, 13:19
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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.
pakk is offline   Reply With Quote

Old   December 24, 2020, 13:45
Default 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
hitzhwan is on a distinguished road
Quote:
Originally Posted by pakk View Post
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.
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.
hitzhwan is offline   Reply With Quote

Old   December 24, 2020, 14:36
Default
  #8
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
How did you investigate that the heat Flux did not change?
pakk is offline   Reply With Quote

Old   December 24, 2020, 14:39
Default 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
hitzhwan is on a distinguished road
Quote:
Originally Posted by pakk View Post
How did you investigate that the heat Flux did not change?
I monitor the heat flux of the wall and plot it in the console.
hitzhwan is offline   Reply With Quote

Old   December 24, 2020, 15:17
Default
  #10
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Change heatflux1 to 1000, just to see if you see a difference.
pakk is offline   Reply With Quote

Old   December 24, 2020, 17:11
Default 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
hitzhwan is on a distinguished road
Quote:
Originally Posted by pakk View Post
Change heatflux1 to 1000, just to see if you see a difference.
There is no difference, the heat flux is still 0, it shows the codes does not work.
hitzhwan is offline   Reply With Quote

Old   December 24, 2020, 21:01
Default
  #12
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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?
pakk is offline   Reply With Quote

Old   December 24, 2020, 22:26
Default 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
hitzhwan is on a distinguished road
Quote:
Originally Posted by pakk View Post
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?
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?
hitzhwan is offline   Reply With Quote

Old   December 25, 2020, 15:57
Default
  #14
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
No, I don't have Fluent on my pc.
pakk is offline   Reply With Quote

Old   December 28, 2020, 00:36
Default
  #15
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Old   December 28, 2020, 12:33
Default
  #16
New Member
 
mostafa_Fx
Join Date: Dec 2020
Posts: 3
Rep Power: 5
aregdgshj is on a distinguished road
first code is better
aregdgshj is offline   Reply With Quote

Old   December 28, 2020, 13:56
Default Have you run it in your pc? which code do you use?
  #17
Senior Member
 
Join Date: Dec 2017
Posts: 388
Rep Power: 10
hitzhwan is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
everything works well.
and monitor works well either:
in surface report definition window
area-weight average -> wall fluxes -> total surface heat flux
Have you run it in your pc? which code do you use?
hitzhwan is offline   Reply With Quote

Old   December 29, 2020, 02:51
Default
  #18
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Old   December 29, 2020, 12:24
Default 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
hitzhwan is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
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



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)
}
hitzhwan is offline   Reply With Quote

Old   December 30, 2020, 06:41
Default
  #20
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Reply

Tags
udf


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



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