changeset 1913:e97f4352b8d0 feature/grids/manifolds

Merge feature/grids/parameter_spaces
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 01 Feb 2025 23:20:31 +0100
parents 04c251bccbd4 (current diff) dcbe8119fb0a (diff)
children e7f8d11c4670
files src/Grids/mapped_grid.jl
diffstat 2 files changed, 106 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
diff -r 04c251bccbd4 -r e97f4352b8d0 src/Grids/mapped_grid.jl
--- a/src/Grids/mapped_grid.jl	Sat Feb 01 22:17:39 2025 +0100
+++ b/src/Grids/mapped_grid.jl	Sat Feb 01 23:20:31 2025 +0100
@@ -92,7 +92,6 @@
     )
 end
 
-# TODO: Make sure all methods of `mapped_grid` are implemented correctly and tested.
 """
     mapped_grid(x, J, size...)
 
@@ -102,8 +101,7 @@
 """
 function mapped_grid(x, J, size::Vararg{Int})
     D = length(size)
-        lg = equidistant_grid(ntuple(i->0., D), ntuple(i->1., D), size...) # TODO: Clean this up with ParamaterSpace once feature/grids/manifolds is merged
-    return mapped_grid(x, J, lg)
+    return mapped_grid(x, J, unithyperbox(D), size...)
 end
 
 """
diff -r 04c251bccbd4 -r e97f4352b8d0 src/Grids/parameter_space.jl
--- a/src/Grids/parameter_space.jl	Sat Feb 01 22:17:39 2025 +0100
+++ b/src/Grids/parameter_space.jl	Sat Feb 01 23:20:31 2025 +0100
@@ -1,45 +1,73 @@
 """
     ParameterSpace{D}
 
-A space of parameters of dimension `D`. Used with `Chart` to indicate which
-parameters are valid for that chart.
+A space of parameters of dimension `D`.
 
-Common parameter spaces are created using the functions unit sized spaces
-* `unitinterval`
-* `unitrectangle`
-* `unitbox`
-* `unittriangle`
-* `unittetrahedron`
-* `unithyperbox`
-* `unitsimplex`
+Common parameter spaces are created using functions for unit sized spaces
+* [`unitinterval`](@ref)
+* [`unitsquare`](@ref)
+* [`unitcube`](@ref)
+* [`unithyperbox`](@ref)
+* [`unittriangle`](@ref)
+* [`unittetrahedron`](@ref)
+* [`unitsimplex`](@ref)
 
-See also: [`Interval`](@ref), [`Rectangle`](@ref), [`Box`](@ref),
-[`Triangle`](@ref), [`Tetrahedron`](@ref), [`HyperBox`](@ref),
-[`Simplex`](@ref),
+See also: [`Interval`](@ref), [`HyperBox`](@ref),
+[`Simplex`](@ref).
 """
 abstract type ParameterSpace{D} end
 Base.ndims(::ParameterSpace{D}) where D = D
 
+"""
+    Interval{T} <: ParameterSpace{1}
+
+A `ParameterSpace` representing an interval.
+"""
 struct Interval{T} <: ParameterSpace{1}
     a::T
     b::T
+end
 
-    function Interval(a,b)
-        a, b = promote(a, b)
-        new{typeof(a)}(a,b)
-    end
+"""
+    Interval(a,b)
+
+An interval with limits `a` and `b`.
+"""
+function Interval(a,b)
+    a, b = promote(a, b)
+    Interval{typeof(a)}(a,b)
 end
 
+"""
+    limits(i::Interval)
+
+The limits of the interval.
+"""
 limits(i::Interval) = (i.a, i.b)
 
+"""
+    unitinterval(T=Float64)
+
+The interval ``(0,1)``.
+"""
 unitinterval(T=Float64) = Interval(zero(T), one(T))
 
 
+"""
+    HyperBox{T,D} <: ParameterSpace{D}
+
+A `ParameterSpace` representing a hyper box.
+"""
 struct HyperBox{T,D} <: ParameterSpace{D}
     a::SVector{D,T}
     b::SVector{D,T}
 end
 
+"""
+    HyperBox(a,b)
+
+A `HyperBox` with lower limits `a` and upper limits `b` for each dimension.
+"""
 function HyperBox(a,b)
     ET = promote_type(eltype(a),eltype(b))
     T = SVector{length(a),ET}
@@ -49,15 +77,48 @@
 Rectangle{T} = HyperBox{T,2}
 Box{T} = HyperBox{T,3}
 
+"""
+    limits(box::HyperBox, d)
+
+Limits of `box` along dimension `d`.
+"""
 limits(box::HyperBox, d) = (box.a[d], box.b[d])
+
+"""
+    limits(box::HyperBox)
+
+The lower and upper limits of `box` as tuples.
+"""
 limits(box::HyperBox) = (box.a, box.b)
 
+"""
+    unitsquare(T=Float64)
+
+The square starting at ``(0,0)`` with side length 1.
+"""
 unitsquare(T=Float64) = unithyperbox(T,2)
+
+"""
+    unitcube(T=Float64)
+
+The cube starting at ``(0,0,0)`` with side length 1.
+"""
 unitcube(T=Float64) = unithyperbox(T,3)
+
+"""
+    unithyperbox(T=Float64, D)
+
+The hypercube in dimension `D` starting at ``(0,0,0,...)`` with side length 1.
+"""
 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D)))
 unithyperbox(D) = unithyperbox(Float64,D)
 
 
+"""
+    Simplex{T,D,NV} <: ParameterSpace{D}
+
+A `ParameterSpace` representing a simplex.
+"""
 struct Simplex{T,D,NV} <: ParameterSpace{D}
     verticies::NTuple{NV,SVector{D,T}}
 
@@ -65,6 +126,11 @@
     Simplex(::Tuple{}) = throw(ArgumentError("Must provide at least one vertex."))
 end
 
+"""
+    Simplex(verticies...)
+
+A simplex with the given vierticies.
+"""
 function Simplex(verticies::Vararg{AbstractArray})
     ET = mapreduce(eltype,promote_type,verticies)
     T = SVector{length(verticies[1]),ET}
@@ -72,13 +138,35 @@
     return Simplex(Tuple(convert(T,v) for v ∈ verticies))
 end
 
+"""
+    verticies(s::Simplex)
+
+Verticies of `s`.
+"""
 verticies(s::Simplex) = s.verticies
 
 Triangle{T} = Simplex{T,2}
 Tetrahedron{T} = Simplex{T,3}
 
+"""
+    unittriangle(T=Float64)
+
+The simplex with verticies ``(0,0)``, ``(1,0)``, and ``(0,1)``.
+"""
 unittriangle(T=Float64) = unitsimplex(T,2)
+
+"""
+    unittetrahedron(T=Float64)
+
+The simplex with verticies ``(0,0,0)``, ``(1,0,0)``, ``(0,1,0)``, and ``(0,0,1)``.
+"""
 unittetrahedron(T=Float64) = unitsimplex(T,3)
+
+"""
+    unitsimplex(T=Float64,D)
+
+The unit simplex in dimension `D` with verticies ``(0,0,0,...)``, ``(1,0,0,...)``, ``(0,1,0,...)``, ``(0,0,1,...)``...
+"""
 function unitsimplex(T,D)
     z = @SVector zeros(T,D)
     unitelement = one(eltype(z))