ensured that Lua code always uses the correct units
This is now done by directly referencing the units variables in a table, and passing them to Lua from siesta as though the user requested it. Tested on the test for simple-lua. Added some of the missing variables as well. Signed-off-by: Nick Papior <nickpapior@gmail.com>
This commit is contained in:
parent
825915bf0d
commit
762960c2b9
|
@ -3,6 +3,7 @@ module flook_siesta
|
|||
#ifdef SIESTA__FLOOK
|
||||
use flook
|
||||
|
||||
use units
|
||||
use siesta_options
|
||||
use siesta_geom
|
||||
use parallel, only : IONode, Node, Nodes
|
||||
|
@ -50,14 +51,17 @@ contains
|
|||
|
||||
use fdf, only : fdf_get
|
||||
use m_os, only : file_exist
|
||||
use dictionary
|
||||
|
||||
type(luaState), intent(inout) :: LUA
|
||||
type(luaTbl) :: tbl
|
||||
logical, intent(in) :: md_lua
|
||||
|
||||
character(len=30) :: fortran_msg
|
||||
|
||||
character(*), parameter :: fortran_static_lua = '&
|
||||
siesta = { &
|
||||
Units = {}, &
|
||||
Node = 0, &
|
||||
Nodes = 1, &
|
||||
INITIALIZE = 1, &
|
||||
|
@ -83,33 +87,10 @@ IOprint = function(...) &
|
|||
end &
|
||||
siesta_comm = function(...) end'
|
||||
|
||||
#ifdef SIESTA__UNITS_ORIGINAL
|
||||
character(*), parameter :: unit_static_lua = '&
|
||||
siesta.Units = { &
|
||||
Ang = 1. / 0.529177, &
|
||||
eV = 1. / 13.60580, &
|
||||
kBar = 1. / 1.47108e5, &
|
||||
Debye = 0.393430, &
|
||||
amu = 2.133107, &
|
||||
} &
|
||||
siesta.Units.GPa = siesta.Units.kBar * 10 &
|
||||
siesta.Units.Kelvin = siesta.Units.eV / 11604.45'
|
||||
#else
|
||||
character(*), parameter :: unit_static_lua = '&
|
||||
siesta.Units = { &
|
||||
Ang = 1.88972612462577017, &
|
||||
eV = 7.34986443513115789e-2, &
|
||||
kBar = 6.79786184348648780e-6, &
|
||||
Debye = 3.93430269519899511e-1, &
|
||||
amu = 2.133107, &
|
||||
Kelvin = 6.33362312691136091e-6, &
|
||||
} &
|
||||
siesta.Units.GPa = siesta.Units.kBar * 10'
|
||||
#endif
|
||||
|
||||
! For error-handling with lua
|
||||
integer :: err
|
||||
character(len=2048) :: err_msg
|
||||
type(dictionary_t) :: units_dict
|
||||
|
||||
! Whether the interactive lua stuff should be runned
|
||||
slua_interactive = fdf_get('LUA.Interactive', .false.)
|
||||
|
@ -174,8 +155,34 @@ siesta.Units.GPa = siesta.Units.kBar * 10'
|
|||
|
||||
! Create LUA table for data container
|
||||
call lua_run(LUA, code = fortran_static_lua )
|
||||
! Append the unit table for SIESTA unit conversion
|
||||
call lua_run(LUA, code = unit_static_lua )
|
||||
|
||||
! create the unit table
|
||||
units_dict = units_dict // &
|
||||
('Units.eV'.kv.eV)
|
||||
units_dict = units_dict // &
|
||||
('Units.Ang'.kv.Ang)
|
||||
units_dict = units_dict // &
|
||||
('Units.kBar'.kv.kBar)
|
||||
units_dict = units_dict // &
|
||||
('Units.Debye'.kv.Debye)
|
||||
units_dict = units_dict // &
|
||||
('Units.amu'.kv.amu)
|
||||
units_dict = units_dict // &
|
||||
('Units.Kelvin'.kv.Kelvin)
|
||||
units_dict = units_dict // &
|
||||
('Units.GPa'.kv.GPa)
|
||||
units_dict = units_dict // &
|
||||
('Units.Pi'.kv.Pi)
|
||||
units_dict = units_dict // &
|
||||
('Units.Joule'.kv.Joule)
|
||||
units_dict = units_dict // &
|
||||
('Units.hbar'.kv.hbar)
|
||||
|
||||
! open global siesta table
|
||||
tbl = lua_table(LUA, 'siesta')
|
||||
call slua_put_dict(tbl, units_dict, units_dict)
|
||||
call lua_close_tree(tbl)
|
||||
call delete(units_dict)
|
||||
|
||||
! Register siesta calls to communicate to the lua layer
|
||||
! Old names for backwards compatibility
|
||||
|
|
Loading…
Reference in New Issue