Split of the code in src

This commit is contained in:
Fernando P. Panadero 2024-02-21 17:05:34 +01:00
commit 3cb578d033
4 changed files with 459 additions and 349 deletions

160
src/io.jl Normal file
View file

@ -0,0 +1,160 @@
using LatticeGPU
using TOML
using TimerOutputs
using ArgParse
using CUDA
"""
function read_input()
Stores as global variables 'parsed_args' (info from the command line) and 'params' (info from the input file)
"""
function read_input()
global parsed_args = parse_commandline()
println("--------------------------------------------------")
println("Reading input file from:", parsed_args["i"], "...")
global params = TOML.parsefile(parsed_args["i"])
return nothing
end
function parse_commandline()
s = ArgParseSettings()
@add_arg_table s begin
"-i"
help = "Input parameters file"
required = true
arg_type = String
"-c"
help = "Gauge configuration file"
required = true
arg_type = String
"--cern"
help = "Config written with the export_cnfg_cern() convention"
action = :store_true
end
return parse_args(s)
end
"""
function load_gauge_field()
Returns the gauge field and computes the Csw term
"""
function load_gauge_field()
println("Reading gauge field from: ", parsed_args["c"], "...")
if !parsed_args["cern"]
U,_ = read_cnfg(parsed_args["c"])
else
U = read_cnfg_cern(parsed_args["c"],lp)
end
Csw!(dws, U, gp, lp)
return U
end
function read_cnfg_cern(path::String,lp::SpaceParm)
U = vector_field(SU3{Float64}, lp);
file = open(path)
for t in 1:lp.iL[4]
for i in 1:lp.iL[1]
for j in 1:lp.iL[2]
for k in 1:lp.iL[3]
for d in [4,1,2,3]
f,r = point_index(CartesianIndex((i,j,k,t)),lp)
#a11 !!
re11 = read(file,Float64)
co11 = read(file,Float64)
#a12 !!
re12 = read(file,Float64)
co12 = read(file,Float64)
#a13 !!
re13 = read(file,Float64)
co13 = read(file,Float64)
#a21 !!
re21 = read(file,Float64)
co21 = read(file,Float64)
#a22 !!
re22 = read(file,Float64)
co22 = read(file,Float64)
#a23 !!
re23 = read(file,Float64)
co23 = read(file,Float64)
#a31
re31 = read(file,Float64)
co31 = read(file,Float64)
#a32
re32 = read(file,Float64)
co32 = read(file,Float64)
#a33
re33 = read(file,Float64)
co33 = read(file,Float64)
CUDA.@allowscalar (U[f,d,r] = SU3{Float64}(re11 + im*co11, re12 + im*co12, re13 + im*co13,
re21 + im*co21, re22 + im*co22, re23 + im*co23))
end
end
end
end
end
length(read(file)) == (prod(lp.iL[1:3])*4*8*9*2) ? nothing : error("File not fully read")
close(file)
return U
end
"""
function load_structs()
Stores in global variables the needed structures, i.e. lp, gp, dpar, dws, ymws
"""
function load_structs()
global lp = SpaceParm{4}(tuple(params["Space"]["size"]...), tuple(params["Space"]["blocks"]...),BC_SF_ORBI, (0,0,0,0,0,0))
global gp = GaugeParm{Float64}(SU3{Float64},params["Fermion"]["beta"],1.0,(params["Space"]["cG"],0.0),params["Space"]["phiT"],lp.iL);
global dpar = DiracParam{Float64}(SU3fund,(1/(2*params["Fermion"]["kappa"])) - 4,params["Fermion"]["csw"],ntuple(i -> exp((i!=4)*im*params["Fermion"]["theta"]/lp.iL[i]),4),0.0,params["Fermion"]["ct"]);
global dws = DiracWorkspace(SU3fund,Float64,lp);
global ymws = YMworkspace(SU3,Float64,lp);
println("Parameters:")
println("Lattice size: ", lp.iL)
println("Phi0 = ", params["Space"]["phi0"])
println("PhiT = ", params["Space"]["phiT"])
println("cG = ", gp.cG[1])
println("kappa = ", params["Fermion"]["kappa"])
println("theta = ", params["Fermion"]["theta"])
println("csw = ", dpar.csw)
println("ct = ", dpar.ct)
println("tolerance = ", params["Solver"]["tolerance"])
println("maxiter = ", params["Solver"]["maxiter"])
return nothing
end