Skip to content

Commit

Permalink
merge conflicts/fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rymanderson committed Jan 28, 2025
2 parents d21d242 + 3f573ee commit 5b83685
Show file tree
Hide file tree
Showing 38 changed files with 7,286 additions and 1,960 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ authors = ["Ryan Anderson <[email protected]> and contributors"]
version = "0.3.0"

[deps]
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"

[compat]
BSON = "0.3"
LegendrePolynomials = "0.4"
StaticArrays = "1"
WriteVTK = "1"
Expand Down
55 changes: 49 additions & 6 deletions scripts/test_local_error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,41 @@ function manual_sum(r, ρ_max, A, p, ΔC)
return val
end

function manual_integral_box(x1,x2,y1,y2,z1,z2,n,ndiv)
xs = range(x1,stop=x2,length=ndiv)
ys = range(y1,stop=y2,length=ndiv)
zs = range(z1,stop=z2,length=ndiv)
dx=xs[2]-xs[1]
dy=ys[2]-ys[1]
dz=zs[2]-zs[1]
val = 0.0
for ix in 1:length(xs)-1
x = (xs[ix]+xs[ix+1])*0.5
for iy in 1:length(ys)-1
y = (ys[iy]+ys[iy+1])*0.5
for iz in 1:length(zs)-1
z = (zs[iz]+zs[iz+1])*0.5
val += (x^2+y^2+z^2)^(-(n+1)*0.5)
end
end
end
return val * dx * dy * dz
end

function manual_sum_box(r, x1,x2,y1,y2,z1,z2,A,p; ndiv=50)
println("Manual Sum Box: p=$p")
val = 0.0

for n in p+1:1000
F = manual_integral_box(x1,x2,y1,y2,z1,z2,n,ndiv)
val += r^n * F
end

val *= A / ((x2-x1)*(y2-y1)*(z2-z1))

return val
end

function theta_integral2(ρ_max, ΔC, n, ρ̂)
stuff = (-ρ_max^2 + ΔC^2 + ρ̂^2) / (2 * ΔC * ρ̂)
θs = range(0, stop=acos(stuff), length=100)
Expand Down Expand Up @@ -163,10 +198,6 @@ function manual_sum5_rel(r, ρ_max, A, p, ΔC)
r_max = r
ρ2_ΔC2_2ΔC = (ρ_max^2 - ΔC^2) / (2*ΔC)
r2_ΔC2 = r^2/(2*ΔC)
@show Γ, r_max, ρ2_ΔC2_2ΔC, r2_ΔC2
@show logterm + t1
@show logterm + t2
@show logterm + t3

return val
end
Expand All @@ -175,9 +206,8 @@ function upper_bound_2(r, ρ_max, A, p, ΔC)
return A / (ΔC - ρ_max - r) * (r/(ΔC - ρ_max))^(p+1)
end


# manual integral
r, ρ_max, A, ΔC = 1.0, 3.0, 1.0, 5.0
r, ρ_max, A, ΔC = 1.0, 0.5, 1.0, 3.0
ps = collect(0:20)

# integral of abs(Plm(cos)...
Expand All @@ -195,9 +225,22 @@ e4_manual = manual_sum4.(Ref(r), Ref(ρ_max), Ref(A), ps, Ref(ΔC))
# simplification
e5_manual = manual_sum5.(Ref(r), Ref(ρ_max), Ref(A), ps, Ref(ΔC))
e5_manual_rel = manual_sum5_rel.(Ref(r), Ref(ρ_max), Ref(A), ps, Ref(ΔC))
e5_manual_rel_2 = e5_manual ./ (A/(ΔC - r - ρ_max))

ub2 = upper_bound_2.(Ref(r), Ref(ρ_max), Ref(A), ps, Ref(ΔC))

# try box integral- x axis
sx = sy = sz = (4/3*pi)^(1/3) * ρ_max # preserve volume
sx = sy = sz = 2 * ρ_max # sphere inscribed in the box
sx = sy = sz = 2 * ρ_max / sqrt(3) # box inscribed in the sphere
x1 = ΔC - sx/2
x2 = ΔC + sx/2
y1 = -sy/2
y2 = sy/2
z1 = -sz/2
z2 = sz/2
e_manual_box_x = manual_sum_box.(Ref(r), Ref(x1), Ref(x2), Ref(y1), Ref(y2), Ref(z1), Ref(z2), Ref(A), ps; ndiv=50)

p = ps[end]

#@btime upper_bound_1($r,$ρ_max,$A,$p,$ΔC)
Expand Down
24 changes: 12 additions & 12 deletions src/FastMultipole.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ using WriteVTK

#------- CONSTANTS -------#

const ONE_OVER_4π = 1/4/pi
const ONE_OVER_4π = 1/(4*π)
const ONE_THIRD = 1/3
const π_over_2 = π/2
const π2 = 2*π
const DEBUG = Array{Bool,0}(undef)
DEBUG[] = false

Expand All @@ -21,12 +23,6 @@ const WARNING_FLAG_PMAX = Array{Bool,0}(undef)
WARNING_FLAG_PMAX[] = true

# multithreading parameters
#const MIN_NPT_B2M = 1
#const MIN_NPT_M2M = 1
#const MIN_NPT_M2L = 1
#const MIN_NPT_L2L = 1
#const MIN_NPT_L2B = 1
#const MIN_NPT_NF = 1
const MIN_NPT_B2M = 100
const MIN_NPT_M2M = 100
const MIN_NPT_M2L = 100
Expand All @@ -37,7 +33,7 @@ const MIN_NPT_NF = 100
# preallocate y-axis rotation matrices by π/2
const Hs_π2 = Float64[1.0]

# preallocate y-axis Wigner matrix normalization
# preallocate y-axis rotation Wigner matrix normalization
const ζs_mag = Float64[1.0]
const ηs_mag = Float64[1.0]

Expand Down Expand Up @@ -73,13 +69,17 @@ include("derivativesswitch.jl")

export DerivativesSwitch

include("error.jl")

export multipole_error, local_error, error

include("sortwrapper.jl")

export SortWrapper

include("interaction_list.jl")

export EqualSpheres, UnequalSpheres, UnequalBoxes, Dynamic, build_interaction_lists
export EqualSpheres, UnequalSpheres, UnequalBoxes, UniformUnequalSpheres, UniformUnequalBoxes, UniformCubes, UniformCubesVelocity, Dynamic, build_interaction_lists

include("fmm.jl")

Expand All @@ -96,10 +96,10 @@ export visualize
#------- PRECALCULATIONS -------#

# precompute y-axis rotation by π/2 matrices up to 20th order
update_Hs_π2!(Hs_π2, Val(20))
update_Hs_π2!(Hs_π2, 21)

# precompute y-axis Wigner matrix normalization up to 20th order
update_ζs_mag!(ζs_mag, Val(20))
update_ηs_mag!(ηs_mag, Val(20))
update_ζs_mag!(ζs_mag, 21)
update_ηs_mag!(ηs_mag, 21)

end # module
Loading

0 comments on commit 5b83685

Please sign in to comment.