Mercurial > repos > public > sbplib_julia
changeset 1563:6e910408c51a feature/sbp_operators/laplace_curvilinear
Merge manifolds
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 25 Apr 2024 10:20:43 +0200 |
parents | efa994405c38 (current diff) 81e97d3bec8c (diff) |
children | d7483e8af705 |
files | src/Grids/Grids.jl |
diffstat | 3 files changed, 247 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
diff -r efa994405c38 -r 6e910408c51a src/Grids/Grids.jl --- a/src/Grids/Grids.jl Thu Apr 25 09:34:34 2024 +0200 +++ b/src/Grids/Grids.jl Thu Apr 25 10:20:43 2024 +0200 @@ -5,6 +5,21 @@ using Sbplib.LazyTensors using StaticArrays + +export HyperBox +export Simplex +export Interval +export Rectangle +export Box +export Triangle +export Tetrahedron + +export limits +export unitinterval +export unitsquare +export unitcube +export unithyperbox + # Grid export Grid export coordinate_size @@ -44,6 +59,7 @@ abstract type BoundaryIdentifier end +include("manifolds.jl") include("grid.jl") include("tensor_grid.jl") include("equidistant_grid.jl")
diff -r efa994405c38 -r 6e910408c51a src/Grids/manifolds.jl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Grids/manifolds.jl Thu Apr 25 10:20:43 2024 +0200 @@ -0,0 +1,188 @@ +""" + ParameterSpace{D} + +A space of parameters of dimension `D`. Used with `Chart` to indicate which +parameters are valid for that chart. + +Common parameter spaces are created using the functions unit sized spaces +* `unitinterval` +* `unitrectangle` +* `unitbox` +* `unittriangle` +* `unittetrahedron` +* `unithyperbox` +* `unitsimplex` + +See also: [`Interval`](@ref), [`Rectangle`](@ref), [`Box`](@ref), +[`Triangle`](@ref), [`Tetrahedron`](@ref), [`HyperBox`](@ref), +[`Simplex`](@ref), +""" +abstract type ParameterSpace{D} end + +struct HyperBox{T,D} <: ParameterSpace{D} + a::SVector{D,T} + b::SVector{D,T} +end + +function HyperBox(a,b) + T = SVector{length(a)} + HyperBox(convert(T,a), convert(T,b)) +end + +Interval{T} = HyperBox{T,1} +Rectangle{T} = HyperBox{T,2} +Box{T} = HyperBox{T,3} + +limits(box::HyperBox, d) = (box.a[d], box.b[d]) +limits(box::HyperBox) = (box.a, box.b) + +unitinterval(T=Float64) = unithyperbox(T,1) +unitsquare(T=Float64) = unithyperbox(T,2) +unitcube(T=Float64) = unithyperbox(T,3) +unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D))) +unithyperbox(D) = unithyperbox(Float64,D) + + +struct Simplex{T,D} <: ParameterSpace{D} + verticies::NTuple{D,SVector{D,T}} +end + +Triangle{T} = Simplex{T,2} +Tetrahedron{T} = Simplex{T,3} + +unittriangle(T) = unitsimplex(T,2) +unittetrahedron(T) = unitsimplex(T,3) +function unitsimplex(T,D) + z = @SVector zeros(T,D) + unitelement = one(eltype(z)) + verticies = ntuple(i->setindex(z, unitelement, i), 4) + return Simplex(verticies) +end + + +""" + +A parametrized description of a manifold or part of a manifold. + +Should implement a methods for +* `parameterspace` +* `(::Chart)(ξs...)` + +There is a default implementation for `(::Chart{D})(::SVector{D})` +""" +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 + +(c::Chart{D})(x̄::SVector{D}) where D = c(x̄...) + + +struct ConcereteChart{PST<:ParameterSpace, MT} + parameterspace::PST + mapping::MT +end + +(c::Chart)(x̄) = c.mapping(x̄) + + +""" + Atlas + +A collection of charts and their connections. +Should implement methods for `charts` and +""" +abstract type Atlas end + +""" + charts(::Atlas) + +The colloction of charts in the atlas. +""" +function charts end + +""" + connections + +TBD: What exactly should this return? + +""" + +struct CartesianAtlas <: Atlas + charts::Matrix{Chart} +end + +charts(a::CartesianAtlas) = a.charts + +struct UnstructuredAtlas <: Atlas + charts::Vector{Chart} + connections +end + +charts(a::UnstructuredAtlas) = a.charts + + +### +# Geometry +### + +abstract type Curve end +abstract type Surface end + + +struct Line{PT} <: Curve + p::PT + tangent::PT +end + +(c::Line)(s) = c.p + s*c.tangent + + +struct LineSegment{PT} <: Curve + a::PT + b::PT +end + +(c::LineSegment)(s) = (1-s)*c.a + s*c.b + + +struct Circle{T,PT} <: Curve + c::PT + r::T +end + +(c::Circle)(θ) = c.c + r*@SVector[cos(Θ), sin(Θ)] + +struct TransfiniteInterpolationSurface{T1,T2,T3,T4} <: Surface + c₁::T1 + c₂::T2 + c₃::T3 + c₄::T4 +end + +function (s::TransfiniteInterpolationSurface)(u,v) + c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄ + P₀₀ = c₁(0) + P₁₀ = c₂(0) + P₁₁ = c₃(0) + P₀₁ = c₄(0) + return (1-v)*c₁(u) + u*c₂(v) + v*c₃(1-u) + (1-u)*c₄(1-v) - ( + (1-u)*(1-v)*P₀₀ + u*(1-v)*P₁₀ + u*v*P₁₁ + (1-u)*v*P₀₁ + ) +end + +function (s::TransfiniteInterpolationSurface)(ξ̄::AbstractArray) + s(ξ̄...) +end + + +function polygon_sides(Ps...) + n = length(Ps) + return [t->line(t,Ps[i],Ps[mod1(i+1,n)]) for i ∈ eachindex(Ps)] +end
diff -r efa994405c38 -r 6e910408c51a test/Grids/manifolds_test.jl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/Grids/manifolds_test.jl Thu Apr 25 10:20:43 2024 +0200 @@ -0,0 +1,43 @@ +using Test + +using Sbplib.Grids +using Sbplib.RegionIndices +using Sbplib.LazyTensors + +# using StaticArrays + +@testset "HyperBox" begin + @test HyperBox([1,1], [2,2]) isa HyperBox{Int, 2} + + @test limits(HyperBox([1,2], [3,4])) == ([1,2], [3,4]) + @test limits(HyperBox([1,2], [3,4]), 1) == (1,3) + @test limits(HyperBox([1,2], [3,4]), 2) == (2,4) + + @test unitinterval() isa HyperBox{Float64,1} + @test limits(unitinterval()) == ([0], [1]) + + @test unitinterval(Int) isa HyperBox{Int,1} + @test limits(unitinterval(Int)) == ([0], [1]) + + @test unitsquare() isa HyperBox{Float64,2} + @test limits(unitsquare()) == ([0,0],[1,1]) + + @test unitcube() isa HyperBox{Float64,3} + @test limits(unitcube()) == ([0,0,0],[1,1,1]) + + @test unithyperbox(4) isa HyperBox{Float64,4} + @test limits(unithyperbox(4)) == ([0,0,0,0],[1,1,1,1]) +end + +@testset "Simplex" begin + @test Simplex([1,2], [3,4]) isa Simplex{Int, 2} + @test Simplex([1,2,3], [4,5,6]) isa Simplex{Int, 3} +end + +@testset "Chart" begin + +end + +@testset "Atlas" begin + +end