Mercurial > repos > public > sbplib_julia
diff src/Grids/mapped_grid.jl @ 1777:819ab806960f feature/grids/manifolds
Merge feature/grids/curvilinear
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sun, 15 Sep 2024 23:00:15 +0200 |
parents | e2abd72d7ce0 265a740a49da |
children | 2b5f81e288f1 |
line wrap: on
line diff
--- a/src/Grids/mapped_grid.jl Wed Sep 11 15:44:20 2024 +0200 +++ b/src/Grids/mapped_grid.jl Sun Sep 15 23:00:15 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{<:AbstractArray{<:Any, 2}, D}} <: Grid{T,D} - logicalgrid::GT +struct MappedGrid{T,D, GT<:Grid{<:Any,D}, CT<:AbstractArray{T,D}, JT<:AbstractArray{<:AbstractMatrix{<:Any}, D}} <: Grid{T,D} + 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{<:AbstractArray{<:Any, 2}, 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,24 +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 """ - 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) @@ -55,25 +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) @@ -86,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, ) @@ -121,21 +123,6 @@ end """ - jacobian_determinant(g::MappedGrid) - -The jacobian determinant of `g` as a grid function. -""" -function jacobian_determinant(g::MappedGrid) - return map(jacobian(g)) do ∂x∂ξ - det(∂x∂ξ) - end -end -# TBD: Should this be changed to calculate sqrt(g) instead? -# This would make it well defined also for n-dim grids embedded in higher dimensions. -# TBD: Is there a better name? metric_determinant? -# TBD: Is the best option to delete it? - -""" metric_tensor(g::MappedGrid) The metric tensor of `g` as a grid function.