Cookbook

Having lua control a HANDE simulation allows for some pretty clean ways to run complicated simulations. Here we will list some examples.

Twist Averaging

To aid in the removal of single-particle finite size effects it is often helpful to perform twist averaging. Here we want to average results over multiple twist vectors \(\mathbf{k}_s\) where each component of \(\mathbf{k}_s\) can be chosen to lie within the simulation cell Brillouin zone. Normally we would need to run multiple independent simulations yielding many output files, which can be problematic for file systems. Lua allows us to run the calculations from a single input file.

In the example below we show this for a twist averaged canonical total energy calculation, which can be useful for correcting incomplete twist averaged QMC calculations which are typically much more expensive.

-- Function to generate a random twist.
function get_twist()
    ks = {}
    -- 3D UEG.
    for i = 0, 2 do
        -- For the UEG, we only need to generate a twist vectors whose components lie in
        -- the range [-pi/L, pi/L). In HANDE we interpret the input ks as being in terms
        -- of 2pi/L, so we need to randomly pick components in the range [-0.5, 0.5).
        sign = math.pow(-1, math.random(0, 1))
        ks[i] = 0.5*sign*math.random()
    end
    return ks
end

-- The number of simulations to average over.
ntwists = 3000
math.randomseed( os.time() )

for i = 1, ntwists do
    ks = get_twist()
    sys = ueg {
        nel = 19,
        ms = 19,
        dim = 3,
        cutoff = 20,
        rs = 0.5,
        twist = ks,
        verbose = false,
    }
    mc_state = canonical_estimates {
        sys = sys,
        canonical_estimates = {
            beta = 16,
            nattempts = 10000,
            ncycles = 10,
            fermi_temperature = true,
        },
    }
    sys:free() -- Free up memory.
end

The output file can then be analysed to obtain the canonical total energy estimate for each twist angle using

$ analyse_canonical.py --sim canonical_twist.out

where canonical_twist.out is the output filename.