Skip to content

Commit 9f2a5be

Browse files
jlchangithub-actions[bot]ranochaJoshuaLampert
authored
Use VectorOfArray in wrap_array for DGMulti solvers (#2150)
* update bound on RecursiveArrayTools to have access to 3.27.3 d * comment out broken precompile statements * adding VoA for DGMulti * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * run `Trixi.rhs!` twice to try to avoid excessive allocations * bump lower compat of RecursiveArrayTools * run Trixi.rhs! twice to reduce allocation count * update l2, linf errors * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update test/test_dgmulti_2d.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Update test/test_dgmulti_2d.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * bump LinearAlgebra lower compat for Downgrade CI * fixing one precompile statement * Revert "fixing one precompile statement" This reverts commit 1b700bc. * change mu::Float64 to mu::Function in elixir * update CI * Formatting suggestions Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix threaded CI test values * bump LinearAlgebra compat to fix threaded_legacy tests * Update test/test_threaded.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * unwrap VoA for jacobian computations * unwrap VoA for PlotData1D/PlotData2D * Update src/semidiscretization/semidiscretization.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/visualization/types.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Unpack VoA for visualization test * bump Julia compat and ci.yml to v1.10 * Update test/test_visualization.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix VoA in test_visualization * Update test/test_dgmulti_3d.jl * Update test/test_dgmulti_3d.jl * uncommenting precompile statement * Auto stash before merge of "jc/wrap_VectorOfArray" and "origin/jc/wrap_VectorOfArray" * removing IfElse.jl from Project.toml (why did I add this?) * mark allocation tests as broken for now * mark allocation tests as broken for now mark all 1D allocated tests as broken for now * update dgmulti tests * remove @test_broken for passing tests * update DGMulti FDSBP 3D CI values * update parabolic dispatch * update parabolic dispatch update parabolic dispatch * Apply suggestions from code review Formatting Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Remove additional Trixi.rhs! call in tests * Reduce number of allowed allocations * remove additional Trixi.rhs! calls and reduce number of allowed allocations * remove more Trixi.rhs! calls * format * clean up parabolic rhs test * Update test/test_parabolic_2d.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update test/test_dgmulti_1d.jl Co-authored-by: Joshua Lampert <[email protected]> * use CFL based time stepping to fix positivity issue * format * fix docs * fix test values (use the ones I get locally) * Keep mu as a constant instead of a function * try to fix precompiling of summary callback * fix precompile * try compat "1" for LinearAlgebra * revert precompile stuff * remove #= FIXME comments * Update test/test_parabolic_3d.jl Co-authored-by: Joshua Lampert <[email protected]> * Update test/test_parabolic_3d.jl Co-authored-by: Joshua Lampert <[email protected]> * add news and bump dev version --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Hendrik Ranocha <[email protected]> Co-authored-by: Joshua Lampert <[email protected]>
1 parent d107764 commit 9f2a5be

File tree

16 files changed

+348
-284
lines changed

16 files changed

+348
-284
lines changed

NEWS.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ Trixi.jl follows the interpretation of [semantic versioning (semver)](https://ju
44
used in the Julia ecosystem. Notable changes will be documented in this file
55
for human readability.
66

7+
8+
## Changes when updating to v0.10 from v0.9.x
9+
10+
#### Added
11+
12+
#### Changed
13+
14+
- The numerical solution is wrapped in a `VectorOfArrays` from
15+
[RecursiveArrayTools.jl](https://github.com/SciML/RecursiveArrayTools.jl)
16+
for `DGMulti` solvers ([#2150]). You can use `Base.parent` to unwrap
17+
the original data.
18+
19+
#### Deprecated
20+
21+
#### Removed
22+
23+
724
## Changes in the v0.9 lifecycle
825

926
#### Added
@@ -24,6 +41,7 @@ for human readability.
2441

2542
- The required Julia version is updated to v1.10.
2643

44+
2745
## Changes when updating to v0.9 from v0.8.x
2846

2947
#### Added

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Trixi"
22
uuid = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb"
33
authors = ["Michael Schlottke-Lakemper <[email protected]>", "Gregor Gassner <[email protected]>", "Hendrik Ranocha <[email protected]>", "Andrew R. Winters <[email protected]>", "Jesse Chan <[email protected]>"]
4-
version = "0.9.18-DEV"
4+
version = "0.10.0-DEV"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"

docs/src/visualization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ julia> compute_vorticity(velocity, semi) =
174174
compute_vorticity(velocity, Trixi.mesh_equations_solver_cache(semi)...);
175175
176176
julia> function get_velocity(sol)
177-
rho, rhou, rhov, E = StructArrays.components(sol.u[end])
177+
rho, rhou, rhov, E = StructArrays.components(Base.parent(sol.u[end]))
178178
v1 = rhou ./ rho
179179
v2 = rhov ./ rho
180180
return v1, v2

examples/dgmulti_1d/elixir_euler_shu_osher_gauss_shock_capturing.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ gamma_gas = 1.4
55
equations = CompressibleEulerEquations1D(gamma_gas)
66

77
###############################################################################
8-
# setup the GSBP DG discretization that uses the Gauss operators from
9-
# Chan, Del Rey Fernandez, Carpenter (2019).
8+
# setup the GSBP DG discretization that uses the Gauss operators from
9+
# Chan, Del Rey Fernandez, Carpenter (2019).
1010
# [https://doi.org/10.1137/18M1209234](https://doi.org/10.1137/18M1209234)
1111

1212
# Shu-Osher initial condition for 1D compressible Euler equations
@@ -19,8 +19,7 @@ function initial_condition_shu_osher(x, t, equations::CompressibleEulerEquations
1919
v_left = 4 * sqrt(35) / 9
2020
p_left = 31 / 3
2121

22-
# Replaced v_right = 0 to v_right = 0.1 to avoid positivity issues.
23-
v_right = 0.1
22+
v_right = 0.0
2423
p_right = 1.0
2524

2625
rho = ifelse(x[1] > x0, 1 + 1 / 5 * sin(5 * x[1]), rho_left)
@@ -82,12 +81,14 @@ summary_callback = SummaryCallback()
8281
analysis_callback = AnalysisCallback(semi, interval = 100, uEltype = real(dg))
8382

8483
# handles the re-calculation of the maximum Δt after each time step
85-
stepsize_callback = StepsizeCallback(cfl = 0.1)
84+
stepsize_callback = StepsizeCallback(cfl = 0.2)
8685

8786
# collect all callbacks such that they can be passed to the ODE solver
8887
callbacks = CallbackSet(summary_callback, analysis_callback, stepsize_callback)
8988

9089
# ###############################################################################
9190
# # run the simulation
9291

93-
sol = solve(ode, SSPRK43(), adaptive = true, callback = callbacks, save_everystep = false)
92+
sol = solve(ode, SSPRK43(), adaptive = false,
93+
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
94+
callback = callbacks, save_everystep = false)

src/Trixi.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ using OffsetArrays: OffsetArray, OffsetVector
6060
using P4est
6161
using T8code
6262
using RecipesBase: RecipesBase
63+
using RecursiveArrayTools: VectorOfArray
6364
using Requires: @require
6465
using Static: Static, One, True, False
6566
@reexport using StaticArrays: SVector

src/semidiscretization/semidiscretization.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ function _jacobian_ad_forward(semi, t0, u0_ode, du_ode, config)
277277
return J
278278
end
279279

280+
# unpack u if it is wrapped in VectorOfArray (mainly for DGMulti solvers)
281+
jacobian_ad_forward(semi::AbstractSemidiscretization, t0, u0_ode::VectorOfArray) = jacobian_ad_forward(semi,
282+
t0,
283+
parent(u0_ode))
284+
280285
# This version is specialized to `StructArray`s used by some `DGMulti` solvers.
281286
# We need to convert the numerical solution vectors since ForwardDiff cannot
282287
# handle arrays of `SVector`s.

src/solvers/dgmulti/dg.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ end
128128
# interface with semidiscretization_hyperbolic
129129
wrap_array(u_ode, mesh::DGMultiMesh, equations, dg::DGMulti, cache) = u_ode
130130
wrap_array_native(u_ode, mesh::DGMultiMesh, equations, dg::DGMulti, cache) = u_ode
131+
132+
# used to initialize `u_ode` in `semidiscretize`
133+
function allocate_coefficients(mesh::DGMultiMesh, equations, dg::DGMulti, cache)
134+
return VectorOfArray(allocate_nested_array(real(dg), nvariables(equations),
135+
size(mesh.md.x), dg))
136+
end
137+
wrap_array(u_ode::VectorOfArray, mesh::DGMultiMesh, equations, dg::DGMulti, cache) = parent(u_ode)
138+
131139
function digest_boundary_conditions(boundary_conditions::NamedTuple{Keys, ValueTypes},
132140
mesh::DGMultiMesh,
133141
dg::DGMulti,
@@ -199,10 +207,6 @@ function create_cache(mesh::DGMultiMesh{NDIMS}, equations, dg::DGMultiWeakForm,
199207
local_values_threaded, flux_threaded, rotated_flux_threaded)
200208
end
201209

202-
function allocate_coefficients(mesh::DGMultiMesh, equations, dg::DGMulti, cache)
203-
return allocate_nested_array(real(dg), nvariables(equations), size(mesh.md.x), dg)
204-
end
205-
206210
function compute_coefficients!(u, initial_condition, t,
207211
mesh::DGMultiMesh, equations, dg::DGMulti, cache)
208212
md = mesh.md

src/solvers/dgmulti/flux_differencing_gauss_sbp.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ end
176176
@inline function tensor_product_gauss_face_operator!(out::AbstractVector,
177177
A::TensorProductGaussFaceOperator{2, Interpolation},
178178
x_in::AbstractVector)
179-
#! format: on
179+
#! format: on
180180
(; interp_matrix_gauss_to_face_1d, face_indices_tensor_product) = A
181181
(; nnodes_1d) = A
182182

@@ -215,7 +215,7 @@ end
215215
@inline function tensor_product_gauss_face_operator!(out::AbstractVector,
216216
A::TensorProductGaussFaceOperator{3, Interpolation},
217217
x::AbstractVector)
218-
#! format: on
218+
#! format: on
219219
(; interp_matrix_gauss_to_face_1d, face_indices_tensor_product) = A
220220
(; nnodes_1d) = A
221221

@@ -268,7 +268,7 @@ end
268268
@inline function tensor_product_gauss_face_operator!(out_vec::AbstractVector,
269269
A::TensorProductGaussFaceOperator{2, Projection{ApplyFaceWeights}},
270270
x::AbstractVector) where {ApplyFaceWeights}
271-
#! format: on
271+
#! format: on
272272
(; interp_matrix_gauss_to_face_1d, face_indices_tensor_product) = A
273273
(; inv_volume_weights_1d, nnodes_1d) = A
274274

@@ -322,7 +322,7 @@ end
322322
@inline function tensor_product_gauss_face_operator!(out_vec::AbstractVector,
323323
A::TensorProductGaussFaceOperator{3, Projection{ApplyFaceWeights}},
324324
x::AbstractVector) where {ApplyFaceWeights}
325-
#! format: on
325+
#! format: on
326326
@unpack interp_matrix_gauss_to_face_1d, face_indices_tensor_product = A
327327
@unpack inv_volume_weights_1d, nnodes_1d, nfaces = A
328328

src/visualization/types.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,20 @@ function PlotData1D(u, mesh::TreeMesh, equations, solver, cache;
635635
orientation_x)
636636
end
637637

638+
# unwrap u if it is VectorOfArray
639+
PlotData1D(u::VectorOfArray, mesh, equations, dg::DGMulti{1}, cache; kwargs...) = PlotData1D(parent(u),
640+
mesh,
641+
equations,
642+
dg,
643+
cache;
644+
kwargs...)
645+
PlotData2D(u::VectorOfArray, mesh, equations, dg::DGMulti{2}, cache; kwargs...) = PlotData2D(parent(u),
646+
mesh,
647+
equations,
648+
dg,
649+
cache;
650+
kwargs...)
651+
638652
function PlotData1D(u, mesh, equations, solver, cache;
639653
solution_variables = nothing, nvisnodes = nothing,
640654
reinterpolate = default_reinterpolate(solver),

test/test_dgmulti_1d.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ end
7474
"elixir_euler_shu_osher_gauss_shock_capturing.jl"),
7575
cells_per_dimension=(64,), tspan=(0.0, 1.0),
7676
l2=[
77-
1.673813320412685,
78-
5.980737909458242,
79-
21.587822949251173
77+
1.6967151731067875,
78+
6.018445633981826,
79+
21.77425594743242
8080
],
8181
linf=[
82-
3.1388039126918064,
83-
10.630952212105246,
84-
37.682826521024865
82+
3.2229876650556477,
83+
10.702690533393842,
84+
38.37424900889908
8585
])
8686
# Ensure that we do not have excessive memory allocations
8787
# (e.g., from type instabilities)
@@ -207,14 +207,14 @@ end
207207
cells_per_dimension=(8,),
208208
approximation_type=SBP(),
209209
l2=[
210-
3.03001101100507e-6,
211-
1.692177335948727e-5,
212-
3.002634351734614e-16,
213-
1.1636653574178203e-15
210+
3.0300196635805022e-6,
211+
1.6921833812545857e-5,
212+
2.9844594164368975e-16,
213+
1.1012004949980629e-15
214214
],
215215
linf=[
216-
1.2043401988570679e-5,
217-
5.346847010329059e-5,
216+
1.2043309307818717e-5,
217+
5.346754311919e-5,
218218
9.43689570931383e-16,
219219
2.220446049250313e-15
220220
])

0 commit comments

Comments
 (0)