Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Benchmark Problem 8: Homogeneous Nucleation

%%javascript
    MathJax.Hub.Config({
      TeX: { equationNumbers: { autoNumber: "AMS" } }
    });
Loading...
from IPython.display import HTML

HTML('''<script>
code_show=true; 
function code_toggle() {
 if (code_show){
 $('div.input').hide();
 $('div.prompt').hide();
 } else {
 $('div.input').show();
$('div.prompt').show();
 }
 code_show = !code_show
} 
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Code Toggle"></form>''')
Loading...
from IPython.display import HTML

HTML('''
<a href="https://github.com/usnistgov/pfhub/raw/master/benchmarks/benchmark8.ipynb"
   download>
<button type="submit">Download Notebook</button>
</a>
''')
Loading...

Benchmark Problem 8: Homogeneous Nucleation

from IPython.display import HTML

HTML('''{% include jupyter_benchmark_table.html num="[8]" revision=1 %}''')
Loading...

See the journal publication entitled “Phase Field Benchmark Problems for Nucleation” for more details about the nucleation benchmark problem. An in-depth analysis focused on this benchmark was also published in the journal publication entitled “On the Effect of Nucleation Undercooling on Phase Transformation Kinetics”. The analysis in this later publication led to several minor changes to the benchmark that are not present in the first journal publication. Furthermore, read the extended essay for a discussion about the need for benchmark problems.

Overview

Phase field modeling of nucleation has a long history and is covered in a number of reviews (Gránásy 2002, Castro 2003, Simmons 2004, Gránásy 2007, Warren 2009, Heo 2014, Gránásy 2019). The problem formulation of crystallization of an ideal pure liquid cooled below its melting point starts with homogeneous nucleation, a process in which the internal fluctuations of the undercooled liquid lead to the formation of crystal-like seeds able to grow to macroscopic sizes. The nucleation can be assisted by the presence of surfaces (container walls, foreign particles, etc.), in which case the process is termed heterogeneous nucleation. We note that homogeneous nucleation is an idealized formulation, and it is unlikely homogeneous nucleation occurs, due to impurities present in experimental apparatus. However, creating benchmark problems for homogeneous nucleation is still needed since the focus in nucleation research often lies on the underlying homogeneous nucleation, as it is the basis for advancing theoretical approaches to the much more complex phenomena governing heterogeneous nucleation. This benchmark (benchmark 8) targets homogeneous nucleation while benchmark 9 targets heterogeneous nucleation.

There are two main modeling approaches to introduce nuclei into a metastable system: the Langevin noise method (Kubo 1966, Gránásy 2002) and the explicit nucleation method (Simmons 2000, Shi 2019) . We focus on the explicit method, where the critical nucleus size and the nucleation energy are determined by the classical nucleation theory. We break down our consideration of homogeneous nucleation into three parts. Part (a) considers the simple case of single-seed homogeneous nucleation. We explore how the particle size influences the evolution of the nucleus when the thermodynamic driving force is close to the critical value where we can observe whether the particle grows, dissolves or remains stationary. In parts (b) and (c) we consider multiple-seed homogeneous nucleation, with nuclei appearing at fixed time t=0t=0 or at random times distributed uniformly, respectively, with the latter part illustrating a scenario with constant nucleation rate. The Benchmark Problem probes the differences between transformation kinetics of the two cases and summarizes them using the Avrami plots based on the Johnson-Mehl-Avrami-Kolmogorov (JMAK) theory (Johnson 1939, Avrami 1939, Avrami 1940, Avrami 1941, Kolmogorov 1937).

Model Formulation

The phase field model in classical nucleation theory

For this benchmark problems we use the simplest possible phase field model with a single non-conserved phase field ϕ\phi, which describes an isothermal pure substance with one liquid (ϕ=0\phi=0) and one solid (ϕ=1\phi=1) phase. The free energy of this system is

F(ϕ)=[ϵ22(ϕ)2+wg(ϕ)Δfp(ϕ)]dV,\mathcal{F}(\phi)=\int \left[\frac{\epsilon^2}{2}(\nabla \phi)^2+wg(\phi)-\Delta f p(\phi) \right] d{V},

