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

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

June 2, 2022, 12:20
UDF for Defining different Density calculation formula for different Cell-zones.
#1
New Member

shubham
Join Date: Dec 2021
Posts: 1
Rep Power: 0
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"

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

DEFINE_PROPERTY(cell_density,c,t)
{
real rho;
int i;

real T;
real xch4;
Material *sp;
Domain *mixture_domain;
mixture_domain = Get_Domain(3); // domain id of liquid phase = 3
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?

Attached Files
 rho_mix_2 - Copy.c (1.1 KB, 1 views)

 June 10, 2022, 00:48 #2 Senior Member   Alexander Join Date: Apr 2013 Posts: 2,259 Rep Power: 33 i think you don't need these lines: Code: `mixture_species_loop(THREAD_MATERIAL(t),sp,i)` most likely concentration macro leads to error Code: `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

 Tags mixture density, multiphase mixture model, udf