Your first fields

Before building an electronic structure calculation, it helps to try the field operations on a function whose behaviour you already know. A normalized Gaussian is particularly useful: both its integral and its electrostatic potential have independent analytical references, so a surprising result gives you something concrete to investigate. The short script below uses this function to connect sampling, volume integration, and a Poisson solve. It requires only the core package, NumPy, and SciPy.

 1"""A small check of sampling, volume integration, and isolated Poisson."""
 2import numpy as np
 3
 4from flodi import RadialGrid
 5
 6
 7def main():
 8    grid = RadialGrid.uniform(n_r=160, r_max=5.0)
 9    source = grid.sample(lambda c: np.exp(-c.r**2) / np.pi**1.5)
10    potential = grid.poisson(source)
11    residual = grid.laplacian(potential) + 4 * np.pi * source
12    residual_norm = np.sqrt(grid.integrate(residual.conj(), residual).real)
13
14    print(f"Source array shape: {source.values.shape}")
15    print(f"Integrated source: {grid.integrate(source):.8f}")
16    print(f"Potential at the outer face: {float(potential.boundary):.8f}")
17    print(f"Discrete residual norm: {residual_norm:.3e}")
18
19
20if __name__ == "__main__":
21    main()

Download first_fields.py and run it with python first_fields.py in the environment from Install and check the environment. Read main() first.

What each object means

The calculation begins with grid, which divides a finite spherical domain into shells and places a sample at the centre of each one. Sampling the Gaussian creates source, a field containing its density per physical volume at those centres. When you call grid.integrate(source), FLODI weights each value by the shell it represents, giving an approximation to the integral over the finite domain. The result should be close to one; its remaining difference reflects both quadrature error and the Gaussian tail outside the grid.

The Poisson solve turns this source into potential, another field on the same grid, satisfying \(-\nabla^2 V=4\pi s\) with a decaying exterior. For this Gaussian, the infinite-domain reference is \(\operatorname{erf}(r)/r\). Its slow decay explains why the potential has a nonzero value at the finite outer face even though it approaches zero at infinity; the boundary treatment must preserve that distinction.

Finally, the script substitutes the computed potential into the discrete Poisson equation and measures the residual. A small value relative to the terms in that equation shows that the linear solve has been carried out accurately, with its final digits affected by roundoff. To assess the spatial approximation as well, you need a separate comparison with the exact potential. The worked example in From a source to a potential develops that comparison and shows why it answers a different question.

Try one change at a time

Try increasing n_r while keeping r_max fixed, and observe how the integral changes as the shells become thinner. Then extend the domain while preserving the cell width to examine the effect of the omitted tail. Recording the settings beside each result will help you distinguish these two sources of error when you return to the comparison later.

Continue with Representations and normalization to establish representation and normalization conventions, or Functions, arrays, and fields to work with sampled functions and arrays.