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

dynamic contact angle udf

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 21, 2021, 23:26
Default dynamic contact angle udf
  #1
DQH
New Member
 
Join Date: Jun 2021
Posts: 4
Rep Power: 4
DQH is on a distinguished road
Recentlt,I find a dynamic contact angle udf online,when I using it,some errors are coming,the udf under this:

#include "udf.h"
#include "sg_mphase.h"
#include "sg_vof.h"
#include "sg.h"
#include "mem.h"

#define VISCOSITY 0.001
#define SURF_TENS 0.0728
#define MYTRUE 1
#define MYFALSE 0
#define Hoff(x) acos(1-(2.0*tanh(5.16*(pow((x/(1+(1.31*pow(x,0.99)))),0.706)))))
#define static_Con_Ang 35
#define index_source 3

/* This Code computes the normals of the VOF function*/

DEFINE_ADJUST(store_gradient,domain)
{

Thread *t;
Thread **pt;
cell_t c;
int phase_domain_index=1; /* Secondary Domain */
Domain *pDomain=DOMAIN_SUB_DOMAIN(domain,phase_domain_ind ex);
void calc_source();

Alloc_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_N ULL);
Scalar_Reconstruction(pDomain,SV_VOF,-1,SV_VOF_RG,NULL);
Scalar_Derivatives(pDomain,SV_VOF,-1,SV_VOF_G,SV_VOF_RG,Vof_Deriv_Accumulate);

mp_thread_loop_c (t,domain,pt)
if (FLUID_THREAD_P(t))
{
Thread *ppt=pt[phase_domain_index];
begin_c_loop (c,t)
{
calc_source(c,t);
}
end_c_loop (c,t)
}
Free_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_NU LL);

}

void calc_source(cell_t cell,Thread *thread)
{

real VOF_Val[3],VOF_Mag,source,VOF_Norm[3];
Thread *phaset;
phaset= THREAD_SUB_THREAD(thread,1);

if(C_VOF(cell,phaset)!=0.0 && N_TIME>1)
{
/* The gradients of the VOF function are found in the x,y and z dir. */
if (NULLP(THREAD_STORAGE(phaset,SV_VOF_G)))
{
Message0("N_TIME = %d, ....show-grad:Gradient of VOF is not available \n ", N_TIME);
Error("0");
}
VOF_Val[0]=-C_VOF_G(cell,phaset)[0];
VOF_Val[1]=-C_VOF_G(cell,phaset)[1];
VOF_Val[2]=-C_VOF_G(cell,phaset)[2];

/* The magnitude of the VOF gradients is found so it can be normalized */
VOF_Mag=NV_MAG(VOF_Val);
if(VOF_Mag!=0.0)
{
VOF_Mag=NV_MAG(VOF_Val);
VOF_Norm[0]=VOF_Val[0]/VOF_Mag;
VOF_Norm[1]=VOF_Val[1]/VOF_Mag;
VOF_Norm[2]=VOF_Val[2]/VOF_Mag;
}
else
{
/* This is to avoid the divide by zero function*/
VOF_Norm[0]=0.0;
VOF_Norm[1]=0.0;
VOF_Norm[2]=0.0;
}
C_UDMI(cell,thread,0)=VOF_Norm[0];
C_UDMI(cell,thread,1)=VOF_Norm[1];
C_UDMI(cell,thread,2)=VOF_Norm[2];
}
source=0.0;
C_UDMI(cell,thread,index_source) = source;
}
DEFINE_SOURCE(VOF_Norms,cell,thread,dS,eqn)
{
real source;
source = C_UDMI(cell,thread,index_source);
return source;
}

