Skip to content

Commit f1024e6

Browse files
committed
use factorized matrices for BBMBBMEquations1D
1 parent 338f8f8 commit f1024e6

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/DispersiveShallowWater.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module DispersiveShallowWater
33
using BandedMatrices: BandedMatrix
44
using DiffEqBase: DiffEqBase, SciMLBase, terminate!
55
using Interpolations: Interpolations, linear_interpolation
6-
using LinearAlgebra: mul!, I, Diagonal, diag
6+
using LinearAlgebra: mul!, I, Diagonal, diag, factorize
77
using PolynomialBases: PolynomialBases
88
using Printf: @printf, @sprintf
99
using RecipesBase: RecipesBase, @recipe, @series

src/equations/bbm_bbm_1d.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function create_cache(mesh, equations::BBMBBMEquations1D,
132132
::BoundaryConditionPeriodic,
133133
RealT, uEltype)
134134
D = equations.D
135-
invImD2 = inv(I - 1 / 6 * D^2 * Matrix(solver.D2))
135+
invImD2 = factorize(I - 1 / 6 * D^2 * sparse(solver.D2))
136136
return (invImD2 = invImD2,)
137137
end
138138

@@ -146,7 +146,7 @@ function create_cache(mesh, equations::BBMBBMEquations1D,
146146
Pd = BandedMatrix((-1 => fill(one(real(mesh)), N - 2),), (N, N - 2))
147147
D2d = (sparse(solver.D2) * Pd)[2:(end - 1), :]
148148
# homogeneous Dirichlet boundary conditions
149-
invImD2d = inv(I - 1 / 6 * D^2 * D2d)
149+
invImD2d = factorize(I - 1 / 6 * D^2 * D2d)
150150
m = diag(M)
151151
m[1] = 0
152152
m[end] = 0
@@ -156,10 +156,10 @@ function create_cache(mesh, equations::BBMBBMEquations1D,
156156
if solver.D1 isa DerivativeOperator ||
157157
solver.D1 isa UniformCoupledOperator
158158
D1_b = BandedMatrix(solver.D1)
159-
invImD2n = inv(I + 1 / 6 * D^2 * inv(M) * D1_b' * PdM * D1_b)
159+
invImD2n = factorize(I + 1 / 6 * D^2 * inv(M) * D1_b' * PdM * D1_b)
160160
elseif solver.D1 isa UpwindOperators
161161
D1plus_b = BandedMatrix(solver.D1.plus)
162-
invImD2n = inv(I + 1 / 6 * D^2 * inv(M) * D1plus_b' * PdM * D1plus_b)
162+
invImD2n = factorize(I + 1 / 6 * D^2 * inv(M) * D1plus_b' * PdM * D1plus_b)
163163
else
164164
@error "unknown type of first-derivative operator: $(typeof(solver.D1))"
165165
end
@@ -202,8 +202,8 @@ function rhs!(du_ode, u_ode, t, mesh, equations::BBMBBMEquations1D, initial_cond
202202

203203
@timeit timer() "source terms" calc_sources!(dq, q, t, source_terms, equations, solver)
204204

205-
@timeit timer() "deta elliptic" deta[:]=invImD2 * deta
206-
@timeit timer() "dv elliptic" dv[:]=invImD2 * dv
205+
@timeit timer() "deta elliptic" deta[:]=invImD2 \ deta
206+
@timeit timer() "dv elliptic" dv[:]=invImD2 \ dv
207207

208208
return nothing
209209
end
@@ -241,9 +241,9 @@ function rhs!(du_ode, u_ode, t, mesh, equations::BBMBBMEquations1D, initial_cond
241241

242242
@timeit timer() "source terms" calc_sources!(dq, q, t, source_terms, equations, solver)
243243

244-
@timeit timer() "deta elliptic" deta[:]=invImD2n * deta
244+
@timeit timer() "deta elliptic" deta[:]=invImD2n \ deta
245245
@timeit timer() "dv elliptic" begin
246-
dv[2:(end - 1)] = invImD2d * dv[2:(end - 1)]
246+
dv[2:(end - 1)] = invImD2d \ dv[2:(end - 1)]
247247
dv[1] = dv[end] = zero(eltype(dv))
248248
end
249249

0 commit comments

Comments
 (0)