set g(ϕ)=ϕ2(1ϕ)2g(\phi)=\phi^2(1-\phi)^2, a simple double well function with minima at ϕ=0\phi=0 and ϕ=1\phi=1, w w controls the double-well barrier height, ϵ2\epsilon^2 is the gradient energy coefficient, let p(ϕ)=ϕ3(1015ϕ+6ϕ2)p(\phi)=\phi^3(10-15\phi+6\phi^2), which ensures that p(0)=p(0)=p(1)=0p(0)=p'(0)=p'(1)=0 and p(1)=1p(1)=1, and Δf\Delta f is the driving force for solidification at the simulation temperature (Δf\Delta f is positive below the melting point). The time evolution of ϕ\phi is given by the Allen-Cahn equation (Allen 1979)

ϕt=MδFδϕ=M[ϵ22ϕwg(ϕ)+Δfp(ϕ)]\frac{\partial \phi}{\partial t}=-M\frac{\delta \mathcal{F}}{\delta \phi}=M\left[\epsilon^2\nabla^2\phi-wg'(\phi)+\Delta fp'(\phi)\right]

where MM is the mobility parameter. We will restrict the problem to two dimensions (2D). For a planar interface, one can show that the equilibrium (Δf\Delta f=0) solid-liquid interface profile with the interface centered at x=x0x=x_0 is given by

ϕ(x)=12[1tanh(xx02)],\phi(x)=\frac{1}{2}\left[1-\tanh\left(\frac{x-x_0}{\sqrt{2}\ell}\right)\right],

where xx is the perpendicular distance from the interface. We use this expression as the initial condition when we introduce a nucleus. We can also obtain the width \ell and the free energy of the interface, γ\gamma, as

=ϵ2w\ell=\sqrt{\frac{\epsilon^2}{w}}

and

γ=ϵ2w32.\gamma=\frac{\sqrt{\epsilon^2w}}{3\sqrt{2}}.

Choosing a characteristic length scale ξ=\xi=\ell and a characteristic time scale τ=1/(Mw)\tau=1/(Mw), we can obtain a nondimensional form of the problem (the nondimensional quantities are denoted by tildes),

F~(ϕ)=[12(~ϕ)2+g(ϕ)Δf~p(ϕ)]dV~\widetilde{\mathcal{F}}(\phi)=\int \left[\frac{1}{2}(\widetilde{\nabla} \phi)^2+g(\phi)- \widetilde{\Delta f} p(\phi) \right] d{\widetilde{V}}

and

ϕt~=~2ϕg(ϕ)+Δf~p(ϕ),\frac{\partial \phi}{\partial \widetilde{t}}=\widetilde{\nabla}^2\phi-g'(\phi)+\widetilde{\Delta f}p'(\phi),

with Δf~=Δf/w\widetilde{\Delta f}=\Delta f/w.

The properties of the classical nucleus

The explicit nucleation method that we employ introduces nuclei into a metastable system, with their radii and nucleation barrier determined from classical nucleation theory. Classical nucleation theory views crystallite fluctuations appearing in the undercooled liquid as small spherical domains of the bulk crystalline phase bounded by a mathematically sharp solid-liquid interface. For a 2D system, the free energy of a circular solid particle of radius rr is

ΔG(r)=2πrγπr2Δf\Delta G(r) = 2 \pi r \gamma - \pi r^2 \Delta f

where Δf\Delta f is the nucleation driving force that is used in our phase field model, and γ\gamma is the free energy of the interface. The free energy of the particle is a balance between the energy cost in forming the solid-liquid interface, and the free energy from the driving force which is released when the crystalline particle forms. Once the rate of change of free energy with respect to particle size becomes negative, the particle can grow. Taking the derivative of ΔG(r)\Delta G(r) we get the rate of change of free energy with respect to radius as

dΔGdr=2πγ2πrΔf.\frac{d\Delta G}{dr}=2\pi \gamma - 2\pi r\Delta f.

By setting dΔG/drd\Delta G/dr to zero, we obtain the critical radius rr^* as

r=γΔf.r^* = \frac{\gamma}{\Delta f}.

The corresponding critical nucleation free energy is

ΔG=πγ2Δf.\Delta G^* = \frac{\pi \gamma^2}{\Delta f}.

Using the same units as before, the nondimensional forms of these quantities are

r~=1321Δf~\widetilde{r}^* = \frac{1}{3\sqrt{2}}\frac{1}{\widetilde{\Delta f}}

and

ΔG~=π181Δf~,\widetilde{\Delta G}^* = \frac{\pi}{18}\frac{1}{\widetilde{\Delta f}} ,

respectively.

Avrami plots

