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

Add capability to handle with node variables #67

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c9756da
Add node variables
bennibolm Jun 30, 2022
a2d340a
Merge branch 'main' into node-variables
bennibolm Nov 16, 2022
2cef2a3
Add StructuredMesh
bennibolm Nov 22, 2022
896759a
Merge branch 'main' into node-variables
bennibolm Dec 7, 2022
0f9202c
Add branch to allow reinterpolate=false
bennibolm Jan 18, 2023
90901ac
Merge branch 'main' into node-variables
bennibolm Jan 18, 2023
2f0fb88
Adapt to main
bennibolm Jan 18, 2023
ed0d2c7
Merge branch 'main' into node-variables
bennibolm May 17, 2023
0aee544
Fix interpolation of node variables
bennibolm May 17, 2023
be8c617
Merge branch 'main' into node-variables
bennibolm Aug 21, 2023
1e93ad3
Add tests for subcell limiting coefficients
bennibolm Aug 21, 2023
cdc6d23
Add data comparison for subcell shockcapturing to tests
bennibolm Aug 23, 2023
d7856e3
Merge branch 'main' into node-variables
bennibolm Oct 18, 2023
2f4ec01
Add info when interpolating alphas
bennibolm Oct 25, 2023
2140c28
Use `println` instead of `info` to not interrupt the test
bennibolm Oct 25, 2023
7cdb7dc
Print reinterpolate warning only once
bennibolm Dec 6, 2023
7f4a857
Merge branch 'main' into node-variables
bennibolm Dec 6, 2023
153b72d
Merge branch 'main' into node-variables
bennibolm Mar 21, 2024
9c963b7
Merge branch 'main' into node-variables
bennibolm Apr 22, 2024
7a39d91
Adapt test structure
bennibolm Apr 23, 2024
5a1ab1c
Update test set names
bennibolm Apr 24, 2024
88bb441
Merge branch 'main' into node-variables
bennibolm Jun 18, 2024
526b7ce
Adapt comment (suggestion); Adapt commit hash of repo with reference …
bennibolm Jun 21, 2024
aeb6802
Adapt if clause for printing warning
bennibolm Jun 21, 2024
458b0fb
Subcell tests only for julia v1.8+
bennibolm Jun 24, 2024
7dec585
Update hash of newest commit
bennibolm Jun 24, 2024
9f6c359
Merge branch 'main' into node-variables
bennibolm Jul 24, 2024
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
22 changes: 21 additions & 1 deletion src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function trixi2vtk(filename::AbstractString...;
if is_datafile
verbose && println("| Reading data file...")
@timeit "read data" (labels, data, n_elements, n_nodes,
element_variables, time) = read_datafile(filename)
element_variables, node_variables, time) = read_datafile(filename)

assert_cells_elements(n_elements, mesh, filename, meshfile)

Expand Down Expand Up @@ -202,6 +202,26 @@ function trixi2vtk(filename::AbstractString...;
verbose && println("| | Element variable: $label...")
@timeit label vtk_celldata[label] = variable
end

# Add node variables
for (label, variable) in node_variables
verbose && println("| | Node variable: $label...")
if reinterpolate
if index == 1
bennibolm marked this conversation as resolved.
Show resolved Hide resolved
println("WARNING: The limiting coefficients are no continuous field but happens " *
"to be represented by a piecewise-constant approximation. Thus, reinterpolation " *
"does not give a meaningful representation.")
end
@timeit "interpolate data" interpolated_cell_data = interpolate_data(Val(format),
reshape(variable, size(variable)..., 1),
mesh, n_visnodes, verbose)
else
@timeit "interpolate data" interpolated_cell_data = reshape(variable,
n_visnodes^ndims_ * n_elements)
end
# Add the "interpolated" cell_data to celldata, not node_data
@timeit label vtk_nodedata[label] = interpolated_cell_data
bennibolm marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
end
Expand Down
17 changes: 16 additions & 1 deletion src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ function read_datafile(filename::String)
index +=1
end

return labels, data, n_elements, n_nodes, element_variables, time
# Extract node variable arrays
node_variables = Dict{String, Union{Array{Float64}, Array{Int}}}()
index = 1
while haskey(file, "node_variables_$index")
varname = read(attributes(file["node_variables_$index"])["name"])
nodedata = read(file["node_variables_$index"])
if ndims_ == 2
node_variables[varname] = Array{Float64}(undef, n_nodes, n_nodes, n_elements)
@views node_variables[varname][:, :, :] .= nodedata
else
error("Unsupported number of spatial dimensions: ", ndims_)
end
index +=1
end

return labels, data, n_elements, n_nodes, element_variables, node_variables, time
end
end
37 changes: 37 additions & 0 deletions test/test_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,43 @@ end
end
end
end

@testset "Subcell limiting coefficients" begin
isdir(outdir) && rm(outdir, recursive=true)
run_trixi(joinpath(examples_dir(), "tree_2d_dgsem", "elixir_euler_sedov_blast_wave_sc_subcell.jl"), maxiters=10)

@timed_testset "do not reinterpolate" begin
# Create and test output without reinterpolation
@test_nowarn trixi2vtk(joinpath(outdir, "solution_000010.h5"), output_directory=outdir, reinterpolate=false)
outfilename = "solution_000010.vtu"
out_file = joinpath(outdir, outfilename)

# save output file to `artifacts` to facilitate debugging of failing tests
testname = "2d-treemesh-shockcapturing-subcell-no-reinterp"
cp(out_file, joinpath(artifacts_dir, testname * "-" * outfilename), force=true)

# remote file path is actually a URL so it always has the same path structure
remote_filename = "2d/treemesh/dgsem_sedov_subcell_no_interp_10.vtu"
ref_file = get_test_reference_file("dgsem_sedov_subcell_no_interp_10.vtu", remote_filename)
compare_point_data(out_file, ref_file)
end

@timed_testset "do reinterpolate" begin
# Create and test output without reinterpolation
@test_nowarn trixi2vtk(joinpath(outdir, "solution_000010.h5"), output_directory=outdir, reinterpolate=true)
outfilename = "solution_000010.vtu"
out_file = joinpath(outdir, outfilename)

# save output file to `artifacts` to facilitate debugging of failing tests
testname = "2d-treemesh-shockcapturing-subcell-reinterp"
cp(out_file, joinpath(artifacts_dir, testname * "-" * outfilename), force=true)

# remote file path is actually a URL so it always has the same path structure
remote_filename = "2d/treemesh/dgsem_sedov_subcell_interp_10.vtu"
ref_file = get_test_reference_file("dgsem_sedov_subcell_interp_10.vtu", remote_filename)
compare_cell_data(out_file, ref_file)
sloede marked this conversation as resolved.
Show resolved Hide resolved
end
bennibolm marked this conversation as resolved.
Show resolved Hide resolved
end
end

# Clean up afterwards: delete Trixi output directory and reference file directory
Expand Down
Loading