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

fluctuating velocity generation program error

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 4, 2017, 15:32
Default fluctuating velocity generation program error
  #1
New Member
 
Ashutosh Sharma
Join Date: Jan 2017
Posts: 11
Rep Power: 9
ashu@123 is on a distinguished road
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

main()
{
int step, i, k;
float I, Lxu, U, u, pi, A, B, t, dt, nUpper, nLower, dn, n, phi, Su, sum, Ak;
double r;
char filename[8];
FILE *fp;
/*================================================= ========*/
printf ("Enter name of file to write to:");
scanf("%s", filename);
fp = fopen(filename,"w");
printf ("Enter the streamwise mean velocity:");
scanf("%f", &U);
printf ("Enter the streamwise turbulent intensity (decimal):");
scanf("%f", &I);
printf ("Enter the streamwise integral length scale (m):");
scanf("%f", &Lxu);
printf ("Number of timesteps, maximum 20000:");
scanf("%d", &step);
printf ("Stepsize of time in second:");
scanf("%f", &dt);
pi = 3.141592654;
A = 4.0*I*I*Lxu*U;
B = 70.8*(Lxu/U)*(Lxu/U);
nUpper=1.0/2.0/dt;
nLower=0.001;
dn=(nUpper-nLower)/step; /* here taking N = M = step */
t = 0;
for (i=0; i<step; i++)
{
sum = 0.0;
srand48(time(NULL));
n = nLower+0.5*dn;
for(k=0; k<step; k++)
{
r = drand48();
phi=r*2.0*pi; /*phi to be randomly selected*/
Su = A/pow((1.0 + B*n*n),(5.0/6.0));
Ak = sqrt(Su*dn);
sum = sum + Ak*cos(2.0*pi*n*t + phi);
n = n+dn;
}
u = sqrt(2.0)*sum;
fprintf(fp,"%f\n",u);
t = t + dt;
}
fclose(fp);
}




Above program is to generate fluctuating velocity components.
While running above program, i am getting following error:

undefined reference to 'srand48'
undefined reference to 'drand48'

can anyone suggest me where is the problem in above program.
Thank You in advance.
ashu@123 is offline   Reply With Quote

Old   February 6, 2017, 11:27
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You ask where the problem is in your program... Well, the error messages are clear...

Code:
undefined reference to 'srand48'
undefined reference to 'drand48'
Search for 'srand48' and 'drand48' and you will easily find the lines that give the problem. The first problem is in the line "srand48(time(NULL));" and the second problem in the line "r = drand48();".

A better question would be: what is the problem in your program? Well, even that is more or less clear from the error message: you use two words that are undefined. The compiler does not know what srand48 is. The compiler does not know what drand48 is. So the compiler does not know what to do.

An even better question would be: how to solve these problems? That is not shown in the error message. But some logical thinking can solve this. The problem is that you use functions that are not known to the compiler. There are two ways to solve this:
1. Tell the compiler what the functions should do;
2. Use different functions that the compiler knows.

I have no idea why you chose to use srand48 and drand48. But they are unknown to your compiler. For this work, it is sufficient to use the standard random number generator, see http://www.cplusplus.com/reference/cstdlib/rand/.
pakk 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
error compiling modified applications yvyan OpenFOAM Programming & Development 21 March 1, 2016 05:53
[OpenFOAM] Native ParaView Reader Bugs tj22 ParaView 270 January 4, 2016 12:39
[swak4Foam] GroovyBC the dynamic cousin of funkySetFields that lives on the suburb of the mesh gschaider OpenFOAM Community Contributions 300 October 29, 2014 19:00
Errors in UDF shashank312 Fluent UDF and Scheme Programming 6 May 30, 2013 21:30
How to install CGNS under windows xp? lzgwhy Main CFD Forum 1 January 11, 2011 19:44


All times are GMT -4. The time now is 16:02.