Skip to content

Commit b6b4c32

Browse files
committed
Added IdentityCellNumber
1 parent f6e6554 commit b6b4c32

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

src/CellValues/IdentityCellNumbers.jl

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module IdentityCellNumbers
2+
3+
using Gridap
4+
5+
export IdentityCellNumber
6+
import Gridap: reindex
7+
import Base: size
8+
import Base: getindex
9+
10+
struct IdentityCellNumber{T} <: IndexCellValue{T,1}
11+
length::Int
12+
end
13+
14+
function IdentityCellNumber(::Type{T},l::Integer) where T <: Integer
15+
IdentityCellNumber{T}(l)
16+
end
17+
18+
function getindex(c::IdentityCellNumber{T},i::Integer) where T
19+
@assert i > 0
20+
@assert i <= c.length
21+
j::T = i
22+
j
23+
end
24+
25+
size(c::IdentityCellNumber) = (c.length,)
26+
27+
function reindex(values::IndexCellValue, indices::IdentityCellNumber)
28+
@assert length(values) == length(indices)
29+
values
30+
end
31+
32+
end # module

src/CellValues/files.jl

+3
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,7 @@ include("CompressedCellValues.jl")
5353
include("NonIterableCellMaps.jl")
5454
@reexport using Gridap.NonIterableCellMaps
5555

56+
include("IdentityCellNumbers.jl")
57+
@reexport using Gridap.IdentityCellNumbers
58+
5659

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module IdentityCellNumbersTests
2+
3+
using Test
4+
using Gridap
5+
using Gridap.CellValuesGallery
6+
7+
a = [2,3,4,6,1,8,3,5]
8+
cn = CellValueFromArray(a)
9+
10+
l = length(a)
11+
id = IdentityCellNumber(Int,l)
12+
r = collect(1:l)
13+
test_index_cell_number(id,r)
14+
15+
cn2 = reindex(cn,id)
16+
17+
@test cn2 === cn
18+
19+
end # module

test/CellValuesTests/runtests.jl

+2
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ include("MapsMocks.jl")
4242

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

45+
@testset "IdentityCellNumbers" begin include("IdentityCellNumbersTests.jl") end
46+
4547
end # module
4648

0 commit comments

Comments
 (0)