Mercurial > repos > public > sbplib_julia
comparison test/Grids/geometry_test.jl @ 2037:e1ce0697caf5 feature/sbp_operators/laplace_curvilinear
Merge feature/grids/geometry_functions
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Wed, 04 Feb 2026 09:44:55 +0100 |
| parents | 5c2448d6a201 |
| children |
comparison
equal
deleted
inserted
replaced
| 2003:524a52f190d7 | 2037:e1ce0697caf5 |
|---|---|
| 1 using Diffinitive.Grids | 1 using Diffinitive.Grids |
| 2 using Diffinitive.Grids: Line, LineSegment, linesegments, polygon_edges, Circle, TransfiniteInterpolationSurface, check_transfiniteinterpolation | 2 using Diffinitive.Grids: Line, LineSegment, linesegments, polygon_edges, Circle, TransfiniteInterpolationSurface, check_transfiniteinterpolation, arc, Arc |
| 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}} |
| 160 @test Grids.jacobian(c, 3π/2) ≈ [2,0] | 160 @test Grids.jacobian(c, 3π/2) ≈ [2,0] |
| 161 @test Grids.jacobian(c, π/4) ≈ [-√(2),√(2)] | 161 @test Grids.jacobian(c, π/4) ≈ [-√(2),√(2)] |
| 162 end | 162 end |
| 163 end | 163 end |
| 164 | 164 |
| 165 @testset "Arc" begin | |
| 166 @test Arc(Circle([0,0], 1), 0, 1) isa Arc{SVector{2,Int}, Int} | |
| 167 @test Arc(Circle([0,0], 1.), 0, 1) isa Arc{SVector{2,Int}, Float64} | |
| 168 @test Arc(Circle([1., 1.], 1), 0., 1.) isa Arc{SVector{2,Float64}, Float64} | |
| 169 @test Arc(Circle([1., 1.], 1), 0, 1) isa Arc{SVector{2,Float64}, Int} | |
| 170 @test Arc(Circle([1., 1.], 1), 0, 1.) isa Arc{SVector{2,Float64}, Float64} | |
| 171 | |
| 172 a = Arc(Circle([0,0], 1), 0, π/2) | |
| 173 @test a(0) ≈ [1,0] | |
| 174 @test a(1/3) ≈ [√(3)/2,1/2] | |
| 175 @test a(1/2) ≈ [1/√(2),1/√(2)] | |
| 176 @test a(2/3) ≈ [1/2, √(3)/2] | |
| 177 @test a(1) ≈ [0,1] | |
| 178 | |
| 179 @testset "Grids.jacobian" begin | |
| 180 c = Circle([0,0], 1) | |
| 181 | |
| 182 @testset "Matched to circle" begin | |
| 183 a = Arc(c, 0, 1) | |
| 184 @testset for t ∈ range(0,1,8) | |
| 185 @test jacobian(a,t) ≈ jacobian(c,t) | |
| 186 end | |
| 187 end | |
| 188 | |
| 189 @testset "Full circle" begin | |
| 190 a = Arc(c, 0, 2π) | |
| 191 @testset for t ∈ range(0,1,8) | |
| 192 @test jacobian(a,t) ≈ 2π*jacobian(c,t) | |
| 193 end | |
| 194 end | |
| 195 | |
| 196 @testset "Other" begin | |
| 197 a = Arc(c, π/3, 5π/4) | |
| 198 @testset for t ∈ range(0,1,8) | |
| 199 @test jacobian(a,t) ≈ 11π/12*jacobian(c,t) | |
| 200 end | |
| 201 end | |
| 202 end | |
| 203 end | |
| 204 | |
| 205 @testset "arc" begin | |
| 206 @testset "Half circles around [0.5, 0.0]" begin | |
| 207 a = [0,0] | |
| 208 b = [1,0] | |
| 209 | |
| 210 A = arc(a,b,1/2) | |
| 211 @test A(0) ≈ a atol=1e-15 | |
| 212 @test A(1) ≈ b | |
| 213 @test A(0.5) ≈ [0.5, -0.5] | |
| 214 | |
| 215 A = arc(a,b,-1/2) | |
| 216 @test A(0) ≈ a atol=1e-15 | |
| 217 @test A(1) ≈ b | |
| 218 @test A(0.5) ≈ [0.5, 0.5] | |
| 219 end | |
| 220 | |
| 221 @testset "Unit arc" begin | |
| 222 A = arc([1,0],[0,1],1) | |
| 223 @test A(0) ≈ [1,0] | |
| 224 @test A(1) ≈ [0,1] | |
| 225 @testset for t ∈ range(0,1,13) | |
| 226 @test A(t) ≈ [cos(t*π/2), sin(t*π/2)] | |
| 227 end | |
| 228 end | |
| 229 | |
| 230 @testset "Inverted unit arc" begin | |
| 231 A = arc([1,0],[0,1],-1) | |
| 232 @test A(0) ≈ [1,0] | |
| 233 @test A(1) ≈ [0,1] | |
| 234 @testset "Inverted unit arc t=$t" for t ∈ range(0,1,13) | |
| 235 @test A(t) ≈ [1+cos(-π/2 - t*π/2), 1+sin(-π/2 - t*π/2)] | |
| 236 end | |
| 237 end | |
| 238 | |
| 239 @testset "Quarters of unit circle" begin | |
| 240 unitvec(θ) = [cos(θ), sin(θ)] | |
| 241 @testset "θ ∈ ($(i)π/4, $(i+2)π/4)" for i ∈ range(0, step=1, length=8) | |
| 242 θ = i*π/4 | |
| 243 @testset let θ₀ = θ, θ₁ = θ+π/2, r = 1 | |
| 244 A = arc(unitvec(θ₀), unitvec(θ₁), r) | |
| 245 @test A(0) ≈ unitvec(θ) | |
| 246 @test A(1/3) ≈ unitvec(θ+π/6) | |
| 247 @test A(1/2) ≈ unitvec(θ+π/4) | |
| 248 @test A(2/3) ≈ unitvec(θ+π/3) | |
| 249 @test A(1) ≈ unitvec(θ+π/2) | |
| 250 end | |
| 251 | |
| 252 @testset let θ₀ = θ+π/2, θ₁ = θ, r = -1 | |
| 253 A = arc(unitvec(θ₀), unitvec(θ₁), r) | |
| 254 @test A(0) ≈ unitvec(θ+π/2) | |
| 255 @test A(1/3) ≈ unitvec(θ+π/3) | |
| 256 @test A(1/2) ≈ unitvec(θ+π/4) | |
| 257 @test A(2/3) ≈ unitvec(θ+π/6) | |
| 258 @test A(1) ≈ unitvec(θ) | |
| 259 end | |
| 260 end | |
| 261 end | |
| 262 | |
| 263 @test_throws DomainError arc([-1,0], [1,0], 0.7) | |
| 264 end | |
| 265 | |
| 165 @testset "TransfiniteInterpolationSurface" begin | 266 @testset "TransfiniteInterpolationSurface" begin |
| 166 @testset "Constructors" begin | 267 @testset "Constructors" begin |
| 167 @test TransfiniteInterpolationSurface(t->[1,2], t->[2,1], t->[0,0], t->[1,1]) isa TransfiniteInterpolationSurface | 268 @test TransfiniteInterpolationSurface(t->[1,2], t->[2,1], t->[0,0], t->[1,1]) isa TransfiniteInterpolationSurface |
| 168 | 269 |
| 169 cs = polygon_edges([0,0],[1,0],[1,1],[0,1]) | 270 cs = polygon_edges([0,0],[1,0],[1,1],[0,1]) |
| 201 @test ti(1/2, 0) == (a+b)/2 | 302 @test ti(1/2, 0) == (a+b)/2 |
| 202 @test ti(1/2, 1) == (c+d)/2 | 303 @test ti(1/2, 1) == (c+d)/2 |
| 203 @test ti(0, 1/2) == (a+d)/2 | 304 @test ti(0, 1/2) == (a+d)/2 |
| 204 @test ti(1, 1/2) == (b+c)/2 | 305 @test ti(1, 1/2) == (b+c)/2 |
| 205 | 306 |
| 206 # TODO: Some test with curved edges? | 307 a, b, c, d = [0,0],[1,1/2],[1,3/2],[0,1] |
| 308 ti = TransfiniteInterpolationSurface( | |
| 309 t->@SVector[t, t^2/2], | |
| 310 LineSegment(b,c), | |
| 311 LineSegment(c,d), | |
| 312 LineSegment(d,a), | |
| 313 ) | |
| 314 | |
| 315 @test ti(0,0) == a | |
| 316 @test ti(1,0) == b | |
| 317 @test ti(1,1) == c | |
| 318 @test ti(0,1) == d | |
| 319 | |
| 320 @test ti(1/2, 0) == [1/2, 1/8] | |
| 321 @test ti(1/2, 1) == (c+d)/2 | |
| 322 @test ti(0, 1/2) == (a+d)/2 | |
| 323 @test ti(1, 1/2) == (b+c)/2 | |
| 207 end | 324 end |
| 208 | 325 |
| 209 @testset "check_transfiniteinterpolation" begin | 326 @testset "check_transfiniteinterpolation" begin |
| 210 cs = polygon_edges([0,0],[1,0],[1,1],[0,1]) | 327 cs = polygon_edges([0,0],[1,0],[1,1],[0,1]) |
| 211 ti = TransfiniteInterpolationSurface(cs...) | 328 ti = TransfiniteInterpolationSurface(cs...) |
| 266 mid(x,y) = (x+y)/2 | 383 mid(x,y) = (x+y)/2 |
| 267 @test Grids.jacobian(ti, [1/2, 0]) ≈ [b-a mid(c,d)-mid(a,b)] | 384 @test Grids.jacobian(ti, [1/2, 0]) ≈ [b-a mid(c,d)-mid(a,b)] |
| 268 @test Grids.jacobian(ti, [1/2, 1]) ≈ [c-d mid(c,d)-mid(a,b)] | 385 @test Grids.jacobian(ti, [1/2, 1]) ≈ [c-d mid(c,d)-mid(a,b)] |
| 269 @test Grids.jacobian(ti, [0, 1/2]) ≈ [mid(b,c)-mid(a,d) d-a] | 386 @test Grids.jacobian(ti, [0, 1/2]) ≈ [mid(b,c)-mid(a,d) d-a] |
| 270 @test Grids.jacobian(ti, [1, 1/2]) ≈ [mid(b,c)-mid(a,d) c-b] | 387 @test Grids.jacobian(ti, [1, 1/2]) ≈ [mid(b,c)-mid(a,d) c-b] |
| 271 | 388 end |
| 272 # TODO: Some test with curved edges? | 389 end |
| 273 end | |
| 274 end |
