
[Sponsors] 
Variable Surface Tension Modelling UDF (Modifications to CSF) 

LinkBack  Thread Tools  Search this Thread  Display Modes 
March 8, 2021, 15:18 
Variable Surface Tension Modelling UDF (Modifications to CSF)

#1 
Member
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6 
Hey,
I'm new to UDFs in FLUENT and am writing a UDF involving a modification in the interface curvature calculation part of the CSF model to smoothen it. So far, I've understood that C_VOF_G(c,t) can calculate gradient of volume fraction and NV_MAG(C_VOF_G(c,t)) can calculate magnitude of volume fraction. For the divergence part, will I have to save the unit normal in a UDS (C_UDSI) using a cell loop, and assign C_USDI_G to the interface curvature "k" to directly access the gradient of the scalar? I would also like to modify the property determination method for the VOF model as indicated in the picture. How would I be implementing this change on FLUENT? Also where would I be hooking both these UDFs exactly? 

March 23, 2021, 05:28 

#2  
Member
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6 
I've written a UDF for the surface tension force which I'm sharing below. I'm getting a bunch of errors that I've looked around for but am unable to resolve. Any help would be appreciated.
Code:
/*********************************************************************** UDF for defining surface tension source term and interface smoothening ************************************************************************/ #include "udf.h" DEFINE_SOURCE(surface_tension_force,c,t,dS,eqn) { /* Note that t is the mixture thread passed by the solver in this case */ Domain *d; real source; real k; /* interface curvature */ real ncap; /* unit normal */ real n; /* a function of the phase fraction */ real sigma = 0.072; /* surface tension coefficient */ real alphacell = C_UDMI(c,t,1); /* calculates the area averaged volume fraction of individual cell */ real rho1 = 1.225; /* Density of air */ real rho2 = 1; /* Density of nonNewtonian fluid */ C_UDSI(c,t,0) = alphacell; /* Fill UDS with the alphacell values to get gradient value */ n = C_UDSI_G(c,t,0); /* Get value of n as the gradient of alphacell (phase fraction) */ ncap = n/NV_MAG(n); /* calculate unit vector */ C_UDSI(c,t,1) = ncap; /* Fill another UDS with the variable ncap */ k = C_UDSI_G(c,t,1); /* Get value of k as the gradient of ncap */ source = sigma*k*C_R(c,t)*n/(0.5*(rho1+rho2)); /* Calculate the surface tension force */ dS[eqn] = 0; return source; } Quote:


March 23, 2021, 11:40 

#3 
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26 
Ignoring the errors: your concept can not work.
You fill UDS, and want to get the gradient at the same time. How should that work after the first cell? How can Fluent calculate a gradient if only one cell has a value? I think you have to do this in three steps : 1. Fill UDS0 completely. 2.calculate UDS 1 completely as gradient. 3.calculate the source completely as gradient of UDS1. Even then, I'm not sure if this is the right approach, but I don't have enough time to think a better one.
__________________
"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". 

March 23, 2021, 13:35 

#4  
Member
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6 
Quote:
However I'm still receiving the same errors and I'm not sure what they mean. I thought maybe it meant I can't store my UDS and UDS_G values in 'real' variables and also tried storing them in UDMs and not real variables like "n, ncap and k" as I've used below, but my errors remain the same irrespective of the approach. Below are my code and errors. All errors pertain to the lines involving calculation of n, ncap and k. Please suggest. Code:
/*********************************************************************** UDF for defining surface tension source term and interface smoothening ************************************************************************/ #include "udf.h" DEFINE_SOURCE(surface_tension_force,c,t,dS,eqn) { /* Note that t is the mixture thread passed by the solver in this case */ Domain *d = Get_Domain(1); /* defines the mixture domain */ real source; real k; /* interface curvature */ real ncap; /* unit normal */ real n; /* a function of the phase fraction */ real sigma = 0.072; /* surface tension coefficient */ real alphacell = C_UDMI(c,t,1); /* calculates the area averaged volume fraction of individual cell */ real rho1 = 1.225; /* Density of air */ real rho2 = 1; /* Density of nonNewtonian fluid */ /* Fill UDS with the alphacell values to get gradient value */ thread_loop_c(t,d) { begin_c_loop(c,t) { C_UDSI(c,t,0) = alphacell; } end_c_loop(c,t) } /* Get value of n as the gradient of alphacell (phase fraction) */ thread_loop_c(t,d) { begin_c_loop(c,t) { n = C_UDSI_G(c,t,0); } end_c_loop(c,t) } ncap = n/NV_MAG(n); /* calculate unit vector */ /* Fill another UDS with the variable ncap */ thread_loop_c(t,d) { begin_c_loop(c,t) { C_UDSI(c,t,1) = ncap; } end_c_loop(c,t) } thread_loop_c(t,d) { begin_c_loop(c,t) { k = C_UDSI_G(c,t,1); /* Get value of k as the gradient of ncap */ } end_c_loop(c,t) } source = sigma*k*C_R(c,t)*n/(0.5*(rho1+rho2)); /* Calculate the surface tension force */ dS[eqn] = 0; return source; } Quote:


