changeset 1581:f77c5309dd2b feature/grids/manifolds

Rename ConcreteChart to Chart and remove the abstarct chart type
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 25 Apr 2024 22:32:54 +0200
parents fdee60ab8c4e
children d9d767980d6f d7483e8af705
files src/Grids/manifolds.jl test/Grids/manifolds_test.jl test/Grids/mapped_grid_test.jl
diffstat 3 files changed, 27 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/manifolds.jl	Thu Apr 25 22:15:12 2024 +0200
+++ b/src/Grids/manifolds.jl	Thu Apr 25 22:32:54 2024 +0200
@@ -66,42 +66,39 @@
 unitsimplex(D) = unitsimplex(Float64, D)
 
 """
+    Chart{D}
 
 A parametrized description of a manifold or part of a manifold.
-
-Should implement a methods for
-* `parameterspace`
-* `(::Chart)(ξs...)`
 """
-abstract type Chart{D} end
-# abstract type Chart{D,R} end
-
-domain_dim(::Chart{D}) where D = D
-# range_dim(::Chart{D,R}) where {D,R} = R
-
-"""
-The parameterspace of a chart
-"""
-function parameterspace end
-
-
-# TODO: Add trait for if there is a jacobian available?
-# Add package extension to allow calling the getter function anyway if it's not available
-# And can we add an informative error that ForwardDiff could be loaded to make it work?
-# Or can we handle this be custom implementations? For sometypes in the library it can be implemented explicitly.
-# And as an example for ConcreteChart it can be implemented by the user like
-# c = ConcreteChart(...)
-# jacobian(c::typeof(c)) = ...
-
-struct ConcreteChart{D, PST<:ParameterSpace{D}, MT} <: Chart{D}
+struct Chart{D, PST<:ParameterSpace{D}, MT}
     mapping::MT
     parameterspace::PST
 end
 
-(c::ConcreteChart)(ξ) = c.mapping(ξ)
-parameterspace(c::ConcreteChart) = c.parameterspace
+domain_dim(::Chart{D}) where D = D
+(c::Chart)(ξ) = c.mapping(ξ)
+parameterspace(c::Chart) = c.parameterspace
+
+"""
+    jacobian(c::Chart, ξ)
 
-jacobian(c::ConcreteChart, ξ) = jacobian(c.mapping, ξ)
+The jacobian of the mapping evaluated at `ξ`. This defers to the
+implementation of `jacobian` for the mapping itself. If no implementation is
+available one can easily be specified for either the mapping function or the
+chart itself.
+```julia
+c = Chart(f, ps)
+jacobian(f::typeof(f), ξ) = f′(ξ)
+```
+or
+```julia
+c = Chart(f, ps)
+jacobian(c::typeof(c),ξ) = f′(ξ)
+```
+which will both allow calling `jacobian(c,ξ)`.
+"""
+jacobian(c::Chart, ξ) = jacobian(c.mapping, ξ)
+
 
 """
     Atlas
--- a/test/Grids/manifolds_test.jl	Thu Apr 25 22:15:12 2024 +0200
+++ b/test/Grids/manifolds_test.jl	Thu Apr 25 22:32:54 2024 +0200
@@ -50,10 +50,7 @@
 end
 
 @testset "Chart" begin
-end
-
-@testset "ConcreteChart" begin
-    c = ConcreteChart(x->2x, unitsquare())
+    c = Chart(x->2x, unitsquare())
     @test c isa Chart{2}
     @test c([3,2]) == [6,4]
     @test parameterspace(c) == unitsquare()
--- a/test/Grids/mapped_grid_test.jl	Thu Apr 25 22:15:12 2024 +0200
+++ b/test/Grids/mapped_grid_test.jl	Thu Apr 25 22:32:54 2024 +0200
@@ -186,7 +186,7 @@
 
 
     @testset "mapped_grid(::Chart)" begin
-        c = ConcreteChart(unitsquare()) do (ξ,η)
+        c = Chart(unitsquare()) do (ξ,η)
             @SVector[2ξ, 3η]
         end
         Grids.jacobian(c::typeof(c), ξ̄) = @SMatrix[2 0; 0 3]