Skip to content

Commit

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

using Gridap
using Gridap.Helpers

export UnimplementedMap
export NonIterableCellMap
import Base: iterate
import Gridap: evaluate
import Gridap: return_size

struct UnimplementedMap{S,M,T,N} <: Map{S,M,T,N} end

function evaluate!(
this::UnimplementedMap{S,M,T,N},
points::AbstractArray{<:S,M},
v::AbstractArray{T,N}) where {S,M,T,N}
@notimplemented
end

function return_size(::UnimplementedMap{S,M,T,N},::NTuple{M,Int}) where {S,M,T,N}
@notimplemented
end

abstract type NonIterableCellMap{S,M,T,N} <: IterCellValue{UnimplementedMap{S,M,T,N}} end

function iterate(::NonIterableCellMap)
_error()
end

function iterate(::NonIterableCellMap,state)
_error()
end

function _error()
error("Iteration is intentionally disabled for this type.")
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 @@ -50,4 +50,7 @@ include("ConstantCellValues.jl")
include("CompressedCellValues.jl")
@reexport using Gridap.CompressedCellValues

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


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

using Test
using Gridap

struct Foo <: NonIterableCellMap{Point{2},1,Int,1} end

foo = Foo()

@test isa(foo,CellMap)

try
iterate(foo)
catch LoadError
end

try
iterate(foo,2)
catch LoadError
end

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

@testset "CompressedCellValues" begin include("CompressedCellValuesTests.jl") end

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

end # module

0 comments on commit 956a537

Please sign in to comment.