/* This Define_profile code is designed to provide a dynamic contact angle for the VOF function*/
DEFINE_PROFILE(con_ang,t,pos)
{
/* First the various pointer variables are created*/
face_t f;
cell_t c;
real feta_d,vel_Val[3],cont_Line_Vel,VOF_Normal[3],cap_Num,static_Con_Rad,x_Bottom,
x_Top,x_Bisect,hoff_Old,hoff_Cur,hoff_New,finish_C ond,inv_Hoff=0.0;
int notConverged,itNum;
Thread *t0,*pt;

/* This code is designed to find the zero for the inverted hoffman function by finding the zero */
/* of the function at which the hoffman function results in the static contact angle */
/* First the variables are assigned*/
notConverged=MYTRUE;
x_Bottom=0.001;
x_Top=2.0;
itNum=0;
static_Con_Rad=((static_Con_Ang*M_PI)/180);
/* A while loop performs the bisection method, a simple but very stable zero finder */
while(notConverged)
{
/* The variables used in the bisection method are assigned and the hoffman */
/* functions are evaluated */
itNum++;
hoff_Old=(Hoff(x_Bottom)- static_Con_Rad);
hoff_Cur=(Hoff(x_Top)- static_Con_Rad);
x_Bisect=(x_Bottom+x_Top)/2.0;
hoff_New=(Hoff(x_Bisect)- static_Con_Rad);
finish_Cond=fabs(1-(x_Bisect/x_Top));

/* The loop ends when the relative error is less than 1e-8 and the inverse */
/* hoffman value is stored for use later */
if(finish_Cond<0.00000001||itNum>10000000)
{
inv_Hoff=x_Bisect;
notConverged=MYFALSE;
}
/* Conditions for the bisection method */
if((hoff_Old*hoff_New)<0.0)
{
x_Top=x_Bisect;
}
if((hoff_Cur*hoff_New)<=0.0)
{
x_Bottom=x_Bisect;
}
}
/* Now the main loop goes through all the faces in the boundary */
begin_f_loop(f,t)
{
/* The cell and phase threads are isolated */
c=F_C0(f,t);
t0=THREAD_T0(t);
pt= THREAD_SUB_THREAD(t0,1);
/* The main formulation is only applied if the VOF is >0 */
if(C_VOF(c,pt)!=0.0)
{
/* The velocities are recorded in each direction */
vel_Val[0]=C_U(c,t0);
vel_Val[1]=C_V(c,t0);
vel_Val[2]=C_W(c,t0);

/* The VOF normals are brought in */
VOF_Normal[0]=C_UDMI(c,t0,0);
VOF_Normal[1]=C_UDMI(c,t0,1);
VOF_Normal[2]=C_UDMI(c,t0,2);

/* The contact line vel. is calc from the dot product of VOF and Vel */
cont_Line_Vel=NV_DOT(vel_Val,VOF_Normal);

/* The capillary number is found based on cont line vel. */
cap_Num=fabs((VISCOSITY*cont_Line_Vel)/SURF_TENS);

/* The dynamic contact angle is defined then stored in the profile */
if(cap_Num+inv_Hoff<0.0)
{
cap_Num=inv_Hoff;
}
feta_d=((Hoff(cap_Num+inv_Hoff))*180)/M_PI;
F_PROFILE(f,t,pos)=feta_d;
}
else
{
F_PROFILE(f,t,pos)=static_Con_Ang;
}
}
end_f_loop(f,t)
}


The error is:
================================================== ============================

Node 5: Process 1404: Received signal SIGSEGV.

================================================== ============================

================================================== ============================

Node 4: Process 9168: Received signal SIGSEGV.

================================================== ============================
999999: mpt_accept: error: accept failed: No such file or directory
The fl process could not be started.

so,what is the problem?
DQH is offline   Reply With Quote

Old   July 22, 2021, 00:18
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Maybe you did not reserve enough UDM locations.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   July 22, 2021, 00:22
Default
  #3
DQH
New Member
 
Join Date: Jun 2021
Posts: 4
Rep Power: 4
DQH is on a distinguished road
Thank you for your reply,do you know how can I solve this question?
DQH is offline   Reply With Quote

Old   July 22, 2021, 00:33
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Reserve UDM locations.

There is a manual, look for UDM. I don't know the menu options by heart, I would also need to look it up.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   July 22, 2021, 00:34
Default
  #5
DQH
New Member
 
Join Date: Jun 2021
Posts: 4
Rep Power: 4
DQH is on a distinguished road
Thanks again,I will try
DQH is offline   Reply With Quote

Old   July 22, 2021, 00:41
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
It looks like you need 3 locations.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   July 22, 2021, 00:52
Default
  #7
DQH
New Member
 
Join Date: Jun 2021
Posts: 4
Rep Power: 4
DQH is on a distinguished road
Ah,I am a rookie,so I don't know how to set up it,and where the manual is,thank you very much indeed
DQH is offline   Reply With Quote

Old   May 8, 2022, 17:57
Default
  #8
New Member
 
Manthan Patel
Join Date: May 2022
Posts: 2
Rep Power: 0
me20m025 is on a distinguished road
Hey I'm working on UDF of dynamic contact angle as well

I'm using the Axisymmetric model

I'm getting an error after loading the udf while assigning the DEFINE_Profile udf

I'm attaching the code below

#include "udf.h"
#include "mem.h"

/* Dynamic Contact UDF */


/********************/
/* Model Parameters */
/********************/




/* Enumerate UDM numbers */
enum{
VOF_G_X,
VOF_G_Y,
VOF_G_Z,
CONTACT_ANGLE,
CONTACT_N_REQ_UDM
};


