From 97c99198cee459eb19217413b0fe775f902b4e0b Mon Sep 17 00:00:00 2001 From: Michael Kraus Date: Thu, 5 Dec 2024 12:15:39 +0100 Subject: [PATCH] Add LDAEProblem for degenerate Lagrangians. --- src/EulerLagrange.jl | 4 +++- src/lagrangian_degenerate.jl | 24 ++++++++++++++++++++++++ test/lagrangian_lotka_volterra.jl | 4 +++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/EulerLagrange.jl b/src/EulerLagrange.jl index 4291953..91ea543 100644 --- a/src/EulerLagrange.jl +++ b/src/EulerLagrange.jl @@ -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 diff --git a/src/lagrangian_degenerate.jl b/src/lagrangian_degenerate.jl index 6f3491e..2f495ce 100644 --- a/src/lagrangian_degenerate.jl +++ b/src/lagrangian_degenerate.jl @@ -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 diff --git a/test/lagrangian_lotka_volterra.jl b/test/lagrangian_lotka_volterra.jl index cded987..b2fa610 100644 --- a/test/lagrangian_lotka_volterra.jl +++ b/test/lagrangian_lotka_volterra.jl @@ -1,5 +1,4 @@ using EulerLagrange -using GeometricEquations using LinearAlgebra using Test @@ -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)