Validation¶
The test-suite (pytest) checks the package at three levels.
Against the thesis code¶
The original scripts are kept unmodified in legacy/. tools/make_golden.py
runs them on small sc, bcc and fcc samples and stores their inputs and outputs in
tests/data/golden/. The tests then require that:
- the lattice positions, in the same order, match;
- the direction sets have the same size for every \(H^2 \le 300\), and the \(H^2\) chosen from a target diameter is the same;
- with the same directions and phases, every backend reproduces the legacy field (to float32 precision) and the same solid/pore classification, atom by atom;
- \(\xi\), \(q_0\), \(L\), the curvatures and the genus written by the legacy log are reproduced (the surface density is the exception: see Changes).
A separate test reruns the legacy script and compares it bit for bit with the stored fixtures.
Against Soyarslan et al. (2018)¶
- Table 1 of the paper (\(\xi\), \(S\tilde{L}\), \(S_B\tilde{L}\), \(\langle\kappa_g\rangle\tilde{L}^2\), \(\langle\kappa_m\rangle\tilde{L}\) for \(\phi_B = 0.1, \dots, 0.9\)) is reproduced to all printed digits.
- Eq. 16 (scaled genus) is reproduced.
Against the field statistics¶
- Every backend agrees with the term-by-term formula to \(10^{-9}\), including cases with heavy aliasing in the FFT.
- The field is periodic with the requested period.
- Over realisations, \(f(\mathbf{x})\) has mean 0 and variance 1; the spatial autocorrelation equals the power spectrum exactly, and its orientational average is \(\sin(q_0 r)/(q_0 r)\).
- The measured solid fraction averages to \(\phi_B\).
- The interface area measured by marching cubes
(
nanofoams.measure.measure) matches \(S\) within ~1 % on average.
Measuring a foam yourself¶
import nanofoams
from nanofoams.measure import measure
params = nanofoams.FoamParameters("sc", 1.0, 96, 0.3, h2=54, seed=0)
field = nanofoams.GaussianRandomField.from_parameters(params)
m = measure(field, params.xi, resolution=96) # needs nanofoams[analysis]
m.surface_density, nanofoams.predict(params).surface_density