1
1
using MPISphericalHarmonics
2
2
using MPIMagneticFields
3
3
using MPIFiles
4
+ using SphericalHarmonicExpansions
4
5
using Test
5
6
using Aqua
6
7
@@ -34,6 +35,25 @@ using Aqua
34
35
@test isapprox (coeffs[j,1 ]. c, ideal[j], atol = 1e-10 )
35
36
end
36
37
38
+ @testset " magneticField" begin
39
+ # further tests for function magneticField()
40
+ coords = Float64 .(ustrip .(Unitful. m .(hcat ([p for p in tDes]. .. ))))
41
+ R = Float64 (ustrip (Unitful. m (tDes. radius)))
42
+ center = Float64 .(ustrip .(Unitful. m .(tDes. center)))
43
+ L = floor (Int,tDes. T/ 2 )
44
+
45
+ # transposed positions
46
+ coeffsTest, = MPISphericalHarmonics. magneticField (coords' , fieldValues, R, center, L, x, y, z)
47
+ for j= 1 : 3
48
+ @test isapprox (coeffs[j,1 ]. c, coeffsTest[j,1 ]. c, atol = 1e-10 )
49
+ end
50
+
51
+ # Errors
52
+ @test_throws DimensionMismatch MPISphericalHarmonics. magneticField (coords, zeros (4 ,length (tDes)), R, center, L, x, y, z) # >3 field values in the first dimension
53
+ @test_throws DimensionMismatch MPISphericalHarmonics. magneticField (coords, fieldValues[:,1 : end - 1 ], R, center, L, x, y, z) # number of field values != number of measured positions
54
+ end
55
+
56
+
37
57
@testset " MagneticFieldCoefficients" begin
38
58
39
59
# # Test Constructor
@@ -48,6 +68,11 @@ using Aqua
48
68
@test coeffsMF. center == zeros (Float64,3 )
49
69
@test coeffsMF. ffp === nothing
50
70
71
+ L = 1
72
+ coeffsMF = MagneticFieldCoefficients (L)
73
+ @test size (coeffsMF. coeffs) == (3 ,1 )
74
+ [@test coeffsMF. coeffs[j,1 ]. L == L for j= 1 : 3 ]
75
+
51
76
# constructor with t-design
52
77
coeffsMF = MagneticFieldCoefficients (coeffs, tDes, zeros (Float64,3 ,1 ))
53
78
@test coeffsMF. radius == 0.042
@@ -64,8 +89,13 @@ using Aqua
64
89
65
90
# # measurement data (without coefficients)
66
91
filename = " idealGradientField.h5"
67
- func = SphericalHarmonicsDefinedField (filename)
68
- @test isapprox (func[0.01 ,0.01 ,0.01 ], [- 0.01 ,- 0.01 ,0.02 ], atol= ε)
92
+ field = SphericalHarmonicsDefinedField (filename)
93
+ @test isapprox (field[0.01 ,0.01 ,0.01 ], [- 0.01 ,- 0.01 ,0.02 ], atol= ε)
94
+
95
+ # Test field types
96
+ @test fieldType (field) isa OtherField
97
+ @test definitionType (field) isa SphericalHarmonicsDataBasedFieldDefinition
98
+ @test timeDependencyType (field) isa TimeConstant
69
99
70
100
# get coefficients
71
101
coeffsMF, = MPISphericalHarmonics. loadTDesignCoefficients (filename)
@@ -76,10 +106,9 @@ using Aqua
76
106
77
107
# # load coefficients from file
78
108
# write coefficients in file
79
- filename2 = " idealGradientFieldwithCoeffs.h5"
80
- filename3 = " idealGradientFieldwithCoeffs2.h5"
81
- filename4 = " idealGradientFieldwithCoeffs3.h5"
82
- cp (filename, filename2)
109
+ filename2 = " Coeffs.h5"
110
+ filename3 = " Coeffs2.h5"
111
+ filename4 = " Coeffs3.h5"
83
112
write (filename2, coeffsMF. coeffs)
84
113
# add radius and center
85
114
cp (filename2, filename3)
@@ -106,6 +135,8 @@ using Aqua
106
135
# with given FFP
107
136
coeffsTest = MagneticFieldCoefficients (filename4)
108
137
@test coeffsTest. ffp == zeros (3 ,1 ) # FFP
138
+ field = SphericalHarmonicsDefinedField (filename4)
139
+ @test isapprox (field[- 0.02 ,0.02 ,- 0.03 ], [0.02 ,- 0.02 ,- 0.06 ], atol= ε)
109
140
110
141
# remove test files
111
142
rm (filename2)
@@ -114,7 +145,26 @@ using Aqua
114
145
end
115
146
116
147
@testset " Multiple patches" begin
117
- # TODO
148
+ # # Multi-patch setting: Second field with offset
149
+ coeffsPatch = hcat (deepcopy (coeffs),deepcopy (coeffs)) # two patches
150
+ for j= 1 : 3 coeffsPatch[j,2 ][0 ,0 ] = 0.01 end # set offset
151
+ field = SphericalHarmonicsDefinedField (func = fastfunc .(coeffsPatch))
152
+
153
+ # # Test FFPs (for both patches)
154
+ # First patch
155
+ @test field. patch == 1
156
+ ffp = zeros (3 )
157
+ @test isapprox (field[ffp... ], zeros (3 ), atol= 1e-10 )
158
+
159
+ # Second patch
160
+ selectPatch (field,2 )
161
+ @test field. patch == 2
162
+ # test offset in (0,0,0)
163
+ offset = ones (3 ) .* 0.01
164
+ @test isapprox (field[0 ,0 ,0 ], offset, atol= 1e-10 )
165
+ # test FFP
166
+ ffp = [0.01 , 0.01 , - 0.005 ]
167
+ @test isapprox (field[ffp... ], zeros (3 ), atol= 1e-10 )
118
168
end
119
169
end
120
170
0 commit comments