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

I have two single udf files(see attachments), how can I put them together in one .c f

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 8, 2020, 11:07
Default I have two single udf files(see attachments), how can I put them together in one .c f
  #1
Senior Member
 
Join Date: Dec 2017
Posts: 388
Rep Power: 10
hitzhwan is on a distinguished road
I have two single udf files(see attachments), how can I put them together in one .c file, who can help me?
Attached Files
File Type: c velocity.c (658 Bytes, 14 views)
File Type: c heat.c (423 Bytes, 8 views)
hitzhwan is offline   Reply With Quote

Old   October 10, 2020, 09:30
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You can do it in notepad. Open one, select all, copy. Then open the other one, paste.
pakk is offline   Reply With Quote

Old   October 10, 2020, 13:38
Default Thank you for your reply,I tried it, but the heat.c does not work, could you tell me
  #3
Senior Member
 
Join Date: Dec 2017
Posts: 388
Rep Power: 10
hitzhwan is on a distinguished road
Quote:
Originally Posted by pakk View Post
You can do it in notepad. Open one, select all, copy. Then open the other one, paste.
Thank you for your reply,I tried it, but the heat.c does not work, could you tell me the reason? Whether should revise it a little such as delete one head "#include "udf.h"". I have also tried this, it still does not work.
hitzhwan is offline   Reply With Quote

Old   October 10, 2020, 13:49
Default
  #4
Member
 
mohammadreza
Join Date: Feb 2020
Posts: 31
Rep Power: 6
mohammadreza_hj is on a distinguished road
Quote:
Originally Posted by hitzhwan View Post
I have two single udf files(see attachments), how can I put them together in one .c file, who can help me?
i think that you should put your solver on transient and try again... or in heat udf, define a variable like Q and put that into the loop instead of the profile.
i hope that work.
mohammadreza_hj is offline   Reply With Quote

Old   October 10, 2020, 14:10
Default Hi, thank you for your reply. I am using a transient model, and I just try the udf.c
  #5
Senior Member
 
Join Date: Dec 2017
Posts: 388
Rep Power: 10
hitzhwan is on a distinguished road
Quote:
Originally Posted by mohammadreza_hj View Post
i think that you should put your solver on transient and try again... or in heat udf, define a variable like Q and put that into the loop instead of the profile.
i hope that work.
Hi, thank you for your reply. I am using a transient model, and I just try the udf.c solely, it can work, which shows the profile does not have any problem. But when I put two udfs together, the heat.c does not work. This shows that may be the problem locates at the putting together directed.
hitzhwan is offline   Reply With Quote

Old   October 11, 2020, 08:27
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by hitzhwan View Post
Thank you for your reply,I tried it, but the heat.c does not work, could you tell me the reason? Whether should revise it a little such as delete one head "#include "udf.h"". I have also tried this, it still does not work.
You really need to be more specific. What does "heat.c does not work" mean? Does it give warnings? Errors? Crash the program? Give wrong results? I can not see what you see on you screen, so please don't let me guess what happens.
pakk is offline   Reply With Quote

Old   October 11, 2020, 19:14
Default
  #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
You really need to be more specific. What does "heat.c does not work" mean? Does it give warnings? Errors? Crash the program? Give wrong results? I can not see what you see on you screen, so please don't let me guess what happens.
Hi, it means the function in the heat.c does not work in the fluent, it cannot realize the function(by monitoring the heat flux in the wall, the wall heat flux is still 0 at time larger than 0.3s,which is not correct), and there is no error in fluent. Does that make sense?
hitzhwan is offline   Reply With Quote

Old   October 12, 2020, 07:55
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
put your code into 1 file and compile
Code:
#include "udf.h"

DEFINE_PROFILE(inlet_x_velocity, thread, index)
{
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;
begin_f_loop(f, thread)/* loops over all faces in the thread passed
in the DEFINE macro argument*/
{
F_CENTROID(x,f,thread);
y = x[1];
F_PROFILE(f, thread, index) = 20. - y*y/(.0745*.0745)*20.;
}
end_f_loop(f, thread)
}

DEFINE_PROFILE(hf_change,thread,position) 
{
  face_t f;
  real time,heat_flux1,heat_flux2;
  heat_flux1 = 0;
  heat_flux2 = 47300;
  time= RP_Get_Real("flow-time");
  begin_f_loop(f,thread)
  {
   
	if (time<0.3)
	{
	F_PROFILE(f,thread,position)=heat_flux1;
	}
        
	else if (time>=0.3)
	{
	F_PROFILE(f,thread,position)=heat_flux2;
	}
      	
   }
  end_f_loop(f,thread)
}
hook functions properly, which means apply to boundaries respectively
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   October 12, 2020, 08:07
Default
  #9
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by hitzhwan View Post
Hi, it means the function in the heat.c does not work in the fluent, it cannot realize the function(by monitoring the heat flux in the wall, the wall heat flux is still 0 at time larger than 0.3s,which is not correct), and there is no error in fluent. Does that make sense?
Did it work when it was in a separate file?

