TAGGED: cfd-udf-fleunt, dpm, number-of-particles
-
-
February 17, 2026 at 6:09 pm
Smruti R.
SubscriberI have written the following code for getting the total number of active particles in a domain (while using DPM in FLuent). The problem that I am facing is while printing the total number of particles, the moment the control comes out of the inner loop, the variable total_particles gets reinitialized back to 0 (even within the same function). Could someone please advise as in what is going wrong?
I have tried putting total_particles as a global variable too, but that too didn't help.#include "udf.h"#include "dpm.h"Â/* Name of the output file */#define FILE_NAME "active_particles.txt"ÂDEFINE_EXECUTE_AT_END(write_total_particles){  int total_particles = 0;  Particle *p;  Injection *inj;  Â  /* Loop over all injections */  loop(inj, Get_dpm_injections())  {    Message("total particles = %d, inside loop 1\n", total_particles);    /* Loop over all particles in the injection */    loop(p, inj->p)    {      total_particles = total_particles + 1;      Message("total particles = %d, inside loop 2\n", total_particles);    }  }  Â  /* Write total count from node 0 */  if (I_AM_NODE_ZERO_P)  {    FILE *fpp = fopen(FILE_NAME, "a");    if (fpp)    {      fprintf(fpp, "%f\t%d\n", CURRENT_TIME, total_particles);      fclose(fpp);    }    else    {       Message("Warning : Hey there, Could not open %s\n", FILE_NAME);    }  }} -
February 17, 2026 at 6:21 pm
Smruti R.
SubscriberTo add more clarity to my current explanation, here is what happens.Â
Let's say, there are 30 injections in total & every injection has a separate number of particles. Now, when the control completed counting the particles for the first injection, while coming out of the inner loop (i.e. loop(p, inj->p)), it should store the number of particles & that should be added to the number of particles in the subsequent injections. However, everytime, the control iterates through the injection loop (i.e. loop(inj, Get_dpm_injections())), the variable total_particles gets initialized to 0. And the total number doesn't add up.Â
So, could someone please look into as in what's going wrong? -
February 18, 2026 at 11:53 am
Rob
Forum ModeratorAre you trying to count the total parcels in the domain or what's just been injected?
-
- You must be logged in to reply to this topic.
-
5154
-
1836
-
1387
-
1248
-
1021
© 2026 Copyright ANSYS, Inc. All rights reserved.