#define VISCOSITY 0.001153
#define SURF_TENS 0.0727
#define static_Con_Ang 93.0
#define dyn_adv_Ang 108.0
#define dyn_rec_Ang 78.0


#define C_VOF_G_X(C,T)C_UDMI(C,T,VOF_G_X)
#define C_VOF_G_Y(C,T)C_UDMI(C,T,VOF_G_Y)
#define C_VOF_G_Z(C,T)C_UDMI(C,T,VOF_G_Z)

#define C_CONTACT_ANGLE(C,T)C_UDMI(C,T,CONTACT_ANGLE)




DEFINE_ADJUST(dynamic_contact, domain)
{
Thread *ct, *pct, *t0;
Thread *ft;
cell_t c, c0;
face_t f;
double theta_n;
real vel_re[ND_ND],Unit_tan[ND_ND], vof_n[ND_ND],VOF_Norm[ND_ND], vec_nw[ND_ND], vec_tw[ND_ND];
real A[ND_ND], Amag, VOF_Mag,Tan_Mag, veltan[ND_ND];
double f_Hoff_inverse, x_hoff, Ca;

int phase_domain_index = 1;

Domain *pDomain = DOMAIN_SUB_DOMAIN(domain, phase_domain_index);



if (first_iteration)
{


if (N_UDM < CONTACT_N_REQ_UDM)
{
Message0("\n WARNING: Require at least %d UDMs to be set up for dynamic contact angle model.\n", CONTACT_N_REQ_UDM);
return;
}

/*Calculate VOF gradient*/

Alloc_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_N ULL); /* Primary storage of variables being calculated */
Scalar_Reconstruction(pDomain, SV_VOF,-1,SV_VOF_RG,NULL);
Scalar_Derivatives(pDomain,SV_VOF,-1,SV_VOF_G,SV_VOF_RG,Vof_Deriv_Accumulate);

/* Store VOF gradient in user memory */

thread_loop_c(ct, domain)
{


if (FLUID_THREAD_P(ct))
{

pct = THREAD_SUB_THREAD(ct, phase_domain_index); /* Use this instead of pt [] */
begin_c_loop(c, ct)
{
ND_V(C_VOF_G_X(c, ct), C_VOF_G_Y(c, ct),C_VOF_G_Z(c, ct ),=,C_VOF_G(c, pct)); /* Set 3 components to a vector */
}
end_c_loop(c, ct)
}

/* Free memory used for VOF gradient */
Free_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_NU LL);
}





/* Calculate wall contact angle and save to user memory */
thread_loop_f(ft, domain)
{
/* to loop over all face threads in a given domain.*/
if(THREAD_TYPE(ft) == THREAD_F_WALL) /* Mixture Thread and Wall */
{
t0 = THREAD_T0(ft);


if (FLUID_THREAD_P(t0)) /* Fluid Zone */
{

begin_f_loop(f, ft)
{
c0 = F_C0(f, ft);

/* Get flow velocity */
NV_D(vel_re ,= ,C_U(c0, t0), C_V(c0, t0), C_W(c0, t0));

F_AREA(A, f, ft) ; /* Area vector */

Amag = NV_MAG(A);
NV_S(A,/=,Amag);

/*A now holds outward face normal*/

NV_D(vof_n, =, C_VOF_G_X(c0, t0), C_VOF_G_Y(c0, t0 ), C_VOF_G_Z(c0, t0));

VOF_Mag=NV_MAG(vof_n);

if(VOF_Mag!=0.0)
{
VOF_Mag=NV_MAG(vof_n);
NV_VS(VOF_Norm, =, vof_n, *, (1/VOF_Mag));
}
else
{
NV_VS(VOF_Norm, =, vof_n, *, (0.0));
}

/* vof along wall*/

NV_VS(vec_nw, =, A, *, NV_DOT( VOF_Norm, A));
NV_VV(vec_tw, =, VOF_Norm, -, vec_nw);


Tan_Mag = NV_MAG(vec_tw);

if(Tan_Mag!=0.0)
{
Tan_Mag = NV_MAG(vec_tw);
NV_VS(Unit_tan, =, vec_tw, *, (1/Tan_Mag));
NV_VS(veltan, =, Unit_tan, *, NV_DOT( vel_re, Unit_tan));
}
else
{
NV_D(veltan, =, C_VOF_G_X(c0, t0), C_VOF_G_Y(c0, t0 ), C_VOF_G_Z(c0, t0));
}







/*Contact line direction*/



/*Receding : Calculate dynamic contact angle*/
if (NV_DOT(veltan, vof_n) > 0.0)
{

Ca = (VISCOSITY*(NV_MAG(veltan)))/SURF_TENS;
/*DRCA model*/
theta_n = ((pow((pow(((dyn_rec_Ang)*M_PI/180.0), 3) - 72.0*Ca),(1/3)))*180)/M_PI;

C_CONTACT_ANGLE(c0, t0) = theta_n ; /* deg */
}
else
{

/* Advancing : Calculate dynamic contact angle*/
Ca = (VISCOSITY*(NV_MAG(veltan)))/SURF_TENS;
/* Kistler’s model*/
f_Hoff_inverse = pow(((dyn_adv_Ang)*M_PI/180.0), 3)/72.0;
x_hoff = Ca + f_Hoff_inverse;
theta_n = ((acos(1.0 - (2.0*tanh(5.16*pow((x_hoff/(1.0 + 1.31*pow(x_hoff, 0.99))),0.706)))))*180)/M_PI;
C_CONTACT_ANGLE(c0, t0) = theta_n; /* [ degs ] */

}

}
end_f_loop (f, ft)
}
}
}
}

