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

Help with the udf compiling

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 23, 2022, 09:05
Default Help with the udf compiling
  #1
New Member
 
D20125511
Join Date: Oct 2022
Posts: 3
Rep Power: 3
D20125511 is on a distinguished road
Hello there,

I'm trying to perform a 2D axisymmetric simulation of a sessile droplet with a dynamic contact angle and wetting force model as a UDF. I'm quite new with udfs and getting a series of errors when I'm trying to compile my code in ANSYS Fluent v2021 R2 and the code is been written in Visual Studio 17.4.

UDF:
#include "udf.h"
#include "sg.h"

/************************************************** ******
DEFINITION OF PRE - PROCESSING PARAMETERS
************************************************** *****/

#define Psat_ref 12352 //REFERENCE SATURATION PRESSURE FOR THE CALCULTION OF CLAUSIUS-CLAPEYRON EQUATION
#define Tsat_ref 323.15 //REFERENCE SATURATION TEMPERATURE
#define Tref 298.15 //REFERENCE (AMBIENT) TEMEPRATURE - SIMULATING CONDITIONS
#define Dref 2.6e-5 //REFERENCE DIFFUSION FOR THE CALCUTION OF TEMPERATURE-DEPENDENT DIFFUSION COEFFICIENT
#define Mair 0.029 //MOLECULAR WEIGHT FOR AIR (kg/mol)
#define Mw 0.018 //MOLECULAR WEIGHT FOR WATER (kg/mol)
#define R 8.3145 //UNIVERSAL GAS CONSTANT (J/mol*K)
#define Hamb 0.45 //AMBIENT RELATIVE HUMIDITY
#define THC_w 4182 //THERMAL CAPACITY OF WATER (J/kg)
#define THC_v 1006 //THERMAL CAPACITY OF AIR (J/kg)

/************************************************** ******
DEFINITION OF TEMPERATURE DEPENDENT MATERIALS PROPERTIES
************************************************** *****/

DEFINE_PROPERTY(Saturation_temp, sfc, rho_w, ka_w, mu_w, hfg, P_sat, ka_v, mu_v, c, t)
{
/*
t: mixture thread
c: cell variable
Cell Volume
*/

real T_sat;
real vol = C_VOLUME(c, t);
Thread *pt = THREAD_SUB_THREAD(t, 0); //PRIMARY PHASE THREAD
Thread *st = THREAD_SUB_THREAD(t, 1); //SECONDARY PHASE THREAD

real vf_s = C_VOF(c, st); //IDENTITY OF SECONDARY PHASE BY CONSIDERING VOF CELLS
real vf_p = 1 - vf_s; //IDENTITY OF PRIMARY PHASE (1 - SECOUNDARY VOF CELLS)
real P_mixture = C_P(c, t); //DEFINITION OF MIXTURE PRESSURE (WATER VAPOR - AIR)
real P_operating = RP_Get_Real("operating-pressure"); //FOR GETTING THE OPERATING PRESSURE
real rho_p = C_R(c, pt); //PRIMARY PHASE DENSITY
real P_w; //CELL PRESSURE FOR WATER PHASE

if (vf_p == 1) //FOR SECONDARY PHASE ONLY
{
P_w = P_mixture + P_operating;
}
else
{
real m_sec = rho_p * vol * vf_p; //CALCULATION OF SECONDARY PHASE MASS
real m_wv = C_YI(c, pt, 0) * m_sec; //CALCULATION OF MASS OF WATER VAPOR WITHIN A CELL
real m_air = m_sec - m_wv; //CALCULATION OF MASS OF AIR WITHIN A CELL
real N_wv = m_wv / Mw; //CALCULATION OF TOTAL NUMBER OF MOLES OF WATER VAPOR
real N_air = m_air / Mair; //CALCULATION OF TOTAL NUMBER OF MOLES OF AIR
real N_total = N_wv + N_air; //CALCULATION OF TOTAL NUMBER OF MOLES OF COMPOUNDS

P_w = (C_P(c, t) + P_operating) * (N_wv / N_total); //CALCULATION OF PARTIAL VAPOR PRESSURE
}

T_sat = (1723.6425 / (8.05573 - ((double)log10((double)P_w / 133.322))) - 233.08) + 273.15; //FROM ANTOINE EQUATION - DESCRIBING THE RELATION BETWEEN VAPOR PRESSURE & TEMPERATURE FOR PURE SUBSTANCES
C_UDMI(c, t, 0) = T_sat;
if (T_sat < 273 || T_sat > 473)
Message("Temp %f\n", T_sat);


sfc = 0.0943 + 4.0e-6 * T_sat - 3.0e-7 * T_sat * T_sat; //TEMPERATURE-DEPENDENT SURFACE-TENSION (N/m)
rho_w = 753.09 + 1.8804 * T_sat - 0.0036 * T_sat * T_sat; //TEMPERATURE-DEPENDENT DENSITY OF WATER (kg/m3)
ka_w = -0.7513 + 0.0074 * T_sat - 1.0e-5 * T_sat * T_sat; //TEMPERATURE-DEPENDENT THERMAL CONDUCTIVITY OF WATER (W/m*K)
mu_w = 0.1104 - 0.0009 * T_sat + 3.0E-6 * T_sat * T_sat - 3.0E-9 * T_sat * T_sat * T_sat; //TEMPERATURE-DEPENDENT VISCOSITY OF WATER (Pa*s)
hfg = -3.4 6* T_sat * T_sat + 2.7554e6; //TEMPERATURE-DEPENDENT LATENT HEAT OF VAPORIZATION OF WATER (J/kg)
P_sat = -4.0E6 + 40702 * T_sat - 139.54 * T_sat * T_sat + 0.1599 * T_sat * T_sat * T_sat; //TEMPERATURE-DEPENDENT SATURATION PRESSURE (Pa)
ka_v = 8.0e-5 * T_sat - 0.0047; //TEMPERATURE-DEPENDENT THERMAL CONDUCTIVITY OF VAPOR (W/m*K)
mu_v = 3.0e-8 * T_sat - 1.0e-7; //TEMPERATURE-DEPENDENT DENSITY OF VAPOR (kg/m3)

return T_sat;
}

