@@ -519,10 +519,15 @@ end
519519 solution_variables=nothing, nvisnodes=nothing)
520520
521521Create a new `PlotData1D` object that can be used for visualizing 1D DGSEM solution data array
522- `u` with `Plots.jl`. All relevant geometrical information is extracted from the semidiscretization
523- `semi`. By default, the primitive variables (if existent) or the conservative variables (otherwise)
524- from the solution are used for plotting. This can be changed by passing an appropriate conversion
525- function to `solution_variables`.
522+ `u` with `Plots.jl`. All relevant geometrical information is extracted from the
523+ semidiscretization `semi`. By default, the primitive variables (if existent)
524+ or the conservative variables (otherwise) from the solution are used for
525+ plotting. This can be changed by passing an appropriate conversion function to
526+ `solution_variables`, e.g., [`cons2cons`](@ref) or [`cons2prim`](@ref).
527+
528+ Alternatively, you can also pass a function `u` with signature `u(x, equations)`
529+ returning a vector. In this case, the `solution_variables` are ignored. This is useful,
530+ e.g., to visualize an analytical solution.
526531
527532`nvisnodes` specifies the number of visualization nodes to be used. If it is `nothing`,
528533twice the number of solution DG nodes are used for visualization, and if set to `0`,
@@ -547,11 +552,19 @@ function PlotData1D(u_ode, semi; kwargs...)
547552 kwargs... )
548553end
549554
555+ function PlotData1D (func:: Function , semi; kwargs... )
556+ PlotData1D (func,
557+ mesh_equations_solver_cache (semi)... ;
558+ kwargs... )
559+ end
560+
550561function PlotData1D (u, mesh:: TreeMesh , equations, solver, cache;
551562 solution_variables = nothing , nvisnodes = nothing ,
552- slice = :x , point = (0.0 , 0.0 , 0.0 ), curve = nothing )
563+ slice = :x , point = (0.0 , 0.0 , 0.0 ), curve = nothing ,
564+ variable_names = nothing )
553565 solution_variables_ = digest_solution_variables (equations, solution_variables)
554- variable_names = SVector (varnames (solution_variables_, equations))
566+ variable_names_ = digest_variable_names (solution_variables_, equations,
567+ variable_names)
555568
556569 original_nodes = cache. elements. node_coordinates
557570 unstructured_data = get_unstructured_data (u, solution_variables_, mesh, equations,
@@ -610,15 +623,17 @@ function PlotData1D(u, mesh::TreeMesh, equations, solver, cache;
610623 end
611624 end
612625
613- return PlotData1D (x, data, variable_names , mesh_vertices_x,
626+ return PlotData1D (x, data, variable_names_ , mesh_vertices_x,
614627 orientation_x)
615628end
616629
617630function PlotData1D (u, mesh, equations, solver, cache;
618631 solution_variables = nothing , nvisnodes = nothing ,
619- slice = :x , point = (0.0 , 0.0 , 0.0 ), curve = nothing )
632+ slice = :x , point = (0.0 , 0.0 , 0.0 ), curve = nothing ,
633+ variable_names = nothing )
620634 solution_variables_ = digest_solution_variables (equations, solution_variables)
621- variable_names = SVector (varnames (solution_variables_, equations))
635+ variable_names_ = digest_variable_names (solution_variables_, equations,
636+ variable_names)
622637
623638 original_nodes = cache. elements. node_coordinates
624639 unstructured_data = get_unstructured_data (u, solution_variables_, mesh, equations,
@@ -642,15 +657,25 @@ function PlotData1D(u, mesh, equations, solver, cache;
642657 slice, point, nvisnodes)
643658 end
644659
645- return PlotData1D (x, data, variable_names , mesh_vertices_x,
660+ return PlotData1D (x, data, variable_names_ , mesh_vertices_x,
646661 orientation_x)
647662end
648663
664+ function PlotData1D (func:: Function , mesh, equations, dg:: DGMulti{1} , cache;
665+ solution_variables = nothing , variable_names = nothing )
666+ x = mesh. md. x
667+ u = func .(x, equations)
668+
669+ return PlotData1D (u, mesh, equations, dg, cache;
670+ solution_variables, variable_names)
671+ end
672+
649673# Specializes the `PlotData1D` constructor for one-dimensional `DGMulti` solvers.
650674function PlotData1D (u, mesh, equations, dg:: DGMulti{1} , cache;
651- solution_variables = nothing )
675+ solution_variables = nothing , variable_names = nothing )
652676 solution_variables_ = digest_solution_variables (equations, solution_variables)
653- variable_names = SVector (varnames (solution_variables_, equations))
677+ variable_names_ = digest_variable_names (solution_variables_, equations,
678+ variable_names)
654679
655680 orientation_x = 0 # Set 'orientation' to zero on default.
656681
@@ -679,11 +704,16 @@ function PlotData1D(u, mesh, equations, dg::DGMulti{1}, cache;
679704 # Same as above - we create `data_plot` as array of size `num_plotting_points`
680705 # by "number of plotting variables".
681706 x_plot = vec (x)
682- data_plot = permutedims (reinterpret (reshape, eltype (eltype (data)), vec (data)),
683- (2 , 1 ))
707+ data_ = reinterpret (reshape, eltype (eltype (data)), vec (data))
708+ # If there is only one solution variable, we need to add a singleton dimension
709+ if ndims (data_) == 1
710+ data_plot = reshape (data_, :, 1 )
711+ else
712+ data_plot = permutedims (data_, (2 , 1 ))
713+ end
684714 end
685715
686- return PlotData1D (x_plot, data_plot, variable_names , mesh. md. VX, orientation_x)
716+ return PlotData1D (x_plot, data_plot, variable_names_ , mesh. md. VX, orientation_x)
687717end
688718
689719"""
0 commit comments