Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 51

Implementing Monte Carlo Estimators for Cell-Averaged Scalar Flux

Recommended resources

Introduction

Welcome to the next stage of our journey into Monte Carlo simulation. In the previous lesson, we successfully scaled up our simulation from a single particle history to a full batch, allowing us to compute macroscopic probabilities like transmission and reflection by aggregating thousands of outcomes. This was a critical step, but to unlock the full power of Monte Carlo for dosimetry and shielding, we need to move beyond simple boundary events and learn how to measure quantities within the simulation volume.

This lesson introduces the concept of estimators, or tallies, which are the statistical tools used to "score" physical quantities of interest during a particle's random walk. We will focus on the fundamental quantity of scalar flux (), as it forms the basis for calculating reaction rates, kerma, and dose. You will learn the theory and implementation of three canonical flux estimators: the track-length, collision, and surface-crossing estimators. By the end, you will be able to modify your Python code to calculate the average scalar flux within a defined region of your slab geometry.


What Is Scalar Flux? The Monte Carlo Perspective

Before we can score scalar flux, let's refine our understanding of it. In your medical physics work, you've certainly encountered flux, often in the context of beam intensity or as a precursor to dose. While formally defined by the ICRU in terms of particles incident on a sphere, this definition is not the most intuitive for computational purposes. A more practical understanding is essential for Monte Carlo methods.

A very helpful paper by Prof. James Holloway, "Teaching Flux in the Age of Desktop Monte Carlo," explores three equivalent interpretations of scalar flux.

[PDF] Teaching Flux In The Age Of Desktop Monte Carlo - ASEE PEER

This paper provides an excellent conceptual bridge between the abstract definition of flux and its practical computation in Monte Carlo codes. It argues why one particular interpretation is the most useful for our purposes.

First, read the introductory sections to understand the different "competing interpretations" of scalar flux. Next, review the "Outline of a pedagogical approach" section, which builds up the concept from particle number density. Pay attention to how angular flux (\psi) is defined as speed times number density, and scalar flux (\phi) is its integral over all directions. Finally, and most importantly, read the section that begins by discussing the path-length density. This part explains that the total path-length (or track-length) traveled by all particles within a volume, per unit time, is equal to the scalar flux integrated over that volume.

As the paper highlights, the most powerful interpretation for Monte Carlo is that the cell-averaged scalar flux is the total path length generated by particles within that cell's volume, divided by the volume itself.

Let's formalize this. If we simulate source particles, and sum up all the track segments of all particles that pass through a volume , the average scalar flux in that volume is estimated as:

This directly gives rise to our first and most important estimator.


The Track-Length Estimator ()

The track-length estimator is a direct implementation of the path-length interpretation of flux. For each particle that travels through a scoring region (a "cell"), we simply add the length of its path inside that region to our tally.

The formal definition for the track-length estimator of the average scalar flux in a volume is:

where:

  • is the total number of source histories.
  • The sum is over all track segments of all particles.
  • is the length of a particle's track segment within .
  • is the statistical weight of the particle. In our analog simulation, .

This estimator is widely used and is known for its robustness and efficiency, especially in regions that are not optically thick. Major production codes like MCNP use it as their primary volume-averaged flux tally (the F4 tally).

In the general flow of a Monte Carlo simulation, our tallying logic fits into the "Increment tallies & update particle's parameters" step. For a track-length estimator, this happens after a particle moves but before its next collision or boundary crossing.

The Collision Estimator ()

An alternative way to estimate flux is to score at collision points. The intuition here is that the frequency of collisions in a region is proportional to the flux and the material's total cross section (). If we count collisions, we can work backward to estimate the flux that caused them.

The collision estimator is defined as:

where:

  • The sum is over all collisions that occur within the volume .
  • is the particle's weight just before the collision.
  • is the total macroscopic cross section at the energy of the collision.

The term is crucial. It corrects for the fact that collisions are more likely in materials with high cross sections. A collision in a high- material represents "less" flux than a collision in a low- material, because the particle didn't have to travel as far on average to cause it. This estimator performs well in optically thick regions where collisions are frequent but is very inefficient in near-vacuum regions.


The Surface-Crossing Estimator ()

Finally, we can estimate the average flux in a volume by observing the particles that cross its boundary surfaces. This estimator connects back to the more classical definitions of flux and current.

The surface-crossing estimator is:

where:

  • The sum is over all particle crossings of any of the surfaces of volume .
  • is the particle's weight at the crossing point.
  • is the unit vector of the particle's direction.
  • is the unit vector normal to the surface at the crossing point.

