Skip to content

Commit

Permalink
introduce get_default_nvisnodes_mesh (#56)
Browse files Browse the repository at this point in the history
* introduce get_default_nvisnodes_mesh

* fix tests
  • Loading branch information
ranocha committed Dec 1, 2022
1 parent d38a662 commit 883b1c7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ function trixi2vtk(filename::AbstractString...;
assert_cells_elements(n_elements, mesh, filename, meshfile)

# Determine resolution for data interpolation
n_visnodes = get_default_nvisnodes(nvisnodes, n_nodes, mesh)
n_visnodes = get_default_nvisnodes_solution(nvisnodes, n_nodes, mesh)
else
# If file is a mesh file, do not interpolate data
n_visnodes = 1
# If file is a mesh file, do not interpolate data as detailed
n_visnodes = get_default_nvisnodes_mesh(nvisnodes, mesh)
end

# Create output directory if it does not exist
Expand Down Expand Up @@ -250,7 +250,8 @@ function assert_cells_elements(n_elements, mesh::P4estMesh, filename, meshfile)
end


function get_default_nvisnodes(nvisnodes, n_nodes, mesh::TreeMesh)
# default number of visualization nodes if a solution should be visualized
function get_default_nvisnodes_solution(nvisnodes, n_nodes, mesh::TreeMesh)
if nvisnodes === nothing
return 2 * n_nodes
elseif nvisnodes == 0
Expand All @@ -260,9 +261,8 @@ function get_default_nvisnodes(nvisnodes, n_nodes, mesh::TreeMesh)
end
end


function get_default_nvisnodes(nvisnodes, n_nodes,
mesh::Union{StructuredMesh, UnstructuredMesh2D, P4estMesh})
function get_default_nvisnodes_solution(nvisnodes, n_nodes,
mesh::Union{StructuredMesh, UnstructuredMesh2D, P4estMesh})
if nvisnodes === nothing || nvisnodes == 0
return n_nodes
else
Expand All @@ -271,6 +271,27 @@ function get_default_nvisnodes(nvisnodes, n_nodes,
end


# default number of visualization nodes if only the mesh should be visualized
function get_default_nvisnodes_mesh(nvisnodes, mesh::TreeMesh)
if nvisnodes === nothing
# for a Cartesian mesh, we do not need to interpolate
return 1
else
return nvisnodes
end
end

function get_default_nvisnodes_mesh(nvisnodes,
mesh::Union{StructuredMesh, UnstructuredMesh2D, P4estMesh})
if nvisnodes === nothing
# for curved meshes, we need to get at least the vertices
return 2
else
return nvisnodes
end
end


function add_celldata!(vtk_celldata, mesh::TreeMesh, verbose)
@timeit "add data to VTK file" begin
leaf_cells = Trixi.leaf_cells(mesh.tree)
Expand Down
4 changes: 4 additions & 0 deletions test/test_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ end
outfiles = ("solution_000000.vtu", "solution_000000_celldata.vtu",
"solution_00000.pvd", "solution_00000_celldata.pvd")
end
@test_nowarn trixi2vtk(joinpath(outdir, "mesh.h5"))

# Store output files as artifacts to facilitate debugging of failing tests
testname = "2d-tree-mesh-uniform-mesh"
Expand Down Expand Up @@ -86,6 +87,7 @@ end
test_trixi2vtk("solution_000000.h5", outdir,
hashes=[("solution_000000.vtu", "564701ed0a9a90230f3a67f8bddd0616c818319b")])
end
@test_nowarn trixi2vtk(joinpath(outdir, "mesh.h5"))

# Store output files as artifacts to facilitate debugging of failing tests
outfiles = ("solution_000000.vtu",)
Expand Down Expand Up @@ -133,6 +135,7 @@ end
test_trixi2vtk("solution_000000.h5", outdir,
hashes=[("solution_000000.vtu", "acc03f295d2b7daee2cb0b4e29b90035c5e92bd7")])
end
@test_nowarn trixi2vtk(joinpath(outdir, "mesh.h5"))

# Store output files as artifacts to facilitate debugging of failing tests
outfiles = ("solution_000000.vtu",)
Expand All @@ -159,6 +162,7 @@ end
test_trixi2vtk("solution_000000.h5", outdir,
hashes=[("solution_000000.vtu", "a80aadb353ce6ec40baa1b94d278c480f17d0419")])
end
@test_nowarn trixi2vtk(joinpath(outdir, "mesh.h5"))

# Store output files as artifacts to facilitate debugging of failing tests
outfiles = ("solution_000000.vtu",)
Expand Down
3 changes: 3 additions & 0 deletions test/test_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
test_trixi2vtk("solution_000000.h5", outdir,
hashes=[("solution_000000.vtu", "6ab3aa525851187ee0839e1d670a254a66be4ad7"),
("solution_000000_celldata.vtu", "fdfee2d4200ecdad08067b37908412813016f4e7")])
@test_nowarn trixi2vtk(joinpath(outdir, "mesh.h5"))

# Store output files as artifacts to facilitate debugging of failing tests
outfiles = ("solution_000000.vtu", "solution_000000_celldata.vtu")
Expand All @@ -51,6 +52,7 @@ end
test_trixi2vtk("solution_000000.h5", outdir,
hashes=[("solution_000000.vtu", "58e07f981fd6c005ea17e47054bd509c2c66d771")])
end
@test_nowarn trixi2vtk(joinpath(outdir, "mesh.h5"))

# Store output files as artifacts to facilitate debugging of failing tests
outfiles = ("solution_000000.vtu",)
Expand All @@ -77,6 +79,7 @@ end
test_trixi2vtk("solution_000000.h5", outdir,
hashes=[("solution_000000.vtu", "0fa5a099378d153aa3a1bb7dcf3559ea5d6bf9c5")])
end
@test_nowarn trixi2vtk(joinpath(outdir, "mesh.h5"))

# Store output files as artifacts to facilitate debugging of failing tests
outfiles = ("solution_000000.vtu",)
Expand Down

0 comments on commit 883b1c7

Please sign in to comment.