# How to update variable value every 50 iterations?

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

 September 3, 2019, 02:55 #2 Senior Member   Alexander Join Date: Apr 2013 Posts: 1,419 Rep Power: 21 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 /* 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

September 3, 2019, 05:20
#3
New Member

Join Date: Sep 2019
Posts: 24
Rep Power: 3
Quote:
 Originally Posted by AlexanderZ 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 /* 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.

 Tags udf, udf code

 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 OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post bigphil OpenFOAM CC Toolkits for Fluid-Structure Interaction 566 Today 13:45 Nkl OpenFOAM Running, Solving & CFD 19 October 10, 2019 02:42 mbay101 OpenFOAM Running, Solving & CFD 13 December 28, 2013 13:12 jonmec OpenFOAM Running, Solving & CFD 3 July 28, 2011 05:24 nileshjrane OpenFOAM Running, Solving & CFD 8 August 26, 2010 12:50

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