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?
-
February 20, 2026 at 1:31 am
Smruti R.
SubscriberI want to calculate the total number of active particles in the domain (at a particular time step) & pass on that data to a file to get a time-wise variation.
-
-
February 20, 2026 at 8:51 am
Rob
Forum ModeratorAre the DPM Report functions not sufficient?
-
February 20, 2026 at 10:44 am
Smruti R.
SubscriberThe DPM report function mentioned in the “report definitions” tab only reports the injected mass & total mass in the domain, however, there is no way we can get the active particle numbers directly from the report definitions. While running the simulation, I do see the total number of tracked particles in the TUI (Console), but no way you can directly get the total number of tracked particles.
Hence, I had to write a UDF to get the total number of tracked particles.
-
-
- You must be logged in to reply to this topic.
-
5159
-
1836
-
1387
-
1249
-
1021
© 2026 Copyright ANSYS, Inc. All rights reserved.