Reorganize dependency structure

This commit is contained in:
Nuwan Yapa 2025-02-21 10:55:11 -05:00
parent 0c748534c8
commit f1553f548f
12 changed files with 74 additions and 76 deletions

56
NuclearRMF.jl Normal file
View File

@ -0,0 +1,56 @@
using PolyLog, Plots
include("nucleons.jl")
include("mesons.jl")
"Total binding energy of the system"
total_E(s::system, Es_p, occs_p, Es_n, occs_n) = sum(occs_p .* (M_p .- Es_p)) + sum(occs_n .* (M_n .- Es_n)) - meson_E(s)
"Normalized Woods-Saxon form used for constructing an initial solution"
Woods_Saxon(r::Float64; R::Float64=7.0, a::Float64=0.5) = -1 / (8π * a^3 * reli3(-exp(R / a)) * (1 + exp((r - R) / a)))
"Run the full program by self-consistent solution of nucleon and meson densities"
function solve_system(s::system; reinitialize_densities=true, monitor_print=true, monitor_plot=false)
if reinitialize_densities
dens_guess = Woods_Saxon.(rs(s))
@. s.ρ_sp = s.Z * dens_guess
@. s.ρ_vp = s.Z * dens_guess
@. s.ρ_sn = s.N * dens_guess
@. s.ρ_vn = s.N * dens_guess
end
if monitor_plot
p = plot(legends=false, size=(1024, 768), layout=(2, 4), title=["ρₛₚ" "ρᵥₚ" "ρₛₙ" "ρᵥₙ" "Φ₀" "W₀" "B₀" "A₀"])
end
previous_E_per_A = NaN
while true
# mesons
@time "Meson fields" solveMesonFields!(s, isnan(previous_E_per_A) ? 50 : 15)
# protons
@time "Proton spectrum" (κs_p, Es_p) = findAllOrbitals(true, s)
occs_p = fillNucleons(s.Z, κs_p, Es_p)
@time "Proton densities" (s.ρ_sp, s.ρ_vp) = calculateNucleonDensity(κs_p, Es_p, occs_p, true, s)
# neutrons
@time "Neutron spectrum" (κs_n, Es_n) = findAllOrbitals(false, s)
occs_n = fillNucleons(s.N, κs_n, Es_n)
@time "Neutron densities" (s.ρ_sn, s.ρ_vn) = calculateNucleonDensity(κs_n, Es_n, occs_n, false, s)
if monitor_plot
for s in p.series_list
s.plotattributes[:linecolor] = :gray
end
plot!(p, rs(s), hcat(s.ρ_sp, s.ρ_vp, s.ρ_sn, s.ρ_vn, s.Φ0, s.W0, s.B0, s.A0), linecolor=:red)
display(p)
end
E_per_A = total_E(s, Es_p, occs_p, Es_n, occs_n) / A(s)
monitor_print && println("Total binding E per nucleon = $E_per_A")
# check convergence
abs(previous_E_per_A - E_per_A) < 0.0001 && break
previous_E_per_A = E_per_A
end
end

2
common.jl Normal file
View File

@ -0,0 +1,2 @@
const ħc = 197.33 # MeVfm
const r_reg = 1E-8 # fm # regulator for R

View File

@ -1,6 +1,5 @@
using DifferentialEquations
const ħc = 197.33 # MeVfm
include("common.jl")
include("system.jl")
# Values defined in C. J. Horowitz and J. Piekarewicz, Phys. Rev. Lett. 86, 5647 (2001)
# Values taken from Hartree.f (FSUGarnet)
@ -17,8 +16,6 @@ const λ = -0.003551486718 # dimensionless # LambdaSS
const ζ = 0.023499504053 # dimensionless # LambdaVV
const Λv = 0.043376933644 # dimensionless # LambdaVR
const r_reg = 1E-8 # fm # regulator for Green's functions
"Green's function for Klein-Gordon equation in natural units"
greensFunctionKG(m, r, rp) = -1 / (m * (r + r_reg) * (rp + r_reg)) * sinh(m * min(r, rp)) * exp(-m * max(r, rp))

View File

@ -1,12 +1,11 @@
using DifferentialEquations
include("bisection.jl")
include("common.jl")
include("system.jl")
const ħc = 197.33 # MeVfm
const M_n = 939.0 # MeV/c2
const M_p = 939.0 # MeV/c2
const r_reg = 1E-8 # fm # regulator for the centrifugal term
"The spherical Dirac equation that returns du=[dg, df] in-place where
u=[g, f] are the reduced radial components evaluated at r,
κ is the generalized angular momentum,

View File

