comparison test/Grids/geometry_test.jl @ 1973:8e9575b518a1 feature/grids/geometry_functions

Add tests for TransfiniteInterpolationSurface and implemnet check_tranfiniteinterpolation
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 14 Feb 2025 22:19:06 +0100
parents 7f4a5146c84c
children 3ed7ca1f60c4
comparison
equal deleted inserted replaced
1971:9e89084cbba4 1973:8e9575b518a1
1 using Diffinitive.Grids 1 using Diffinitive.Grids
2 using Diffinitive.Grids: Line, LineSegment, linesegments, polygon_edges, Circle 2 using Diffinitive.Grids: Line, LineSegment, linesegments, polygon_edges, Circle, TransfiniteInterpolationSurface, check_transfiniteinterpolation
3 using StaticArrays 3 using StaticArrays
4 4
5 @testset "Line" begin 5 @testset "Line" begin
6 @testset "Constructors" begin 6 @testset "Constructors" begin
7 @test Line([1,2],[2,3]) isa Line{SVector{2,Int}} 7 @test Line([1,2],[2,3]) isa Line{SVector{2,Int}}
114 end 114 end
115 end 115 end
116 116
117 @testset "TransfiniteInterpolationSurface" begin 117 @testset "TransfiniteInterpolationSurface" begin
118 @testset "Constructors" begin 118 @testset "Constructors" begin
119 @test TransfiniteInterpolationSurface(t->[1,2], t->[2,1], t->[0,0], t->[1,1]) isa TransfiniteInterpolationSurface
120
121 cs = polygon_edges([0,0],[1,0],[1,1],[0,1])
122 @test TransfiniteInterpolationSurface(cs...) isa TransfiniteInterpolationSurface
119 end 123 end
120 124
121 @test_broken false 125 @testset "Evaluation" begin
126 a, b, c, d = [1,0],[2,1/4],[2.5,1],[-1/3,1]
127 cs = polygon_edges([0,0],[1,0],[1,1],[0,1])
128 ti = TransfiniteInterpolationSurface(cs...)
129
130 @test ti(0,0) == [0,0]
131 @test ti([0,0]) == [0,0]
132 @test ti(1,0) == [1,0]
133 @test ti([1,0]) == [1,0]
134 @test ti(1,1) == [1,1]
135 @test ti([1,1]) == [1,1]
136 @test ti(0,1) == [0,1]
137 @test ti([0,1]) == [0,1]
138
139 @test ti(1/2, 0) == [1/2, 0]
140 @test ti(1/2, 1) == [1/2, 1]
141 @test ti(0,1/2) == [0,1/2]
142 @test ti(1,1/2) == [1,1/2]
143
144
145 a, b, c, d = [1,0],[2,1/4],[2.5,1],[-1/3,1]
146 cs = polygon_edges(a,b,c,d)
147 ti = TransfiniteInterpolationSurface(cs...)
148
149 @test ti(0,0) == a
150 @test ti(1,0) == b
151 @test ti(1,1) == c
152 @test ti(0,1) == d
153
154 @test ti(1/2, 0) == (a+b)/2
155 @test ti(1/2, 1) == (c+d)/2
156 @test ti(0, 1/2) == (a+d)/2
157 @test ti(1, 1/2) == (b+c)/2
158
159 # TODO: Some test with curved edges?
160 end
161
162 @testset "check_transfiniteinterpolation" begin
163 cs = polygon_edges([0,0],[1,0],[1,1],[0,1])
164 ti = TransfiniteInterpolationSurface(cs...)
165
166 @test check_transfiniteinterpolation(ti) == nothing
167 @test check_transfiniteinterpolation(Bool, ti) == true
168
169 bad_sides = [
170 LineSegment([0,0],[1/2,0]),
171 LineSegment([1,0],[1,1/2]),
172 LineSegment([1,1],[0,1/2]),
173 LineSegment([0,1],[0,1/2]),
174 ]
175
176 s1 = TransfiniteInterpolationSurface(bad_sides[1],cs[2],cs[3],cs[4])
177 s2 = TransfiniteInterpolationSurface(cs[1],bad_sides[2],cs[3],cs[4])
178 s3 = TransfiniteInterpolationSurface(cs[1],cs[2],bad_sides[3],cs[4])
179 s4 = TransfiniteInterpolationSurface(cs[1],cs[2],cs[3],bad_sides[4])
180
181 @test check_transfiniteinterpolation(Bool, s1) == false
182 @test check_transfiniteinterpolation(Bool, s2) == false
183 @test check_transfiniteinterpolation(Bool, s3) == false
184 @test check_transfiniteinterpolation(Bool, s4) == false
185
186 @test_throws Exception check_transfiniteinterpolation(s1)
187 @test_throws Exception check_transfiniteinterpolation(s2)
188 @test_throws Exception check_transfiniteinterpolation(s3)
189 @test_throws Exception check_transfiniteinterpolation(s4)
190 end
122 end 191 end