Skip to content
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

Add package extension for Makie #1494

Merged
merged 14 commits into from
May 29, 2023
10 changes: 10 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ 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"

[compat]
CodeTracking = "1.0.5"
ConstructionBase = "1.3"
Expand All @@ -53,6 +59,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 All @@ -78,3 +85,6 @@ Triangulate = "2.0"
TriplotBase = "0.1"
TriplotRecipes = "0.1"
julia = "1.8"

[extras]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
25 changes: 25 additions & 0 deletions src/visualization/recipes_makie.jl → ext/TrixiMakieExt.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
# Package extension for adding Makie-based features to Trixi.jl
module TrixiMakieExt

# Required for visualization code
# We do not check `isdefined(Base, :get_extension)` since Julia v1.9.0
# does not load package extensions when their dependency is loaded from
# the main environment
if VERSION >= v"1.9.1"
using Makie: Makie, GeometryBasics
else
using ..Makie: Makie, GeometryBasics
end

# 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,
wrap_array_native, mesh_equations_solver_cache

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

# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
# Since these FMAs can increase the performance of many numerical algorithms,
# we need to opt-in explicitly.
Expand Down Expand Up @@ -381,3 +404,5 @@ end


end # @muladd

end
15 changes: 10 additions & 5 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ export DGMulti, DGMultiBasis, estimate_dt, DGMultiMesh, GaussSBP
export ViscousFormulationBassiRebay1, ViscousFormulationLocalDG

# Visualization-related exports
export PlotData1D, PlotData2D, ScalarPlotData2D, getmesh, adapt_to_mesh_level!, adapt_to_mesh_level
export PlotData1D, PlotData2D, ScalarPlotData2D, getmesh, adapt_to_mesh_level!, adapt_to_mesh_level,
iplot, iplot!

function __init__()
init_mpi()
Expand All @@ -257,10 +258,14 @@ 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
# We do not check `isdefined(Base, :get_extension)` since Julia v1.9.0
# does not load package extensions when their dependency is loaded from
# the main environment
@static if !(VERSION >= v"1.9.1")
@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin
include("../ext/TrixiMakieExt.jl")
end
end

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

# Add function definitions here such that they can be exported from Trixi.jl and extended in the
# TrixiMakieExt package extension or by the Makie-specific code loaded by Requires.jl
function iplot end
function iplot! end

end # @muladd