Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RateSystem #117

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CriticalTransitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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 +70,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
31 changes: 31 additions & 0 deletions src/RateSystem.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# | | | |
# t_i autonomous t_ni non-autonomous t_nf autonomous t_f
# | | | |

# we write

function RateSystem(tni,tnf,f,λ,p_λ,initvals)
func(u,p,t) = combined_system(u,t,tni,tnf,f,λ,p_λ);
return CoupledODEs(func, initvals, Float64[], t0=tni)
end

function combined_system(u,t,tni,tnf,f,λ,p_λ)
lambda = t < tni ? λ(u,p_λ,tni) : tni <= t <= tnf ? λ(u,p_λ,t) : λ(u,p_λ,tnf)
return f(u,lambda,t)
end;


###############
# user writes

# ...moved to test/RateSystem.jl (Reyk)


# further ideas
# function futureSyst(RateSyst)
# Canard Trajectories

# \dot(x) = f(x(t),λ(t))



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)
Loading