Skip to content

Commit

Permalink
fix vtk export of fields on mixed grids (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimauth authored Sep 28, 2023
1 parent d422b69 commit 383c0c5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Dofs/DofHandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,10 @@ function _evaluate_at_grid_nodes(dh::DofHandler, u::Vector{T}, fieldname::Symbol
field_idx === nothing && continue
# Set up CellValues with the local node coords as quadrature points
CT = getcelltype(get_grid(dh), first(sdh.cellset))
ip = getfieldinterpolation(sdh, field_idx)
ip_geo = default_interpolation(CT)
local_node_coords = reference_coordinates(ip_geo)
qr = QuadratureRule{getrefshape(ip)}(zeros(length(local_node_coords)), local_node_coords)
ip = getfieldinterpolation(sdh, field_idx)
if ip isa VectorizedInterpolation
# TODO: Remove this hack when embedding works...
cv = CellValues(qr, ip.ip, ip_geo)
Expand Down
31 changes: 31 additions & 0 deletions test/test_mixeddofhandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,36 @@ function test_show()
repr(dh.subdofhandlers[1].field_interpolations[1]), "\n Dofs per cell: 8\n")
end

function test_vtk_export()
nodes = Node.([Vec(0.0, 0.0),
Vec(1.0, 0.0),
Vec(1.0, 1.0),
Vec(0.0, 1.0),
Vec(2.0, 0.0),
])
cells = [
Quadrilateral((1, 2, 3, 4)),
Triangle((3, 2, 5))
]
grid = Grid(cells, nodes)
ip_tri = Lagrange{RefTriangle, 1}()
ip_quad = Lagrange{RefQuadrilateral, 1}()
dh = DofHandler(grid)
sdh_quad = SubDofHandler(dh, Set(1))
add!(sdh_quad, :u, ip_quad)
sdh_tri = SubDofHandler(dh, Set(2))
add!(sdh_tri, :u, ip_tri)
close!(dh)
u = collect(1:ndofs(dh))
filename = "mixed_2d_grid"
vtk_grid(filename, dh) do vtk
vtk_point_data(vtk, dh, u)
end
sha = bytes2hex(open(SHA.sha1, filename*".vtu"))
@test sha == "339ab8a8a613c2f38af684cccd695ae816671607"
rm(filename*".vtu") # clean up
end

@testset "DofHandler" begin
test_1d_bar_beam();
test_2d_scalar();
Expand All @@ -637,4 +667,5 @@ end
test_unique_cellsets()
test_celliterator_subdomain()
test_show()
test_vtk_export()
end

0 comments on commit 383c0c5

Please sign in to comment.