Skip to content

Commit 5e4830a

Browse files
Avoid adjoint sparse matrix times Diagonal (#179)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 526ea31 commit 5e4830a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/equations/serre_green_naghdi_1d.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ function assemble_system_matrix!(cache, h, D1, D1mat,
268268
# is not necessarily perfectly symmetric but only up to
269269
# round-off errors. We wrap it here to avoid issues with the
270270
# factorization.
271-
return Symmetric(Diagonal(M_h) + D1mat' * Diagonal(M_h3_3) * D1mat)
271+
return Symmetric(Diagonal(M_h) + D1mat' * (Diagonal(M_h3_3) * D1mat))
272272
end
273273

274274
# variable bathymetry

src/equations/svaerd_kalisch_1d.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ function create_cache(mesh, equations::SvaerdKalischEquations1D,
264264
D1 isa FourierDerivativeOperator
265265
D1_central = D1
266266
D1mat = sparse(D1_central)
267-
minus_MD1betaD1 = D1mat' * Diagonal(M_beta) * D1mat
267+
minus_MD1betaD1 = D1mat' * (Diagonal(M_beta) * D1mat)
268268
system_matrix = let cache = (; D1, M_h, minus_MD1betaD1)
269269
assemble_system_matrix!(cache, h,
270270
equations, boundary_conditions)
271271
end
272272
elseif D1 isa PeriodicUpwindOperators
273273
D1_central = D1.central
274274
D1mat_minus = sparse(D1.minus)
275-
minus_MD1betaD1 = D1mat_minus' * Diagonal(M_beta) * D1mat_minus
275+
minus_MD1betaD1 = D1mat_minus' * (Diagonal(M_beta) * D1mat_minus)
276276
system_matrix = let cache = (; D1, M_h, minus_MD1betaD1)
277277
assemble_system_matrix!(cache, h,
278278
equations, boundary_conditions)
@@ -326,16 +326,17 @@ function create_cache(mesh, equations::SvaerdKalischEquations1D,
326326
D1 isa UniformCoupledOperator
327327
D1_central = D1
328328
D1mat = sparse(D1_central)
329-
minus_MD1betaD1 = sparse(D1mat' * Diagonal(M_beta) *
330-
D1mat * Pd)[(begin + 1):(end - 1), :]
329+
minus_MD1betaD1 = sparse(D1mat' * (Diagonal(M_beta) *
330+
D1mat * Pd))[(begin + 1):(end - 1), :]
331331
system_matrix = let cache = (; D1, M_h, minus_MD1betaD1)
332332
assemble_system_matrix!(cache, h, equations, boundary_conditions)
333333
end
334334
elseif D1 isa UpwindOperators
335335
D1_central = D1.central
336336
D1mat_minus = sparse(D1.minus)
337-
minus_MD1betaD1 = sparse(D1mat_minus' * Diagonal(M_beta) *
338-
D1mat_minus * Pd)[(begin + 1):(end - 1), :]
337+
minus_MD1betaD1 = sparse(D1mat_minus' * (Diagonal(M_beta) *
338+
D1mat_minus * Pd))[(begin + 1):(end - 1),
339+
:]
339340
system_matrix = let cache = (; D1, M_h, minus_MD1betaD1)
340341
assemble_system_matrix!(cache, h, equations, boundary_conditions)
341342
end

0 commit comments

Comments
 (0)