# Convective B.C. at the outlet

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

March 28, 2017, 17:30
Convective B.C. at the outlet
#1
New Member

Karthikeyan
Join Date: Nov 2016
Posts: 14
Rep Power: 6
Hi,

I am working on the 2D transient simulation of external flow over a cylinder and would like to use the convective BC given by:

∂u/∂t+(U_c)(∂u/∂x)=0

at the outlet boundary. I have written a UDF to represent the discretized version of the BC; the UDF is getting interpreted and I am hooking to the 'velocity inlet BC' that I have given at outlet but when I try to initialize the solution, "fatal signal segmentation error" is reported.

I am attaching my source file. can I get some help?

thanks,
Karthikeyan

Quote:
 #include"udf.h" DEFINE_PROFILE(CBC_u_vel,t,i) { real x, y, z, u_temp, u_cor, mass_out = 0, ds; real x[ND_ND], y[ND_ND]; Thread *nt; face_t f; cell_t c, nc; begin_f_loop(f,t) { mass_out+=F_FLUX(f,t); } end_f_loop(f,t) u_cor = (20 - mass_out)/20; begin_f_loop(f,t) { nc = F_C0(f,t); nt = THREAD_T0(t); F_CENTROID(x,f,t); C_CENTROID(y,nc,nt); ds = x[0] - y[0]; if((CURRENT_TIME/CURRENT_TIMESTEP <= 1) { x = 0; y = 0; } else { x = F_U_M1(f,t); y = C_U_M1(nc,nt); } u_temp = F_U_M1(f,t) - CURRENT_TIMESTEP*(F_U_M1(f,t)-C_U_M1(nc,nt))/ds; F_PROFILE(f,t,i) = u_temp + u_cor; } end_f_loop(f,t) }
Attached Files
 convective BC_u-vel.c (622 Bytes, 8 views)

Last edited by kar1209; March 28, 2017 at 17:36. Reason: For quoting the Source file

 March 29, 2017, 08:43 #2 Senior Member   Join Date: Nov 2013 Posts: 1,518 Rep Power: 21 You defined x and y two times. And the following code does nothing: Code: ```if((CURRENT_TIME/CURRENT_TIMESTEP <= 1) { x = 0; y = 0; } else { x = F_U_M1(f,t); y = C_U_M1(nc,nt); }``` Because you never use x and y afterwards.

April 4, 2017, 03:47
#3
New Member

Karthikeyan
Join Date: Nov 2016
Posts: 14
Rep Power: 6
I have corrected my code but still I am getting the "received a fatal signal (segmentation fault)" error. Is it because the function is not able to access the previous timestep values using F_U_M1 and C_U_M1?
Code:
```#include"udf.h"
DEFINE_PROFILE(CBC_u_vel,t,i)
{
real u_f_old, u_c_old, u_temp, u_cor, mass_out = 0, ds;
real x[ND_ND], y[ND_ND];
face_t f;
cell_t c, nc;
begin_f_loop(f,t)
{
mass_out+=F_FLUX(f,t);
}
end_f_loop(f,t)
u_cor = (20 - mass_out)/20;
begin_f_loop(f,t)
{
nc = F_C0(f,t);
F_CENTROID(x,f,t);
C_CENTROID(y,nc,nt);
ds = x[0] - y[0];
u_f_old = F_U_M1(f,t);
u_c_old = C_U_M1(nc,nt);
u_temp = u_f_old - CURRENT_TIMESTEP*(u_f_old - u_c_old)/ds;
F_PROFILE(f,t,i) = u_temp + u_cor;
}
end_f_loop(f,t)
}```
The UDF manual says:
Quote:
 Note that data from C_T_M1 is available only if user-defined scalars are defined.
How do I define and use user-defined scalars to access data using C_U_M1 in my program?

Any help would be appreciated.

April 11, 2017, 07:21
Got it working!
#4
New Member

Karthikeyan
Join Date: Nov 2016
Posts: 14
Rep Power: 6
I finally managed to get my udf working by using a user defined memory. The link "Previous time step variable to be used in UDF" helped me.

