|
1 | | -# ModiaLang.jl |
| 1 | +# Modia.jl |
2 | 2 |
|
3 | | -[](https://github.com/ModiaSim/ModiaLang.jl/blob/master/LICENSE.md) |
| 3 | +[](https://modiasim.github.io/Modia.jl/stable) |
| 4 | +[](https://github.com/ModiaSim/Modia.jl/blob/master/LICENSE) |
4 | 5 |
|
5 | | -ModiaLang is part of [ModiaSim](https://modiasim.github.io/docs/). |
| 6 | +The [Modia Tutorial](https://modiasim.github.io/Modia.jl/stable/tutorial/GettingStarted.html) provides an introduction to Modia. |
| 7 | +The [Modia3D Tutorial](https://modiasim.github.io/Modia3D.jl/stable/tutorial/GettingStarted.html) provides an introduction to use 3D components in Modia. |
| 8 | +Modia is part of [ModiaSim](https://modiasim.github.io/docs/). |
6 | 9 |
|
7 | | -ModiaLang is usually used via [Modia](https://github.com/ModiaSim/Modia.jl). |
8 | | - |
9 | | -ModiaLang provides the core equation-based language of Modia, transformation of a model to ODE form dx/dt = f(x,t) and a thin interface to [DifferentialEquations](https://github.com/SciML/DifferentialEquations.jl). |
| 10 | +[Modia](https://github.com/ModiaSim/Modia.jl) is an environment in 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 (like a mechanical body, an electrical resistance, or a pipe) that are physically connected together. A model component is constructed by **`expression = expression` equations** or by Julia structs/functions, such as the pre-defined Modia 3D-mechanical components. The defined model is symbolically processed (for example, equations might be analytically differentiated) with algorithms from package [ModiaBase.jl](https://github.com/ModiaSim/ModiaBase.jl). From the transformed model a Julia function is generated that is used to simulate the model with integrators from [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl). |
| 11 | +The basic type of the floating point variables is usually `Float64`, but can be set to any |
| 12 | +type `FloatType<:AbstractFloat` via `@instantiateModel(..., FloatType = xxx)`, for example |
| 13 | +it can be set to `Float32, DoubleFloat, Measurement{Float64}, StaticParticles{Float64,100}`. |
10 | 14 |
|
11 | 15 | ## Installation |
12 | | - |
13 | | -Typically, a user installs [Modia](https://github.com/ModiaSim/Modia.jl) and does not need |
14 | | -to install ModiaLang separately. |
15 | 16 |
|
16 | | -If needed, ModiaLang is installed with (Julia >= 1.5 is required): |
| 17 | +The package is registered and is installed with (Julia >= 1.7 is required): |
| 18 | + |
| 19 | +```julia |
| 20 | +julia> ]add Modia |
| 21 | +``` |
| 22 | + |
| 23 | +Furthermore, one or more of the following packages should be installed in order |
| 24 | +to be able to generate plots: |
| 25 | + |
| 26 | +```julia |
| 27 | +julia> ]add ModiaPlot_PyPlot # if plotting with PyPlot desired |
| 28 | + add ModiaPlot_GLMakie # if plotting with GLMakie desired |
| 29 | + add ModiaPlot_WGLMakie # if plotting with WGLMakie desired |
| 30 | + add ModiaPlot_CairoMakie # if plotting with CairoMakie desired |
| 31 | +``` |
| 32 | + |
| 33 | +Note, Modia exports all exported symbols of |
| 34 | + |
| 35 | +- [DifferentialEquations](https://github.com/SciML/DifferentialEquations.jl) and of |
| 36 | +- [Unitful](https://github.com/PainterQubits/Unitful.jl) |
| 37 | + |
| 38 | + |
| 39 | +## Examples |
| 40 | + |
| 41 | +The following equations describe a damped pendulum: |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +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, simulated and plotted with |
| 47 | +(note, you can define models also without units, or remove units before the model is processed): |
17 | 48 |
|
18 | 49 | ```julia |
19 | | -julia> ]add ModiaLang |
| 50 | +using Modia |
| 51 | +@usingModiaPlot # Use plot package defined with |
| 52 | + # ENV["MODIA_PLOT"] or Modia.usePlotPackage(..) |
| 53 | + |
| 54 | +Pendulum = Model( |
| 55 | + L = 0.8u"m", |
| 56 | + m = 1.0u"kg", |
| 57 | + d = 0.5u"N*m*s/rad", |
| 58 | + g = 9.81u"m/s^2", |
| 59 | + phi = Var(init = 1.57*u"rad"), |
| 60 | + w = Var(init = 0u"rad/s"), |
| 61 | + equations = :[ |
| 62 | + w = der(phi) |
| 63 | + 0.0 = m*L^2*der(w) + d*w + m*g*L*sin(phi) |
| 64 | + r = [L*cos(phi), -L*sin(phi)] |
| 65 | + ] |
| 66 | +) |
| 67 | + |
| 68 | +pendulum1 = @instantiateModel(Pendulum) |
| 69 | +simulate!(pendulum1, Tsit5(), stopTime = 10.0u"s", log=true) |
| 70 | +plot(pendulum1, [("phi", "w"); "r"], figure = 1) |
20 | 71 | ``` |
21 | 72 |
|
| 73 | +The result is the following plot: |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +Simulation and plotting of the pendulum with normally distributed uncertainty added to some parameters is performed in the following way: |
| 78 | + |
| 79 | +```julia |
| 80 | +using Measurements |
| 81 | + |
| 82 | +PendulumWithUncertainties = Pendulum | Map(L = (0.8 ± 0.2)u"m", |
| 83 | + m = (1.0 ± 0.2)u"kg", |
| 84 | + d = (0.5 ± 0.2)u"N*m*s/rad") |
| 85 | + |
| 86 | +pendulum2 = @instantiateModel(PendulumWithUncertainties, |
| 87 | + FloatType = Measurement{Float64}) |
| 88 | + |
| 89 | +simulate!(pendulum2, Tsit5(), stopTime = 10.0u"s") |
| 90 | +plot(pendulum2, [("phi", "w"); "r"], figure = 2) |
| 91 | +``` |
| 92 | + |
| 93 | +resulting in the following plot where mean values are shown with thick lines |
| 94 | +and standard deviations as area around the mean values. |
| 95 | + |
| 96 | + |
| 97 | + |
22 | 98 | ## Main Developers |
23 | 99 |
|
24 | 100 | - [Hilding Elmqvist ](mailto:[email protected]), [Mogram ](http://www.mogram.net/). |
25 | | - |
26 | 101 | - [Martin Otter](https://rmc.dlr.de/sr/en/staff/martin.otter/), |
27 | 102 | [DLR - Institute of System Dynamics and Control](https://www.dlr.de/sr/en). |
28 | 103 |
|
29 | | -License: MIT (expat) |
|
0 commit comments