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 not perform reinterpolation #57

Merged
merged 53 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
258de35
add flags and capability to convert the raw solution data into vtu f…
andrewwinters5000 Nov 24, 2022
21fe1ac
Merge branch 'main' into convert-raw
ranocha Nov 25, 2022
cadfbff
Merge branch 'main' into convert-raw
andrewwinters5000 Nov 29, 2022
2a4b617
simplify how raw data is copied
andrewwinters5000 Dec 1, 2022
09fe034
working version across all mesh types
andrewwinters5000 Dec 1, 2022
dc3ecc3
Merge branch 'main' into convert-raw
andrewwinters5000 Dec 1, 2022
aaab1d1
rearrange to fix setting incorrect nvisnodes
andrewwinters5000 Dec 1, 2022
0127d98
add tests using ReadVTK instead of comparing hashes
andrewwinters5000 Dec 1, 2022
0a55363
for now add the reference files to this repo. possibly change
andrewwinters5000 Dec 1, 2022
6c59553
remove reference files from repo
andrewwinters5000 Dec 2, 2022
6d8da8d
update all 2d tests. pass locally
andrewwinters5000 Dec 2, 2022
9eb67d3
update the testing functions
andrewwinters5000 Dec 2, 2022
95c0019
remove unnecessary code
andrewwinters5000 Dec 2, 2022
42c9660
remove extra space
andrewwinters5000 Dec 2, 2022
e2b3323
adjust default setting for the mesh visualization
andrewwinters5000 Dec 2, 2022
5120881
new battery of 3D tests. All pass locally
andrewwinters5000 Dec 2, 2022
42f2340
update 2D tests to grab files from Trixi2Vtk_reference_files repo
andrewwinters5000 Dec 2, 2022
ec176e1
add a delete of the local reference files folder
andrewwinters5000 Dec 2, 2022
699b5cf
ignore the reference_files folder
andrewwinters5000 Dec 2, 2022
7be6b50
update 3D tests to grab files from Trixi2Vtk_reference_files repo
andrewwinters5000 Dec 2, 2022
cb545a8
remove unused dependency
andrewwinters5000 Dec 2, 2022
9dd56e4
introduce new testing functions and ability to grab reference files f…
andrewwinters5000 Dec 2, 2022
bc408d8
forgot to update a docstring
andrewwinters5000 Dec 2, 2022
d779e50
remove need for artifacts folder
andrewwinters5000 Dec 3, 2022
b9b62ad
reorganize new tests and clarify filenames.
andrewwinters5000 Dec 5, 2022
c75c5a8
fix broken file paths for Windows system
andrewwinters5000 Dec 5, 2022
a876ccd
reinstate that test files are stored in an artifacts folder for debug…
andrewwinters5000 Dec 5, 2022
89d9634
Merge branch 'main' into convert-raw
andrewwinters5000 Dec 6, 2022
191432e
adjust testing to avoid problematic terms from ReadVTK
andrewwinters5000 Dec 6, 2022
97dd1ad
for now comment out vti stuff to get an idea of code coverage
andrewwinters5000 Dec 6, 2022
c45d4ae
add workaround to get Windows tests to pass
andrewwinters5000 Dec 6, 2022
07ae8a5
add additional manual tests
andrewwinters5000 Dec 7, 2022
190ba92
workaorund to not save artifacts on Windows runners. Hopefully addres…
andrewwinters5000 Dec 7, 2022
d4a96c2
fix broken test due to Windows globbing. Artifacts folder isn't the p…
andrewwinters5000 Dec 7, 2022
69f98b8
Change such that Windows only runs the TreeMesh tests
andrewwinters5000 Dec 7, 2022
46bc2f0
no longer need to load test_skip command
andrewwinters5000 Dec 7, 2022
db9d2c7
put VTI output routines back in
andrewwinters5000 Dec 8, 2022
f071a55
add error message if output format and mesh type are incompatible
andrewwinters5000 Dec 8, 2022
95e260d
update test reference files tag and add new VTI tests
andrewwinters5000 Dec 8, 2022
17c33c5
typo fix
andrewwinters5000 Dec 8, 2022
77e2f72
remove unnecessary comments
andrewwinters5000 Dec 15, 2022
c7a0f7c
improve logic for format and mesh check
andrewwinters5000 Dec 15, 2022
054c0ca
remove empty nodeset declaration
andrewwinters5000 Dec 15, 2022
2150dff
Apply suggestions from code review
andrewwinters5000 Dec 16, 2022
a676f0c
add missing header tests to cell data function
andrewwinters5000 Dec 16, 2022
e071b22
adjust node_set creation and revert function to set the n_visnodes fo…
andrewwinters5000 Dec 16, 2022
b98bdbb
VTI format check only applies to TreeMesh{2}
andrewwinters5000 Dec 16, 2022
aaaabc6
make sure that node_set is always the same type
andrewwinters5000 Dec 16, 2022
2aa5532
name change compare_cell_info -> compare_cell_data
andrewwinters5000 Dec 16, 2022
67a3eb8
name change compare_point_info -> compare_point_data
andrewwinters5000 Dec 16, 2022
c7667c6
remove unnecessary spaces
andrewwinters5000 Dec 16, 2022
ab0617f
remove unnecessary spaces
andrewwinters5000 Dec 16, 2022
a6e4104
Merge branch 'convert-raw' of github.com:trixi-framework/Trixi2Vtk.jl…
andrewwinters5000 Dec 16, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
**/Manifest.toml
out/
artifacts/
reference_files/
docs/build
public/
coverage/
Expand Down
59 changes: 52 additions & 7 deletions src/convert.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
trixi2vtk(filename::AbstractString...;
format=:vtu, verbose=false, hide_progress=false, pvd=nothing,
output_directory=".", nvisnodes=nothing)
output_directory=".", nvisnodes=nothing, save_celldata=true,
reinterpolate=true, data_is_uniform=false)