My intention was to impose the convective boundary condition at the outlet of my flow domain.

My objective is to simulate the flow over a square prism at low Reynolds number. The boundary condition to be imposed at the outlet of the domain is:

u/∂t) + (Uc)(∂u/∂x) =0

where, Uc is the convective velocity of the vortex centres and it is usually taken equal to the freestream velocity (Uc = 1 in my case). The attached image bears the discretized form of the equation.

My udf for the above purpose is:

Code:
```#include"udf.h"
/*defining a global variable to to check for the number of timer steps*/
int n_ts = -1;
DEFINE_PROFILE(CBC_u_vel,t,i)
{
real ds, x[ND_ND], y[ND_ND];
face_t f;
cell_t nc;
/* assignment of F_UDMI from previous time step to the profile at the current time step*/
/*if condition to allow assignment of [rofile variable only at the first iteration of the time step*/
if(n_ts != N_TIME)
{
if(CURRENT_TIME == 0)
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = 1;
}
end_f_loop(f,t)
else
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = F_UDMI(f,t,0);
}
end_f_loop(f,t)
/*assigning the time step number to n_ts so that the profile does not work in the next iteration of the time step*/
n_ts = N_TIME;
}
/*loop for updating the F_UDMI at every iteration of the current time step*/
/*at the end of last iteration of the time step, F_UDMI will have the converged solution to be used in the next time step */
begin_f_loop(f,t)
{
nc = F_C0(f,t);
F_CENTROID(x,f,t);
C_CENTROID(y,nc,nt);
ds = x[0] - y[0];
F_UDMI(f,t,0) = F_U(f,t) - CURRENT_TIMESTEP*(F_U(f,t) - C_U(nc,nt))/ds;
}
end_f_loop(f,t)
}```
Unlike my earlier attempts, I am able to successfully hook the udf. I have selected "velocity inlet" BC at the outlet zone and then I have hooked the udf to the x component of the velocity.

When I run the solution and plot the lift and drag coefficient history, I get them as very erroneous.

What might be going wrong in my procedure?
Thanks in advance for any help
Attached Images
 CBC.PNG (13.7 KB, 38 views)

 April 12, 2018, 04:04 #5 New Member   Join Date: Apr 2018 Posts: 3 Rep Power: 4 Hello everybody, Does anyone has input on how to use th UDF that kar1209 posted ? Hooking it up and using it does not yield correct results, and as a matter of fact if 1/ I use it in a velocity inlet, it leads to segfault 2/ I use it as a slip velocity at a wall, the velocity in the cells next to the wall still goes to zero ... I am using Fluent v16.2. Thank you in advance for anyone's help ! Cheers

 November 14, 2018, 07:04 convective B.C. at outlet. #6 New Member   mukesh Join Date: Nov 2018 Posts: 2 Rep Power: 0 Hello everyone, I have used kar1209's coding for convective b.c.at outlet but in x component of velocity inlet type. It leads crashing of simulation.I have also used velocity with negative sign but facing same problem. Any help would be appreciated.

 November 14, 2018, 23:47 #7 Senior Member   Alexander Join Date: Apr 2013 Posts: 1,471 Rep Power: 21 describe step by step, how you start this simulation best regards

 November 28, 2018, 01:43 convective B.C. at outlet. #8 New Member   mukesh Join Date: Nov 2018 Posts: 2 Rep Power: 0 thank you for replying AlexanderZ. My simulation detail-i have used 2d, transient case for uniform flow(velocity= 9 m/s) over cylinder. model-kw SST, method- 2nd order implicit, rest all are default( ANSYS fluent 19.1) Boundary condition- 1. Inlet-velocity inlet 2.wall-wall with no slip condition 3.cylinder-wall with no slip condition 4.outlet-convective b.c.(mentioned already) time step is .001s suggestion is very please to me. thank you.

 Tags boundary condition, convective, cylinder flow, fluent, udf