Skip to content

Commit db183bb

Browse files
SKopeczJoshuaLampertranocha
authored
Improve code readability and reduce OOP allocations for StaticArrays (#183)
* created function basic_patankar_step for oop * revised MPRK43 * revised SSPMPRK oop implementations * format * fix SSPMPRK43 * bugfix SSPMPRK43 * more structure, more dispatch * bugfix * revised SSPMPRK schemes * bugfix * revised lincomb function * added @muladd * build_mprk_matrix for StaticMatrix * bugfix build_mprk_matrix for StaticMatrix * build_mprk_matrix for StaticMatrix without slicing allocations * format * Revised implementation of build_mprk_matrix for StaticMatrix. Now tests pass as before. * lincomb! in MPRK schemes * bugfix MPRK22 * remove stale explicit imports * introduced basic_patankar_step! and basic_patankar_step_conservative! * revised sspmprk * removed comments * add diagonal of sparse matrix efficiently * use naive loop to add diagonal of sparse matrices * consolidate broadcasts * removed @unpack * additional comments in source file * Update src/mprk.jl Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com> * format * Apply suggestions from code review Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com> * Apply more suggestions from code review Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com> --------- Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com> Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com>
1 parent ae6c5e2 commit db183bb

5 files changed

Lines changed: 388 additions & 820 deletions

File tree

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8"
1212
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1313
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1414
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
15-
SimpleUnPack = "ce78b400-467f-4804-87d8-8f486da07d0a"
1615
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1716
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1817
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
@@ -34,7 +33,6 @@ OrdinaryDiffEqCore = "1.21, 2"
3433
RecipesBase = "1.3.4"
3534
Reexport = "1.2.2"
3635
SciMLBase = "2.78"
37-
SimpleUnPack = "1"
3836
SparseArrays = "1"
3937
StaticArrays = "1.9.7"
4038
Statistics = "1"

src/PositiveIntegrators.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ module PositiveIntegrators
44
using LinearAlgebra: LinearAlgebra, Tridiagonal, I, diag, mul!
55
using Statistics: median
66

7-
using SparseArrays: SparseArrays, AbstractSparseMatrix,
7+
using SparseArrays: SparseArrays, AbstractSparseMatrix, SparseMatrixCSC,
88
issparse, nonzeros, nzrange, rowvals, spdiagm
9-
using StaticArrays: SVector, SMatrix, StaticArray, @SVector, @SMatrix, MMatrix
9+
using StaticArrays: SVector, SMatrix, StaticArray, StaticMatrix, @SVector, @SMatrix, MMatrix
1010

1111
using FastBroadcast: @..
1212
using MuladdMacro: @muladd
13-
using SimpleUnPack: @unpack
1413

1514
using Reexport: @reexport
1615

@@ -28,8 +27,7 @@ using LinearSolve: LinearSolve, LinearProblem, LUFactorization, solve!
2827

2928
import SciMLBase: interp_summary
3029

31-
using OrdinaryDiffEqCore: @cache,
32-
OrdinaryDiffEqAdaptiveAlgorithm,
30+
using OrdinaryDiffEqCore: OrdinaryDiffEqAdaptiveAlgorithm,
3331
OrdinaryDiffEqConstantCache, OrdinaryDiffEqMutableCache,
3432
False,
3533
_vec

src/mpdec.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ function _build_mpdec_matrix_and_rhs!(M::AbstractSparseMatrix, rhs, P::AbstractS
564564
end
565565

566566
@muladd function perform_step!(integrator, cache::MPDeCConstantCache, repeat_step = false)
567-
@unpack alg, t, dt, uprev, f, p = integrator
568-
@unpack K, M, nodes, theta, small_constant, ValM = cache
567+
(; alg, t, dt, uprev, f, p) = integrator
568+
(; K, M, nodes, theta, small_constant, ValM) = cache
569569

570570
C = cmatrix(uprev, ValM)
571571
C2 = cmatrix(uprev, ValM)
@@ -702,9 +702,9 @@ function initialize!(integrator, cache::Union{MPDeCCache, MPDeCConservativeCache
702702
end
703703

704704
@muladd function perform_step!(integrator, cache::MPDeCCache, repeat_step = false)
705-
@unpack t, dt, uprev, u, f, p = integrator
706-
@unpack tmp, P, P2, d, σ, C, C2, linsolve_rhs, linsolve = cache
707-
@unpack K, M, nodes, theta, small_constant = cache.tab
705+
(; t, dt, uprev, u, f, p) = integrator
706+
(; tmp, P, P2, d, σ, C, C2, linsolve_rhs, linsolve) = cache
707+
(; K, M, nodes, theta, small_constant) = cache.tab
708708

709709
# Initialize C matrices
710710
for i in 1:(M + 1)
@@ -743,9 +743,9 @@ end
743743

744744
@muladd function perform_step!(integrator, cache::MPDeCConservativeCache,
745745
repeat_step = false)
746-
@unpack t, dt, uprev, u, f, p = integrator
747-
@unpack tmp, P, P2, σ, C, C2, linsolve_rhs, linsolve = cache
748-
@unpack K, M, nodes, theta, small_constant = cache.tab
746+
(; t, dt, uprev, u, f, p) = integrator
747+
(; tmp, P, P2, σ, C, C2, linsolve_rhs, linsolve) = cache
748+
(; K, M, nodes, theta, small_constant) = cache.tab
749749

750750
# Initialize right hand side of linear system
751751
linsolve_rhs .= uprev

0 commit comments

Comments
 (0)