@@ -14,7 +14,7 @@ using Aqua
14
14
15
15
# # Calculate some field values
16
16
# load a spherical t-design
17
- tDes = loadTDesign (6 ,26 ,42 u " mm" )
17
+ tDes = loadTDesign (6 ,26 ,42.0 u " mm" )
18
18
# ideal gradient field with FFP
19
19
idealField = IdealFFP ([- 1 ,- 1 ,2 ])
20
20
# get field values
@@ -34,6 +34,88 @@ using Aqua
34
34
@test isapprox (coeffs[j,1 ]. c, ideal[j], atol = 1e-10 )
35
35
end
36
36
37
+ @testset " MagneticFieldCoefficients" begin
38
+
39
+ # # Test Constructor
40
+ # Errors
41
+ @test_throws DomainError MagneticFieldCoefficients (- 2 )
42
+ @test_throws DimensionMismatch MagneticFieldCoefficients (coeffs[1 : 2 ,:])
43
+
44
+ # standard constructors
45
+ coeffsMF = MagneticFieldCoefficients (coeffs)
46
+ @test coeffsMF. coeffs == coeffs
47
+ @test coeffsMF. radius == 0.0
48
+ @test coeffsMF. center == zeros (Float64,3 )
49
+ @test coeffsMF. ffp === nothing
50
+
51
+ # constructor with t-design
52
+ coeffsMF = MagneticFieldCoefficients (coeffs, tDes, zeros (Float64,3 ,1 ))
53
+ @test coeffsMF. radius == 0.042
54
+ @test coeffsMF. center == zeros (Float64,3 )
55
+ @test coeffsMF. ffp == zeros (Float64,3 ,1 )
56
+
57
+ # constructor with wrong FFP sizes
58
+ @test_throws DimensionMismatch MagneticFieldCoefficients (coeffs, tDes, zeros (2 ,1 ))
59
+ @test_throws DimensionMismatch MagneticFieldCoefficients (coeffs, tDes, zeros (3 ,2 ))
60
+ end
61
+
62
+ @testset " Load data from file" begin
63
+ ɛ = eps (Float64)
64
+
65
+ # # measurement data (without coefficients)
66
+ filename = " idealGradientField.h5"
67
+ func = SphericalHarmonicsDefinedField (filename)
68
+ @test isapprox (func[0.01 ,0.01 ,0.01 ], [- 0.01 ,- 0.01 ,0.02 ], atol= ε)
69
+
70
+ # get coefficients
71
+ coeffsMF, = MPISphericalHarmonics. loadTDesignCoefficients (filename)
72
+ @test isapprox (coeffsMF. radius, 0.042 , atol= ε) # radius
73
+ @test isapprox (coeffsMF. coeffs[1 ][1 ,1 ], - 1.0 , atol= 1e-10 ) # gradient (x)
74
+ @test isapprox (coeffsMF. coeffs[2 ][1 ,- 1 ], - 1.0 , atol= 1e-10 ) # gradient (y)
75
+ @test isapprox (coeffsMF. coeffs[3 ][1 ,0 ], 2.0 , atol= 1e-10 ) # gradient (z)
76
+
77
+ # # load coefficients from file
78
+ # write coefficients in file
79
+ filename2 = " idealGradientFieldwithCoeffs.h5"
80
+ filename3 = " idealGradientFieldwithCoeffs2.h5"
81
+ filename4 = " idealGradientFieldwithCoeffs3.h5"
82
+ cp (filename, filename2)
83
+ write (filename2, coeffsMF. coeffs)
84
+ # add radius and center
85
+ cp (filename2, filename3)
86
+ h5open (filename3, " cw" ) do file
87
+ write (file, " /radius" , coeffsMF. radius)
88
+ write (file, " /center" , coeffsMF. center)
89
+ end
90
+ # add FFP
91
+ cp (filename3, filename4)
92
+ h5open (filename4, " cw" ) do file
93
+ write (file, " /ffp" , zeros (3 ,1 ))
94
+ end
95
+
96
+ # only coefficients (no further informations given)
97
+ coeffsTest = MagneticFieldCoefficients (filename2)
98
+ @test isapprox (coeffsTest. radius, 0.01 , atol= ε) # radius
99
+
100
+ # with given radius & center
101
+ coeffsTest = MagneticFieldCoefficients (filename3)
102
+ @test isapprox (coeffsTest. radius, 0.042 , atol= ε) # radius
103
+ @test isapprox (coeffsTest. center, zeros (3 ), atol= ε) # center
104
+ @test coeffsTest. ffp === nothing # FFP
105
+
106
+ # with given FFP
107
+ coeffsTest = MagneticFieldCoefficients (filename4)
108
+ @test coeffsTest. ffp == zeros (3 ,1 ) # FFP
109
+
110
+ # remove test files
111
+ rm (filename2)
112
+ rm (filename3)
113
+ rm (filename4)
114
+ end
115
+
116
+ @testset " Multiple patches" begin
117
+ # TODO
118
+ end
37
119
end
38
120
39
121
end
0 commit comments