1+ using VortexStepMethod: BoundFilament, velocity_3D_bound_vortex!
2+ using LinearAlgebra
3+ using Test
4+
5+ # Test helper functions
6+ function create_test_filament ()
7+ BoundFilament ([0.0 , 0.0 , 0.0 ], [1.0 , 0.0 , 0.0 ])
8+ end
9+
10+ function analytical_solution (control_point, gamma)
11+ A = [0.0 , 0.0 , 0.0 ]
12+ B = [1.0 , 0.0 , 0.0 ]
13+ P = control_point
14+
15+ r0 = B - A
16+ r1 = P - A
17+ r2 = P - B
18+
19+ r1Xr2 = cross (r1, r2)
20+ norm_r1Xr2 = norm (r1Xr2)
21+
22+ return (gamma / (4 π)) * (r1Xr2 / (norm_r1Xr2^ 2 )) *
23+ dot (r0, r1/ norm (r1) - r2/ norm (r2))
24+ end
25+
26+ @testset " BoundFilament Tests" begin
27+ gamma = 1.0
28+ core_radius_fraction = 0.01
29+ induced_velocity = zeros (3 )
30+
31+ @testset " Calculate Induced Velocity" begin
32+ filament = create_test_filament ()
33+ control_point = [0.5 , 1.0 , 0.0 ]
34+
35+ velocity_3D_bound_vortex! (
36+ induced_velocity,
37+ filament,
38+ control_point,
39+ gamma,
40+ core_radius_fraction
41+ )
42+ analytical_velocity = analytical_solution (control_point, gamma)
43+
44+ @test isapprox (induced_velocity, analytical_velocity, rtol= 1e-6 )
45+ end
46+
47+ @testset " Point Exactly on Filament" begin
48+ filament = create_test_filament ()
49+ test_points = [
50+ [0.0 , 0.0 , 0.0 ], # start point
51+ [1.0 , 0.0 , 0.0 ], # end point
52+ [0.5 , 0.0 , 0.0 ], # middle point
53+ ]
54+
55+ for point in test_points
56+ velocity_3D_bound_vortex! (
57+ induced_velocity,
58+ filament,
59+ point,
60+ gamma,
61+ core_radius_fraction
62+ )
63+ @test all (isapprox .(induced_velocity, zeros (3 ), atol= 1e-10 ))
64+ @test ! any (isnan .(induced_velocity))
65+ end
66+ end
67+
68+ @testset " Long Filament" begin
69+ filament = BoundFilament ([0.0 , 0.0 , 0.0 ], [1e6 , 0.0 , 0.0 ])
70+ control_point = [5e5 , 1.0 , 0.0 ]
71+
72+ velocity_3D_bound_vortex! (
73+ induced_velocity,
74+ filament,
75+ control_point,
76+ gamma,
77+ core_radius_fraction
78+ )
79+
80+ @test ! any (isnan .(induced_velocity))
81+ @test isapprox (induced_velocity[1 ], 0.0 , atol= 1e-8 )
82+ @test abs (induced_velocity[2 ]) < 1e-8
83+ @test isapprox (induced_velocity[3 ], 0.0 )
84+ end
85+
86+ @testset " Point Far from Filament" begin
87+ filament = create_test_filament ()
88+ control_point = [0.5 , 1e6 , 0.0 ]
89+
90+ velocity_3D_bound_vortex! (
91+ induced_velocity,
92+ filament,
93+ control_point,
94+ gamma,
95+ core_radius_fraction
96+ )
97+
98+ @test ! any (isnan .(induced_velocity))
99+ @test all (isapprox .(induced_velocity, zeros (3 ), atol= 1e-12 ))
100+ end
101+
102+ v1, v2, v4 = zeros (3 ), zeros (3 ), zeros (3 )
103+
104+ @testset " Different Gamma Values" begin
105+ filament = create_test_filament ()
106+ control_point = [0.5 , 1.0 , 0.0 ]
107+
108+ velocity_3D_bound_vortex! (v1, filament, control_point, 1.0 , core_radius_fraction)
109+ velocity_3D_bound_vortex! (v2, filament, control_point, 2.0 , core_radius_fraction)
110+ velocity_3D_bound_vortex! (v4, filament, control_point, 4.0 , core_radius_fraction)
111+
112+ @test isapprox (v4, 2 * v2)
113+ @test isapprox (v4, 4 * v1)
114+ end
115+
116+ @testset " Symmetry" begin
117+ filament = BoundFilament ([- 1.0 , 0.0 , 0.0 ], [1.0 , 0.0 , 0.0 ])
118+
119+ velocity_3D_bound_vortex! (v1, filament, [0.0 , 1.0 , 0.0 ], gamma, core_radius_fraction)
120+ velocity_3D_bound_vortex! (v2, filament, [0.0 , - 1.0 , 0.0 ], gamma, core_radius_fraction)
121+
122+ @test isapprox (v1, - v2)
123+ end
124+
125+ @testset " Around Core Radius" begin
126+ filament = create_test_filament ()
127+ delta = 1e-5
128+
129+ points = [
130+ [0.5 , core_radius_fraction - delta, 0.0 ],
131+ [0.5 , core_radius_fraction, 0.0 ],
132+ [0.5 , core_radius_fraction + delta, 0.0 ]
133+ ]
134+
135+ velocities = [zeros (3 ) for p in points]
136+ [
137+ velocity_3D_bound_vortex! (velocities[i], filament, p, gamma, core_radius_fraction)
138+ for (i, p) in enumerate (points)
139+ ]
140+
141+ # Check for NaN and finite values
142+ @test all (! any (isnan .(v)) for v in velocities)
143+ @test all (all (isfinite .(v)) for v in velocities)
144+
145+ # Check magnitude is maximum at core radius
146+ @test norm (velocities[2 ]) > norm (velocities[1 ])
147+ @test norm (velocities[2 ]) > norm (velocities[3 ])
148+
149+ # Check continuity around core radius
150+ @test isapprox (velocities[1 ], velocities[2 ], rtol= 1e-3 )
151+
152+ # Check non-zero velocities
153+ @test ! all (isapprox .(velocities[1 ], zeros (3 ), atol= 1e-10 ))
154+ @test ! all (isapprox .(velocities[2 ], zeros (3 ), atol= 1e-10 ))
155+ @test ! all (isapprox .(velocities[3 ], zeros (3 ), atol= 1e-10 ))
156+
157+ # Check symmetry
158+ v_neg = zeros (3 )
159+ velocity_3D_bound_vortex! (
160+ v_neg,
161+ filament,
162+ [0.5 , - core_radius_fraction, 0.0 ],
163+ gamma,
164+ core_radius_fraction
165+ )
166+ @test isapprox (velocities[2 ], - v_neg)
167+ end
168+ end
0 commit comments