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

How to update variable value every 50 iterations?

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 2, 2019, 08:55
Default How to update variable value every 50 iterations?
  #1
New Member
 
Join Date: Sep 2019
Posts: 24
Rep Power: 3
NonStopEagle is on a distinguished road
Hello Everyone,
I have been trying to write a program to compute slip velocity on a wall for a micro-nozzle, i need to update the value of relaxation every 50 iterations and have written a code for the same. But i just can't seem to get it to work.


Any help will be appreciated.


thanks in advance
(there are some redundant variables...i am still testing the code)

heres the udf :


#include "udf.h" /* must be at the beginning of every UDF */
/*#include "mem.h" /* must be at the beginning of this UDF */
//#include <math.h> /* must be at the beginning of this UDF */
/*#include "metric.h" /* must be at the beginning of this UDF */
#define k_B 1.3805e-23 /* Boltzman constant (j/K)*/
#define sigma 419e-12 /* molecular diameter*/
#define sigma_v 1 /* Tangential momentum accommodation coefficient*/
#define sigma_T 1 /*Thermal accommodation coefficient*/
#define pi 3.14159 /* pi number*/
#define sqrt_2 1.41421 /* sqrt(2) number */
//#define relax 50e-3
DEFINE_PROFILE(wall_slip_velocity, t, index)
{
double T, P, density, MU, K, landa, a_m, du_da, dT_dx, u_f,DU,DV;
double A[ND_ND];
face_t f;
Thread* t0;
cell_t c0;
double relax = 105e-3;
double DUR, DVR;
int counter = 0;

begin_f_loop(f, t)
{
counter = counter + 1;
printf("Counter %d", counter);
t0 = THREAD_T0(t); /* adjacent cell thread to f */
c0 = F_C0(f, t); /* adjacent cell to f */
T = C_T(c0, t0); /* temperature of the cell */
P = C_P(c0, t0); /* peressure of the cell */
density = C_R(c0, t0); /* density of the cell*/
MU = C_MU_L(c0, t0); /* laminar viscosity of the cell */
K = C_K_L(c0, t0); /* thermal conductivity of the cell */
landa = (k_B * T) / (sqrt_2 * pi * sigma * sigma * P); /* mean free path line */
DU = C_DUDY(c0, t0);
DV = C_DVDY(c0, t0);
if (DU < 0)
{
DU = (-1 * DU);
}
if (DV < 0)
{
DV = (-1 * DV);
}

F_AREA(A, f, t);
a_m = NV_MAG(A); /* magnitude of the cell area vector */
du_da = NV_DOT(A, A) / a_m; /* n- component of the cell x-velocity reconstruction gradient(RG) vector */
dT_dx = 1; /* x-component of the cell temperature reconstruction gradient(RG) vector */

// Calculation of the Wall Slip Velocity
F_PROFILE(f, t, index) = relax * sin(22.75 * pi / 180) * (((2 - sigma_v) / sigma_v) * landa * (DU + DV) + 0.75 * (MU / (density * T)) * dT_dx);
if ((counter % 50) == 0)
{
relax = relax + 1e-3;
printf("The residual is : %f", counter);
}


}
end_f_loop(f, t)


}
DEFINE_PROFILE(wall_slip_velocity, t, index)
{
double T, P, density, MU, K, landa, a_m, du_da, dT_dx, u_f, DU, DV;
double A[ND_ND];
face_t f;
Thread* t0;
cell_t c0;
double relax = 105e-3;
double DUR, DVR;
int counter = 0.0;

begin_f_loop(f, t)
{
t0 = THREAD_T0(t); /* adjacent cell thread to f */
c0 = F_C0(f, t); /* adjacent cell to f */
T = C_T(c0, t0); /* temperature of the cell */
P = C_P(c0, t0); /* peressure of the cell */
density = C_R(c0, t0); /* density of the cell*/
MU = C_MU_L(c0, t0); /* laminar viscosity of the cell */
/*DUR = C_U_RG(c0, t0)[1];
DVR = C_V_RG(c0, t0)[1];*/

K = C_K_L(c0, t0); /* thermal conductivity of the cell */
landa = (k_B * T) / (sqrt_2 * pi * sigma * sigma * P); /* mean free path line */
DU = C_DUDY(c0, t0);
DV = C_DVDY(c0, t0);
if (DU < 0)
{
DU = (-1 * DU);
}
if (DV < 0)
{
DV = (-1 * DV);
}

F_AREA(A, f, t);
a_m = NV_MAG(A); /* magnitude of the cell area vector */
du_da = NV_DOT(A, A) / a_m; /* n- component of the cell x-velocity reconstruction gradient(RG) vector */
dT_dx = 1; /* x-component of the cell temperature reconstruction gradient(RG) vector */
F_PROFILE(f, t, index) = relax * cos(22.75 * pi / 180) * (((2 - sigma_v) / sigma_v) * landa * (DU + DV) + 0.75 * (MU / (density * T)) * dT_dx);
if ((counter % 50) == 0)
{
relax = relax + 1e-3;
}
counter = counter + 1;
}
end_f_loop(f, t)
}
NonStopEagle is offline   Reply With Quote

