Skip to content

Commit

Permalink
incorporated RateSystem file
Browse files Browse the repository at this point in the history
  • Loading branch information
reykboerner committed Oct 16, 2024
1 parent c71f1b4 commit 525c6a1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/CriticalTransitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ using StochasticDiffEq:
u_modified!
using DynamicalSystemsBase:
DynamicalSystemsBase,
ContinuousTimeDynamicalSystem,
CoupledSDEs,
CoupledODEs,
dynamic_rule,
Expand Down Expand Up @@ -55,6 +56,7 @@ include("extention_functions.jl")
include("utils.jl")
include("system_utils.jl")
include("io.jl")
include("RateSystem.jl")
include("trajectories/simulation.jl")
include("trajectories/transition.jl")
include("trajectories/equib.jl")
Expand All @@ -69,6 +71,7 @@ using .CTLibrary
# Core types
export CoupledSDEs, CoupledODEs, noise_process, covariance_matrix, diffusion_matrix
export dynamic_rule, current_state, set_state!, trajectory
export RateSystem

# Methods
export drift, div_drift
Expand Down
26 changes: 2 additions & 24 deletions src/RateSys.jl → src/RateSystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
# t_i autonomous t_ni non-autonomous t_nf autonomous t_f
# | | | |

using DynamicalSystems
using Plots

# we write

function RateSyst(tni,tnf,f,λ,p_λ,initvals)
function RateSystem(tni,tnf,f,λ,p_λ,initvals)
func(u,p,t) = combined_system(u,t,tni,tnf,f,λ,p_λ);
return ContinuousDynamicalSystem(func, initvals, Float64[], t0=tni)
end
Expand All @@ -21,26 +18,7 @@ end;
###############
# user writes

function f(u::SVector{1, Float64},p::SVector{1, Float64},t::Float64)
x = u[1]
λ = p[1]
dx = (x+λ)^2 - 1
return SVector{1}(dx)
end;

function λ(p::Vector{Float64},t::Float64)
r,λ_max = p
lambda = (λ_max/2)*(tanh(λ_max*r*t/2) +1)
return SVector{1}(lambda)
end;

tni=-10.; tnf=10.; p_λ = [1.0,3.0]; initvals = [-4.];
sys = RateSyst(tni,tnf,f,λ,p_λ,initvals)

traj=trajectory(sys,40.,t0=-20.)

trajic=[traj[1][i][1] for i in 1:length(traj[1])]
plot(collect(traj[2]),trajic)
# ...moved to test/RateSystem.jl (Reyk)


# further ideas
Expand Down
22 changes: 22 additions & 0 deletions test/RateSystem.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Plots

function f(u::SVector{1, Float64},p::SVector{1, Float64},t::Float64)
x = u[1]
λ = p[1]
dx = (x+λ)^2 - 1
return SVector{1}(dx)
end;

function λ(p::Vector{Float64},t::Float64)
r,λ_max = p
lambda = (λ_max/2)*(tanh(λ_max*r*t/2) +1)
return SVector{1}(lambda)
end;

tni=-10.; tnf=10.; p_λ = [1.0,3.0]; initvals = [-4.];
sys = RateSystem(tni,tnf,f,λ,p_λ,initvals)

traj=trajectory(sys,40.,t0=-20.)

trajic=[traj[1][i][1] for i in 1:length(traj[1])]
plot(collect(traj[2]),trajic)

0 comments on commit 525c6a1

Please sign in to comment.