diff --git a/Manifest.toml b/Manifest.toml index f906617..2540827 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -165,9 +165,9 @@ uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" [[DiffEqBase]] deps = ["ArrayInterface", "ChainRulesCore", "DataStructures", "DocStringExtensions", "FastBroadcast", "FunctionWrappers", "IterativeSolvers", "LabelledArrays", "LinearAlgebra", "Logging", "MuladdMacro", "NonlinearSolve", "Parameters", "Printf", "RecursiveArrayTools", "RecursiveFactorization", "Reexport", "Requires", "SciMLBase", "Setfield", "SparseArrays", "StaticArrays", "Statistics", "SuiteSparse", "ZygoteRules"] -git-tree-sha1 = "932153f62d0508e59733e0fc33361470d293a889" +git-tree-sha1 = "9d312bb0b7c8ace440a71c64330cf1bea0ade0c8" uuid = "2b5f629d-d688-5b77-993f-72d75c75574e" -version = "6.68.1" +version = "6.70.0" [[DiffEqCallbacks]] deps = ["DataStructures", "DiffEqBase", "ForwardDiff", "LinearAlgebra", "NLsolve", "OrdinaryDiffEq", "RecipesBase", "RecursiveArrayTools", "StaticArrays"] @@ -257,9 +257,9 @@ uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" [[DynamicPolynomials]] deps = ["DataStructures", "Future", "LinearAlgebra", "MultivariatePolynomials", "MutableArithmetics", "Pkg", "Reexport", "Test"] -git-tree-sha1 = "5e47c4d652ea67652b7c5945c79c46472397d47f" +git-tree-sha1 = "e9d82a6f35d199d3821c069932115e19ca2a2b3d" uuid = "7c1d4256-1411-5781-91ec-d7bc3513ac07" -version = "0.3.18" +version = "0.3.19" [[EllipsisNotation]] deps = ["ArrayInterface"] @@ -385,9 +385,9 @@ version = "0.21.1" [[JuliaFormatter]] deps = ["CSTParser", "CommonMark", "DataStructures", "Pkg", "Tokenize"] -git-tree-sha1 = "671676423c7c70673d4d2f03f2be2d6741c6884e" +git-tree-sha1 = "03d48b801c3d497c301a137ad32be7a70f1a64cb" uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899" -version = "0.15.1" +version = "0.15.2" [[LaTeXStrings]] git-tree-sha1 = "c7f1c695e06c01b95a67f0cd1d34994f3e7db104" @@ -396,9 +396,9 @@ version = "1.2.1" [[LabelledArrays]] deps = ["ArrayInterface", "LinearAlgebra", "MacroTools", "StaticArrays"] -git-tree-sha1 = "5e38cfdd771c34821ade5515f782fe00865d60b3" +git-tree-sha1 = "41fc666d11a346e55f7fb70318e7078bfc0ae7cb" uuid = "2ee39098-c373-598a-b85f-a56591580800" -version = "1.6.2" +version = "1.6.3" [[Latexify]] deps = ["Formatting", "InteractiveUtils", "LaTeXStrings", "MacroTools", "Markdown", "Printf", "Requires"] @@ -452,9 +452,9 @@ uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" [[LoopVectorization]] deps = ["ArrayInterface", "DocStringExtensions", "IfElse", "LinearAlgebra", "OffsetArrays", "Polyester", "Requires", "SLEEFPirates", "Static", "StrideArraysCore", "ThreadingUtilities", "UnPack", "VectorizationBase"] -git-tree-sha1 = "06c91d5495c32bca6b843551a1331c3cd2fb23d0" +git-tree-sha1 = "b844cb320457812f739fe75f216a481095daf5c2" uuid = "bdcacae8-1622-11e9-2a5c-532679323890" -version = "0.12.53" +version = "0.12.55" [[MacroTools]] deps = ["Markdown", "Random"] @@ -497,12 +497,10 @@ uuid = "961ee093-0014-501f-94e3-6117800e7a78" version = "5.25.1" [[ModiaBase]] -deps = ["DataFrames", "DiffRules", "LinearAlgebra", "Measurements", "MonteCarloMeasurements", "OrderedCollections", "Unitful"] -git-tree-sha1 = "e22838a9cb989b67c5a2c0e42212977dda15964c" -repo-rev = "development" -repo-url = "https://github.com/ModiaSim/ModiaBase.jl.git" +deps = ["DataFrames", "DiffRules", "LinearAlgebra", "Measurements", "MonteCarloMeasurements", "OrderedCollections", "TimerOutputs", "Unitful"] +git-tree-sha1 = "36df1afcd6f4967406476ca5292dbc097f2bc1b9" uuid = "ec7bf1ca-419d-4510-bbab-199861c55244" -version = "0.7.2-dev" +version = "0.7.3" [[ModiaResult]] deps = ["DataFrames", "DataStructures", "Measurements", "MonteCarloMeasurements", "Pkg", "Tables", "Unitful"] @@ -637,9 +635,9 @@ version = "0.4.0" [[Polyester]] deps = ["ArrayInterface", "IfElse", "ManualMemory", "Requires", "Static", "StrideArraysCore", "ThreadingUtilities", "VectorizationBase"] -git-tree-sha1 = "f5a74523ebc205723baefb95874f708741199d70" +git-tree-sha1 = "4b692c8ce1912bae5cd3b90ba22d1b54eb581195" uuid = "f517fe37-dbe3-4b94-8317-1923a5111588" -version = "0.3.4" +version = "0.3.7" [[PooledArrays]] deps = ["DataAPI", "Future"] @@ -702,9 +700,9 @@ version = "1.1.1" [[RecursiveArrayTools]] deps = ["ArrayInterface", "ChainRulesCore", "DocStringExtensions", "LinearAlgebra", "RecipesBase", "Requires", "StaticArrays", "Statistics", "ZygoteRules"] -git-tree-sha1 = "2a76e8f24c67f3ebecaccefa8d4abd27db828407" +git-tree-sha1 = "0426474f50756b3b47b08075604a41b460c45d17" uuid = "731186ca-8d62-57ce-b412-fbd966d074cd" -version = "2.14.9" +version = "2.16.1" [[RecursiveFactorization]] deps = ["LinearAlgebra", "LoopVectorization"] @@ -752,9 +750,9 @@ uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" [[SLEEFPirates]] deps = ["IfElse", "Static", "VectorizationBase"] -git-tree-sha1 = "da6d214ffc85b1292f300649ef86d3c4f9aaf25d" +git-tree-sha1 = "a8415a7a0e050cc927bf045665b8ed3376a6e368" uuid = "476501e8-09a2-5ece-8869-fb82de89a1fa" -version = "0.6.22" +version = "0.6.24" [[SafeTestsets]] deps = ["Test"] @@ -764,9 +762,9 @@ version = "0.0.1" [[SciMLBase]] deps = ["ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "RecipesBase", "RecursiveArrayTools", "StaticArrays", "Statistics", "Tables", "TreeViews"] -git-tree-sha1 = "afa011b411259faa53ccf95b8f18f1e704535c3d" +git-tree-sha1 = "f0bf114650476709dd04e690ab2e36d88368955e" uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462" -version = "1.18.1" +version = "1.18.2" [[Serialization]] uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" @@ -808,9 +806,9 @@ version = "1.15.0" [[SpecialFunctions]] deps = ["ChainRulesCore", "LogExpFunctions", "OpenSpecFun_jll"] -git-tree-sha1 = "a50550fa3164a8c46747e62063b4d774ac1bcf49" +git-tree-sha1 = "508822dca004bf62e210609148511ad03ce8f1d8" uuid = "276daf66-3868-5448-9aa4-cd146d93841b" -version = "1.5.1" +version = "1.6.0" [[Static]] deps = ["IfElse"] @@ -820,9 +818,9 @@ version = "0.2.5" [[StaticArrays]] deps = ["LinearAlgebra", "Random", "Statistics"] -git-tree-sha1 = "1b9a0f17ee0adde9e538227de093467348992397" +git-tree-sha1 = "5b2f81eeb66bcfe379947c500aae773c85c31033" uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "1.2.7" +version = "1.2.8" [[Statistics]] deps = ["LinearAlgebra", "SparseArrays"] @@ -859,9 +857,9 @@ version = "6.35.0" [[StrideArraysCore]] deps = ["ArrayInterface", "ManualMemory", "Requires", "ThreadingUtilities", "VectorizationBase"] -git-tree-sha1 = "2525850b6887e217c3cc149ab29eb2a7a6360d37" +git-tree-sha1 = "e1c37dd3022ba6aaf536541dd607e8d5fb534377" uuid = "7792a7ef-975c-4747-a70f-980b88e8d1da" -version = "0.1.16" +version = "0.1.17" [[StructTypes]] deps = ["Dates", "UUIDs"] @@ -927,9 +925,9 @@ uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [[ThreadingUtilities]] deps = ["ManualMemory"] -git-tree-sha1 = "593009385e6536dc50baedc2c8bc1a3717ef358f" +git-tree-sha1 = "03013c6ae7f1824131b2ae2fc1d49793b51e8394" uuid = "8290d209-cae3-49c0-8002-c8c24d57dab5" -version = "0.4.5" +version = "0.4.6" [[TimerOutputs]] deps = ["ExprTools", "Printf"] @@ -973,9 +971,9 @@ version = "1.9.0" [[VectorizationBase]] deps = ["ArrayInterface", "Hwloc", "IfElse", "Libdl", "LinearAlgebra", "Static"] -git-tree-sha1 = "ddeac5d8aad03c17bdc8efd45246e82fc52d12f4" +git-tree-sha1 = "a4bc1b406dcab1bc482ce647e6d3d53640defee3" uuid = "3d5dd08c-fd9d-11e8-17fa-ed2836048c2f" -version = "0.20.24" +version = "0.20.25" [[VertexSafeGraphs]] deps = ["LightGraphs"] diff --git a/Project.toml b/Project.toml index d839292..4470150 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ -name = "TinyModia" -uuid = "0169e107-af13-440d-89df-ca21e82123ce" +name = "ModiaLang" +uuid = "34b37210-eaa3-4b48-8781-0b87bf559981" authors = ["Hilding Elmqvist ", "Martin Otter "] -version = "0.8.0-dev" +version = "0.8.0" [deps] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" @@ -22,6 +22,7 @@ TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [compat] +DataFrames = "0.22, 0.21, 0.20, 0.19" DifferentialEquations = "6.17, 6.16" FiniteDiff = "2.8, 2.7, 2.6, 2.5" ForwardDiff = "0.10" diff --git a/README.md b/README.md index 08665cb..5b1dee6 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,22 @@ -# TinyModia +# ModiaLang.jl -[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://modiasim.github.io/TinyModia.jl/stable/index.html) -[![The MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/ModiaSim/TinyModia.jl/blob/master/LICENSE.md) +[![The MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/ModiaSim/ModiaLang.jl/blob/master/LICENSE.md) -TinyModia is part of [ModiaSim](https://modiasim.github.io/docs/). +ModiaLang is part of [ModiaSim](https://modiasim.github.io/docs/). -TinyModia is a minimalistic 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. 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). -The basic type of the floating point variables in the generated function is usually `Float64`, -but can be set to any type `T<:AbstractFloat`, for example -`Float32, DoubleFloat, Measurement{Float64}, StaticParticles{Float64,100}`. +ModiaLang is usually used via [Modia](https://github.com/ModiaSim/Modia.jl). + +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). ## Installation -The package is registered and is installed with (Julia >= 1.5 is required): - -```julia -julia> ]add TinyModia -``` +Typically, a user installs [Modia](https://github.com/ModiaSim/Modia.jl) and does not need +to install ModiaLang separately. -It is recommended to also add the following packages, in order that all tests and examples can be executed in your standard environment: +If needed, ModiaLang is installed with (Julia >= 1.5 is required): ```julia -julia> ]add ModiaPlot, Unitful, DifferentialEquations, Measurements, MonteCarloMeasurements, Distributions +julia> ]add ModiaLang ``` ## Main Developers diff --git a/docs/make.jl b/docs/make.jl deleted file mode 100644 index ec6a15d..0000000 --- a/docs/make.jl +++ /dev/null @@ -1,21 +0,0 @@ -using Documenter, TinyModia, ModiaResult, ModiaPlot_PyPlot - -makedocs( - #modules = [TinyModia], - sitename = "TinyModia", - authors = "Hilding Elmqvist (Mogram) and Martin Otter (DLR-SR)", - format = Documenter.HTML(prettyurls = false), - pages = [ - "Home" => "index.md", - "Tutorial" => [ - "tutorial/Tutorial.md" - "tutorial/GettingStarted.md" - "tutorial/Modeling.md" - "tutorial/Simulation.md" - "tutorial/FloatingPointTypes.md" - "tutorial/Appendix.md" - ], - "Functions" => "Functions.md", - "Internal" => "Internal.md" - ] -) diff --git a/docs/resources/images/BandPassFilterPlot.png b/docs/resources/images/BandPassFilterPlot.png deleted file mode 100644 index be98b99..0000000 Binary files a/docs/resources/images/BandPassFilterPlot.png and /dev/null differ diff --git a/docs/resources/images/Filter.png b/docs/resources/images/Filter.png deleted file mode 100644 index 6b1d7fc..0000000 Binary files a/docs/resources/images/Filter.png and /dev/null differ diff --git a/docs/resources/images/PendulumEquations.png b/docs/resources/images/PendulumEquations.png deleted file mode 100644 index 22011e5..0000000 Binary files a/docs/resources/images/PendulumEquations.png and /dev/null differ diff --git a/docs/resources/images/PendulumFigures.png b/docs/resources/images/PendulumFigures.png deleted file mode 100644 index 4624164..0000000 Binary files a/docs/resources/images/PendulumFigures.png and /dev/null differ diff --git a/docs/resources/images/PendulumWithMonteCarlo.png b/docs/resources/images/PendulumWithMonteCarlo.png deleted file mode 100644 index 2fcfde2..0000000 Binary files a/docs/resources/images/PendulumWithMonteCarlo.png and /dev/null differ diff --git a/docs/resources/images/PendulumWithUncertainties.png b/docs/resources/images/PendulumWithUncertainties.png deleted file mode 100644 index 495a9c3..0000000 Binary files a/docs/resources/images/PendulumWithUncertainties.png and /dev/null differ diff --git a/docs/resources/images/PendulumWithUncertaintities.png b/docs/resources/images/PendulumWithUncertaintities.png deleted file mode 100644 index 8482fb2..0000000 Binary files a/docs/resources/images/PendulumWithUncertaintities.png and /dev/null differ diff --git a/docs/resources/images/ServoSystem.png b/docs/resources/images/ServoSystem.png deleted file mode 100644 index d343641..0000000 Binary files a/docs/resources/images/ServoSystem.png and /dev/null differ diff --git a/docs/resources/images/SimpleModel_GLMakie.png b/docs/resources/images/SimpleModel_GLMakie.png deleted file mode 100644 index 3fadee6..0000000 Binary files a/docs/resources/images/SimpleModel_GLMakie.png and /dev/null differ diff --git a/docs/resources/images/TwoInertiasAndIdealGear.png b/docs/resources/images/TwoInertiasAndIdealGear.png deleted file mode 100644 index ccdcea6..0000000 Binary files a/docs/resources/images/TwoInertiasAndIdealGear.png and /dev/null differ diff --git a/docs/resources/images/matrix-of-plots.png b/docs/resources/images/matrix-of-plots.png deleted file mode 100644 index 7a59e44..0000000 Binary files a/docs/resources/images/matrix-of-plots.png and /dev/null differ diff --git a/docs/resources/models/DocuModels.mo b/docs/resources/models/DocuModels.mo deleted file mode 100644 index 7cf0ee0..0000000 --- a/docs/resources/models/DocuModels.mo +++ /dev/null @@ -1,27 +0,0 @@ -within ; -package DocuModels - model Filter - Modelica.Electrical.Analog.Basic.Resistor R(R=0.5) - annotation (Placement(transformation(extent={{-50,40},{-30,60}}))); - Modelica.Electrical.Analog.Basic.Capacitor C(C=2.0) annotation (Placement( - transformation( - extent={{-10,-10},{10,10}}, - rotation=-90, - origin={-10,30}))); - Modelica.Electrical.Analog.Sources.ConstantVoltage V(V=10) annotation ( - Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=-90, - origin={-70,30}))); - equation - connect(V.p, R.p) - annotation (Line(points={{-70,40},{-70,50},{-50,50}}, color={0,0,255})); - connect(R.n, C.p) - annotation (Line(points={{-30,50},{-10,50},{-10,40}}, color={0,0,255})); - connect(C.n, V.n) annotation (Line(points={{-10,20},{-10,8},{-70,8},{-70,20}}, - color={0,0,255})); - annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram( - coordinateSystem(preserveAspectRatio=false))); - end Filter; - annotation (uses(Modelica(version="3.2.3"))); -end DocuModels; diff --git a/docs/src/Functions.md b/docs/src/Functions.md deleted file mode 100644 index c70eedd..0000000 --- a/docs/src/Functions.md +++ /dev/null @@ -1,105 +0,0 @@ -# Functions - -```@meta -CurrentModule = TinyModia -``` - - -## Instantiation - -```@docs -@instantiateModel -instantiateModel -``` - -## Simulation - -```@docs -simulate! -``` - - -## Linearization - -```@docs -linearize! -``` - - -## Results and Plotting - -The simulation result of a model `instantiatedModel` supports the abstract interface -[ModiaResult](https://modiasim.github.io/ModiaResult.jl/stable/index.html) and -exports them, so the functions can be accessed without prefixing them with `TinyModia`. -The following functions are provided (for details see -[Functions of ModiaResult](https://modiasim.github.io/ModiaResult.jl/stable/Functions.html#Functions-of-ModiaResult)): - -```@meta -CurrentModule = TinyModia -``` - -| Functions | Description | -|:---------------------------------|:--------------------------------------------------| -| `@usingModiaPlot` | Expands into `using ModiaPlot_` | -| `usePlotPackage` | Define the plot package to be used. | -| `usePreviousPlotPackage` | Define the previously defined plot package to be used. | -| `currentPlotPackage` | Return name defined with `usePlotPackage` | -| `resultInfo` | Return info about the result as [DataFrame](https://github.com/JuliaData/DataFrames.jl) table | -| `printResultInfo` | Print info of the result on stdout. | -| `rawSignal` | Return raw signal data given the signal name. | -| `getPlotSignal` | Return signal data prepared for a plot package. | -| `defaultHeading` | Return default heading of a result. | -| `signalNames` | Return all signal names. | -| `timeSignalName` | Return the name of the time signal. | -| `hasOneTimeSignal` | Return true if one time signal present. | -| `hasSignal` | Return true if a signal name is known. | - - -The following functions are available after `ENV["MODIA_PLOT"] = XXX` or -`@usingModiaPlot(XXX)` have been executed -(for details see -[Functions of Plot Package](https://modiasim.github.io/ModiaResult.jl/stable/Functions.html#Functions-of-Plot-Package)): - - -| Functions | Description | -|:-------------------|:----------------------------------------------------------| -| `plot` | Plot simulation results in multiple diagrams/figures. | -| `saveFigure` | Save figure in different formats on file. | -| `closeFigure` | Close one figure | -| `closeAllFigures` | Close all figures | -| `showFigure` | Show figure in window (only GLMakie, WGLMakie) | - - -A TinyModia variable `a.b.c` is identified by a String key `"a.b.c"`. -The legends/labels of the plots are automatically constructed by the -names and units of the variables. Example: - -```julia -using TinyModia -@usingModiaPlot - -instantiatedModel = @instantiatedModel(...) -simulate!(instantiatedModel, ...) -plot(instantiatedModel, - [ ("phi", "r") ("phi", "phi2", "w"); - ("w", "w2", "phi2") "w" ], - heading="Matrix of plots") -``` - -generates the following plot: - -![Matrix-of-Plots](../resources/images/matrix-of-plots.png) - - -## PathPlanning - -There are some pre-defined functions to define reference paths - -```@docs -PTP_path -pathEndTime -getPosition! -getPosition -getIndex -getPath -``` \ No newline at end of file diff --git a/docs/src/Internal.md b/docs/src/Internal.md deleted file mode 100644 index 2541dcb..0000000 --- a/docs/src/Internal.md +++ /dev/null @@ -1,37 +0,0 @@ -# Internal - -This chapter documents internal functions that are typically only -for use of the developers of package TinyModia. - -## Code Generation - -This section provides functions to **generate Julia code** of the -transformed equations. - -```@meta -CurrentModule = TinyModia -``` - -```@docs -SimulationModel -generate_getDerivatives! -init! -outputs! -addToResult! -getFloatType -baseType -measurementToString -``` - -## Inquiries in Model - -```@docs -isInitial -isTerminal -isEvent -isFirstEventIteration -isFirstEventIterationDirectlyAfterInitial -isAfterSimulationStart -isZeroCrossing -storeResults -``` diff --git a/docs/src/index.md b/docs/src/index.md deleted file mode 100644 index 88f3041..0000000 --- a/docs/src/index.md +++ /dev/null @@ -1,118 +0,0 @@ -# TinyModia Documentation - -[TinyModia](https://github.com/ModiaSim/TinyModia.jl) is a minimalistic 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. 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). -The basic type of the floating point variables is usually `Float64`, but can be set to any -type `FloatType<:AbstractFloat` via `@instantiateModel(..., FloatType = xxx)`, for example -it can be set to `Float32, DoubleFloat, Measurement{Float64}, StaticParticles{Float64,100}`. - -## Installation - -The package is registered and is installed with (Julia >= 1.5 is required): - -```julia -julia> ]add TinyModia -``` - -Furthermore, one or more of the following packages should be installed in order -to be able to generate plots: - -```julia -julia> ]add ModiaPlot_PyPlot # if plotting with PyPlot desired - add ModiaPlot_GLMakie # if plotting with GLMakie desired - add ModiaPlot_WGLMakie # if plotting with WGLMakie desired - add ModiaPlot_CairoMakie # if plotting with CairoMakie desired -``` - -It is recommended to also add the following packages, in order that all tests and examples can be executed in your standard environment: - -```julia -julia> ]add Unitful, DifferentialEquations, Measurements - add MonteCarloMeasurements, Distributions -``` - -## Release Notes - - -### Version 0.8.0 - -- Improved scalability by using OrderedDicts instead of named tuples for models, variables and parameter modifications. -- Speed improvements for structural and symbolic algorithms. -- Added support for state events, time events and synchronous operators. -- Added support for mixed linear equation systems having Real and Boolean unknowns. -- Added support for user-defined components defined by structs and functions - (multibody modeling with Modia3D is based on this feature). - This makes it possible to utilize algorithms specialized for a component. -- Added support for numerical and analytic linearization. -- Added support for propagation of parameters (e.g. deep in a model, the value of a parameter can be defined as a function of some top level parameter and this parameter is changed before simulation starts). -- New small model libraries Translational.jl and PathPlanning.jl added. -- Result storage changed: `sol = simulate!(...)` calls internally `sol = solve(..)` from DifferentialEquations.jl. `sol` contains time and the states at the communication time grid and - at events. This is now kept in simulate(..), so the return value of simulate!(..) can be exactly used as if `solve(..)` would have been used directly. -- The plot(..) command now supports the following underlying plot packages: - [PyPlot](https://github.com/JuliaPy/PyPlot.jl), - [GLMakie](https://github.com/JuliaPlots/GLMakie.jl), - [WGLMakie](https://github.com/JuliaPlots/WGLMakie.jl), and - [CairoMakie](https://github.com/JuliaPlots/CairoMakie.jl). - It is also possible to select `NoPlot`, to ignore `plot(..)` calls - or `SilenNoPlot` to ignore `plot(..)` calls silently. The latter is useful for `runtests.jl`. - Note, often [PyPlot](https://github.com/JuliaPy/PyPlot.jl) is the best choice. - -Changes that are **not backwards compatible** to version 0.7.x: - -- Models are OrderedDicts and no longer NamedTuples. - -- simulate!(..): - - If FloatType=Float64 and no algorithm is defined, then Sundials.CVODE\_BDF() is used - instead of the default algorithm of DifferentialEquations as in 0.7. The reason is that Modia models - are usually large and expensive to evaluate and have often stiff parts, so that multi-step - methods are often by far the best choice. CVODE_BDF() seems to be a good choice in many applications - (another algorithm should be used, if there are many events, highly oscillatory vibrations, or if all states are non-stiff). - - The default value of `stopTime` is equal to `startTime` (which has a default value of 0.0 s), and is no longer 1.0 s. - -- Plotting is defined slightly differently (`@useModiaPlot`, instead of `using ModiaPlot`). - - -### Version 0.7.3 - -- Evaluation and propagation of parameter expressions (also in simulate!(..., merge=Map(...))). - Propagation of start/init values of states is not yet supported. - -- State events supported. - - -### Version 0.7.2 - -- Missing dependency of Test package added. - -### Version 0.7.1 - -- Variable constructor `Var(...)` introduced. For example: - `v = input | Var(init = 1.2u"m")`. - For details see section [A.1 Var constructor](@ref). - -- Functions are called in the scope where macro [`@instantiateModel`](@ref) is called. - -- New arguments of function [`simulate!`](@ref): - - Parameter and init/start values can be changed with argument `merge`. - - A simulation can be checked with argument `requiredFinalStates`. - - Argument `logParameters` lists the parameter and init/start values used for the simulation. - - Argument `logStates` lists the states, init, and nominal values used for the simulation. - -- `end` in array ranges is supported, for example `v[2:end]`. - -- New (small) model library `TinyModia/models/HeatTransfer.jl`. - -- TinyModia Tutorial improved. - -- [Functions](@ref) docu improved. - -### Version 0.7.0 - -- Initial version, based on code developed for Modia 0.6 and ModiaMath 0.6. - - -## Main developers - -- [Hilding Elmqvist](mailto:Hilding.Elmqvist@Mogram.net), [Mogram](http://www.mogram.net/). - -- [Martin Otter](https://rmc.dlr.de/sr/en/staff/martin.otter/), - [DLR - Institute of System Dynamics and Control](https://www.dlr.de/sr/en). \ No newline at end of file diff --git a/docs/src/tutorial/Appendix.md b/docs/src/tutorial/Appendix.md deleted file mode 100644 index 5f630fc..0000000 --- a/docs/src/tutorial/Appendix.md +++ /dev/null @@ -1,120 +0,0 @@ -# Appendix A - -## A.1 Var constructor - -The constructor `Var(..)` defines attributes of a variable with key/value pairs. -In column 1 the keys are shown. The default is that none of the keys are defined -(meaning `key = nothing`). Most of the keys are also provided as predefined constants as shown -in column 2 and 3. These constants can be used as shortcuts: - -| Var key | ShortCut | Shortcut value | Description | -|:---------- |:----------|:----------------------|:---------------------------------------------------| -| parameter | parameter | Var(parameter = true) | If true, value is fixed during simulation | -| input | input | Var(input = true) | If true, input signal | -| output | output | Var(output = true) | If true, output signal | -| potential | potential | Var(potential = true) | If true, potential variable | -| flow | flow | Var(flow = true) | If true, flow variable | -| init | -- | -- | Initial value of ODE state (defines unit and size) | -| start | -- | -- | Start value of variable (defines unit and size) | - -Example: - -```julia -v = output | Var(start = zeros(3)u"N*m") - -# Same as: v = Var(output = true, start = zeros(3)u"N*m") -``` - -An attribute can be removed by using a value of `nothing`. Example: - -```julia -System1 = Model(v = input | Var(init = 1.0), ...) - -# System2 = Model(v = input, ...) -System2 = System1 | Map(v = Var(init = nothing), ...) -``` - -The following attributes are also defined for constructor `Var`, -but have **no effect yet**. -Using `min, max, info` already now, might be useful for model libraries: - -| Var Key | Shortcut | Shortcut value | Description | -|:--------- |:------------------|:----------------------|:---------------------------------| -| constant | constant | Var(constant = true) | If true, value cannot be changed | -| min, max | interval(a,b) | Var(min = a, max = b) | Allowed variable value range | -| info | info"..." | Var(info="...") | Description | - -Example: -```julia -v = output | interval(0.0,1.0) | Var(start = zeros(3)u"N*m") | info"An output variable" - -# Same as: v = Var(output = true, min = 0.0, max = 1.0, -# start = zeros(3)u"N*m", info = "An output variable") -``` - - -## A.2 Dictionaries and quoted expressions - -The fundamental mechanism for defining models, variables and parameter modifications in TinyModia are ordered dictionaries, i.e. a list of key/value pairs: - -```julia -julia> using OrderedCollections - -julia> S = OrderedDict(:p=>5, :q=>10) -OrderedDict{Symbol, Int64} with 2 entries: - :p => 5 - :q => 10 -``` - -It is also possible to define a constructor `Model` with keyword arguments which creates the ordered dictionary: - -```julia -julia> Model(; kwargs...) = OrderedDict{Symbol, Any}(kwargs) -Model (generic function with 1 method) - -julia> T=Model(q=100, r=200) -OrderedDict{Symbol, Any} with 2 entries: - :q => 100 - :r => 200 -``` - -The values can also be a quoted expression, i.e. an expression enclosed in `:( )`, an array of quoted expressions encloded in `:[ ]` or just a quoted symbol, `:x`. This mechanism is used to encode equations and expressions of the model which needs to be manipulated before the model can be simulated. - -Julia defines a very useful merge operation between dictionaries: - -```julia -julia> merge(S, T) -OrderedDict{Symbol, Any} with 3 entries: - :p => 5 - :q => 100 - :r => 200 -``` - -If a key already exists `q` in the first dictionary, it's value is overwritten otherwise it's added, `r`. Such a merge semantics allows for unification of parameter modifications and inheritance as will be demonstrated below. - -## A.3 MergeModels algorithm - -The basics of the `mergeModels` algorithm and the merge operator `|` are defined as follows (without logging): - -```julia -function mergeModels(m1::OrderedDict, m2::OrderedDict, env=Symbol()) - result = deepcopy(m1) - for (k,v) in m2) - if typeof(v) <: OrderedDict - if k in keys(result) && ! (:_redeclare in keys(v)) - result[k] = mergeModels(result[k], v, k) - else - result[k] = v - end - elseif v === nothing - delete!(result, k) - else - result[k] = v - end - end - return result -end - -|(m::OrderedDict, n::OrderedDict) = mergeModels(m, n) - -``` diff --git a/docs/src/tutorial/FloatingPointTypes.md b/docs/src/tutorial/FloatingPointTypes.md deleted file mode 100644 index 877636e..0000000 --- a/docs/src/tutorial/FloatingPointTypes.md +++ /dev/null @@ -1,178 +0,0 @@ -# 4 Floating Point Types - -The types of the floating point numbers in a TinyModia model can be -parameterized with argument `FloatType` of macro [`@instantiateModel`](@ref): - -```julia -filter = @instantiateModel(Filter; FloatType = Float64) -``` - -By default, a floating point number has type `Float64`. - -!!! warning - Using another floating point type requires that - a DifferentialEquations.jl integrator is used that is implemented - in **native Julia**. An integrator that interfaces an integrator - implemented in C (such as `CVODE_BDF()` the popular Sundials BDF method), - cannot be used. - - -## 4.1 Lower and higher precision - -In principal, any floating point type of Julia (so any type that -is derived from `AbstractFloat`) can be used in the model and -the integrators. Examples - -| Type | Precision | Package | Usage | -|:---------|:----------|:-------------|:------------------ | -| Float32 | 7 digits | built-in | Embedded system | -| Float64 | 16 digits | built-in | Offline simulation | -| Double64 | 30 digits | [DoubleFloats](https://github.com/JuliaMath/DoubleFloats.jl) | High precision needed | -| BigFloat | arbitrary | [built-in](https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/#Arbitrary-Precision-Arithmetic) | Very high precision needed (very slow) | - -- The `Float32` type might be used to test the execution and numerics of a model - that shall later run on an embedded system target - (there is no automatic way, yet, to translate a TinyModia model to `C`). - -- `Double64` is a type that is constructed from two Float64 types. - The execution is much faster as the comparable Julia built-in type - [BigFloat](https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/#Arbitrary-Precision-Arithmetic-1) when set to 128 bit precision. - The `Double64` type might be used, when simulation - with `Float64` fails due to numerical reasons (for example the model is very - sensitive, or equation systems are close to singularity) or when - very stringent relative tolerances are needed, for example relative tolerance = 1e-15 - as needed for some space applications. - -In the following example, simulation is performed with a `Float32` floating point type -used for model and integrator and utilizing a Runge-Kutta integrator of -order 4 with a fixed step size of 0.01 s: - -```julia -filter = @instantiateModel(Filter, FloatType = Float32) -simulate!(filter, RK4(), adaptive=false, stopTime=10.0, interval=0.01) -``` - - -## 4.2 Uncertainties - -Package [Measurements](https://github.com/JuliaPhysics/Measurements.jl) -provides a floating point type designed for error propagation. -A floating point number is defined with a nominal value and an -uncertainty: - -```julia -using Measurements - -m1 = 2.1 ± 0.4 -m2 = 2*m1 # 4.2 ± 0.8 -m3 = m2 - m1 # 2.1 ± 0.4 -``` - -The statement `m1 = 2.1 ± 0.4` defines that `m1` has a nominal value -of `2.1` with a [standard deviation](https://en.wikipedia.org/wiki/Standard_deviation) of `0.4`. -This means that the probability is about 95 % that the value of `m1` is in the -range `1.3 .. 2.9`. Package -[Measurements](https://github.com/JuliaPhysics/Measurements.jl) -computes the error propagation with first-order theory -(so this is typically an **approximation**) by computing -the partial derivatives of all variables with respect to all -source error definitions and computing the propagated error -with this information. The benefit is that the error bounds are typically -reasonably propagated and the computation is reasonably fast. -The drawback is that it is an approximation and will be not correct, -if the uncertainty is too large and/or the signals change too quickly -(for example are discontinuous). - -The following model defines a simple pendulum where a mass point is attached via a -rod and a revolute joint to the environment. It is described by the equations - -```math -\begin{aligned} - \frac{d\varphi}{dt} &= \omega \\ - 0 &= m \cdot L^2 \cdot \frac{d\omega}{dt} + d \cdot \omega + m \cdot g \cdot L \cdot sin(\varphi) -\end{aligned} -``` - -where ``\varphi`` is the rotation angle, ``\omega`` the angular velocity, -``m`` the mass, ``L`` the rod length, ``d`` a damping constant and -``g`` the gravity constant. This model can be defined with the commands: - -```julia -Pendulum = Model( - L = (0.8±0.1)u"m", - m = (1.0±0.1)u"kg", - d = (0.5±0.05)u"N*m*s/rad", - g = 9.81u"m/s^2", - phi = Var(init = (pi/2±0.1)*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) - ] -) - -pendulum = @instantiateModel(Pendulum, FloatType=Measurements.Measurement{Float64}) -simulate!(pendulum, Tsit5(), stopTime = 10.0) -plot(pendulum, "phi") -``` - -and simulates the pendulum with uncertain parameter and init values and -results in the following plot: - -![PendulumWithUncertaintities](../../resources/images/PendulumWithUncertaintities.png) - -The area around the nominal value of a variable characterizes the standard deviation. - - -## 4.3 Monte-Carlo Simulation - -The Julia package [MonteCarloMeasurements.jl](https://github.com/baggepinnen/MonteCarloMeasurements.jl) -provides calculations with particles. -A value can be defined with a distribution of say 2000 values randomly chosen according to a desired distribution and then all calculations are performed with 2000 values at the same time (corresponds to 2000 simulations that are carried out). - -In the example below, a modest form of 100 particles (100 simulations) with Uniform distributions of some -parameters and init values are defined that correspond roughly to the definition with uncertainties of the -previous section (but using uniform instead for normal distributions): - -```julia -using TinyModia -using DifferentialEquations -using ModiaPlot -using MonteCarloMeasurements -using Distributions -using Unitful - -const nparticles = 100 -uniform(vmin,vmax) = StaticParticles(nparticles,Distributions.Uniform(vmin,vmax)) - -Pendulum = Model( - L = uniform(0.6, 1.0), - m = uniform(0.8, 1.2), - d = uniform(0.4, 0.6), - g = 9.81, - phi = Var(init = uniform(pi/2-0.2, pi/2+0.2)), - w = Var(init = 0), - equations = :[ - w = der(phi) - 0.0 = m*L^2*der(w) + d*w + m*g*L*sin(phi) - ] -) - -pendulum = @instantiateModel(Pendulum,FloatType=StaticParticles{Float64,nparticles}) -simulate!(pendulum, Tsit5(), stopTime = 10.0) -plot(pendulum, "phi", MonteCarloAsArea=false) -``` - -The simulation result is shown in the next figure: - -![PendulumWithMonteCarlo.png](../../resources/images/PendulumWithMonteCarlo.png) - -Since plot option `MonteCarloAsArea=false` is used, all 100 simulations are -shown in the plot, together with the mean value of all simulations. -The default plot behavior is to show the mean value and the area in which -all simulations are contained (this is useful, if there are much more simulations, -because GLMakie crashes when there are too many curves in a diagram). - -There are currently a few restrictions, in particular units are not yet supported in the combination -of TinyModia and MonteCarloMeasurements, so units are not defined in the model above. - diff --git a/docs/src/tutorial/GettingStarted.md b/docs/src/tutorial/GettingStarted.md deleted file mode 100644 index 400ee91..0000000 --- a/docs/src/tutorial/GettingStarted.md +++ /dev/null @@ -1,69 +0,0 @@ -# 1 Getting Started - -A simple differential equation with $x(t) \in \R$ - -```math -T \cdot \frac{dx}{dt} + x = 1; \;\;\; x(t_0) = 0.2 -``` - -can be defined, simulated and plotted with the following commands: - -```julia -using TinyModia -using DifferentialEquations -using Unitful -@usingModiaPlot # Use plot package defined with - # ENV["MODIA_PLOT"] or usePlotPackage(..) - - -# Define model -SimpleModel = Model( - T = 0.4, - x = Var(init=0.2), - equation = :[T * der(x) + x = 1], -) - -# Transform to ODE form -simpleModel = @instantiateModel(SimpleModel) - -# Simulate with default integrator Sundials.CVODE_BDF -simulate!(simpleModel, stopTime = 1.2) - -# Simulate with a specific integrator (Tsit5) and use a unit for stopTime -simulate!(simpleModel, Tsit5(), stopTime = 1.2u"s") - -# Produce a line plot -plot(simpleModel, ("x", "der(x)")) -``` - -A model is defined with a constructor `Model` taking a comma separated list of name/value pairs. -The model consist of a definition of a parameter `T` with default value 0.2. -Constructor `Var` with an `init` key is used to define the initial condition `0.2` of the state `x`, and one equation. Equations can have a Julia expression on both sides of the equal sign and are given as a *quoted* array expression `:[ ]` assigned to a unique identifier such as `equation`. - -Macro `@instantiateModel(..)` symbolically processes the model, in particular solves the equation -for the derivative `der(x)`, so the following equation will be used by the integrator: - -```math -\frac{dx}{dt} = (1 - x) / T -``` - -Furthermore, a Julia function is generated and compiled to evaluate this equation. `@instantiateModel(..)` -returns an instance containing all the information needed for the further steps. - -The first [`simulate!`](@ref) function performs one simulation with the TinyModia default integrator -`Sundials.CVODE_BDF()`. The second `simulate!` call defines the integrator as second argument. -Integrator `Tsit5` is an [adaptive Runge-Kutta method of order 5/4 from Tsitouras](https://www.sciencedirect.com/science/article/pii/S0898122111004706). There are > 100 ODE integrators provided. For details, see [here](https://docs.sciml.ai/stable/solvers/ode_solve/). The simulation result is stored inside `simpleModel`. - -Function call `plot(..)` produces a line plot. Variables to be plotted -are defined as tuples or arrays of variable names. Tuples are displayed in one diagram. A Vector or -matrix of tuples or strings are displayed as vector or matrix of diagrams. -When `ENV["MODIA_PLOT"] = "GLMakie"` is set, then command `plot(..)` produces the following image - -![SimpleModel Plot](../../resources/images/SimpleModel_GLMakie.png) - -When `ENV["MODIA_PLOT"] = "PyPlot"` is set, the following image is produced: - -![SimpleModel Plot](../../resources/images/SimpleModel_PyPlot.png) - -Note, the tool bar of PyPlot provides various interactive commands, for example to zoom into the -plot or to store the plot in different formats on file (for example in `png` or `svg` format). diff --git a/docs/src/tutorial/Modeling.md b/docs/src/tutorial/Modeling.md deleted file mode 100644 index 57edee4..0000000 --- a/docs/src/tutorial/Modeling.md +++ /dev/null @@ -1,518 +0,0 @@ -# 2 Modeling - -## 2.1 Equation oriented models - - -A low pass filter block with input `u` and output `y` - -```math -\begin{aligned} -T \cdot \frac{dx}{dt} + x &= u\\ - y &= x \\ -x(t_0) &= 0 -\end{aligned} -``` -can be defined as: - -```julia -using TinyModia - -LowPassFilter = Model( - T = 0.2, - u = input, - y = output | Var(:x), - x = Var(init=0), - equation = :[T * der(x) + x = u], -) -``` -The symbols `input` and `output` refer to predefined variable constructors to define the input and output variables. If an equation has just a unique variable in the left hand side, `y`, the right hand side can be given as a quoted expression in a Var-constructor `Var(:x)` after the `output` constructor combined with the merge operator, `|`, see below. - -## 2.2 Merging models - -It is possible to combine models by merging. If we want to change the model to become a highpass filter, an alternative output equation - -```math -y = -x + u -``` - -is defined in an anonymous model `Model( y = :(-x + u) )`. This anonymous model is merged with `LowPassFilter` using the merge operator `|`: - -```julia -HighPassFilter = LowPassFilter | Model( y = Var(:(-x + u) ) ) -``` - -The merging implies that the `output` property of `y` is kept, but the binding expression is changed from `:x` to `:(-x + u)`. - -In general, recursive merging is desired and TinyModia provides a `mergeModels` function for that (see appendix [A.3 MergeModels algorithm](@ref)). This function is invoked as a binary operator `|` (also used for merge in Python). Note, that the order of the arguments/operands are important. - -Generalizing the block to have two outputs for both low and high pass filtering would be done as follows: - -```julia -LowAndHighPassFilter = LowPassFilter | Model( - y = nothing, - low = output | Var(:x), - high = output | Var(:(-x + u)), - ) -``` -The equation for `y` is removed by "assigning" `nothing` and two variables are defined and declared as outputs. - -Model `LowAndHighPassFilter` represents the following equations: - -```math -\begin{aligned} -T \cdot \frac{dx}{dt} + x &= u\\ - low &= x \\ - high &= -x + u \\ -x(t_0) &= 0 -\end{aligned} -``` - -By turning on logging of merging `setLogMerge(true)`, the translator gives the log: - -```julia -Adding: value = :(x) -Adding: value = :(-x + u) -Deleting: y -Adding: low = Var( - output = true, - value = :(x), - ), -Adding: high = Var( - output = true, - value = :(-x + u), - ), -``` - -The resulting model is pretty printed by calling `@showModel LowAndHighPassFilter`: - -```julia -LowAndHighPassFilter = Model( - T = 0.2, - u = Var( - input = true, - ), - x = Var( - init = 0.0 V, - ), - equations = :([T * der(x) + x = u]), - low = Var( - output = true, - value = :(x), - ), - high = Var( - output = true, - value = :(-x + u), - ), -), -``` - -## 2.3 Functions and tables - -In order to test an input/output block as defined in the previous section, an input needs to be defined. This can be made by adding an equation for `u`. Assume we want `u` to be sinousoidial with an increasing frequency: - -```julia -TestLowAndHighPassFilter = LowAndHighPassFilter | Model( - u = :(sin( (time+1u"s")*u"1/s/s" * time)*u"V"), - x = Var(init=0.2u"V") - ) -``` - -`time` is a reserved name for the independent variable. It has unit `s` for seconds. The Julia package [Unitful](https://painterqubits.github.io/Unitful.jl/stable/) provides a means for defining units and managing unit inference. It need not be explicitly defined, because its symbols are exported by `using TinyModia`. Definition of units is done with a string macro `u"..."`. In this case, the input signal was given unit Volt. The state x must then also have consistent unit, that is Volt. If the model equations contain systems of simultaneous equations, then approximate guess values, optionally with units, must be given `start`: `i = Var(start=0.0u"A")`. - -The input signal can also be defined by interpolation in a table: - -```julia -using Interpolations - -table = CubicSplineInterpolation(0:0.5:2.0, [0.0, 0.7, 2.0, 1.8, 1.2]) -TestLowAndHighPassFilter2 = TestLowAndHighPassFilter | Map(u = :(table(time*u"1/s")*u"V")) -``` - -A function cannot return more as one variable and a function cannot modify -one of its arguments: - -``` -equations = :[ - (y1, y1) = fc1(u1,u2) # Error: Two return arguments - fc2!(u,y) # Error: Not known that fc2! computes y - println("This is a test") # Fine -] -``` - -The first issue can be fixed by rewriting the function call: - -``` -equations = :[ - v = fc1(u1,u2) - y1 = v[1] - y2 = v[2] -] -``` - - -## 2.4 Hierarchical modeling - -Sofar, the composition of models have resulted in dictionaries of key/value pairs with values being numeric values or quoted expressions. Hierarchical models are obtained if the values themself are `Models`, i.e. dictionaries. A model with two filters can, for example, be defined as follows: - -```julia -TwoFilters = ( - high = HighPassFilter, - low = LowPassFilter, -) -``` - -Note, that the previous definitions of HighPassFilter and LowPassFilter was used instead of making the Model defintions inline. - -A band pass filter is a series connection of a high pass filter and a low pass filter and can be described as: - -```julia -BandPassFilter = ( - u = input, - y = output, - high = HighPassFilter | Map(T=0.5, x=Var(init=0.1u"V")), - low = LowPassFilter | Map(x=Var(init=0.2u"V")), - equations = :[ - high.u = u, - low.u = high.y, - y = low.y] -) -``` - -A new input, `u`, has been defined which is propagated to `high.u`. The series connection itself is obtained by the equation `low.u = high.y`. Note, that dot-notation is allowed in equations. - -The input and output for the BandPassFilter when using the same input definition as for the TestLowPassFilter - -```julia -TestBandPassFilter = BandPassFilter | Map( - u = :(sin( (time+1u"s")*u"1/s/s" * time)*u"V") - ) -bandPassFilter = @instantiateModel(TestBandPassFilter) -simulate!(bandPassFilter, Tsit5(), stopTime = 50u"s") -plot(bandPassFilter, ["u", "y"], figure=2) -``` - - -is shown below: - -![Band Pass Filter Plot](../../resources/images/BandPassFilterPlot.png) - - -## 2.5 Physically oriented modeling - -Sofar, only signal flow modeling has been used, i.e. input/output blocks coupled with equations between outputs and inputs. For object oriented modeling more high level constructs are neccessary. Coupling is then acausal and involves potentials such as electric potential, positions, pressure, etc. and flows such as electric current, forces and torques and mass flow rate. - -### 2.5.1 Connectors - -Models which contain any `flow` variable, i.e. a variable having an attribute `flow=true`, are considered connectors. Connectors must have equal number of flow and potential variables, i.e. variables having an attribute `potential=true`, and have matching array sizes. Connectors may not have any equations. An example of an electrical connector with potential (in Volt) and current (in Ampere) is shown below. - -```julia -Pin = Model( v = potential, i = flow ) -``` -`potential` is a shortcut for `Var(potential=true)` and similarly for `flow`. - -### 2.5.2 Components - -Components are declared in a similar ways as blocks. However, the interfaces between components are defined using connector instances. - -An electrical resistor can be descibed as follows: - -```julia -Resistor = Model( - R = 1.0u"Ω", - p = Pin, - n = Pin, - equations = :[ - 0 = p.i + n.i - v = p.v - n.v - i = p.i - R*i = v ] - ) -``` - -### 2.5.3 Inheritance - -Various physical components sometimes share common properties. One mechanism to handle this is to use inheritance. In TinyModia, **merging** is used. - -Electrical components such as resistors, capacitors and inductors are categorized as oneports which have two pins. Common properties are: constraint on currents at the pins and definitions of voltage over the component and current through the component. - -```julia -OnePort = Model( - p = Pin, - n = Pin, - equations = :[ - 0 = p.i + n.i - v = p.v - n.v - i = p.i ] ) -``` - -Having such a OnePort definition makes it convenient to define electrical component models by merging OnePort with specific parameter definitions with default values and equations: - -```julia -Resistor = OnePort | Model( R = 1.0u"Ω", equation = :[ R*i = v ], ) - -Capacitor = OnePort | Model( C = 1.0u"F", v=Map(init=0.0u"V"), equation = :[ C*der(v) = i ] ) - -Inductor = OnePort | Model( L = 1.0u"H", i=Map(init=0.0u"A"), equation = :[ L*der(i) = v ] ) - -ConstantVoltage = OnePort | Model( V = 1.0u"V", equation = :[ v = V ] ) -``` -The merged `Resistor` is shown below: - -```julia -Resistor = Model( - p = Model( - v = Var( - potential = true, - ), - i = Var( - flow = true, - ), - ), - n = Model( - v = Var( - potential = true, - ), - i = Var( - flow = true, - ), - ), - equations = :([v = p.v - n.v; 0 = p.i + n.i; i = p.i, R * i = v]), - R = 1.0 Ω, -), -``` - -### 2.5.4 Connections - -Connections are described as an array of tuples listing the connectors that are connected: -```julia - ( , , ... ) -``` -A connect reference has either the form 'connect instance name' or 'component instance name'.'connect instance name' with 'connect instance name' being either a connector instance, input or output variable. - -Examples -```julia - connect = :[ - (V.p, R1.p) - (R1.n, p) - (C1.n, V.n, R2.p) - ... - ] -``` - -For connectors, all the potentials of the connectors in the same connect tuple are set equal and the sum of all incoming flows to the model are set equal to the sum of the flows into sub-components. A Modelica inspired form of connections, i.e. connect-equations, are also supported: - -```julia - equations = :[ - connect(V.p, R1.p) - connect(R1.n, p) - connect(C1.n, V.n, R2.p) - ... - ] -``` - -### 2.5.5 Connected models - -Having the above electrical component models, enables defining a filter - -![Filter Circuit](../../resources/images/Filter.png) - -by instanciating components, setting parameters and defining connections. - - -```julia -Filter = ( - R = Resistor | Map(R=0.5u"Ω"), - C = Capacitor | Map(C=2.0u"F"), - V = ConstantVoltage | Map(V=10.0u"V"), - connect = :[ - (V.p, R.p) - (R.n, C.p) - (C.n, V.n) - ] -) -``` - -The connect tuples are translated to: - -```julia - V.p.v = R.p.v - 0 = V.p.i + R.p.i - R.n.v = C.p.v - 0 = R.n.i + C.p.i - C.n.v = V.n.v - 0 = C.n.i + V.n.i -``` - -### 2.5.6 Parameter propagation - -Hierarchical modification of parameters is powerful but sometimes a bit inconvenient. It is also possible to propagate parameters introduced on a high level down in the hierarchy. The following Filter model defines three parameters, `r`, `c` and `v`. The `r` parameter is used to set the resistance of the resistor R: `Map(R=:r)`. - -```julia -Filter2 = Model( - r = 2.0u"Ω", - c = 1.0u"F", - v = 10u"V", - R = Resistor | Map(R=:r), - C = Capacitor | Map(C=:c), - V = ConstantVoltage | Map(V=:v), - connect = :[ - (V.p, R.p) - (R.n, C.p) - (C.n, V.n) - ] -) -``` - -Two separate filters can then be defined with: - -```julia -TwoFilters = Model( f1 = Filter | Map( r = 10.0, c = 2.0), f2 = Filter ) -``` - -### 2.5.7 Redeclarations - -It is possible to reuse a particular model topology by redeclaring the model of particular components. For example, changing the filter `f1` to a voltage divider by changing C from a Capacitor to a Resistor. A predefined definition `redeclare` is used for this purpose. - -```julia -VoltageDividerAndFilter = TwoFilters | Map(f1 = Map(C = redeclare | Resistor | Map(R = 20.0))) -``` - -By using `redeclare`, a new model based on a Resistor is used for `C` and the usual merge semantics with the previously defined model of `C` is not used. - -The above examples are available in file `FilterCircuit.jl`. - - -### 2.5.8 Drive train example - -A larger example that utilizes most of the previously described features of -TinyModia is available as `$(TinyModia.path)/examples/ServoSystem.jl`. -This is a textual (TinyModia) representation of a Modelica model - -![ServoSystem](../../resources/images/ServoSystem.png) - -and demonstrates how to build up a hierarchical, multi-domain model consisting -of a servo-system with a load, where the servo-system consists of -an electric motor with a current and speed controller, as well with a more -detailed model of a gearbox. - - -## 2.6 Arrays - -Model parameters and variables can be arrays. For example a linear state space system - -```math -\begin{aligned} -\frac{d\boldsymbol{x}}{dt} &= \boldsymbol{A} \cdot \boldsymbol{x} + \boldsymbol{B} \cdot \boldsymbol{u}\\ - \boldsymbol{y} &= \boldsymbol{C} \cdot \boldsymbol{x} + \boldsymbol{D} \cdot \boldsymbol{u} -\end{aligned} -``` - -can be defined as: - -```julia -StateSpace = Model( - A = fill(0.0, 0, 0), - B = fill(0.0, 0, 0), - C = fill(0.0, 0, 0), - D = fill(0.0, 0, 0), - u = input, - y = output, - x = Var(init = zeros(0)), - equations = :[ - der(x) = A*x + B*u - y = C*x + D*u - ] -) -``` - -and used as: - -```julia -col(args...) = hvcat(1, args...) # Construct a column matrix from a vector - -SecondOrder = Model( - w = 20.0, - D = 0.1, - k = 2.0, - sys = StateSpace | Map(A = :([ 0 1; - -w^2 -2*D*w]), - B = :(col([0; w^2])), - C = :([k 0]), - D = :(zeros(1,1)), - x = Var(init = zeros(2)) ), - equations = :[sys.u = [1.0]] -) -``` -Variables `sys.u` and `sys.y` are vectors with one element each. - -Note, `[0; w^2]` is a vector in Julia and not a column matrix -(see the discussion [here](https://discourse.julialang.org/t/construct-a-2-d-column-array/30617)). -In order that `B` is defined as column matrix, the function `col(..)` is used. - -Array equations remain array equations during symbolic transformation and in the generated code, -so the code is both compact and efficient. In order that this is reasonably possible, the definition -of an array cannot be split in different statements: - -```julia -equations = :[ # error, vector v is not defined as one symbol - m1*der(v[1]) = 2.0 - m2*der(v[2]) = 3.0 -] -``` - -If scalar equations are needed in which arrays are used, then the arrays have -to be first defined and then elements can be used. - -```julia -v = Var(init=zeros(2)), -equations = :[ - a = der(v) - a1 = a[1] - a2 = a[2] - m1*a1 = 2.0 - m2*a2 = 3.0 -] -``` - -## 2.7 Model libraries - -TinyModia provides a small set of pre-defined model components in directory -`$(TinyModia.path)/models`: - -- `AllModels.jl` - Include all model libraries -- `Blocks.jl` - Input/output control blocks -- `Electric.jl` - Electric component models -- `HeatTransfer.jl` - 1D heat transfer component models -- `Rotational.jl` - 1D rotational, mechanical component models -- `Translational.jl` - 1D translational, mechanical component models -- [PathPlanning](@ref) - Defining reference trajectories and access them. - -These models are included in package `TinyModia`, but are not exported, so must -be access with `TinyModia.xxx". - -The circuit of section [2.5.5 Connected models](@ref) can be for example -constructed with these libraries in the following way: - -```julia -using TinyModia -using DifferentialEquations -@usingModiaPlot - -FilterCircuit = Model( - R = TinyModia.Resistor | Map(R=0.5u"Ω"), - C = TinyModia.Capacitor | Map(C=2.0u"F", v=Var(init=0.1u"V")), - V = TinyModia.ConstantVoltage | Map(V=10.0u"V"), - ground = TinyModia.Ground, - connect = :[ - (V.p, R.p) - (R.n, C.p) - (C.n, V.n, ground.p) - ] -) - -filterCircuit = @instantiateModel(FilterCircuit) -simulate!(filterCircuit, Tsit5(), stopTime=10.0) -plot(filterCircuit, ["C.v", "C.i"], figure=3) -``` - -It is planned to support a much larger set of predefined model components in the future. diff --git a/docs/src/tutorial/Simulation.md b/docs/src/tutorial/Simulation.md deleted file mode 100644 index 477b06f..0000000 --- a/docs/src/tutorial/Simulation.md +++ /dev/null @@ -1,250 +0,0 @@ -# 3 Simulation - -A particular model is instantiated, simulated and results plotted with the commands: - -```julia -using TinyModia -using DifferentialEquations -@usingModiaPlot - -filter = @instantiateModel(Filter) -simulate!(filter, stopTime=10.0) -plot(filter, "y", figure=1) -``` - - -## 3.1 Instantiating - -The `@instantiateModel` macro takes additional arguments: - -```julia -modelInstance = @instantiateModel(model; - FloatType = Float64, aliasReduction=true, unitless=false, - log=false, logModel=false, logDetails=false, logStateSelection=false, - logCode=false, logExecution=false, logTiming=false) -``` - -The macro performs structural and symbolic transformations, generates a function for -calculation of derivatives suitable for use with [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl) -and returns `modelInstance::SimulationModel` that can be used in other functions, -for example to simulate or plot results: - -* `model`: model (declarations and equations). -* `FloatType`: Variable type for floating point numbers (see below). -* `aliasReduction`: Perform alias elimination and remove singularities. -* `unitless`: Remove units (useful while debugging models and needed for MonteCarloMeasurements). -* `log`: Log the different phases of translation. -* `logModel`: Log the variables and equations of the model. -* `logDetails`: Log internal data during the different phases of translation. -* `logStateSelection`: Log details during state selection. -* `logCode`: Log the generated code. -* `logExecution`: Log the execution of the generated code (useful for timing compilation) -* `logCalculations`: Log the calculations of the generated code (useful for finding unit bugs) -* `logTiming`: Log timing of different phases. -* `return modelInstance prepared for simulation` - -## 3.2 Simulating - -The [`simulate!`](@ref) function performs one simulation with -[DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl) using the default integrator -that this package automatically selects and stores the result in `modelInstance`. - It is also possible to specify the integrator as second argument of `simulate!`: - -```julia -using TinyModia -using DifferentialEquations -@usingModiaPlot - -filter = @instantiateModel(Filter) -sol = simulate!(filter, Tsit5(), stopTime=10.0, merge=Map(T=0.5, x=0.8)) -plot(filter, ["y", "x"], figure=1) -``` - -Integrator `DifferentialEquations.Tsit5` is an -[adaptive Runge-Kutta method of order 5/4 from Tsitouras](https://www.sciencedirect.com/science/article/pii/S0898122111004706). -There are > 100 ODE integrators provided. For details, see [here](https://docs.sciml.ai/stable/solvers/ode_solve/). - -Parameters and init/start values can be changed with the `merge` keyword. -The effect is the same, as if the filter would have been instantiated with: - -```julia -filter = @instantiateModel(Filter | Map(T=0.5, x=Var(init=0.8)) -``` - -Note, with the `merge` keyword in simulate!, init/start values are directly -given as a value (`x = 0.8`) and are not defined with `Var(..)`. - -Function `simulate!` returns `sol` which is the value that is returned by function -[DifferentialEquations.solve](https://diffeq.sciml.ai/stable/features/ensemble/#Solving-the-Problem). -Functions of `DifferentialEquations` that operate on this return argument can therefore also be -used on the return argument `sol` of `simulate!`. - - -## 3.4 Plotting - -A short overview of the most important plot commands is given in section -section [Results and Plotting](@ref) - - -## 3.5 State selection (DAEs) - -TinyModia has a sophisticated symbolic engine to transform high index DAEs -(Differential Algebraic Equations) automatically to ODEs (Ordinary Differential Equations in -state space form). During the transformation, equations might be analytically -differentiated and code might be generated to solve linear equation systems -numerically during simulation. The current engine **cannot** transform a DAE to ODE form, if the -**DAE contains nonlinear algebraic equations**. There is an (internal) prototype available to transform -nearly any DAE system to a special index 1 DAE system that can be solved with standard DAE integrators. -After a clean-up phase, this engine will be made publicly available at some time in the future. -Some of the algorithms used in TinyModia are -described in [Otter and Elmqvist (2017)](https://modelica.org/events/modelica2017/proceedings/html/submissions/ecp17132565_OtterElmqvist.pdf). Some algorithms are not yet published. - -Usually, the symbolic engine is only visible to the modeler, when the model has errors, -or when the number of ODE states is less than the number of DAE states. The latter case -is discussed in this section. - -The following object diagram shows two rotational inertias that are connected -by an ideal gear. One inertia is actuated with a sinusoidal torque: - -![TwoInertiasAndIdealGear](../../resources/images/TwoInertiasAndIdealGear.png) - -In order to most easily understand the issues, this model -is provided in a compact, "flattened" form: - -```julia -TwoInertiasAndIdealGearTooManyInits = Model( - J1 = 50, - J2 = 100, - ratio = 2, - f = 3, # Hz - - phi1 = Var(init = 0.0), # Absolute angle of inertia1 - w1 = Var(init = 0.0), # Absolute angular velocity of inertia1 - phi2 = Var(init = 0.0), # Absolute angle of inertia2 - w2 = Var(init = 0.0), # Absolute angular velocity of inertia2 - - equations = :[ - tau = 2.0*sin(2*3.14*f*time/u"s") - - # inertia1 - w1 = der(phi1) - J1*der(w1) = tau - tau1 - - # ideal gear - phi1 = ratio*phi2 - ratio*tau1 = tau2 - - # inertia2 - w2 = der(phi2) - J2*der(w2) = tau2 - ] -) - -drive1 = @instantiateModel(TwoInertiasAndIdealGearTooManyInits) -simulate!(drive1, Tsit5(), stopTime = 1.0, logStates=true) -plot(drive1, [("phi1", "phi2"), ("w1", "w2")]) -``` - -The option `logStates=true` results in the following output: - -``` -... Simulate model TwoInertiasAndIdealGearTooManyInits - -│ # │ state │ init │ unit │ nominal │ -├───┼────────┼──────┼──────┼─────────┤ -│ 1 │ phi2 │ 0.0 │ │ NaN │ -│ 2 │ w2 │ 0.0 │ │ NaN │ -``` - -This model translates and simulates without problems. - -Changing the init-value of `w2` to `1.0` and resimulating: - -```julia -simulate!(drive1, Tsit5(), stopTime = 1.0, logStates=true, merge = Map(w2=1.0)) -``` - -results in the following error: - -``` -... Simulate model TwoInertiasAndIdealGearTooManyInits - -│ # │ state │ init │ unit │ nominal │ -├───┼───────┼──────┼──────┼─────────┤ -│ 1 │ phi2 │ 0.0 │ │ NaN │ -│ 2 │ w2 │ 1.0 │ │ NaN │ - - -Error from simulate!: -The following variables are explicitly solved for, have init-values defined -and after initialization the init-values are not respected -(remove the init-values in the model or change them to start-values): - -│ # │ name │ beforeInit │ afterInit │ -├───┼──────┼────────────┼───────────┤ -│ 1 │ w1 │ 0.0 │ 2.0 │ -``` - -The issue is the following: - -Every variable that is used in the `der` operator is a **potential ODE state**. -When an `init` value is defined for such a variable, then TinyModia either utilizes -this initial condition (so the variable has this value after initialization), or an -error is triggered, as in the example above. - -The model contains the equation: - -```julia -phi1 = ratio*phi2 -``` - -So the potential ODE states `phi1` and `phi2` are constrained, and only one of them -can be selected as ODE state, and the other variable is computed from this equation. -Since parameter `ratio` can be changed before simulation is started, it can be changed -also to a value of `ratio = 0`. Therefore, only when `phi2` is selected as ODE state, -`phi1` can be uniquely computed from this equation. If `phi1` would be selected as ODE state, -then a division by zero would occur, if `ratio = 0`, since `phi2 = phi1/ratio`. For this -reason, TinyModia selects `phi2` as ODE state. This means the **`init` value of `phi1` -has no effect**. This is uncritical, as long as initialization computes this init value -from the constraint equation above, as done in the example above. - -When differentiating the equation above: - -```julia -der(phi1) = ratio*der(phi2) # differentiated constraint equation - w1 = der(phi1) - w2 = der(phi2) -``` - -it becomes obvious, that there is also a hidden constraint equation for -the potential ODE states `w1, w2`: - -```julia -w1 = ratio*w2 # hidden constraint equation -``` - -Again, TinyModia selects `w2` as ODE state, and ignores the `init` value of `w1`. -In the second simulation, the `init` value of `w1` (= 0.0) is no longer consistent to the -init value of `w2` (= 1.0). Therefore, an error occurs. - -The remedy is to remove the `init` values of `phi1, w1` from the model: - -```julia -drive2 = @instantiateModel(TwoInertiasAndIdealGearTooManyInits | - Map(phi1 = Var(init=nothing), - w1 = Var(init=nothing)) ) -simulate!(drive2, Tsit5(), stopTime = 1.0, logStates=true, merge = Map(w2=1.0)) -``` - -and simulation is successful! - -TinyModia tries to respect `init` values during symbolic transformation. -In cases as above, this is not possible and the reported issue occurs. -In some cases, it might not be obvious, why TinyModia selects a particular -variable as an ODE state. You can get more information by setting -`logStateSelection=true`: - -```julia -drive1 = @instantiateModel(TwoInertiasAndIdealGearTooManyInits, logStateSelection=true) -``` - diff --git a/docs/src/tutorial/Tutorial.md b/docs/src/tutorial/Tutorial.md deleted file mode 100644 index c1b2367..0000000 --- a/docs/src/tutorial/Tutorial.md +++ /dev/null @@ -1,21 +0,0 @@ -# TinyModia Tutorial - -This tutorial gives an overview of package [TinyModia](https://github.com/ModiaSim/TinyModia.jl) -to construct component-based and equation-based models with the **Modia language** -on a high level, symbolically transforming these models into ODEs -(Ordinary Differential Equations in state space form), simulating them and plotting result variables. - -Note, all examples in this tutorial can be executed with\ -`using TinyModia; include("$(TinyModia.path)/examples/Tutorial.jl")` - -!!! info - TinyModia has an interface to various plot packages. A plot package can be - either selected by setting `ENV["MODIA_PLOT"] = XXX`, for example in the `config/startup.jl` - file of Julia or by command `TinyModia.usePlotPackage(XXX)`. Possible values for `XXX`: - - "[PyPlot](https://github.com/JuliaPy/PyPlot.jl)" (plots with Matplotlib from Python), - - "[GLMakie](https://github.com/JuliaPlots/GLMakie.jl)" (interactive plots in an OpenGL window), - - "[WGLMakie](https://github.com/JuliaPlots/WGLMakie.jl)" (interactive plots in a browser window), - - "[CairoMakie](https://github.com/JuliaPlots/CairoMakie.jl)" (static plots on file with publication quality), - - "NoPlot" (= all `plot(...)` calls are ignored), or - - "SilentNoPlot" (= NoPlot without messages). - diff --git a/examples/CauerLowPassFilter.jl b/examples/CauerLowPassFilter.jl deleted file mode 100644 index fd62da0..0000000 --- a/examples/CauerLowPassFilter.jl +++ /dev/null @@ -1,91 +0,0 @@ -module CauerLowPassFilterModel - -using TinyModia - -using DifferentialEquations -using Test -@usingModiaPlot - -include("../models/Electric.jl") - -l1 = 1.304 -l2 = 0.8586 -c1 = 1.072*1u"F" -c2 = 1/(1.704992^2*l1)*1u"F" -c3 = 1.682*1u"F" -c4 = 1/(1.179945^2*l2)*1u"F" -c5 = 0.7262*1u"F" - -CauerLowPassOPVWithoutNodes(i=1) = Model( - # Cauer low pass filter with operational amplifiers - - C1 = Capacitor | Map(C=c1 + c2), - C2 = Capacitor | Map(C=c2, v=Var(init=nothing)), - C3 = Capacitor | Map(C=l1*1u"F"), - C4 = Capacitor | Map(C=c4*i, v=Var(init=nothing)), - C5 = Capacitor | Map(C=c2, v=Var(init=nothing)), - R1 = Resistor | Map(R=1u"Ω"), - R2 = Resistor | Map(R=1u"Ω"), - R3 = Resistor | Map(R=1u"Ω"), - Op1 = IdealOpAmp3Pin, - G = Ground, - R4 = Resistor | Map(R=-1u"Ω"), - R5 = Resistor | Map(R=-1u"Ω"), - Op2 = IdealOpAmp3Pin, - Op3 = IdealOpAmp3Pin, - G1 = Ground, - R6 = Resistor | Map(R=1u"Ω"), - R7 = Resistor | Map(R=1u"Ω"), - C6 = Capacitor | Map(C=c2 + c3 + c4, v=Var(init=nothing)), - R8 = Resistor | Map(R=-1u"Ω"), - R9 = Resistor | Map(R=-1u"Ω"), - R10 = Resistor | Map(R=1u"Ω"), - Op4 = IdealOpAmp3Pin, - Op5 = IdealOpAmp3Pin, - C7 = Capacitor | Map(C=l2*1u"F"), - C8 = Capacitor | Map(C=c4, i=Var(start=0u"A")), - C9 = Capacitor | Map(C=c4 + c5), - R11 = Resistor | Map(R=1u"Ω"), - - G2 = Ground, - G3 = Ground, - G4 = Ground, - V = ConstantVoltage | Map(V=1.0u"V"), - Ground1 = Ground, - -connect = :[ - (Op1.in_p, G.p) - (G1.p, Op2.in_p) - (R1.n, Op1.in_n, C2.n, R2.n, C1.p, R3.p) - (R3.n, C1.n, Op1.out, R4.p, C5.p) - (R4.n, Op2.in_n, C3.p, R5.n) - (C2.p, R5.p, Op3.out, C6.n, R9.p, C8.p) - (C3.n, Op2.out, R2.p, R7.p) - (R7.n, Op3.in_n, C5.n, R6.n, C6.p, C4.n) - (C4.p, R8.p, R11.n, C9.n, Op5.out) - (R9.n, R8.n, Op4.in_n, C7.p) - (R6.p, C7.n, Op4.out, R10.p) - (G2.p, Op3.in_p) - (R11.p, C9.p, R10.n, Op5.in_n, C8.n) - (Op4.in_p, G3.p) - (Op5.in_p, G4.p) - (V.p, Ground1.p) - (V.n, R1.p) ] -) - -n = 10 -println("Build array of $n Cauer low pass filters") -@time Filters = Model( - filters = [CauerLowPassOPVWithoutNodes(0.1*i) for i in 1:n] -) - -@test_skip begin -model = @instantiateModel(Filters, logDetails=false, logTiming=true, unitless=true) - -println("Simulate") -@time simulate!(model, Tsit5(), stopTime = 60, requiredFinalStates = - [-0.5000732186007855, -0.5002239998029879, 0.4996923410661849, -0.4996706636198064, -0.5000929741546876, -0.5001255383344897, -0.500147742207576, 0.49981113006573824, -0.4996196061432069, -0.5001392063603706, -0.5001815616147427, -0.5000459266587362, 0.49996685095395915, -0.49958392015463465, -0.5001886259176451, -0.5002389821958331, -0.4999173001411904, 0.5001611780149184, -0.49957016523210945, -0.5002393712119582, -0.5002944833191254, -0.49976183273648583, 0.5003940588092074, -0.49958591550449066, -0.5002887040151874, -0.500343478728503, -0.4995812991530469, 0.5006629055320556, -0.49963969356758026, -0.5003327561376948, -0.50037980690654, -0.49938004306850625, 0.5009615326279456, -0.4997407922705924, -0.5003662177501006, -0.500395375828166, -0.4991659724894459, 0.5012787730322307, -0.4998989295998676, -0.5003819572251011, -0.5003797586125351, -0.49895184523346914, 0.5015966895590688, -0.5001236602409048, -0.5003705619890064, -0.5003197458974357, -0.49875691633150787, 0.5018882791340892, -0.5004234377294563, -0.5003197904255381]) -plot(model, ["filters_1.C9.v", "filters_2.C9.v", "filters_3.C9.v"]) -end - -end diff --git a/examples/FilterCircuit.jl b/examples/FilterCircuit.jl deleted file mode 100644 index 0f570c5..0000000 --- a/examples/FilterCircuit.jl +++ /dev/null @@ -1,82 +0,0 @@ -module FilterCircuit - -using TinyModia - -using DifferentialEquations -@usingModiaPlot - -setLogMerge(false) - -include("../models/Electric.jl") - -Filter = Model( - R = Resistor | Map(R=0.5u"Ω"), - C = Capacitor | Map(C=2.0u"F", v=Var(init=0.1u"V")), - V = ConstantVoltage | Map(V=10.0u"V"), - ground = Ground, - connect = :[ - (V.p, R.p) - (R.n, C.p) - (C.n, V.n, ground.p) - ] -) - -model = @instantiateModel(Filter) -@time simulate!(model, Tsit5(), stopTime = 10, requiredFinalStates=[9.999550454584188]) -plot(model, [("R.v", "C.v")]) - -println("Simulate once more with different R.R") -@time simulate!(model, Tsit5(), stopTime = 10, merge = Map(R = Map(R = 5u"Ω")), requiredFinalStates = [6.3579935215716095]) -plot(model, [("R.v", "C.v")]) - -# setLogMerge(true) -println("Filter without ground and parameter propagation") -Filter2 = Model( - r = 2.0u"Ω", - c = 1.0u"F", - v = 10u"V", - R = Resistor | Map(R=:r), - C = Capacitor | Map(C=:c), - V = ConstantVoltage | Map(V=:v), - connect = :[ - (V.p, R.p) - (R.n, C.p) - (C.n, V.n) - ] -) - -# @showModel(Filter2) - -model = @instantiateModel(Filter2) -simulate!(model, Tsit5(), stopTime = 10, requiredFinalStates = [9.932620374719848]) -plot(model, [("R.v", "C.v")]) - - -println("Voltage divider by redeclaring capacitor to resistor") -Cpar = Map(C = 5.0u"F") - -TwoFilters = Model( f1 = Filter | Map( R = Map(R = 10.0u"Ω"), C = Cpar), f2 = Filter) - -#setLogMerge(true) - -VoltageDividerAndFilter = TwoFilters | Map(f1 = Map(C = redeclare | Resistor | (R = 2.0u"Ω", v = Map(start = 0u"V")))) - -model = @instantiateModel(VoltageDividerAndFilter, unitless=true, logCalculations=false, evaluateParameters=true) -simulate!(model, Tsit5(), stopTime = 10) -plot(model, [("f1.R.v", "f1.C.v"), ("f2.R.v", "f2.C.v")]) - -n=10 -println("Build array of $n filters") -Filters = Model( - filters = [Filter | Map( R = Map(R = (10.0+5*i)*u"Ω")) for i in 1:n] -) - -setLogMerge(false) - -model = @instantiateModel(Filters) - -simulate!(model, Tsit5(), stopTime = 10, requiredFinalStates = -[2.9063400246452358, 2.2898722474751163, 1.8945655444974656, 1.6198309235728083, 1.4179087924692246, 1.2632806644107324, 1.1410907635368692, 1.0421095614435398, 0.9603029088053439, 0.8915602951695468]) -plot(model, [("filters_1.R.v", "filters_1.C.v"), ("filters_2.R.v", "filters_2.C.v")]) - -end \ No newline at end of file diff --git a/examples/FilterCircuitTest.jl b/examples/FilterCircuitTest.jl deleted file mode 100644 index f4d6145..0000000 --- a/examples/FilterCircuitTest.jl +++ /dev/null @@ -1,67 +0,0 @@ -module FilterCircuit - -using TinyModia -using DifferentialEquations -@usingModiaPlot -using Unitful - -setLogMerge(true) - -include("../models/ElectricTest.jl") - -# res = Resistor -# @showModel(res) - -@showModel(Capacitor) - -Filter = Model( - R = Resistor | Map(R=0.5u"Ω"), - C = Capacitor | Map(C=2.0u"F", v=Map(init=0.1u"V")), - V = ConstantVoltage | Map(V=10.0u"V"), - ground = Ground, - connect = :[ - (V.p, R.p) - (R.n, C.p) - (C.n, V.n, ground.p) - ] -) - -@showModel(Filter) - -#= -Filter2 = Model( - r = 1.0u"Ω", - c = 1.0u"F", - v = 1.0u"V", - R = Resistor | Map(R=:(up.r)), - C = Capacitor | Map(C=:(up.c)), - V = ConstantVoltage | Map(V=:(up.v)), - ground = Ground, - connect = :[ - (V.p, R.p) - (R.n, C.p) - (C.n, V.n, ground.p) - ] -) - -Cpar = Map(C = 5.0u"F") - -TwoFilters = Model( f1 = Filter | Map( R = Map(R = 10.0u"Ω"), C = Cpar), f2 = Filter) - -VoltageDividerAndFilter = TwoFilters | Map(f1 = Map(C = Redeclare | Resistor | (R = 20.0u"Ω", start = Map(v = 0u"V")))) - -println("Build") -@time Filters = Model( - filters = [Filter for i in 1:10] -) - -setLogMerge(false) - -model = @instantiateModel(Filters, logDetails=false, aliasReduction=false) - -println("Simulate") -@time simulate!(model, Tsit5(), stopTime = 50, requiredFinalStates = - [9.999999294887072, 9.999999294887072, 9.999999294887072, 9.999999294887072, 9.999999294887072, 9.999999294887072, 9.999999294887072, 9.999999294887072, 9.999999294887072, 9.999999294887072]) -plot(model, [("filters_1.R.v", "filters_1.C.v"), ("filters_2.R.v", "filters_2.C.v")]) -=# -end \ No newline at end of file diff --git a/examples/MotorControl.jl b/examples/MotorControl.jl deleted file mode 100644 index 79a87b8..0000000 --- a/examples/MotorControl.jl +++ /dev/null @@ -1,162 +0,0 @@ -module MotorControl - -println("\nMotorControl: Demonstrating the ability to simulate hierarchical mixed domain models") - -include("../models/Blocks.jl") -include("../models/Electric.jl") -include("../models/Rotational.jl") - -using TinyModia -using DifferentialEquations -@usingModiaPlot -using Measurements - -export MotorControl2 - -MotorControl1 = Model( - step = Step | Map(height=4.7*u"A", offset=0u"A"), - feedback = Feedback, - PI = PI | Map(T=0.005u"s", k=30, x = Var(init=0.0u"A")), - firstOrder = FirstOrder | Map(k=1u"V/A", T=0.001u"s", x = Var(init=0.0u"V")), - - signalVoltage = SignalVoltage, - resistor = Resistor | Map(R=13.8u"Ω"), - inductor = Inductor | Map(L=0.061u"H"), - emf = EMF | Map(k=1.016u"N*m/A"), - ground = Ground, - currentSensor = CurrentSensor, - - motorInertia = Inertia | Map(J=0.0025u"kg*m^2"), - idealGear = IdealGear | Map(ratio=105), - springDamper = SpringDamper | Map(c=5.0e5u"N*m/rad", d=500u"N*m*s/rad"), - loadInertia = Inertia | Map(J=100u"kg*m^2"), - tload = Torque, - - equations = :[ - tload.tau = 0.0u"N*m", - ], - - connect = :[ - (step.y, feedback.u1) - (feedback.y, PI.u) - (PI.y, firstOrder.u) - (firstOrder.y, signalVoltage.v) - - (signalVoltage.p, resistor.p) - (resistor.n, inductor.p) - (inductor.n, emf.p) - (emf.n, ground.p, currentSensor.p) - (currentSensor.n, signalVoltage.n) - (currentSensor.i, feedback.u2) - - (emf.flange, motorInertia.flange_a) - (motorInertia.flange_b, idealGear.flange_a) - (idealGear.flange_b, springDamper.flange_a) - (springDamper.flange_b, loadInertia.flange_a) - (tload.flange, loadInertia.flange_b) ] -) - -model = @instantiateModel(MotorControl1, log=false) -println("Simulate") -@time simulate!(model, stopTime=0.1, tolerance=1e-6, log=false, requiredFinalStates = - [3.487844601078223, 106.82874860310305, 4.616087152802267, 2.014120727821878, 41.98048886114646, 0.018332432934516536, 0.3725930536373392]) -plot(model, [("currentSensor.i", "step.y"), "loadInertia.w"], figure=1) - - -# Hierarchical model - -ControlledMotor = Model( - refCurrent = input, - feedback = Feedback, - PI = PI | Map(T=0.005u"s", k=30, x = Var(init=0.0u"A")), - firstOrder = FirstOrder | Map(k=1u"V/A", T=0.001u"s", x = Var(init=0.0u"V")), - - signalVoltage = SignalVoltage, - resistor = Resistor | Map(R=13.8u"Ω"), - inductor = Inductor | Map(L=0.061u"H"), - emf = EMF | Map(k=1.016u"N*m/A"), - ground = Ground, - currentSensor = CurrentSensor, - - motorInertia = Inertia | Map(J=0.0025u"kg*m^2"), - flange = Flange, - - connect = :[ - (refCurrent, feedback.u1) - (feedback.y, PI.u) - (PI.y, firstOrder.u) - (firstOrder.y, signalVoltage.v) - - (signalVoltage.p, resistor.p) - (resistor.n, inductor.p) - (inductor.n, emf.p) - (emf.n, ground.p, currentSensor.p) - (currentSensor.n, signalVoltage.n) - (currentSensor.i, feedback.u2) - - (emf.flange, motorInertia.flange_a) - (motorInertia.flange_b, flange) ] -) - -MotorControl2 = Model( - step = Step | Map(height=4.7*u"A", offset=0u"A"), - - controlledMotor = ControlledMotor, - - idealGear = IdealGear | Map(ratio=105), - springDamper = SpringDamper | Map(c=5.0e5u"N*m/rad", d=500u"N*m*s/rad"), - loadInertia = Inertia | Map(J=100.0u"kg*m^2"), - tload = Torque, - - equations = :[ - tload.tau = 0.0u"N*m", - ], - - connect = :[ - (step.y, controlledMotor.refCurrent) - - (controlledMotor.flange, idealGear.flange_a) - (idealGear.flange_b, springDamper.flange_a) - (springDamper.flange_b, loadInertia.flange_a) - (tload.flange, loadInertia.flange_b) ] -) - -model = @instantiateModel(MotorControl2) -println("Simulate") -@time simulate!(model, stopTime=0.1, tolerance=1e-6, log=false, requiredFinalStates = - [3.487844601078223, 106.82874860310305, 4.616087152802267, 2.014120727821878, 41.98048886114646, 0.018332432934516536, 0.3725930536373392]) -plot(model, [("controlledMotor.currentSensor.i", "step.y"), "loadInertia.w"], figure=1) - - -# Model with uncertainties - -MotorControlWithUncertainties = MotorControl2 | Map( loadInertia = Map(J=(100.0 ± 10)*u"kg*m^2"), controlledMotor = Map(PI = Map(k=30 ± 3) ) ) - -model = @instantiateModel(MotorControlWithUncertainties, FloatType = Measurement{Float64}) -println("Simulate") -@time simulate!(model, stopTime=0.1, tolerance=1e-6, log=false) -plot(model, [("controlledMotor.currentSensor.i", "step.y"), "loadInertia.w"], figure=1) - -end - -#= -module MotorControlModuleMonteCarlo - -using ModiaBase.TinyModia -using Unitful -using Main.MotorControlModule -include("../test/SimulateAndPlot.jl") - -using MonteCarloMeasurements - -# Model with Monte Carlo - -MotorControlWithUncertainties = MotorControl2 | Map( loadInertia = Map(J=(100.0 ∓ 10)), controlledMotor = Map(PI = Map(k=30 ∓ 3) ) ) - -model = @instantiateModel(MotorControlWithUncertainties, FloatType = StaticParticles{Float64,100}, unitless=true) -println("Simulate") -@time simulate!(model, stopTime=0.1, tolerance=1e-6, log=false) -plot(model, [("controlledMotor.currentSensor.i", "step.y"), "loadInertia.w"], figure=1) - -end -=# diff --git a/examples/Pendulum.jl b/examples/Pendulum.jl deleted file mode 100644 index 480ccef..0000000 --- a/examples/Pendulum.jl +++ /dev/null @@ -1,53 +0,0 @@ -module PendulumSimulation - -using TinyModia, Unitful -@usingModiaPlot -using DifferentialEquations -using Test - -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)] - ] -) - - -pendulum = @instantiateModel(Pendulum) -simulate!(pendulum, Tsit5(), stopTime = 10.0u"s", log=true) -plot(pendulum, [("phi", "w"); "r"]) - -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) - - -# Linearize -using DoubleFloats -using Measurements -println("\n... Numerically linearize at stopTime = 10 with Float64 and Double64:") -(A_10, x_10) = linearize!(pendulum2, stopTime=10) - -pendulum3 = SimulationModel{Measurement{Double64}}(pendulum2) -(A_10_Double64, x_10_Double64) = linearize!(pendulum3, stopTime=10) - -xNames = get_xNames(pendulum2) -@show xNames -println(IOContext(stdout, :error_digits=>15), "A_10 = ", A_10, ", x_10 = ", x_10) -println(IOContext(stdout, :error_digits=>15), "A_10_Double64 = ", A_10_Double64, ", x_10_Double64 = ", x_10_Double64) - -end \ No newline at end of file diff --git a/examples/Rectifier.jl b/examples/Rectifier.jl deleted file mode 100644 index a9ed9b2..0000000 --- a/examples/Rectifier.jl +++ /dev/null @@ -1,74 +0,0 @@ -module RectifierSimulation - -using TinyModia -using DifferentialEquations -@usingModiaPlot - -setLogMerge(false) - -include("../models/Electric.jl") - - -# Sinusoidal voltage source -SineVoltage = OnePort | Model( V = 1.0u"V", f = 1.0u"Hz", equations = :[ v = V*sin(2*3.14*f*time) ] ) - -# Ideal diode -IdealDiode = OnePort | Model( - Ron = 1e-5u"Ω", - Goff = 1e-5u"1/Ω", - s = Var(start = 0.0), - equations = :[ - closed = positive(s) # closed = s > 0 - v = s*u"V"*(if closed; Ron*u"1/Ω" else 1 end) - i = s*u"A"*(if closed; 1 else Goff*u"Ω" end) - ] - ) - - -Rectifier1 = Model( - R1 = Resistor | Map(R=1.0u"Ω"), - R2 = Resistor | Map(R=100.0u"Ω"), - C = Capacitor | Map(C=0.1u"F", v=Var(init=0.0u"V")), - D = IdealDiode, - V = SineVoltage | Map(V=5.0u"V", f=1.5u"Hz"), - ground = Ground, - connect = :[ - (V.p , R1.p) - (R1.n, D.p) - (D.n , R2.p, C.p) - (ground.p, R2.n, C.n, V.n) - ] -) - -rectifier1 = @instantiateModel(Rectifier1) -@time simulate!(rectifier1, Tsit5(), stopTime = 3, requiredFinalStates=[4.5665505086780565]) -plot(rectifier1, [("V.v", "D.v", "C.v"), "D.i"], figure=1) - - -Rectifier2 = Model( - V = SineVoltage | Map(V=220.0u"V", f=50.0u"Hz"), - R1 = Resistor | Map(R=20.0u"Ω"), - R2 = Resistor | Map(R=500.0u"Ω"), - C = Capacitor | Map(C=1e-4u"F", v=Var(init=0.0u"V")), - D1 = IdealDiode, - D2 = IdealDiode, - D3 = IdealDiode, - D4 = IdealDiode, - ground = Ground, - connect = :[ - (V.p , R1.p) - (R1.n, D1.p, D3.n) - (V.n , D2.p, D4.n, ground.p) - (D1.n, D2.n, R2.p, C.p) - (D3.p, D4.p, R2.n, C.n) - ] -) - -rectifier2 = @instantiateModel(Rectifier2, unitless=true) -@time simulate!(rectifier2, Tsit5(), stopTime = 0.1, log=true, requiredFinalStates=[183.9899542497182]) -plot(rectifier2, [("V.v", "C.v"), "V.i"], figure=2) - -@time simulate!(rectifier2, stopTime = 0.1, log=true) #, requiredFinalStates=[183.9899542497182]) -plot(rectifier2, [("V.v", "C.v"), "V.i"], figure=3) - -end \ No newline at end of file diff --git a/examples/Rectifier.mo b/examples/Rectifier.mo deleted file mode 100644 index fda1250..0000000 --- a/examples/Rectifier.mo +++ /dev/null @@ -1,118 +0,0 @@ -within ; -package Rectifier - model Rectifier1 - extends Modelica.Icons.Example; - - Modelica.Electrical.Analog.Sources.SineVoltage sineVoltage(V=5, freqHz=1.5) - annotation (Placement(transformation( - extent={{-10,10},{10,-10}}, - rotation=270, - origin={-50,30}))); - Modelica.Electrical.Analog.Basic.Resistor R1(R=1) - annotation (Placement(transformation(extent={{-32,40},{-12,60}}))); - Modelica.Electrical.Analog.Basic.Resistor R2(R=10) annotation (Placement( - transformation( - extent={{-10,-10},{10,10}}, - rotation=270, - origin={30,30}))); - Modelica.Electrical.Analog.Basic.Capacitor capacitor(C=0.1) annotation ( - Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=-90, - origin={52,30}))); - Modelica.Electrical.Analog.Basic.Ground ground - annotation (Placement(transformation(extent={{-60,-20},{-40,0}}))); - Modelica.Electrical.Analog.Ideal.IdealDiode diode - annotation (Placement(transformation(extent={{0,40},{20,60}}))); - equation - connect(sineVoltage.p, R1.p) - annotation (Line(points={{-50,40},{-50,50},{-32,50}}, color={0,0,255})); - connect(R2.n, sineVoltage.n) annotation (Line(points={{30,20},{30,6},{-50,6},{ - -50,20}}, color={0,0,255})); - connect(capacitor.n, sineVoltage.n) annotation (Line(points={{52,20},{52,6},{-50, - 6},{-50,20}}, color={0,0,255})); - connect(sineVoltage.n, ground.p) - annotation (Line(points={{-50,20},{-50,0}}, color={0,0,255})); - connect(R1.n, diode.p) - annotation (Line(points={{-12,50},{0,50}}, color={0,0,255})); - connect(diode.n, R2.p) - annotation (Line(points={{20,50},{30,50},{30,40}}, color={0,0,255})); - connect(diode.n, capacitor.p) - annotation (Line(points={{20,50},{52,50},{52,40}}, color={0,0,255})); - annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram( - coordinateSystem(preserveAspectRatio=false))); - end Rectifier1; - - model Rectifier2 - extends Modelica.Icons.Example; - - Modelica.Electrical.Analog.Sources.SineVoltage Vsource(V=220, freqHz=50) - annotation (Placement(transformation( - extent={{-10,10},{10,-10}}, - rotation=270, - origin={-80,30}))); - Modelica.Electrical.Analog.Basic.Resistor R1(R=20) - annotation (Placement(transformation(extent={{-62,30},{-42,50}}))); - Modelica.Electrical.Analog.Basic.Resistor R2(R=500) - annotation (Placement( - transformation( - extent={{-10,-10},{10,10}}, - rotation=270, - origin={30,42}))); - Modelica.Electrical.Analog.Basic.Capacitor C(C=1e-4) annotation (Placement( - transformation( - extent={{-10,-10},{10,10}}, - rotation=-90, - origin={52,40}))); - Modelica.Electrical.Analog.Basic.Ground ground - annotation (Placement(transformation(extent={{-90,-8},{-70,12}}))); - Modelica.Electrical.Analog.Ideal.IdealDiode D1 annotation (Placement( - transformation( - extent={{10,10},{-10,-10}}, - rotation=-90, - origin={-10,58}))); - Modelica.Electrical.Analog.Ideal.IdealDiode D3 annotation (Placement( - transformation( - extent={{10,10},{-10,-10}}, - rotation=-90, - origin={-10,0}))); - Modelica.Electrical.Analog.Ideal.IdealDiode D2 annotation (Placement( - transformation( - extent={{10,10},{-10,-10}}, - rotation=-90, - origin={10,58}))); - Modelica.Electrical.Analog.Ideal.IdealDiode D4 annotation (Placement( - transformation( - extent={{10,10},{-10,-10}}, - rotation=-90, - origin={10,0}))); - equation - connect(Vsource.p, R1.p) - annotation (Line(points={{-80,40},{-62,40}}, color={0,0,255})); - connect(Vsource.n, ground.p) - annotation (Line(points={{-80,20},{-80,12}}, color={0,0,255})); - connect(R1.n, D1.p) - annotation (Line(points={{-42,40},{-10,40},{-10,48}}, color={0,0,255})); - connect(D3.n, D1.p) - annotation (Line(points={{-10,10},{-10,48}}, color={0,0,255})); - connect(D1.n, D2.n) - annotation (Line(points={{-10,68},{10,68}}, color={0,0,255})); - connect(D4.n, D2.p) - annotation (Line(points={{10,10},{10,48}}, color={0,0,255})); - connect(Vsource.n, D2.p) - annotation (Line(points={{-80,20},{10,20},{10,48}}, color={0,0,255})); - connect(D3.p, D4.p) - annotation (Line(points={{-10,-10},{10,-10}}, color={0,0,255})); - connect(D2.n, R2.p) annotation (Line(points={{10,68},{40,68},{40,56},{30,56}, - {30,52}}, color={0,0,255})); - connect(R2.p, C.p) annotation (Line(points={{30,52},{30,56},{52,56},{52,50}}, - color={0,0,255})); - connect(D4.p, C.n) annotation (Line(points={{10,-10},{40,-10},{40,20},{52, - 20},{52,30}}, color={0,0,255})); - connect(R2.n, C.n) annotation (Line(points={{30,32},{30,20},{52,20},{52,30}}, - color={0,0,255})); - annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram( - coordinateSystem(preserveAspectRatio=false))); - end Rectifier2; - annotation (uses(Modelica(version="3.2.3"))); -end Rectifier; diff --git a/examples/ServoSystem.jl b/examples/ServoSystem.jl deleted file mode 100644 index 594acc1..0000000 --- a/examples/ServoSystem.jl +++ /dev/null @@ -1,147 +0,0 @@ -module ServoSystemSimulation - -println("\nServoSystem: Demonstrating the ability to simulate hierarchical mixed domain models") - -include("../models/Blocks.jl") -include("../models/Electric.jl") -include("../models/Rotational.jl") - -using TinyModia -using DifferentialEquations -@usingModiaPlot - - -setLogMerge(false) - -Gear = Model( - flange_a = Flange, - flange_b = Flange, - gear = IdealGear_withSupport | Map(ratio = 105.0), - fixed = Fixed, - spring = Spring | Map(c=5.84e5u"N*m/rad"), - damper1 = Damper | Map(d=500.0u"N*m*s/rad"), - damper2 = Damper | Map(d=100.0u"N*m*s/rad"), - - connect = :[ - (flange_a , gear.flange_a) - (fixed.flange , gear.support, damper2.flange_b) - (gear.flange_b, damper2.flange_a, spring.flange_a, damper1.flange_a) - (flange_b , spring.flange_b, damper1.flange_b)] -) - - -ControlledMotor = Model( - refCurrent = input, - flange = Flange, - feedback = Feedback, - PI = PI | Map(k=30, T=1.0u"s"), - firstOrder = FirstOrder | Map(k=1.0, T=0.001u"s"), - signalVoltage = UnitlessSignalVoltage, - resistor = Resistor | Map(R=13.8u"Ω"), - inductor = Inductor | Map(L=0.061u"H"), - emf = EMF | Map(k=1.016u"N*m/A"), - ground = Ground, - currentSensor = UnitlessCurrentSensor, - motorInertia = Inertia | Map(J=0.0025u"kg*m^2"), - - connect = :[ - (refCurrent, feedback.u1) - (feedback.y, PI.u) - (PI.y, firstOrder.u) - (firstOrder.y, signalVoltage.v) - - (signalVoltage.p, resistor.p) - (resistor.n, inductor.p) - (inductor.n, emf.p) - (emf.n, ground.p, currentSensor.p) - (currentSensor.n, signalVoltage.n) - (currentSensor.i, feedback.u2) - - (emf.flange, motorInertia.flange_a) - (motorInertia.flange_b, flange) ] -) - - -SpeedController = Model( - refSpeed = input, - motorSpeed = input, - refCurrent = output, - gain = Gain | Map(k=105.0), - PI = PI | Map(T=1.0u"s", k=1.0), - feedback = Feedback, - - connect = :[ - (refSpeed , gain.u) - (gain.y , feedback.u1) - (motorSpeed, feedback.u2) - (feedback.y, PI.u) - (PI.y , refCurrent)] -) - - -Servo = Model( - refSpeed = input, - flange_b = Flange, - speedController = SpeedController | Map(ks=1.0, Ts=1.0u"s", ratio=105.0), - motor = ControlledMotor | Map(km=30.0, Tm=0.005u"s"), - gear = Gear | Map(ratio=105.0), - speedSensor1 = UnitlessSpeedSensor, - speedSensor2 = UnitlessSpeedSensor, - speedError = Feedback, - - connect = :[ - (refSpeed , speedController.refSpeed, speedError.u1) - (speedController.refCurrent, motor.refCurrent) - (motor.flange , gear.flange_a, speedSensor1.flange) - (speedSensor1.w , speedController.motorSpeed) - (gear.flange_b , flange_b, speedSensor2.flange) - (speedSensor2.w , speedError.u2)] -) - - -TestServo = Model( - ks = 0.8, - Ts = 0.08u"s", - ramp = Ramp | Map(duration=1.18u"s", height=2.95), - servo = Servo | Map(ks=:(up.ks), Ts=:(up.Ts)), - load = Inertia | Map(J=170u"kg*m^2"), - equations =:[load.flange_b.tau = 0u"N*m"], - connect = :[ - (ramp.y , servo.refSpeed) - (servo.flange_b, load.flange_a) ] -) - -plotVariables = [("ramp.y", "load.w") "servo.speedError.y"; - "servo.gear.spring.phi_rel" "servo.motor.currentSensor.i"] - -testServo1 = @instantiateModel(TestServo) -println("Simulate") -@time simulate!(testServo1, Tsit5(), stopTime=2.0, tolerance=1e-6, requiredFinalStates = - [7.320842067204029, 9.346410309487013, 355.30389168655955, 2.792544498835712, 429.42665751348284, 311.7812493890421, 4.089776248793499, 2.969353608933471]) -plot(testServo1, plotVariables, figure=1) - - -println("\nServo with uncertainties") -using Measurements -TestServoWithUncertainties = TestServo | Map( - load = Map(J=(110.0 ± 20)u"kg*m^2"), - servo = Map(motor = Map(resistor = Map(R=(13.8±1.0)u"Ω")))) -testServo2 = @instantiateModel(TestServoWithUncertainties , FloatType = Measurement{Float64}) -@time simulate!(testServo2, Tsit5(), stopTime=2.0, tolerance=1e-6) -plot(testServo2, plotVariables, figure=2) - -println("\nServo with Monte Carlo simulation") -import MonteCarloMeasurements -using Distributions -const nparticles = 100 -uniform(vmin,vmax) = MonteCarloMeasurements.StaticParticles(nparticles,Distributions.Uniform(vmin,vmax)) - -TestServoWithMonteCarlo = TestServo | Map( - load = Map(J = uniform(50,170)), - servo = Map(motor = Map(resistor = Map(R = uniform(12.8,14.8))))) -testServo3 = @instantiateModel(TestServoWithMonteCarlo, FloatType = MonteCarloMeasurements.StaticParticles{Float64,nparticles}, unitless=true) -@time simulate!(testServo3, Tsit5(), stopTime=2.0, tolerance=1e-6) -plot(testServo3, plotVariables, figure=3) - - -end diff --git a/examples/ServoSystem.mo b/examples/ServoSystem.mo deleted file mode 100644 index 5f3f934..0000000 --- a/examples/ServoSystem.mo +++ /dev/null @@ -1,388 +0,0 @@ -within ; -package ServoSystem - "Servo system consisting of current and speed controlled DC motor + gear with elasticity and damping + load" - - model Gear "Gear with elasticity and damping" - parameter Real ratio=105 "Getriebe-Uebersetzung"; - Modelica.Mechanics.Rotational.Components.IdealGear gear( - ratio=ratio, useSupport=true) - annotation (Placement(transformation(extent={{-60,-10},{-40,10}}, - rotation=0))); - Modelica.Mechanics.Rotational.Interfaces.Flange_a flange_a - annotation (Placement(transformation(extent={{-110,-10},{-90,10}}, - rotation=0))); - Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b - annotation (Placement(transformation(extent={{90,-10},{110,10}}, rotation= - 0))); - Modelica.Mechanics.Rotational.Components.Spring - spring(c=5.84e5) - annotation (Placement(transformation(extent= - {{20,10},{40,30}}, rotation=0))); - Modelica.Mechanics.Rotational.Components.Damper damper1( - d=500) - annotation (Placement(transformation(extent={{20,-30},{40,-10}}, rotation= - 0))); - Modelica.Mechanics.Rotational.Components.Fixed fixed - annotation (Placement(transformation(extent={{-60,-49},{-40,-29}}, - rotation=0))); - Modelica.Mechanics.Rotational.Components.Damper damper2( - d=100) - annotation (Placement(transformation( - origin={-30,-20}, - extent={{-10,-10},{10,10}}, - rotation=270))); - equation - connect(gear.flange_a, flange_a) - annotation (Line(points={{-60,0},{-100,0}}, color={0,0,0})); - connect(gear.flange_b, spring.flange_a) - annotation (Line(points={{-40,0},{0,0},{0,20},{20,20}}, color={0,0,0})); - connect(gear.flange_b, damper1.flange_a) - annotation (Line(points={{-40,0},{0,0},{0,-20},{20,-20}}, color={0,0,0})); - connect(spring.flange_b, flange_b) annotation (Line(points={{40,20},{60,20}, - {60,0},{100,0}}, color={0,0,0})); - connect(damper1.flange_b, flange_b) - annotation (Line(points={{40,-20},{60,-20},{60,0},{100,0}}, color={0,0,0})); - connect(fixed.flange, damper2.flange_b) - annotation (Line(points={{-50,-39},{-50,-30},{-30,-30}}, color={0,0,0})); - connect(gear.support,fixed.flange) - annotation (Line(points={{-50,-10},{-50,-39}}, color={0,0,0})); - connect(damper2.flange_a, gear.flange_b) annotation (Line(points={{-30,-10},{ - -30,0},{-40,0}},color={0,0,0})); - annotation ( - Icon(coordinateSystem( - preserveAspectRatio=false, - extent={{-100,-100},{100,100}}, - grid={1,1}), graphics={ - Rectangle( - extent={{-100,10},{-60,-10}}, - lineColor={0,0,0}, - fillPattern=FillPattern.HorizontalCylinder, - fillColor={192,192,192}), - Rectangle( - extent={{60,10},{100,-10}}, - lineColor={0,0,0}, - fillPattern=FillPattern.HorizontalCylinder, - fillColor={192,192,192}), - Rectangle( - extent={{-40,60},{40,-60}}, - lineColor={0,0,0}, - pattern=LinePattern.Solid, - lineThickness=0.25, - fillPattern=FillPattern.HorizontalCylinder, - fillColor={192,192,192}), - Polygon( - points={{-60,10},{-60,20},{-40,40},{-40,-40},{-60,-20},{-60,10}}, - lineColor={0,0,0}, - fillPattern=FillPattern.HorizontalCylinder, - fillColor={128,128,128}), - Polygon( - points={{60,20},{40,40},{40,-40},{60,-20},{60,20}}, - lineColor={128,128,128}, - fillColor={128,128,128}, - fillPattern=FillPattern.Solid), - Polygon( - points={{-60,-90},{-50,-90},{-20,-30},{20,-30},{48,-90},{60,-90},{60, - -100},{-60,-100},{-60,-90}}, - lineColor={0,0,0}, - fillColor={0,0,0}, - fillPattern=FillPattern.Solid), - Text( - extent={{-150,110},{150,70}}, - textString="%name", - lineColor={0,0,255}, - fontSize=0), - Text( - extent={{-150,-110},{150,-150}}, - lineColor={0,0,0}, - textString="ratio=%ratio")}), - Diagram(coordinateSystem( - preserveAspectRatio=false, - extent={{-100,-100},{100,100}}, - grid={1,1}), graphics), - conversion(noneFromVersion="")); - end Gear; - - model ControlledMotor "Current controlled DC motor" - extends Modelica.Electrical.Machines.Icons.Machine; - - parameter Real km=30 "Gain"; - parameter Modelica.SIunits.Time Tm=0.005 "Time Constant (T>0 required)"; - - Modelica.Blocks.Continuous.PI PI(k=km, T=Tm) - annotation (Placement(transformation(extent={{-52,60},{-32,80}}, - rotation=0))); - - Modelica.Mechanics.Rotational.Interfaces.Flange_b flange - annotation (Placement(transformation(extent={{90,-10},{110,10}}, rotation= - 0))); - Modelica.Blocks.Interfaces.RealInput refCurrent - "Reference current of motor" - annotation (Placement(transformation(extent={{-140,-20},{-100,20}}, - rotation=0))); - Modelica.Blocks.Math.Feedback feedback - annotation (Placement(transformation(extent={{-90,-10},{-70,10}}, - rotation=0))); - Modelica.Blocks.Continuous.FirstOrder firstOrder(T=0.001, initType=Modelica.Blocks.Types.Init.InitialState) - annotation (Placement(transformation(extent={{-18,60},{2,80}}, rotation= - 0))); - Modelica.Electrical.Analog.Basic.Resistor resistor(R=13.8) - annotation (Placement(transformation(extent={{-10,20},{10,40}}, rotation=0))); - Modelica.Electrical.Analog.Basic.Inductor inductor(L=0.061, i(start=0, - fixed=true)) - annotation (Placement(transformation(extent={{20,20},{40,40}},rotation=0))); - Modelica.Electrical.Analog.Basic.Ground ground - annotation (Placement(transformation(extent={{40,-50},{60,-30}}, rotation=0))); - Modelica.Electrical.Analog.Sources.SignalVoltage signalVoltage - annotation (Placement(transformation( - origin={-20,0}, - extent={{-10,10},{10,-10}}, - rotation=270))); - Modelica.Electrical.Analog.Basic.EMF emf(k=1.016) - annotation (Placement(transformation( - extent={{40,-10},{60,10}}, - rotation=0))); - Modelica.Mechanics.Rotational.Components.Inertia motorInertia(J=0.0025) - annotation (Placement(transformation(extent={{66,-10},{86,10}}, - rotation=0))); - Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensor - annotation (Placement(transformation(extent={{18,-40},{-2,-20}}, rotation= - 0))); - equation - - connect(feedback.u1, refCurrent) - annotation (Line(points={{-88,0},{-120,0}}, color={0,0,127})); - connect(feedback.y, PI.u) - annotation (Line(points={{-71,0},{-66,0},{-66,70},{-54,70}}, - color={0,0,127})); - connect(PI.y, firstOrder.u) - annotation (Line(points={{-31,70},{-20,70}}, - color={0,0,127})); - connect(signalVoltage.p,resistor. p) annotation (Line(points={{-20,10},{-20, - 30},{-10,30}}, color={0,0,255})); - connect(resistor.n,inductor. p) - annotation (Line(points={{10,30},{20,30}}, color={0,0,255})); - connect(inductor.n,emf. p) annotation (Line(points={{40,30},{50,30},{50,10}}, - color={0,0,255})); - connect(emf.n,ground. p) - annotation (Line(points={{50,-10},{50,-30}}, - color={0,0,255})); - connect(motorInertia.flange_a,emf.flange) - annotation (Line(points={{66,0},{60,0}}, color={0,0,0})); - connect(currentSensor.n,signalVoltage. n) annotation (Line(points={{-2,-30}, - {-20,-30},{-20,-10}}, color={0,0,255})); - connect(currentSensor.p,ground. p) - annotation (Line(points={{18,-30},{50,-30}}, color={0,0,255})); - connect(firstOrder.y, signalVoltage.v) annotation (Line(points={{3,70},{28,70}, - {28,46},{-50,46},{-50,0},{-32,0}}, color={0,0,127})); - connect(currentSensor.i, feedback.u2) annotation (Line(points={{8,-41},{8,-52}, - {-80,-52},{-80,-8}}, color={0,0,127})); - connect(motorInertia.flange_b, flange) - annotation (Line(points={{86,0},{100,0}}, color={0,0,0})); - annotation ( Icon(coordinateSystem(preserveAspectRatio=false, - extent={{-100,-100},{100,100}}), graphics={ - Text( - extent={{-150,120},{150,80}}, - lineColor={0,0,255}, - textString="%name"), - Rectangle( - extent={{-100,10},{-60,-10}}, - fillPattern=FillPattern.HorizontalCylinder, - fillColor={95,95,95})})); - end ControlledMotor; - - model SpeedController "PI Geschwindigkeits-Regler" - import SI = Modelica.SIunits; - parameter Real ks "Verstaerkung vom PI Geschwindigkeitsregler"; - parameter SI.Time Ts "Zeitkonstante vom PI Geschwindigkeitsregler"; - parameter Real ratio=105 "Getriebe-Uebersetzung"; - - Modelica.Blocks.Interfaces.RealInput refSpeed "Reference speed of load" - annotation ( Placement( - transformation(extent={{-140,-20},{-100,20}}, rotation=0))); - Modelica.Blocks.Interfaces.RealOutput refCurrent "Reference current of motor" - annotation (Placement( - transformation(extent={{100,-10},{120,10}}, rotation=0))); - Modelica.Blocks.Interfaces.RealInput motorSpeed "Actual speed of motor" - annotation ( - Placement(transformation( - origin={0,-120}, - extent={{-20,-20},{20,20}}, - rotation=90))); - Modelica.Blocks.Math.Feedback feedback - annotation (Placement(transformation(extent={{-10,-10},{10,10}}, rotation= - 0))); - Modelica.Blocks.Math.Gain gain(k=ratio) - annotation (Placement(transformation(extent={{-50,-10},{-30,10}}, - rotation=0))); - Modelica.Blocks.Continuous.PI PI(T=Ts, k=ks) - annotation (Placement(transformation(extent={{30,-10},{50,10}}, rotation= - 0))); - equation - connect(gain.y,feedback.u1) annotation (Line(points={{-29,0},{ - -8,0}}, color={0,0,127})); - connect(feedback.y,PI.u) annotation (Line(points={{9,0},{28,0}}, - color={0,0,127})); - connect(PI.y, refCurrent) annotation (Line(points={{51,0},{110,0}}, - color={0,0,127})); - connect(gain.u, refSpeed) - annotation (Line(points={{-52,0},{-120,0}}, color={0,0,127})); - connect(feedback.u2, motorSpeed) - annotation (Line(points={{0,-8},{0,-120}}, color={0,0,127})); - annotation ( - Diagram(coordinateSystem( - preserveAspectRatio=false, - extent={{-100,-100},{100,100}}, - grid={2,2}), graphics), - Icon(coordinateSystem( - preserveAspectRatio=false, - extent={{-100,-100},{100,100}}, - grid={2,2}), graphics={ - Rectangle( - extent={{-100,-100},{100,100}}, - lineColor={0,0,0}, - pattern=LinePattern.Solid, - lineThickness=0.25, - fillColor={235,235,235}, - fillPattern=FillPattern.Solid), - Rectangle( - extent={{-30,54},{30,24}}, - lineColor={0,0,255}, - fillColor={255,255,255}, - fillPattern=FillPattern.Solid), - Polygon( - points={{-30,40},{-60,50},{-60,30},{-30,40}}, - lineColor={0,0,255}, - fillColor={0,0,255}, - fillPattern=FillPattern.Solid), - Line(points={{-31,-41},{-78,-41},{-78,39},{-30,39}}), - Rectangle( - extent={{-30,-26},{30,-56}}, - lineColor={0,0,255}, - fillColor={255,255,255}, - fillPattern=FillPattern.Solid), - Polygon( - points={{60,-32},{30,-42},{60,-52},{60,-32}}, - lineColor={0,0,255}, - fillColor={0,0,255}, - fillPattern=FillPattern.Solid), - Line(points={{30,39},{76,39},{76,-41},{30,-41}}), - Text( - extent={{-150,150},{150,110}}, - textString="%name", - lineColor={0,0,255}, - fontSize=0)}), - conversion(noneFromVersion="")); - end SpeedController; - - model Servo "Drehzahlgeregelter Motor mit Getriebe" - extends Modelica.Electrical.Machines.Icons.TransientMachine; - Modelica.Blocks.Interfaces.RealInput refSpeed "Reference speed of load" annotation (Placement( - transformation(extent={{-140,-20},{-100,20}}, rotation=0))); - Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b annotation (Placement( - transformation(extent={{90,-10},{110,10}}, rotation=0))); - - parameter Real ks "Verstaerkung vom PI Geschwindigkeitsregler"; - parameter Modelica.SIunits.Time Ts "Zeitkonstante vom PI Geschwindigkeitsregler"; - - parameter Real km=30 "Verstaerkung vom PI Motorregler"; - parameter Modelica.SIunits.Time Tm=0.005 "Zeitkonstante vom PI Motorregler"; - parameter Real ratio=105 "Getriebeuebersetzung"; - - ServoSystem.ControlledMotor motor(km=km, Tm=Tm) annotation (Placement( - transformation(extent={{-20,-10},{0,10}}, rotation=0))); - SpeedController speedController( - ks=ks, - Ts=Ts, - ratio=ratio) annotation (Placement(transformation(extent={{-70,-10},{-50,10}}, - rotation=0))); - Gear gear(ratio=ratio) annotation (Placement(transformation(extent={{30,-10}, - {50,10}}, rotation=0))); - - Modelica.Blocks.Math.Feedback speedError - annotation (Placement(transformation(extent={{-40,40},{-20,60}}, rotation= - 0))); - Modelica.Mechanics.Rotational.Sensors.SpeedSensor speedSensor2 - annotation (Placement(transformation( - origin={70,20}, - extent={{-10,-10},{10,10}}, - rotation=90))); - Modelica.Mechanics.Rotational.Sensors.SpeedSensor speedSensor1 - annotation (Placement(transformation( - origin={10,-20}, - extent={{-10,-10},{10,10}}, - rotation=270))); - equation - connect(speedSensor2.w, speedError.u2) - annotation (Line(points={{70,31},{70,34},{-30,34},{-30,42}}, color={0,0, - 127})); - connect(refSpeed, speedController.refSpeed) - annotation (Line(points={{-120,0},{-72,0}}, color={0,0,127})); - connect(speedController.refCurrent, motor.refCurrent) - annotation (Line(points={{-49,0},{-22,0}}, color={0,0,127})); - connect(speedError.u1, refSpeed) - annotation (Line(points={{-38,50},{-90,50},{-90,0},{-120,0}}, color={0,0, - 127})); - connect(motor.flange,speedSensor1.flange) annotation (Line(points={{0,0}, - {10,0},{10,-10}}, color={0,0,0})); - connect(speedSensor1.w, speedController.motorSpeed) annotation (Line(points= - {{10,-31},{10,-40},{-60,-40},{-60,-12}}, color={0,0,127})); - connect(motor.flange, gear.flange_a) - annotation (Line(points={{0,0},{30,0}}, color={0,0,0})); - connect(gear.flange_b, flange_b) - annotation (Line(points={{50,0},{100,0}}, color={0,0,0})); - connect(gear.flange_b, speedSensor2.flange) - annotation (Line(points={{50,0},{70,0},{70,10}}, color={0,0,0})); - annotation ( - Icon(coordinateSystem( - preserveAspectRatio=false, - extent={{-100,-100},{100,100}}, - grid={1,1}), graphics={ - Text( - extent={{-150,120},{150,80}}, - textString="%name", - lineColor={0,0,255}), - Text( - extent={{-150,-110},{150,-150}}, - lineColor={0,0,0}, - textString="ks=%ks, Ts=%Ts"), - Rectangle( - extent={{-100,10},{-60,-10}}, - fillPattern=FillPattern.HorizontalCylinder, - fillColor={95,95,95})}), - Diagram(coordinateSystem( - preserveAspectRatio=false, - extent={{-100,-100},{100,100}}, - grid={1,1}), graphics)); - end Servo; - -model Test "Test to tune speed controller" - import SI = Modelica.SIunits; - extends Modelica.Icons.Example; - parameter Real ks = 0.8 "Verstaerkung vom PI Geschwindigkeitsregler"; - parameter SI.Time Ts= 0.08 "Zeitkonstante vom PI Geschwindigkeitsregler"; - Servo servo(ks=ks, Ts=Ts) annotation (Placement(transformation(extent={{-20, - 0},{0,20}}, rotation=0))); - - Modelica.Mechanics.Rotational.Components.Inertia load(J=170) - "J=50..170 kgm^2" annotation (Placement(transformation(extent={{20,0},{40, - 20}}, rotation=0))); - Modelica.Blocks.Sources.Ramp ramp(duration=1.18, height=2.95) - annotation (Placement(transformation(extent={{-60,0},{-40,20}}, rotation= - 0))); -equation - connect(ramp.y, servo.refSpeed) - annotation (Line(points={{-39,10},{-22,10}}, color={0,0,127})); - connect(servo.flange_b, load.flange_a) - annotation (Line(points={{0,10},{20,10}}, color={0,0,0})); - annotation ( - Diagram(coordinateSystem( - preserveAspectRatio=false, - extent={{-100,-100},{100,100}}, - grid={2,2}), graphics), - experiment(StopTime=2), - __Dymola_Commands(file="Scripts/plot load.w, speedError1.mos" - "plot load.w, speedError", file="Scripts/plot current1.mos" - "plot current")); -end Test; - annotation (uses(Modelica(version="3.2.3"))); -end ServoSystem; diff --git a/examples/ServoSystem.pptx b/examples/ServoSystem.pptx deleted file mode 100644 index 401d13b..0000000 Binary files a/examples/ServoSystem.pptx and /dev/null differ diff --git a/examples/SimpleFilters.jl b/examples/SimpleFilters.jl deleted file mode 100644 index 912ef66..0000000 --- a/examples/SimpleFilters.jl +++ /dev/null @@ -1,90 +0,0 @@ -module SimpleFilters - -using TinyModia -using DifferentialEquations -@usingModiaPlot - -SimpleModel = Model( - T = 0.2, - x = Var(init=0.5), - equation = :[T * der(x) + x = 2] -) - -# @showModel(SimpleModel) - -model = @instantiateModel(SimpleModel) -simulate!(model, Tsit5(), stopTime = 5, requiredFinalStates = [1.9999996962023168]) -plot(model, ["x"]) - -LowPassFilter = Model( - T = 0.2, - u = input, - y = output | Var(:x), - x = Var(init=0.0u"V"), - equations = :[T * der(x) + x = u], -) - -# @showModel(LowPassFilter) - -HighPassFilter = LowPassFilter | Model( - y = Var(:(-x + u)), - ) - -# @showModel(HighPassFilter) - -# setLogMerge(true) - -LowAndHighPassFilter = LowPassFilter | Model( - y = nothing, - low = output | Var(:x), - high = output | Var(:(-x + u)), -) - -setLogMerge(false) - -# @showModel(LowAndHighPassFilter) - -TestLowAndHighPassFilter = LowAndHighPassFilter | Model( - u = :(sin( (time+1u"s")*u"1/s/s" * time)*u"V"), - x = Var(init=0.2u"V") -) - -# @showModel(TestLowAndHighPassFilter) - -model = @instantiateModel(TestLowAndHighPassFilter, log=false, logCode=false) -simulate!(model, Tsit5(), stopTime = 5, requiredFinalStates = [-0.22633046061014014]) -plot(model, ["low", "high"]) - -TwoFilters = Model( - high = HighPassFilter, - low = LowPassFilter, -) - -# @showModel(TwoFilters) - -BandPassFilter = Model( - u = input, - y = output, - high = HighPassFilter | Map(T=0.5, x=Var(init=0.1u"V")), - low = LowPassFilter | Map(x=Var(init=0.2u"V")), - equations = :[ - high.u = u, - low.u = high.y, - y = low.y] -) - -# @showModel(BandPassFilter) - -TestBandPassFilter = BandPassFilter | Model( - u = :(sin( (0.05*time+1u"s")*u"1/s/s" * time)*u"V"), -) - -# @showModel(TestBandPassFilter) - -setLogMerge(false) - -model = @instantiateModel(TestBandPassFilter, logDetails=false) -simulate!(model, Tsit5(), stopTime = 50, requiredFinalStates = [-0.25968254453053435, -0.6065869606784539]) -plot(model, ["u", "y"]) - -end \ No newline at end of file diff --git a/examples/Tutorial.jl b/examples/Tutorial.jl deleted file mode 100644 index dd5fe2f..0000000 --- a/examples/Tutorial.jl +++ /dev/null @@ -1,106 +0,0 @@ -module Tutorial - -# 1 Getting started - -using TinyModia -using DifferentialEquations -using Unitful -@usingModiaPlot - -# Define model -SimpleModel = Model( - T = 0.4, - x = Var(init=0.2), - equation = :[T * der(x) + x = 1], -) - -# Transform to ODE form -simpleModel = @instantiateModel(SimpleModel) - -# Simulate with a default integrator of DifferentialEquations -simulate!(simpleModel, stopTime = 1.2) - -# Simulate with a specific integrator (Tsit5) and use a unit for stopTime -simulate!(simpleModel, Tsit5(), stopTime = 1.2u"s") - -# Produce a line plot with GLMakie -plot(simpleModel, ("x", "der(x)"), figure=1) - - - -# 2.1 - Equation oriented models - -using TinyModia - -LowPassFilter = Model( - T = 0.2, - u = input, - y = output | Var(:x), - x = Var(init=0), - equation = :[T * der(x) + x = u], -) - - - -# 2.2 Merging models - -HighPassFilter = LowPassFilter | Model( y = :(-x + u) ) - -setLogMerge(true) - -LowAndHighPassFilter = LowPassFilter | Model( - y = nothing, - low = output | Var(:x), - high = output | Var(:(-x + u)), - ) - -setLogMerge(false) - -@showModel LowAndHighPassFilter - - - -# 2.3 Functions and tables - -TestLowAndHighPassFilter = LowAndHighPassFilter | Model( - u = :(sin( (time+1u"s")*u"1/s/s" * time)*u"V"), - x = Var(init=0.2u"V") - ) - - -using Interpolations - -table = CubicSplineInterpolation(0:0.5:2.0, [0.0, 0.7, 2.0, 1.8, 1.2]) -TestLowAndHighPassFilter2 = TestLowAndHighPassFilter | Map(u = :(table(time*u"1/s")*u"V")) - - - -# 2.4 Hierarchical modeling - -TwoFilters = ( - high = HighPassFilter, - low = LowPassFilter, -) - -BandPassFilter = ( - u = input, - y = output, - high = HighPassFilter | Map(T=0.5, x=Var(init=0.1u"V")), - low = LowPassFilter | Map(x=Var(init=0.2u"V")), - equations = :[ - high.u = u, - low.u = high.y, - y = low.y] -) - -TestBandPassFilter = BandPassFilter | Map( - u = :(sin( (time+1u"s")*u"1/s/s" * time)*u"V") - ) - -#bandPassFilter = @instantiateModel(TestBandPassFilter, logStateSelection=true) -#simulate!(bandPassFilter, Tsit5(), stopTime = 50u"s") -#plot(bandPassFilter, ["u", "y"], figure=2) - - - -end \ No newline at end of file diff --git a/examples/runexamples.jl b/examples/runexamples.jl deleted file mode 100644 index d65a069..0000000 --- a/examples/runexamples.jl +++ /dev/null @@ -1,13 +0,0 @@ -using Test - -@testset "TinyModia examples with simulation" begin - -include("SimpleFilters.jl") -include("FilterCircuit.jl") -include("CauerLowPassFilter.jl") -include("Rectifier.jl") -include("MotorControl.jl") -include("Pendulum.jl") -include("ServoSystem.jl") - -end diff --git a/models/Blocks.jl b/models/Blocks.jl index da86c8c..2d833a3 100644 --- a/models/Blocks.jl +++ b/models/Blocks.jl @@ -8,7 +8,7 @@ Modia module with block component models (inspired from Modelica Standard Librar """ #module Blocks -using TinyModia +using ModiaLang using Unitful #export Gain, FirstOrder, Feedback, PI, Step, Ramp # Sine, Switch, MIMO diff --git a/models/Electric.jl b/models/Electric.jl index 84d9879..b6c2134 100644 --- a/models/Electric.jl +++ b/models/Electric.jl @@ -8,7 +8,7 @@ Modia module with electric component models (inspired from Modelica Standard Lib """ #module Electric -using TinyModia +using ModiaLang using Unitful Pin = Model( v = potential, i = flow ) diff --git a/models/ElectricTest.jl b/models/ElectricTest.jl index 3d9fef9..65f93d7 100644 --- a/models/ElectricTest.jl +++ b/models/ElectricTest.jl @@ -8,7 +8,7 @@ Modia module with electric component models (inspired from Modelica Standard Lib """ #module Electric -using TinyModia +using ModiaLang using Unitful Var(args...; kwargs...) = (;args..., kwargs...) diff --git a/models/HeatTransfer.jl b/models/HeatTransfer.jl index 7f9e4b7..dceadfb 100644 --- a/models/HeatTransfer.jl +++ b/models/HeatTransfer.jl @@ -6,7 +6,7 @@ Copyright 2021, DLR Institute of System Dynamics and Control License: MIT (expat) =# -using TinyModia +using ModiaLang using Unitful HeatPort = Model( T = potential, # Absolute temperature diff --git a/models/Rotational.jl b/models/Rotational.jl index 0b6c9e9..84d005b 100644 --- a/models/Rotational.jl +++ b/models/Rotational.jl @@ -10,7 +10,7 @@ Modia module with rotational component models (inspired from Modelica Standard L #export Flange, Inertia, Spring, SpringDamper, EMF, IdealGear, Torque, CurrentSensor, Fixed, Damper, IdealGear_withSupport, SpeedSensor -using TinyModia +using ModiaLang using Unitful # Connector for 1D rotational systems diff --git a/models/Translational.jl b/models/Translational.jl index 8a6956a..adfda97 100644 --- a/models/Translational.jl +++ b/models/Translational.jl @@ -10,7 +10,7 @@ Modia module with translational component models (inspired from Modelica Standar #export Flange, Inertia, Spring, SpringDamper, EMF, IdealGear, Torque, CurrentSensor, Fixed, Damper, IdealGear_withSupport, SpeedSensor -using TinyModia +using ModiaLang using Unitful # Connector for 1D translational systems diff --git a/src/CodeGeneration.jl b/src/CodeGeneration.jl index 86cad75..63ae668 100644 --- a/src/CodeGeneration.jl +++ b/src/CodeGeneration.jl @@ -94,7 +94,7 @@ function get_x_start!(FloatType, equationInfo, parameters) printstyled("Model error: ", bold=true, color=:red) printstyled("Length of ", xe_info.x_name, " shall be changed from ", xe_info.length, " to $len\n", - "This is currently not support in TinyModia.", bold=true, color=:red) + "This is currently not support in ModiaLang.", bold=true, color=:red) return false end startIndex += xe_info.length @@ -262,7 +262,7 @@ end that is evaluation of expressions in the environment of the user. - `modelName::String`: Name of the model - `getDerivatives::Function`: Function that is used to evaluate the model equations, - typically generated with [`TinyModia.generate_getDerivatives!`]. + typically generated with [`ModiaLang.generate_getDerivatives!`]. - `equationInfo::ModiaBase.EquationInfo`: Information about the states and the equations. - `x_startValues`:: Deprecated (is no longer used). - `parameters`: A hierarchical NamedTuple of (key, value) pairs defining the parameter and init/start values. @@ -475,11 +475,11 @@ SimulationModel{MonteCarloMeasurements.StaticParticles{T,N},ParType}(args...; kw timeType(m::SimulationModel{FloatType,ParType,EvaluatedParType,TimeType}) where {FloatType,ParType,EvaluatedParType,TimeType} = TimeType -positive(m::SimulationModel, args...; kwargs...) = TinyModia.positive!(m.eventHandler, args...; kwargs...) -negative(m::SimulationModel, args...; kwargs...) = TinyModia.negative!(m.eventHandler, args...; kwargs...) -change( m::SimulationModel, args...; kwargs...) = TinyModia.change!( m.eventHandler, args...; kwargs...) -edge( m::SimulationModel, args...; kwargs...) = TinyModia.edge!( m.eventHandler, args...; kwargs...) -after( m::SimulationModel, args...; kwargs...) = TinyModia.after!( m.eventHandler, args...; kwargs...) +positive(m::SimulationModel, args...; kwargs...) = ModiaLang.positive!(m.eventHandler, args...; kwargs...) +negative(m::SimulationModel, args...; kwargs...) = ModiaLang.negative!(m.eventHandler, args...; kwargs...) +change( m::SimulationModel, args...; kwargs...) = ModiaLang.change!( m.eventHandler, args...; kwargs...) +edge( m::SimulationModel, args...; kwargs...) = ModiaLang.edge!( m.eventHandler, args...; kwargs...) +after( m::SimulationModel, args...; kwargs...) = ModiaLang.after!( m.eventHandler, args...; kwargs...) pre( m::SimulationModel, i) = m.pre[i] @@ -1398,7 +1398,7 @@ function generate_getDerivatives!(AST::Vector{Expr}, equationInfo::ModiaBase.Equ push!(code_x, :( $x_name = _x[$indexRange]*@u_str($x_unit)) ) end if hasUnits - push!(code_der_x, :( _der_x[$indexRange] = TinyModia.stripUnit( $der_x_name )) ) + push!(code_der_x, :( _der_x[$indexRange] = ModiaLang.stripUnit( $der_x_name )) ) else push!(code_der_x, :( _der_x[$indexRange] = $der_x_name )) end @@ -1424,7 +1424,7 @@ function generate_getDerivatives!(AST::Vector{Expr}, equationInfo::ModiaBase.Equ push!(code_previous2, :( _m.nextPrevious[$i] = $previousName )) end code_previous3 = quote - if TinyModia.isFirstEventIteration(_m) && !TinyModia.isInitial(_m) + if ModiaLang.isFirstEventIteration(_m) && !ModiaLang.isInitial(_m) $(code_previous2...) end end @@ -1441,7 +1441,7 @@ function generate_getDerivatives!(AST::Vector{Expr}, equationInfo::ModiaBase.Equ # Generate code of the function code = quote function $functionName(_der_x, _x, _m, _time)::Nothing - _m.time = TinyModia.getValue(_time) + _m.time = ModiaLang.getValue(_time) _m.nGetDerivatives += 1 instantiatedModel = _m _p = _m.evaluatedParameters @@ -1454,7 +1454,7 @@ function generate_getDerivatives!(AST::Vector{Expr}, equationInfo::ModiaBase.Equ $(code_pre...) if _m.storeResult - TinyModia.addToResult!(_m, _der_x, $(variables...)) + ModiaLang.addToResult!(_m, _der_x, $(variables...)) end return nothing end diff --git a/src/EvaluateParameters.jl b/src/EvaluateParameters.jl index ce2e1ca..9e43e10 100644 --- a/src/EvaluateParameters.jl +++ b/src/EvaluateParameters.jl @@ -294,7 +294,7 @@ function propagateEvaluateAndInstantiate2!(modelModule, parameters, ParType, eqI printstyled("Model error: ", bold=true, color=:red) printstyled("Length of ", xe_info.x_name, " shall be changed from ", xe_info.length, " to $len\n", - "This is currently not support in TinyModia.", bold=true, color=:red) + "This is currently not support in ModiaLang.", bold=true, color=:red) return nothing end x_found[j] = true diff --git a/src/TinyModia.jl b/src/ModiaLang.jl similarity index 99% rename from src/TinyModia.jl rename to src/ModiaLang.jl index 98d72e9..0560ee0 100644 --- a/src/TinyModia.jl +++ b/src/ModiaLang.jl @@ -1,12 +1,12 @@ """ -Main module of TinyModia. +Main module of ModiaLang. * Developer: Hilding Elmqvist, Mogram AB * First version: December 2020 * License: MIT (expat) """ -module TinyModia +module ModiaLang # Defalut switch settings logStatistics = false @@ -729,7 +729,7 @@ function stateSelectionAndCodeGeneration(modStructure, name, modelModule, FloatT if haskey(init, nameAsExpr) vSolvedWithInitValuesAndUnit[name] = eval( init[nameAsExpr] ) else - @warn "Internal issue of TinyModia: $name is assumed to have an init-value, but it is not found." + @warn "Internal issue of ModiaLang: $name is assumed to have an init-value, but it is not found." end end diff --git a/src/PathPlanning.jl b/src/PathPlanning.jl index 671d565..646beda 100644 --- a/src/PathPlanning.jl +++ b/src/PathPlanning.jl @@ -39,7 +39,7 @@ a flange according to a given acceleration. # Example ```julia -using TinyModia +using ModiaLang @usingModiaPlot const ptp_path = PTP_path(["angle1", "angle2", "angle3"], diff --git a/src/ReverseDiffInterface.jl b/src/ReverseDiffInterface.jl index 7b48ce5..741cd14 100644 --- a/src/ReverseDiffInterface.jl +++ b/src/ReverseDiffInterface.jl @@ -1,7 +1,7 @@ export ModiaProblem, ModiaSolve -function ModiaProblem(m1::TinyModia.SimulationModel{FloatType1,ParType,EvaluatedParType,FloatType1}, - m2::TinyModia.SimulationModel{FloatType2,ParType,EvaluatedParType,FloatType2}; +function ModiaProblem(m1::ModiaLang.SimulationModel{FloatType1,ParType,EvaluatedParType,FloatType1}, + m2::ModiaLang.SimulationModel{FloatType2,ParType,EvaluatedParType,FloatType2}; p, merge=nothing, kwargs...) where {FloatType1,ParType,EvaluatedParType,FloatType2} TimeType1 = FloatType1 @@ -34,13 +34,13 @@ function ModiaProblem(m1::TinyModia.SimulationModel{FloatType1,ParType,Evaluated println("... Construct simulation problem of DifferentialEquations.jl for ", m.modelName) end - success1 = TinyModia.init!(m1) - if !success1|| m1.eventHandler.restart == TinyModia.Terminate + success1 = ModiaLang.init!(m1) + if !success1|| m1.eventHandler.restart == ModiaLang.Terminate return nothing end - success2 = TinyModia.init!(m2) - if !success2|| m2.eventHandler.restart == TinyModia.Terminate + success2 = ModiaLang.init!(m2) + if !success2|| m2.eventHandler.restart == ModiaLang.Terminate return nothing end diff --git a/src/SimulateAndPlot.jl b/src/SimulateAndPlot.jl index f712f62..4fc35a2 100644 --- a/src/SimulateAndPlot.jl +++ b/src/SimulateAndPlot.jl @@ -58,7 +58,7 @@ Simulate `instantiatedModel::SimulationModel` with `algorithm` If the `algorithm` argument is missing, `algorithm=Sundials.CVODE_BDF()` is used, provided instantiatedModel has `FloatType = Float64`. Otherwise, a default algorithm will be chosen from DifferentialEquations (for details see [https://arxiv.org/pdf/1807.06430](https://arxiv.org/pdf/1807.06430), Figure 3). -The symbol `CVODE_BDF` is exported from TinyModia, so that `simulate!(instantiatedModel, CVODE_BDF(), ...)` +The symbol `CVODE_BDF` is exported from ModiaLang, so that `simulate!(instantiatedModel, CVODE_BDF(), ...)` can be used (instead of `import Sundials; simulate!(instantiatedModel, Sundials.CVODE_BDF(), ...)`). The simulation results stored in `model` can be plotted with plot and the result values @@ -100,7 +100,7 @@ can be retrieved with `rawSignal(..)` or `getPlotSignal(..)` # Examples ```julia -using TinyModia +using ModiaLang using DifferentialEquations using Unitful @usingModiaPlot @@ -363,7 +363,7 @@ You can improve this situation, by using a larger # Example ```julia -using TinyModia +using ModiaLang using DoubleFloats using Measurements @@ -642,7 +642,7 @@ In both cases, a **view** on the internal result memory is provided # Example ```julia -using TinyModia +using ModiaLang @usingModiaPlot using Unitful diff --git a/test/TestAsynchronous.jl b/test/TestAsynchronous.jl index 8f7da5a..569fdf3 100644 --- a/test/TestAsynchronous.jl +++ b/test/TestAsynchronous.jl @@ -2,7 +2,7 @@ module TestAsynchronous #println("\nAsynchronousExamples: Demonstrating the ability to simulate models with asynchronous semantics") -using TinyModia +using ModiaLang @usingModiaPlot using DifferentialEquations diff --git a/test/TestBouncingBall.jl b/test/TestBouncingBall.jl index adad59d..47f7a3a 100644 --- a/test/TestBouncingBall.jl +++ b/test/TestBouncingBall.jl @@ -1,6 +1,6 @@ module TestBouncingBall -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot diff --git a/test/TestExtraSimulateKeywordArguments.jl b/test/TestExtraSimulateKeywordArguments.jl index 4cccae7..1231bc3 100644 --- a/test/TestExtraSimulateKeywordArguments.jl +++ b/test/TestExtraSimulateKeywordArguments.jl @@ -1,6 +1,6 @@ module TestExtraSimulateKeywordArguments -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot diff --git a/test/TestFilterCircuit.jl b/test/TestFilterCircuit.jl index 7e972e0..f4aeef5 100644 --- a/test/TestFilterCircuit.jl +++ b/test/TestFilterCircuit.jl @@ -1,6 +1,6 @@ module TestFilterCircuit -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot diff --git a/test/TestFirstOrder.jl b/test/TestFirstOrder.jl index 2e90893..a072547 100644 --- a/test/TestFirstOrder.jl +++ b/test/TestFirstOrder.jl @@ -1,6 +1,6 @@ module TestFirstOrder -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot diff --git a/test/TestFirstOrder2.jl b/test/TestFirstOrder2.jl index c644209..3516cc4 100644 --- a/test/TestFirstOrder2.jl +++ b/test/TestFirstOrder2.jl @@ -1,6 +1,6 @@ module TestFirstOrder2 -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot using Test diff --git a/test/TestHeatTransfer.jl b/test/TestHeatTransfer.jl index 81c1711..6d522b1 100644 --- a/test/TestHeatTransfer.jl +++ b/test/TestHeatTransfer.jl @@ -1,11 +1,11 @@ module TestHeatTransfer -using TinyModia +using ModiaLang using Unitful @usingModiaPlot using DifferentialEquations -include("$(TinyModia.path)/models/HeatTransfer.jl") +include("$(ModiaLang.path)/models/HeatTransfer.jl") SimpleRod = Model( fixedT = FixedTemperature | Map(T = 393.15u"K"), diff --git a/test/TestInputOutput.jl b/test/TestInputOutput.jl index f4809d3..cbb1252 100644 --- a/test/TestInputOutput.jl +++ b/test/TestInputOutput.jl @@ -1,6 +1,6 @@ module TestInputOutput -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot diff --git a/test/TestMechanics.jl b/test/TestMechanics.jl index 92f4b03..61605c8 100644 --- a/test/TestMechanics.jl +++ b/test/TestMechanics.jl @@ -1,21 +1,21 @@ module TestMechanics -println("TestMechanics: Tests how 3D mechanics could be combined with TinyModia.") +println("TestMechanics: Tests how 3D mechanics could be combined with ModiaLang.") -using TinyModia +using ModiaLang using Unitful @usingModiaPlot using DifferentialEquations using RuntimeGeneratedFunctions RuntimeGeneratedFunctions.init(@__MODULE__) -# TinyModia models -include("$(TinyModia.path)/models/Blocks.jl") -include("$(TinyModia.path)/models/Electric.jl") -include("$(TinyModia.path)/models/Rotational.jl") +# ModiaLang models +include("$(ModiaLang.path)/models/Blocks.jl") +include("$(ModiaLang.path)/models/Electric.jl") +include("$(ModiaLang.path)/models/Rotational.jl") -# Generic TinyModia3D model stubs (always available) +# Generic ModiaLang3D model stubs (always available) RevoluteStub = Model( flange = Flange, @@ -52,7 +52,7 @@ function Pendulum_f1(_m::TestMechanics.SimulationModel3D, phi, w, tau, m, L, g) end -# TinyModia model for the system +# ModiaLang model for the system Pendulum = Model( model3D = SimulationModel3D(), @@ -64,7 +64,7 @@ Pendulum = Model( # 3D model stubs rev = RevoluteStub | Map(init = Map(phi=1.5u"rad", w=2u"rad/s")), - # Standard TinyModia models + # Standard ModiaLang models damper = Damper | Map(d=0.4u"N*m*s/rad"), support = Fixed, diff --git a/test/TestParameter.jl b/test/TestParameter.jl index 5512ed8..de99825 100644 --- a/test/TestParameter.jl +++ b/test/TestParameter.jl @@ -1,9 +1,9 @@ module TestParameter -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot -include("$(TinyModia.path)/models/Blocks.jl") +include("$(ModiaLang.path)/models/Blocks.jl") inputSignal(t) = sin(t) diff --git a/test/TestPathPlanning.jl b/test/TestPathPlanning.jl index dce12a1..5913e72 100644 --- a/test/TestPathPlanning.jl +++ b/test/TestPathPlanning.jl @@ -1,6 +1,6 @@ module TestPath -using TinyModia +using ModiaLang using Measurements @usingModiaPlot diff --git a/test/TestSimpleStateEvents.jl b/test/TestSimpleStateEvents.jl index d72ae6c..13cab3f 100644 --- a/test/TestSimpleStateEvents.jl +++ b/test/TestSimpleStateEvents.jl @@ -1,6 +1,6 @@ module TestSimpleStateEvents -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot diff --git a/test/TestSingularLRRL.jl b/test/TestSingularLRRL.jl index 8b32bb7..f339bce 100644 --- a/test/TestSingularLRRL.jl +++ b/test/TestSingularLRRL.jl @@ -1,6 +1,6 @@ module TestSingularLRRL -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot diff --git a/test/TestSource.jl b/test/TestSource.jl index 36d389b..f2cbb9a 100644 --- a/test/TestSource.jl +++ b/test/TestSource.jl @@ -1,6 +1,6 @@ module TestSource -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot diff --git a/test/TestStateSelection.jl b/test/TestStateSelection.jl index e284a7a..618d3b8 100644 --- a/test/TestStateSelection.jl +++ b/test/TestStateSelection.jl @@ -1,6 +1,6 @@ module TestStateSelection -using TinyModia +using ModiaLang using Test function checkStateSelection(model, x_names, linearEquations=[]) diff --git a/test/TestStateSpace.jl b/test/TestStateSpace.jl index 6d0d4f0..fbd0f8f 100644 --- a/test/TestStateSpace.jl +++ b/test/TestStateSpace.jl @@ -1,10 +1,10 @@ module TestStateSpace -using TinyModia +using ModiaLang @usingModiaPlot using DifferentialEquations -include("$(TinyModia.path)/models/Blocks.jl") +include("$(ModiaLang.path)/models/Blocks.jl") # Second order system: diff --git a/test/TestSynchronous.jl b/test/TestSynchronous.jl index d95bb7d..18cbc71 100644 --- a/test/TestSynchronous.jl +++ b/test/TestSynchronous.jl @@ -2,7 +2,7 @@ module TestSynchronous #println("\nSynchronousExamples: Demonstrating the ability to simulate models with synchronous semantics") -using TinyModia +using ModiaLang @usingModiaPlot using DifferentialEquations diff --git a/test/TestTwoInertiasAndIdealGear.jl b/test/TestTwoInertiasAndIdealGear.jl index d0bb127..b9263f1 100644 --- a/test/TestTwoInertiasAndIdealGear.jl +++ b/test/TestTwoInertiasAndIdealGear.jl @@ -1,6 +1,6 @@ module TestTwoInertiasAndIdealGear -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot using Unitful diff --git a/test/TestTwoInertiasAndIdealGearWithMonteCarlo.jl b/test/TestTwoInertiasAndIdealGearWithMonteCarlo.jl index 364c749..e5736d1 100644 --- a/test/TestTwoInertiasAndIdealGearWithMonteCarlo.jl +++ b/test/TestTwoInertiasAndIdealGearWithMonteCarlo.jl @@ -1,6 +1,6 @@ module TestTwoInertiasAndIdealGearWithMonteCarlo -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot using MonteCarloMeasurements diff --git a/test/TestTwoInertiasAndIdealGearWithUnits.jl b/test/TestTwoInertiasAndIdealGearWithUnits.jl index f699474..4af6b56 100644 --- a/test/TestTwoInertiasAndIdealGearWithUnits.jl +++ b/test/TestTwoInertiasAndIdealGearWithUnits.jl @@ -1,6 +1,6 @@ module TestTwoInertiasAndIdealGearWithUnits -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot using Unitful diff --git a/test/TestTwoInertiasAndIdealGearWithUnitsAndMonteCarlo.jl b/test/TestTwoInertiasAndIdealGearWithUnitsAndMonteCarlo.jl index 5a2cf55..1aba097 100644 --- a/test/TestTwoInertiasAndIdealGearWithUnitsAndMonteCarlo.jl +++ b/test/TestTwoInertiasAndIdealGearWithUnitsAndMonteCarlo.jl @@ -1,6 +1,6 @@ module TestTwoInertiasAndIdealGearWithUnitsAndMonteCarlo -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot using MonteCarloMeasurements diff --git a/test/TestTwoInertiasAndIdealGearWithUnitsAndUncertainties.jl b/test/TestTwoInertiasAndIdealGearWithUnitsAndUncertainties.jl index d8cfb77..c771905 100644 --- a/test/TestTwoInertiasAndIdealGearWithUnitsAndUncertainties.jl +++ b/test/TestTwoInertiasAndIdealGearWithUnitsAndUncertainties.jl @@ -1,7 +1,7 @@ module TestTwoInertiasAndIdealGearWithUnitsAndUncertainties -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot using Measurements diff --git a/test/TestUncertainties.jl b/test/TestUncertainties.jl index 8b318fb..1021a4d 100644 --- a/test/TestUncertainties.jl +++ b/test/TestUncertainties.jl @@ -1,6 +1,6 @@ module TestUncertainties -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot diff --git a/test/TestUnits.jl b/test/TestUnits.jl index 3bf904f..c060059 100644 --- a/test/TestUnits.jl +++ b/test/TestUnits.jl @@ -1,6 +1,6 @@ module TestUnits -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot using Test diff --git a/test/TestUnitsAndUncertainties.jl b/test/TestUnitsAndUncertainties.jl index 07c5f78..680b38c 100644 --- a/test/TestUnitsAndUncertainties.jl +++ b/test/TestUnitsAndUncertainties.jl @@ -1,6 +1,6 @@ module TestUnitsAndUncertainites -using TinyModia +using ModiaLang using DifferentialEquations @usingModiaPlot using Measurements diff --git a/test/TestVariables.jl b/test/TestVariables.jl index adba61c..aaec053 100644 --- a/test/TestVariables.jl +++ b/test/TestVariables.jl @@ -1,6 +1,6 @@ module TestVariables -using TinyModia +using ModiaLang @usingModiaPlot using Measurements using StaticArrays diff --git a/test/include_all.jl b/test/include_all.jl index 9b5c649..d85ab8b 100644 --- a/test/include_all.jl +++ b/test/include_all.jl @@ -37,7 +37,3 @@ Test.@testset "Test events, etc." begin include("TestExtraSimulateKeywordArguments.jl") Test.@test_skip include("TestBouncingBall.jl") end - -Test.@testset "Test examples" begin - include("../examples/runexamples.jl") -end diff --git a/test/runtests.jl b/test/runtests.jl index 89cc69b..053140b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,10 +2,10 @@ module Runtests # Run all tests with SilentNoPlot (so not plots) -using TinyModia +using ModiaLang using Test -@time @testset verbose=true "TinyModia (with SilentNoPlot)" begin +@time @testset verbose=true "ModiaLang (with SilentNoPlot)" begin usePlotPackage("SilentNoPlot") include("include_all.jl") usePreviousPlotPackage() diff --git a/test/runtests_withPlot.jl b/test/runtests_withPlot.jl index e74033f..b5e237c 100644 --- a/test/runtests_withPlot.jl +++ b/test/runtests_withPlot.jl @@ -1,9 +1,9 @@ module Runtests_withPlot -using TinyModia +using ModiaLang using Test -const test_title = "Test TinyModia with simulation (with " * currentPlotPackage() * ")" +const test_title = "Test ModiaLang with simulation (with " * currentPlotPackage() * ")" @testset "$test_title" begin include("include_all.jl")