-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d93fe4
commit 9b8a706
Showing
5 changed files
with
90 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,61 @@ | ||
function zeroth_order(q::Vector{T}, z::Vector{T}, soepara::SoePara{Complex{T}}, uspara::USeriesPara{T}, sort_z::Vector{Int}, L::NTuple{3, T}, M_mid::Int) where{T} | ||
L_x, L_y, L_z = L | ||
function FGT1d(qs::Vector{T}, poses::Vector{NTuple{3, T}}, s::T, L_z::T, Q_0::Int) where{T} | ||
n_atoms = length(qs) | ||
grids = zeros(T, Q_0) | ||
r_z = [L_z / 2 * ( 1.0 - cos((2i - 1)*π / (2 * Q_0)) ) for i in 1:Q_0] | ||
|
||
E_k0 = zero(Complex{T}) | ||
for l in M_mid + 1:length(uspara.sw) | ||
sl, wl = uspara.sw[l] | ||
E_k0 += wl * sl^2 * FET1d(q, q, z, soepara, α = sl, sort_x = sort_z) | ||
for i in 1:n_atoms | ||
q = qs[i] | ||
for j in 1:Q_0 | ||
z = poses[i][3] | ||
grids[j] += q * exp(- (z - r_z[j])^2 / s^2) | ||
end | ||
end | ||
|
||
chebcoefs = zeros(T, Q_0) | ||
|
||
for k in 1:Q_0, l in 1:Q_0 | ||
cheb_temp = k == 1 ? 0.5 : chebpoly(k - 1, r_z[l] - L_z / T(2), L_z / T(2)) | ||
chebcoefs[k] += 2 / Q_0 * grids[l] * cheb_temp | ||
end | ||
|
||
E_k0 = zero(T) | ||
for i in 1:n_atoms | ||
q = qs[i] | ||
z = poses[i][3] | ||
for k in 1:Q_0 | ||
E_k0 += q * chebcoefs[k] * chebpoly(k - 1, z - L_z / T(2), L_z / T(2)) | ||
end | ||
end | ||
|
||
return real(π * E_k0 / (2 * L_x * L_y)) | ||
return E_k0 | ||
end | ||
|
||
function revise_z!(z::Vector{T}, sort_z::Vector{Int}, poses::Vector{NTuple{3, T}}) where{T} | ||
for i in 1:length(poses) | ||
z[i] = poses[i][3] | ||
function FGT1d_naive(qs::Vector{T}, poses::Vector{NTuple{3, T}}, s::T) where{T} | ||
n_atoms = length(qs) | ||
E_k0 = zero(T) | ||
|
||
for i in 1:n_atoms, j in 1:n_atoms | ||
qi = qs[i] | ||
xi, yi, zi = poses[i] | ||
qj = qs[j] | ||
xj, yj, zj = poses[j] | ||
E_k0 += qi * qj * exp( - (zi - zj)^2 / s^2) | ||
end | ||
sortperm!(sort_z, z) | ||
return z | ||
|
||
return E_k0 | ||
end | ||
|
||
SoePara4() = SoePara{ComplexF64}([ | ||
(2.48631398597651 - 0.897378323045937im, 0.826249456689224 - 1.78131068518845im), | ||
(2.48631398597651 + 0.897378323045937im, 0.826249456689224 + 1.78131068518845im), | ||
(2.40315018095227 - 2.83616068448077im, -0.326515398594273 + 0.111936582560313im), | ||
(2.40315018095227 + 2.83616068448077im, -0.326515398594273 - 0.111936582560313im) | ||
]) | ||
|
||
SoePara8() = SoePara{ComplexF64}([ | ||
(3.33815646978136 + 5.05854898587389im, -0.00886007694548523 + 0.0113042091292579im), | ||
(3.33815646978136 - 5.05854898587389im, -0.00886007694548516 - 0.011304209129258im), | ||
(3.53279071224249 + 0.653112650324427im, 2.97739506379945 + 6.91132455163189im), | ||
(3.53279071224249 - 0.653112650324427im, 2.97739506379944 - 6.9113245516319im), | ||
(3.50499106490061 + 1.98468086946842im, -2.89181556737244 - 1.11452178676621im), | ||
(3.50499106490061 - 1.98468086946842im, -2.89181556737244 + 1.11452178676621im), | ||
(3.44496629848779 + 3.40626818209147im, 0.423280530725485 - 0.16080466274867im), | ||
(3.44496629848779 - 3.40626818209147im, 0.423280530725485 + 0.160804662748669im) | ||
]) | ||
|
||
# the default 16 terms approach | ||
SoePara16() = SoePara{ComplexF64}([ | ||
(4.56160429581067 + 8.10664614462486im, 5.99673832958228e-6 - 1.68666706190233e-6im), | ||
(4.56160429581067 - 8.10664614462486im, 5.99673832964075e-6 + 1.68666706179742e-6im), | ||
(4.67614751620509 + 6.66817205403247im, -0.00128256763349392 + 5.69515998682304e-5im), | ||
(4.67614751620509 - 6.66817205403247im, -0.00128256763349477 - 5.695159986638e-5im), | ||
(4.75706771210077 + 5.46277771275372im, 0.0467989716657016 + 0.024842808276986im), | ||
(4.75706771210077 - 5.46277771275372im, 0.0467989716657026 - 0.0248428082770166im), | ||
(4.81739468471801 + 4.37139574323745im, -0.335267028777594 - 0.757075111679156im), | ||
(4.81739468471801 - 4.37139574323745im, -0.335267028777571 + 0.757075111679353im), | ||
(4.86201933938979 + 3.34750236244862im, -1.99598682670183 + 5.9922116425601im), | ||
(4.86201933938979 - 3.34750236244862im, -1.99598682670221 - 5.99221164256101im), | ||
(4.89345823682377 + 2.3658861273834im, 23.9009795446709 - 12.0862363354612im), | ||
(4.89345823682377 - 2.3658861273834im, 23.9009795446732 + 12.0862363354632im), | ||
(4.91338156910332 + 1.41021110952036im, -64.0632116678656 - 22.5380203666186im), | ||
(4.91338156910332 - 1.41021110952036im, -64.0632116678705 + 22.5380203666172im), | ||
(4.92300187934591 + 0.468589313154398im, 42.9479635779022 + 98.1965284307393im), | ||
(4.92300187934591 - 0.468589313154398im, 42.9479635779079 - 98.1965284307392im), | ||
(0.0334524767879181 + 0.0245907245253121im, 2.77886417555933e-16 - 1.05052462423441e-16im), | ||
(0.0334524767879181 - 0.0245907245253121im, 2.77886412307273e-16 + 1.0505268058843e-16im) | ||
]) | ||
|
||
function zeroth_order(qs::Vector{T}, poses::Vector{NTuple{3, T}}, L::NTuple{3, T}, uspara::USeriesPara{T}, Q_0::Int) where{T} | ||
|
||
L_x, L_y, L_z = L | ||
|
||
E_k0 = zero(T) | ||
|
||
for l in M_mid + 1:length(uspara.sw) | ||
sl, wl = uspara.sw[l] | ||
E_k0 += wl * sl^2 * FGT1d(qs, poses, sl, L_z, Q_0) | ||
end | ||
|
||
return π * E_k0 / (2 * L_x * L_y) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
@testset "zeroth_order by SOE" begin | ||
|
||
n_atoms = 100 | ||
@testset "FGT1d by chebshev" begin | ||
n_atoms = 256 | ||
L = 20.0 | ||
poses = [ (rand() * L, rand() * L, rand() * L) for i in 1:n_atoms ] | ||
qs = [ (-1.0)^i for i in 1:n_atoms ] | ||
z = [ poses[i][3] for i in 1:n_atoms ] | ||
sort_z = sortperm(z) | ||
soepara = SoePara16() | ||
Q0 = 64 | ||
|
||
for preset in 1:6 | ||
uspara = USeriesPara(preset) | ||
M_mid = 0 | ||
qs = [(-1.0)^i for i in 1:n_atoms] | ||
poses = [(rand() * L, rand() * L, rand() * L) for i in 1:n_atoms] | ||
|
||
E0_soe = zeroth_order(qs, z, soepara, uspara, sort_z, (L, L, L), M_mid) | ||
E0_direct = long_energy_us_0(qs, poses, (L, L, L), uspara, 1, length(uspara.sw)) | ||
uspara = USeriesPara(6) | ||
|
||
@show E0_soe, E0_direct, abs(E0_soe - E0_direct) | ||
# @test abs(E0_soe - E0_direct) < 1e-14 | ||
for l in 10:length(uspara.sw) | ||
s, w = uspara.sw[l] | ||
E_FGT = FGT1d(qs, poses, s, L, Q0) | ||
E_naive = FGT1d_naive(qs, poses, s) | ||
# @show l, E_FGT, E_naive, E_FGT - E_naive | ||
@test E_FGT ≈ E_naive | ||
end | ||
end |