@@ -391,54 +391,66 @@ function get_data_2d(center_level_0, length_level_0, leaf_cells, coordinates, le
391391 return xs, ys, node_centered_data, mesh_vertices_x, mesh_vertices_y
392392end
393393
394+ # For finite difference methods (FDSBP), we do not want to reinterpolate the data, but use the same
395+ # nodes as input nodes. For DG methods, we usually want to reinterpolate the data on an equidistant grid.
396+ default_reinterpolate (solver) = solver isa FDSBP ? false : true
397+
394398# Extract data from a 1D DG solution and prepare it for visualization as a line plot.
395399# This returns a tuple with
396400# - x coordinates
397401# - nodal 1D data
398402#
399403# Note: This is a low-level function that is not considered as part of Trixi's interface and may
400- # thus be changed in future releases.
401- function get_data_1d (original_nodes, unstructured_data, nvisnodes)
404+ # thus be changed in future releases.
405+ function get_data_1d (original_nodes, unstructured_data, nvisnodes, reinterpolate )
402406 # Get the dimensions of u; where n_vars is the number of variables, n_nodes the number of nodal values per element and n_elements the total number of elements.
403407 n_nodes, n_elements, n_vars = size (unstructured_data)
404408
405- # Set the amount of nodes visualized according to nvisnodes .
406- if nvisnodes === nothing
407- max_nvisnodes = 2 * n_nodes
408- elseif nvisnodes == 0
409- max_nvisnodes = n_nodes
409+ # If `reinterpolate` is `false`, we do nothing .
410+ # If `reinterpolate` is `true`, the output nodes are equidistantly spaced.
411+ if reinterpolate == false
412+ interpolated_nodes = original_nodes
413+ interpolated_data = unstructured_data
410414 else
411- @assert nvisnodes>= 2 " nvisnodes must be zero or >= 2"
412- max_nvisnodes = nvisnodes
413- end
415+ # Set the amount of nodes visualized according to nvisnodes.
416+ if nvisnodes === nothing
417+ max_nvisnodes = 2 * n_nodes
418+ elseif nvisnodes == 0
419+ max_nvisnodes = n_nodes
420+ else
421+ @assert nvisnodes>= 2 " nvisnodes must be zero or >= 2"
422+ max_nvisnodes = nvisnodes
423+ end
414424
415- interpolated_nodes = Array {eltype(original_nodes), 2} (undef, max_nvisnodes,
416- n_elements)
417- interpolated_data = Array {eltype(unstructured_data), 3} (undef, max_nvisnodes,
418- n_elements, n_vars)
425+ interpolated_nodes = Array {eltype(original_nodes), 2} (undef, max_nvisnodes,
426+ n_elements)
427+ interpolated_data = Array {eltype(unstructured_data), 3} (undef, max_nvisnodes,
428+ n_elements, n_vars)
419429
420- for j in 1 : n_elements
421- # Interpolate on an equidistant grid.
422- interpolated_nodes[:, j] .= range (original_nodes[1 , 1 , j],
423- original_nodes[1 , end , j],
424- length = max_nvisnodes)
425- end
430+ for j in 1 : n_elements
431+ # Interpolate on an equidistant grid.
432+ interpolated_nodes[:, j] .= range (original_nodes[1 , 1 , j],
433+ original_nodes[1 , end , j],
434+ length = max_nvisnodes)
435+ end
426436
427- nodes_in, _ = gauss_lobatto_nodes_weights (n_nodes)
428- nodes_out = collect (range (- 1 , 1 , length = max_nvisnodes))
429-
430- # Calculate vandermonde matrix for interpolation.
431- vandermonde = polynomial_interpolation_matrix (nodes_in, nodes_out)
432-
433- # Iterate over all variables.
434- for v in 1 : n_vars
435- # Interpolate data for each element.
436- for element in 1 : n_elements
437- multiply_scalar_dimensionwise! (@view (interpolated_data[:, element, v]),
438- vandermonde,
439- @view (unstructured_data[:, element, v]))
437+ nodes_in, _ = gauss_lobatto_nodes_weights (n_nodes)
438+ nodes_out = collect (range (- 1 , 1 , length = max_nvisnodes))
439+
440+ # Calculate vandermonde matrix for interpolation.
441+ vandermonde = polynomial_interpolation_matrix (nodes_in, nodes_out)
442+
443+ # Iterate over all variables.
444+ for v in 1 : n_vars
445+ # Interpolate data for each element.
446+ for element in 1 : n_elements
447+ multiply_scalar_dimensionwise! (@view (interpolated_data[:, element, v]),
448+ vandermonde,
449+ @view (unstructured_data[:, element, v]))
450+ end
440451 end
441452 end
453+
442454 # Return results after data is reshaped
443455 return vec (interpolated_nodes), reshape (interpolated_data, :, n_vars),
444456 vcat (original_nodes[1 , 1 , :], original_nodes[1 , end , end ])
@@ -675,8 +687,8 @@ function unstructured_3d_to_2d(unstructured_data, coordinates, levels,
675687end
676688
677689# Convert 2d unstructured data to 1d slice and interpolate them.
678- function unstructured_2d_to_1d (original_nodes, unstructured_data, nvisnodes, slice,
679- point)
690+ function unstructured_2d_to_1d (original_nodes, unstructured_data, nvisnodes,
691+ reinterpolate, slice, point)
680692 if slice === :x
681693 slice_dimension = 2
682694 other_dimension = 1
@@ -749,7 +761,7 @@ function unstructured_2d_to_1d(original_nodes, unstructured_data, nvisnodes, sli
749761 end
750762
751763 return get_data_1d (reshape (new_nodes[:, 1 : new_id], 1 , n_nodes_in, new_id),
752- new_unstructured_data[:, 1 : new_id, :], nvisnodes)
764+ new_unstructured_data[:, 1 : new_id, :], nvisnodes, reinterpolate )
753765end
754766
755767# Calculate the arc length of a curve given by ndims x npoints point coordinates (piece-wise linear approximation)
@@ -1085,8 +1097,8 @@ function get_value_at_point(point, nodes, data)
10851097end
10861098
10871099# Convert 3d unstructured data to 1d slice and interpolate them.
1088- function unstructured_3d_to_1d (original_nodes, unstructured_data, nvisnodes, slice,
1089- point)
1100+ function unstructured_3d_to_1d (original_nodes, unstructured_data, nvisnodes,
1101+ reinterpolate, slice, point)
10901102 if slice === :x
10911103 slice_dimension = 1
10921104 other_dimensions = [2 , 3 ]
@@ -1178,7 +1190,7 @@ function unstructured_3d_to_1d(original_nodes, unstructured_data, nvisnodes, sli
11781190 end
11791191
11801192 return get_data_1d (reshape (new_nodes[:, 1 : new_id], 1 , n_nodes_in, new_id),
1181- new_unstructured_data[:, 1 : new_id, :], nvisnodes)
1193+ new_unstructured_data[:, 1 : new_id, :], nvisnodes, reinterpolate )
11821194end
11831195
11841196# Interpolate unstructured DG data to structured data (cell-centered)
0 commit comments