Mercurial > repos > public > sbplib_julia
changeset 1774:035af82f559a feature/grids/curvilinear
Rename logicalgrid to logical_grid
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sun, 15 Sep 2024 18:03:37 +0200 |
parents | 08e52f442872 |
children | ecec2b0eea0f |
files | src/Grids/Grids.jl src/Grids/mapped_grid.jl test/Grids/mapped_grid_test.jl |
diffstat | 3 files changed, 35 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/Grids.jl Sun Sep 15 18:00:40 2024 +0200 +++ b/src/Grids/Grids.jl Sun Sep 15 18:03:37 2024 +0200 @@ -41,7 +41,7 @@ # MappedGrid export MappedGrid export jacobian -export logicalgrid +export logical_grid export mapped_grid export jacobian_determinant export metric_tensor
--- a/src/Grids/mapped_grid.jl Sun Sep 15 18:00:40 2024 +0200 +++ b/src/Grids/mapped_grid.jl Sun Sep 15 18:03:37 2024 +0200 @@ -5,20 +5,20 @@ coordinates. The physical coordinates and the Jacobian are stored as grid functions corresponding to the logical grid. -See also: [`logicalgrid`](@ref), [`jacobian`](@ref), [`metric_tensor`](@ref). +See also: [`logical_grid`](@ref), [`jacobian`](@ref), [`metric_tensor`](@ref). """ struct MappedGrid{T,D, GT<:Grid{<:Any,D}, CT<:AbstractArray{T,D}, JT<:AbstractArray{<:AbstractMatrix{<:Any}, D}} <: Grid{T,D} - logicalgrid::GT + logical_grid::GT physicalcoordinates::CT jacobian::JT """ - MappedGrid(logicalgrid, physicalcoordinates, jacobian) + MappedGrid(logical_grid, physicalcoordinates, jacobian) A MappedGrid with the given physical coordinates and jacobian. """ - function MappedGrid(logicalgrid::GT, physicalcoordinates::CT, jacobian::JT) where {T,D, GT<:Grid{<:Any,D}, CT<:AbstractArray{T,D}, JT<:AbstractArray{<:AbstractMatrix{<:Any}, D}} - if !(size(logicalgrid) == size(physicalcoordinates) == size(jacobian)) + function MappedGrid(logical_grid::GT, physicalcoordinates::CT, jacobian::JT) where {T,D, GT<:Grid{<:Any,D}, CT<:AbstractArray{T,D}, JT<:AbstractArray{<:AbstractMatrix{<:Any}, D}} + if !(size(logical_grid) == size(physicalcoordinates) == size(jacobian)) throw(ArgumentError("Sizes must match")) end @@ -26,26 +26,24 @@ throw(ArgumentError("The size of the jacobian must match the dimensions of the grid and coordinates")) end - return new{T,D,GT,CT,JT}(logicalgrid, physicalcoordinates, jacobian) + return new{T,D,GT,CT,JT}(logical_grid, physicalcoordinates, jacobian) end end function Base.:(==)(a::MappedGrid, b::MappedGrid) - same_logicalgrid = logicalgrid(a) == logicalgrid(b) + same_logical_grid = logical_grid(a) == logical_grid(b) same_coordinates = collect(a) == collect(b) same_jacobian = jacobian(a) == jacobian(b) - return same_logicalgrid && same_coordinates && same_jacobian + return same_logical_grid && same_coordinates && same_jacobian end -# Review: rename function logicalgrid to logical_grid -# for consistency with mapped_grid. """ - logicalgrid(g::MappedGrid) + logical_grid(g::MappedGrid) The logical grid of `g`. """ -logicalgrid(g::MappedGrid) = g.logicalgrid +logical_grid(g::MappedGrid) = g.logical_grid """ jacobian(g::MappedGrid) @@ -57,27 +55,27 @@ # Indexing interface Base.getindex(g::MappedGrid, I::Vararg{Int}) = g.physicalcoordinates[I...] -Base.eachindex(g::MappedGrid) = eachindex(g.logicalgrid) +Base.eachindex(g::MappedGrid) = eachindex(g.logical_grid) -Base.firstindex(g::MappedGrid, d) = firstindex(g.logicalgrid, d) -Base.lastindex(g::MappedGrid, d) = lastindex(g.logicalgrid, d) +Base.firstindex(g::MappedGrid, d) = firstindex(g.logical_grid, d) +Base.lastindex(g::MappedGrid, d) = lastindex(g.logical_grid, d) # Iteration interface Base.iterate(g::MappedGrid) = iterate(g.physicalcoordinates) Base.iterate(g::MappedGrid, state) = iterate(g.physicalcoordinates, state) Base.IteratorSize(::Type{<:MappedGrid{<:Any, D}}) where D = Base.HasShape{D}() -Base.length(g::MappedGrid) = length(g.logicalgrid) -Base.size(g::MappedGrid) = size(g.logicalgrid) -Base.size(g::MappedGrid, d) = size(g.logicalgrid, d) +Base.length(g::MappedGrid) = length(g.logical_grid) +Base.size(g::MappedGrid) = size(g.logical_grid) +Base.size(g::MappedGrid, d) = size(g.logical_grid, d) -boundary_identifiers(g::MappedGrid) = boundary_identifiers(g.logicalgrid) -boundary_indices(g::MappedGrid, id::TensorGridBoundary) = boundary_indices(g.logicalgrid, id) +boundary_identifiers(g::MappedGrid) = boundary_identifiers(g.logical_grid) +boundary_indices(g::MappedGrid, id::TensorGridBoundary) = boundary_indices(g.logical_grid, id) # Review: Error when calling plot(boundary_grid(g, id)) # Currently need to collect first, i.e., plot(collect(boundary_grid(g, id))) function boundary_grid(g::MappedGrid, id::TensorGridBoundary) - b_indices = boundary_indices(g.logicalgrid, id) + b_indices = boundary_indices(g.logical_grid, id) # Calculate indices of needed jacobian components D = ndims(g) @@ -90,7 +88,7 @@ boundary_physicalcoordinates = @view g.physicalcoordinates[b_indices...] return MappedGrid( - boundary_grid(g.logicalgrid, id), + boundary_grid(g.logical_grid, id), boundary_physicalcoordinates, boundary_jacobian, )
--- a/test/Grids/mapped_grid_test.jl Sun Sep 15 18:00:40 2024 +0200 +++ b/test/Grids/mapped_grid_test.jl Sun Sep 15 18:03:37 2024 +0200 @@ -37,11 +37,11 @@ @test mg isa Grid{SVector{2, Float64},2} @test jacobian(mg) isa Array{<:AbstractMatrix} - @test logicalgrid(mg) isa Grid + @test logical_grid(mg) isa Grid @test collect(mg) == x̄ @test jacobian(mg) == J - @test logicalgrid(mg) == lg + @test logical_grid(mg) == lg x̄ = map(ξ̄ -> @SVector[ξ̄[1],ξ̄[2], ξ̄[1] + ξ̄[2]], lg) @@ -50,11 +50,11 @@ @test mg isa Grid{SVector{3, Float64},2} @test jacobian(mg) isa Array{<:AbstractMatrix} - @test logicalgrid(mg) isa Grid + @test logical_grid(mg) isa Grid @test collect(mg) == x̄ @test jacobian(mg) == J - @test logicalgrid(mg) == lg + @test logical_grid(mg) == lg sz1 = (10,11) sz2 = (10,12) @@ -247,7 +247,7 @@ ] function expected_bg(mg, bId, Jb) - lg = logicalgrid(mg) + lg = logical_grid(mg) return MappedGrid( boundary_grid(lg, bId), map(x̄, boundary_grid(lg, bId)), @@ -279,7 +279,7 @@ @test mg isa MappedGrid{SVector{2,Float64}, 2} lg = equidistant_grid((0,0), (1,1), 10, 11) - @test logicalgrid(mg) == lg + @test logical_grid(mg) == lg @test collect(mg) == map(x̄, lg) @test mapped_grid(lg, x̄, J) == mg @@ -293,7 +293,7 @@ ] g = mapped_grid(x̄, J, 10, 11) - J = map(logicalgrid(g)) do (ξ,η) + J = map(logical_grid(g)) do (ξ,η) 2η^2 - ξ end @test jacobian_determinant(g) ≈ J @@ -315,7 +315,7 @@ ] g = mapped_grid(x̄, J, 10, 11) - G = map(logicalgrid(g)) do (ξ,η) + G = map(logical_grid(g)) do (ξ,η) @SMatrix[ 1+η^2 ξ*η+2η; ξ*η+2η ξ^2 + 4η^2; @@ -332,7 +332,7 @@ ] g = mapped_grid(x̄, J, 10, 11) - G⁻¹ = map(logicalgrid(g)) do (ξ,η) + G⁻¹ = map(logical_grid(g)) do (ξ,η) @SMatrix[ (1+η)^2 -ξ*(1+η); -ξ*(1+η) (1+ξ)^2+ξ^2; @@ -384,7 +384,7 @@ @test normal(g, CartesianBoundary{1,LowerBoundary}()) == fill(@SVector[-1,0], 11) @test normal(g, CartesianBoundary{1,UpperBoundary}()) == fill(@SVector[1,0], 11) @test normal(g, CartesianBoundary{2,LowerBoundary}()) == fill(@SVector[0,-1], 10) - @test normal(g, CartesianBoundary{2,UpperBoundary}()) ≈ map(boundary_grid(g,CartesianBoundary{2,UpperBoundary}())|>logicalgrid) do ξ̄ + @test normal(g, CartesianBoundary{2,UpperBoundary}()) ≈ map(boundary_grid(g,CartesianBoundary{2,UpperBoundary}())|>logical_grid) do ξ̄ α = 1-2ξ̄[1] @SVector[α,1]/√(α^2 + 1) end @@ -393,28 +393,28 @@ unit(v) = v/norm(v) @testset let bId = CartesianBoundary{1,LowerBoundary}() - lbg = boundary_grid(logicalgrid(g), bId) + lbg = boundary_grid(logical_grid(g), bId) @test normal(g, bId) ≈ map(lbg) do (ξ, η) -unit(@SVector[1/2, η/3-1/6]) end end @testset let bId = CartesianBoundary{1,UpperBoundary}() - lbg = boundary_grid(logicalgrid(g), bId) + lbg = boundary_grid(logical_grid(g), bId) @test normal(g, bId) ≈ map(lbg) do (ξ, η) unit(@SVector[7/2, 2η-1]/(5 + 3η + 2η^2)) end end @testset let bId = CartesianBoundary{2,LowerBoundary}() - lbg = boundary_grid(logicalgrid(g), bId) + lbg = boundary_grid(logical_grid(g), bId) @test normal(g, bId) ≈ map(lbg) do (ξ, η) -unit(@SVector[-2ξ, 2]/(6 + ξ^2 - 2ξ)) end end @testset let bId = CartesianBoundary{2,UpperBoundary}() - lbg = boundary_grid(logicalgrid(g), bId) + lbg = boundary_grid(logical_grid(g), bId) @test normal(g, bId) ≈ map(lbg) do (ξ, η) unit(@SVector[-3ξ, 2]/(6 + ξ^2 + 3ξ)) end