hello.
I am currently writing a mass source term UDF to implement a mass transport model in a 3D model.
The model is to absorb oxygen from the air into water, and I need the VOF gradient to calculate the effective area in this process.
effective area * abs(liquid volume fraction gradient) = abs(liquid volume fraction gradient)
Therefore, the UDF is largely written in two parts: the VOF gradient calculation and the source term.
Initially, I used the C_VOF_G codec, but I encountered an error, so I used the code published on the Internet. (
Source)
The UDF code I wrote is shown below.
PHP Code:
#include "udf.h"
#include "math.h"
#define MW_O2 0.03199 /* Oxygen molecular weight [kg/mol] */
#define MW_H2O 0.0180001 /* Water molecular weight [kg/mol] */
#define Henry_coeff 0.0013 /* Henry's constant for oxygen in mol/atm/L */
#define D_L 2.1e-9 /* Diffusion coefficient oxygen in water, D [m^2/s] */
#define PI 3.14159265359
#define OMEGA 104.72 /* Rotating speed [rad/s] */
#define H 0.005 /* Packing height [m] */
#define R_MEAN 0.0275 /* Mean radius of RPB [m] */
#define A_P 0.001591633448 /* Packing surface area [1/m] */
#define domain_ID 1
/* VOF gradient UDF */
DEFINE_ADJUST(adjust_gradient, domain)
{
Thread *t;
cell_t c;
face_t f;
domain = Get_Domain(domain_ID);
/* Fill UDS with the variable. */
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDSI(c,t,0) = C_VOF(c,t);
C_UDSI(c,t,1) = 1-C_VOF(c,t);
}
end_c_loop (c,t)
}
thread_loop_f (t,domain)
{
if (THREAD_STORAGE(t,SV_UDS_I(0))!=NULL)
begin_f_loop (f,t)
{
F_UDSI(f,t,0) = F_VOF(f,t);
F_UDSI(f,t,1) = 1-F_VOF(f,t);
}
end_f_loop (f,t)
}
}
DEFINE_ON_DEMAND(store_gradient)
{
Domain *domain;
cell_t c;
Thread *t;
domain=Get_Domain(1);
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDMI(c,t,0) = NV_MAG(C_UDSI_G(c,t,0));
C_UDMI(c,t,1) = NV_MAG(C_UDSI_G(c,t,1));
}
end_c_loop (c,t)
}
}
DEFINE_SOURCE(oxygen_absorption_source, c, t, dS, eqn)
{
real source = 0.0;
real ae, kl, yl_saturation, rho_L_O2, Slg, film_thickness, film_velocity,
contact_time; real rho_L = 1011.7; /* Liquid density */
real mu_L = 0.00339; /* Liquid viscosity */
real dp = 0.00015; /* Characteristic dimension of wire mesh*/
real Q_L = 7.7254337e-7 * 1.5289; /* volume flow rate [m^3/s] */
real xc[ND_ND];
C_CENTROID(xc, c, t); /* Get the coordinates of the cell's centroid */
real r_local = sqrt(xc[0] * xc[0] + xc[1] * xc[1]);
real g_centrifugal = r_local * OMEGA;
real vol_frac_O2 = C_YI(c, t, 0); /* Oxygen volume fraction (species index
0) */ real vol_frac_N2 = C_YI(c, t, 1); /* Nitrogen volume fraction (species
index 1) */
real local_pressure = C_P(c, t); /* Local cell pressure */
real O2_PARTIAL_PRESSURE = vol_frac_O2 * local_pressure; /* Partial
pressure of oxygen */
real liquid_gradient = fabs(C_UDMI(c, t, 0)); /* Liquid VOF gradient
magnitude */ real gas_gradient = fabs(C_UDMI(c, t, 1)); /* Gas VOF gradient magnitude */
if (liquid_gradient > 0.0) /* Effective area calculation */
{
ae = gas_gradient / liquid_gradient; /* Effective area based on the
relationship a_e * |grad_liquid| = |grad_gas| */ }
else
{
ae = 0.0; /* Avoid division by zero */
}
C_UDMI(c, t, 2) = ae;
yl_saturation = (MW_O2 * O2_PARTIAL_PRESSURE) / Henry_coeff;
real tau = Q_L / (2 * PI * R_MEAN * H * A_P); /* specific flow rate */
film_thickness = pow((3 * mu_L * tau) / (rho_L * g_centrifugal), 1.0 / 3.0)
film_velocity = (rho_L * g_centrifugal * pow(film_thickness, 2)) / (3 *
mu_L); contact_time = (PI / 2) * (dp / film_velocity);
kl = 2 * sqrt(D_L / (PI * contact_time));
C_UDMI(c, t, 3) = kl;
rho_L_O2 = C_YI(c, t, 0) * rho_L; /* Dissolved O2 concentration in the
liquid phase */ Slg = kl * ae * (yl_saturation - rho_L_O2); /* Source term */
/* Apply source term only when VOF is around 0.5 (at the gas-liquid
interface) */ if (C_VOF(c, t) > 0.499999 && C_VOF(c, t) < 0.500001)
{
source = Slg;
}
return source;
}
There are 3 fluid cell zones, and I used vof model and species model together.
However, this UDF file can be compiled, but when I hook define_demand to Execute on demand..., the following error occurs.
PHP Code:
==============================================================================
Node 0: Process 34348: Received signal SIGSEGV.
==============================================================================
==============================================================================
Node 3: Process 2492: Received signal SIGSEGV.
==============================================================================
==============================================================================
Node 2: Process 10764: Received signal SIGSEGV.
==============================================================================
==============================================================================
Node 1: Process 28536: Received signal SIGSEGV.
==============================================================================
999999: mpt_accept: error: accept failed: No such file or directory
999999: mpt_accept: error: accept failed: No such file or directory
999999: mpt_accept: error: accept failed: No such file or directory
999999: mpt_accept: error: accept failed: No such file or directory
Judging from the error, it seems to be occurring in the adjust part and the demand part, what could be the problem?
I need your help.
Thank you.