UDF for fluid property determination in VOF

Member Posts: 3

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 area-averaged 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?

Tagged:

• 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 non-Newtonian viscosity, then use another UDM as above then use the DEFINE_PROPERTY for each phase. The VOF model will handle the free surface position.

• UKPosts: 12,186Forum Coordinator

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.

1. Where would I hook the UDF or call it? How do I pass on the calculated values to the momentum equation?
2. And how would I ensure that the values I calculate are the ones being used while solving the momentum equation? (what is the link)

• 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!

• UKPosts: 12,186Forum Coordinator

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 step-by-step 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??

1. Hook a UDF (1) for the non-Newtonian viscosity for the primary fluid.
2. Create another UDF (2) in which the area-averaged phase fraction is calculated and is used for the mixture fluid property determination using the modified exponential method.
3. Create a source term UDF (3) for handling the interface curvature smoothening.
4. Where to hook the second UDF (2)?
• Thanks, I was able to figure out a way to implement that based on your suggestion. I've written a UDF for calculating the non-Newtonian 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 non-Newtonian fluid viscosity calculated using APL model

*******************************************************************************/

#include "udf.h"

{

cell_t c;

domain = Get_Domain(2); /*Defines the primary phase which is the non-Newtonian fluid */

/* Declare the coefficients for APL model to calculate non-Newtonian 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, (n-1))),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.

rho = rho2 + ((rho1 - rho2)*C_VOF(c, pt);
mu = mu2 + ((mu1 - mu2)*C_VOF(c, pt);

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 1e-4 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 3e-4 seconds. I'm running with a time step of 1e-7 seconds and when I'm running a regular VOF case without the UDF there are no issues with the convergence.

• rho and mu are calculated based on mass fraction, not volume fraction

• edited April 2021

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*

• UKPosts: 12,186Forum Coordinator

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.

• GermanyPosts: 7,973Forum Coordinator

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?

• edited April 2021

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.

• GermanyPosts: 7,973Forum Coordinator

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.