The term is a geometric correction. A particle crossing a surface at a grazing angle () contributes more to the volume flux for a given surface-crossing event than a particle crossing perpendicularly. This estimator can be very effective but can also suffer from high variance, especially if particles can cross surfaces at very shallow angles.

The following resource provides concise definitions for these three estimators.

[PDF] chapter 2: the monte carlo method - canteach

This chapter from a course on MCNP provides a brief but clear overview of scoring and different estimator types.

Please read the section titled "Scoring". It contains three key paragraphs defining the surface crossing estimator, the track length estimator, and the collision density estimator. Note that "fluence" is used interchangeably with "flux".


Implementing and Comparing Estimators

Now, let's consider how to implement these in your Python code. You will need to first define a scoring mesh. For our slab geometry, this can be a simple 1D array of bins along the z-axis.

Let's say our slab of thickness T is divided into M cells, each of width . The volume of each cell is , where is the cross-sectional area. Since flux is usually calculated per unit area, we can work with flux per unit source particle and a cell "volume" that is just the cell width .

Your simulate_photon_history function should be modified to accept three arrays, one for each tally: tl_tally, c_tally, sc_tally.

Track-Length Tally Logic:
When a particle moves from to :

  1. Determine which scoring cells the track segment passes through.
  2. For each cell j it passes through, calculate the path length within that cell.
  3. Add this length to the tally: tl_tally[j] += l_j.

Collision Tally Logic:
When a collision occurs at position with energy :

  1. Determine which cell j contains .
  2. Calculate the total macroscopic cross section .
  3. Add the score to the tally: c_tally[j] += 1.0 / sigma_t_total.

Surface-Crossing Tally Logic:
When a particle's path crosses a cell boundary at with direction :

  1. The direction cosine along z is . The surface normal is along the z-axis, so .
  2. Determine which two cells, j and j+1, share this boundary.
  3. Both tallies could be incremented, or by convention, only the cell being entered is scored. Let's score the cell the particle is entering.
  4. Add the score to the appropriate tally: sc_tally[j_enter] += 1.0 / abs(mu).

After running the batch simulation, you normalize each tally bin j by dividing by the number of histories and the cell volume (or width ).

Statistical Performance

These estimators, while all aiming to compute the same quantity, have different statistical properties. The variance of the estimate for a given computational effort can differ significantly.

This plot compares the convergence of the mean scalar flux calculated by a collision estimator (C) and a track-length estimator (TL) as the number of histories (N) increases. The First Collision (FC) estimator is a related variant.

Notice two key things in the "Flux Estimator Convergence" plot:

  1. The track-length estimator (TL, green line) shows smaller fluctuations at low N compared to the collision estimator (C, blue line), indicating it is converging faster and has lower variance for this particular problem.
  2. The estimators appear to be converging to different values. This is not an error! It highlights a subtle but critical point: while mathematically equivalent in an infinite, homogeneous medium, estimators can have biases in finite or inhomogeneous problems. The collision estimator naturally favors regions where collisions are more likely (higher ). The track-length estimator correctly weights all regions of the volume by the time spent within them, making it a more robust volume-average estimator. This is why it is generally preferred.

Conclusion

In this lesson, we have moved from simple event counting to sophisticated in-volume scoring. You have learned the theoretical basis for three fundamental flux estimators used in Monte Carlo transport, grounded in the physical interpretation of scalar flux as a path-length rate density.

Key Takeaways:

  • Scalar Flux can be interpreted as the path-length rate density, a concept that is ideal for Monte Carlo simulation.
  • The Track-Length Estimator () directly implements this concept by summing particle path lengths within a volume. It is generally the most efficient and robust estimator for volume-averaged flux.
  • The Collision Estimator () scores at each collision site. It is effective in optically thick regions but can be biased in heterogeneous media.
  • The Surface-Crossing Estimator () scores at cell boundaries. It relates flux to particle current across surfaces.
  • Implementing these estimators requires modifying your particle tracking loop to add scores to tally arrays based on particle movement, collisions, and boundary crossings.

Preview of the Next Lesson:
With the ability to score scalar flux, we are now just one step away from our primary goal in dosimetry. In the next lesson, "Score collision kerma in a Monte Carlo simulation and approximate absorbed dose under CPE," we will leverage these new techniques. You will learn how to use the information from collisions and flux tallies, combined with energy-transfer coefficients, to calculate kerma and, under the condition of charged particle equilibrium, absorbed dose.