This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org
Viv Python

Notebooks · lib/scf/mix

Mixing densities in a self-consistent field

mix_densities(x_in, x_out, hist) is a contract: the density the next pass of a self-consistent field starts from, made from the density the pass started with (x_in), the one it produced (x_out) and the earlier pairs in hist. The densities are one flat array; a solver packs whatever it mixes (lib/skyrme packs rho, tau and J of both kinds).

  • linear: (1 - alpha) x_in + alpha x_out. No history.
  • pulay: Pulay's direct inversion in the iterative subspace (P. Pulay, Chem. Phys. Lett. 73, 393 (1980)), applied to densities: the combination of the last history inputs whose residuals (output minus input) combine to the shortest residual, with the coefficients summing to one, then a linear step of alpha along that residual.
  • broyden: Johnson's modified Broyden method (D. D. Johnson, Phys. Rev. B 38, 12807 (1988)) with every weight 1 and w0 = BROYDEN_W0. It works on differences of consecutive pairs; with w0 = 0 its step equals Pulay's (V. Eyert, J. Comput. Phys. 124, 271 (1996)), so w0 is what makes it a different method here.

Two mixers given the same pair return different next densities on purpose; they agree only at the fixed point. The contract's agree line compares residual, the largest |x_out - x_in|, which every method computes from the same two arrays; the converged energies and densities of the three are compared in the tests of lib/skyrme/spherical.viv.

Used with from scf.mix import mix_densities, mix_start.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

This program declares a record type (MixHistory), and records run only in compiled C for now, so the Run buttons here are off. Open it in the workbench and use its C tab to compile it.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 32–233