@ -1,4 +1,4 @@
using Interpolations, PolyLog, Plots
using Interpolations
"Defines a nuclear system containing relevant parameters and meson/nucleon densities"
mutable struct system
@ -40,9 +40,6 @@ Z_or_N(s::system, p::Bool)::Int = p ? s.Z : s.N
"Create an empty array for the size of the mesh"
zero_array(s::system) = zeros(1 + s.divs)
"Normalized Woods-Saxon form used for constructing an initial solution"
Woods_Saxon(r::Float64; R::Float64=7.0, a::Float64=0.5) = -1 / (8π * a^3 * reli3(-exp(R / a)) * (1 + exp((r - R) / a)))
"Create linear interpolations for the meson fields"
function fields_interp(s::system)
S_interp = linear_interpolation(rs(s), s.Φ0)
@ -51,56 +48,3 @@ function fields_interp(s::system)
A_interp = linear_interpolation(rs(s), s.A0)
return (S_interp, V_interp, R_interp, A_interp)
end
include("nucleons.jl")
include("mesons.jl")
"Run the full program by self-consistent solution of nucleon and meson densities"
function solve_system(s::system; reinitialize_densities=true, monitor_print=true, monitor_plot=false)
if reinitialize_densities
dens_guess = Woods_Saxon.(rs(s))
@. s.ρ_sp = s.Z * dens_guess
@. s.ρ_vp = s.Z * dens_guess
@. s.ρ_sn = s.N * dens_guess
@. s.ρ_vn = s.N * dens_guess
end
if monitor_plot
p = plot(legends=false, size=(1024, 768), layout=(2, 4), title=["ρₛₚ" "ρᵥₚ" "ρₛₙ" "ρᵥₙ" "Φ₀" "W₀" "B₀" "A₀"])
end
previous_E_per_A = NaN
while true
# mesons
@time "Meson fields" solveMesonFields!(s, isnan(previous_E_per_A) ? 50 : 15)
# protons
@time "Proton spectrum" (κs_p, Es_p) = findAllOrbitals(true, s)
occs_p = fillNucleons(s.Z, κs_p, Es_p)
@time "Proton densities" (s.ρ_sp, s.ρ_vp) = calculateNucleonDensity(κs_p, Es_p, occs_p, true, s)
# neutrons
@time "Neutron spectrum" (κs_n, Es_n) = findAllOrbitals(false, s)
occs_n = fillNucleons(s.N, κs_n, Es_n)
@time "Neutron densities" (s.ρ_sn, s.ρ_vn) = calculateNucleonDensity(κs_n, Es_n, occs_n, false, s)
if monitor_plot
for s in p.series_list
s.plotattributes[:linecolor] = :gray
end
plot!(p, rs(s), hcat(s.ρ_sp, s.ρ_vp, s.ρ_sn, s.ρ_vn, s.Φ0, s.W0, s.B0, s.A0), linecolor=:red)
display(p)
end
E_per_A = total_E(s, Es_p, occs_p, Es_n, occs_n) / A(s)
monitor_print && println("Total binding E per nucleon = $E_per_A")
# check convergence
abs(previous_E_per_A - E_per_A) < 0.0001 && break
previous_E_per_A = E_per_A
end
end
"Total binding energy of the system"
total_E(s::system, Es_p, occs_p, Es_n, occs_n) = sum(occs_p .* (M_p .- Es_p)) + sum(occs_n .* (M_n .- Es_n)) - meson_E(s)

View File

@ -1,5 +1,5 @@
using DelimitedFiles, Interpolations, Plots
include("../system.jl")
using DelimitedFiles, Plots
include("../nucleons.jl")
# test data generated from Hartree.f
# format: x S(x) V(x) R(x) A(x)

View File

@ -1,4 +1,4 @@
include("../system.jl")
include("../NuclearRMF.jl")
s = system(82, 126, 20.0, 400)

View File

@ -1,5 +1,5 @@
using DelimitedFiles, Interpolations, Plots
include("../system.jl")
using DelimitedFiles, Plots
include("../mesons.jl")
# test data generated from Hartree.f
# format: x S(x) V(x) R(x) A(x)

View File

@ -1,5 +1,5 @@
using DelimitedFiles, Plots
include("../system.jl")
include("../nucleons.jl")
# test data generated from Hartree.f
# format: x S(x) V(x) R(x) A(x)

View File

@ -1,5 +1,5 @@
using DelimitedFiles, Interpolations, Plots
include("../system.jl")
using DelimitedFiles, Plots
include("../nucleons.jl")
# test data generated from Hartree.f
# format: x S(x) V(x) R(x) A(x)

View File

@ -1,5 +1,5 @@
using DelimitedFiles, Interpolations, Plots
include("../system.jl")
using DelimitedFiles, Plots
include("../nucleons.jl")
# test data generated from Hartree.f
# format: x S(x) V(x) R(x) A(x)

View File

@ -1,5 +1,5 @@
using DelimitedFiles, Plots
include("../system.jl")
include("../nucleons.jl")
# test data generated from Hartree.f
# format: x S(x) V(x) R(x) A(x)