Git Product home page Git Product logo

modiamath.jl's Introduction

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

  • LATEST โ€” in-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)

modiamath.jl's People

Contributors

martinotter avatar crlaugh avatar ufechner7 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.