Calculating number of particles in specific Region while Simulation runs

Submitted by berlinphoenix on Thu, 06/25/2020 - 17:39

Hi,

i have the common task to track the mixing status in my apparatus. For this i need to find the number of particles Type 1 and Type 2 in specific regions. Lets say i want to have cylinders and count the number of particles in them every 10000th time step and print the result to a file, How can i do that? Is there a way to do that in the input file?

Thanks and kind regards

mschramm | Thu, 06/25/2020 - 23:45

Hello,
This can be done by creating the regions, adding atoms to a groups based on their atom types, then counting the number of atoms in the group in a specific region.
https://www.cfdem.com/media/DEM/docu/region.html
https://www.cfdem.com/media/DEM/docu/group.html
https://www.cfdem.com/media/DEM/docu/variable.html

So to count all atoms of atom_type 1 in reg1
region reg1 block -3.0 5.0 -3.0 5.0 0 1
group g_type_ type 1
variable num_type_1_atoms_in_reg1 equal count(g_type_1,reg1)

berlinphoenix | Thu, 07/02/2020 - 19:19

Hi, thanks for your reply! I tested your suggestion:

region reg1 block -3.0 5.0 -3.0 5.0 0 1
group g_type_1 type 1
variable num_type_1_atoms_in_reg1 equal count(g_type_1,reg1)

This prints a value for all elements of type 1 regardless of the region they are in. How can i print the value of variable "num_type_1_atoms_in_reg1" ?
If i do "fix extra all print 100 "N = $num_type_1_atoms_in_reg1" it gives me the "substitution for illegal variable" error.
Also i want to save the counted particles every 1000th iteration. How can i do that? If i use the dump/custom command it complains about the variable not being of atom style...

Thanks a lot for your help

mschramm | Fri, 07/03/2020 - 02:44

Hello,
This is a snip of my input file for a shear cell simulation
region bulk_box block 0.025 0.1 0.0 0.1 0.0065 0.0450 units box
variable num_atoms equal count(all,bulk_box)

This counts the particles from the region that I care about. The difference is that I want to count all of the particles vs just a specific atom type

As for the variable error.
fix extra all print 100 "N = $num_type_1_atoms_in_reg1
should be
fix extra all print 100 "N = ${num_type_1_atoms_in_reg1}

only variables with a single letter do NOT need to be wrapped with {}.

berlinphoenix | Fri, 07/03/2020 - 16:47

Hi mschramm,

thanks a lot this works now as expected!
Now i want to calculate a further quantity from the number of particles in a specific region. For this i need a if loop to check if the denominator equals 0. I tried this code:

region reg1 cylinder y 0.0 0.0 0.5 2.0 3.0 units box

group reg1_g_type_1 type 1
group reg1_g_type_2 type 2

variable num1_reg1 equal count(reg1_t_type_1,reg1)
variable num2_reg1 equal count(reg1_g_type_2,reg1)

if "${num1_reg1} + ${num2_reg1} > 0.0" then " fix extra all print 1000 "Sum > 0""

This gives me an illegal if command error. Not sure what is wrong. Unfortunately i haven't found a working snippet anywhere..
Thanks for your help, much appreciated