Skip to content

Commit 1b67150

Browse files
committed
added first test
1 parent 84f768d commit 1b67150

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

src/MPISphericalHarmonics.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ using MPIMagneticFields
88
using SphericalHarmonicExpansions
99
using MPIFiles
1010

11+
export MagneticFieldCoefficients
12+
13+
# Spherical harmonic coefficients describing a magnetic field
1114
mutable struct MagneticFieldCoefficients
12-
coeffs::Array{SphericalHarmonicCoefficients,2}
13-
radius::Float64
14-
center::Vector{Float64}
15-
ffp::Union{Array{Float64,2},Nothing}
15+
coeffs::Array{SphericalHarmonicCoefficients,2} # coefficients
16+
radius::Float64 # radius of measured sphere
17+
center::Vector{Float64} # center of measured sphere
18+
ffp::Union{Array{Float64,2},Nothing} # field-free-point (if available)
1619

1720
function MagneticFieldCoefficients(coeffs::Array{SphericalHarmonicCoefficients,2}, radius::Float64,
1821
center::Vector{Float64}, ffp::Union{Array{Float64,2},Nothing})
@@ -94,7 +97,7 @@ end
9497
"""
9598
function magneticField(tDesign::SphericalTDesign, field::Union{AbstractArray{T,2},AbstractArray{T,3}},
9699
x::Variable, y::Variable, z::Variable;
97-
L::Int=Int(floor(tDesign.T/2)),
100+
L::Int=floor(Int,tDesign.T/2),
98101
calcSolid::Bool=true) where T <: Real
99102

100103
# get tDesign positions [m] and removing the unit
@@ -208,4 +211,4 @@ MPIMagneticFields.value(field::SphericalHarmonicDefinedField, r) = [MPIMagneticF
208211

209212
selectPatch(field::SphericalHarmonicDefinedField, patchNum) = field.patch = patchNum
210213

211-
end
214+
end

test/runtests.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using MPISphericalHarmonics
2+
using MPIMagneticFields
3+
using MPIFiles
24
using Test
35
using Aqua
46

@@ -7,5 +9,31 @@ using Aqua
79
Aqua.test_all(MPISphericalHarmonics, ambiguities=false)
810
end
911

12+
13+
@testset "Ideal Coefficents" begin
14+
15+
## Calculate some field values
16+
# load a spherical t-design
17+
tDes = loadTDesign(6,26,42u"mm")
18+
# ideal gradient field with FFP
19+
idealField = IdealFFP([-1,-1,2])
20+
# get field values
21+
fieldValues = hcat([idealField[ustrip.(Unitful.m.(pos))...] for pos in tDes]...)
22+
23+
## Calculate coefficients
24+
MPISphericalHarmonics.@polyvar x y z
25+
coeffs, = MPISphericalHarmonics.magneticField(tDes, fieldValues, x,y,z)
26+
27+
## Test coefficients
28+
numCoeffs = length(coeffs[1,1].c)
29+
# ideal coefficients
30+
ideal = [zeros(numCoeffs) for j=1:3]
31+
ideal[1][4] = ideal[2][2] = idealField.gradient[1] # gradient (x,y)
32+
ideal[3][3] = idealField.gradient[3] # gradient (z)
33+
for j=1:3
34+
@test isapprox(coeffs[j,1].c, ideal[j], atol = 1e-10)
35+
end
36+
37+
end
1038

1139
end

0 commit comments

Comments
 (0)