CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Fluent UDF - Random Noise (https://www.cfd-online.com/Forums/fluent/47658-fluent-udf-random-noise.html)

Tanner March 18, 2008 10:28

Fluent UDF - Random Noise
 
I am trying to implement a constant time dependent (step) velocity normal to the boundary at the inlet of my simulation. I would also like to include some random nosie with zero mean. I am not an expert in C but i patched together the script below:

#include "udf.h"

#include "stdlib.h"

DEFINE_PROFILE(Velocity_profile,thread,index) {

face_t f;

double Flow_Time;

double U;

double Random_Number_Array[100000] = {0.0};

double Mean = {0.0};

int Number_of_Face_Nodes;

int i;

int Counter = {0};

//Find number of nodes on face//

Number_of_Face_Nodes = F_NNODES(f,thread);

//Find simulation time//

Flow_Time = RP_GET_REAL("flow-time");

if (Flow_Time < 1.0)

U = 1.0;

else

{

U=2.0;

}

//Generate Random numbers for each node on inflow face//

//The range is set to -0.5 to 0.5//

for (i=1 ; i < Number_of_Face_Nodes ; i++)

{

srand();

Random_Number_Array[i] =(((double) rand()/(double) RAND_MAX)-0.5)*((double) 2);

Mean = Mean + Random_Number_Array[i]; }

Mean = Mean/(double) Number_of_Face_Nodes;

//Ensure that mean is zero//

for (i=1 ; i < Number_of_Face_Nodes ; i++)

{Random_Number_Array[i] = Random_Number_Array[i] - Mean;}

begin_f_loop(f,t)

{

Counter = Counter + 1;

//Velocity at each node is U + differenc Random fluctuation//

F_PROFILE(f, thread, index) = U + Random_Number_Array[Counter];

}

end_f_loop(f,t) }

I think this is a good start though I cannot get fluent (6.3.26) to interpret it. I get the error:

cpp -I"/work/tanner/cx1_Fluent/Fluent.Inc/fluent6.3.26/src" -I"/work/tanner/cx1_Fluent/Fluent.Inc/fluent6.3.26/cortex/src" -I"/work/tanner/cx1_Fluent/Fluent.Inc/fluent6.3.26/client/src" -I"/work/tanner/cx1_Fluent/Fluent.Inc/fluent6.3.26/multiport/src" -I. -DUDFCONFIG_H="<udfconfig.h>" "/work/tanner/LES_Unsteady/OCPS2_Forced/test.c" In file included from /work/tanner/LES_Unsteady/OCPS2_Forced/test.c:2: /usr/include/stdlib.h:33: stddef.h: No such file or directory In file included from /usr/include/sys/types.h:31,

from /usr/include/stdlib.h:433,

from /work/tanner/LES_Unsteady/OCPS2_Forced/test.c:2: /usr/include/bits/types.h:31: stddef.h: No such file or directory In file included from /usr/include/stdlib.h:433,

from /work/tanner/LES_Unsteady/OCPS2_Forced/test.c:2: /usr/include/sys/types.h:147: stddef.h: No such file or directory In file included from /usr/include/stdlib.h:606,

from /work/tanner/LES_Unsteady/OCPS2_Forced/test.c:2: /usr/include/alloca.h:25: stddef.h: No such file or directory Error: /usr/include/stdlib.h: line 108: syntax error. cpp: output pipe has been closed

I would certainly appreciate some help. I'm not sure how to get fluent to find the stdlib.h though it is installed on my computer. Many thanks.


Tanner March 19, 2008 06:38

Re: Fluent UDF - Random Noise
 
I have managed to hook the UDF I wanted using the compile function rather than the intrepreted function.

My only concern now is how often the UDF is updated. I want a random profile at each time step NOT iteration.

I have found that including an "if (first_iteration)" statement produces works for unsteady PISO but is this suitable for NITA?

How frequently are profiles updated for NITA? How can I tell it to update at the start of each time step?

Светлана May 29, 2014 03:27

looking at your code, it looks like U is "1.0 + random noise" on the first time step, and "2.0 + random noise" on next time steps. Would you happen to know how to make it "U_old + random noise" instead please?


All times are GMT -4. The time now is 01:36.