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 return type of evaluate_at_grid_nodes #1044

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/Dofs/DofHandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,10 @@ function _evaluate_at_grid_nodes(dh::DofHandler, u::AbstractVector{T}, fieldname
# VTK output of solution field (or L2 projected scalar data)
n_c = n_components(ip)
vtk_dim = n_c == 2 ? 3 : n_c # VTK wants vectors padded to 3D
data = fill(NaN * zero(T), vtk_dim, getnnodes(get_grid(dh)))
data = fill(T(NaN) * zero(T), vtk_dim, getnnodes(get_grid(dh)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data = fill(T(NaN) * zero(T), vtk_dim, getnnodes(get_grid(dh)))
data = fill(T(NaN), vtk_dim, getnnodes(get_grid(dh)))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I fix this consistently in this PR? Because other places use this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do if you want to :)
Just noticed that this was not required after the changes here.
But it could depend on the resolution of the Int discussion below...

else
# Just evaluation at grid nodes
data = fill(NaN * zero(RT), getnnodes(get_grid(dh)))
data = fill(T(NaN) * zero(RT), getnnodes(get_grid(dh)))
end
# Loop over the subdofhandlers
for sdh in dh.subdofhandlers
Expand Down
7 changes: 6 additions & 1 deletion test/test_dofs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,22 @@ add!(dh, :v, Lagrange{RefQuadrilateral,1}()^2)
add!(dh, :s, Lagrange{RefQuadrilateral,1}())
close!(dh)

u = [1.1, 1.2, 2.1, 2.2, 4.1, 4.2, 3.1, 3.2, 1.3, 2.3, 4.3, 3.3]
u = Float64[1.1, 1.2, 2.1, 2.2, 4.1, 4.2, 3.1, 3.2, 1.3, 2.3, 4.3, 3.3]
u2 = Float32[1.1, 1.2, 2.1, 2.2, 4.1, 4.2, 3.1, 3.2, 1.3, 2.3, 4.3, 3.3]
uv = @view u[1:end]
# :s on solution
s_nodes = evaluate_at_grid_nodes(dh, u, :s)
@test s_nodes ≈ [i+0.3 for i=1:4]
@test eltype(s_nodes) == Float64
@test eltype(evaluate_at_grid_nodes(dh, u2, :s)) == Float32
# :s on a view into solution
sv_nodes = evaluate_at_grid_nodes(dh, uv, :s)
@test sv_nodes ≈ [i+0.3 for i=1:4]
# :v on solution
v_nodes = evaluate_at_grid_nodes(dh, u, :v)
@test v_nodes ≈ [Vec{2,Float64}(i -> j+i/10) for j = 1:4]
@test eltype(v_nodes) == Vec{2,Float64}
@test eltype(evaluate_at_grid_nodes(dh, u2, :v)) == Vec{2,Float32}
# :v on a view into solution
vv_nodes = evaluate_at_grid_nodes(dh, uv, :v)
@test vv_nodes ≈ [Vec{2,Float64}(i -> j+i/10) for j = 1:4]
Expand Down
2 changes: 1 addition & 1 deletion test/test_mixeddofhandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ function test_vtk_export()
sdh_tri = SubDofHandler(dh, Set(2))
add!(sdh_tri, :u, ip_tri)
close!(dh)
u = collect(1:ndofs(dh))
u = collect(1.:ndofs(dh))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Int types won't work after this? Perhaps you can use float(T) when computing the type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that integer types should not work here, because we assume that the solutions are in some continuous space.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to proceed?

filename = "mixed_2d_grid"
VTKGridFile(filename, dh) do vtk
write_solution(vtk, dh, u)
Expand Down