Extension to the SciML ecosystem
The SciML ecosystem provides a rich set of tools to solve (non)-linear equations, differential equations and inverse problems. We provide an interface (in the form of Package extensions) to export the the derived harmonic equations computed with harmonic balance method or krylov-bogoliubov method to the SciML ecosystem.
ModeligToolkit.jl
The ModelingToolkit.jl (MTK) package provides a symbolic framework for defining and simplifying mathematical models. Through, MTK SciML provides a symbolic interface for their ecosystem
SciMLBase.ODEProblem Method
ODEProblem(
eom::Union{DifferentialEquation, HarmonicEquation},
u0,
tspan::Tuple,
p;
in_place,
kwargs...
) -> AnyCreates and ModelingToolkitBase.ODEProblem from a DifferentialEquation or HarmonicEquation.
The parameters p can be any map of symbolic variables to values: a Dict, or a Vector or Tuple of pairs. Whether the generated function is in-place is set with the in_place keyword or, equivalently, with the ODEProblem{iip} type parameter.
Example
using ModelingToolkitBase, StaticArrays
@variables α ω ω0 F γ t x(t)
diff_eq = DifferentialEquation(
d(x, t, 2) + ω0^2 * x + α * x^3 + γ * d(x, t) ~ F * cos(ω * t), x
)
add_harmonic!(diff_eq, x, ω) #
harmonic_eq = get_harmonic_equations(diff_eq)
param = (α => 1.0, ω0 => 1.1, F => 0.01, γ => 0.01, ω => 1.1)
# in place (most performant for large systems)
ODEProblem(harmonic_eq, [1.0, 0.0], (0, 100), param)
# out of place (most performant for small systems with StaticArrays)
ODEProblem(
harmonic_eq, [1.0, 0.0], (0, 100), param;
in_place=false, u0_constructor=x -> SVector(x...)
)
# the in-placeness can also be set with a type parameter
ODEProblem{false}(harmonic_eq, [1.0, 0.0], (0, 100), param)ModelingToolkitBase.System Type
System(eom::HarmonicEquation) -> SystemCreates and ModelingToolkitBase.System from a HarmonicEquation.
Example
using ModelingToolkitBase
@variables α ω ω0 F γ t x(t)
diff_eq = DifferentialEquation(
d(x, t, 2) + ω0^2 * x + α * x^3 + γ * d(x, t) ~ F * cos(ω * t), x
)
add_harmonic!(diff_eq, x, ω) #
harmonic_eq = get_harmonic_equations(diff_eq)
sys = System(harmonic_eq)
param = (α => 1.0, ω0 => 1.1, F => 0.01, γ => 0.01, ω => 1.1)
ODEProblem(sys, [1.0, 0.0], (0, 100), param)System(diff_eq::DifferentialEquation) -> SystemCreates and ModelingToolkitBase.System from a DifferentialEquation.
Example
using ModelingToolkitBase
@variables α ω ω0 F γ t x(t)
diff_eq = DifferentialEquation(
d(x, t, 2) + ω0^2 * x + α * x^3 + γ * d(x, t) ~ F * cos(ω * t), x
)
sys = System(diff_eq)
param = (α => 1.0, ω0 => 1.1, F => 0.01, γ => 0.01, ω => 1.1)
ODEProblem(sys, [1.0, 0.0], (0, 100), param)SciMLBase.SteadyStateProblem Type
SteadyStateProblem(
eom::HarmonicEquation,
u0,
p;
in_place,
kwargs...
) -> AnyCreates and ModelingToolkitBase.SteadyStateProblem from a HarmonicEquation.
The parameters p can be any map of symbolic variables to values: a Dict, or a Vector or Tuple of pairs. Whether the generated function is in-place is set with the in_place keyword or, equivalently, with the SteadyStateProblem{iip} type parameter.
Example
using ModelingToolkitBase, StaticArrays
@variables α ω ω0 F γ t x(t)
diff_eq = DifferentialEquation(
d(x, t, 2) + ω0^2 * x + α * x^3 + γ * d(x, t) ~ F * cos(ω * t), x
)
add_harmonic!(diff_eq, x, ω) #
harmonic_eq = get_harmonic_equations(diff_eq)
param = (α => 1.0, ω0 => 1.1, F => 0.01, γ => 0.01, ω => 1.1)
SteadyStateProblem(harmonic_eq, [1.0, 0.0], param)SciMLBase.NonlinearProblem Type
NonlinearProblem(
eom::HarmonicEquation,
u0,
p;
in_place,
kwargs...
) -> AnyCreates and ModelingToolkitBase.NonlinearProblem from a HarmonicEquation.
The parameters p can be any map of symbolic variables to values: a Dict, or a Vector or Tuple of pairs. Whether the generated function is in-place is set with the in_place keyword or, equivalently, with the NonlinearProblem{iip} type parameter.
Example
using ModelingToolkitBase, StaticArrays
@variables α ω ω0 F γ t x(t)
diff_eq = DifferentialEquation(
d(x, t, 2) + ω0^2 * x + α * x^3 + γ * d(x, t) ~ F * cos(ω * t), x
)
add_harmonic!(diff_eq, x, ω) #
harmonic_eq = get_harmonic_equations(diff_eq)
param = (α => 1.0, ω0 => 1.1, F => 0.01, γ => 0.01, ω => 1.1)
NonlinearProblem(harmonic_eq, [1.0, 0.0], param)