changeset 2072:c36812de3f2d feature/grids/geometry_functions

Add parameter validation when evaluating jacobian for transfinite interpolation
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 17 Feb 2026 20:40:21 +0100
parents 9e9c56f5a656
children bc09d0bfac65
files src/Grids/geometry.jl test/Grids/geometry_test.jl
diffstat 2 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/geometry.jl	Tue Feb 17 20:37:53 2026 +0100
+++ b/src/Grids/geometry.jl	Tue Feb 17 20:40:21 2026 +0100
@@ -306,6 +306,9 @@
 end
 
 function Grids.jacobian(s::TransfiniteInterpolationSurface, ξ̄)
+    if ξ̄ ∉ unitsquare()
+        throw(DomainError(ξ̄, "Transfinite interpolation was called with parameters outside the unit square."))
+    end
     u, v = ξ̄
 
     c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄
--- a/test/Grids/geometry_test.jl	Tue Feb 17 20:37:53 2026 +0100
+++ b/test/Grids/geometry_test.jl	Tue Feb 17 20:40:21 2026 +0100
@@ -393,5 +393,13 @@
         @test Grids.jacobian(ti, [1/2, 1]) ≈ [c-d mid(c,d)-mid(a,b)]
         @test Grids.jacobian(ti, [0, 1/2]) ≈ [mid(b,c)-mid(a,d) d-a]
         @test Grids.jacobian(ti, [1, 1/2]) ≈ [mid(b,c)-mid(a,d) c-b]
+
+        @testset "Out of domain error" begin
+            @test_throws DomainError Grids.jacobian(ti, [-0.1, 0])
+            @test_throws DomainError Grids.jacobian(ti, [1.1, 0])
+            @test_throws DomainError Grids.jacobian(ti, [0, -0.1])
+            @test_throws DomainError Grids.jacobian(ti, [0, 1.1])
+            @test_throws DomainError Grids.jacobian(ti, [1.1, -0.1])
+        end
     end
 end