Skip to content

Commit

Permalink
add tests and fix stochastic matrix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsignorelli committed Jun 26, 2024
1 parent b23d8fb commit 391af76
Show file tree
Hide file tree
Showing 39 changed files with 63 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/map/ctors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ function zero(::Type{$t{S,T,U,V,W}}; use::UseType=GTPSA.desc_current, idpt::W=no

if V != Nothing
E = similar(V, nv, nv)
E .= 0
else
E = nothing
end
Expand Down
2 changes: 1 addition & 1 deletion src/map/methods.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# --- norm ---
function norm(m::Union{TaylorMap,VectorField})
nrm = zero(numtype(eltype(m.x)))
nrm = 0.

nv = numvars(m)
for i=1:nv
Expand Down
2 changes: 1 addition & 1 deletion src/normal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function normal(m::DAMap, resonances=nothing)

an = canc^-1

return a0 a1 an, eg
return a0 a1 an#, eg
end


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
67 changes: 60 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NonlinearNormalForm
using Test

@testset "NonlinearNormalForm.jl" begin
@testset "Composition and inversion" begin
d = Descriptor(1,2)
x1 = vars()[1]
m1 = DAMap(x=[1+2*x1+2*x1^2], x0=[4])
Expand All @@ -19,9 +19,62 @@ using Test
@test norm(m2^3 - DAMap(x=[1+8*x1+56*x1^2], x0=[3])) < tol
@test norm(mt2^3 - TPSAMap(x=[13+8*x1-8*x1^2], x0=[3])) < tol

# with temporary inverter"
#@test norm(m1^-3 - DAMap(x=[4+0.125*x1-0.109375*x1^2],x0=[1])) < tol
#@test norm(m1^-3 - inv(m1^3)) < tol
#@test norm(mt1^-3 - inv(mt1^3)) < tol
#@test norm(mt1^-3 - TPSAMap(x=[4+0.9615384615384616E-02*x1-0.4978379608557124E-04*x1^2],x0=[-35])) < tol
end
@test norm(m1^-3 - DAMap(x=[4+0.125*x1-0.109375*x1^2],x0=[1])) < tol
@test norm(m1^-3 - inv(m1^3)) < tol
@test norm(mt1^-3 - inv(mt1^3)) < tol
@test norm(mt1^-3 - TPSAMap(x=[4+0.9615384615384616E-02*x1-0.4978379608557124E-04*x1^2],x0=[-35])) < tol
end

@testset "Comparison with FPP" begin

tol = 1e-12


# Normal form -------------------------------------
# 2D all pseudo-harmonic oscillators order 3
m = read_fpp_map("order2/test.map")
R_fpp = read_fpp_map("order2/R.map")
c = to_phasor(m)
a = normal(m)
@test norm(inv(c)inv(a)mac - R_fpp) < tol

# 2D all pseudo-harmonic oscillators order 10
m = read_fpp_map("order10/test.map")
R_fpp = read_fpp_map("order10/R.map")
c = to_phasor(m)
a = normal(m)
@test norm(inv(c)inv(a)mac - R_fpp) < tol

# 4D all pseudo-harmonic oscillators order 6
m = read_fpp_map("order6var4/test.map")
R_fpp = read_fpp_map("order6var4/R.map")
c = to_phasor(m)
a = normal(m)
@test norm(inv(c)inv(a)mac - R_fpp) < 1e-8

# 6D coasting last plane order 3
m = read_fpp_map("coast/test.map",idpt=true)
R_fpp = read_fpp_map("coast/R.map",idpt=true)
c = to_phasor(m)
a = normal(m)
@test norm(inv(c)inv(a)mac - R_fpp) < tol

# Equilibrium moments -----------------------------
Σ_fpp = [ 0.3799021729309453E-03 0.6751391708793735E-04 0.5210559309521585E-04 0.5356022290151431E-04 0.7855831912608747E-04 0.2787256761813361E-04;
0.6751391708793728E-04 0.1198436499688306E-03 0.2355446920731669E-05 0.2584036833779584E-04 0.4495800939032602E-04 -0.5279019399759065E-05;
0.5210559309521584E-04 0.2355446920731667E-05 0.9446395990088929E-04 0.6887819755086758E-04 0.1212047267833650E-03 0.1627981838787403E-03;
0.5356022290151429E-04 0.2584036833779585E-04 0.6887819755086762E-04 0.2881897937276110E-03 0.8460461412432578E-04 -0.8485345202908079E-05;
0.7855831912608744E-04 0.4495800939032603E-04 0.1212047267833649E-03 0.8460461412432579E-04 0.1116532341434929E-03 0.9345624000572918E-04;
0.2787256761813363E-04 -0.5279019399759087E-05 0.1627981838787403E-03 -0.8485345202908038E-05 0.9345624000572919E-04 0.2503415143184575E-03]
m = read_fpp_map("radiation/test.map")
R_fpp = read_fpp_map("radiation/R.map")
c = to_phasor(m)
a = normal(m)
@test norm(inv(c)*inv(a)*m*a*c - R_fpp) < tol
Σ = equilibrium_moments(m,a)
@test norm- Σ_fpp) < tol



end

0 comments on commit 391af76

Please sign in to comment.