EulerLagrange.jl

Code generation for Euler-Lagrange equations.
Author JuliaGNI
Popularity
4 Stars
Updated Last
2 Months Ago
Started In
December 2020

EulerLagrange

Stable Latest Build Status Coverage

This package generates code for the Euler-Lagrange equations as well as Hamilton's equations for GeometricIntegrators.jl and related packages.

Installation

EulerLagrange.jl and all of its dependencies can be installed via the Julia REPL by typing

]add EulerLagrange

Basic usage

Using EulerLagrange.jl is very simple and typically consists of four to five steps:

  1. Obtain symbolic variables for a Lagrangian or Hamiltonian system of a given dimension.
  2. Obtain a symbolic representation of the parameters of the system if it has any.
  3. Build the Lagrangian or Hamiltonian using those symbolic variables and parameters.
  4. Construct a LagrangianSystem or HamiltonianSystem, which is where the actual code generation happens.
  5. Generate a LODEProblem or HODEProblem that can then be solved with GeometricIntegrators.jl.

In the following, we showcase this procedure for a particle in a square potential.

Before any use, we need to load EulerLagrange:

using EulerLagrange

Next, we generate symbolic variables for a one-dimensional system:

t, x, v = lagrangian_variables(1)

With those variables, we can construct a Lagrangian

L = v  v / 2 - x  x / 2

This Lagrangian together with the symbolic variables is then used to construct a LagrangianSystem:

lag_sys = LagrangianSystem(L, t, x, v)

The constructor computes the Euler-Lagrange equations and generates the corresponding Julia code. In the last step, we can now construct a LODEProblem from the LagrangianSystem and some appropriate initial conditions, a time span to integrate over and a time step:

tspan = (0.0, 10.0)
tstep = 0.01

q₀ = [1.0]
p₀ = [0.5]

lprob = LODEProblem(lag_sys, tspan, tstep, q₀, p₀)

Should we fancy so, we can integrate this system using GeometricIntegrators:

using GeometricIntegrators
integrate(lprob, ExplicitMidpoint())

References

If you use EulerLagrange.jl in your work, please consider citing it by

@misc{Kraus:2023:EulerLagrange,
  title={EulerLagrange.jl: Code generation for Euler-Lagrange equations in Julia},
  author={Kraus, Michael},
  year={2023},
  howpublished={\url{https://github.com/JuliaGNI/EulerLagrange.jl}},
  doi={10.5281/zenodo.8241048}
}

Development

We are using git hooks, e.g., to enforce that all tests pass before pushing. In order to activate these hooks, the following command must be executed once:

git config core.hooksPath .githooks