diff --git a/src/CellValues/IdentityCellNumbers.jl b/src/CellValues/IdentityCellNumbers.jl new file mode 100644 index 000000000..2b70773ef --- /dev/null +++ b/src/CellValues/IdentityCellNumbers.jl @@ -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 diff --git a/src/CellValues/files.jl b/src/CellValues/files.jl index a7f407d64..3633e7523 100644 --- a/src/CellValues/files.jl +++ b/src/CellValues/files.jl @@ -53,4 +53,7 @@ include("CompressedCellValues.jl") include("NonIterableCellMaps.jl") @reexport using Gridap.NonIterableCellMaps +include("IdentityCellNumbers.jl") +@reexport using Gridap.IdentityCellNumbers + diff --git a/test/CellValuesTests/IdentityCellNumbersTests.jl b/test/CellValuesTests/IdentityCellNumbersTests.jl new file mode 100644 index 000000000..2383aef43 --- /dev/null +++ b/test/CellValuesTests/IdentityCellNumbersTests.jl @@ -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 diff --git a/test/CellValuesTests/runtests.jl b/test/CellValuesTests/runtests.jl index 33689e678..e0bd51660 100644 --- a/test/CellValuesTests/runtests.jl +++ b/test/CellValuesTests/runtests.jl @@ -42,5 +42,7 @@ include("MapsMocks.jl") @testset "NonIterableCellMaps" begin include("NonIterableCellMapsTests.jl") end +@testset "IdentityCellNumbers" begin include("IdentityCellNumbersTests.jl") end + end # module