Avrami plots describe how solids transform from one phase to another at constant temperature. In particular, they can describe the kinetics of nucleation. The Avrami plots come from the JMAK theory (Johnson 1939, Avrami 1939, Avrami 1940, Avrami 1941, Kolmogorov 1937), which makes a number of assumptions and simplifications: (i) nucleation occurs randomly and homogeneously over the entire un-transformed portion of the material, (ii) the growth rate is constant and does not depend on the extent of transformation, (iii) the particles have convex shape with the same orientation, and (iv) the size of the system is infinite (both in space and time).

The basis of the Avrami plots is the transformed fraction (solid fraction) Y(t)Y(t) vs. time. According to the JMAK theory,

Y(t)=1exp(Ktn),Y(t)=1-\exp (-Kt^n),

where KK is a constant depending on the nucleation and growth rates, n=d+1n=d+1 for continuous nucleation and n=dn=d if nucleation happens only at t=0t=0, and dd is the number of spatial dimensions. If we plot log(log(1Y))\log(-\log(1-Y)) vs. log(t)\log(t), then for the JMAK kinetics (Eq. \ref{eqn:Xt}) we get a straight line with slope nn.

With this straight line, a slope value can be obtained by selecting a fitting range from the values in the range of 2<log(log(1Y))<0-2 < \log(-\log(1-Y)) < 0 and using linear regression. This range corresponds to the volume fractions 0.02<Y<0.9 0.02 < Y < 0.9 which represents a major portion of the transformation. This fitting range enables a consistent fitting range to be applied in all parts which involve Avrami plots (Mancias 2022).

Benchmark 8 Specification

From here on, we will use only the nondimensional forms of the phase field (Eqs. \ref{eqn:tFphi}, \ref{eqn:dphidtt}, and \ref{eqn:phir}) and nucleation (Eqs. \ref{eqn:trc} and \ref{eqn:tdeltaGc}) equations, but we will drop the tildes.

We consider 2D simulation domains centered at x=y=0x=y=0. Periodic boundary conditions are applied in order to emulate JMAK theory assumptions of infinite domain and spatiotemporal homogeneity of nucleation and growth.

Part (a): single seed

In this problem we examine the morphology change of the nucleus for different initial radii in a domain of 100×100100 \times 100 units. The driving force is set to Δf=2/30\Delta f = \sqrt{2}/30, which corresponds to a critical radius of r=5r^*=5 (Eq. \ref{eqn:trc}). Next, we place a circular seed at the center of the domain. Incorporating a nucleus into a diffuse interface phase field model leads to a small offset from a classical, sharp-interface model of a nucleus. To account for this, we incorporate a diffuse-interface seed using the profile ϕ(r)\phi(r) given by modifying Eq. \ref{eqn:phir} to 2D where r=x2+y2r=\sqrt{x^2+y^2}, with a radius r0=rr_0=r^*. This seed is the diffuse-interface approximation of the classical sharp interface nucleus corresponding to the given Δf\Delta f, and therefore it should be fairly close to (an unstable) equilibrium. Part (a) is then defined by the Allen-Cahn equation

ϕt=2ϕg(ϕ)+Δfp(ϕ)\frac{\partial \phi}{\partial {t}}={\nabla}^2\phi-g'(\phi)+{\Delta f}p'(\phi)

for the phase field ϕ\phi, and the three different initial conditions: in the first case with the seed radius r0r_0 corresponding exactly to the critical one (critical nucleus), and in the other two cases, slightly below and above the critical radius (subcritical and supercritical nuclei):

ϕ(r)=12[1tanh(rr02)],\phi(r)=\frac{1}{2}\left[1-\tanh\left( \frac{r-r_0}{\sqrt{2}} \right)\right],

where r0={r,0.99r,1.01r}r_0=\{r^*, 0.99r^*, 1.01r^*\}. Figure 1 shows the computational domain with an initial seed of radius r=rr=r^*. The time evolution of the system is then followed for times up to t=200t = 200 units, and the solid fraction YY and the total free energy FF are plotted as functions of time. Finally, the problem also includes a convergence test with respect to mesh (spatial resolution). The closer the initial radius rr is to the critical radius rr^*, the more sensitive the numerical integration will be to round-off errors. Therefore, a convergence test is included for r0=1.01rr_0=1.01r^* using successive runs each halving the average spatial mesh size Δx\Delta x between consecutive runs. At least 3 runs are required to estimate the rate of convergence based on the L2L^2 error with the finest mesh being used as a gold standard. The simulations should be run to t=200t=200 and the final phase field (at t=200t=200) for each successive run should be submitted.

