diff --git a/src/CellValues/NonIterableCellMaps.jl b/src/CellValues/NonIterableCellMaps.jl new file mode 100644 index 000000000..8757788f3 --- /dev/null +++ b/src/CellValues/NonIterableCellMaps.jl @@ -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 diff --git a/src/CellValues/files.jl b/src/CellValues/files.jl index 7ccee2bfb..a7f407d64 100644 --- a/src/CellValues/files.jl +++ b/src/CellValues/files.jl @@ -50,4 +50,7 @@ include("ConstantCellValues.jl") include("CompressedCellValues.jl") @reexport using Gridap.CompressedCellValues +include("NonIterableCellMaps.jl") +@reexport using Gridap.NonIterableCellMaps + diff --git a/test/CellValuesTests/NonIterableCellMapsTests.jl b/test/CellValuesTests/NonIterableCellMapsTests.jl new file mode 100644 index 000000000..cd20d75b9 --- /dev/null +++ b/test/CellValuesTests/NonIterableCellMapsTests.jl @@ -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 diff --git a/test/CellValuesTests/runtests.jl b/test/CellValuesTests/runtests.jl index b9891ef6f..33689e678 100644 --- a/test/CellValuesTests/runtests.jl +++ b/test/CellValuesTests/runtests.jl @@ -40,5 +40,7 @@ include("MapsMocks.jl") @testset "CompressedCellValues" begin include("CompressedCellValuesTests.jl") end +@testset "NonIterableCellMaps" begin include("NonIterableCellMapsTests.jl") end + end # module