|
1 | 1 | using StochasticDiffEq, DiffEqNoiseProcess, Test, DiffEqDevTools, Random |
2 | 2 | Random.seed!(1) |
3 | 3 |
|
4 | | -u0 = zeros(2) |
5 | | -v0 = ones(2) |
6 | | -γ = 1 |
7 | | - |
8 | 4 | f1_harmonic(v,u,p,t) = -u |
9 | 5 | f2_harmonic(v,u,p,t) = v |
10 | 6 | g(u,p,t) = 1 |
| 7 | +γ = 1 |
| 8 | + |
| 9 | +@testset "Scalar u" begin |
| 10 | + u0 = 0 |
| 11 | + v0 = 1 |
| 12 | + |
| 13 | + ff_harmonic = DynamicalSDEFunction(f1_harmonic,f2_harmonic,g) |
| 14 | + prob1 = DynamicalSDEProblem(ff_harmonic,g,v0,u0,(0.0,5.0)) |
| 15 | + |
| 16 | + dts = (1/2) .^ (8:-1:4) |
| 17 | + |
| 18 | + # Can't use NoiseGrid as noise is not generated with the correct size in convergence.jl. We require noise with shape of v. |
| 19 | + sim1 = analyticless_test_convergence(dts,prob1,BAOAB(gamma=γ),(1/2)^10;trajectories=Int(2e2),use_noise_grid=false) |
| 20 | + display(sim1.𝒪est) |
| 21 | + @test abs(sim1.𝒪est[:weak_final]-1) < 0.3 |
| 22 | +end |
| 23 | + |
| 24 | +@testset "Vector u" begin |
| 25 | + |
| 26 | + u0 = zeros(2) |
| 27 | + v0 = ones(2) |
11 | 28 |
|
12 | | -f1_harmonic_iip(dv,v,u,p,t) = dv .= f1_harmonic(v,u,p,t) |
13 | | -f2_harmonic_iip(du,v,u,p,t) = du .= f2_harmonic(v,u,p,t) |
14 | | -g_iip(du,u,p,t) = du .= g(u,p,t) |
| 29 | + f1_harmonic_iip(dv,v,u,p,t) = dv .= f1_harmonic(v,u,p,t) |
| 30 | + f2_harmonic_iip(du,v,u,p,t) = du .= f2_harmonic(v,u,p,t) |
| 31 | + g_iip(du,u,p,t) = du .= g(u,p,t) |
15 | 32 |
|
16 | | -ff_harmonic = DynamicalSDEFunction(f1_harmonic,f2_harmonic,g) |
17 | | -prob1 = DynamicalSDEProblem(ff_harmonic,g,v0,u0,(0.0,5.0)) |
18 | | -sol1 = solve(prob1,BAOAB(gamma=γ);dt=1/10,save_noise=true) |
| 33 | + ff_harmonic = DynamicalSDEFunction(f1_harmonic,f2_harmonic,g) |
| 34 | + prob1 = DynamicalSDEProblem(ff_harmonic,g,v0,u0,(0.0,5.0)) |
| 35 | + sol1 = solve(prob1,BAOAB(gamma=γ);dt=1/10,save_noise=true) |
19 | 36 |
|
20 | | -prob2 = DynamicalSDEProblem(f1_harmonic_iip,f2_harmonic_iip,g_iip,v0,u0,(0.0,5.0); noise=NoiseWrapper(sol1.W)) |
21 | | -sol2 = solve(prob2,BAOAB(gamma=γ);dt=1/10) |
| 37 | + prob2 = DynamicalSDEProblem(f1_harmonic_iip,f2_harmonic_iip,g_iip,v0,u0,(0.0,5.0); noise=NoiseWrapper(sol1.W)) |
| 38 | + sol2 = solve(prob2,BAOAB(gamma=γ);dt=1/10) |
22 | 39 |
|
23 | | -@test sol1[:] ≈ sol2[:] |
| 40 | + @test sol1[:] ≈ sol2[:] |
24 | 41 |
|
25 | | -dts = (1/2) .^ (8:-1:4) |
| 42 | + dts = (1/2) .^ (8:-1:4) |
26 | 43 |
|
27 | | -# Can't use NoiseGrid as noise is not generated with the correct size in convergence.jl. We require noise with shape of v. |
28 | | -sim1 = analyticless_test_convergence(dts,prob1,BAOAB(gamma=γ),(1/2)^10;trajectories=Int(1e2),use_noise_grid=false) |
29 | | -@test abs(sim1.𝒪est[:weak_final]-1) < 0.3 |
| 44 | + # Can't use NoiseGrid as noise is not generated with the correct size in convergence.jl. We require noise with shape of v. |
| 45 | + sim1 = analyticless_test_convergence(dts,prob1,BAOAB(gamma=γ),(1/2)^10;trajectories=Int(1e2),use_noise_grid=false) |
| 46 | + @test abs(sim1.𝒪est[:weak_final]-1) < 0.3 |
| 47 | +end |
0 commit comments