DEFINE ADJUST(dropadj, d)
{
int zone_ID = 12; //IDENTIFICATION OF WALL ZONE TO DEFINE CONTACT ANGLE
cell_t c;
cell_t c0;
Thread *t0, *tw, *ta;
face_t f;
real uCL, theta, Ca, t, x, y, source, vo, vol, fvo, x1[ND_ND];
double dynamiccangle;
int phase_domain_index = 1;
Thread *thread = Lookup_Thread(d, zone_ID);
begin_f_loop(f, thread)
{
c0 = F_C0(f, thread);
t0 = THREAD_T0(thread);
ta = THREAD_SUB_THREAD(t0, 0);
tw = THREAD_SUB_THREAD(t0, phase_domain_index);
uCL = C_U(c0, tw);
C_UDMI(c0, tw, 0) = uCL;
Ca = 0.001003 * uCL / 0.072;
vol = C_VOLUME(c0, t0);
C_CENTROID(x1, c0, to);

if (uCL > 0) //IMPLEMENTATION OF KISTLER'S LAW
{
theta = Ca + 0.326144; //arccos(0.326144) = 1.2385 rad = 70.96
y = pow((theta / (1 + (1.31 * pow(theta, 0.99)))), 0.706) * 5.16;
t = tanh(y);
x = (1 - 2 * t);
dynamiccangle = acos(x) / 22 * 7 * 180;

if (C_VOF(c0, tw) > 0.05 && C_VOF(c0, tw) < 0.95)
{
source = 0.072 * (-0.951 - cos(dynamiccangle)) * x1[0] / vol; //DEFINITION OF WETTING FORCE MODEL
C_UDMI(c0, t0, 3) = source;
}
F_UDMI(f, thread, 2) = source;
C_UDMI(F_C0(f, thread), THREAD_TO(thread), 2) = F_UDMI(f, thread, 2);
}
else if (uCL < 0)
{
theta = Ca + 0.32626;
y = pow((theta / (1 + (1.31 * pow(theta, 0.99)))), 0.706) * 5.16;
t = tanh(y);
x = (1 - 2 * t);
dynamiccangle = acos(x) / 22 * 7 * 180;

if (C_VOF(c0, tw) > 0.005 && C_VOF(c0, tw) < 0.99)
{
source = 0.072 * (-0.927 - cos(dynamiccangle)) * x1[0] / vol;
C_UDMI(c0, t0, 3) = source;
}
F_UDMI(f, thread, 2) = source;
C_UDMI(F_C0(f, thread), THREAD_TO(thread), 2) = F_UDMI(f, thread, 2);
}
}
end_f_loop(f,thread)
}

/************************************************** ******
DEFINITION OF OUTER BOUNDARY PROFILE BASED ON AMBIENT CONDITIONS & CONTACT ANGLE
************************************************** *****/

