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

Compiling UDF in FLuent

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By ngoctm

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 24, 2019, 09:49
Default Compiling UDF in FLuent
  #1
New Member
 
Ekha
Join Date: Aug 2018
Posts: 16
Rep Power: 8
ekha is on a distinguished road
Hi,

I am facing errors while trying to do interpretation or compilation for a UDF in fluent.

I am simulating a 2D rectangular cavity with the following boundary conditions: adiabatic top layer, periodic side walls and rigid bottom with thermal heat flux and small random perturbations following this equation: dT/dy= -exp(-h)+ epsilon*[rand(x)-0.5] , where rand is a one dimensional array of random numbers uniformly distributed in the range of [0,1].

I used a UDF to assign the heat flux and perturbation to the bottom layer. When I used interpretation of UDF, I get an error notifying that: srand: undeclared variable.

When trying to compile it, I get an error notifying that: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).\n\nThe system cannot find the file specified. however, the UDF source files are in the directory that contains my case and data files.



Following the UDF I am using to set up the boundary condition at the bottom layer:




Code:
#include "udf.h"

#include "stdlib.h"            /* srand and rand */

#include "time.h"

#include "random.h"

 

#define RAND_MAX 32767

 

 

DEFINE_PROFILE(Temp_rand_pertubation_bottom,thread,index)

{

 

real x[ND_ND]; /* this will hold the position vector */

 

face_t f;

 

real time= CURRENT_TIME;

 

 

float h,E,r;

 

srand((unsigned)time(NULL));        /*  this to specify a different random number at each cell */

k=0.6                /* thermal conductivity */

T=300               /* Temp in Kelvin */

h = 0.5; /* cavity height  */

E= 0.01; /* epsilon constant value */

 

 

  begin_f_loop_all(f,thread)

{

r= rand()/float(RAND_MAX);       /* r is a 1D array of random numbers uniformly distributed in the range of [0,1] */

  

F_CENTROID (x,f,thread);

 

F_PROFILE(f,thread,index) = k*T*(- exp(-h)+E*(r-0.5))/h;         /* apply random perturbation */

}

  end_f_loop_all(f,thread);

 

void srand(unsighned int seed);

}
To try solving the compilation error:


I tried both serial and parallel and got same error.
I have installed the latest version of visual studio
Restarted the machine
I tried to launch Fluent from the VS command window
I have set up the Path in the environment variable correctly as below:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools;

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC;

C:\Program Files\ANSYS Inc\v192\fluent;

I get help from Ansys Community and CFD-online and links below:

https://www.researchgate.net/post/UD..._to_avoid_this

https://www.cfd-online.com/Forums/fl...df-windows-10-

a.htmlhttps://www.youtube.com/watch?v=xt2hnE9_LdM&lc=z230wdny3yqwdf2y004t1aokgot sclzxfp5jetjrb2a3rk0h00410.1540346039732132


BUT still facing the same problem !


Could you please guide me how to get this error solved.

Please note that I am using Fluent v19.2 running parallel processor and Visual Studio v2019.

Many Thanks.
ekha is offline   Reply With Quote

Old   June 25, 2019, 05:10
Default
  #2
Member
 
Join Date: Mar 2009
Location: Vietnam
Posts: 36
Rep Power: 18
ngoctm is on a distinguished road
Hi Ekha,

I have some suggestions for your code. Please find the attached file.

Hope this help,
Attached Files
File Type: c abc.c (930 Bytes, 12 views)
ekha likes this.
ngoctm is offline   Reply With Quote

Old   June 25, 2019, 05:17
Default
  #3
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
when compiling: push BUILD button, not load

best regards
AlexanderZ is offline   Reply With Quote

Old   June 25, 2019, 12:14
Default
  #4
New Member
 
Ekha
Join Date: Aug 2018
Posts: 16
Rep Power: 8
ekha is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
when compiling: push BUILD button, not load

best regards
Thanks for your reply.

I do BUILD the UDF before Loading it, It builds successfully but I face the problem when trying to load it.

However, even I am getting this error, I found a 'libudf' file in the directory but the UDF does not come out in the drop down menu in heat flux boundary condition dialog box.
ekha is offline   Reply With Quote

Old   June 25, 2019, 22:46
Default
  #5
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
it means your UDF is not compiled
try again and put here FULL log

best regards
AlexanderZ is offline   Reply With Quote

Old   July 3, 2019, 03:59
Default
  #6
New Member
 
Ekha
Join Date: Aug 2018
Posts: 16
Rep Power: 8
ekha is on a distinguished road
Hi,

It works!

I used visual studio 2017 instead of 2019 since the latter is not compatible with ANSYS 19.2.
ekha is offline   Reply With Quote

Old   July 3, 2019, 04:02
Default
  #7
New Member
 
Ekha
Join Date: Aug 2018
Posts: 16
Rep Power: 8
ekha is on a distinguished road
Hi,

When using the UDF at the bottom layer, I supposed to see plumes or rolls on the temperature contour profile.

BUT I didn't, what I get is a simple diffusion problem.

I modified the UDF based on your suggestions, so that each cell on the bottom layer has different random number of heat flux, srand function is used.

Here is the UDF I used:

#include "udf.h"



#include "stdlib.h"

/* srand and rand */



#include "random.h"



#include "time.h"



/*#define RAND_MAX 32767*/



#define k 0.6

/* thermal conductivity */



#define T 300

/* Temp in Kelvin */



DEFINE_PROFILE(Temp_rand_pertubation_bottom,thread ,index)



{



real x[ND_ND];

/* this will hold the position vector */



face_t f;



real time = CURRENT_TIME;



float h = 0.5;

float E = 0.01;



srand((unsigned int) time);

/*this to specify a different random number at each cell*/



begin_f_loop_all(f,thread)



{



float r = (rand() / RAND_MAX);

/* r is a 1D array of random numbers uniformly distributed in the range of [0,1] */



F_CENTROID (x,f,thread);



F_PROFILE(f,thread,index) = k*T*(- exp(-h)+E*(r-0.5))/h;

/* apply random perturbation */



}



end_f_loop_all(f,thread);





void srand(unsigned int seed);



}



please advice me whether I need to modify the code.



Many thanks for your valuable help.

Esra'a
ekha 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
looking for a smart interface matlab fluent chary FLUENT 24 June 18, 2021 10:07
How to solve UDF compilation problems in Fluent. pakk Fluent UDF and Scheme Programming 16 September 10, 2018 03:48
The fluent stopped and errors with "Emergency: received SIGHUP signal" yuyuxuan FLUENT 0 December 3, 2013 23:56
Error while compiling udf in fluent 13.0.0 siddharth12 FLUENT 0 December 3, 2013 17:46
compiling my UDF Seyed Farid Hosseinizadeh FLUENT 22 February 14, 2006 11:19


All times are GMT -4. The time now is 14:05.