From 94991f34a3f6f35b23d23734aab88646edbaa75c Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Wed, 11 Dec 2024 16:02:19 +0100 Subject: [PATCH] refactor to reduce code redundancy --- src/equations/equations.jl | 16 ++++++++++++++++ src/equations/serre_green_naghdi_1d.jl | 20 ++++++++------------ src/equations/svaerd_kalisch_1d.jl | 9 +++------ 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/equations/equations.jl b/src/equations/equations.jl index 1c19c37f..ef81e73d 100644 --- a/src/equations/equations.jl +++ b/src/equations/equations.jl @@ -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}, diff --git a/src/equations/serre_green_naghdi_1d.jl b/src/equations/serre_green_naghdi_1d.jl index 5af96671..4dcc91a8 100644 --- a/src/equations/serre_green_naghdi_1d.jl +++ b/src/equations/serre_green_naghdi_1d.jl @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/equations/svaerd_kalisch_1d.jl b/src/equations/svaerd_kalisch_1d.jl index 01f1bb09..057b49b1 100644 --- a/src/equations/svaerd_kalisch_1d.jl +++ b/src/equations/svaerd_kalisch_1d.jl @@ -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 @@ -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