### Example: Standard Shooting setup Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-periodic-orbits.md Complete example demonstrating the setup of a Van der Pol oscillator for shooting methods. ```julia using BifurcationKit, OrdinaryDiffEq # Define ODE function limit_cycle_ode(u, p, t) x, y = u μ = p[1] return [y, μ*(1 - x^2)*y - x] # Van der Pol end # Initial conditions and parameters u0 = [1.0, 0.0] p0 = [1.0] ode_prob = ODEProblem(limit_cycle_ode, u0, (0.0, 10.0), p0) # Setup shooting flow = Flow(ode_prob, Tsit5()) M = 5 # 5 shooting sections shooting = Shooting(flow, M; section = SectionSS()) # Create bifurcation problem prob_po = BifurcationProblem(shooting, [u0; period], p0, (@optic _[1])) ``` -------------------------------- ### Example: Poincaré shooting setup Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-periodic-orbits.md Example demonstrating the initialization of a Poincaré shooting method with an explicit section. ```julia # Poincaré shooting with explicit section normal = [1.0, 0.0] # Section normal x0 = [0.0, 0.0] # Point on section section = SectionPS(normal, x0) poincare_shooting = PoincareShooting(flow, section) ``` -------------------------------- ### Run Continuation Example Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-continuation.md A complete example demonstrating the setup of a bifurcation problem, continuation parameters, and execution of the continuation algorithm. ```julia using BifurcationKit # Setup F(x, p) = [x[1]^2 - p[1], x[2] - 1] J(x, p) = [2*x[1] 0; 0 1] prob = BifurcationProblem(F, [0.5, 1.0], (0.5,); J = J) # Parameters opts = ContinuationPar( p_min = 0.0, p_max = 2.0, max_steps = 500, detect_bifurcation = 3 ) # Run br = continuation(prob, PALC(), opts) # Analyze println(length(br), " steps") println("Bifurcations: ", length(br.specialpoint)) ``` -------------------------------- ### Add Packages for SH2d-fronts-cuda.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs AbstractFFTs, FFTW, KrylovKit, Plots, and CUDA for the SH2d-fronts-cuda.jl example. CUDA is not required to run the example. ```julia using Pkg pkg"add AbstractFFTs FFTW KrylovKit Plots CUDA" ``` -------------------------------- ### Continuation Execution Examples Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-continuation.md Examples of running continuation with different algorithms. ```julia using BifurcationKit # Use PALC br = continuation(prob, PALC(), opts) # Use Natural parametrization br = continuation(prob, Natural(), opts) # Use multiple shooting for periodic orbits br_po = continuation(prob_po, Multiple(opts), opts) ``` -------------------------------- ### Example usage of TWModel Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/types-and-arrays.md Shows how to initialize a traveling wave model and perform continuation. ```julia using BifurcationKit # Traveling wave problem prob_tw = TWModel(prob_pde, 50) # Continuation of traveling waves br_tw = continuation(prob_tw, PALC(), opts) ``` -------------------------------- ### Newton Solver Configurations Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/configuration-reference.md Example configurations for different problem scales and hardware requirements. ```julia newton = NewtonPar( tol = 1e-10, max_iterations = 20, linsolver = DefaultLS() ) ``` ```julia newton = NewtonPar( tol = 1e-8, max_iterations = 30, linsolver = GMRESKrylovKit(restart = 40, tol = 1e-5) ) ``` ```julia newton = NewtonPar( tol = 1e-8, max_iterations = 25, linsolver = GMRESKrylovKit(restart = 50, tol = 1e-4) ) ``` -------------------------------- ### Implement a discrete event example Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/events-and-bifurcations.md Example of defining a condition function that triggers every 10 steps and creating a DiscreteEvent instance. ```julia # Event: every 10 steps function every_n_steps(iter::ContIterable, state::ContState) return state.step % 10 == 0 end event = DiscreteEvent(2, every_n_steps) ``` -------------------------------- ### Setup Deflation for Multiple Branches Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/types-and-arrays.md Example of using DeflatedProblem to continue multiple branches by populating the deflation operator from a previous continuation. ```julia # Setup deflation for multiple branches defl = DeflationOperator(1.0, 2.0) # Continue first branch normally br1 = continuation(prob, PALC(), opts; max_steps = 100) for sol in br1.sol add_solution!(defl, sol.x) end # Continue second branch with deflation prob_defl = DeflatedProblem(prob, defl) br2 = continuation(prob_defl, PALC(), opts; max_steps = 100) ``` -------------------------------- ### Add Packages for SH2d-fronts.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs Plots, SparseArrays, LinearAlgebra, and IncompleteLU for the SH2d-fronts.jl example. ```julia using Pkg pkg"add Plots SparseArrays LinearAlgebra IncompleteLU" ``` -------------------------------- ### Directory Tree Example Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/test/README.md Illustrates the expected directory structure for test files within the `test` directory. ```bash ./ ├── codim_2_po_collocation/ │ └── codim2PO-OColl.jl ├── codim_2_po_shooting/ │ └── codim2PO-shooting.jl ├── codim_2_po_shooting_mf/ │ └── codim2PO-shooting-mf.jl ├── condensation_of_parameters/ │ └── cop.jl ├── continuation/ │ ├── simple_continuation.jl │ ├── test_bif_detection.jl │ └── test-cont-non-vector.jl ... ├── results/ │ └── test_results.jl ├── runtests.jl └── wave/ └── test_wave.jl ``` -------------------------------- ### Full bifurcation diagram analysis Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-bifurcation-diagram.md Example demonstrating the setup, computation, and recursive analysis of a bifurcation diagram. ```julia using BifurcationKit # Setup cubic bifurcation with hysteresis F(u, p) = [u[1]^3 - u[1] + p[1]] J(u, p) = [3*u[1]^2 - 1] prob = BifurcationProblem(F, [0.0], (0.0,); J = J) # Parameters for diagram opts = ContinuationPar( p_min = -2.0, p_max = 2.0, max_steps = 200, detect_bifurcation = 3 ) # Compute diagram bd = bifurcationdiagram(prob, PALC(), opts, 2) # Analyze function analyze_diagram(bd::BifDiagNode, level=0, path=[]) indent = " " ^ level br = bd.branch println("$(indent)Branch at level $level: $(length(br)) points") println("$(indent) Type code: $(bd.code)") # Print bifurcation points on this branch for bp in br.specialpoint println("$(indent) Bifurcation: $(bp.type) at p=$(bp.param)") end # Recurse to children for (i, child) in enumerate(bd.children) analyze_diagram(child, level + 1, [path; i]) end end analyze_diagram(bd) ``` -------------------------------- ### Add Packages for SH3d.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs KrylovKit, GLMakie, SparseArrays, and SuiteSparse for the SH3d.jl example. ```julia using Pkg pkg"add KrylovKit GLMakie SparseArrays SuiteSparse" ``` -------------------------------- ### Add Packages for codim2PO.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs Plots, ForwardDiff, and OrdinaryDiffEq for the codim2PO.jl example. ```julia using Pkg pkg"add Plots ForwardDiff OrdinaryDiffEq" ``` -------------------------------- ### Add Packages for brusselatorShooting.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs Plots, SparseArrays, LoopVectorization, DifferentialEquations, ForwardDiff, and SparseDiffTools for the brusselatorShooting.jl example. ```julia using Pkg pkg"add Plots SparseArrays LoopVectorization DifferentialEquations ForwardDiff SparseDiffTools" ``` -------------------------------- ### Add Packages for codim2PO-sh-mf.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs Test, Plots, ComponentArrays, DifferentialEquations, DifferentiationInterface, Zygote, and ForwardDiff for the codim2PO-sh-mf.jl example, which is a Work In Progress. ```julia using Pkg pkg"add Test Plots ComponentArrays DifferentialEquations DifferentiationInterface Zygote ForwardDiff" ``` -------------------------------- ### Apply PrecPartialSchurKrylovKit in Newton Solver Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/types-and-arrays.md Example demonstrating the creation of the preconditioner and its integration into a GMRES linear solver. ```julia using BifurcationKit\n\n# Create preconditioner\nprec = PrecPartialSchurKrylovKit(nev = 20, tol = 1e-4)\n\n# Use in linear solver\nls = GMRESKrylovKit(restart = 40, Pr = prec)\nnewton_opts = NewtonPar(linsolver = ls) ``` -------------------------------- ### Add Packages for pd-1d.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs ForwardDiff, DifferentialEquations, and SparseArrays for the pd-1d.jl example. ```julia using Pkg pkg"add ForwardDiff DifferentialEquations SparseArrays" ``` -------------------------------- ### Add Packages for COModel.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs Plots and DifferentialEquations for the COModel.jl example. ```julia using Pkg pkg"add Plots DifferentialEquations" ``` -------------------------------- ### Add Packages for cGL2d-Shooting.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs Plots and SparseArrays for the cGL2d-Shooting.jl example. ```julia using Pkg pkg"add Plots SparseArrays" ``` -------------------------------- ### Example Usage of Trapezoid Method Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-periodic-orbits.md Demonstrates setting up a periodic orbit problem using the Trapeze method and running a continuation. ```julia using BifurcationKit # Using trapezoid rule po_trap = Trapeze(prob, 50) # Continuation br_po = continuation_potrap(prob, PALC(), opts) ``` -------------------------------- ### Add Packages for brusselator.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs Plots and SparseArrays for the brusselator.jl example. ```julia using Pkg pkg"add Plots SparseArrays " ``` -------------------------------- ### Configure Newton Solver with DefaultEig Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Example usage of DefaultEig within the Newton and Continuation parameter structures. ```julia using BifurcationKit eig = DefaultEig(which = real) newton_opts = NewtonPar(eigsolver = eig) opts = ContinuationPar(newton_options = newton_opts) ``` -------------------------------- ### Continuation Result Example Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-continuation.md Demonstrates running a continuation and accessing the resulting branch data, bifurcation points, and stability information. ```julia using BifurcationKit # Run continuation br = continuation(prob, PALC(), ContinuationPar(max_steps = 500)) # Access results println("Branch has ", length(br), " steps") println("Parameters: ", br.param) # Check bifurcations bifs = bifurcation_points(br) for bp in bifs println("Bifurcation at p = $(bp.param), type = $(bp.type)") end # Extract solution at specific step sol = get_solx(br, 50) p_val = get_solp(br, 50) # Check stability for i in 1:length(br) if br[i].stable == false println("Unstable at step $i: ", br[i].n_unstable, " unstable modes") end end ``` -------------------------------- ### Example Usage of Collocation Method Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-periodic-orbits.md Demonstrates setting up a periodic orbit problem using the Collocation method and running a continuation. ```julia using BifurcationKit # Problem F(u, p) = [u[2], -u[1] - p[1]*u[2]*(u[1]^2 - 1)] J(u, p) = [0 1; -1 - 2*p[1]*u[1]*u[2] -p[1]*(u[1]^2 - 1)] prob = BifurcationProblem(F, [1.0, 0.0], (0.1,); J = J) # Collocation M = 20 # 20 collocation points po_coll = Collocation(prob, M) # Setup continuation opts = ContinuationPar(p_min = 0.0, p_max = 5.0, max_steps = 100) br_po = continuation(prob_po, PALC(), opts) ``` -------------------------------- ### Add Packages for carrier.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs Plots, SparseArrays, and BandedMatrices for the carrier.jl example. ```julia using Pkg pkg"add Plots SparseArrays BandedMatrices" ``` -------------------------------- ### Example usage of TimeMesh Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/types-and-arrays.md Demonstrates creating a uniform time mesh and accessing its properties. ```julia using BifurcationKit # Uniform mesh for periodic orbit mesh = TimeMesh(20; kind = :uniform) println("Mesh points: ", mesh.mesh) println("Quadrature weights: ", mesh.weights) ``` -------------------------------- ### Add Packages for cGL2d.jl Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/examples/readme.md Installs Plots, ForwardDiff, IncompleteLU, and SparseArrays for the cGL2d.jl example. ```julia using Pkg pkg"add Plots ForwardDiff IncompleteLU SparseArrays" ``` -------------------------------- ### Configure Newton Parameters with GMRES Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Example of setting up Newton parameters with a specific linear solver for use in continuation. ```julia using BifurcationKit # Create Newton parameters with GMRES newton_opts = NewtonPar( tol = 1e-10, max_iterations = 20, verbose = true, linsolver = GMRESIterativeSolvers() ) # Use in continuation opts = ContinuationPar(newton_options = newton_opts) ``` -------------------------------- ### Apply PrecPartialSchurArnoldiMethod in Newton Solver Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/types-and-arrays.md Example demonstrating the creation of the ArnoldiMethod preconditioner and its integration into a GMRESIterativeSolvers solver. ```julia using BifurcationKit, ArnoldiMethod\n\n# Preconditioner using largest magnitude eigenvalues\nprec = PrecPartialSchurArnoldiMethod(which = LM(), nev = 20)\n\n# Use in Newton solver\nls = GMRESIterativeSolvers(restart = 40, Pr = prec) ``` -------------------------------- ### Configure Floquet Multipliers in Continuation Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-periodic-orbits.md Example of integrating FloquetQaD into the Newton solver options for continuation. ```julia using BifurcationKit\n\n# Compute Floquet multipliers\nfloquet = FloquetQaD()\n\n# In continuation\nopts = ContinuationPar(\n newton_options = NewtonPar(eigsolver = floquet)\n) ``` -------------------------------- ### BorderedArray Usage Example Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/types-and-arrays.md Demonstrates initializing a BorderedArray, accessing its components, calculating its norm, and using it with a bordered linear solver. ```julia using BifurcationKit # Setup bordered array for PALC u = [1.0, 2.0, 3.0] p = 0.5 ba = BorderedArray(u, p) # Access components println(ba.u) # [1.0, 2.0, 3.0] println(ba.p) # 0.5 # Compute norm n = norm(ba) # sqrt(1 + 4 + 9 + 0.25) = 3.899... # Use in bordered linear solver ls = BorderingBLS(DefaultLS(), DefaultLS()) sol = ls(J, rhs::BorderedArray) ``` -------------------------------- ### Generate Initial Guess from Analytical Solution Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-periodic-orbits.md Example usage of generate_solution to create an initial condition for a periodic orbit solver. ```julia # Initial guess from analytical solution\nM = 20\npo_coll = Collocation(prob, M)\n\n# Define analytical limit cycle (example)\norbit(t) = [cos(t), sin(t)] # unit circle\nperiod = 2π\n\n# Generate initial condition\nx0 = generate_solution(po_coll, orbit, period)\n\n# Solve for periodic orbit\nsol = newton(prob_po, x0, p0, NewtonPar()) ``` -------------------------------- ### Manual Continuation Loop Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-continuation.md Example of using ContIterable to manually control the continuation process. ```julia using BifurcationKit iter = ContIterable(prob, PALC(), ContinuationPar()) for state in iter println("Step $(state.step): p = $(getp(state))") # Custom processing if state.step > 50 break # Early termination end end ``` -------------------------------- ### Use GMRESIterativeSolvers in Newton Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Demonstrates configuring a Newton solver with GMRESIterativeSolvers, including an example with a right preconditioner. ```julia using BifurcationKit, IterativeSolvers # Matrix-free Newton with GMRES ls = GMRESIterativeSolvers(restart = 40, tol = 1e-6) newton_opts = NewtonPar(linsolver = ls) # With right preconditioner ls = GMRESIterativeSolvers(restart = 40, Pr = myPreconditioner) ``` -------------------------------- ### Define and use BifFunction Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-bifurcation-problem.md Example showing the definition of a vector field and Jacobian, followed by the creation of a BifurcationProblem. ```julia using BifurcationKit # Define the vector field F(x, p) = [x[1]^2 + p[1] - 1, x[2] - x[1]] # Define the Jacobian J(x, p) = [2*x[1] 0; -1 1] # Create the bifurcation function bf = BifFunction(F, J) # Use it in a continuation problem prob = BifurcationProblem(bf, [0.5, 0.5], 0.1, (@optic _[1])) ``` -------------------------------- ### Define and solve a predator-prey model Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-bifurcation-problem.md Example demonstrating the definition of a vector field, its Jacobian, and the creation of a BifurcationProblem for continuation. ```julia using BifurcationKit # Simple predator-prey model function predator_prey(u, p) x, y = u a, b = p.a, p.b return [a*x - x*y, x*y - b*y] end # Jacobian function jac_pp(u, p) x, y = u a, b = p.a, p.b return [a - y -x; y x - b] end # Problem u0 = [1.0, 1.0] params = (a = 1.5, b = 1.0) prob = BifurcationProblem(predator_prey, u0, params, (@optic _.a); J = jac_pp) # Now use with continuation br = continuation(prob, PALC(), ContinuationPar()) ``` -------------------------------- ### Manage multiple events with SetOfEvents Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/events-and-bifurcations.md Example of grouping multiple event types into a set and using them in a continuation process. ```julia events = [ ContinuousEvent(1, cond1), ContinuousEvent(2, cond2), DiscreteEvent(3, cond3) ] event_set = SetOfEvents(events) br = continuation(prob, PALC(), opts; event = event_set) ``` -------------------------------- ### Configure Solvers and Continuation Parameters Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/quick-start-reference.md Set up Newton solver options and continuation parameters for the analysis. ```julia # Newton solver newton = NewtonPar( tol = 1e-10, max_iterations = 20, linsolver = DefaultLS() ) # Continuation parameters opts = ContinuationPar( dsmin = 1e-4, dsmax = 1e-1, ds = 1e-2, p_min = 0.0, p_max = 5.0, max_steps = 500, detect_bifurcation = 3, newton_options = newton ) ``` -------------------------------- ### Configure Continuation Parameters Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-continuation.md Demonstrates how to instantiate ContinuationPar with custom settings and how to integrate it with custom Newton options. ```julia using BifurcationKit # Basic continuation setup opts = ContinuationPar( dsmin = 1e-4, dsmax = 1e-1, ds = 1e-2, p_min = 0.0, p_max = 5.0, max_steps = 1000, detect_bifurcation = 3 ) # With custom Newton options newton_opts = NewtonPar(tol = 1e-10, max_iterations = 20) opts = ContinuationPar(newton_options = newton_opts) ``` -------------------------------- ### Configure Continuation Algorithms Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/configuration-reference.md Select and initialize continuation algorithms for different branch types and convergence requirements. ```julia alg = PALC() ``` ```julia alg = Natural() ``` ```julia alg = Multiple(contparams) ``` ```julia alg = AutoSwitch( algorithms = [PALC(), Natural()], thresholds = [0.5, 1.0] ) ``` -------------------------------- ### Initialize DefaultLS Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Shows the constructor for the DefaultLS solver and its application within Newton parameters. ```julia DefaultLS(; useFactorization = true) ``` ```julia using BifurcationKit # Use in Newton parameters ls = DefaultLS(useFactorization = true) newton_opts = NewtonPar(linsolver = ls) ``` -------------------------------- ### Initialize KrylovLS Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Constructor for the Krylov linear solver wrapper with configurable tolerance and iteration limits. ```julia KrylovLS( solver = :GMRES, tol = 1e-4, maxiter = 100, kwargs... ) ``` -------------------------------- ### Initialize Shooting method Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-periodic-orbits.md Constructor for the standard shooting method for periodic orbits. ```julia Shooting( flow::Flow, M::Int; section = SectionSS(), kwargs... ) ``` -------------------------------- ### Detect General Bifurcations Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/events-and-bifurcations.md Example of using BifDetectEvent to monitor eigenvalue changes and access results. ```julia # Detect Hopf bifurcation event = BifDetectEvent() opts = ContinuationPar( detect_event = 2, # Locate event via bisection tol_param_bisection_event = 1e-10 ) br = continuation(prob, PALC(), opts; event = event) # Access detected events in results for bp in br.specialpoint println("Bifurcation at p = $(bp.param), type = $(bp.type)") end ``` -------------------------------- ### Run All Tests Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/test/README.md Execute all tests in the project using `Pkg.test()`. ```julia julia -e 'Pkg.activate("."); Pkg.test()' ``` ```julia julia -e 'Pkg.activate("."); Pkg.test(test_args = [ "-a" ])' ``` -------------------------------- ### continuation! Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-continuation.md Continues an existing branch of solutions using an inplace algorithm. ```APIDOC ## continuation!(br, alg, contparams; kwargs...) ### Description Inplace version of continuation that continues an existing branch with new parameters and algorithm settings. ### Signature continuation!(br::ContResult, alg::AbstractContinuationAlgorithm, contparams::ContinuationPar; kwargs...) -> ContResult ### Example # Initial continuation br = continuation(prob, PALC(), ContinuationPar(max_steps = 100)) # Continue with more steps br = continuation!(br, PALC(), ContinuationPar(max_steps = 200)) ``` -------------------------------- ### Save Data at Bifurcation Events Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/events-and-bifurcations.md Example of defining a custom save function and using SaveAtEvent during continuation. ```julia # Save bifurcation points function save_bifurcation(iter, state) return (p = getp(state), x = getx(state), step = state.step) end event = ContinuousEvent(1, bifurcation_condition) save_event = SaveAtEvent(event, save_bifurcation) br = continuation(prob, PALC(), opts; event = save_event) ``` -------------------------------- ### Initialize PrecPartialSchurKrylovKit Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/types-and-arrays.md Constructor for the KrylovKit-based partial Schur preconditioner. ```julia PrecPartialSchurKrylovKit(;\n tol = 1e-3,\n nev = 10,\n kwargs...\n) ``` -------------------------------- ### Configure Solvers by Problem Scale Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/README.md Provides recommended solver configurations for small, large, and GPU-based problems. ```julia newton = NewtonPar(linsolver = DefaultLS()) opts = ContinuationPar(nev = min(n, 20), detect_bifurcation = 3) ``` ```julia newton = NewtonPar(linsolver = GMRESKrylovKit(restart = 40)) opts = ContinuationPar(nev = 5, save_eigenvectors = false) ``` ```julia newton = NewtonPar(eigsolver = EigKrylovKit()) opts = ContinuationPar(nev = 3, save_eigenvectors = false) ``` -------------------------------- ### Combine events using PairOfEvents Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/events-and-bifurcations.md Example of combining two continuous events and passing them to the continuation function. ```julia # Combine two events event1 = ContinuousEvent(1, condition1) event2 = ContinuousEvent(2, condition2) pair = PairOfEvents(event1, event2) br = continuation(prob, PALC(), opts; event = pair) ``` -------------------------------- ### Initialize EigKrylovKit Solver Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Constructs an eigenvalue solver using KrylovKit.jl, ideal for matrix-free Jacobian operations. ```julia EigKrylovKit(; which = :LR, howmany = 3, tol = 1e-6, maxiter = 100, kwargs... ) ``` ```julia using BifurcationKit # For matrix-free Jacobians on GPU eig = EigKrylovKit(which = :LR, howmany = 5, tol = 1e-5) ``` -------------------------------- ### Check Newton convergence Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Demonstrates how to verify if a Newton solver result has converged and access its properties. ```julia sol = newton(prob, x0, params, NewtonPar()) # Check convergence if converged(sol) # Use solution x_opt = sol.u # Check iteration counts @info "Converged in $(sol.itnewton) Newton steps" @info "Residuals: $(sol.residuals)" end ``` -------------------------------- ### KrylovLS Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Constructor for the Krylov linear solver wrapper with automatic algorithm selection. ```APIDOC ## KrylovLS ### Description Krylov solver wrapper with automatic algorithm selection. ### Constructor KrylovLS(; solver = :GMRES, tol = 1e-4, maxiter = 100, kwargs...) ### Parameters - **solver** (Symbol) - Default: :GMRES - Which solver to use (:GMRES, :MINRES, :LSMR, etc.) - **tol** (Float) - Default: 1e-4 - Convergence tolerance - **maxiter** (Int) - Default: 100 - Maximum iterations - **kwargs** (—) - Additional arguments passed to solver ``` -------------------------------- ### Solve Nonlinear Equation with Newton Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Demonstrates setting up a bifurcation problem and executing the Newton solver. ```julia using BifurcationKit # Setup problem F(x, p) = [x[1]^2 - p[1], x[2] - 1] J(x, p) = [2*x[1] 0; 0 1] prob = BifurcationProblem(F, [0.5, 1.0], (1.0,); J = J) # Solve opts = NewtonPar(tol = 1e-10) sol = newton(prob, [0.5, 1.0], (1.0,), opts) if converged(sol) println("Solution: ", sol.u) else println("Did not converge") end ``` -------------------------------- ### Configure Medium Problems (100 < n < 10,000) Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/configuration-reference.md Utilize iterative solvers with moderate tolerances and partial spectrum computation. ```julia # Use iterative solvers with reasonable tolerances newton = NewtonPar( linsolver = GMRESKrylovKit(restart = 40, tol = 1e-6), eigsolver = EigKrylovKit(howmany = 5, tol = 1e-5) ) opts = ContinuationPar( dsmin = 1e-5, dsmax = 1e-2, nev = 5, # Partial spectrum save_eig_every_step = 2, # Sparse saves save_eigenvectors = false # Don't store full matrices ) ``` -------------------------------- ### Standard Branch Tracing Configuration Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/configuration-reference.md A balanced configuration for general branch tracing with bifurcation localization enabled. ```julia opts = ContinuationPar( dsmin = 1e-4, dsmax = 1e-1, ds = 1e-2, max_steps = 500, detect_bifurcation = 3, # Locate bifurcations nev = 5, newton_options = NewtonPar(tol = 1e-10) ) ``` -------------------------------- ### Generate Guess from Hopf Bifurcation Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-periodic-orbits.md Signature and usage for creating an initial guess for a periodic orbit starting from a Hopf point. ```julia guess_from_hopf(\n br::ContResult,\n ind::Int,\n ds::Float,\n M::Int\n) -> AbstractVector ``` ```julia # Found Hopf bifurcation in equilibrium branch\nhopf_ind = 1\n\n# Generate periodic orbit guess\nx_po = guess_from_hopf(br_eq, hopf_ind, 0.1, 20)\n\n# Setup and solve periodic orbit problem\npo_prob = Collocation(prob, 20)\nsol_po = newton(po_prob, x_po, p0, NewtonPar()) ``` -------------------------------- ### Configure File I/O with JLD2 Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/configuration-reference.md Save continuation results to disk and load them back into the workspace. ```julia using JLD2 opts = ContinuationPar( save_to_file = true, save_sol_every_step = 5 ) # Automatic filename: "branch-2024-01-15T10:30:45.686.jld2" # Or specify filename: br = continuation( prob, PALC(), opts; filename = "my_branch.jld2" ) ``` ```julia br = JLD2.load("my_branch.jld2")["br"] ``` -------------------------------- ### Initialize NewtonPar Constructor Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Defines the structure for Newton-Krylov algorithm parameters. ```julia NewtonPar( tol = 1e-12, max_iterations = 25, verbose = false, linsolver = DefaultLS(), eigsolver = DefaultEig(), linesearch = false, α = 1.0, αmin = 0.001 ) ``` -------------------------------- ### Manipulate data with get, set, and @set Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/types-and-arrays.md Extract or modify values within structures using optics or the @set macro. ```julia get(lens, obj) -> value ``` ```julia set(lens, obj, value) -> new_obj ``` ```julia @set obj.field = value new_obj = @set obj.field.nested = value ``` -------------------------------- ### Initialize SectionSS Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-periodic-orbits.md Constructor for a standard shooting section without an explicit Poincaré map. ```julia SectionSS() ``` -------------------------------- ### bifurcationdiagram(prob, alg, contparams, levels; kwargs...) Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-bifurcation-diagram.md Computes a bifurcation diagram by recursively tracing branches starting from a bifurcation problem. ```APIDOC ## bifurcationdiagram ### Description Computes a bifurcation diagram by recursively tracing all branches starting from the provided bifurcation problem. ### Signature `bifurcationdiagram(prob::AbstractBifurcationProblem, alg::AbstractContinuationAlgorithm, contparams::ContinuationPar, levels::Int; max_recursion = 2, only_stable = false, verbosity = 0, kwargs...) -> BifDiagNode` ### Parameters - **prob** (BifurcationProblem) - Required - Bifurcation problem - **alg** (ContinuationAlgorithm) - Required - Continuation algorithm (PALC, Natural, etc.) - **contparams** (ContinuationPar) - Required - Continuation parameters - **levels** (Int) - Required - Recursion depth for automatic branch switching - **max_recursion** (Int) - Optional - Maximum recursion level (Default: 2) - **only_stable** (Bool) - Optional - Only trace stable branches (Default: false) - **verbosity** (UInt8) - Optional - Verbosity level 0-3 (Default: 0) - **kwargs** (Any) - Optional - Additional arguments ### Returns - **BifDiagNode** - The root of the bifurcation diagram tree. ### Example ```julia using BifurcationKit # Simple bifurcation problem F(u, p) = [p[1] - u[1]^3 - u[1], u[2]] J(u, p) = [p[1] - 3*u[1]^2 - 1 0; 0 1] prob = BifurcationProblem(F, [0.0, 0.0], (0.0,); J = J) # Continuation parameters opts = ContinuationPar( p_min = -2.0, p_max = 2.0, max_steps = 100, detect_bifurcation = 3 ) # Compute full bifurcation diagram bd = bifurcationdiagram(prob, PALC(), opts, 2) ``` ``` -------------------------------- ### Configure Small Problems (n < 100) Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/configuration-reference.md Use direct solvers for small-scale problems where full spectrum computation is feasible. ```julia # Use direct solvers newton = NewtonPar(linsolver = DefaultLS()) opts = ContinuationPar( dsmin = 1e-4, dsmax = 1e-1, nev = min(n, 10), # Full spectrum save_eigenvectors = true ) ``` -------------------------------- ### ContinuationPar Constructor Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-continuation.md The ContinuationPar constructor initializes the parameters for the continuation algorithm. It accepts various keyword arguments to control step size, bifurcation detection, and solver options. ```APIDOC ## ContinuationPar Constructor ### Description Initializes the configuration object for continuation algorithms in BifurcationKit.jl. ### Signature ContinuationPar(; dsmin, dsmax, ds, a, p_min, p_max, max_steps, newton_options, η, save_to_file, save_sol_every_step, nev, save_eig_every_step, save_eigenvectors, plot_every_step, tol_stability, detect_fold, detect_bifurcation, dsmin_bisection, n_inversion, max_bisection_steps, tol_bisection_eigenvalue, detect_event, tol_param_bisection_event, detect_loop) ### Parameters - **dsmin** (Float) - Minimum arc-length step size. - **dsmax** (Float) - Maximum arc-length step size. - **ds** (Float) - Initial arc-length step size. - **max_steps** (Int) - Maximum number of continuation steps. - **newton_options** (NewtonPar) - Configuration for the underlying Newton solver. - **detect_bifurcation** (Int) - Bifurcation detection level (0=none, 1=compute eigs, 2=detect, 3=locate). ### Example ```julia using BifurcationKit # Basic continuation setup opts = ContinuationPar( dsmin = 1e-4, dsmax = 1e-1, ds = 1e-2, p_min = 0.0, p_max = 5.0, max_steps = 1000, detect_bifurcation = 3 ) ``` ``` -------------------------------- ### Set Environment Variables Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/configuration-reference.md Shell commands to configure debugging and hardware acceleration settings. ```bash export DEBUG=1 ``` ```bash export VERBOSE=2 ``` ```bash export BKIT_GPU=1 ``` ```bash export BKIT_PRECOND=1 ``` -------------------------------- ### NewtonPar Constructor Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/configuration-reference.md Configuration parameters for the Newton solver, including convergence criteria, line search settings, and solver selection. ```APIDOC ## NewtonPar(tol, max_iterations, ...) ### Description Defines parameters for the Newton solver used in bifurcation analysis. ### Parameters - **tol** (Float64) - Optional - Residual tolerance for convergence. - **max_iterations** (Int) - Optional - Maximum number of Newton steps. - **linesearch** (Bool) - Optional - Enable Armijo line search. - **α** (Float64) - Optional - Initial damping factor. - **αmin** (Float64) - Optional - Minimum damping factor. - **linesolver** (Any) - Optional - Linear system solver. - **eigsolver** (Any) - Optional - Eigenvalue solver. - **verbose** (Bool) - Optional - Enable progress printing. ``` -------------------------------- ### Define and solve an ODE bifurcation problem Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-bifurcation-problem.md Demonstrates creating an ODE system with ModelingToolkit, converting it to an ODEProblem, and initializing an ODEBifProblem for continuation. ```julia using BifurcationKit, OrdinaryDiffEq, ModelingToolkit # Define an ODE system with ModelingToolkit @variables t x(t) y(t) @parameters p eqs = [ Dt(x) ~ p*x - x*y, Dt(y) ~ x*y - y ] sys = ODESystem(eqs) # Convert to ODE problem ode_prob = ODEProblem(sys, [1.0, 1.0], (0.0, 100.0), [1.5]) # Create bifurcation problem bif_prob = ODEBifProblem(ode_prob, Tsit5(); lens = setindex(p, 2)) # Run continuation br = continuation(bif_prob, PALC(), ContinuationPar()) ``` -------------------------------- ### Initialize Collocation Method Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-periodic-orbits.md Constructor for the Collocation method requiring a BifurcationProblem and the number of collocation points. ```julia Collocation( prob::BifurcationProblem, M::Int; kwargs... ) ``` -------------------------------- ### Initialize KrylovLSInplace Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Constructor for the inplace variant of the Krylov linear solver, designed for pre-allocated memory usage. ```julia KrylovLSInplace(; kwargs...) ``` -------------------------------- ### Initialize PrecPartialSchurArnoldiMethod Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/types-and-arrays.md Constructor for the ArnoldiMethod-based partial Schur preconditioner. ```julia PrecPartialSchurArnoldiMethod(;\n which = LM(),\n nev = 10,\n kwargs...\n) ``` -------------------------------- ### Compute Bifurcation Diagram in Julia Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-bifurcation-diagram.md Demonstrates setting up a bifurcation problem, defining continuation parameters, and executing the recursive bifurcation diagram computation. ```julia using BifurcationKit # Simple bifurcation problem F(u, p) = [p[1] - u[1]^3 - u[1], u[2]] J(u, p) = [p[1] - 3*u[1]^2 - 1 0; 0 1] prob = BifurcationProblem(F, [0.0, 0.0], (0.0,); J = J) # Continuation parameters opts = ContinuationPar( p_min = -2.0, p_max = 2.0, max_steps = 100, detect_bifurcation = 3 ) # Compute full bifurcation diagram bd = bifurcationdiagram(prob, PALC(), opts, 2) # Explore the diagram println("Root branch has ", length(bd.branch), " points") # Access secondary branches for child in bd.children println("Child branch at bifurcation $(child.bifpoint)") end ``` -------------------------------- ### Initialize ContinuationPar Constructor Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-continuation.md The constructor for ContinuationPar defines the default settings for the continuation algorithm. ```julia ContinuationPar( dsmin = 1e-4, dsmax = 1e-1, ds = 1e-2, a = 0.5, p_min = -1.0, p_max = 1.0, max_steps = 400, newton_options = NewtonPar(), η = 150.0, save_to_file = false, save_sol_every_step = 1, nev = 3, save_eig_every_step = 1, save_eigenvectors = true, plot_every_step = 10, tol_stability = 1e-10, detect_fold = true, detect_bifurcation = 3, dsmin_bisection = 1e-16, n_inversion = 2, max_bisection_steps = 25, tol_bisection_eigenvalue = 1e-16, detect_event = 0, tol_param_bisection_event = 1e-16, detect_loop = false ) ``` -------------------------------- ### Use GMRESKrylovKit in Newton Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Demonstrates configuring a Newton solver with GMRESKrylovKit, suitable for GPU-friendly matrix-free problems. ```julia using BifurcationKit, KrylovKit # For GPU-friendly matrix-free problems ls = GMRESKrylovKit(restart = 40, tol = 1e-5) newton_opts = NewtonPar(linsolver = ls) ``` -------------------------------- ### Run Continuation Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/quick-start-reference.md Execute the continuation algorithm using the defined problem and options. ```julia br = continuation( prob, PALC(), # Algorithm opts, # Parameters verbosity = 2 ) ``` -------------------------------- ### Fast Branch Tracing Configuration Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/configuration-reference.md Use this configuration for low-accuracy, high-speed branch tracing where only eigenvalue computation is required. ```julia opts = ContinuationPar( dsmin = 1e-3, dsmax = 5e-2, ds = 1e-2, max_steps = 200, detect_bifurcation = 1, # Compute eigenvalues only nev = 3, newton_options = NewtonPar(tol = 1e-6, max_iterations = 10) ) ``` -------------------------------- ### Initialize BifDetectEvent Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/events-and-bifurcations.md Constructor for the BifDetectEvent. ```julia BifDetectEvent() ``` -------------------------------- ### Initialize EigArpack Solver Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Constructs an eigenvalue solver using Arpack.jl. Requires Arpack to be loaded in the environment. ```julia EigArpack(sigma = nothing, which = :LR; kwargs...) ``` ```julia using BifurcationKit, Arpack # Find largest real eigenvalues eig = EigArpack(which = :LR, tol = 1e-6) # Shift-invert for smallest eigenvalues eig = EigArpack(sigma = 0.0, which = :SM) ``` -------------------------------- ### Construct PropertyLens and IndexLens Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/types-and-arrays.md Directly instantiate lenses for property or index access. ```julia lens = PropertyLens(:alpha) ``` ```julia lens = IndexLens(2) # Select second element ``` -------------------------------- ### PrecPartialSchurKrylovKit Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/types-and-arrays.md Constructor for a preconditioner based on partial Schur decomposition using KrylovKit. ```APIDOC ## PrecPartialSchurKrylovKit ### Description Creates a preconditioner based on partial Schur decomposition with KrylovKit. ### Parameters - **tol** (Float) - Optional - Convergence tolerance (Default: 1e-3) - **nev** (Int) - Optional - Number of eigenvalues for preconditioner (Default: 10) - **kwargs** (Any) - Optional - Additional KrylovKit arguments ### Example ```julia using BifurcationKit prec = PrecPartialSchurKrylovKit(nev = 20, tol = 1e-4) ls = GMRESKrylovKit(restart = 40, Pr = prec) ``` ``` -------------------------------- ### Construct EigArnoldiMethod Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/_autodocs/api-newton-linear-solvers.md Initializes the Arnoldi-based eigenvalue solver with specified convergence criteria and eigenvalue selection strategy. ```julia EigArnoldiMethod( which = LM(), nev = 3, tol = 1e-6, maxiter = 100, kwargs... ) ``` ```julia using BifurcationKit, ArnoldiMethod # Find eigenvalues with largest magnitude eig = EigArnoldiMethod(which = LM(), nev = 5) ```