By the way:if you compile, there is no need to put in on one file. That is only needed if you interpret, and you should not do that unless strictly necessary.
pakk is offline   Reply With Quote

Old   October 12, 2020, 11:04
Default Hi,it works in separate file, why can not do that way?
  #10
Senior Member
 
Join Date: Dec 2017
Posts: 388
Rep Power: 10
hitzhwan is on a distinguished road
Quote:
Originally Posted by pakk View Post
Did it work when it was in a separate file?

By the way:if you compile, there is no need to put in on one file. That is only needed if you interpret, and you should not do that unless strictly necessary.
Hi,it works in separate file, why can not do that way?
hitzhwan is offline   Reply With Quote

Old   October 12, 2020, 11:07
Default I do as you said,but it still 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 AlexanderZ View Post
put your code into 1 file and compile
Code:
#include "udf.h"

DEFINE_PROFILE(inlet_x_velocity, thread, index)
{
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;
begin_f_loop(f, thread)/* loops over all faces in the thread passed
in the DEFINE macro argument*/
{
F_CENTROID(x,f,thread);
y = x[1];
F_PROFILE(f, thread, index) = 20. - y*y/(.0745*.0745)*20.;
}
end_f_loop(f, thread)
}

DEFINE_PROFILE(hf_change,thread,position) 
{
  face_t f;
  real time,heat_flux1,heat_flux2;
  heat_flux1 = 0;
  heat_flux2 = 47300;
  time= RP_Get_Real("flow-time");
  begin_f_loop(f,thread)
  {
   
	if (time<0.3)
	{
	F_PROFILE(f,thread,position)=heat_flux1;
	}
        
	else if (time>=0.3)
	{
	F_PROFILE(f,thread,position)=heat_flux2;
	}
      	
   }
  end_f_loop(f,thread)
}
hook functions properly, which means apply to boundaries respectively


I compiled as you said,but it still does not work.
The below are the process notes:

nformation: The surface name point-150 no longer exists for report definition tem-150. They must have been deactivated/deleted.
Information: The surface name line-150 no longer exists for report definition phase-line-150. They must have been deactivated/deleted.
Information: The surface name line-30 no longer exists for report definition phase-line-30. They must have been deactivated/deleted.
************************************************** **************************
************************************************** **************************
** 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. **
************************************************** **************************
************************************************** **************************
cpp -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/main" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/addon-wrapper" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/io" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/species" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/pbns" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/numerics" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/sphysics" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/storage" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/mphase" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/bc" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/models" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/material" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/amg" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/util" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/mesh" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/udf" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/ht" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/dx" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/turbulence" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/acoustics" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/parallel" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/etc" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/ue" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/dpm" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/dbns" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/tgrid/src" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/PRIME/tgrid/src" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/client/src" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/multiport/src" -I. -DUSE_UDF_HOST_DUMMY -DUDFCONFIG_H="<udfconfig-host.h>" "C:/Users/zhwan/Desktop/compiled.c"

cpp -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/main" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/addon-wrapper" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/io" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/species" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/pbns" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/numerics" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/sphysics" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/storage" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/mphase" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/bc" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/models" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/material" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/amg" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/util" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/mesh" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/udf" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/ht" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/dx" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/turbulence" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/acoustics" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/parallel" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/etc" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/ue" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/dpm" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/src/dbns" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/tgrid/src" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/PRIME/tgrid/src" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/client/src" -I"C:\PROGRA~1\ANSYSI~1\v193\fluent\fluent19.3.0/multiport/src" -I. -DUDFCONFIG_H="<C:/Users/zhwan/AppData/Local/Temp/udfconfig-12632-node0.h>" "C:/Users/zhwan/AppData/Local/Temp/compiled.c.12632.0.c"
Attached Files
File Type: c compiled.c (779 Bytes, 1 views)
hitzhwan is offline   Reply With Quote

Old   October 13, 2020, 00:54
Default
  #12
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you may try to change time= RP_Get_Real("flow-time");
to time= CURRENT_TIME;
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   October 13, 2020, 18:26
Default There is no difference for it.
  #13
Senior Member
 
Join Date: Dec 2017
Posts: 388
Rep Power: 10
hitzhwan is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
you may try to change time= RP_Get_Real("flow-time");
to time= CURRENT_TIME;
There is no difference for it.
hitzhwan is offline   Reply With Quote

Old   October 14, 2020, 05:45
Default
  #14
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by hitzhwan View Post
Hi,it works in separate file, why can not do that way?
You are very confusing in your communication. If it works in a separate file, you can do it that way. Why do you ask me why you can NOT do it in that way?

