CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

UDF loop problems

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 25, 2023, 12:44
Default UDF loop problems
  #1
New Member
 
tsuman
Join Date: Dec 2023
Posts: 3
Rep Power: 3
tsuman is on a distinguished road
Hello,

I am working on coal combustion simulation, so I use the UDF below to calculate the p_comb_totals[c] / particle_counts[c], but it shows that there is no particle in injections, Please tell what it's wrong with my UDF

Thanks for your help


__________________________________________________ __________________________________________________ ________________________________
DEFINE_ON_DEMAND(pcomb_index)
{
Domain *d;
Thread *t;
cell_t c;
Particle *p;
d = Get_Domain(1);

Injection *I;
Injection *Ilist;
int *particle_counts;
real *p_comb_totals;
int nCells = 0;

Ilist = Get_dpm_injections();


int nInjections = 0, nParticles = 0;
loop(I, Ilist)
{
nInjections++;
nParticles = 0;

loop(p, I->p)
{
nParticles++;
}
Message("Injection %d has %d particles.\n", nInjections, nParticles);
}
Message("Total number of injections: %d\n", nInjections);


real Mw_O2 = 32e-3; // kg/mol
real Mw_CO2 = 44e-3; // kg/mol
real Mw_H2O = 18e-3; // kg/mol

Message("Determining the number of cells...\n");


thread_loop_c(t, d)
{
begin_c_loop(c, t)
{
nCells++;
}
end_c_loop(c, t)
}

Message("Total number of cells: %d\n", nCells);


particle_counts = (int *)calloc(nCells, sizeof(int));
p_comb_totals = (real *)calloc(nCells, sizeof(real));


Message("Processing particles...\n");

loop(I, Ilist)
{

loop(p, I->p)
{

c = P_CELL(p);
t = P_CELL_THREAD(p);


real rho_gas = C_R(c, t);
real T_gas = C_T(c, t);
real Y_O2 = C_YI(c, t, 1);
real Y_CO2 = C_YI(c, t, 5);
real Y_H2O = C_YI(c, t, 0);



real T_p = P_T(p);
real d_p = P_DIAM(p);
real A_p = M_PI * d_p * d_p;

real D_O2 = C1 * pow((T_p + T_gas) / 2, 0.75) / d_p;
real D_CO2 = C1 * pow((T_p + T_gas) / 2, 0.75) / d_p;
real D_H2O = C1 * pow((T_p + T_gas) / 2, 0.75) / d_p;


real Rk_O2 = C2_O2 * exp(-E_O2 / (R * T_p));
real Rk_CO2 = C2_CO2 * exp(-E_CO2 / (R * T_p));
real Rk_H2O = C2_H2O * exp(-E_H2O / (R * T_p));


real k_O2 = -A_p * rho_gas * R * T_gas * Y_O2 * D_O2 * Rk_O2 / (Mw_O2 * (D_O2 + Rk_O2));
real k_CO2 = -A_p * rho_gas * R * T_gas * Y_CO2 * D_CO2 * Rk_CO2 / (Mw_CO2 * (D_CO2 + Rk_CO2));
real k_H2O = -A_p * rho_gas * R * T_gas * Y_H2O * D_H2O * Rk_H2O / (Mw_H2O * (D_H2O + Rk_H2O));

real p_comb = k_O2 / (k_O2 + k_CO2 + k_H2O);

p_comb_totals[c] += p_comb;
particle_counts[c]++;
}
}


thread_loop_c(t, d)
{
begin_c_loop(c, t)
{
if (particle_counts[c] > 0)
{
C_UDMI(c, t, 0) = p_comb_totals[c] / particle_counts[c];
}
else
{
C_UDMI(c, t, 0) = 0.0;
}
}
end_c_loop(c, t)
}



free(particle_counts);
free(p_comb_totals);

Message("DEFINE_ON_DEMAND Success\n");
}

Last edited by tsuman; December 26, 2023 at 23:01.
tsuman is offline   Reply With Quote

Reply


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 to loop over Inlet and inject particles at the face centroids Vera1234 Fluent UDF and Scheme Programming 2 February 2, 2022 20:11
Need help regarding 6DOF udf with face loop burhanibrar Fluent UDF and Scheme Programming 20 July 28, 2021 05:48
[Gmsh] Extrude on gmsh Pedro Felix OpenFOAM Meshing & Mesh Conversion 0 October 30, 2019 13:33
Mixing loop reactor, recycle UDF Tleja Fluent UDF and Scheme Programming 0 September 25, 2015 13:33
Help UDF to Boundary Conditions in Closed Loop Pipe Blader Fluent UDF and Scheme Programming 2 May 14, 2012 10:48


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