modiasim / tinymodia.jl Goto Github PK
View Code? Open in Web Editor NEWDeprecated package (use instead Modia.jl)
License: MIT License
Deprecated package (use instead Modia.jl)
License: MIT License
I'm trying to add an example using ModiaSim to my repo of models at https://github.com/epirecipes/sir-julia. The gist is here.
A couple of questions:
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
I installed TinyModia ModiaBase and ModiaPlot on Julia 1.6.1 in Linux Ubuntu.
I tried running this example, but it crashes on "Var" ... I can't figure out where I'm going wrong.
ulia> using TinyModia
julia> using ModiaBase
julia> using ModiaPlot
julia> # Cartesian pendulum model.
CPendulum = Model(
L = Var(1.0, parameter=true),
m = Var(1.0, parameter=true),
g_n = Var(9.80665, parameter=true),
x = Var(init=1/sqrt(2)),
y = Var(init=-1/sqrt(2)),
vx = Var(),
vy = Var(),
F = Var(),
equation = :[
der(x) = vx
der(y) = vy
m*der(vx) = (F/L)*x
m*der(vy) = (F/L)*y - m*g_n
x^2 + y^2 = L^2]
)
ERROR: UndefVarError: Var not defined
Stacktrace:
[1] top-level scope
@ REPL[54]:2
In the doc string of the package it is stated that thermo-fluid systems can be modelled with TinyModia.jl
.
Is this already possible?
If not, what are the plans? Will it be using the stream connector idea used in Modelica?
I am trying to get a first-order ODE working in which I initialize the state variable at a nonzero value, but neither setting start=1.0 or init=1.0 seems to change the result. My code is as follows:
using TinyModia
using ModiaBase
using ModiaPlot
Var(args...; kwargs...) = (;args..., kwargs...)
Var(value::Union{Float64, Int64, Bool, String, Expr}, args...; kwargs...) = (;value = value, args..., kwargs...)
SimpleModel = Model(
T = 1.0,
x = Var(start=1.0),
equation = :[T * der(x) + x = 0.0],
)
simpleModel = @instantiateModel(SimpleModel)
simulate!(simpleModel, stopTime=10.0)
plot(simpleModel, "x", figure=1)
The result is fixed at zero, e.g.,
Is this a bug, or is some method other than what I included here needed?
It seems not possible to use a function (apart from Julia built-in functions) inside the equation section (like the getForce(...) function in the Modia example "CollidingBalls.jl"). I tried to define it inside and outside the respective module. While generation of the runtime-generated function for the rhs (in the instantiation) works fine, evaluation of it gives the error that the function is not defined. Is there a work-around or is this a limitation of TinyModia (compared to Modia)?
Thanks in advance!
I created a Model that starts like this:
SingleTrackModel = Model(
inputs = :[delta,T_F,T_R],
m = 1450,
I_z = 1.0,
l_F = 1.1,
l_R = 1.59,
h = 0.4,
I_w = [1.8, 1.8],
...
Now in the equations
section, I cannot access elements of parameters I_w
using I_w[ind...]
. A tested workaround I found is to use getindex(I_w, ind...)
instead. However, neither does I_w
show up in field parametersAndConstantVariables
of the instantiated model, nor can I spot its contents in the field p
.
However I would like to alter p
after model instantiation (machine learning purposes).
Is there any supported and intended way to use and alter parameters in arrays?
I tried to implement a single pendulum model in Cartesian coordinates, but got an error when I tried to instantiate it. Should this model work with the current release (0.7.2)?
using TinyModia
using ModiaBase
using ModiaPlot
# Cartesian pendulum model.
CPendulum = Model(
L = Var(1.0, parameter=true),
m = Var(1.0, parameter=true),
g_n = Var(9.80665, parameter=true),
x = Var(init=1/sqrt(2)),
y = Var(init=-1/sqrt(2)),
vx = Var(),
vy = Var(),
F = Var(),
equation = :[
der(x) = vx
der(y) = vy
m*der(vx) = (F/L)*x
m*der(vy) = (F/L)*y - m*g_n
x^2 + y^2 = L^2]
)
cPendulum = @instantiateModel(CPendulum)
When I try to instantiate this, I get
julia> cPendulum = @instantiateModel(CPendulum)
Instantiating model Main.CPendulum
ERROR: BoundsError: attempt to access 0-element Vector{Any} at index [1]
Stacktrace:
[1] getindex
@ .\array.jl:801 [inlined]
[2] derivative(ex::Expr, timeInvariants::Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}})
@ ModiaBase.Differentiate C:\Users\laughman\.julia\packages\ModiaBase\igtEB\src\Differentiate.jl:84
[3] (::ModiaBase.Differentiate.var"#4#8"{Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}}})(e::Expr)
@ ModiaBase.Differentiate .\none:0
[4] iterate
@ .\generator.jl:47 [inlined]
[5] collect_to!(dest::Vector{Expr}, itr::Base.Generator{Vector{Any}, ModiaBase.Differentiate.var"#4#8"{Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}}}}, offs::Int64, st::Int64)
@ Base .\array.jl:724
[6] collect_to_with_first!(dest::Vector{Expr}, v1::Expr, itr::Base.Generator{Vector{Any}, ModiaBase.Differentiate.var"#4#8"{Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}}}}, st::Int64)
@ Base .\array.jl:702
[7] collect(itr::Base.Generator{Vector{Any}, ModiaBase.Differentiate.var"#4#8"{Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}}}})
@ Base .\array.jl:683
[8] derivative(ex::Expr, timeInvariants::Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}})
@ ModiaBase.Differentiate C:\Users\laughman\.julia\packages\ModiaBase\igtEB\src\Differentiate.jl:98
[9] assignAndBLT(equations::Vector{Any}, unknowns::Vector{Any}, parameters::OrderedCollections.OrderedDict{Any, Any}, Avar::Vector{Int64}, G::Vector{Vector{Int64}}, states::Vector{Any}, logDetails::Bool, log::Bool, logTiming::Bool)
@ TinyModia C:\Users\laughman\.julia\packages\TinyModia\yrVLj\src\TinyModia.jl:197
[10] instantiateModel(model::NamedTuple{(:class, :L, :m, :g_n, :x, :y, :vx, :vy, :F, :equation), Tuple{Symbol, NamedTuple{(:class, :value, :parameter), Tuple{Symbol, Float64, Bool}}, NamedTuple{(:class, :value, :parameter), Tuple{Symbol, Float64, Bool}}, NamedTuple{(:class, :value, :parameter), Tuple{Symbol, Float64, Bool}}, NamedTuple{(:class, :init), Tuple{Symbol, Float64}}, NamedTuple{(:class, :init), Tuple{Symbol, Float64}}, NamedTuple{(:class,), Tuple{Symbol}}, NamedTuple{(:class,), Tuple{Symbol}}, NamedTuple{(:class,), Tuple{Symbol}}, Expr}}; modelName::String, modelModule::Module, source::String, FloatType::Type, aliasReduction::Bool, unitless::Bool, log::Bool, logModel::Bool, logDetails::Bool, logStateSelection::Bool, logCode::Bool, logExecution::Bool, logTiming::Bool)
@ TinyModia C:\Users\laughman\.julia\packages\TinyModia\yrVLj\src\TinyModia.jl:847
[11] top-level scope
@ REPL[3]:1
Is TinyModia able to compile the Cartesian pendulum at this point, or is this functionality still in process?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.