changeset 1998:6dd00ea0511a feature/grids/manifolds

Add check if the logical coordinates are in the parameter space when calling a chart
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 25 Apr 2025 08:28:34 +0200
parents 6dc6dfd11820
children a1b2453c02c9
files src/Grids/manifolds.jl test/Grids/manifolds_test.jl
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/manifolds.jl	Fri Apr 25 08:18:36 2025 +0200
+++ b/src/Grids/manifolds.jl	Fri Apr 25 08:28:34 2025 +0200
@@ -9,9 +9,15 @@
 end
 
 Base.ndims(::Chart{D}) where D = D
-(c::Chart)(ξ) = c.mapping(ξ)
 parameterspace(c::Chart) = c.parameterspace
 
+function (c::Chart)(ξ)
+    if ξ ∉ parameterspace(c)
+        throw(DomainError(ξ, "chart was called logical coordinates outside the parameterspace. If this was inteded, use the `mapping` field from the Chart struct instead."))
+    end
+    return c.mapping(ξ)
+end
+
 """
     jacobian(c::Chart, ξ)
 
--- a/test/Grids/manifolds_test.jl	Fri Apr 25 08:18:36 2025 +0200
+++ b/test/Grids/manifolds_test.jl	Fri Apr 25 08:28:34 2025 +0200
@@ -18,10 +18,15 @@
     Grids.jacobian(::typeof(X), ξ) = @SVector[2,2]
     c = Chart(X, unitsquare())
     @test c isa Chart{2}
-    @test c([3,2]) == [6,4]
     @test parameterspace(c) == unitsquare()
     @test ndims(c) == 2
 
+    @testset "Calling" begin
+        c = Chart(X, unitsquare())
+        @test c([.3,.2]) == [.6,.4]
+        @test_throws DomainError c([3,2])
+    end
+
     @test jacobian(c, [3,2]) == [2,2]
 
     @test Set(boundary_identifiers(Chart(X,unitsquare()))) == Set([east(),west(),south(),north()])