Skip to content

Commit 3cf5ee0

Browse files
add solution_container and auxiliary_container
1 parent 0ecf613 commit 3cf5ee0

File tree

6 files changed

+36
-23
lines changed

6 files changed

+36
-23
lines changed

src/callbacks_step/analysis_covariant.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ function Trixi.integrate(func::Func, u,
2626
equations::AbstractCovariantEquations,
2727
dg::DGMulti, cache; normalize = true) where {Func}
2828
rd = dg.basis
29-
md = mesh.md
30-
@unpack u_values, aux_quad_values = cache
29+
(; u_values) = cache.solution_container
30+
(; aux_quad_values) = cache.auxiliary_container
3131

3232
# interpolate u to quadrature points
3333
Trixi.apply_to_each_field(Trixi.mul_by!(rd.Vq), u_values, u)
3434

3535
integral = zero(func(u_values[1], equations))
3636
total_volume = zero(sum(rd.wq))
37-
for element in Trixi.eachelement(mesh, dg, cache)
37+
for element in Trixi.eachelement(dg, cache)
3838
weights = area_element.(aux_quad_values[:, element], equations) .* rd.wq
3939
integral += sum(weights .* func.(u_values[:, element], equations))
4040
total_volume += sum(weights)
@@ -108,7 +108,8 @@ function Trixi.analyze(::typeof(Trixi.entropy_timederivative), du, u, t,
108108
dg::DGMulti, cache)
109109
rd = dg.basis
110110
md = mesh.md
111-
@unpack u_values, aux_quad_values = cache
111+
(; u_values) = cache.solution_container
112+
(; aux_quad_values) = cache.auxiliary_container
112113

113114
# interpolate u, du to quadrature points
114115
du_values = similar(u_values)
@@ -186,7 +187,8 @@ function Trixi.calc_error_norms(func, u, t, analyzer,
186187
cache_analysis) where {NDIMS, NDIMS_AMBIENT}
187188
rd = dg.basis
188189
md = mesh.md
189-
@unpack u_values, aux_quad_values = cache
190+
(; u_values) = cache.solution_container
191+
(; aux_quad_values) = cache.auxiliary_container
190192

191193
# interpolate u to quadrature points
192194
Trixi.apply_to_each_field(Trixi.mul_by!(rd.Vq), u_values, u)

src/callbacks_step/save_solution_2d_manifold_in_3d_cartesian.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ end
214214
@inline function calc_vorticity_node(u, equations::AbstractEquations,
215215
dg::DGMulti, cache, i, element)
216216
rd = dg.basis
217-
(; aux_values) = cache
217+
(; aux_values) = cache.auxiliary_container
218218
Dr, Ds = rd.Drst
219219

220220
dv2dxi1 = dv1dxi2 = zero(eltype(u))

src/callbacks_step/save_solution_covariant.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ end
3636
# Convert to another set of variables using a solution_variables function
3737
function convert_variables(u, solution_variables, mesh::DGMultiMesh,
3838
equations::AbstractCovariantEquations, dg, cache)
39-
(; aux_values) = cache
39+
(; aux_values) = cache.auxiliary_container
4040
# Extract the number of solution variables to be output
4141
# (may be different than the number of conservative variables)
4242
n_vars = length(Trixi.varnames(solution_variables, equations))
@@ -76,7 +76,7 @@ end
7676
@inline function cons2prim_and_vorticity(u, mesh::DGMultiMesh,
7777
equations::AbstractCovariantEquations{2},
7878
dg::DGMulti, cache, i)
79-
(; aux_values) = cache
79+
(; aux_values) = cache.auxiliary_container
8080
u_node = u[:, i]
8181
aux_node = aux_values[i]
8282
element = (i - 1) ÷ nnodes(dg) + 1

src/callbacks_step/stepsize_dg2d.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function Trixi.max_dt(u, t, mesh::DGMultiMesh,
7474
constant_speed::False,
7575
equations::AbstractCovariantEquations{NDIMS},
7676
dg::DGMulti, cache) where {NDIMS}
77-
(; aux_values) = cache
77+
(; aux_values) = cache.auxiliary_container
7878

7979
dt_min = Inf
8080
for e in eachelement(mesh, dg, cache)

