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

Inserting values in a specific order using begin_f_loop()

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 23, 2019, 08:32
Default Inserting values in a specific order using begin_f_loop()
  #1
New Member
 
Join Date: Sep 2019
Posts: 24
Rep Power: 6
NonStopEagle is on a distinguished road
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.
NonStopEagle is offline   Reply With Quote

Old   September 24, 2019, 01:03
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 33
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Old   September 24, 2019, 13:13
Default
  #3
New Member
 
Join Date: Sep 2019
Posts: 24
Rep Power: 6
NonStopEagle is on a distinguished road
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
NonStopEagle is offline   Reply With Quote

Reply

Tags
fluent - udf, udf

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
mass flow in is not equal to mass flow out saii CFX 12 March 19, 2018 06:21
Simulation of a single bubble with a VOF-method Suzzn CFX 21 January 29, 2018 01:58
using chemkin JMDag2004 OpenFOAM Pre-Processing 2 March 8, 2016 23:38
Two-Phase Buoyant Flow Issue Miguel Baritto CFX 4 August 31, 2006 13:02
Printing Values on a Specific Surface Matthew FLUENT 1 February 8, 2006 09:15


All times are GMT -4. The time now is 09:24.