Skip to content

Commit c882498

Browse files
authored
Add Trixi example (#7)
1 parent aa15836 commit c882498

File tree

10 files changed

+556
-5
lines changed

10 files changed

+556
-5
lines changed

docs/LocalPreferences.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[Trixi]
2+
loop_vectorization = false
3+
backend = "static"
4+

docs/Project.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
[deps]
2+
Ariadne = "0be81120-40bf-4f8b-adf0-26103efb66f1"
23
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
4+
DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
35
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
46
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244"
57
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
68
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
79
KrylovPreconditioners = "45d422c2-293f-44ce-8315-2cb988662dec"
810
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
911
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
10-
Ariadne = "0be81120-40bf-4f8b-adf0-26103efb66f1"
1112
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
13+
OrdinaryDiffEqLowStorageRK = "b0944070-b475-4768-8dec-fb6eb410534d"
14+
OrdinaryDiffEqSDIRK = "2d112036-d095-4a1e-ab9a-08536f3ecdbf"
15+
OrdinaryDiffEqSSPRK = "669c94d9-1f4b-4b64-b377-1aa079aa2388"
1216
PlutoStaticHTML = "359b1769-a58e-495b-9770-312e911026ad"
1317
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1418
SummationByPartsOperators = "9f78cca6-572e-554e-b819-917d2f1cf240"
19+
Theseus = "7f538e44-2768-4ef2-af90-2110c0378286"
20+
Trixi = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb"
1521

1622
[sources]
1723
Ariadne = {path = ".."}
24+
Theseus = {path = "../libs/Theseus"}
25+
26+
[compat]
27+
Trixi = "0.13.1"

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ examples = [
4949
"Implicit -- Heat 1D" => "heat_1D",
5050
"Implicit -- Heat 1D DG" => "heat_1D_DG",
5151
"Implicit -- Heat 2D" => "heat_2D",
52+
"Trixi" => "trixi",
5253
]
5354

5455
for (_, name) in examples

docs/src/refs.bib

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,50 @@ @ARTICLE{Kan2022-ko
5151
urldate = {2024-10-21},
5252
language = {en}
5353
}
54+
55+
@ARTICLE{Hosea1996-xv,
56+
title = {Analysis and implementation of {TR}-{BDF2}},
57+
author = {Hosea, M E and Shampine, L F},
58+
journaltitle = {Applied numerical mathematics: transactions of IMACS},
59+
publisher = {Elsevier BV},
60+
volume = {20},
61+
issue = {1-2},
62+
pages = {21--37},
63+
date = {1996-02-01},
64+
doi = {10.1016/0168-9274(95)00115-8},
65+
issn = {0168-9274,1873-5460},
66+
urldate = {2025-03-04},
67+
language = {en}
68+
}
69+
70+
@ARTICLE{Bank1985-gh,
71+
title = {Transient simulation of silicon devices and circuits},
72+
author = {Bank, R E and Coughran, W M and Fichtner, W and Grosse, E H
73+
and Rose, D J and Smith, R K},
74+
journaltitle = {IEEE transactions on electron devices},
75+
publisher = {Institute of Electrical and Electronics Engineers (IEEE)},
76+
volume = {32},
77+
issue = {10},
78+
pages = {1992--2007},
79+
date = {1985-10},
80+
doi = {10.1109/t-ed.1985.22232},
81+
issn = {0018-9383,1557-9646},
82+
urldate = {2025-05-27},
83+
language = {en}
84+
}
85+
86+
@ARTICLE{Bonaventura2021-za,
87+
title = {The {TR}-{BDF2} method for second order problems in structural
88+
mechanics},
89+
author = {Bonaventura, Luca and Mármol, Macarena Gómez},
90+
journaltitle = {Computers \& mathematics with applications (Oxford, England:
91+
1987)},
92+
publisher = {Elsevier BV},
93+
volume = {92},
94+
pages = {13--26},
95+
date = {2021-06-15},
96+
doi = {10.1016/j.camwa.2021.03.037},
97+
issn = {0898-1221,1873-7668},
98+
urldate = {2025-05-27},
99+
language = {en}
100+
}

examples/LocalPreferences.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[Trixi]
2+
loop_vectorization = false
3+
backend = "static"

examples/Project.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
[deps]
2+
Ariadne = "0be81120-40bf-4f8b-adf0-26103efb66f1"
23
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
3-
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
4+
DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
45
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
6+
Theseus = "7f538e44-2768-4ef2-af90-2110c0378286"
57
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
68
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
79
KrylovPreconditioners = "45d422c2-293f-44ce-8315-2cb988662dec"
810
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
9-
Ariadne = "0be81120-40bf-4f8b-adf0-26103efb66f1"
1011
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
1112
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
13+
OrdinaryDiffEqLowStorageRK = "b0944070-b475-4768-8dec-fb6eb410534d"
14+
OrdinaryDiffEqSDIRK = "2d112036-d095-4a1e-ab9a-08536f3ecdbf"
15+
OrdinaryDiffEqSSPRK = "669c94d9-1f4b-4b64-b377-1aa079aa2388"
1216
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1317
SummationByPartsOperators = "9f78cca6-572e-554e-b819-917d2f1cf240"
18+
Trixi = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb"
1419

1520
[sources]
1621
Ariadne = {path = ".."}
22+
Theseus = {path = "../libs/Theseus"}
23+
24+
[compat]
25+
julia = "1.10"
26+
Trixi = "0.13.1"

examples/implicit.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# # [Implicit schemes](@id implicit_schemes)
22
using Ariadne
33

4-
using Ariadne
5-
64
# ## Implicit Euler
75

86
function G_Euler!(res, uₙ, Δt, f!, du, u, p, t)

examples/trixi.jl

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# # Using the an implicit solver based on Ariadne with Trixi.jl
2+
3+
using Trixi
4+
using Theseus
5+
using CairoMakie
6+
using LinearAlgebra
7+
import Ariadne: JacobianOperator
8+
9+
10+
# Notes:
11+
# Must disable both Polyester and LoopVectorization for Enzyme to be able to differentiate Trixi.jl
12+
# Using https://github.com/trixi-framework/Trixi.jl/pull/2295
13+
#
14+
# LocalPreferences.jl
15+
# ```toml
16+
# [Trixi]
17+
# loop_vectorization = false
18+
# backend = "static"
19+
# ```
20+
21+
@assert Trixi._PREFERENCE_THREADING !== :polyester
22+
@assert !Trixi._PREFERENCE_LOOPVECTORIZATION
23+
24+
# ## Load Trixi Example
25+
trixi_include(@__MODULE__, joinpath(examples_dir(), "tree_2d_dgsem", "elixir_advection_basic.jl"), sol = nothing);
26+
27+
u = copy(ode.u0)
28+
du = zero(ode.u0)
29+
res = zero(ode.u0)
30+
31+
F! = Theseus.nonlinear_problem(Theseus.ImplicitEuler(), ode.f)
32+
J = JacobianOperator(F!, res, u, (ode.u0, 1.0, du, ode.p, 0.0, (), 1))
33+
34+
out = zero(u)
35+
v = zero(u)
36+
37+
## precompile
38+
mul!(u, J, v)
39+
F!(res, u, (ode.u0, 1.0, du, ode.p, 0.0, (), 1))
40+
41+
@time mul!(u, J, v)
42+
@time F!(res, u, (ode.u0, 1.0, du, ode.p, 0.0, (), 1))
43+
44+
# Cost of time(mul!) ≈ 2 * time(F!)
45+
46+
# ### Solve using ODE interface
47+
48+
sol_trbdf2 = solve(
49+
ode, Theseus.TRBDF2();
50+
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
51+
ode_default_options()..., callback = callbacks,
52+
## verbose=1,
53+
krylov_algo = :gmres,
54+
## krylov_kwargs=(;verbose=1)
55+
);
56+
57+
# #### Plot the solution
58+
59+
# We have to manually convert the sol since Theseus has it's own leightweight solution type.
60+
61+
plot(Trixi.PlotData2DTriangulated(sol_trbdf2.u[end], sol_trbdf2.prob.p))
62+
63+
# ### Solve using OrdinaryDiffEqSDIRKSDIRK
64+
65+
import OrdinaryDiffEqSDIRK
66+
import DifferentiationInterface: AutoFiniteDiff
67+
sol_sdrik = solve(
68+
ode, OrdinaryDiffEqSDIRK.TRBDF2(autodiff = AutoFiniteDiff());
69+
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
70+
ode_default_options()..., callback = callbacks,
71+
adaptive = false
72+
);
73+
74+
# #### Plot the solution
75+
76+
plot(Trixi.PlotData2DTriangulated(sol_sdrik.u[end], sol_sdrik.prob.p))
77+
78+
# ## Increase CFL numbers
79+
80+
trixi_include(@__MODULE__, joinpath(examples_dir(), "tree_2d_dgsem", "elixir_advection_basic.jl"), cfl = 10, sol = nothing);
81+
82+
sol = solve(
83+
ode, Theseus.ImplicitEuler();
84+
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
85+
ode_default_options()..., callback = callbacks,
86+
## verbose=1,
87+
krylov_algo = :gmres,
88+
## krylov_kwargs=(;verbose=1)
89+
);
90+
91+
@show callbacks.discrete_callbacks[4]
92+
93+
# ### Plot the solution
94+
95+
plot(Trixi.PlotData2DTriangulated(sol.u[end], sol.prob.p))

libs/Theseus/Project.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name = "Theseus"
2+
uuid = "7f538e44-2768-4ef2-af90-2110c0378286"
3+
authors = ["Valentin Churavy <[email protected]>"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
8+
Ariadne = "0be81120-40bf-4f8b-adf0-26103efb66f1"
9+
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
10+
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
11+
12+
[sources]
13+
Ariadne = {path = "../.."}
14+
15+
[compat]
16+
DiffEqBase = "6.174.0"
17+
Ariadne = "0.1.0"
18+
SciMLBase = "2.91.0"
19+
UnPack = "1.0.2"

0 commit comments

Comments
 (0)