-
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.
Merge pull request #3 from HPMolSim/Taylor
added cheb interp for U_series
- Loading branch information
Showing
11 changed files
with
139 additions
and
18 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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function USeries_direct(z::T, k_xi::T, k_yj::T, uspara::USeriesPara{T}, M_mid::Int) where{T} | ||
t = zero(T) | ||
k2 = k_xi^2 + k_yj^2 | ||
|
||
for l in M_mid + 1:length(uspara.sw) | ||
sl, wl = uspara.sw[l] | ||
t += π * wl * exp(-sl^2 * k2 / 4) * exp(-z^2 / sl^2) * (T(2) - T(4) * z^2 / sl^2 + k2 * sl^2) | ||
end | ||
|
||
return t | ||
end | ||
|
||
function ChebUSeries_k(k_xi::T, k_yj::T, L_z::T, uspara::USeriesPara{T}, M::Int, Q::Int) where{T} | ||
|
||
f = z -> USeries_direct(z, k_xi, k_yj, uspara, M) | ||
x = chebpoints(Q, zero(T), L_z) | ||
|
||
return chebinterp(f.(x), zero(T), L_z) | ||
end | ||
|
||
function ChebUSeries(k_x::Vector{T}, k_y::Vector{T}, L_z::T, uspara::USeriesPara{T}, M::Int, Q::Int) where{T} | ||
|
||
cheb_mat = Array{ChebPoly{1, T, T}, 2}(undef, (length(k_x), length(k_y))) | ||
|
||
for i in 1:length(k_x) | ||
for j in 1:length(k_y) | ||
cheb_mat[i, j] = ChebUSeries_k(k_x[i], k_y[j], L_z, uspara, M, Q) | ||
end | ||
end | ||
|
||
return cheb_mat | ||
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,4 +1,5 @@ | ||
[deps] | ||
EwaldSummations = "329efeb5-5dc7-45f3-8303-d0bcfeef1c8a" | ||
ExTinyMD = "fec76197-d59f-46dd-a0ed-76a83c21f7aa" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
TaylorSeries = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@testset "Cheb expansion of U_series" begin | ||
@info "testing the Cheb expansion" | ||
k_xi = 0.1 | ||
k_yj = 0.2 | ||
L_z = 10.0 | ||
z = [0.01:0.01:L_z...] | ||
f_cheb = FastSpecSoG.ChebUSeries_k(k_xi, k_yj, L_z, USeriesPara(2), 3, 16) | ||
direct_U = map(x -> FastSpecSoG.USeries_direct(x, k_xi, k_yj, USeriesPara(2), 3), z) | ||
@test isapprox(f_cheb.(z), direct_U) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
@testset "interpolate on non-uniform grid" begin | ||
@info "testing the interpolation on non-uniform grid" | ||
n_atoms = 8 | ||
L = (100.0, 100.0, 100.0) | ||
|
||
qs = rand(n_atoms) | ||
qs .-= sum(qs) ./ n_atoms | ||
poses = [tuple(L .* rand(3)...) for i in 1:n_atoms] | ||
|
||
# using the 3DFFT | ||
# using the FFCT | ||
N_grid = (16, 16, 16) | ||
uspara = USeriesPara(2) | ||
Q = 64 | ||
soepara = SoePara16() | ||
for M_mid in 0:length(uspara.sw) - 1 | ||
|
||
for M_mid in 2:length(uspara.sw) - 1 | ||
@testset "M_mid = $M_mid" begin | ||
k_x, k_y, k_mat, r_z, us_mat, H_r, H_c, H_s, ivsm, b_l, b_u, phase_x, phase_y, phase_xs, phase_ys, phase_xys, rhs, sol, sort_z, z, size_dict, temp_ijlk, temp_ijl, z_coef, exp_coef = FFCT_precompute(L, N_grid, USeriesPara(2), M_mid, n_atoms) | ||
|
||
cheb_mat = ChebUSeries(k_x, k_y, L[3], uspara, M_mid, Q) | ||
|
||
H_r_einsum = copy(interpolate_nu_einsum!(copy(H_r), qs, poses, L, k_x, k_y, k_mat, phase_xs, phase_ys, phase_xys, z_coef, exp_coef, temp_ijlk, temp_ijl, r_z, us_mat, uspara, M_mid, size_dict)) | ||
|
||
H_r_einsum_direct = copy(interpolate_nu_einsum_non_inplace!(copy(H_r), qs, poses, L, k_x, k_y, k_mat, phase_xs, phase_ys, phase_xys, z_coef, exp_coef, r_z, us_mat, uspara, M_mid)) | ||
H_r_einsum_direct = copy(FastSpecSoG.interpolate_nu_einsum_non_inplace!(copy(H_r), qs, poses, L, k_x, k_y, k_mat, phase_xs, phase_ys, phase_xys, z_coef, exp_coef, r_z, us_mat, uspara, M_mid)) | ||
|
||
H_r_loop = copy(interpolate_nu_loop!(copy(H_r), qs, poses, N_grid, L, k_x, k_y, phase_x, phase_y, r_z, us_mat, uspara, M_mid)) | ||
|
||
H_r_cheb = copy(interpolate_nu_cheb!(copy(H_r), qs, poses, L, k_x, k_y, phase_x, phase_y, r_z, cheb_mat)) | ||
|
||
@test H_r_einsum ≈ H_r_einsum_direct | ||
@test H_r_einsum_direct ≈ H_r_loop | ||
@test H_r_einsum ≈ H_r_loop | ||
@test isapprox(H_r_einsum, H_r_cheb; atol=1e-8) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
using FastSpecSoG | ||
using Test | ||
using ExTinyMD, EwaldSummations | ||
using ExTinyMD, EwaldSummations, TaylorSeries | ||
|
||
@testset "FastSpecSoG.jl" begin | ||
include("U_series.jl") | ||
# include("energy_naive.jl") | ||
include("energy_mid.jl") | ||
include("interpolate_nu.jl") | ||
include("energy_long.jl") | ||
include("cheb_interpolate.jl") | ||
end |