To submit results to the PFHub website, see the submission guidelines below.

Single seed at t=0

Illustration of the $100 \times 100$ computational domain in 2D.

Part (b): multiple initial seeds

The second part of the homogeneous nucleation benchmark problem focuses on the kinetics of nucleation using Avrami plots and compares them to JMAK theory. To obtain reasonable statistics for these two parts, the simulation volume needs to be larger so it can encompass a larger number of smaller nuclei. We therefore increase the domain size to 500×500500 \times 500 units of length, and the driving force to Δf=1/(32)\Delta f = 1/(3 \sqrt{2}), which corresponds to a critical radius of r=1r^*=1. Random initial positions ri\mathbf{r}_i of 25 supercritical seeds i,i=1,,25i, i=1,\ldots,25 are generated with r0=2.2rr_0=2.2r^* drawn from a uniform distribution on the 500×500500\times500 domain. Periodic boundary conditions are applied. The distribution of the phase field ϕ\phi is the sum of the phase fields ϕi\phi_i with profiles

ϕi(r)=12[1tanh(rri2.2r2)].\phi_i(r)=\frac{1}{2}\left[1-\tanh\left( \frac{|\mathbf{r}-\mathbf{r}_i|-2.2r^*}{\sqrt{2}} \right)\right].

from the different seeds ii. Overlaps between different seeds are managed by setting ϕ=1\phi=1 in all regions where the sums of ϕi>1\phi_i >1. After placing initial seeds and adjusting the initial phase field ϕ\phi so that ϕ1\phi\leq1 everywhere, the simulation is run up to total time t=200t=200, at which time the whole domain is transformed to a solid (ϕ=1\phi=1). This is repeated at least 10 times, each time with different random seeds, and the total free energy, time evolution of the solid fraction YY, discrete particle count NN (the number of disjoint regions with ϕ=1\phi=1) and Avrami plots are generated from all simulations; from the Avrami plot the exponent nn is estimated and compared to the JMAK theory. The number of simulation repeats you can perform in a “reasonable” time will depend on your code and hardware: 10 is required for statistical relevance, but more is better.

Both Part (b) and Part (c) involve a random number generator. Because different executions will in general generate different random numbers, specific individual solutions will in general not be reproduced. However, statistics such as the average slope of Avrami plots can be meaningfully compared.

To submit results to the PFHub website, see the submission guidelines below.

Part (c): multiple seeds at random times

For the third part of the homogeneous benchmark problem, the computational domain is first expanded to 1000×10001000 \times1000. Instead of inserting nuclei at fixed time t=0t = 0 as in part two of the problem, in this case 100 random nucleation times tit_i are generated, i=1,,100i=1,\ldots,100, drawn from a uniform distribution in the interval ti[0,600)t_i \in [0, 600) with centers ri\mathbf{r}_i drawn from a uniform distribution on the 1000×10001000\times1000 domain. The driving force is the same as Part (b): Δf=1/(32)\Delta f=1/(3 \sqrt{2}), which corresponds to a critical radius r=1r^*=1. The initial radii are also kept the same at r0=2.2rr_0 = 2.2r^* and the boundary conditions are periodic.

ϕi(r)=12[1tanh(rri1.1r2)].\phi_i(r)=\frac{1}{2}\left[1-\tanh\left( \frac{|\mathbf{r}-\mathbf{r}_i|-1.1r^*}{\sqrt{2}} \right)\right].

Again, ϕ\phi is set to unity in regions of overlaps of nuclei. The simulation is performed up to times t=600t=600, and then repeated for a total of ten (10) simulations for statistical significance. The total free energy, time evolution of the solid fraction YY, and discrete particle count NN are plotted as functions of time, and an Avrami plot is generated for each of the 10 runs.

To submit results to the PFHub website, see the submission guidelines below.

Submission Guidelines

Please follow these upload instructions.

In addition to that specified, further data to upload can include a Youtube video, images of the nuclei at different times, or the entire phase field variable at different times. This data can be uploaded directly to the website or stored at a secondary location and only the link to the data provided. This data is not required, but will help others view your work.

Part (a)

