-
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
ffd5b5c
commit 5b68c50
Showing
7 changed files
with
137 additions
and
7 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,61 @@ | ||
function gather_single(q::T, pos::NTuple{N, T}, gridinfo::GridInfo{N, T}, gridbox::GridBox{N, T}, chebcoefs::NTuple{N, ChebCoef{T}}) where{N, T} | ||
|
||
potential_i = zero(T) | ||
|
||
cheb_value = gridbox.cheb_value | ||
near_id_image = image_grid_id(pos, gridinfo) | ||
near_pos_image = image_grid_pos(near_id_image, gridinfo) | ||
for i in 1:N | ||
dx = pos[i] - near_pos_image[i] | ||
pwcheb_eval!(dx, cheb_value[i], chebcoefs[i]) | ||
end | ||
|
||
for id in Iterators.product([- gridinfo.w[i] : gridinfo.w[i] for i in 1:N]...) | ||
potential_i += real(gridbox.image_grid[(near_id_image.id .+ id)...]) * prod(cheb_value[i][id[i] + gridinfo.w[i] + 1] for i in 1:N) | ||
end | ||
|
||
return q * 4π * prod(gridinfo.h) * potential_i | ||
end | ||
|
||
function gather(qs::Vector{T}, poses::Vector{NTuple{N, T}}, gridinfo::GridInfo{N, T}, gridbox::GridBox{N, T}, chebcoefs::NTuple{N, ChebCoef{T}}) where{N, T} | ||
|
||
@assert length(qs) == length(poses) | ||
|
||
potential = zero(T) | ||
for i in 1:length(qs) | ||
potential += gather_single(qs[i], poses[i], gridinfo, gridbox, chebcoefs) | ||
end | ||
|
||
return potential | ||
end | ||
|
||
function gather_single_direct(q::T, pos::NTuple{N, T}, gridinfo::GridInfo{N, T}, gridbox::GridBox{N, T}, chebcoefs::NTuple{N, ChebCoef{T}}) where{N, T} | ||
|
||
potential_i = zero(T) | ||
|
||
cheb_value = gridbox.cheb_value | ||
near_id_image = image_grid_id(pos, gridinfo) | ||
near_pos_image = image_grid_pos(near_id_image, gridinfo) | ||
for i in 1:N | ||
dx = pos[i] - near_pos_image[i] | ||
f_eval!(dx, cheb_value[i], chebcoefs[i]) | ||
end | ||
|
||
for id in Iterators.product([- gridinfo.w[i] : gridinfo.w[i] for i in 1:N]...) | ||
potential_i += real(gridbox.image_grid[(near_id_image.id .+ id)...]) * prod(cheb_value[i][id[i] + gridinfo.w[i] + 1] for i in 1:N) | ||
end | ||
|
||
return q * 4π * prod(gridinfo.h) * potential_i | ||
end | ||
|
||
function gather_direct(qs::Vector{T}, poses::Vector{NTuple{N, T}}, gridinfo::GridInfo{N, T}, gridbox::GridBox{N, T}, chebcoefs::NTuple{N, ChebCoef{T}}) where{N, T} | ||
|
||
@assert length(qs) == length(poses) | ||
|
||
potential = zero(T) | ||
for i in 1:length(qs) | ||
potential += gather_single_direct(qs[i], poses[i], gridinfo, gridbox, chebcoefs) | ||
end | ||
|
||
return potential | ||
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function ScalingFactor(f::Function, gridinfo::GridInfo{N, T}) where{N, T} | ||
factors = zeros(Complex{T}, gridinfo.N_pad...) | ||
|
||
for i in Iterators.product([1:gridinfo.N_pad[d] for d in 1:N]...) | ||
k = [gridinfo.k[d][i[d]] for d in 1:N] | ||
factors[i...] = Complex{T}(f(k...)) | ||
end | ||
|
||
return ScalingFactor{N, T}(f, factors) | ||
end | ||
|
||
function scale!(gridbox::GridBox{N, T}, scalingfactor::ScalingFactor{N, T}) where{N, T} | ||
|
||
gridbox.pad_grid .*= scalingfactor.factors | ||
|
||
return gridbox | ||
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