src/solvers/dgmulti/dg.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@ function Trixi.create_cache(mesh::DGMultiMesh{NDIMS}, equations::AbstractCovaria
1515
nvars = nvariables(equations)
1616
naux = n_aux_node_vars(equations)
1717

18-
# storage for volume quadrature values, face quadrature values, flux values
18+
# We are duplicating the contents of solution_container in the top-level cache, but
19+
# note that no actual data is being copied here, just references to the same arrays.
1920
u_values = Trixi.allocate_nested_array(uEltype, nvars, size(md.xq), dg)
2021
u_face_values = Trixi.allocate_nested_array(uEltype, nvars, size(md.xf), dg)
2122
flux_face_values = Trixi.allocate_nested_array(uEltype, nvars, size(md.xf), dg)
23+
local_values_threaded = [Trixi.allocate_nested_array(uEltype, nvars, (rd.Nq,), dg)
24+
for _ in 1:Threads.maxthreadid()]
25+
solution_container = (; u_values, u_face_values, flux_face_values,
26+
local_values_threaded)
27+
28+
# To parallel the solution container, we create an auxiliary container.
2229
aux_values = Trixi.allocate_nested_array(uEltype, naux, size(md.x), dg)
2330
aux_quad_values = Trixi.allocate_nested_array(uEltype, naux, size(md.xq), dg)
2431
aux_face_values = Trixi.allocate_nested_array(uEltype, naux, size(md.xf), dg)
32+
auxiliary_container = (; aux_values, aux_quad_values, aux_face_values)
2533

2634
if typeof(rd.approximation_type) <:
2735
Union{SBP, Trixi.AbstractNonperiodicDerivativeOperator}
@@ -30,10 +38,6 @@ function Trixi.create_cache(mesh::DGMultiMesh{NDIMS}, equations::AbstractCovaria
3038
lift_scalings = nothing
3139
end
3240

33-
# local storage for volume integral and source computations
34-
local_values_threaded = [Trixi.allocate_nested_array(uEltype, nvars, (rd.Nq,), dg)
35-
for _ in 1:Threads.nthreads()]
36-
3741
# For curved meshes, we interpolate geometric terms from nodal points to quadrature points.
3842
# For affine meshes, we just access one element of this interpolated data.
3943
dxidxhatj = map(x -> rd.Vq * x, md.rstxyzJ)
@@ -49,14 +53,16 @@ function Trixi.create_cache(mesh::DGMultiMesh{NDIMS}, equations::AbstractCovaria
4953

5054
# for scaling by curved geometric terms (not used by affine DGMultiMesh)
5155
flux_threaded = [[Trixi.allocate_nested_array(uEltype, nvars, (rd.Nq,), dg)
52-
for _ in 1:NDIMS] for _ in 1:Threads.nthreads()]
56+
for _ in 1:NDIMS] for _ in 1:Threads.maxthreadid()]
5357
rotated_flux_threaded = [Trixi.allocate_nested_array(uEltype, nvars, (rd.Nq,), dg)
54-
for _ in 1:Threads.nthreads()]
58+
for _ in 1:Threads.maxthreadid()]
5559

60+
# For backwards compatibility with older DGMulti code, the solution is included in the
61+
# top-level cache. TODO: remove once DGMulti refactor is complete and stable.
5662
cache = (; md, weak_differentiation_matrices, lift_scalings, invJ, dxidxhatj,
57-
u_values, u_face_values, flux_face_values,
58-
aux_values, aux_quad_values, aux_face_values,
59-
local_values_threaded, flux_threaded, rotated_flux_threaded)
63+
solution_container, u_values, u_face_values, flux_face_values,
64+
auxiliary_container, local_values_threaded, flux_threaded,
65+
rotated_flux_threaded)
6066
return cache
6167
end
6268

src/solvers/dgmulti/dg_manifold_covariant.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ function Trixi.compute_coefficients!(::Nothing, u, initial_condition, t,
55
dg::DGMulti, cache)
66
md = mesh.md
77
rd = dg.basis
8-
@unpack u_values, aux_quad_values = cache
8+
(; u_values) = cache.solution_container
9+
(; aux_quad_values) = cache.auxiliary_container
910
# evaluate the initial condition at quadrature points
1011
Trixi.@threaded for i in Trixi.each_quad_node_global(mesh, dg, cache)
1112
x_node = SVector(getindex.(md.xyzq, i))
@@ -24,7 +25,8 @@ function Trixi.calc_sources!(du, u, t, source_terms,
2425
rd = dg.basis
2526
md = mesh.md
2627
@unpack Pq = rd
27-
@unpack u_values, aux_quad_values, local_values_threaded = cache
28+
(; u_values, local_values_threaded) = cache.solution_container
29+
(; aux_quad_values) = cache.auxiliary_container
2830
Trixi.@threaded for e in Trixi.eachelement(mesh, dg, cache)
2931
source_values = local_values_threaded[Threads.threadid()]
3032

@@ -56,7 +58,9 @@ function Trixi.calc_volume_integral!(du, u,
5658
cache) where {NDIMS_AMBIENT, NDIMS}
5759
rd = dg.basis
5860
md = mesh.md
59-
(; weak_differentiation_matrices, u_values, aux_quad_values, local_values_threaded) = cache
61+
(; weak_differentiation_matrices) = cache
62+
(; u_values, local_values_threaded) = cache.solution_container
63+
(; aux_quad_values) = cache.auxiliary_container
6064

6165
# interpolate to quadrature points
6266
Trixi.apply_to_each_field(Trixi.mul_by!(rd.Vq), u_values, u)
@@ -88,7 +92,8 @@ function Trixi.calc_interface_flux!(cache, surface_integral::SurfaceIntegralWeak
8892
rd = dg.basis
8993
@unpack mapM, mapP, Jf = md
9094
@unpack nrstJ, Nfq = rd
91-
@unpack u_face_values, flux_face_values, aux_face_values = cache
95+
(; u_face_values, flux_face_values) = cache.solution_container
96+
(; aux_face_values) = cache.auxiliary_container
9297
Trixi.@threaded for face_node_index in Trixi.each_face_node_global(mesh, dg, cache)
9398

9499
# inner (idM -> minus) and outer (idP -> plus) indices

0 commit comments

Comments
 (0)