Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SimpleUnPack = "ce78b400-467f-4804-87d8-8f486da07d0a"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand All @@ -59,13 +58,15 @@ Convex = "f65535da-76fb-5f13-bab9-19810c17039a"
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"

[extensions]
TrixiCUDAExt = "CUDA"
TrixiConvexECOSExt = ["Convex", "ECOS"]
TrixiMakieExt = "Makie"
TrixiNLsolveExt = "NLsolve"
TrixiPlotsExt = "Plots"
TrixiSparseConnectivityTracerExt = "SparseConnectivityTracer"

[compat]
Expand Down Expand Up @@ -96,14 +97,14 @@ NLsolve = "4.5.1"
Octavian = "0.3.28"
OffsetArrays = "1.13"
P4est = "0.4.12"
Plots = "1.38.13"
Polyester = "=0.7.16, 0.7.18"
PrecompileTools = "1.2.1"
Preferences = "1.5"
Printf = "1"
RecipesBase = "1.3.4"
RecursiveArrayTools = "3.37"
Reexport = "1.2.2"
Requires = "1.3"
SciMLBase = "2.141.0"
SimpleUnPack = "1.1"
SparseArrays = "1"
Expand Down
77 changes: 77 additions & 0 deletions ext/TrixiPlotsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module TrixiPlotsExt

# Load the required packages
using Plots: Plots
using Trixi
using Trixi: AbstractPlotData, PlotDataSeries, PlotMesh, PlotData1D, PlotData2D,
ScalarPlotData2D, PlotData2DCartesian, PlotData2DTriangulated, getmesh,
TrixiODESolution, AbstractSemidiscretization, ScalarData, DiscreteCallback,
CallbackSet, ODEProblem, ODESolution
Comment thread
ShahuK283 marked this conversation as resolved.
Outdated
using MuladdMacro: @muladd
using RecipesBase
Comment thread
ShahuK283 marked this conversation as resolved.
Outdated
using Printf: @sprintf

@muladd begin
#! format: noindent

function Trixi.show_plot(plot_data, variable_names;
show_mesh = true, plot_arguments = Dict{Symbol, Any}(),
time = nothing, timestep = nothing)
# Gather subplots
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

# Note, for the visualization callback to work for general equation systems
# this layout construction would need to use the if-logic below.
# Currently, there is no use case for this so it is left here as a note.
#
# Determine layout
# if length(plots) <= 3
# cols = length(plots)
# rows = 1
# else
# cols = ceil(Int, sqrt(length(plots)))
# rows = div(length(plots), cols, RoundUp)
# end
# layout = (rows, cols)

# Determine layout
cols = ceil(Int, sqrt(length(plots)))
rows = div(length(plots), cols, RoundUp)
layout = (rows, cols)

# Show plot
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)
# Gather subplots
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

# Determine layout
cols = ceil(Int, sqrt(length(plots)))
rows = div(length(plots), cols, RoundUp)
layout = (rows, cols)

# Create plot
Plots.plot(plots..., layout = layout)

# Determine filename and save plot
filename = joinpath("out", @sprintf("solution_%09d.png", timestep))
return Plots.savefig(filename)
end
end # @muladd
end # module TrixiPlotsExt
6 changes: 0 additions & 6 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ using P4est
using T8code
using RecipesBase: RecipesBase
using RecursiveArrayTools: VectorOfArray
using Requires: @require
using Static: Static, One, True, False
@reexport using StaticArrays: SVector
using StaticArrays: StaticArrays, MVector, MArray, SMatrix, @SMatrix
Expand Down Expand Up @@ -350,11 +349,6 @@ function __init__()
init_t8code()

register_error_hints()

# Enable features that depend on the availability of the Plots package
@require Plots="91a5bcdd-55d7-5caf-9e0b-520d859cae80" begin
using .Plots: Plots
end
end

include("auxiliary/precompile.jl")
Expand Down
63 changes: 2 additions & 61 deletions src/callbacks_step/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ function VisualizationCallback(semi, plot_data_creator = nothing;
# Requires.jl only when Plots is present.
# In the future, we should update/remove this warning if other plotting packages are
# starting to be used.
if !(:Plots in names(@__MODULE__, all = true))
@warn "Package `Plots` not loaded but required by `VisualizationCallback` to visualize results"
end
Comment thread
ShahuK283 marked this conversation as resolved.
Outdated

return DiscreteCallback(visualization_callback, visualization_callback, # the first one is the condition, the second the affect!
save_positions = (false, false),
Expand Down Expand Up @@ -188,40 +185,7 @@ This function is the default `plot_creator` argument for the [`VisualizationCall

See also: [`VisualizationCallback`](@ref), [`save_plot`](@ref)
Comment thread
ShahuK283 marked this conversation as resolved.
"""
function show_plot(plot_data, variable_names;
show_mesh = true, plot_arguments = Dict{Symbol, Any}(),
time = nothing, timestep = nothing)
# Gather subplots
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

# Note, for the visualization callback to work for general equation systems
# this layout construction would need to use the if-logic below.
# Currently, there is no use case for this so it is left here as a note.
#
# Determine layout
# if length(plots) <= 3
# cols = length(plots)
# rows = 1
# else
# cols = ceil(Int, sqrt(length(plots)))
# rows = div(length(plots), cols, RoundUp)
# end
# layout = (rows, cols)

# Determine layout
cols = ceil(Int, sqrt(length(plots)))
rows = div(length(plots), cols, RoundUp)
layout = (rows, cols)

# Show plot
return display(Plots.plot(plots..., layout = layout))
end
function show_plot end

"""
save_plot(plot_data, variable_names;
Expand All @@ -237,28 +201,5 @@ The `timestep` is used in the filename. `time` is currently unused by this funct

See also: [`VisualizationCallback`](@ref), [`show_plot`](@ref)
Comment thread
ShahuK283 marked this conversation as resolved.
"""
function save_plot(plot_data, variable_names;
show_mesh = true, plot_arguments = Dict{Symbol, Any}(),
time = nothing, timestep = nothing)
# Gather subplots
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

# Determine layout
cols = ceil(Int, sqrt(length(plots)))
rows = div(length(plots), cols, RoundUp)
layout = (rows, cols)

# Create plot
Plots.plot(plots..., layout = layout)

# Determine filename and save plot
filename = joinpath("out", @sprintf("solution_%09d.png", timestep))
return Plots.savefig(filename)
end
function save_plot end
end # @muladd
Loading