Simulate multiple mixtures by thread id


In multiple species problems, there can only be ONE mixture. This is a problem in multiple channel flows with different fluid types, especially in cases where one of the fluids is a multiple species mixture and the other is a pure fluid.

/* UDF that simulates multiple mixtures.

by William Wangard, Ph.D.
Fluent, Inc.


To use,

* Set number of liquid zones which is hardwired into the UDF (The other zones are gaseous)
* Hardwire in thread IDS of liquid zones into the UDF....
* Compile UDF
* hook "density" UDF
* hook "init" UDF
* For robustness, FIX mass fraction of liquid to 1 in liquid cell zones. FIX mass fraction of liquid to ZERO in gas cell zones.

Currently, the "chemical formula" of the liquid must be called "water." You can change this to fit your needs. The density of the liquid is defined as 1000.0 kg/m3

*/

#include "udf.h"
/* zone_type is an int array that stores the thread-type for each thread-id.
* */

void assign_zone_types(void);
void my_init(void);

int zone_type[200] = {-1};
int i_water = -1;
boolean initialized = FALSE;

Material* mat = NULL;

/* IDS of LIQUID zone... only 1 zone */
#define NLZONES 1
int liquid_zone_ids[NLZONES] = {7};

enum {
liquid_zone = 0,
gas_zone = 1
};


void assign_zone_types(void)
{
int i;
Domain* d = Get_Domain(1);
Thread* t;
thread_loop_c(t,d)
{
zone_type[t->id] = gas_zone;
}

/* Assume CELL ZONE ID = 10 is liquid zone */
for(i=0; i<NLZONES; i++)
zone_type[liquid_zone_ids[i]] = liquid_zone;
}


DEFINE_INIT(init,d)
{
my_init();
}


void my_init(void)
{

int spe;


/* Return 0 if no species equations */
if (!(rp_spe && rf_energy))
{
Error("Turn on species transport!n");
return;
}

/* Get mixture */
mat = mixture_material(Get_Domain(1));

/* Find water in mixture */
spe_loop(spe,n_spe)
{
if (STREQ(MIXTURE_SPECIE_NAME(mat,spe),"water"))
{
i_water = spe;
}
}

assign_zone_types();

initialized = TRUE;

if (i_water < 0)
Message("No liquid species in mixturen");
else
Message("Liquid species is %in", i_water);

}


DEFINE_PROPERTY(density, c, t)
{

int i;
real rho, mwi;
int zt = zone_type[t->id];

/* Default coolant density */
real coolant_density = 1000.0;


if (!initialized || NULLP(mat)) my_init();

if (zt == liquid_zone)
{
rho = coolant_density;
}
else if (zt == gas_zone)
{
mwi = 0.0;
spe_loop(i, n_spe)
{
mwi += C_YI(c,t,i) / (MATERIAL_PROP(MIXTURE_SPECIE(mat,i),PROP_mwi) + EPSILON) ;
}
if (i_water >= 0)
mwi -= C_YI(c,t,i_water) / (MATERIAL_PROP(MIXTURE_SPECIE(mat,i_water),PROP_mwi) + EPSILON);

rho = ABS_P(C_P(c,t),op_pres) / (UNIVERSAL_GAS_CONSTANT * C_T(c,t) * mwi);
}
else
{
Error("Incorrect cell thread zone assignmentn");
return 1.0;
}

return rho;
}





Show Form
No comments yet. Be the first to add a comment!