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

Urgent! UDF error "implicit declaration of function"

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 17, 2010, 16:54
Default Urgent! UDF error "implicit declaration of function"
  #1
Member
 
Ivan
Join Date: May 2009
Posts: 85
Rep Power: 16
ivanbuz is on a distinguished road
Urgent, will wait online for answers!

After compiling the following UDF, I see the error message "inlet_u.c:39: warning: implicit declaration of function erf". And the simulation crash if I continue using this UDF.

What is the reason? and How can I solve it? Thanks!


/* UDF for specifying a transient inlet velocity profile boundary condition */

#include "udf.h"
#include "math.h"
#define PI 4.*atan(1.)
#define RT 0.00183
real VM=21.911;
real VNin=0.01;

/**************** x velocity ****************/
DEFINE_PROFILE(v_x, thread, index)
{

face_t f;
real t,dt,u;
real D1,D2,D3,D4,D5,D6,D7;
real G1,G2,G3;

/* wind gust model parameters */
D1=VM*700;
D2=7/(3*RT);
D3=1;
D4=3/(3*RT);
D5=0.15;
D6=7/(10*RT);
D7=2*PI/(RT/10);

/* get flow time */
t = CURRENT_TIME;

/* u = X Velocity */
if (t<=VNin*RT)
{ u = VM;}
else
{ /* get dt */
dt = t-VNin*RT;
/* wind gust model */
G1=D1*dt*exp(-D2*dt);
G2=D3*erf(D4*dt);
G3=D5*exp(-D6*dt)*sin(D7*dt);
/* get u */
u = VM+G1+G2+G3;}

/* assign X velocity */
begin_f_loop(f, thread)
{ F_PROFILE(f, thread, index) = u; }
end_f_loop(f, thread)

}
ivanbuz is offline   Reply With Quote

Old   June 17, 2010, 16:57
Default
  #2
Member
 
Ivan
Join Date: May 2009
Posts: 85
Rep Power: 16
ivanbuz is on a distinguished road
The only problem is the function erf. But I have included math.h, anything else needs to be done? Or math.h is NOT the right header file to include if I want to use function erf?

erf is error function.
ivanbuz is offline   Reply With Quote

Old   June 17, 2010, 17:24
Default
  #3
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
I suppose you are on a Windows system ? If yes the erf function is not implemented in math.h . So basically you will need to implement a custom version of erf in your UDF function.

If you are on Linux erf should be already defined in math.h so you need to search for the error in a different place.

Do
DoHander is offline   Reply With Quote

Old   June 17, 2010, 17:30
Default
  #4
Member
 
Ivan
Join Date: May 2009
Posts: 85
Rep Power: 16
ivanbuz is on a distinguished road
Thank you so much for replying.

I run Fluent on Linux. I searched the src folder (it contains the udf.h file) for the file math.h and did NOT find it.

If I have to implement a custom version of erf, how to do it?

I checked the UDF manual, it says "C compilers include a library of standard mathematical and I/O functions", but it does not say what if I want to use a function like erf.
ivanbuz is offline   Reply With Quote

Old   June 17, 2010, 17:35
Default
  #5
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
I would recommend you to use a good book like:

http://books.google.ca/books?id=1aAO...page&q&f=false

for understanding the theory (erf is not so easy to implement in C). BTW you can not use the code from the book because it is very C++ (template classes and so on) and Fluent won't accept it, but probably you can modify the code ...

Do
DoHander is offline   Reply With Quote

Old   June 17, 2010, 17:37
Default
  #6
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
Hey,

try the same code but with:

#include <math.h>

instead of:

#include "math.h"

Let me know if this has solved your problem.

Do
DoHander is offline   Reply With Quote

Old   June 17, 2010, 17:39
Default
  #7
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
/* UDF for specifying a transient inlet velocity profile boundary condition */

#include "udf.h"
#include <math.h>
#define PI 4.*atan(1.)
#define RT 0.00183
real VM=21.911;
real VNin=0.01;