Part (a) requires running three simulations with a single seed with different values of r0r_0 using the model formulation defined above. The three required simulations are

  1. r0=0.99rr_0 = 0.99 r^*

  2. r0=rr_0 = r^*

  3. r0=1.01rr_0 = 1.01 r^*

Each simulation should be run to t=200t=200 and the following data should be collected.

  • The solid fraction in the domain (the integral VϕdV/VdV\int_V \phi \mathrm{d}V / \int_V \mathrm{d}V) during the transient (not necessarily at every time step but for ~100 data points).

  • The free energy integrated over the whole domain, F\mathcal{F}, during the transient.

  • The phase field, ϕ\phi, at each grid point in the domain at t=200t=200.

One PFHub upload is required for all the simulations. The solid fraction and free energy data should be included in the same file for each simulation. The file name needs to be data_{i}.{ext} depending on the simulation number, i, (1 to 3) and the file extension, ext, either csv, json or tsv. The CSV (JSON or TSV are also fine) files should have a format similar to the example below and with the same column headers.

time,fraction,energy
0.000000000000000000e+00,8.214174263100689974e-03,3.579809478015085311e+00
1.000000000000000056e-01,8.205027223394931180e-03,3.577696619091880859e+00
2.000000000000000111e-01,8.197361418448430651e-03,3.576379039721957032e+00
...

The phase field data file should be named phase_field_{i}.{ext} and have the following column headers.

x,y,phi
0.0,1.0,0.5
0.0,1.5,0.49
...

where x and y is a position in the domain and phi is the value at that position.

Part (b)

Part (b) requires running ten simulations with multiple seeds randomly positioned at t=0t=0, see the definition above. The simulations are run to t=200t=200. The following data should be collected.

  • The solid fraction in the domain (the integral VϕdV/VdV\int_V \phi \mathrm{d}V / \int_V \mathrm{d}V) during the transient (not necessarily at every time step but for ~100 data points).

  • The free energy integrated over the whole domain, F\mathcal{F}, during the transient.

  • The discrete particle count, NN, during the transient.

One PFHub upload is required with ten data files, but with a total of 30 entries in the “Data Files” section. The solid fraction, free energy and particle count can be included in the same data file for each simulation. The entries should be labeled as solid_fraction_{i}, free_energy_{i} or particle_count_{i} depending on the simulation number (1 to 10). The CSV (JSON or TSV are also fine) files should have a format similar to the following.

time,fraction,energy,particle_count
0.000000000000000000e+00,8.214174263100689974e-03,3.579809478015085311e+00,24
1.000000000000000056e-01,8.205027223394931180e-03,3.577696619091880859e+00,24
2.000000000000000111e-01,8.197361418448430651e-03,3.576379039721957032e+00,23
...

Part (c)

Part (c) requires running 10 simulations with seeds randomly appearing between t=0t=0 and t=600t=600, see the definition above. The simulations are run to t=600t=600. The following data should be collected.

  • The solid fraction in the domain (the integral VϕdV/VdV\int_V \phi \mathrm{d}V / \int_V \mathrm{d}V) during the transient (not necessarily at every time step but for ~100 data points).

  • The free energy integrated over the whole domain, F\mathcal{F}, during the transient.

  • The discrete particle count, NN, during the transient.

One PFHub upload is required with ten data files, but with a total of 30 entries in the “Data Files” section. The solid fraction, free energy and particle count can be included in the same data file for each simulation. The entries should be labeled as solid_fraction_{i}, free_energy_{i} or particle_count_{i} depending on the simulation number (1 to 10). The CSV (JSON or TSV are also fine) files should have a format similar to the following.

time,fraction,energy,particle_count
0.000000000000000000e+00,8.214174263100689974e-03,3.579809478015085311e+00,0
1.000000000000000056e-01,8.205027223394931180e-03,3.577696619091880859e+00,1
2.000000000000000111e-01,8.197361418448430651e-03,3.576379039721957032e+00,1
...

Please use the [upload form]({{ site.baseurl }}/simulations/upload_form/) to upload your results.

Results

Results from this benchmark problem are displayed on the [simulation result page]({{ site.baseurl }}/simulations/8a.1) for different codes.

References

[^] [^]

Gránásy, L and and Börzsönyi, T and Pusztai, T. 2002. Nucleation and bulk crystallization in binary phase field theory. URL

[^]

Castro, Mario. 2003. Phase-field approach to heterogeneous nucleation. URL

[^]

