changeset 1842:f2b32da29b73 feature/grids/manifolds

Introduce mapped_grid for ParameterSpace and simplify implementation of equidistant_grid(::Chart)
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 22 Oct 2024 15:32:33 +0200
parents 1c58005429fd
children ea98f03e18e0
files src/Grids/equidistant_grid.jl src/Grids/mapped_grid.jl test/Grids/mapped_grid_test.jl
diffstat 3 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/equidistant_grid.jl	Tue Oct 22 08:50:23 2024 +0200
+++ b/src/Grids/equidistant_grid.jl	Tue Oct 22 15:32:33 2024 +0200
@@ -155,12 +155,7 @@
 equidistant_grid(hb::HyperBox, dims::Vararg{Int}) = equidistant_grid(limits(hb)..., dims...)
 
 function equidistant_grid(c::Chart, dims::Vararg{Int})
-    lg = equidistant_grid(parameterspace(c), dims...)
-    return MappedGrid(
-        lg,
-        map(c,lg),
-        map(ξ->jacobian(c, ξ), lg),
-    )
+    mapped_grid(c, ξ->jacobian(c,ξ), parameterspace(c), dims...)
 end
 
 
--- a/src/Grids/mapped_grid.jl	Tue Oct 22 08:50:23 2024 +0200
+++ b/src/Grids/mapped_grid.jl	Tue Oct 22 15:32:33 2024 +0200
@@ -121,6 +121,17 @@
 end
 
 """
+    mapped_grid(x, J, parameterspace, size)
+
+A `MappedGrid` with logical grid `lg`. Physical coordinates and Jacobian are
+determined by the functions `x` and `J`.
+"""
+function mapped_grid(x, J, ps::ParameterSpace, size::Vararg{Int})
+    lg = equidistant_grid(ps, size...)
+    return mapped_grid(lg, x, J)
+end
+
+"""
     metric_tensor(g::MappedGrid)
 
 The metric tensor of `g` as a grid function.
--- a/test/Grids/mapped_grid_test.jl	Tue Oct 22 08:50:23 2024 +0200
+++ b/test/Grids/mapped_grid_test.jl	Tue Oct 22 15:32:33 2024 +0200
@@ -278,11 +278,13 @@
     mg = mapped_grid(x̄, J, 10, 11)
     @test mg isa MappedGrid{SVector{2,Float64}, 2}
 
-    lg = equidistant_grid((0,0), (1,1), 10, 11)
+    lg = equidistant_grid(unitsquare(), 10, 11)
     @test logical_grid(mg) == lg
     @test collect(mg) == map(x̄, lg)
 
     @test mapped_grid(lg, x̄, J) == mg
+
+    @test mapped_grid(x̄, J, unitsquare(), 10, 11) == mg
 end
 
 @testset "metric_tensor" begin