Skip to content

Commit eca75cf

Browse files
sloederanocha
andauthored
Add package extension for Makie (#1494)
* Add package extension for Makie * Add Makie to the [extras] section to make it work for Julia v1.8 * Fix typo * Apply suggestions from code review Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com> * Update Project.toml * Move Makie-specific code to package extension file * Unconditionally export `iplot`, `iplot!` * fix export list * Add missing `using` * Use more stuff from Trixi * Extend coverage tracking to package extensions --------- Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com>
1 parent da457e4 commit eca75cf

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
TRIXI_TEST: ${{ matrix.trixi_test }}
122122
- uses: julia-actions/julia-processcoverage@v1
123123
with:
124-
directories: src,examples
124+
directories: src,examples,ext
125125
- uses: codecov/codecov-action@v3
126126
with:
127127
file: ./lcov.info

Project.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"
4242
TriplotBase = "981d1d27-644d-49a2-9326-4793e63143c3"
4343
TriplotRecipes = "808ab39a-a642-4abf-81ff-4cb34ebbffa3"
4444

45+
[weakdeps]
46+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
47+
48+
[extensions]
49+
TrixiMakieExt = "Makie"
50+
4551
[compat]
4652
CodeTracking = "1.0.5"
4753
ConstructionBase = "1.3"
@@ -53,6 +59,7 @@ HDF5 = "0.14, 0.15, 0.16"
5359
IfElse = "0.1"
5460
LinearMaps = "2.7, 3.0"
5561
LoopVectorization = "0.12.118"
62+
Makie = "0.19"
5663
MPI = "0.20"
5764
MuladdMacro = "0.2.2"
5865
Octavian = "0.3.5"
@@ -78,3 +85,6 @@ Triangulate = "2.0"
7885
TriplotBase = "0.1"
7986
TriplotRecipes = "0.1"
8087
julia = "1.8"
88+
89+
[extras]
90+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

src/visualization/recipes_makie.jl renamed to ext/TrixiMakieExt.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
# Package extension for adding Makie-based features to Trixi.jl
2+
module TrixiMakieExt
3+
4+
# Required for visualization code
5+
# We do not check `isdefined(Base, :get_extension)` since Julia v1.9.0
6+
# does not load package extensions when their dependency is loaded from
7+
# the main environment
8+
if VERSION >= v"1.9.1"
9+
using Makie: Makie, GeometryBasics
10+
else
11+
using ..Makie: Makie, GeometryBasics
12+
end
13+
14+
# Use all exported symbols to avoid having to rewrite `recipes_makie.jl`
15+
using Trixi
16+
17+
# Use additional symbols that are not exported
18+
using Trixi: PlotData2DTriangulated, TrixiODESolution, PlotDataSeries, ScalarData, @muladd,
19+
wrap_array_native, mesh_equations_solver_cache
20+
21+
# Import functions such that they can be extended with new methods
22+
import Trixi: iplot, iplot!
23+
124
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
225
# Since these FMAs can increase the performance of many numerical algorithms,
326
# we need to opt-in explicitly.
@@ -381,3 +404,5 @@ end
381404

382405

383406
end # @muladd
407+
408+
end

src/Trixi.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ export DGMulti, DGMultiBasis, estimate_dt, DGMultiMesh, GaussSBP
245245
export ViscousFormulationBassiRebay1, ViscousFormulationLocalDG
246246

247247
# Visualization-related exports
248-
export PlotData1D, PlotData2D, ScalarPlotData2D, getmesh, adapt_to_mesh_level!, adapt_to_mesh_level
248+
export PlotData1D, PlotData2D, ScalarPlotData2D, getmesh, adapt_to_mesh_level!, adapt_to_mesh_level,
249+
iplot, iplot!
249250

250251
function __init__()
251252
init_mpi()
@@ -257,10 +258,14 @@ function __init__()
257258
using .Plots: Plots
258259
end
259260

260-
@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin
261-
include("visualization/recipes_makie.jl")
262-
using .Makie: Makie, GeometryBasics
263-
export iplot, iplot! # interactive plot
261+
# Until Julia v1.9 is the minimum required version for Trixi.jl, we still support Requires.jl
262+
# We do not check `isdefined(Base, :get_extension)` since Julia v1.9.0
263+
# does not load package extensions when their dependency is loaded from
264+
# the main environment
265+
@static if !(VERSION >= v"1.9.1")
266+
@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin
267+
include("../ext/TrixiMakieExt.jl")
268+
end
264269
end
265270

266271
@require Flux="587475ba-b771-5e3f-ad9e-33799f191a9c" begin

src/visualization/visualization.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ include("types.jl")
88
include("utilities.jl")
99
include("recipes_plots.jl")
1010

11+
# Add function definitions here such that they can be exported from Trixi.jl and extended in the
12+
# TrixiMakieExt package extension or by the Makie-specific code loaded by Requires.jl
13+
function iplot end
14+
function iplot! end
15+
1116
end # @muladd

0 commit comments

Comments
 (0)