Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong usage of shape_value_type #1160

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Dofs/DofHandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -933,14 +933,17 @@
return _evaluate_at_grid_nodes(dh, u, fieldname)
end

function_value_init(::ScalarInterpolation, ::AbstractVector{T}) where {T} = zero(T)
function_value_init(::VectorInterpolation{vdim}, ::AbstractVector{T}) where {vdim, T <: Number} = zero(Vec{vdim, T})

Check warning on line 937 in src/Dofs/DofHandler.jl

View check run for this annotation

Codecov / codecov/patch

src/Dofs/DofHandler.jl#L936-L937

Added lines #L936 - L937 were not covered by tests

# Internal method that have the vtk option to allocate the output differently
function _evaluate_at_grid_nodes(dh::DofHandler{sdim}, u::AbstractVector{T}, fieldname::Symbol, ::Val{vtk} = Val(false)) where {T, vtk, sdim}
# Make sure the field exists
fieldname ∈ getfieldnames(dh) || error("Field $fieldname not found.")
# Figure out the return type (scalar or vector)
field_idx = find_field(dh, fieldname)
ip = getfieldinterpolation(dh, field_idx)
RT = shape_value_type(ip, T)
RT = typeof(function_value_init(ip, u))

Check warning on line 946 in src/Dofs/DofHandler.jl

View check run for this annotation

Codecov / codecov/patch

src/Dofs/DofHandler.jl#L946

Added line #L946 was not covered by tests
if vtk
# VTK output of solution field (or L2 projected scalar data)
n_c = n_components(ip)
Expand Down
14 changes: 8 additions & 6 deletions test/test_interpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ function test_interpolation_properties(ip::Interpolation{RefShape, FunOrder}) wh
# Test A-D
_test_interpolation_properties(dof_data, refshape_data)

# Test E: All base functions implemented.
# Test E: All base functions implemented and infers correct types.
# Argument errors for 0th and n+1 indices.
ξ = zero(Vec{Ferrite.getrefdim(ip)})
@test_throws ArgumentError Ferrite.reference_shape_value(ip, ξ, 0)
for i in 1:getnbasefunctions(ip)
@test Ferrite.reference_shape_value(ip, ξ, i) isa Ferrite.shape_value_type(ip, Float64)
for T in (Float64, Float32)
ξ = zero(Vec{Ferrite.getrefdim(ip), T})
@test_throws ArgumentError Ferrite.reference_shape_value(ip, ξ, 0)
for i in 1:getnbasefunctions(ip)
@test (@inferred Ferrite.reference_shape_value(ip, ξ, i)) isa Ferrite.shape_value_type(ip, T)
end
@test_throws ArgumentError Ferrite.reference_shape_value(ip, ξ, getnbasefunctions(ip) + 1)
end
@test_throws ArgumentError Ferrite.reference_shape_value(ip, ξ, getnbasefunctions(ip) + 1)
end
end

Expand Down