printf("Executed Adjust\n\n\n\n\n");

}





DEFINE_PROFILE(contact_angle, t, i)
{
face_t f;
cell_t c0;
Thread *t0;
begin_f_loop(f, t)
{
c0 = F_C0(f ,t);
t0 = F_C0_THREAD(f , t );
F_PROFILE(f ,t ,i) = C_CONTACT_ANGLE(c0, t0); /* Angle within the liquid in degrees */
}
end_f_loop(f, t)
}

DEFINE_EXECUTE_AFTER_CASE(set_name, libname )
{
Message0 (" Setting UDM names . . . ");
Set_User_Memory_Name(VOF_G_X,"VOF Gradient−x");
Set_User_Memory_Name(VOF_G_Y,"VOF Gradient−y");
Set_User_Memory_Name(VOF_G_Z,"VOF Gradient−z ");

Set_User_Memory_Name(CONTACT_ANGLE," Contact Angle [deg]");


Message0 ("Done.\n") ;
}








The error is



Node 0: Process 23624: Received signal SIGSEGV.

================================================== ============================

999999: mpt_accept: error: accept failed: No error

999999: mpt_accept: error: accept failed: No error

999999: mpt_accept: error: accept failed: No error

999999: mpt_accept: error: accept failed: No error

999999: mpt_accept: error: accept failed: No error

999999: mpt_accept: error: accept failed: No error
.
.
.
.
.
.
.

The fl process could not be started.





Also is it normal to get some warning during building the udf

Last edited by me20m025; May 9, 2022 at 04:58.
me20m025 is offline   Reply With Quote

Old   May 9, 2022, 01:23
Default
  #9
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
ft is not defined

also you have following warning
Code:
warning C4819: The file contains a character that cannot be represented in the current code page (949).
easy to avoid using English letters only
__________________
best regards


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

Old   May 9, 2022, 04:58
Smile
  #10
New Member
 
Manthan Patel
Join Date: May 2022
Posts: 2
Rep Power: 0
me20m025 is on a distinguished road
Hey, AlexanderZ thanks for the reply.

I did define the 'ft' thread in my code.
I've updated my code in the reply

It somehow got removed while posting it here.

But I'm still getting the same error

can you please help me out?
me20m025 is offline   Reply With Quote

Old   May 10, 2022, 02:51
Default
  #11
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
your code is too complex to debug it, I recommend to simplify, split for a few parts and debug separately

first_iteration is not defined and never happens actually
so VOF gradients are not allocated
Code:
Alloc_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_NULL); /* Primary storage of variables being calculated */
Scalar_Reconstruction(pDomain, SV_VOF,-1,SV_VOF_RG,NULL);
Scalar_Derivatives(pDomain,SV_VOF,-1,SV_VOF_G,SV_VOF_RG,Vof_Deriv_Accumulate);
on line 91 you are removing gradients from memory
Code:
Free_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_NULL);
why? as you are using them below on surface loops? and on other iterations?

make a clear logic of your algorithm
__________________
best regards


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

Reply


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
Dynamic contact angle hsieh OpenFOAM Running, Solving & CFD 24 June 13, 2021 23:22
dynamic contact angle implementation q doubtsincfd OpenFOAM Programming & Development 7 November 12, 2015 08:07
inaccurate contact angle capturing in high shear/viscousity flow chery1986 OpenFOAM Running, Solving & CFD 0 October 23, 2015 00:14
Dynamic contact angle raj kumar saini Fluent UDF and Scheme Programming 0 October 13, 2014 02:18
dynamic contact angle / contact line velocity ThomasN CFX 6 September 23, 2014 06:07


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