You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ext/MTKBifurcationKitExt.jl
+78-16Lines changed: 78 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,64 @@ module MTKBifurcationKitExt
6
6
using ModelingToolkit, Setfield
7
7
import BifurcationKit
8
8
9
+
### Observable Plotting Handling ###
10
+
11
+
# Functor used when the plotting variable is an observable. Keeps track of the required information for computing the observable's value at each point of the bifurcation diagram.
12
+
struct ObservableRecordFromSolution{S,T}
13
+
# The equations determining the observables values.
14
+
obs_eqs::S
15
+
# The index of the observable that we wish to plot.
16
+
target_obs_idx::Int64
17
+
# The final index in subs_vals that contains a state.
18
+
state_end_idxs::Int64
19
+
# The final index in subs_vals that contains a param.
20
+
param_end_idxs::Int64
21
+
# The index (in subs_vals) that contain the bifurcation parameter.
22
+
bif_par_idx::Int64
23
+
# A Vector of pairs (Symbolic => value) with teh default values of all system variables and parameters.
24
+
subs_vals::T
25
+
26
+
functionObservableRecordFromSolution(nsys::NonlinearSystem, plot_var, bif_idx, u0_vals, p_vals) where {S,T}
27
+
obs_eqs =observed(nsys)
28
+
target_obs_idx =findfirst(isequal(plot_var, eq.lhs) for eq inobserved(nsys))
# Gets the (base) substitution values for parameters.
36
+
subs_vals_params =Pair.(parameters(nsys),p_vals)
37
+
# Gets the (base) substitution values for observables.
38
+
subs_vals_obs = [obs.lhs =>substitute(obs.rhs, [subs_vals_states; subs_vals_params]) for obs inobserved(nsys)]
39
+
# Sometimes observables depend on other observables, hence we make a second upate to this vector.
40
+
subs_vals_obs = [obs.lhs =>substitute(obs.rhs, [subs_vals_states; subs_vals_params; subs_vals_obs]) for obs inobserved(nsys)]
41
+
# During the bifurcation process, teh value of some states, parameters, and observables may vary (and are calculated in each step). Those that are not are stored in this vector
0 commit comments