conv_meshcutoff.lua
local cutoff_start = 150.
local cutoff_end = 650.
local cutoff_step = 50.
local flos = require "flos"
local cutoff = flos.Array.range(cutoff_start, cutoff_end, cutoff_step)
local Etot = flos.Array.zeros(#cutoff)
local icutoff = 1
function siesta_comm()
if siesta.state == siesta.INITIALIZE then
siesta.receive({"Mesh.Cutoff.Minimum"})
siesta.Mesh.Cutoff.Minimum = cutoff[icutoff]
IOprint( ("\nLUA: starting mesh-cutoff: %8.3f Ry\n"):format(cutoff[icutoff]) )
siesta.send({"Mesh.Cutoff.Minimum"})
end
if siesta.state == siesta.INIT_MD then
siesta.receive({"Mesh.Cutoff.Used"})
cutoff[icutoff] = siesta.Mesh.Cutoff.Used
end
if siesta.state == siesta.MOVE then
siesta.receive({"E.total",
"MD.Relaxed"})
Etot[icutoff] = siesta.E.total
if step_cutoff(cutoff[icutoff]) then
siesta.Mesh.Cutoff.Minimum = cutoff[icutoff]
else
siesta.MD.Relaxed = true
end
siesta.send({"Mesh.Cutoff.Minimum", "MD.Relaxed"})
end
if siesta.state == siesta.ANALYSIS then
local file = io.open("meshcutoff_E.dat", "w")
file:write("# Mesh-cutoff vs. energy\n")
file:write( ("%8.3e %17.10e %17.10e\n"):format(cutoff[1], 0., Etot[1]) )
for i = 2, #cutoff do
file:write( ("%8.3e %17.10e %17.10e\n"):format(cutoff[i], Etot[i]-Etot[i-1], Etot[i]) )
end
file:close()
end
end
function step_cutoff(cur_cutoff)
if icutoff < #cutoff then
icutoff = icutoff + 1
else
return false
end
if cutoff[icutoff] <= cur_cutoff then
cutoff[icutoff] = cutoff[icutoff-1]
Etot[icutoff] = Etot[icutoff-1]
return step_cutoff(cur_cutoff)
end
return true
end