ITADN

Difficult to diagnose error when using L2 projector

#1263Openkreutzheidephil 创建于 2025-12-16
K
kreutzheidephilcommented
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?
2 条评论