Simmons, J P and Wen, Y and Shen, C and Wang, Y. 2004. Microstructural development involving nucleation and growth phenomena simulated with the Phase Field method. URL

[^]

Gránásy, L and T and Pusztai, T and Saylor, D and Warren, J A. 2007. Phase field theory of heterogeneous crystal nucleation. URL

[^]

Warren, J A and Pusztai, T and Gránásy, L K and Gránásy, L. 2009. Phase field approach to heterogeneous crystal nucleation in alloys. URL

[^]

Heo, T W and Chen, L. 2014. Phase-field modeling of nucleation in solid-state phase transformations. URL

[^]

Gránásy, L and Tóth, G and Warren, J A and Podmaniczky, F and Tegze, G and Rátkai, L and Pusztai, T. 2019. Phase-field modeling of crystal nucleation in undercooled liquids -- A review. URL

[^]

Kubo, R. 1966. The fluctuation-dissipation theorem. URL

[^]

Simmons, J P and Shen, C and Wang, Y. 2000. Phase field modeling of simultaneous nucleation and growth by explicitly incorporating nucleation events. URL

[^]

Shi, R and Khairallah, S and Heo, T W and Rolchigo, M and McKeown, J T and Matthews, M J. 2019. Integrated simulation framework for additively manufactured Ti-6Al-4V: melt pool dynamics, microstructure, solid-state phase transformation, and microelastic response. URL

[^] [^]

Johnson, William A and Mehl, R F. 1939. Reaction kinetics in processes of nucleation and growth. URL

[^] [^]

Avrami, Melvin. 1939. Kinetics of phase change. I General theory. URL

[^] [^]

Avrami, Melvin. 1940. Kinetics of phase change. II transformation-time relations for random distribution of nuclei. URL

[^] [^]

Avrami, Melvin. 1941. Granulation, phase change, and microstructure kinetics of phase change. III. URL

[^] [^]

Kolmogorov, A N. 1937. On the Statistical Theory of the Crystallization of Metals. URL

[^]

Allen, Samuel M and Cahn, John W. 1979. A microscopic theory for antiphase boundary motion and its application to antiphase domain coarsening. URL

[^]

Mancias, J., Attari, V., Arroyave, R and Tourret, D. 2022. On the Effect of Nucleation Undercooling on Phase Transformation Kinetics. URL

Appendix

The following code is given as a resource for those implementing the benchmark to help count the particles in Part (b) and Part (c). One possibility as outlined here is to use scipy.ndimage.label. This returns a tuple with a labeled array of unique features as the first item and a count of features as the second item. In the case of the phase field the values will require thresholding to 0 or 1 before using scipy.ndimage.label.

import numpy as np
import scipy.ndimage
import matplotlib.pyplot as plt

def make_particles(shape, n_particles, max_radius, seed=99):
    """Make an array with random particles
    
    Args:
      shape: shape of array
      n_particles: number of particles in arrau
      max_radius: maximum possible radius of particles
      seed: random seed
      
    Returns: numpy array mask with particles
    """
    np.random.seed(seed)
        
    def xy_grid(shape):
        """Generate a grid of x, y values in a single array
        
        The returned array has shape (len(shape),) + shape + (1,). The last axis is
        for the operations with particles.
        """
        linspace = lambda x: np.linspace(0, x - 1, x) + 0.5
        return np.array(np.meshgrid(*map(linspace, shape), indexing="ij"))[..., None]
    
    # first axis is dimensions
    # second and third axes are shape of domain
    # last axis is the number of particles. 
    centers = (np.random.random((len(shape), n_particles)) * np.array(shape)[:, None])[:, None, None]
    radii = (np.random.random(n_particles) * max_radius)[None, None]
    return numpy.any(((xy_grid(shape) - centers)**2).sum(0) < radii**2, axis=-1)

arr = make_particles((100, 200), 20, 10)
plt.imshow(arr)
print('Actual number of particles:', scipy.ndimage.label(arr)[1])
import numpy as np
import scipy.ndimage
import matplotlib.pyplot as plt

