Skip to content

Commit

Permalink
Add LDAEProblem for degenerate Lagrangians.
Browse files Browse the repository at this point in the history
  • Loading branch information
michakraus committed Dec 5, 2024
1 parent d6329d1 commit 97c9919
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/EulerLagrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ module EulerLagrange

import GeometricBase: equations, functions, parameters
import GeometricEquations: HODE, HODEProblem
import GeometricEquations: LODE, LODEProblem
import GeometricEquations: LODE, LODEProblem, LDAE, LDAEProblem
import GeometricEquations: ODE, ODEProblem
import GeometricEquations: _lode_default_v̄

RuntimeGeneratedFunctions.init(@__MODULE__)


export ODE, ODEProblem
export HODE, HODEProblem
export LODE, LODEProblem
export LDAE, LDAEProblem

export equations, functions, parameters, variables

Expand Down
24 changes: 24 additions & 0 deletions src/lagrangian_degenerate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,27 @@ function LODEProblem(lsys::DegenerateLagrangianSystem, tspan::Tuple, tstep::Real
_λ₀ = AlgebraicVariable(λ₀)
LODEProblem(lsys, tspan, tstep, _q₀, _p₀, _λ₀; kwargs...)
end


function LDAE(lsys::DegenerateLagrangianSystem; v̄ = functions(lsys).v, f̄ = functions(lsys).f, kwargs...)
eqs = functions(lsys)
LDAE(eqs.ϑ, eqs.f, eqs.u, eqs.g, eqs.ϕ, eqs.ū, eqs.ḡ, eqs.ψ, eqs.ω, eqs.L; v̄ = v̄, f̄ = f̄, invariants = (h = eqs.H,), kwargs...)
end

function LDAEProblem(lsys::DegenerateLagrangianSystem, tspan::Tuple, tstep::Real, ics::NamedTuple; v̄ = functions(lsys).v, f̄ = functions(lsys).f, kwargs...)
eqs = functions(lsys)
LDAEProblem(eqs.ϑ, eqs.f, eqs.u, eqs.g, eqs.ϕ, eqs.ū, eqs.ḡ, eqs.ψ, eqs.ω, eqs.L, tspan, tstep, ics; v̄ = v̄, f̄ = f̄, invariants = (h = eqs.H,), kwargs...)
end

function LDAEProblem(lsys::DegenerateLagrangianSystem, tspan::Tuple, tstep::Real, q₀::StateVariable, p₀::StateVariable, λ₀::AlgebraicVariable, μ₀::AlgebraicVariable; kwargs...)
ics = (q = q₀, p = p₀, λ = λ₀, μ = μ₀)
LDAEProblem(lsys, tspan, tstep, ics; kwargs...)
end

function LDAEProblem(lsys::DegenerateLagrangianSystem, tspan::Tuple, tstep::Real, q₀::AbstractArray, p₀::AbstractArray, λ₀::AbstractArray = zero(q₀), μ₀::AbstractArray = zero(λ₀); kwargs...)
_q₀ = StateVariable(q₀)
_p₀ = StateVariable(p₀)
_λ₀ = AlgebraicVariable(λ₀)
_μ₀ = AlgebraicVariable(μ₀)
LDAEProblem(lsys, tspan, tstep, _q₀, _p₀, _λ₀, _μ₀; kwargs...)
end
4 changes: 3 additions & 1 deletion test/lagrangian_lotka_volterra.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EulerLagrange
using GeometricEquations
using LinearAlgebra
using Test

Expand Down Expand Up @@ -119,3 +118,6 @@ f̃(ṗ₂, t₀, q₀, v₀, params)

@test_nowarn LODE(deg_lag_sys)
@test_nowarn LODEProblem(deg_lag_sys, tspan, tstep, q₀, v₀; parameters = params)

@test_nowarn LDAE(deg_lag_sys)
@test_nowarn LDAEProblem(deg_lag_sys, tspan, tstep, q₀, v₀; parameters = params)

0 comments on commit 97c9919

Please sign in to comment.