Old   September 3, 2019, 02:55
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,419
Rep Power: 21
AlexanderZ will become famous soon enough
if you are talking about timesteps (not iterations) :
Code:
#include "udf.h" /* must be at the beginning of every UDF */
/*#include "mem.h" /* must be at the beginning of this UDF */
//#include <math.h> /* must be at the beginning of this UDF */
/*#include "metric.h" /* must be at the beginning of this UDF */
#define k_B 1.3805e-23 /* Boltzman constant (j/K)*/
#define sigma 419e-12 /* molecular diameter*/
#define sigma_v 1 /* Tangential momentum accommodation coefficient*/
#define sigma_T 1 /*Thermal accommodation coefficient*/
#define pi 3.14159 /* pi number*/
#define sqrt_2 1.41421 /* sqrt(2) number */
double relax = 105e-3;
int counter = 0;
//#define relax 50e-3
DEFINE_PROFILE(wall_slip_velocity, t, index)
{
double T, P, density, MU, K, landa, a_m, du_da, dT_dx, u_f,DU,DV;
double A[ND_ND];
face_t f;
Thread* t0;
cell_t c0;

double DUR, DVR;


begin_f_loop(f, t)
{
counter = counter + 1;
printf("Counter %d", counter);
t0 = THREAD_T0(t); /* adjacent cell thread to f */
c0 = F_C0(f, t); /* adjacent cell to f */
T = C_T(c0, t0); /* temperature of the cell */
P = C_P(c0, t0); /* peressure of the cell */
density = C_R(c0, t0); /* density of the cell*/
MU = C_MU_L(c0, t0); /* laminar viscosity of the cell */
K = C_K_L(c0, t0); /* thermal conductivity of the cell */
landa = (k_B * T) / (sqrt_2 * pi * sigma * sigma * P); /* mean free path line */
DU = C_DUDY(c0, t0);
DV = C_DVDY(c0, t0);
if (DU < 0)
{
DU = (-1 * DU);
}
if (DV < 0)
{
DV = (-1 * DV);
}

F_AREA(A, f, t);
a_m = NV_MAG(A); /* magnitude of the cell area vector */
du_da = NV_DOT(A, A) / a_m; /* n- component of the cell x-velocity reconstruction gradient(RG) vector */
dT_dx = 1; /* x-component of the cell temperature reconstruction gradient(RG) vector */

// Calculation of the Wall Slip Velocity
F_PROFILE(f, t, index) = relax * sin(22.75 * pi / 180) * (((2 - sigma_v) / sigma_v) * landa * (DU + DV) + 0.75 * (MU / (density * T)) * dT_dx);
}
end_f_loop(f, t)


}
DEFINE_PROFILE(wall_slip_velocity, t, index)
{
double T, P, density, MU, K, landa, a_m, du_da, dT_dx, u_f, DU, DV;
double A[ND_ND];
face_t f;
Thread* t0;
cell_t c0;
double DUR, DVR;

begin_f_loop(f, t)
{
t0 = THREAD_T0(t); /* adjacent cell thread to f */
c0 = F_C0(f, t); /* adjacent cell to f */
T = C_T(c0, t0); /* temperature of the cell */
P = C_P(c0, t0); /* peressure of the cell */
density = C_R(c0, t0); /* density of the cell*/
MU = C_MU_L(c0, t0); /* laminar viscosity of the cell */
/*DUR = C_U_RG(c0, t0)[1];
DVR = C_V_RG(c0, t0)[1];*/

K = C_K_L(c0, t0); /* thermal conductivity of the cell */
landa = (k_B * T) / (sqrt_2 * pi * sigma * sigma * P); /* mean free path line */
DU = C_DUDY(c0, t0);
DV = C_DVDY(c0, t0);
if (DU < 0)
{
DU = (-1 * DU);
}
if (DV < 0)
{
DV = (-1 * DV);
}

F_AREA(A, f, t);
a_m = NV_MAG(A); /* magnitude of the cell area vector */
du_da = NV_DOT(A, A) / a_m; /* n- component of the cell x-velocity reconstruction gradient(RG) vector */
dT_dx = 1; /* x-component of the cell temperature reconstruction gradient(RG) vector */
F_PROFILE(f, t, index) = relax * cos(22.75 * pi / 180) * (((2 - sigma_v) / sigma_v) * landa * (DU + DV) + 0.75 * (MU / (density * T)) * dT_dx);
}
end_f_loop(f, t)
}

