Modia.jl version 0.5 (major redesign)
Modia is an environment in the form of a Julia package to model and simulate physical systems (electrical, mechanical, thermo-dynamical, etc.) described by differential and algebraic equations. A user defines a model on a high level with model components (such as a mechanical body, an electrical resistance, or a pipe) that are physically connected together. A model component is constructed by equations (expression = expression
) or by Julia structs/functions, such as the pre-defined Modia 3D-mechanical components. The defined model is symbolically processed (for example, equations are sorted and solved and might be analytically differentiated). A Julia function is generated from the transformed model which is used to simulate the model with integrators from DifferentialEquations.jl. The basic type of the floating point variables is usually Float64
, but can for example be set to Float32, DoubleFloat, Measurement{Float64}, StaticParticles{Float64,100}
.
Modia includes the multibody package Modia3D including 3D shapes for visualization and collision handling. It is, for example, possible to model the 3D mechanical part of a robot with Modia multibody components and the electrical motors and gearboxes that are driving the joints with equation-based Modia components. Collision handling with elastic response calculation is performed for shapes that are defined with a contact material and have a convex geometry or are approximated by the convex hull of a concave geometry.
Modia version 0.5 is a complete redesign and extension compared to earlier versions regarding scalability and how models are defined and manipulated and includes the coupling between 3d-mechanical models and equation-based models.
A brief overview of Modia is given in the JuliaCon 2021 lightning talk: Modia – Modeling Multidomain Engineering Systems with Julia, 2021-07-30, 20:10–20:20 UTC (Modia Lightning talk)
The Modia Tutorial provides an introduction to Modia. The Modia3D Tutorial provides an introduction to the use of 3D components in Modia.
Examples
Modia3D
Animation of 3D mechanics is supported (see video link below):
A recursively defined Modia model is used as a benchmark (see video link below). It has about 900 solids, 380 joints and 380 equation-based damper models (a corresponding Modelica model has about 135000 scalar equations/unknowns):
Example videos:
Equation-based Model
The following equations describe a damped pendulum:
where phi is the rotation angle, omega the angular velocity, m the mass, L the rod length, d a damping constant, g the gravity constant and r the vector from the origin of the world system to the tip of the pendulum. These equations can be defined with:
using Modia
@usingModiaPlot
Pendulum = Model(
L = 0.8u"m",
m = 1.0u"kg",
d = 0.5u"N*m*s/rad",
g = 9.81u"m/s^2",
phi = Var(init = 1.57*u"rad"),
w = Var(init = 0u"rad/s"),
equations = :[
w = der(phi)
0.0 = m*L^2*der(w) + d*w + m*g*L*sin(phi)
r = [L*cos(phi), -L*sin(phi)]
]
)
Simulation and plotting of the pendulum with normally distributed uncertainty added to some parameters is performed in the following way:
using Measurements
PendulumWithUncertainties = Pendulum | Map(L = (0.8 ± 0.2)u"m",
m = (1.0 ± 0.2)u"kg",
d = (0.5 ± 0.2)u"N*m*s/rad")
pendulum2 = @instantiateModel(PendulumWithUncertainties, FloatType = Measurement{Float64})
simulate!(pendulum2, Tsit5(), stopTime = 10.0u"s")
plot(pendulum2, [("phi", "w"); "r"], figure = 2)
resulting in the following plot where mean values are shown with thick lines and standard deviations as area around the mean values.
Hilding Elmqvist, Martin Otter, Andrea Neumayr, Gerhard Hippman