Skip to content

Simulation engine for index-1 DAEs and other mathematical utilities for Modia and Modia3D

License

Notifications You must be signed in to change notification settings

crlaugh/ModiaMath.jl

 
 

Repository files navigation

ModiaMath

Travis Coverage Status codecov.io

ModiaMath provides a simulation engine and other mathematical utilities for packages Modia and Modia3D that are used to model physical systems such as electrical circuits, robots, or vehicles. The recommended way is to use ModiaMath via Modia or Modia3D. However, ModiaMath is self-contained and can be also used without Modia/Modia3D.

The central part of ModiaMath is a simulation engine to solve implicit index one Differential Algebraic Equations (DAEs) with and without time and state events. The theory is partially described in (Otter/Elmqvist, 2017). In particular it is shown, that a large class of DAEs can be transformed automatically to this form (including multibody systems with kinematic loops). As integrator currently IDA of the Sundials integrator suite is used (via the Julia Sundials interface package). It is planned to adapt ModiaMath to Julia package DifferentialEquations and use IDA and other appropriate integrators via this package in the future.

Additionally, ModiaMath provides functions to perform plotting in a convenient way, to generate and use rotation matrices and quaternions for kinematic transformations in 3D, and to provide an infrastructure for DAE variables as needed by Modia3D.

Installation

The package is registered in METADATA.jl and can be installed with Pkg.add.

julia> Pkg.add("ModiaMath")

ModiaMath uses PyPlot for plotting. Installing PyPlot by just using the Julia package manager might fail. In such a case, you might try these installation instructions.

Documentation

  • LATESTin-development version of the documentation.

Use

To define a model

(note, it is simpler and less error prone to define a model with Modia or Modia3D):

  using ModiaMath
  using StaticArrays

  @component Pendulum(;L=1.0, m=1.0, d=0.1, g=9.81) begin
     phi = RealScalar(start=pi/2, unit="rad"    , fixed=true,               numericType=ModiaMath.XD_EXP)
     w   = RealScalar(start=0.0 , unit="rad/s"  , fixed=true, integral=phi, numericType=ModiaMath.XD_EXP)
     a   = RealScalar(            unit="rad/s^2",             integral=w  , numericType=ModiaMath.DER_XD_EXP)
     r   = RealSVector{2}(        unit="m"      ,                           numericType=ModiaMath.WC)
  end;

  function ModiaMath.computeVariables!(p::Pendulum, sim::ModiaMath.SimulationState)
     L = p.L; m = p.m; d = p.d; g = p.g; phi = p.phi.value; w = p.w.value

     p.a.value = (-m*g*L*sin(phi) - d*w) / (m*L^2)

     if ModiaMath.isStoreResult(sim)
        p.r.value = @SVector [L*sin(phi), -L*cos(phi)]
     end
  end;

  simulationModel = ModiaMath.SimulationModel(Pendulum(L=0.8, m=0.5, d=0.2), stopTime=5.0);

To simulate a model and plot results:

  result = ModiaMath.simulate!(simulationModel; log=true);
  ModiaMath.plot(result, [(:phi, :w) :a])

PendulumPlot

To run examples:

  include("$(ModiaMath.path)/examples/Simulate_Pendulum.jl")         # ODE as index-0 DAE
  include("$(ModiaMath.path)/examples/Simulate_FreeBodyRotation.jl") # index-1 DAE
  include("$(ModiaMath.path)/examples/withoutMacros_withoutVariables/Simulate_PendulumDAE.jl") # index-3 DAE
  include("$(ModiaMath.path)/examples/withoutMacros_withoutVariables/Simulate_SimpleStateEvents.jl")
  include("$(ModiaMath.path)/examples/withoutMacros_withoutVariables/Simulate_BouncingBall.jl")

To run tests:

  include("$(ModiaMath.path)/test/runtests.jl")

Status

The package has been tested with Julia 0.6.3 on Windows 7, Kubuntu 18.04, Ubuntu 14.04, OpenSUSE42 and Fedora 28 and with Julia 0.7.0 on Windows 7. ModiaMath cannot yet be upgraded to Julia 1.0.0, because PyPlot is not yet adapted to Julia 1.0.0 (otherwise, it should also work with Julia 1.0.0).

The ModiaMath version number is 0.2.1 and functionality and robustness is planned to be improved for the 1.0 version, see Plans for ModiaMath version 1.0.

Issues and Contributions

Contributions are welcome, as are feature requests and suggestions. Please open an issue in this case and also if you encounter problems.

Main Developer

Martin Otter, DLR - Institute of System Dynamics and Control

License: MIT (expat)

About

Simulation engine for index-1 DAEs and other mathematical utilities for Modia and Modia3D

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Julia 87.5%
  • Modelica 12.5%