Skip to content

Extracting Solutions

After computing the steady-states of the harmonic equations, you'll want to extract the solutions from the HarmonicBalance.Result struct.

Basic Solution Extraction

For plotting, you can extract the solutions using the get_solutions function, which parses a string into a symbolic expression, evaluates it for every steady state solution and filters the solutions by the requested class.

HarmonicBalance.get_solutions Function
julia
get_solutions(
    res::Result, x::String;
    branches=1:branch_count(res), realify=false, class=["stable"], not_class=[]
    )
get_solutions(res::Result; branches=1:branch_count(res), class=["stable"], not_class=[])

Extract solution vectors from a Result object based on specified filtering criteria given by the class keywords. The first method allows extracting a specific solution component by name x. The second method returns complete solution vectors.

Keyword arguments

  • branches=1:branch_count(res): Range of branches to include in the output

  • realify=false: Whether to convert complex solutions to real form

  • class=["physical", "stable"]: Array of classification labels to include

  • not_class=[]: Array of classification labels to exclude

Returns

Filtered solution vectors matching the specified criteria

source
HarmonicBalance.get_single_solution Function
julia
get_single_solution(
    res::HarmonicBalance.Result{D, S, P, F} where F<:FunctionWrappers.FunctionWrapper{Array{S, 2}, Tuple{Array{S, 1}}};
    branch,
    index
)

Return an ordered dictionary specifying all variables and parameters of the solution in result on branch at the position index.

source

Attractors

HarmonicBalance.attractors Function
julia
attractors(res::Result{D}; class="stable", not_class=[]) where D

Extract attractors from a Result object. Returns an array of dictionaries, where each dictionary maps branch identifier to the attractor. The attractors are filtered by their corresponding class.

Keyword arguments

Class selection done by passing String or Vector{String} as kwarg:

class::String       :   only count solutions in this class ("all" --> plot everything)
not_class::String   :   do not count solutions in this class

Returns

Array{Dict,D}: Vector of dictionaries mapping branch indices to points satisfying the stability criteria at each parameter value

source
HarmonicBalance.phase_diagram Function
julia
phase_diagram(res::Result{D}; class="physical", not_class=[]) where {D}

Calculate the phase diagram from a Result object by summing over the number of states at each swept parameters.

Keyword arguments

Class selection done by passing String or Vector{String} as kwarg:

class::String       :   only count solutions in this class ("all" --> plot everything)
not_class::String   :   do not count solutions in this class

Returns

  • Array{Int64,D}: Sum of states after applying the specified class masks
source

classifying solutions

HarmonicBalance.classify_solutions! Function
julia
classify_solutions!(
    res::HarmonicBalance.Result,
    func::Union{Function, String},
    name::String;
    physical
) -> Any

Creates a solution class in res using the function func (parsed into Symbolics.jl input). The new class is labeled with name and stored under res.classes[name]. By default, only physical (real) solutions are classified, and false is returned for the rest. To also classify complex solutions, set physical=false.

Example

julia
# solve a previously-defined problem
res = get_steady_states(problem, swept_parameters, fixed_parameters)

# classify, store in result.classes["large_amplitude"]
classify_solutions!(res, "sqrt(u1^2 + v1^2) > 1.0" , "large_amplitude")
source
HarmonicBalance.get_class Function
julia
get_class(
    res::HarmonicBalance.Result,
    branch::Int64,
    class::String
) -> Any

Returns an array of booleans classifying branch in the solutions in res according to class.

source
julia
get_class(
    soln::HarmonicBalance.Result,
    class::String
) -> Vector

Returns an array of booleans classifying each branch in the solutions in res according to class.

source
HarmonicBalance.filter_result! Function
julia
filter_result!(res::HarmonicBalance.Result, class::String)

Removes all solution branches from res where NONE of the solution falls into class. Typically used to filter out unphysical solutions to prevent huge file sizes.

source