|
[Sponsors] |
How to update variable value every 50 iterations? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 2, 2019, 09:55 |
How to update variable value every 50 iterations?
|
#1 |
New Member
Join Date: Sep 2019
Posts: 24
Rep Power: 7 |
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) } |
|
September 3, 2019, 03:55 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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; } best regards |
|
September 3, 2019, 06:20 |
|
#3 | |
New Member
Join Date: Sep 2019
Posts: 24
Rep Power: 7 |
Quote:
|
||
Tags |
udf, udf code |
|
|
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 | 686 | December 22, 2022 10:10 |
chtMultiRegionSimpleFoam: maximum number of iterations excedeed. | Nkl | OpenFOAM Running, Solving & CFD | 19 | October 10, 2019 03:42 |
Unstabil Simulation with chtMultiRegionFoam | mbay101 | OpenFOAM Running, Solving & CFD | 13 | December 28, 2013 14:12 |
Orifice Plate with a fully developed flow - Problems with convergence | jonmec | OpenFOAM Running, Solving & CFD | 3 | July 28, 2011 06:24 |
Error while running rhoPisoFoam.. | nileshjrane | OpenFOAM Running, Solving & CFD | 8 | August 26, 2010 13:50 |