DEFINE_PROFILE(Contant_Angle_Set_Profile, P_sat_amb, c, t)
{
face_t f; //DEFINITION OF CONTACT ANGLE PROFILE BOUNDARY CONDITION
begin_f_loop(f, t)
{
F_PROFILE(f, t, i) = F_UDMI(f, t, 2);
}
end_f_loop(f,t)

real P_sat_amb; //DEFINITION OF PROFILE BOUNDARY CONDITION FOR SATURATION PRESSURE
P_sat_amb = (double)P_w / Hamb;
return P_sat_amb;
}

/************************************************** ******
DEFINITION OF SOURCE TERM FOR MOMENTUM EQUATION
************************************************** *****/

DEFINE_SOURCE(xmom_source, c, t, ds, eqn)
{
real s = C_UDMI(c, t, 3);
ds[eqn] = 0;
return s;
}


List of Errors after compilation:
thermalpotential.c(30,46): error: too many arguments provided to function-like macro invocation
DEFINE_PROPERTY(Saturation_temp, sfc, rho_w, ka_w, mu_w, hfg, P_sat, ka_v, mu_v, c, t)
^
C:\PROGRA~1\ANSYSI~1\v212\fluent\fluent21.2.0\src\ udf\udf.h(394,9): note: macro 'DEFINE_PROPERTY' defined here
#define DEFINE_PROPERTY(name, c, t) EXTERN_C real name(cell_t c, Thread *t)
^
thermalpotential.c(30,1): warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
DEFINE_PROPERTY(Saturation_temp, sfc, rho_w, ka_w, mu_w, hfg, P_sat, ka_v, mu_v, c, t)
^
thermalpotential.c(30,16): error: expected ';' after top level declarator
DEFINE_PROPERTY(Saturation_temp, sfc, rho_w, ka_w, mu_w, hfg, P_sat, ka_v, mu_v, c, t)
^
;
thermalpotential.c(147,57): error: too many arguments provided to function-like macro invocation
DEFINE_PROFILE(Contant_Angle_Set_Profile, P_sat_amb, c, t)
^
C:\PROGRA~1\ANSYSI~1\v212\fluent\fluent21.2.0\src\ udf\udf.h(392,9): note: macro 'DEFINE_PROFILE' defined here
#define DEFINE_PROFILE(name, t, i) EXTERN_C void name(Thread *t, int i)
^
2 warnings and 3 errors generated.

After Loading the code
Error: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).\n\nThe system cannot find the file specified.
\n\nD:\UDFS\libudf\win64\2ddp_host\libudf.dll
Error Object: #f

Please avail some suggestions so I can perform this task.
D20125511 is offline   Reply With Quote

Old   November 25, 2022, 07:39
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Code:
DEFINE_PROPERTY(Saturation_temp, sfc, rho_w, ka_w, mu_w, hfg, P_sat, ka_v, mu_v, c, t)
remove sfc, rho_w, ka_w, mu_w, hfg, P_sat, ka_v, mu_v from header
definition of DEFINE_PROPERTY is following
Code:
DEFINE_PROPERTY(name,c,t)
read ansys fluent customization manual for more information
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   November 25, 2022, 08:09
Default
  #3
New Member
 
D20125511
Join Date: Oct 2022
Posts: 3
Rep Power: 3
D20125511 is on a distinguished road
Hello Alexander,

I realized that and have defined the properties separately, however, now I'm having different errors:

1) In the definition of the profile for the contact angle set profile, I'm getting errors as the defined variable is not a pointer but an int and it shows in the following line

begin_f_loop(f, t)
{
F_PROFILE(f, t, i) = F_UDMI(f, t, 2);


2)Even if I ran only the defined properties segment alone then I'm getting an error as not able to find vof-air.

Apart from that after I'm getting issues with running the code in a parallel processor even after including #if !Parallel or # !RP_HOST line within the code. Could you please help me out with these issues?
D20125511 is offline   Reply With Quote

Old   November 28, 2022, 18:46
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
simplify your code and debug, late add functionality
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Reply

Tags
dynamic contact angle, fluent, udf

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
UDF compiling error Weiqiang Liu FLUENT 2 November 21, 2018 09:36
UDF Compiling / Parallel mode MV78 Fluent UDF and Scheme Programming 6 May 29, 2018 05:02
ERROR in compiling UDF stefanos Fluent UDF and Scheme Programming 1 April 25, 2012 07:37
udf compiling problem akr FLUENT 3 August 22, 2007 07:14
On Compiling a UDF David Chabot FLUENT 5 May 20, 2005 09:13


All times are GMT -4. The time now is 18:57.