Different Ways to Count Particles in COMSOL Multiphysics
Many different tools are available for counting particles. Choosing the optimal method depends on the application; specifically, whether you want to use the number of counted particles in equations or during postprocessing. The Particle Tracing interfaces in COMSOL Multiphysics feature three main particle counting options. While these approaches are versatile enough to compute quantities such as charge density and momentum flux, our focus here will be computing the number of particles on a set of domains or boundaries.
Three Particle Counting Approaches
When it comes to counting particles, the easiest way to do so is directly within postprocessing, after the solution has been computed. Let’s walk through the steps behind this basic methodology.
First, create a duplicate of the default Particle Data Set, which is automatically generated after computing the solution. Add a Selection to the data set, as illustrated below, and then select the domains or boundaries in which you will count the particles.
Next, add a Global Evaluation node under Derived Values and point to the new Particle Data Set, in this case, Particle 2. You can select specific parameter values or output times in the settings window.
Choose from the following predefined expressions under the Particle statistics section in the Add/Replace Expression menu:
.alpha— Transmission probability (the number of particles in the selection specified by the Particle Data Set divided by the total number of particles).
.Nsel— Total number of particles in selection (the number of particles in the selection specified by the Particle Data Set).
.Nt— Total number of particles (the total number of particles in the entire model).
Evaluating the Global Evaluation node will display the value of the expression in a results table.
Application Library Examples
- Molecular Flow Module > Industrial Applications > charge exchange cell
- AC/DC Module > Particle Tracing > quadrupole mass filter
If the number of particles or the number density of particles needs to be used in another physics interface, the best option is to use an Accumulator. Accumulators transfer information from particles to the mesh elements in which they reside. They are available on both domains and boundaries and can be accessed from the context menu of any Particle Tracing interface. Upon adding an accumulator to a domain, the following settings are shown:
The available options in the Accumulator feature are:
- Accumulator type: When set to Count, the accumulated variable is simply counted in each mesh element, unaffected by the element size. For Density, the accumulated variable is divided by the volume of the mesh element, allowing you to compute quantities like the number density of particles.
- Accumulate over: When set to Elements, the accumulated variable is simply the sum of the source terms for all of the particles that reside in the element at a given point in time. When set to Elements and time, the particles leave behind a contribution in the elements that they pass through, based upon how long they were in each element.
- Source: This is the expression defined on the particle that you want to project onto the underlying mesh. When counting particles, Source is simply set to “1”, but it can be any expression that exists on the particles, such as charge or kinetic energy. It can also depend on variables that are defined in the domain in which the particles are located.
- Unit: When the unit is selected for the accumulated variable, the required unit for the Source will change accordingly.
To count the total number of particles, you can add an integration component coupling to the domain where the accumulator exists. Boundary accumulators automatically add component couplings on the selected boundaries. In our example, the total number of particles is then given by <
(pt.count). This can be evaluated using the Global Evaluation node. The number of particles within each mesh element may also be coupled to other physics, since it is a degree of freedom. We can visualize how the particle counting works by plotting particle locations on a plot of the accumulated variable and the underlying mesh.
A plot shows the particle locations (black dots) on top of the underlying mesh (gray lines). The color in each element represents the value of the accumulated variable.
From the plot above, it is clear that the accumulator does indeed count the number of particles within each mesh element. For mesh elements in which there are no particles, the accumulated variable is zero, indicated by the mesh elements (shown in blue). Most mesh elements have one particle, which is highlighted in green. However, one mesh element happens to contain 2 particles (shown in red).
You can also use accumulators to count the number of particles passing through an interior boundary. To do this, simply add a Wall condition on the boundary that the particles will pass through, setting the Wall condition to Pass through. Add an Accumulator subfeature to the Wall node with the following settings:
When a particle passes through the boundary, the accumulator increments the degree of freedom in the corresponding boundary mesh element. This gives the spatial distribution of the number of particles passing through the interior boundary, as depicted in the animation below.
It is possible to conveniently plot the total number of particles passing through the boundary as a function of time. Simply add a 1D Plot Group and a Global plot feature. The accumulator creates predefined variables to add up the accumulated variables over all the mesh elements. To get the total number of particles, you can use the Sum of accumulated variable count option.
The plot below shows the results for the total number of particles that crossed the interior boundary.
Note: To learn more about the applications of accumulators, you can refer to this earlier blog post by my colleague Christopher Boucher.
Application Library Examples
- Molecular Flow Module > Benchmarks > s_bend_benchmark
Particle Counter, New in COMSOL Multiphysics Version 5.2
A Particle Counter is a domain or boundary feature that provides information about particles arriving on a set of selected domains or surfaces from a specified release feature. Such quantities include transmission probability, current, and mass flow rate. The settings for a Particle Counter feature are very simple. Select a Release feature to connect to, or select All release features. You can add Particle Counter features to the model and access their variables without having to recompute the solution. Simply use Study > Update Solution, and the new variables will be automatically generated and immediately available for evaluation.
Each Particle Counter generates the following expressions. Note that the scope is different than the variables that are always available in the Particle statistics plot group, as outlined in the first section.
.rL— Logical expression for particle inclusion; can be used in the Filter node of the Particle Trajectories plot, allowing visualization of only the particles that connect a source and a destination.
.Nsel— Total number of particles in selection; computes the total number of particles released by a specific release feature in the set of domains or boundaries determined by the Particle Counter selection.
.Nfin,— The number of transmitted particles at the final time (the number of particles in the Particle Counter selection at the final solution time).
.alpha— Transmission probability (the ratio of the number of particles in the Particle Counter selection divided by the number of particles released by the release feature).
When the Release feature is a Particle Beam feature — a specialized release feature for the Charged Particle Tracing interface — additional variables for the average beam position, velocity, and kinetic energy are generated for the particles that connect the counter to the particle beam.
Application Library Examples
- Particle Tracing Module > Charged Particle Tracing > sensitive high resolution ion microprobe
- Particle Tracing Module > Tutorials > brownian motion
- Particle Tracing Module > Fluid Flow > laminar mixer particle
Summary of Counting Particles in COMSOL Multiphysics
There are three ways to count the number of particles on domains and boundaries. For simple models in which only a single release feature is present, the postprocessing tools might suffice. If you want to plot the number of particles on a domain or boundary, or if you want to use the number of particles in another physics interface, accumulators are the answer. To count particles that only connect a specific release feature to a selection of domains or boundaries, you can use the Particle Counter feature — one of the many new additions in COMSOL Multiphysics version 5.2.
Access the MPH-files and documentation for the tutorial models and demo application featured in this blog post at the links below.
- COMSOL Now
- Fluid & Heat
- Structural & Acoustics
- Today in Science