annotate test/SbpOperators/stencil_test.jl @ 867:313648b01504 feature/variable_derivatives

Start implementing nested stencils
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 19 Jan 2022 21:49:34 +0100
parents 4433be383840
children e37ee63bf9ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
728
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
1 using Test
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
2 using Sbplib.SbpOperators
732
6114274447f5 Add missing using and imports in test files
Jonatan Werpers <jonatan@werpers.com>
parents: 728
diff changeset
3 import Sbplib.SbpOperators.Stencil
867
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
4 import Sbplib.SbpOperators.NestedStencil
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
5 import Sbplib.SbpOperators.scale
728
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
6
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
7 @testset "Stencil" begin
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
8 s = Stencil((-2,2), (1.,2.,2.,3.,4.))
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
9 @test s isa Stencil{Float64, 5}
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
10
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
11 @test eltype(s) == Float64
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
12 @test SbpOperators.scale(s, 2) == Stencil((-2,2), (2.,4.,4.,6.,8.))
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
13
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
14 @test Stencil(1,2,3,4; center=1) == Stencil((0, 3),(1,2,3,4))
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
15 @test Stencil(1,2,3,4; center=2) == Stencil((-1, 2),(1,2,3,4))
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
16 @test Stencil(1,2,3,4; center=4) == Stencil((-3, 0),(1,2,3,4))
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
17
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
18 @test CenteredStencil(1,2,3,4,5) == Stencil((-2, 2), (1,2,3,4,5))
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
19 @test_throws ArgumentError CenteredStencil(1,2,3,4)
826
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
20
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
21 # Changing the type of the weights
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
22 @test Stencil{Float64}(Stencil(1,2,3,4,5; center=2)) == Stencil(1.,2.,3.,4.,5.; center=2)
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
23 @test Stencil{Float64}(CenteredStencil(1,2,3,4,5)) == CenteredStencil(1.,2.,3.,4.,5.)
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
24 @test Stencil{Int}(Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1,2,3,4,5; center=2)
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
25 @test Stencil{Rational}(Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1//1,2//1,3//1,4//1,5//1; center=2)
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
26
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
27 @testset "convert" begin
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
28 @test convert(Stencil{Float64}, Stencil(1,2,3,4,5; center=2)) == Stencil(1.,2.,3.,4.,5.; center=2)
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
29 @test convert(Stencil{Float64}, CenteredStencil(1,2,3,4,5)) == CenteredStencil(1.,2.,3.,4.,5.)
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
30 @test convert(Stencil{Int}, Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1,2,3,4,5; center=2)
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
31 @test convert(Stencil{Rational}, Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1//1,2//1,3//1,4//1,5//1; center=2)
4433be383840 Add stencil constructor to change the type of the weights along with a convert method
Jonatan Werpers <jonatan@werpers.com>
parents: 732
diff changeset
32 end
728
45966c77cb20 Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
33 end
867
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
34
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
35 @testset "NestedStencil" begin
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
36
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
37 @testset "Constructors" begin
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
38 s1 = Stencil(-1, 1, 0; center = 1)
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
39 s2 = Stencil(-1, 0, 1; center = 2)
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
40 s3 = Stencil( 0,-1, 1; center = 3)
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
41
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
42 ns = NestedStencil(CenteredStencil(s1,s2,s3))
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
43 @test ns isa NestedStencil{Int,3}
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
44
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
45 @test CenteredNestedStencil(s1,s2,s3) == ns
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
46
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
47 @test NestedStencil(s1,s2,s3, center = 2) == ns
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
48 @test NestedStencil(s1,s2,s3, center = 1) == NestedStencil(Stencil(s1,s2,s3, center=1))
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
49
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
50 @test NestedStencil((-1,1,0),(-1,0,1),(0,-1,1), center=2) == ns
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
51
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
52
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
53 @testset "Error handling" begin
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
54
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
55 end
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
56 end
313648b01504 Start implementing nested stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 826
diff changeset
57 end