CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   Define Profile, time dependent flow variation query (http://www.cfd-online.com/Forums/fluent-udf/113054-define-profile-time-dependent-flow-variation-query.html)

Sdezmond February 11, 2013 09:35

Define Profile, time dependent flow variation query
 
Hello

I'm trying to send a wave down a tank/conduit that is 100m long and 5x5m and filled with 1m of water. To do this im using a UDF to vary the flow at the input face of the tank (one end). essentially all the UDF is supposed to do is check the time, as an if statement to the effect of; if the time is greater than A, but less than B, then set input mass kg/s to x, else set input mass kg/s to y.

This is my first attempt at using fluent or indeed any CFD and im having problems getting it working. I've written two UDFs; one that just inputs a constant flow. I figured if i could get it working at least i would know the basic syntax etc. And one that inputs a wave/flow rise and decline. The first UDF does load in to fluent but doesnt produce the desired result (i don't get any water flowing down the tank), the second wont load as there are syntax issues with the If statement (im not a very experienced programmer and no little about c).

heres my code, can any one give me some pointers?

============
UDF 1 a constant flow

#include “udf.h”

DEFINE_PROFILE(constant_in, t, nv)
{
real x[ND_ND]; real v; face_t f;


begin_f_loop(f,t)
{

F_CENTROID(x,f,t);
v=2;
F_PROFILE(f,t,nv) =v;
}
end_f_loop(f,t)




#include “udf.h”

DEFINE_PROFILE(wave_in, t, nv)
{
real x[ND_ND]; real v =5; face_t f;
real T;
real a =2;
real b=4;


begin_f_loop(f,t)
{

F_CENTROID(x,f,t);
T=RP_Get_real(“flow-time”);

if (T>=a, T<=b);
{

F_PROFILE(f,t,nv) =v;
}
else
{
F_PROFILE(f,t,nv) =2;
}
}
end_f_loop(f,t)
}

NCle February 15, 2013 12:45

similar
 
Hi SDesmond,

I'm trying to do the same thing: have the UDF "turn on" at a certain time in the simulation, with IF statements.

Here is my UDF, which seemed to turn on at right time. notice the 1e-4 seconds (when it turns on). The UDF doesn't change rho unless time > 1e-4 s.

================================================== =====
#include"udf.h"
#define BMODULUS 1.1e15
#define rho_ref 1060
DEFINE_PROPERTY(superfluid_density,c,t)
{
real rho;
real p, dp;
real p_operating;
real time;

p_operating = RP_Get_Real(
"operating-pressure");
time = CURRENT_TIME;
p = C_P(c,t);
dp = p-p_operating;
rho = rho_ref/(1.0-dp/BMODULUS);
if (dp > BMODULUS/2)
rho = rho_ref;
if (dp < 0)
rho = rho_ref;
if (time < 1e-4)
rho = rho_ref;
return rho;
}

================================================== ==================
Hope this helps! I think in your UDF you have two IF conditions like if (dp < 0, dp > x). Try writing it so its just one like if (dp < 0). That might help, but also you may be right: if that is how to say "if this or this" in C+ let me know !

Sdezmond February 15, 2013 23:11

I managed to get my UDF working. Reading the user manuals for fluent, i realised that the UDF code was based on C, so i asked google how you write double clause if statements in C.

you use && symbols between each statement so;

if ( y >= a && Y <= b) is the correct syntax.

also for some reason you have to multiply your eventual flow mass rate by the vector.

This means creating a vector variable

y=x[1]

and then when defining my F_PROFILE i must multiply my flow by it

so if flow rate =F

F_PROFILE = F*Y.

apart from those two errors i think most of my UDF above is fine

amaly March 2, 2013 22:58

UDF to read velocity from a text file
 
Hello,
I would like to set the boundary conditions for LES that can read velocity data from a text file and adapt the boundary conditions accordingly. Any help regarding how to read the data file (velocity.txt) and distribute the values on a grid of points at the input will be appreciated.

msaeedsadeghi March 3, 2013 06:13

You can use fscanf to read a text file and use it's information as you want.

amaly March 3, 2013 12:13

Could you please help me find the error in this UDF:



#include "udf.h"
#include "para.h"
#include "prf.h"
const int maxz=10, maxy=10, SIZE = 10 * 10;
real u[100],v[100],w[100];
int ind[100];
FILE *fp1, *fp2;

DEFINE_ON_DEMAND(my_init_func)
{
#if RP_NODE
if (I_AM_NODE_ZERO_P)
{
Domain *domain;
domain = Get_Domain(1);
fp1 = fopen("u.txt", "r");
fp2 = fopen("index.txt","r");
int i;
for(i = 0;i < SIZE;i++) {
fscanf(fp2,"%d",&ind[i]);
}
printf("Files opened\n");
}
#endif
}

DEFINE_EXECUTE_AT_END(velo_update)
{
#if RP_NODE
if (I_AM_NODE_ZERO_P)
{
Domain *domain;
domain = Get_Domain(1);
static const int SIZE = maxy * maxz;
int i;
for(i = 0;i < SIZE;i++)
fscanf(fp1, "%f", &u[i]);
}
#endif
}

DEFINE_PROFILE(u_velocity,thread,index)
{
#if RP_NODE
if (I_AM_NODE_ZERO_P)
{
face_t f;
int i = 0;
begin_f_loop(f,thread)
{
F_PROFILE(f,thread,index) = u[ind[i]];
i++;
}
end_f_loop(f,thread)
}
#endif
}




I would like to read the values of u from the file u.text each time step and distribute that on the input (input bc is varing with time).

Thanks


All times are GMT -4. The time now is 15:38.