Skip to content

Commit

Permalink
refactor to reduce code redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaLampert committed Dec 11, 2024
1 parent 08c04e6 commit 94991f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
16 changes: 16 additions & 0 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,22 @@ abstract type AbstractSerreGreenNaghdiEquations{NDIMS, NVARS} <:
include("serre_green_naghdi_1d.jl")
include("hyperbolic_serre_green_naghdi_1d.jl")

function solve_system_matrix!(dv, system_matrix, rhs,
::Union{SvaerdKalischEquations1D,
SerreGreenNaghdiEquations1D},
D1, cache, ::BoundaryConditionPeriodic)
scale_by_mass_matrix!(rhs, D1)
solve_system_matrix!(dv, system_matrix, rhs, equations, D1, cache)
end

function solve_system_matrix!(dv, system_matrix, rhs,
::Union{SvaerdKalischEquations1D,
SerreGreenNaghdiEquations1D},
D1, cache, ::BoundaryConditionReflecting)
scale_by_mass_matrix!(rhs, D1)
solve_system_matrix!(dv, system_matrix, (@view rhs[2:(end - 1)]), equations, D1, cache)
end

function solve_system_matrix!(dv, system_matrix, rhs,
::Union{SvaerdKalischEquations1D,
SerreGreenNaghdiEquations1D},
Expand Down
20 changes: 8 additions & 12 deletions src/equations/serre_green_naghdi_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,8 @@ function rhs_sgn_central!(dq, q, equations, source_terms, cache, ::BathymetryFla
end

@trixi_timeit timer() "solving elliptic system" begin
scale_by_mass_matrix!(tmp, D1)
solve_system_matrix!(dv, system_matrix, tmp,
equations, D1, cache)
solve_system_matrix!(dv, system_matrix,
tmp, equations, D1, cache, boundary_conditions)
end

return nothing
Expand Down Expand Up @@ -485,9 +484,8 @@ function rhs_sgn_upwind!(dq, q, equations, source_terms, cache, ::BathymetryFlat
end

@trixi_timeit timer() "solving elliptic system" begin
scale_by_mass_matrix!(tmp, D1)
solve_system_matrix!(dv, system_matrix, tmp,
equations, D1, cache)
solve_system_matrix!(dv, system_matrix,
tmp, equations, D1, cache, boundary_conditions)
end

return nothing
Expand Down Expand Up @@ -591,9 +589,8 @@ function rhs_sgn_central!(dq, q, equations, source_terms, cache,
end

@trixi_timeit timer() "solving elliptic system" begin
scale_by_mass_matrix!(tmp, D1)
solve_system_matrix!(dv, system_matrix, tmp,
equations, D1, cache)
solve_system_matrix!(dv, system_matrix,
tmp, equations, D1, cache, boundary_conditions)
end

return nothing
Expand Down Expand Up @@ -705,9 +702,8 @@ function rhs_sgn_upwind!(dq, q, equations, source_terms, cache,
end

@trixi_timeit timer() "solving elliptic system" begin
scale_by_mass_matrix!(tmp, D1)
solve_system_matrix!(dv, system_matrix, tmp,
equations, D1, cache)
solve_system_matrix!(dv, system_matrix,
tmp, equations, D1, cache, boundary_conditions)
end

return nothing
Expand Down
9 changes: 3 additions & 6 deletions src/equations/svaerd_kalisch_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,8 @@ function rhs!(dq, q, t, mesh, equations::SvaerdKalischEquations1D,
end
@trixi_timeit timer() "solving elliptic system" begin
tmp1 .= dv
scale_by_mass_matrix!(tmp1, D1)
solve_system_matrix!(dv, system_matrix, tmp1,
equations, D1, cache)
solve_system_matrix!(dv, system_matrix,
tmp1, equations, D1, cache, boundary_conditions)
end

return nothing
Expand Down Expand Up @@ -488,10 +487,8 @@ function rhs!(dq, q, t, mesh, equations::SvaerdKalischEquations1D,
end
@trixi_timeit timer() "solving elliptic system" begin
tmp1 .= dv
scale_by_mass_matrix!(tmp1, D1)
solve_system_matrix!((@view dv[2:(end - 1)]), system_matrix,
(@view tmp1[2:(end - 1)]), equations, D1,
cache)
tmp1, equations, D1, cache, boundary_conditions)
dv[1] = dv[end] = zero(eltype(dv))
end

Expand Down

0 comments on commit 94991f3

Please sign in to comment.