def make_particles(shape, n_particles, max_radius, seed=99):
    """Make an array with random particles
    
    Args:
      shape: shape of array
      n_particles: number of particles in arrau
      max_radius: maximum possible radius of particles
      seed: random seed
      
    Returns: numpy array mask with particles
    """
    np.random.seed(seed)
        
    def xy_grid(shape):
        """Generate a grid of x, y values in a single array
        
        The returned array has shape (len(shape),) + shape + (1,). The last axis is
        for the operations with particles.
        """
        linspace = lambda x: np.linspace(0, x - 1, x) + 0.5
        return np.array(np.meshgrid(*map(linspace, shape), indexing="ij"))[..., None]
    
    # first axis is dimensions
    # second and third axes are shape of domain
    # last axis is the number of particles. 
    centers = (np.random.random((len(shape), n_particles)) * np.array(shape)[:, None])[:, None, None]
    radii = (np.random.random(n_particles) * max_radius)[None, None]
    return np.any(((xy_grid(shape) - centers)**2).sum(0) < radii**2, axis=-1)

arr = make_particles((100, 200), 20, 10)
plt.imshow(arr)
print('Actual number of particles:', scipy.ndimage.label(arr)[1])
Actual number of particles: 14
<Figure size 640x480 with 1 Axes>
References
  1. Wu, W., Montiel, D., Guyer, J. E., Voorhees, P. W., Warren, J. A., Wheeler, D., Gránásy, L., Pusztai, T., & Heinonen, O. G. (2021). Phase field benchmark problems for nucleation. Computational Materials Science, 193, 110371. 10.1016/j.commatsci.2021.110371
  2. Mancias, J., Attari, V., Arróyave, R., & Tourret, D. (2022). On the Effect of Nucleation Undercooling on Phase Transformation Kinetics. Integrating Materials and Manufacturing Innovation, 11(4), 628–636. 10.1007/s40192-022-00284-1
  3. Gránásy, L., Börzsönyi, T., & Pusztai, T. (2002). Nucleation and Bulk Crystallization in Binary Phase Field Theory. Physical Review Letters, 88(20). 10.1103/physrevlett.88.206105
  4. Castro, M. (2003). Phase-field approach to heterogeneous nucleation. Physical Review B, 67(3). 10.1103/physrevb.67.035412
  5. Simmons, J. P., Wen, Y., Shen, C., & Wang, Y. Z. (2004). Microstructural development involving nucleation and growth phenomena simulated with the Phase Field method. Materials Science and Engineering: A, 365(1–2), 136–143. 10.1016/j.msea.2003.09.019
  6. Gránásy, L., Pusztai, T., Saylor, D., & Warren, J. A. (2007). Phase Field Theory of Heterogeneous Crystal Nucleation. Physical Review Letters, 98(3). 10.1103/physrevlett.98.035703
  7. Warren, J. A., Pusztai, T., Környei, L., & Gránásy, L. (2009). Phase field approach to heterogeneous crystal nucleation in alloys. Physical Review B, 79(1). 10.1103/physrevb.79.014204
  8. Heo, T. W., & Chen, L.-Q. (2014). Phase-Field Modeling of Nucleation in Solid-State Phase Transformations. JOM, 66(8), 1520–1528. 10.1007/s11837-014-1033-9
  9. Gránásy, L., Tóth, G. I., Warren, J. A., Podmaniczky, F., Tegze, G., Rátkai, L., & Pusztai, T. (2019). Phase-field modeling of crystal nucleation in undercooled liquids – A review. Progress in Materials Science, 106, 100569. 10.1016/j.pmatsci.2019.05.002
  10. Kubo, R. (1966). The fluctuation-dissipation theorem. Reports on Progress in Physics, 29(1), 255–284. 10.1088/0034-4885/29/1/306
  11. Barmak, K. (2010). A Commentary on: “Reaction Kinetics in Processes of Nucleation and Growth”*. Metallurgical and Materials Transactions B, 49(6), 3616–3680. 10.1007/s11663-010-9421-1
  12. Avrami, M. (1939). Kinetics of Phase Change. I General Theory. The Journal of Chemical Physics, 7(12), 1103–1112. 10.1063/1.1750380
  13. Avrami, M. (1940). Kinetics of Phase Change. II Transformation-Time Relations for Random Distribution of Nuclei. The Journal of Chemical Physics, 8(2), 212–224. 10.1063/1.1750631
  14. Avrami, M. (1941). Granulation, Phase Change, and Microstructure Kinetics of Phase Change. III. The Journal of Chemical Physics, 9(2), 177–184. 10.1063/1.1750872
  15. Shiryayev, A. N. (1992). On The Statistical Theory of Metal Crystallization. In Selected Works of A. N. Kolmogorov (pp. 188–192). Springer Netherlands. 10.1007/978-94-011-2260-3_22