/**************** x velocity ****************/
DEFINE_PROFILE(v_x, thread, index)
{

face_t f;
real t,dt,u;
real D1,D2,D3,D4,D5,D6,D7;
real G1,G2,G3;

/* wind gust model parameters */
D1=VM*700;
D2=7/(3*RT);
D3=1;
D4=3/(3*RT);
D5=0.15;
D6=7/(10*RT);
D7=2*PI/(RT/10);

/* get flow time */
t = CURRENT_TIME;

/* u = X Velocity */
if (t<=VNin*RT)
{ u = VM;}
else
{ /* get dt */
dt = t-VNin*RT;
/* wind gust model */
G1=D1*dt*exp(-D2*dt);
G2=D3*erf(D4*dt);
G3=D5*exp(-D6*dt)*sin(D7*dt);
/* get u */
u = VM+G1+G2+G3;}

/* assign X velocity */
begin_f_loop(f, thread)
{ F_PROFILE(f, thread, index) = u; }
end_f_loop(f, thread)

}
DoHander is offline   Reply With Quote

Old   June 17, 2010, 17:39
Default
  #8
Member
 
Ivan
Join Date: May 2009
Posts: 85
Rep Power: 16
ivanbuz is on a distinguished road
Is it possible that a function libarary containing erf is NOT installed so I can NOT use erf?
ivanbuz is offline   Reply With Quote

Old   June 17, 2010, 17:43
Default
  #9
Member
 
Ivan
Join Date: May 2009
Posts: 85
Rep Power: 16
ivanbuz is on a distinguished road
I tried #include <math.h> with no luck. got the same error message
ivanbuz is offline   Reply With Quote

Old   June 17, 2010, 17:46
Default
  #10
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
It depends of your Linux system, but yes it is possible to not have a C compiler installed.

What you can do is to give a search on all your system after math.h (probably it is in /usr/... but better check all), once you find math.h you can check directly if your particular system implements erf (on Ubuntu 9.04 I know the function is implemented).

If you want I can send you my messenger id (in a private message) and we will be able to talk faster.

Do
DoHander is offline   Reply With Quote

Old   June 17, 2010, 17:54
Default
  #11
Member
 
Ivan
Join Date: May 2009
Posts: 85
Rep Power: 16
ivanbuz is on a distinguished road
Thank you DoHander,

I am in a rush. And It just came to my mind that I can use (1-exp(-D4*t)) to replace erf function in the code, and it turns out that the velocity profile looks very similar to the one using erf. Engineer must make approximations all the time anyway. I will come back to solve this problem later.

thanks again.

Ivan
ivanbuz is offline   Reply With Quote

Old   June 17, 2010, 18:01
Default
  #12
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
You use a very crude approximation for erf, you will get about 10^-1 error if you use (1-exp(x)) instead of the actual erf.

The good thing is that if you were capable to compile your code using the exp function you have math.h on your system . The bad thing is that probably you don't have an erf implementation.

Do
DoHander is offline   Reply With Quote

Old   June 17, 2010, 18:02
Default
  #13
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
Here is a slightly better approximation:

http://en.wikipedia.org/wiki/Error_function

Do
DoHander is offline   Reply With Quote

Old   June 17, 2010, 18:11
Default
  #14
Member
 
Ivan
Join Date: May 2009
Posts: 85
Rep Power: 16
ivanbuz is on a distinguished road
Great! that is indeed a better approximation with elementary functions. Thanks!!

Ivan
ivanbuz 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
[swak4Foam] GroovyBC the dynamic cousin of funkySetFields that lives on the suburb of the mesh gschaider OpenFOAM Community Contributions 300 October 29, 2014 18:00
Urgent, Urgent, a UDF problem, PLEASE HELP!!! Max FLUENT 1 September 24, 2010 20:30
So many questions in DPM & UDF - Help! URGENT! Prashanth FLUENT 0 March 3, 2009 22:26
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51
URGENT ! UDF ERROR! Prateep Chatterjee FLUENT 6 October 16, 2001 19:20


All times are GMT -4. The time now is 23:57.