Skip to content

Commit

Permalink
Added IdentityCellNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
fverdugo committed Jul 4, 2019
1 parent f6e6554 commit b6b4c32
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/CellValues/IdentityCellNumbers.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module IdentityCellNumbers

using Gridap

export IdentityCellNumber
import Gridap: reindex
import Base: size
import Base: getindex

struct IdentityCellNumber{T} <: IndexCellValue{T,1}
length::Int
end

function IdentityCellNumber(::Type{T},l::Integer) where T <: Integer
IdentityCellNumber{T}(l)
end

function getindex(c::IdentityCellNumber{T},i::Integer) where T
@assert i > 0
@assert i <= c.length
j::T = i
j
end

size(c::IdentityCellNumber) = (c.length,)

function reindex(values::IndexCellValue, indices::IdentityCellNumber)
@assert length(values) == length(indices)
values
end

end # module
3 changes: 3 additions & 0 deletions src/CellValues/files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ include("CompressedCellValues.jl")
include("NonIterableCellMaps.jl")
@reexport using Gridap.NonIterableCellMaps

include("IdentityCellNumbers.jl")
@reexport using Gridap.IdentityCellNumbers


19 changes: 19 additions & 0 deletions test/CellValuesTests/IdentityCellNumbersTests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module IdentityCellNumbersTests

using Test
using Gridap
using Gridap.CellValuesGallery

a = [2,3,4,6,1,8,3,5]
cn = CellValueFromArray(a)

l = length(a)
id = IdentityCellNumber(Int,l)
r = collect(1:l)
test_index_cell_number(id,r)

cn2 = reindex(cn,id)

@test cn2 === cn

end # module
2 changes: 2 additions & 0 deletions test/CellValuesTests/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ include("MapsMocks.jl")

@testset "NonIterableCellMaps" begin include("NonIterableCellMapsTests.jl") end

@testset "IdentityCellNumbers" begin include("IdentityCellNumbersTests.jl") end

end # module

0 comments on commit b6b4c32

Please sign in to comment.