Ferrite-FEM / Ferrite-FEM/Ferrite.jl

Difficult to diagnose error when using L2 projector

Open
#1,263 2 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Julia
Stars
453
Forks
115
Avg merge
1d 17h
Merged PRs (30d)
11

Description

I encountered the following difficult to diagnose error
```
julia> err
1-element ExceptionStack:
LoadError: MethodError: no method matching _project(::L2Projector, ::Dict{Int64, Vector{Vec{3}}}, ::Vector{QuadratureRule{RefTetrahedron, Vector{Float64}, Vector{Vec{3, Float64}}}})
The function `_project` exists, but no method is defined for this combination of argument types.

Closest candidates are:
_project(::L2Projector, ::Union{AbstractDict{Int64, TC}, AbstractVector{TC}}, ::Vector{<:QuadratureRule}) where {T<:Union{Number, AbstractTensor}, TC<:AbstractVector{T}}
@ Ferrite ~/.julia/packages/Ferrite/XICjE/src/L2_projection.jl:256
_project(::L2Projector, ::Vector{<:QuadratureRule}, ::Union{AbstractDict, AbstractVector}, ::Integer, ::Type{T}) where T
@ Ferrite ~/.julia/packages/Ferrite/XICjE/src/L2_projection.jl:279
```
generated from the following MWE
```
using Ferrite

dim = 3
grid = generate_grid(Tetrahedron, (1,1,1))
ip = Lagrange{RefTetrahedron,2}()^dim
qr = QuadratureRule{RefTetrahedron}(1)
cv = CellValues(qr, ip)
dh = DofHandler(grid)
add!(dh, :u, ip)
close!(dh)

proj = L2Projector(ip, grid)
u = rand(ndofs(dh))

vals = Dict{Int64,Vector{Vec{dim}}}() # doesn't work
# vals = Dict{Int64,Vector{Vec{dim, Float64}}}() # works

valsₑ = [zero(Vec{dim}) for _ in 1:getnquadpoints(cv)]

for cell in CellIterator(dh)
Ferrite.reinit!(cv, cell)
uₑ = @view u[celldofs(cell)][dof_range(dh, :u)]
for qp in 1:getnquadpoints(cv)
valsₑ[qp] = function_value(cv, qp, uₑ)
end
vals[cellid(cell)] = valsₑ
end

u_projected = project(proj, vals, qr)
```
Adding a number type for `Vec{dim}` in the dictionary fixes this (see commented line below initialization) but is difficult to find, maybe it makes sense to throw a more specific/descriptive error in this case?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.