### 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" ``` -------------------------------- ### 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 ``` -------------------------------- ### 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" ``` -------------------------------- ### 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" ``` -------------------------------- ### 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 " ``` -------------------------------- ### 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 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 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 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 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" ``` -------------------------------- ### 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 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" ``` -------------------------------- ### 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" ``` -------------------------------- ### Periodic Orbit Continuation with Trapezoidal Discretization Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Initiates periodic orbit continuation using the Trapezoidal discretization method. Requires BifurcationKit, OrdinaryDiffEq, and LinearAlgebra. Setup involves defining the ODE problem, initial conditions, parameters, and continuation options. ```julia using BifurcationKit, OrdinaryDiffEq, LinearAlgebra # ── Method 1: Trapezoidal discretization probPO_trap = Trapeze(M = 100; N = 2n, # M time slices, N state dim jacobian = BK.DenseAnalytical()) br_po = continuation(br, 1, opts_po, probPO_trap; δp = 0.01, verbosity = 1, normC = norminf) ``` -------------------------------- ### Eigensolvers: Arpack and ArnoldiMethod Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Demonstrates the setup of different eigensolvers, specifically Arpack and ArnoldiMethod. These are used in bifurcation analysis to find eigenvalues, often for detecting Hopf bifurcations. ```julia using BifurcationKit, LinearAlgebra # Arpack eigensolver – `σ` is a shift, `:LM` = largest magnitude after shift eig = EigArpack(0.1, :LM) # ArnoldiMethod eigensolver (pure Julia, no binary dependency) eig2 = EigArnoldiMethod(nev = 10, which = LR()) # LR = largest real part ``` -------------------------------- ### Linear Solvers: Dense and GMRES Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Demonstrates the setup of different linear solvers, including a dense direct solver and GMRES solvers from IterativeSolvers.jl and KrylovKit.jl. These are used within Newton's method for solving nonlinear systems. ```julia using BifurcationKit, LinearAlgebra # Dense / direct (default) ls_direct = DefaultLS() # GMRES via IterativeSolvers.jl, with ILU preconditioner using IterativeSolvers, IncompleteLU Pl = ilu(sparse_jacobian_at_u0, τ = 0.005) ls_gmres = GMRESIterativeSolvers(reltol = 1e-5, N = 1000, restart = 30, Pl = Pl) # GMRES via KrylovKit.jl (works with arbitrary vector types, e.g. GPU arrays) ls_kk = GMRESKrylovKit(dim = 200, atol = 1e-10) ``` -------------------------------- ### Periodic Orbit Continuation with Standard Multiple Shooting Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Initiates periodic orbit continuation using standard multiple shooting. This method requires OrdinaryDiffEq.jl. Setup involves defining the ODE problem, initial conditions, parameters, and continuation options. ```julia using BifurcationKit, OrdinaryDiffEq, LinearAlgebra # ── Method 3: Standard multiple shooting (requires OrdinaryDiffEq.jl) ode_prob = ODEProblem((u, p, t) -> F_vector_field(u, p), u0, (0.0, 1.0), par) probPO_sh = Shooting(ode_prob, Tsit5(), [u_hopf]; abstol = 1e-9, reltol = 1e-7) br_po3 = continuation(br, 1, opts_po, probPO_sh; δp = 0.01, verbosity = 2) ``` -------------------------------- ### Compute Full Automatic Bifurcation Diagram Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Computes a complete bifurcation diagram by tracing root branches, detecting bifurcation points, and recursively computing bifurcated branches. The result is a tree of BifurNode's. Requires BifurcationKit and LinearAlgebra. Setup involves defining the problem, initial conditions, parameters, and continuation options. ```julia using BifurcationKit, LinearAlgebra function F_sh(u, p) (;l, ν, α) = p # … finite-difference discretisation of ∂_t u = -(1+∂²_x)² u + l*u + α*u² - ν*u³ # returns vector of residuals end n = 256 u0 = zeros(n) par = (l = -0.7, ν = 2.0, α = 0.0) prob = BifurcationProblem(F_sh, u0, par, @optic _.l; record_from_solution = (x, p; k...) -> norm(x)) opts = ContinuationPar(ds = 0.01, dsmax = 0.2, p_min = -1.0, p_max = 0.5, nev = 10, detect_bifurcation = 3, newton_options = NewtonPar(tol = 1e-9)) # Compute diagram up to recursion level 3 diagram = bifurcationdiagram(prob, PALC(), 3, opts; verbosity = 0) # Access the root branch root_branch = get_branch(diagram) # Access first bifurcated branch from the second special point on the root branch sub_branch = diagram[2, 1] # Ulam-Harris-Neveu tree navigation # Total number of branches computed @show size(diagram) # Extend the diagram further bifurcationdiagram!(prob, diagram, 5, opts) ``` -------------------------------- ### Compute Normal Form for Generic Branch Point Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Computes the normal form for a generic branch point (Pitchfork/Transcritical). Use the predictor from the normal form to get a starting guess on the bifurcated branch. ```julia nf_bp = get_normal_form(br, 2; verbose = true) δp = 0.02 x_new, p_new = predictor(nf_bp, δp) ``` -------------------------------- ### Continuation Algorithms Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Demonstrates the usage of various continuation algorithms like PALC, Natural, MoorePenrose, and Deflated Continuation (DefCont) with different configurations and options. ```APIDOC ## Continuation Algorithms (PALC, Natural, MoorePenrose, DefCont) BifurcationKit provides several interchangeable continuation algorithms. `PALC` (Pseudo-Arclength) is the workhorse; `Natural` advances the parameter directly; `MoorePenrose` uses the pseudo-inverse tangent; `DefCont` (Deflated Continuation) discovers disconnected branches. ```julia using BifurcationKit prob = BifurcationProblem(...) # any well-formed problem opts = ContinuationPar(ds = 0.01, p_max = 5.0, newton_options = NewtonPar()) # ── Pseudo-arclength (Secant tangent, default bordered linear solver) br1 = continuation(prob, PALC(), opts) # ── PALC with Bordered tangent and explicit linear solver br2 = continuation(prob, PALC(tangent = Bordered(), bls = MatrixBLS()), opts) # ── Natural parameter continuation br3 = continuation(prob, Natural(), opts) # ── Moore-Penrose with iterative correction br4 = continuation(prob, MoorePenrose(tangent = PALC()), opts) # ── Deflated Continuation to track multiple branches simultaneously deflationOp = DeflationOperator(2, 1.0, [zeros(n)]) br5 = continuation(prob, DefCont(deflation_operator = deflationOp, alg = PALC(), max_branches = 20), opts) # br5 is a DCResult; individual branches are accessed via br5[k] ``` ``` -------------------------------- ### BifurcationKit Continuation Algorithms Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Demonstrates various continuation algorithms including PALC, Natural, MoorePenrose, and Deflated Continuation. Shows how to configure tangent computation and linear solvers. ```julia using BifurcationKit prob = BifurcationProblem(...) # any well-formed problem opts = ContinuationPar(ds = 0.01, p_max = 5.0, newton_options = NewtonPar()) # ── Pseudo-arclength (Secant tangent, default bordered linear solver) br1 = continuation(prob, PALC(), opts) # ── PALC with Bordered tangent and explicit linear solver br2 = continuation(prob, PALC(tangent = Bordered(), bls = MatrixBLS()), opts) # ── Natural parameter continuation br3 = continuation(prob, Natural(), opts) # ── Moore-Penrose with iterative correction br4 = continuation(prob, MoorePenrose(tangent = PALC()), opts) # ── Deflated Continuation to track multiple branches simultaneously deflationOp = DeflationOperator(2, 1.0, [zeros(n)]) br5 = continuation(prob, DefCont(deflation_operator = deflationOp, alg = PALC(), max_branches = 20), opts) # br5 is a DCResult; individual branches are accessed via br5[k] ``` -------------------------------- ### 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" ])' ``` -------------------------------- ### Configuring NewtonPar with Custom Solvers Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Shows how to configure NewtonPar with custom linear and eigensolvers. This allows for optimized performance and compatibility with different hardware, such as GPU arrays. ```julia using BifurcationKit, LinearAlgebra # Wire them together opt = NewtonPar(linsolver = ls_kk, eigsolver = eig) opts_cont = ContinuationPar(newton_options = opt, nev = 6) ``` -------------------------------- ### ContinuationPar Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Configures the continuation algorithm, including step size control, parameter range, bifurcation detection level, and eigenvalue tracking. It can be adapted non-destructively. ```APIDOC ## ContinuationPar — continuation algorithm parameters `ContinuationPar` configures the continuation run: step sizes (`ds`, `dsmin`, `dsmax`), the parameter interval (`p_min`, `p_max`), bifurcation detection level (`detect_bifurcation ∈ {0,1,2,3}`), eigensolver calls, and more. ### Parameters - **dsmin**: Minimum step size. - **dsmax**: Maximum step size. - **ds**: Initial step size. - **p_min**: Minimum value of the continuation parameter. - **p_max**: Maximum value of the continuation parameter. - **max_steps**: Maximum number of steps in the continuation. - **nev**: Number of eigenvalues to track. - **detect_bifurcation**: Level of bifurcation detection (0: none, 1: simple, 2: bisection, 3: full bisection). - **tol_stability**: Tolerance for stability analysis. - **newton_options**: `NewtonPar` options for the corrector step. ### Example ```julia using BifurcationKit opts = ContinuationPar( dsmin = 1e-4, dsmax = 0.1, ds = 0.01, p_min = -1.0, p_max = 4.5, max_steps = 400, nev = 5, # number of eigenvalues to track detect_bifurcation = 3, # full bisection to pinpoint bifurcations tol_stability = 1e-10, newton_options = NewtonPar(tol = 1e-10, max_iterations = 20)) # Adapt a ContinuationPar field non-destructively (package re-exports Accessors.jl) opts2 = @set opts.ds = -0.05 # continue in the opposite direction ``` ``` -------------------------------- ### Perform Parameter Continuation in Julia Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt The main entry point for parameter continuation using `continuation(prob, alg, contparams; kwargs...)`. Selects the predictor-corrector algorithm via `alg` (e.g., `PALC()`, `Natural()`). Returns `ContResult` with traced branches and detected bifurcations. ```julia using BifurcationKit, LinearAlgebra, SparseArrays ``` -------------------------------- ### continuation Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt The main entry point for parameter continuation. It traces solution branches using a specified algorithm and returns a `ContResult` object containing the results. ```APIDOC ## continuation — trace a branch of solutions `continuation(prob, alg, contparams; kwargs...)` is the main entry point for parameter continuation. It returns a `ContResult` containing the traced branch, detected bifurcation points, eigenvalues, and solutions along the way. The choice of `alg` (e.g. `PALC()`, `Natural()`, `MoorePenrose()`, `DefCont()`) selects the predictor-corrector algorithm without any other changes. ### Parameters - **prob**: A `BifurcationProblem` object. - **alg**: The continuation algorithm (e.g., `PALC()`, `Natural()`, `MoorePenrose()`, `DefCont()`). - **contparams**: A `ContinuationPar` object. - **kwargs**: Additional keyword arguments. ### Example ```julia using BifurcationKit, LinearAlgebra, SparseArrays # Example usage would follow here, demonstrating how to call the continuation function # with a BifurcationProblem, an algorithm, and ContinuationPar options. ``` ``` -------------------------------- ### 1-D Bratu–Chan Problem Continuation Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Sets up and performs continuation for the 1-D Bratu–Chan problem using PALC algorithm. Demonstrates accessing solution vectors and parameters along the branch. ```julia function F_chan(x, p) (;α) = p; n = length(x) f = similar(x) f[1] = x[1]; f[n] = x[n] for i in 2:n-1 f[i] = (x[i-1] - 2x[i] + x[i+1]) * (n-1)^2 + α * exp(x[i]) end f end n = 201 par = (α = 1.0,) u0 = zeros(n) prob = BifurcationProblem(F_chan, u0, par, @optic _.α; record_from_solution = (x, p; k...) -> norm(x, Inf)) opts = ContinuationPar(ds = 0.05, dsmax = 0.3, p_max = 3.5, nev = 4, detect_bifurcation = 3, newton_options = NewtonPar(tol = 1e-9)) # PALC with Secant predictor (default) br = continuation(prob, PALC(), opts; verbosity = 1) # Display branch summary show(br) # Access special points (Fold, BP, Hopf …) br.specialpoint # Extract parameter values along the branch br.param # Vector{Float64} # Extract k-th solution vector on the branch x5 = get_solx(br, 5) p5 = get_solp(br, 5) # Continue in both directions simultaneously br_both = continuation(prob, PALC(), opts; bothside = true) ``` -------------------------------- ### Configure NewtonPar for Nonlinear Solvers in Julia Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Configures parameters for the Newton-Krylov nonlinear solver, including tolerances, maximum iterations, and linear/eigensolvers. Use `Accessors.@set` or `setproperties` for modifications. ```julia using BifurcationKit # Dense/direct linear solver (default, uses backslash ``) opt = NewtonPar(tol = 1e-10, max_iterations = 50, verbose = true) # GMRES (matrix-free) with KrylovKit backend opt_mf = NewtonPar(tol = 1e-10, linsolver = GMRESKrylovKit(dim = 150)) # Arpack eigensolver for large sparse problems opt_eig = NewtonPar(eigsolver = EigArpack(0.1, :LM)) ``` ```julia using BifurcationKit F(x, p) = [x[1]^2 - p.λ; x[2] - 1.0] prob = BifurcationProblem(F, [0.5, 1.0], (λ = 0.25,), @optic _.λ) sol = BK.solve(prob, Newton(), NewtonPar(tol = 1e-12, verbose = false)) @show sol.converged # true @show sol.u # ≈ [0.5, 1.0] @show sol.residuals # decreasing sequence of norms ``` -------------------------------- ### Configure ContinuationPar for Continuation Runs in Julia Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Configures continuation run parameters such as step sizes, parameter intervals, bifurcation detection level, and eigensolver calls. Fields can be adapted non-destructively using `@set`. ```julia using BifurcationKit opts = ContinuationPar( dsmin = 1e-4, dsmax = 0.1, ds = 0.01, p_min = -1.0, p_max = 4.5, max_steps = 400, nev = 5, # number of eigenvalues to track detect_bifurcation = 3, # full bisection to pinpoint bifurcations tol_stability = 1e-10, newton_options = NewtonPar(tol = 1e-10, max_iterations = 20)) # Adapt a ContinuationPar field non-destructively (package re-exports Accessors.jl) opts2 = @set opts.ds = -0.05 # continue in the opposite direction ``` -------------------------------- ### CI Label to Test Filter String Mapping Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/test/README.md Demonstrates how GitHub labels are translated into filter strings for the `runtests.jl` script in CI environments. ```yaml # Example of valid labels: # - Run test(s): wave # - Run test(s): wave/* # - Run test(s): periodic_orbits_* # - Run test(s): wave | newton # Example of invalid labels (these will run all tests): # - Run test(s): ../examples* # - Run test(s): baddirectory ``` -------------------------------- ### DeflationOperator Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Explains how to use `DeflationOperator` to penalize known roots, enabling Newton's method to find new, previously undiscovered solutions. ```APIDOC ## DeflationOperator — avoid known solutions in Newton `DeflationOperator` penalises a set of known roots so that Newton's method is repelled from them and can converge to new, previously unknown solutions. The deflated functional is `M(u) · F(u) = 0` where `M(u) = ∏ᵢ (‖u - rᵢ‖⁻²ᵖ + α)`. ```julia using BifurcationKit, LinearAlgebra F(x, p) = [x[1]^3 - p.λ * x[1]] # two non-trivial solutions for λ > 0 prob = BifurcationProblem(F, [0.5], (λ = 2.0,), @optic _.λ) npar = NewtonPar(tol = 1e-10, max_iterations = 50) # Find first solution sol1 = BK.solve(prob, Newton(), npar) @show sol1.u # ≈ [√2] # Build deflation operator that avoids sol1 defOp = DeflationOperator(2, 1.0, [sol1.u]) # Search for another solution deflecting away from sol1 sol2 = BK.solve(re_make(prob; u0 = [-0.5]), defOp, npar) @show sol2.u # ≈ [-√2] # Add sol2 and search for the third (trivial) solution push!(defOp, sol2.u) sol3 = BK.solve(re_make(prob; u0 = [0.05]), defOp, npar) @show sol3.u # ≈ [0.0] ``` ``` -------------------------------- ### Periodic Orbit Continuation with Orthogonal Collocation Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Initiates periodic orbit continuation using the Orthogonal Collocation method. This method is generally more accurate for smooth orbits. Requires BifurcationKit, OrdinaryDiffEq, and LinearAlgebra. ```julia using BifurcationKit, OrdinaryDiffEq, LinearAlgebra # ── Method 2: Orthogonal collocation (more accurate for smooth orbits) probPO_coll = Collocation(;Ntst = 20, m = 4, N = 2n) # 20 mesh intervals, degree-4 polynomial br_po2 = continuation(br, 1, opts_po, probPO_coll; δp = 0.01, verbosity = 1) ``` -------------------------------- ### Bordered Linear Solvers Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Lists available bordered linear solvers, which are required by algorithms like PALC for computing bifurcation diagrams. Options include dense solves and bordered matrix methods. ```julia # Bordered linear solvers (required by PALC): # MatrixBLS – dense bordered solve # BorderingBLS – Sherman-Morrison-Woodbury bordering formula ``` -------------------------------- ### NewtonPar Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Configures the Newton-Krylov nonlinear solver, including tolerances, maximum iterations, and choices for linear and eigensolvers. It is immutable and modified copies are created using Accessors.jl. ```APIDOC ## NewtonPar — Newton-Krylov solver parameters `NewtonPar` holds the options for the Newton-Krylov nonlinear solver: tolerances, maximum iterations, the linear solver (`linsolver`), and the eigensolver (`eigsolver`). It is immutable; use `Accessors.@set` or `setproperties` to produce modified copies. ### Parameters - **tol**: Tolerance for the nonlinear solver. - **max_iterations**: Maximum number of iterations for the nonlinear solver. - **linsolver**: The linear solver to use (e.g., direct solver, GMRESKrylovKit). - **eigsolver**: The eigensolver to use (e.g., EigArpack). - **verbose**: Whether to print detailed information during solving. ### Example ```julia using BifurcationKit # Dense/direct linear solver (default, uses backslash ``) opt = NewtonPar(tol = 1e-10, max_iterations = 50, verbose = true) # GMRES (matrix-free) with KrylovKit backend opt_mf = NewtonPar(tol = 1e-10, linsolver = GMRESKrylovKit(dim = 150)) # Arpack eigensolver for large sparse problems opt_eig = NewtonPar(eigsolver = EigArpack(0.1, :LM)) # Solve a single nonlinear problem using BifurcationKit F(x, p) = [x[1]^2 - p.λ; x[2] - 1.0] prob = BifurcationProblem(F, [0.5, 1.0], (λ = 0.25,), @optic _.λ) sol = BK.solve(prob, Newton(), NewtonPar(tol = 1e-12, verbose = false)) @show sol.converged # true @show sol.u # ≈ [0.5, 1.0] @show sol.residuals # decreasing sequence of norms ``` ``` -------------------------------- ### Implement custom finalise_solution function Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Create a custom `finalise_solution` function to print information at each step and optionally stop continuation based on a condition, such as the norm of the solution. ```julia using BifurcationKit # ── finalise_solution: print info and stop if norm too large function my_finalise(z, tau, step, contRes; state, iter, k...) in_bisection(state) && return true # skip during bisection println("Step $step ‖x‖ = $(norm(z.u))") return norm(z.u) < 100.0 # return false to stop end br = continuation(prob, PALC(), opts; finalise_solution = my_finalise) ``` -------------------------------- ### Newton Solver for Branch Switching and Refinement Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Refines detected bifurcation points (Fold, Hopf) using `newton(br, ind; options)` or finds distinct solutions at a branch point using `newton(prob, x0, x1, p0, options, defOp)`. Also shows continuation of fold curves. ```julia using BifurcationKit # Assume `br` already computed from `continuation(...)` and contains a Fold point # Refine the second special point (index 2) to high precision opt_ref = NewtonPar(tol = 1e-12, verbose = true, max_iterations = 30) outfold = newton(br, 2; options = opt_ref) @show BK.converged(outfold) # true @show outfold.u.p # refined fold parameter value # Then continue the fold curve in a second parameter β fold_branch = continuation(br, 2, @optic _.β, ContinuationPar(ds = 0.02, dsmax = 0.1, p_min = 0.0, p_max = 2.0, newton_options = NewtonPar(tol = 1e-10)); jacobian_ma = BK.MinAug()) # minimally augmented formulation ``` -------------------------------- ### Dry Run: List Tests to be Executed Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/test/README.md Simulate test execution to see which tests would run without actually executing them. Useful for verifying filter strings. ```julia julia -e 'Pkg.activate("."); Pkg.test(test_args = [ "periodic_orbits_*", "-n" ])' ``` -------------------------------- ### DeflationOperator for Avoiding Known Solutions Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Uses DeflationOperator to penalize known roots, enabling Newton's method to find new solutions. Demonstrates finding multiple solutions by iteratively updating the deflation operator. ```julia using BifurcationKit, LinearAlgebra F(x, p) = [x[1]^3 - p.λ * x[1]] # two non-trivial solutions for λ > 0 prob = BifurcationProblem(F, [0.5], (λ = 2.0,), @optic _.λ) npar = NewtonPar(tol = 1e-10, max_iterations = 50) # Find first solution sol1 = BK.solve(prob, Newton(), npar) @show sol1.u # ≈ [√2] # Build deflation operator that avoids sol1 defOp = DeflationOperator(2, 1.0, [sol1.u]) # Search for another solution deflecting away from sol1 sol2 = BK.solve(re_make(prob; u0 = [-0.5]), defOp, npar) @show sol2.u # ≈ [-√2] # Add sol2 and search for the third (trivial) solution push!(defOp, sol2.u) sol3 = BK.solve(re_make(prob; u0 = [0.05]), defOp, npar) @show sol3.u # ≈ [0.0] ``` -------------------------------- ### Run Multiple Specific Tests Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/test/README.md Execute tests matching a globbing pattern, useful for running a subset of related tests. ```julia julia -e 'Pkg.activate("."); Pkg.test(test_args = [ "periodic_orbits_*" ])' ``` -------------------------------- ### Branch Switching from Period-Doubling Bifurcation on PO Branch Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Performs automatic branch switching from a Period-Doubling bifurcation point detected on a periodic orbit branch. This is a specialized continuation task. ```julia # Branch switching from a Period-Doubling bifurcation point on a PO branch br_pd = continuation(br_po, 2, opts_po) # automatic branch switching at PO BP ``` -------------------------------- ### BifurcationProblem Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Defines the central struct for a bifurcation problem, packaging the vector field, initial guess, parameters, and the continuation parameter lens. Derivatives are computed automatically. ```APIDOC ## BifurcationProblem — define the vector field `BifurcationProblem(F, u0, params, lens; kwargs...)` is the central struct that packages the vector field `F`, the initial guess `u0`, the full parameter struct `params`, and a `lens` (an `Accessors.jl` optic) that selects which scalar parameter is used as the continuation parameter. All derivatives needed internally (Jacobian, second and third differentials, adjoint) are computed automatically via ForwardDiff when not supplied. ### Parameters - **F**: The vector field function. - **u0**: The initial guess for the solution. - **params**: The full parameter struct. - **lens**: An `Accessors.jl` optic to select the continuation parameter. - **kwargs**: Optional arguments like `record_from_solution` and `plot_solution`. ### Example ```julia using BifurcationKit, LinearAlgebra const BK = BifurcationKit # Logistic fold: F(x, λ) = x*(1-x) - λ (scalar) F(x, p) = [x[1] * (1 - x[1]) - p.λ] u0 = [0.1] par = (λ = 0.1,) lens = (@optic _.λ) # continue w.r.t. λ prob = BifurcationProblem(F, u0, par, lens; record_from_solution = (x, p; k...) -> x[1], # what to store on the branch plot_solution = (x, p; k...) -> nothing) # Modify an existing problem non-destructively prob2 = re_make(prob; u0 = [0.5], params = (λ = 0.2,)) # Query the problem @show getparams(prob) # (λ = 0.1,) @show getlens(prob) # (@optic _.λ) @show getparam(prob) # 0.1 ``` ``` -------------------------------- ### newton function Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Details on using the `newton` function for refining bifurcation points and finding distinct solutions at branch points using deflation. ```APIDOC ## newton — solve with branch switching and codimension-2 refinement Beyond the plain `BK.solve` call, `newton(br, ind; options, ...)` refines a detected bifurcation point (Fold or Hopf) stored in a branch `br` at index `ind`. The second signature `newton(prob, x0, x1, p0, options, defOp)` uses deflation to find the two distinct solutions at a branch point. ```julia using BifurcationKit # Assume `br` already computed from `continuation(...)` and contains a Fold point # Refine the second special point (index 2) to high precision opt_ref = NewtonPar(tol = 1e-12, verbose = true, max_iterations = 30) outfold = newton(br, 2; options = opt_ref) @show BK.converged(outfold) # true @show outfold.u.p # refined fold parameter value # Then continue the fold curve in a second parameter β fold_branch = continuation(br, 2, @optic _.β, ContinuationPar(ds = 0.02, dsmax = 0.1, p_min = 0.0, p_max = 2.0, newton_options = NewtonPar(tol = 1e-10)); jacobian_ma = BK.MinAug()) # minimally augmented formulation ``` ``` -------------------------------- ### Use callback to bound Newton residuals Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Employ a callback function to limit Newton residuals, preventing divergence during solving. This is useful for ill-conditioned problems. ```julia using BifurcationKit # ── Callback to bound Newton residuals (avoids divergence) cb = BK.cbMaxNorm(1e3) sol = BK.solve(prob, Newton(), NewtonPar(max_iterations = 50); callback = cb) ``` -------------------------------- ### Accessing branch data from ContResult Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Retrieve various data points from the `ContResult` object returned by `continuation`, including parameter values, stability information, special points, and solution vectors. ```julia using BifurcationKit br = continuation(prob, PALC(), opts) # Parameter values along the branch br.param # Vector{Float64} # Stability information (n_unstable = number of eigenvalues with Re > 0) br.n_unstable # Vector{Int} # All recorded quantities from record_from_solution br.x # or br.branch.x if record_from_solution returned a NamedTuple # List of detected bifurcation / fold / endpoint special points br.specialpoint # Vector{SpecialPoint} bif_pt = br.specialpoint[1] @show bif_pt.type # :bp, :hopf, :fold, :pd, :ns, :bt, … @show bif_pt.param # parameter value at the bifurcation @show bif_pt.step # continuation step index @show bif_pt.x # solution at the bifurcation # Eigenvalues at a particular continuation step eigenvals(br, 5) # Full solution vector at step k (only if save_sol_every_step > 0) get_solx(br, 3) # Branch switching: automatic from equilibrium bifurcation point br2 = continuation(br, 1) # equilibrium → equilibrium ``` -------------------------------- ### Accessing Periodic Orbit Data Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Retrieves the periodic orbit at a specific continuation step and estimates its period. These functions are used after performing periodic orbit continuation. ```julia # Get the periodic orbit at the 10th continuation step orbit = get_periodic_orbit(br_po, 10) T = getperiod(br_po, 10) # period estimate ``` -------------------------------- ### Define BifurcationProblem in Julia Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Defines the central struct for bifurcation analysis, packaging the vector field, initial guess, parameters, and continuation parameter lens. Derivatives are computed automatically. Use `re_make` to modify existing problems. ```julia using BifurcationKit, LinearAlgebra const BK = BifurcationKit # Logistic fold: F(x, λ) = x*(1-x) - λ (scalar) F(x, p) = [x[1] * (1 - x[1]) - p.λ] u0 = [0.1] par = (λ = 0.1,) lens = (@optic _.λ) # continue w.r.t. λ prob = BifurcationProblem(F, u0, par, lens; record_from_solution = (x, p; k...) -> x[1], # what to store on the branch plot_solution = (x, p; k...) -> nothing) # Modify an existing problem non-destructively prob2 = re_make(prob; u0 = [0.5], params = (λ = 0.2,)) # Query the problem @show getparams(prob) # (λ = 0.1,) @show getlens(prob) # (@optic _.λ) @show getparam(prob) # 0.1 ``` -------------------------------- ### Run Tests in a Specific Directory Source: https://github.com/bifurcationkit/bifurcationkit.jl/blob/master/test/README.md Execute tests located within a specific subdirectory (test category) using a filter string. ```julia julia -e 'Pkg.activate("."); Pkg.test(test_args = [ "wave" ])' ``` ```julia julia -e 'Pkg.activate("."); Pkg.test(test_args = [ "wave/*" ])' ``` -------------------------------- ### Define and use continuous event for continuation Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Define a continuous event to stop continuation when a scalar quantity crosses a threshold. Ensure `detect_bifurcation` is set to 0 when using events. ```julia using BifurcationKit # ── Stop continuation when a scalar quantity exceeds a threshold ev = ContinuousEvent(1, (iter, state; k...) -> [getx(state)[1] - 0.9], # sign change triggers location (iter, state; k...) -> "user_event") opts = ContinuationPar(detect_event = 2, p_max = 10.0, detect_bifurcation = 0, # events and bifurcation detection are mutually exclusive newton_options = NewtonPar(tol = 1e-10)) br = continuation(prob, PALC(), opts; event = ev) ``` -------------------------------- ### get_normal_form for Bifurcation Point Analysis Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Computes the normal form coefficients and critical eigenvectors at a given bifurcation point (Fold, Hopf, etc.) stored in a branch. Used for automatic branch-switching. ```julia using BifurcationKit # br has a Hopf point at specialpoint[1] nf = get_normal_form(br, 1; verbose = true) ``` -------------------------------- ### get_normal_form function Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Explains how to compute normal forms at bifurcation points using `get_normal_form`, which dispatches based on the bifurcation point type. ```APIDOC ## get_normal_form — normal forms at bifurcation points `get_normal_form(br, ind; verbose = false)` computes the normal form at the `ind`-th entry of `br.specialpoint`. The function dispatches on the type of the bifurcation point (Fold, Hopf, Transcritical, Pitchfork, Bogdanov-Takens, etc.) and returns a struct containing the normal-form coefficients and the critical eigenvectors, which are also used by the automatic branch-switching machinery. ```julia using BifurcationKit # br has a Hopf point at specialpoint[1] nf = get_normal_form(br, 1; verbose = true) ``` ``` -------------------------------- ### Compute Normal Form for Hopf Bifurcation Source: https://context7.com/bifurcationkit/bifurcationkit.jl/llms.txt Computes the normal form for a Hopf bifurcation. The returned struct provides information about the critical eigenvalue and Lyapunov coefficients. ```julia nf = get_normal_form(br, 1) @show nf.ω @show real(nf.nf.b3) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.