CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Inserting values in a specific order using begin_f_loop() (https://www.cfd-online.com/Forums/fluent-udf/220811-inserting-values-specific-order-using-begin_f_loop.html)

NonStopEagle September 23, 2019 07:32

Inserting values in a specific order using begin_f_loop()
 
hello everyone,
I have been trying to insert slip velocity values from a text file onto a wall,
but when i use begin_f_loop() to apply the velocity values to faces, the values are applied randomly. I want them to be applied in the order of the cells on the wall.

here's the udf i have
#include "udf.h"

/*Global variables*/
real* uvelocity;
//real* xcord;
//real* yvalu;
//real* search;
int n = 228; /*number of lines with data on the file*/


DEFINE_EXECUTE_ON_LOADING(on_load, libudf) /*Read the .txt file and store the velocity values into a vector*/
{
int i = 1;
float data_vel;
//float xval;
//float yvalue;
FILE* vel;
FILE* tm;
FILE* yval;
vel = fopen("test.txt", "r");
//tm = fopen("xcord.txt", "r");
//yval = fopen("ycord.txt", "r");
uvelocity = (real*)malloc((n) * sizeof(real));
//xcord = (real*)malloc((n) * sizeof(real));
//yvalu = (real*)malloc((n) * sizeof(real));
//search = (real*)malloc((n) * sizeof(real));

/*Places the data into the vector*/
for (i = 1; i <= n; i++)
{
data_vel = 0;
//data_time = 0;
fscanf(vel, "%f", &data_vel);
fscanf(tm, "%f", &xval);
fscanf(yval, "%f", &yvalue);/* read one value per line */
uvelocity[i] = data_vel;
xcord[i] = xval;
yvalu[i] = yvalue;
Message("* velocity_U[%d] = %f\n", i, uvelocity[i]);
Message("* x coodinate[%d] = %f\n", i, xcord[i]);
Message("* y coordinate[%d] = %f\n", i, yvalu[i]);
}
fclose(vel);
fclose(xcord);
fclose(yval);

}

DEFINE_ON_DEMAND(list_velocity) /*check if the values are right on the vector*/
{
int i = 1, j = 1;
for (i = 0; i < n; i++)
{
Message("\nVelocity_U[%d]=%f\n", i, uvelocity[i]);
//Message("\nTime[%d]=%d\n", i, time[j]);
j++;
}
}

DEFINE_PROFILE(inlet_x_velocity, thread, nv)
{
real x[ND_ND];
real y;
face_t f;
int n_ts;
real current_time;
int j = 1;
int tL = 1, tR = 199, deltat = 200;

//current_time = CURRENT_TIME;
//n_ts = N_TIME;
begin_f_loop(f, thread)
{
F_PROFILE(f, thread, nv) = (uvelocity[j]);
j = j + 1;
end_f_loop(f, thread)
}
}
pardon the commenting, the code is not complete yet...
I would appreciate any help.

AlexanderZ September 24, 2019 00:03

try this
Code:

#include "udf.h"

/*Global variables*/
real* uvelocity;
real* xcord;
real* yvalu;
real* search;
int n = 228; /*number of lines with data on the file*/


DEFINE_EXECUTE_ON_LOADING(on_load, libudf) /*Read the .txt file and store the velocity values into a vector*/
{
int i = 1;
float data_vel;
float xval;
float yvalue;
FILE* vel;
FILE* tm;
FILE* yval;
vel = fopen("test.txt", "r");
tm = fopen("xcord.txt", "r");
yval = fopen("ycord.txt", "r");
uvelocity = (real*)malloc((n) * sizeof(real));
//xcord = (real*)malloc((n) * sizeof(real));
//yvalu = (real*)malloc((n) * sizeof(real));
//search = (real*)malloc((n) * sizeof(real));

/*Places the data into the vector*/
for (i = 1; i <= n; i++)
{
data_vel = 0;
//data_time = 0;
fscanf(vel, "%lf", &data_vel);
fscanf(tm, "%lf", &xval);
fscanf(yval, "%lf", &yvalue);/* read one value per line */
uvelocity[i] = data_vel;
xcord[i] = xval;
yvalu[i] = yvalue;
Message("* velocity_U[%d] = %f\n", i, uvelocity[i]);
Message("* x coodinate[%d] = %f\n", i, xcord[i]);
Message("* y coordinate[%d] = %f\n", i, yvalu[i]);
}
fclose(vel);
fclose(tm);
fclose(yval);

}

DEFINE_ON_DEMAND(list_velocity) /*check if the values are right on the vector*/
{
int i = 1, j = 1;
for (i = 0; i < n; i++)
{
Message("\nVelocity_U[%d]=%f\n", i, uvelocity[i]);
//Message("\nTime[%d]=%d\n", i, time[j]);
j++;
}
}

DEFINE_PROFILE(inlet_x_velocity, thread, nv)
{
real x[ND_ND];
real y;
face_t f;
int n_ts;
real current_time;
int j = 1;
int tL = 1, tR = 199, deltat = 200;

//current_time = CURRENT_TIME;
//n_ts = N_TIME;
begin_f_loop(f, thread)
{
F_PROFILE(f, thread, nv) = (uvelocity[j]);
j = j + 1;
end_f_loop(f, thread)
}
}

fscanf(vel, "%lf", &data_vel);
use %lf if you use double precision solver.

also, if you want to apply your velocities in special sequence you may link it to coordinates and check during face loop is this face belongs to specific coordinate

best regards

NonStopEagle September 24, 2019 12:13

Thanks Alexander,
I am trying to input slip velocity on a wall by assigning velocities to the faces adjacent to it. I have the velocity values but when i assign them, they are applied randomly to the faces.
the solution to this, as i understand it to somehow calculate the coordinates of the cells and use them to assign velocities to the faces. I believe this is what you recommended as well.
I have written a udf to get the coordinates but i don't know how to use them to assign the velocity values to the walls
below is the udf for getting the coordinates:
#include"udf.h"
FILE* fout; float xx[ND_ND];

DEFINE_ON_DEMAND(get_coords)
{
Domain* domain;
face_t f;
cell_t c;
Thread* t;
domain = Get_Domain(1);
t = Lookup_Thread(domain, 8);
fout = fopen("Coordinates.out", "w");

if (fout == NULL)
Message("Can't open the file");

else

{
begin_c_loop(c, t)

{
F_CENTROID(xx, c, t);
fprintf(fout, "%d %g %g %g\n", c, xx[0], xx[1], xx[2]);
}
end_c_loop(c, t)

fprintf(fout, "\n");
fclose(fout);
}
}
if you could guide me on how to assign velocity values using the obtained coordinates, it will be really helpful.
thanks in advnace


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