11using StreamMacros
2+ using InteractiveUtils
23using DiffEqBase
34using StaticArrays
45using Test
56
67@testset " StreamMacros.jl" begin
7- bickley = @velo_from_stream stream begin
8- stream = psi₀ + psi₁
9- psi₀ = - U₀ * L₀ * tanh (y / L₀)
10- psi₁ = U₀ * L₀ * sech (y / L₀)^ 2 * re_sum_term
11-
12- re_sum_term = Σ₁ + Σ₂ + Σ₃
13-
14- Σ₁ = ε₁ * cos (k₁* (x - c₁* t))
15- Σ₂ = ε₂ * cos (k₂* (x - c₂* t))
16- Σ₃ = ε₃ * cos (k₃* (x - c₃* t))
17-
18- k₁ = 2 / r₀ ; k₂ = 4 / r₀ ; k₃ = 6 / r₀
19-
20- ε₁ = 0.0075 ; ε₂ = 0.15 ; ε₃ = 0.3
21- c₂ = 0.205 U₀ ; c₃ = 0.461 U₀ ; c₁ = c₃ + (√ 5 - 1 )* (c₂- c₃)
22-
23- U₀ = 62.66e-6 ; L₀ = 1770e-3 ; r₀ = 6371e-3
8+ du = zeros (2 ); u= rand (2 ); t = rand (); DU = zeros (2 ,3 ); U = rand (2 ,3 )
9+ @define_stream bstream begin
10+ bstream = psi₀ + psi₁
11+ psi₀ = - U₀ * L₀ * tanh (y / L₀)
12+ psi₁ = U₀ * L₀ * sech (y / L₀)^ 2 * re_sum_term
13+
14+ re_sum_term = Σ₁ + Σ₂ + Σ₃
15+
16+ Σ₁ = ε₁ * cos (k₁* (x - c₁* t))
17+ Σ₂ = ε₂ * cos (k₂* (x - c₂* t))
18+ Σ₃ = ε₃ * cos (k₃* (x - c₃* t))
19+
20+ k₁ = 2 / r₀ ; k₂ = 4 / r₀ ; k₃ = 6 / r₀
21+
22+ ε₁ = 0.0075 ; ε₂ = 0.15 ; ε₃ = 0.3
23+ c₂ = 0.205 U₀ ; c₃ = 0.461 U₀ ; c₁ = c₃ + (√ 5 - 1 )* (c₂- c₃)
24+
25+ U₀ = 62.66e-6 ; L₀ = 1770e-3 ; r₀ = 6371e-3
2426 end
25- @test bickley isa ODEFunction
27+ bickley = @velo_from_stream bstream
28+ bickley! = @velo!_from_stream bstream
29+ @test bickley isa ODEFunction{false }
30+ @test bickley! isa ODEFunction{true }
2631 @test bickley (SVector (0.0 ,0.0 ), nothing , 0.0 ) isa SVector
32+ @test bickley (SVector (0.0 ,0.0 ), nothing , 0.0 ) == bickley! (ones (2 ), [0.0 , 0.0 ], nothing , 0.0 )
33+ VERSION ≥ v " 1.1" && @test iszero (@allocated bickley! (du, u, nothing , t))
2734
28- bickley2 = @var_velo_from_stream stream begin
29- stream = psi₀ + psi₁
30- psi₀ = - U₀ * L₀ * tanh (y / L₀)
31- psi₁ = U₀ * L₀ * sech (y / L₀)^ 2 * re_sum_term
32-
33- re_sum_term = Σ₁ + Σ₂ + Σ₃
34-
35- Σ₁ = ε₁ * cos (k₁* (x - c₁* t))
36- Σ₂ = ε₂ * cos (k₂* (x - c₂* t))
37- Σ₃ = ε₃ * cos (k₃* (x - c₃* t))
38-
39- k₁ = 2 / r₀ ; k₂ = 4 / r₀ ; k₃ = 6 / r₀
40-
41- ε₁ = 0.0075 ; ε₂ = 0.15 ; ε₃ = 0.3
42- c₂ = 0.205 U₀ ; c₃ = 0.461 U₀ ; c₁ = c₃ + (√ 5 - 1 )* (c₂- c₃)
43-
44- U₀ = 62.66e-6 ; L₀ = 1770e-3 ; r₀ = 6371e-3
45- end
46- @test bickley2 isa ODEFunction
47- @test (bickley2 (SMatrix {2,3} (0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ), nothing , 0.0 )
48- isa SMatrix{2 ,3 })
35+ bickley2 = @var_velo_from_stream bstream
36+ bickley2! = @var_velo!_from_stream bstream
37+ @test bickley2 isa ODEFunction{false }
38+ @test bickley2! isa ODEFunction{true }
39+ @test (bickley2 (SMatrix {2,3} (0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ), nothing , 0.0 ) isa SMatrix{2 ,3 })
40+ @test bickley2 (SMatrix {2,3} (0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ), nothing , 0.0 ) == bickley2! (ones (2 ,3 ), zeros (2 ,3 ), nothing , 0.0 )
41+ VERSION ≥ v " 1.1" && @test iszero (@allocated bickley2! (DU, U, nothing , t))
4942
5043 @test StreamMacros. expr_diff (:(x^ 2 + sin (x) + y), :x ) == :(2 x + cos (x))
5144
@@ -55,10 +48,13 @@ using Test
5548
5649 t1 = @var_velo_from_stream test_stream
5750 t2 = @velo_from_stream test_stream
58- @test t1 isa ODEFunction
59- @test t2 isa ODEFunction
51+ @test t1 isa ODEFunction{ false }
52+ @test t2 isa ODEFunction{ false }
6053 ω = @vorticity_from_stream test_stream
6154 @test ω (rand (), rand (), rand ()) == 4
55+ # works only locally, not on github CI
56+ # ct = code_typed(ω, (Float64, Float64, Float64))
57+ # @test first(ct).first.code[1] == :(return 4)
6258
6359 @define_stream Ψ_rot_dgyre begin
6460 st = window (t, 0 , 1 )* t^ 2 * (3 - 2 * t) + heaviside (t- 1 )
@@ -69,6 +65,10 @@ using Test
6965 Ψ_rot_dgyre = (1 - st) * Ψ_P + st * Ψ_F
7066 end
7167 rot_double_gyre = @velo_from_stream Ψ_rot_dgyre
68+ rot_double_gyre! = @velo!_from_stream Ψ_rot_dgyre
69+ @test rot_double_gyre (SVector {2} (0.0 ,0.0 ), nothing , 0.0 ) == rot_double_gyre! (ones (2 ), zeros (2 ), nothing , 0.0 )
70+ VERSION ≥ v " 1.1" && @test iszero (@allocated rot_double_gyre! (du, u, nothing , t))
71+
7272 dgyrepast = @velo_from_stream Ψ_P begin
7373 Ψ_P = sin (2 π* x)* sin (π* y)
7474 end
0 commit comments