DEFINE_EXECUTE_AT_END(define_relax)
{
if ((counter % 50) == 0)
{
relax = relax + 1e-3;
}
counter = counter + 1;
}
dont forget to hook DEFINE_EXECUTE_AT_END macro

best regards
AlexanderZ is offline   Reply With Quote

Old   September 3, 2019, 05:20
Default
  #3
New Member
 
Join Date: Sep 2019
Posts: 24
Rep Power: 3
NonStopEagle is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
if you are talking about timesteps (not iterations) :
Code:
#include "udf.h" /* must be at the beginning of every UDF */
/*#include "mem.h" /* must be at the beginning of this UDF */
//#include <math.h> /* must be at the beginning of this UDF */
/*#include "metric.h" /* must be at the beginning of this UDF */
#define k_B 1.3805e-23 /* Boltzman constant (j/K)*/
#define sigma 419e-12 /* molecular diameter*/
#define sigma_v 1 /* Tangential momentum accommodation coefficient*/
#define sigma_T 1 /*Thermal accommodation coefficient*/
#define pi 3.14159 /* pi number*/
#define sqrt_2 1.41421 /* sqrt(2) number */
double relax = 105e-3;
int counter = 0;
//#define relax 50e-3
DEFINE_PROFILE(wall_slip_velocity, t, index)
{
double T, P, density, MU, K, landa, a_m, du_da, dT_dx, u_f,DU,DV;
double A[ND_ND];
face_t f;
Thread* t0;
cell_t c0;

double DUR, DVR;


begin_f_loop(f, t)
{
counter = counter + 1;
printf("Counter %d", counter);
t0 = THREAD_T0(t); /* adjacent cell thread to f */
c0 = F_C0(f, t); /* adjacent cell to f */
T = C_T(c0, t0); /* temperature of the cell */
P = C_P(c0, t0); /* peressure of the cell */
density = C_R(c0, t0); /* density of the cell*/
MU = C_MU_L(c0, t0); /* laminar viscosity of the cell */
K = C_K_L(c0, t0); /* thermal conductivity of the cell */
landa = (k_B * T) / (sqrt_2 * pi * sigma * sigma * P); /* mean free path line */
DU = C_DUDY(c0, t0);
DV = C_DVDY(c0, t0);
if (DU < 0)
{
DU = (-1 * DU);
}
if (DV < 0)
{
DV = (-1 * DV);
}

F_AREA(A, f, t);
a_m = NV_MAG(A); /* magnitude of the cell area vector */
du_da = NV_DOT(A, A) / a_m; /* n- component of the cell x-velocity reconstruction gradient(RG) vector */
dT_dx = 1; /* x-component of the cell temperature reconstruction gradient(RG) vector */

// Calculation of the Wall Slip Velocity
F_PROFILE(f, t, index) = relax * sin(22.75 * pi / 180) * (((2 - sigma_v) / sigma_v) * landa * (DU + DV) + 0.75 * (MU / (density * T)) * dT_dx);
}
end_f_loop(f, t)


}
DEFINE_PROFILE(wall_slip_velocity, t, index)
{
double T, P, density, MU, K, landa, a_m, du_da, dT_dx, u_f, DU, DV;
double A[ND_ND];
face_t f;
Thread* t0;
cell_t c0;
double DUR, DVR;

begin_f_loop(f, t)
{
t0 = THREAD_T0(t); /* adjacent cell thread to f */
c0 = F_C0(f, t); /* adjacent cell to f */
T = C_T(c0, t0); /* temperature of the cell */
P = C_P(c0, t0); /* peressure of the cell */
density = C_R(c0, t0); /* density of the cell*/
MU = C_MU_L(c0, t0); /* laminar viscosity of the cell */
/*DUR = C_U_RG(c0, t0)[1];
DVR = C_V_RG(c0, t0)[1];*/

K = C_K_L(c0, t0); /* thermal conductivity of the cell */
landa = (k_B * T) / (sqrt_2 * pi * sigma * sigma * P); /* mean free path line */
DU = C_DUDY(c0, t0);
DV = C_DVDY(c0, t0);
if (DU < 0)
{
DU = (-1 * DU);
}
if (DV < 0)
{
DV = (-1 * DV);
}

F_AREA(A, f, t);
a_m = NV_MAG(A); /* magnitude of the cell area vector */
du_da = NV_DOT(A, A) / a_m; /* n- component of the cell x-velocity reconstruction gradient(RG) vector */
dT_dx = 1; /* x-component of the cell temperature reconstruction gradient(RG) vector */
F_PROFILE(f, t, index) = relax * cos(22.75 * pi / 180) * (((2 - sigma_v) / sigma_v) * landa * (DU + DV) + 0.75 * (MU / (density * T)) * dT_dx);
}
end_f_loop(f, t)
}

DEFINE_EXECUTE_AT_END(define_relax)
{
if ((counter % 50) == 0)
{
relax = relax + 1e-3;
}
counter = counter + 1;
}
dont forget to hook DEFINE_EXECUTE_AT_END macro

best regards
Thanks AlexanderZ, the code works like a charm.
NonStopEagle is offline   Reply With Quote

Reply

Tags
udf, udf code

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
[solidMechanics] Support thread for "Solid Mechanics Solvers added to OpenFOAM Extend" bigphil OpenFOAM CC Toolkits for Fluid-Structure Interaction 566 Today 13:45
chtMultiRegionSimpleFoam: maximum number of iterations excedeed. Nkl OpenFOAM Running, Solving & CFD 19 October 10, 2019 02:42
Unstabil Simulation with chtMultiRegionFoam mbay101 OpenFOAM Running, Solving & CFD 13 December 28, 2013 13:12
Orifice Plate with a fully developed flow - Problems with convergence jonmec OpenFOAM Running, Solving & CFD 3 July 28, 2011 05:24
Error while running rhoPisoFoam.. nileshjrane OpenFOAM Running, Solving & CFD 8 August 26, 2010 12:50


All times are GMT -4. The time now is 21:23.