UDF for fluid property determination in VOF
Hello,
I want to write a UDF to calculate the fluid properties (density & viscosity) through a modified exponential equation as attached in the file and not use the regular linear interpolation at the interface in case of VOF method.
The exponent factor in the modified equation has a viscosity ratio mu1/mu2, where the viscosity of the primary fluid has to be calculated through an asymptotic power law for which I have written a separate UDF using DEFINE_PROPERTY and plan on hooking it in the primary fluid's material properties.
I also need to calculate the areaaveraged volume fraction which I think can be achieved using a C_FACE_LOOP. But my concern is with hooking the modified fluid property determination UDF.
I'm not sure where I would be hooking such a UDF though, Can you suggest how to proceed?
Best Answer

Rob UKPosts: 12,186Forum Coordinator
The averaging would be a function of volume fraction and phase viscosity, you'll just need to be careful with the definitions to link the correct property with the correct phase. That can be stored in a UDM.
If you want to set a mixture viscosity you could use a UDM to determine the nonNewtonian viscosity, then use another UDM as above then use the DEFINE_PROPERTY for each phase. The VOF model will handle the free surface position.
Answers
It'll be a cell loop, and you may want to use a UDM to store the data.
I'm sorry I'm not quite familiar with UDFs yet. Do you want me to store the density and viscosity that I'm calculating using the modified method in a UDM? I'll look on how to accomplish that. But I have a couple of follow up questions though.
In the UDF manual, Look for multiphase looping macros. You will find an example Define_init ... This example loops over all cells in mixture domain. Use it as your starting point ... You will need to use Define_Adjust instead of define_init ... and You will use C_R macro for the density ... not sure about the viscosity.
It needs hard work and probably weeks of debugging. Good Luck!
Break your problem down. Then work out what/when/how to complete each step.
Hey Rob, I have an idea what I want to achieve in a stepbystep manner, but what I'm not sure of is the last part. I know that I can hook the phase viscosity using DEFINE_PROPERTY macro under material properties, how would I go about hooking the mixture property in this case??
Thanks, I was able to figure out a way to implement that based on your suggestion. I've written a UDF for calculating the nonNewtonian viscosity and storing it in a UDM using a DEFINE_ADJUST macro. But I'm getting errors of "uninitialized local variable 't' used" and "uninitialized local variable 'c' used". I understand it is because the thread pointer is unknown but I'm not sure how to access the thread of the particular phase.
The code worked well when defined using DEFINE_PROPERTY macro directly under material properties. I need the thread that would be passed by the solver to UDF in case of a DEFINE_PROPERTY macro under "pt", here in order to do the same calculation. How would I go about that?
/******************************************************************************
UDM for storing the nonNewtonian fluid viscosity calculated using APL model
*******************************************************************************/
#include "udf.h"
DEFINE_ADJUST(non_newtonian_viscosity_udm, domain)
{
Thread *t, *pt;
Thread *mixture_thread = THREAD_SUPER_THREAD(t);
pt = THREAD_SUB_THREAD(mixture_thread, 0);
cell_t c;
domain = Get_Domain(2); /*Defines the primary phase which is the nonNewtonian fluid */
/* Declare the coefficients for APL model to calculate nonNewtonian viscosity */
real mu_0 = 15.9350;
real k = 19.5531;
real n = 0.2891;
real p = 1.00;
real shear_rate;
/* Calculate the viscosity and store in UDM */
shear_rate = C_STRAIN_RATE_MAG(c,pt);
C_UDMI(c,pt,0) = pow((pow(mu_0,p) + pow((k*pow(shear_rate, (n1))),p)),pow(p,1));
}
Hey @Rob ,
I tried the below approach based on your suggestions to see if I could replicate the results of the solver's native VOF adaption, without any modification, using UDF to see if the approach is right. I tried out the simulation for just water and air.
I created property UDFs for both density and viscosity separately, as below, which I hooked onto both the fluids (air and water) and used the VOF of the primary phase.
My residuals have a sawtooth profile to start with and as the flow time progresses the sawtooth profile is enlarging in magnitude (the oscillations are more) and after around 1e4 seconds, I'm starting to get reversed flow on outlet and the number of faces with reversed flow seems to grow with time and the solution sharply diverges within a span of two time steps around 3e4 seconds. I'm running with a time step of 1e7 seconds and when I'm running a regular VOF case without the UDF there are no issues with the convergence.
Could you please suggest?
rho and mu are calculated based on mass fraction, not volume fraction
Hi @YasserSelima ,
I know that rho and mu are based on mass fraction for mixtures. But my purpose here is to change the way in which the properties are being determined at the interface. I see that the properties at the interface depend on the phase fraction as below, which is what I'm trying to replicate using a UDF.
Please correct me if I'm wrong in this aspect.
*SCREENSHOT REMOVED by DrAmine*
If it works without the UDF and fails with the UDF then I'd be looking at what the UDF is doing. I'd also see about hooking the UDF up to calculate the values only, and not apply them in the working VOF case. How do the flow and properties differ from the ones Fluent is using?
I'm definitely sure the issue is with the UDF somewhere, but I'm unable to quite put a finger on what exactly. Below is a picture of the expected variation in properties as compared to Fluent's native method. The UDF I've written right now is the original implementation of FLUENT's VOF, so I'm expecting an arithmetic weighted average as the green line below.
And here is an image of the property I'm obtaining through my UDF.
I'll try maybe storing the property values in a file along with the phase fraction to see if I can get any information on it. But any other suggestions would be great.
Are you trying to modify the density? What is the purpose of changing one of the primitive variables? What do you want to do?
By the way: better to use the same function for both phases so that the phase weighted average is the density you wan to have!
Hi @DrAmine ,
The purpose is to better study the interfacial property in highly viscous fluids. I'm only using water to begin with. The significance and effectiveness of the function in determining interface property is best explained in the first picture involving a comparison. And to answer the question, yes, I'm trying to modify the way density and viscosity at the interface are determined in VOF solver.
And for the second part of your answer, if you could take a look at my below response, I am using the same function for both phases (water and air). I've shared the functions I'm using for density and viscosity. Any suggestions on how to avoid the issues I'm facing?
Hey @Rob ,
I tried out suggestion and created a Adjust UDF to store the values of density and viscosity along with the phase fraction of both the native method and the values calculated by my UDF function in separate files and compared them.
The values of density are exactly the same in both cases for the same value of phase fraction, and the viscosity is almost similar but varies by around +/ 0.0005%, which is too small to make a difference I think. So I'm not sure exactly why this approach isn't working. Please suggest.
Are you plotting node values along the axis? What is your resolution along the line?
I did not need to plot the values. I obtained the density and viscosity values for all cells with phase fraction between 0 & 1. And since there were only 40 or so cells, I directly compared the values.