CFD Online Logo CFD Online URL
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

UDF for Defining different Density calculation formula for different Cell-zones.

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

LinkBack Thread Tools Search this Thread Display Modes
Old   June 2, 2022, 12:20
Post UDF for Defining different Density calculation formula for different Cell-zones.
New Member
Join Date: Dec 2021
Posts: 1
Rep Power: 0
shubham is on a distinguished road
Hello all,
I have a problem in defining Density. I am simulating multiphase simulation where density is a function of Temperature and composition. For that I want to define two different density calculation formula in two different cell zones.

For this I am using the following UDF:

#include "udf.h"
#include "math.h"
#include "materials.h"
#include "threads.h"

/* I want to define two different DENSITY variation in two different cell zones. */

real rho;
int i;

real T;
real xch4;
Material *sp;
Domain *mixture_domain;
mixture_domain = Get_Domain(3); // domain id of liquid phase = 3
Thread *tc1,*tc2;
tc1 = Lookup_Thread(mixture_domain,14); //14 is Domain id of bottom zone
tc2 = Lookup_Thread(mixture_domain,15); //15 Domain id of middle zone

if (t == tc1) //when thread pointer at bottom zone xch4 remain constant

T = C_T(c,t);
xch4 = 0.89;
rho = (-0.8292 - (0.5407*xch4))*(T - 100) - (250.15*xch4) + 690.73;

//return rho;


else if (t == tc2) //when thread pointer at middle zone Temperature remain constant

T = 111.67;
xch4 = C_YI(c,t,1);
rho = (-0.8292 - (0.5407*xch4))*(T - 100) - (250.15*xch4) + 690.73;
//return rho;


return rho;


The UDF compiles without any problems. However, as soon as it starts,
the simulation begins to diverge. Without UDF, the simulation runs without a hitch.
I can't seem to figure out what the issue is.
Does anyone have an idea what this can be due to?

Many thanks in advance.
Attached Files
File Type: c rho_mix_2 - Copy.c (1.1 KB, 1 views)
shubham is offline   Reply With Quote

Old   June 10, 2022, 00:48
Senior Member
Join Date: Apr 2013
Posts: 2,259
Rep Power: 33
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
i think you don't need these lines:
most likely concentration macro leads to error
xch4 = C_YI(c,t,1);
it is possible, that at 0 moment concentration is not defined yet, but you are trying to use it for calculations, that will lead to problems if that is the case.
You may try to define some specific value for initialization (when time = 0) explicitly to bypass possible issue.

make sure you are using correct index for material either, which you put as 1
best regards

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


mixture density, multiphase mixture model, 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 in case with DPM modle POSTHU Fluent UDF and Scheme Programming 0 March 3, 2021 07:21
[snappyHexMesh] Creating multiple multiple cell zones with snappyHexMesh - a newbie in deep water! divergence OpenFOAM Meshing & Mesh Conversion 0 January 23, 2019 04:17
UDF for current density in PEM fuel cell sajjad haider FLUENT 2 February 22, 2012 18:16
Cells with t below lower limit Purushothama Siemens 2 May 31, 2010 21:58
REAL GAS UDF brian FLUENT 6 September 11, 2006 08:23

All times are GMT -4. The time now is 17:32.