I should ask you that question! If it works in separate files, why do go through all these troubles to combine it into one file?
pakk is offline   Reply With Quote

Old   October 14, 2020, 18:27
Default Yes, I have combined it into one file,but one of it (heat.c) does not work, I do not
  #15
Senior Member
 
Join Date: Dec 2017
Posts: 388
Rep Power: 10
hitzhwan is on a distinguished road
Quote:
Originally Posted by pakk View Post
You are very confusing in your communication. If it works in a separate file, you can do it that way. Why do you ask me why you can NOT do it in that way?

I should ask you that question! If it works in separate files, why do go through all these troubles to combine it into one file?
Yes, I have combined it into one file,but one of it (heat.c) does not work, I do not know what is the reason? Can you do it in your computer?
hitzhwan is offline   Reply With Quote

Old   October 19, 2020, 11:56
Default
  #16
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by hitzhwan View Post
Yes, I have combined it into one file,but one of it (heat.c) does not work, I do not know what is the reason? Can you do it in your computer?
If you have combined it into one file, you only have one file. It makes no sense to say "one if it does not work", if you have only one.

You still did not answer the question. Let me ask it again. I will make it big and bold so you can not miss it:

WHY do you want to combine it into one file?

If everything works with separate files, just use separate files. Don't torture yourself.
pakk is offline   Reply With Quote

Old   October 19, 2020, 12:00
Default
  #17
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Oh wait, I know the reason.

You said before that you compiled, but in reality you are interpreting. You go in the menu to "Define -> user-defined -> functions -> Interpreted", right?

Well... Try to compile for a change. Go to "Define -> user-defined -> functions -> Compiled".
pakk is offline   Reply With Quote

Old   October 19, 2020, 14:51
Default But when I try to compiled them one by one , the heat.c does not work, could you help
  #18
Senior Member
 
Join Date: Dec 2017
Posts: 388
Rep Power: 10
hitzhwan is on a distinguished road
Quote:
Originally Posted by pakk View Post
Oh wait, I know the reason.

You said before that you compiled, but in reality you are interpreting. You go in the menu to "Define -> user-defined -> functions -> Interpreted", right?

Well... Try to compile for a change. Go to "Define -> user-defined -> functions -> Compiled".
Yes,you are right. I can interpret them one by one.

But when I try to compiled them one by one , the heat.c does not work, could you help me deal with it .
hitzhwan is offline   Reply With Quote

Old   October 19, 2020, 15:23
Default
  #19
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Let me get this straight, because the story keeps changing.

1. You were able to interpret both files separately. (I mean: no errors or crashes.)
2. When you interpreted heat.c, it gave the result you wanted: the wall heated up after t=0.3.
3. You were able to compile both files separately (I mean: no errors or crashes.)
4. When you used the compiled version for heat.c, you did suddenly NOT get the result you wanted: the wall did not heat up after t=0.3.

Is this accurate?

(I told you before: "does not work" is too vague. Be more specific: does it crash Fluent? does it give errors? Does it give warnings? Does it give unexpected results? Does it make your computer burn? Each of these events has a different solution.)
pakk is offline   Reply With Quote

Old   October 20, 2020, 12:07
Default Yes, all your four points are accurate, there is no errors or crashes when I interpre
  #20
Senior Member
 
Join Date: Dec 2017
Posts: 388
Rep Power: 10
hitzhwan is on a distinguished road
Quote:
Originally Posted by pakk View Post
Let me get this straight, because the story keeps changing.

1. You were able to interpret both files separately. (I mean: no errors or crashes.)
2. When you interpreted heat.c, it gave the result you wanted: the wall heated up after t=0.3.
3. You were able to compile both files separately (I mean: no errors or crashes.)
4. When you used the compiled version for heat.c, you did suddenly NOT get the result you wanted: the wall did not heat up after t=0.3.

Is this accurate?

(I told you before: "does not work" is too vague. Be more specific: does it crash Fluent? does it give errors? Does it give warnings? Does it give unexpected results? Does it make your computer burn? Each of these events has a different solution.)
Yes, all your four points are accurate, there is no errors or crashes when I interpreted or compiled them separately or together. You can run them in your fluent softeware, you can see whether it happens on your software.
hitzhwan is offline   Reply With Quote

Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF compiling error Weiqiang Liu FLUENT 2 November 21, 2018 10:36
Single v.s. double precision Confused CFX 15 November 10, 2016 05:42
using define mass transfer udf for cavitation Komon Fluent UDF and Scheme Programming 14 June 21, 2016 03:50
UDF Compilation Error - Loading Library - COMMON Problem! Help! robtheslob Fluent UDF and Scheme Programming 8 July 24, 2015 01:53
UDF...UDF...UDF...UDF Luc SEMINEL FLUENT 0 November 25, 2002 05:03


All times are GMT -4. The time now is 19:00.