Skip to content

Add package extension for Makie #1494

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

Merged
merged 14 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"
TriplotBase = "981d1d27-644d-49a2-9326-4793e63143c3"
TriplotRecipes = "808ab39a-a642-4abf-81ff-4cb34ebbffa3"

[weakdeps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[extensions]
TrixiMakieExt = "Makie"

[extras]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[compat]
CodeTracking = "1.0.5"
ConstructionBase = "1.3"
Expand All @@ -53,6 +62,7 @@ HDF5 = "0.14, 0.15, 0.16"
IfElse = "0.1"
LinearMaps = "2.7, 3.0"
LoopVectorization = "0.12.118"
Makie = "0.19"
MPI = "0.20"
MuladdMacro = "0.2.2"
Octavian = "0.3.5"
Expand Down
18 changes: 18 additions & 0 deletions ext/TrixiMakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Package extension for adding Makie-based features to Trixi.jl
module TrixiMakieExt

# Required for visualization code
using Makie: Makie, GeometryBasics

# Use all exported symbols to avoid having to rewrite `recipes_makie.jl`
using Trixi

# Use additional symbols that are not exported
using Trixi: PlotData2DTriangulated, TrixiODESolution, PlotDataSeries, ScalarData, @muladd

# Import functions such that they can be extended with new methods
import Trixi: iplot, iplot!

include("../src/visualization/recipes_makie.jl")

end
16 changes: 12 additions & 4 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ export ViscousFormulationBassiRebay1, ViscousFormulationLocalDG
# Visualization-related exports
export PlotData1D, PlotData2D, ScalarPlotData2D, getmesh, adapt_to_mesh_level!, adapt_to_mesh_level

# Until Julia v1.9 is the minimum required version for Trixi.jl, we still support Requires.jl
@static if VERSION >= v"1.10.0-DEV.1288" || VERSION >= v"1.9.1"
export iplot, iplot!
end

function __init__()
init_mpi()

Expand All @@ -257,10 +262,13 @@ function __init__()
using .Plots: Plots
end

@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin
include("visualization/recipes_makie.jl")
using .Makie: Makie, GeometryBasics
export iplot, iplot! # interactive plot
# Until Julia v1.9 is the minimum required version for Trixi.jl, we still support Requires.jl
@static if VERSION < v"1.10.0-DEV.1288" && VERSION < v"1.9.1"
@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin
include("visualization/recipes_makie.jl")
using .Makie: Makie, GeometryBasics
export iplot, iplot! # interactive plot
end
end

@require Flux="587475ba-b771-5e3f-ad9e-33799f191a9c" begin
Expand Down
8 changes: 8 additions & 0 deletions src/visualization/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ include("types.jl")
include("utilities.jl")
include("recipes_plots.jl")

# Until Julia v1.9 is the minimum required version for Trixi.jl, we still support Requires.jl
@static if VERSION >= v"1.10.0-DEV.1288" || VERSION >= v"1.9.1"
# Add function definitions here such that they can be exported from Trixi.jl and extended in the
# TrixiMakieExt package extension
function iplot end
function iplot! end
end

end # @muladd