March 23, 2021, 14:15 

#5 
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26 
Your problem now is that gradient is a vector. You can not store that in a scalar.
__________________
"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". 

March 23, 2021, 14:23 

#6  
Member
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6 
Quote:
The below are the concepts I'm struggling with right now. 1. ncap is a vector that has the value ( n/NV_MAG(n) ), where n is also a vector. How would I perform the operation of dividing a vector by a scalar? As the command as it is gives me an error "error C2296: '/': illegal, left operand has type 'real [2]'" Is there a NV macro that can handle this? 2. I need to calculate the divergence of the vector ncap (or simply said  the Laplacian) and store it in k. How would I go about this? Last edited by Venky_94; March 23, 2021 at 23:24. 

March 25, 2021, 11:08 

#7  
Member
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6 
Quote:
I was able to achieve the first part using the command NV_VS(ncap, =, n, /, NV_MAG(n)). So now I have the unit vector ncap. All I need to do it figure out how to calculate the term ∇⋅ncap (divergence of the unit vector). Any suggestions would be great. 

May 28, 2024, 10:28 

#8 
New Member
Guilherme Luz
Join Date: Mar 2021
Posts: 2
Rep Power: 0 
@Venky94 Thanks a lot for sharing your code structure. Building up on it, I wrote the following UDF as an implementation of the CSF approach. I am using the VOF model for modelling heat pipe dynamics and was missing exactly the calculation of the interface curvature.
So I took the unit normal vector, took the gradient of each of its components and added up the required terms to construct the divergence. You probably don't need this anymore, but here it is for posterity: Code:
/* This source file contains UDF implementations for momentum sources to account for interface forces, porous resistance and capillary effects on the porous structure. The theory behind the model is given by carrillo2020 The specific equations used to model the phenomena are found in the respective header file. */ //  HEADER FILES  // // STANDARD HEADER FILES #include "udf.h" #include "sg_mphase.h" #include "mem.h" #include "math.h" DEFINE_SOURCE(free_flow_source_x,cell,mix_th,dS,eqn) { Thread *pri_th, *sec_th; pri_th = THREAD_SUB_THREAD(mix_th, 0); // Pointer to vapor thread sec_th = THREAD_SUB_THREAD(mix_th, 1); // Pointer to liquid thread Domain *dmn = Get_Domain(1); // Pointer to mixture domain. Required for cell loop. real source[ND_ND] = 0; real k; /* Fluidfluid interface curvature */ real nVector[ND_ND]; /* Fluidfluid interface unit normal vector */ real sigma = 0.072; /* surface tension coefficient */ NV_VS(nVector,=,C_VOF_G(cell,sec_th),/,NV_MAG(C_VOF_G(cell,sec_th))); thread_loop_c(mix_th,dmn) { begin_c_loop(cell,mix_th) { for (int i = 0; i < ND_ND; i++) { C_UDSI(cell,mix_th,i) = nVector[i]; } } end_c_loop(cell,mix_th) } thread_loop_c(mix_th,dmn) { begin_c_loop(cell,mix_th) { for (int i = 0; i < ND_ND; i++) { k += C_UDSI_G(cell,mix_th,i)[i]; /* Get value of k as the gradient of ncap */ } } end_c_loop(cell,mix_th) } source = sigma*k*C_VOF_G(cell,sec_th); //[N/m^3] Force vector created by interface pressure jump dS[eqn] = 0; return source[0]; // Return xcomponent of force vector } 

Tags 
interface curvature, surface tension model, udf, vof multiphase, volume fraction 
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Surface tension UDF  Diconico  FLUENT  3  March 12, 2021 12:38 
OpenFOAM error  Vinay Kumar V  Main CFD Forum  0  February 20, 2020 09:17 
How to add Surface Tension in cavitatingFoam solver  jamestangx  OpenFOAM Programming & Development  1  April 6, 2016 16:39 
Surface Tension Force Model  Miguel  CFX  7  October 2, 2006 05:30 
UDF for surface tension gradient  kiran  FLUENT  2  July 15, 2003 12:00 