Convert Trixi-generated output files to VTK files (VTU or VTI).

Expand All @@ -21,6 +22,13 @@ Convert Trixi-generated output files to VTK files (VTU or VTI).
A value of `0` (zero) uses the number of nodes in the DG elements.
- `save_celldata`: Boolean value to determine if cell-based data should be saved.
(default: `true`)
- `reinterpolate`: Boolean value to determine if data should be reinterpolated
onto uniform points. When `false` the raw data at the compute nodes
is copied into the appropriate format.
(default: `true`)
- `data_is_uniform`: Boolean to indicate if the data to be converted is from a finite difference
method on a uniform grid of points.
(default: `false`)
sloede marked this conversation as resolved.
Show resolved Hide resolved

# Examples
```julia
Expand All @@ -30,7 +38,8 @@ julia> trixi2vtk("out/solution_000*.h5")
"""
function trixi2vtk(filename::AbstractString...;
format=:vtu, verbose=false, hide_progress=false, pvd=nothing,
output_directory=".", nvisnodes=nothing, save_celldata=true)
output_directory=".", nvisnodes=nothing, save_celldata=true,
reinterpolate=true, data_is_uniform=false)
# Reset timer
reset_timer!()

Expand Down Expand Up @@ -103,6 +112,11 @@ function trixi2vtk(filename::AbstractString...;
verbose && println("| Reading mesh file...")
@timeit "read mesh" mesh = Trixi.load_mesh_serial(meshfile; n_cells_max=0, RealT=Float64)

# Check compatibility of the mesh type and the output format
if format === :vti && !(mesh isa Trixi.TreeMesh{2})
throw(ArgumentError("VTI format only available for 2D TreeMesh"))
end

# Read data only if it is a data file
if is_datafile
verbose && println("| Reading data file...")
Expand All @@ -113,24 +127,55 @@ function trixi2vtk(filename::AbstractString...;

# Determine resolution for data interpolation
n_visnodes = get_default_nvisnodes_solution(nvisnodes, n_nodes, mesh)

# If a user requests that no reinterpolation is done automatically set
# `n_visnodes` to be the same as the number of nodes in the raw data.
if !reinterpolate
n_visnodes = n_nodes
end

# Check if the raw data is uniform (finite difference) or not (dg)
# and create the corresponding node set for reinterpolation / copying.
if (reinterpolate && !data_is_uniform) || (!reinterpolate && data_is_uniform)
# (1) Default settings; presumably the most common
# (2) Finite difference data
node_set = collect(range(-1, 1, length=n_visnodes))
elseif !reinterpolate && !data_is_uniform
# raw data is on a set of LGL nodes
node_set, _ = gauss_lobatto_nodes_weights(n_visnodes)
else # reinterpolate & data_is_uniform
throw(ArgumentError("Uniform data should not be reinterpolated! Set `reinterpolate=false` and try again."))
end
else
# If file is a mesh file, do not interpolate data as detailed
n_visnodes = get_default_nvisnodes_mesh(nvisnodes, mesh)
# Create an "empty" node set that is unused in the mesh conversion
node_set = Array{Float64}(undef, n_visnodes)
end

# Create output directory if it does not exist
mkpath(output_directory)

# Build VTK grids
vtk_nodedata, vtk_celldata = build_vtk_grids(Val(format), mesh, n_visnodes, verbose,
output_directory, is_datafile, filename)
vtk_nodedata, vtk_celldata = build_vtk_grids(Val(format), mesh, node_set, n_visnodes, verbose,
output_directory, is_datafile, filename, Val(reinterpolate))

# Interpolate data
if is_datafile
verbose && println("| Interpolating data...")
@timeit "interpolate data" interpolated_data = interpolate_data(Val(format),
data, mesh,
n_visnodes, verbose)
if reinterpolate
@timeit "interpolate data" interpolated_data = interpolate_data(Val(format),
data, mesh,
n_visnodes, verbose)
else # Copy the raw solution data; only works for `vtu` format
# Extract data shape information
ndims_ = ndims(data) - 2
n_variables = length(labels)
# Save raw data as one 1D array for each variable
@timeit "interpolate data" interpolated_data = reshape(data,
n_visnodes^ndims_ * n_elements,
n_variables)
end
end

# Add data to file
Expand Down
8 changes: 4 additions & 4 deletions src/interpolate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ end


# Interpolate data from input format to desired output format (vti version)
function interpolate_data(::Val{:vti}, input_data, mesh, n_visnodes, verbose)
function interpolate_data(::Val{:vti}, input_data, mesh::TreeMesh, n_visnodes, verbose)
coordinates, levels, center_level_0, length_level_0 = extract_mesh_information(mesh)

# Normalize element coordinates: move center to (0, 0) and domain size to [-1, 1]²
# Normalize element coordinates: move center to origin and domain size to [-1, 1]²
normalized_coordinates = similar(coordinates)
for element_id in axes(coordinates, 2)
@views normalized_coordinates[:, element_id] .= (
Expand Down Expand Up @@ -77,7 +77,6 @@ function unstructured2structured(unstructured_data::AbstractArray{Float64},

# Create output data structure
structured = Array{Float64}(undef, resolution, resolution, n_variables)

# For each variable, interpolate element data and store to global data structure
for v in 1:n_variables
# Reshape data array for use in interpolate_nodes function
Expand Down Expand Up @@ -135,7 +134,7 @@ end
# Find 2D array index for a 2-tuple of normalized, cell-centered coordinates (i.e., in [-1,1])
function coordinate2index(coordinate, resolution::Integer)
# Calculate 1D normalized coordinates
dx = 2/resolution
dx = 2 / resolution
mesh_coordinates = collect(range(-1 + dx/2, 1 - dx/2, length=resolution))

# Find index
Expand Down Expand Up @@ -211,6 +210,7 @@ function interpolate_nodes(data_in::AbstractArray{T, 3},
interpolate_nodes!(data_out, data_in, vandermonde, n_vars)
end


function interpolate_nodes!(data_out::AbstractArray{T, 3}, data_in::AbstractArray{T, 3},
vandermonde, n_vars) where T
n_nodes_out = size(vandermonde, 1)
Expand Down
Loading