Skip to content

Commit d7b7d0d

Browse files
committed
add Test for sparse Jacobians, they work!@
1 parent e0f3d93 commit d7b7d0d

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/dynamicalsystem/discrete_famous_systems.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ The first `M` entries of the state are the angles, the last `M` are the momenta.
132132
133133
[1] : H. Kantz & P. Grassberger, J. Phys. A **21**, pp 127–133 (1988)
134134
"""
135+
function coupledstandardmaps end
136+
using SparseArrays
135137
function coupledstandardmaps(M::Int, u0 = 0.001rand(2M);
136138
ks = ones(M), Γ = 1.0)
137139

@@ -148,9 +150,10 @@ function coupledstandardmaps(M::Int, u0 = 0.001rand(2M);
148150
J[i, i+M] = 1
149151
J[i+M, i+M] = 1
150152
end
153+
sparseJ = sparse(J)
151154
p = (ks, Γ)
152-
csm(J, u0, p, 0)
153-
return DDS(csm, u0, p, csm, J)
155+
csm(sparseJ, u0, p, 0)
156+
return DDS(csm, u0, p, csm, sparseJ)
154157
end
155158
struct CoupledStandardMaps{N}
156159
idxs::SVector{N, Int}
@@ -188,7 +191,7 @@ function (f::CoupledStandardMaps{M})(
188191
J[i, f.idxsm1[i]] = J[i+M, f.idxsm1[i]]
189192
J[i, f.idxsp1[i]] = J[i+M, f.idxsp1[i]]
190193
end
191-
return nothing
194+
return J
192195
end
193196

194197

src/dynamicalsystem/dynamicalsystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using LinearAlgebra, DiffEqBase, ForwardDiff, StaticArrays
22
import DiffEqBase: isinplace, reinit!
3+
using SparseArrays
34

45
export dimension, get_state, DynamicalSystem
56
export ContinuousDynamicalSystem, DiscreteDynamicalSystem

test/discrete_systems.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using DynamicalSystemsBase
22
using Test, StaticArrays
33
using DynamicalSystemsBase: DDS, DS
4+
using LinearAlgebra
45

56
println("\nTesting discrete system evolution...")
67

@@ -58,3 +59,25 @@ end
5859

5960
@test jacobian(ds) != jacobian(ds, rand(2M))
6061
end
62+
63+
using SparseArrays
64+
@testset "Sparse Matrix Jacobian" begin
65+
66+
ds = Systems.coupledstandardmaps(10)
67+
J = ds.J
68+
69+
sJ = sparse(J)
70+
71+
sparseds = DiscreteDynamicalSystem(ds.f, ds.u0, ds.p, ds.jacobian, sJ)
72+
73+
j = jacobian(sparseds)
74+
@test typeof(j) <: SparseMatrixCSC
75+
76+
tinteg = tangent_integrator(sparseds, 4)
77+
78+
prev = deepcopy(get_deviations(tinteg))
79+
step!(tinteg)
80+
81+
curr = deepcopy(get_deviations(tinteg))
82+
@test prev != curr
83+
end

0 commit comments

Comments
 (0)