module TrixiPlotsExt
using Plots: Plots
using Trixi: Trixi, getmesh
using MuladdMacro: @muladd
using Printf: @sprintf
@muladd begin
function Trixi.show_plot(plot_data, variable_names;
show_mesh = true, plot_arguments = Dict{Symbol, Any}(),
time = nothing, timestep = nothing)
plots = []
for v in variable_names
push!(plots, Plots.plot(plot_data[v]; plot_arguments...))
end
if show_mesh
push!(plots, Plots.plot(getmesh(plot_data); plot_arguments...))
end
cols = ceil(Int, sqrt(length(plots)))
rows = div(length(plots), cols, RoundUp)
layout = (rows, cols)
return display(Plots.plot(plots..., layout = layout))
end
function Trixi.save_plot(plot_data, variable_names;
show_mesh = true, plot_arguments = Dict{Symbol, Any}(),
time = nothing, timestep = nothing)
plots = []
for v in variable_names
push!(plots, Plots.plot(plot_data[v]; plot_arguments...))
end
if show_mesh
push!(plots, Plots.plot(getmesh(plot_data); plot_arguments...))
end
cols = ceil(Int, sqrt(length(plots)))
rows = div(length(plots), cols, RoundUp)
layout = (rows, cols)
Plots.plot(plots..., layout = layout)
filename = joinpath("out", @sprintf("solution_%09d.png", timestep))
return Plots.savefig(filename)
end
end
end