modiasim / modia.jl Goto Github PK
View Code? Open in Web Editor NEWModeling and simulation of multidomain engineering systems
License: MIT License
Modeling and simulation of multidomain engineering systems
License: MIT License
With Julia 0.7.0, many warnings of the following kind are present when importing Modia:
WARNING: eval from module Unitful to Rotational:
Expr(:call, :*, Unitful.FreeUnits{(Unitful.Unit{:Newton, Unitful.Dimensions{(Unitful.Dimension{:Length}(power=Base.Rational{Int64}(num=1, den=1)), Unitful.Dimension{:Mass}(power=Base.Rational{Int64}(
um=1, den=1)), Unitful.Dimension{:Time}(power=Base.Rational{Int64}(num=-2, den=1)))}}(tens=0, power=Base.Rational{Int64}(num=1, den=1)),), Unitful.Dimensions{(Unitful.Dimension{:Length}(power=Base.Ra
ional{Int64}(num=1, den=1)), Unitful.Dimension{:Mass}(power=Base.Rational{Int64}(num=1, den=1)), Unitful.Dimension{:Time}(power=Base.Rational{Int64}(num=-2, den=1)))}}(), Unitful.FreeUnits{(Unitful.U
it{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(power=Base.Rational{Int64}(num=1, den=1)),)}}(tens=0, power=Base.Rational{Int64}(num=1, den=1)),), Unitful.Dimensions{(Unitful.Dimension{:Len
th}(power=Base.Rational{Int64}(num=1, den=1)),)}}())
** incremental compilation may be broken for this module **
Probably the issue is in these definitions due to argument T:
Variable(;
value=nothing,
info="",
unit=if typeof(value) <: Unitful.Quantity; Unitful.unit(value) else Unitful.NoUnits end,
displayUnit=unit,
min=nothing,
max=nothing,
start=nothing,
fixed::Bool=false,
nominal=nothing,
variability=continuous,
T=if value == nothing; Any else typeof(value) end,
size=if value == nothing; nothing else Base.size(value) end,
flow::Bool=false,
state::Bool=true,
property=general) =
Variable(variability, T, size, value,
unit, displayUnit, min, max, start, fixed, nominal, info, flow, state, property)
TorqueVar(; args...) = Variable(; start = 0.0, size = (),
T = u"N*m", info = "Torque", args...)
@tshort gave the hint that this is a closed issue in Unitful. A workaround according to this issue is to use T = Unitful.N*Unitful.m
. The suggested solution is to define a second string macro U
for use in expressions that shall be used in pre-compilations, so T = U"N*m"
. Unfortunately, this suggestion was not taken into account and the fix to this issue was to just document this behaviour.
With pull request #80 the newest Unitful 0.14.0 is used in Modia.
Unfortunately, some test models do no longer run with this change. In particular, Modia/test/models/TestVariableTypes.jl gives the following errors:
Simulating model: TestVariableTypes2
Number of equations: 10
Number of variables: 10
Number of continuous states: 0
ERROR: LoadError: LoadError: Symbol `V` was found in unit module Unitful, but was not loaded into Main.anonymous. Consider `using Unitful` within `Main.anonymous`?
Stacktrace:
[1] error(::String) at .\error.jl:33
[2] replace_value(::Module, ::Symbol) at HOME\.julia\packages\Unitful\A3sNy\src\user.jl:540
[3] @u_str(::LineNumberNode, ::Module, ::Any) at HOME\.julia\packages\Unitful\A3sNy\src\user.jl:495
[4] eval at .\boot.jl:319 [inlined]
[5] evaluate at HOME\.julia\dev\Modia\src\language\Execution.jl:24 [inlined]
[6] #prepare_ida#5(::Bool, ::Bool, ::Function, ::Modia.Instantiation.Instance, ::Array{Symbol,1}, ::Dict{Symbol,Any}) at HOME\.julia\dev\Modia\src\language\Execution.jl:530
[7] (::getfield(Modia.Execution, Symbol("#kw##prepare_ida")))(::NamedTuple{(:store_eliminated, :need_eliminated_f),Tuple{Bool,Bool}}, ::typeof(Modia.Execution.prepare_ida), ::Modia.Instantiation.Inst
ance, ::Array{Symbol,1}, ::Dict{Symbol,Any}) at .\none:0
[8] #simulate_ida#12(::Bool, ::Float64, ::Float64, ::Float64, ::Bool, ::Function, ::Modia.Instantiation.Instance, ::Array{Float64,1}, ::Nothing) at HOME\.julia\dev\Modia\src\language\Executi
on.jl:604
[9] (::getfield(Modia.Execution, Symbol("#kw##simulate_ida")))(::NamedTuple{(:log, :relTol, :hev),Tuple{Bool,Float64,Float64}}, ::typeof(Modia.Execution.simulate_ida), ::Modia.Instantiation.Instance,
::Array{Float64,1}, ::Nothing) at .\none:0
[10] #simulate_ida#11 at HOME\.julia\dev\Modia\src\language\Execution.jl:587 [inlined]
[11] (::getfield(Modia.Execution, Symbol("#kw##simulate_ida")))(::NamedTuple{(:log, :relTol, :hev),Tuple{Bool,Float64,Float64}}, ::typeof(Modia.Execution.simulate_ida), ::Modia.Instantiation.Instance
, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Nothing) at .\none:0
[12] #simulateModelWithOptions#7(::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:storeEliminated,),Tuple{Bool}}}, ::Function, ::Modia.Instantiation.Model, ::StepRangeLen{Float64,Base.Tw
icePrecision{Float64},Base.TwicePrecision{Float64}}) at HOME\.julia\dev\Modia\src\symbolic\ModelElaboration.jl:373
[13] #simulate#9 at .\none:0 [inlined]
[14] (::getfield(Modia.ModelElaboration, Symbol("#kw##simulate")))(::NamedTuple{(:storeEliminated,),Tuple{Bool}}, ::typeof(Modia.ModelElaboration.simulate), ::Modia.Instantiation.Model, ::Int64) at .
\none:0
[15] top-level scope at none:0
[16] include at .\boot.jl:317 [inlined]
[17] include_relative(::Module, ::String) at .\loading.jl:1044
[18] include(::Module, ::String) at .\sysimg.jl:29
[19] include(::String) at .\client.jl:392
[20] top-level scope at none:0
in expression starting at <macrocall>:0
in expression starting at HOME\.julia\dev\Modia\test\models\TestVariableTypes.jl:162
Simulating model: TestVariableUnits1
ERROR: LoadError: AssertionError: Not possible to infer size of all variables and equations. Examine log for what variables that need sizes or start values.
Stacktrace:
[1] deduceVariableAndEquationSizes(::Modia.Instantiation.Instance, ::OrderedCollections.OrderedDict{Symbol,Any}, ::OrderedCollections.OrderedDict{Symbol,Any}, ::Array{Any,1}) at HOME\.julia\
dev\Modia\src\symbolic\StructuralTransform.jl:607
[2] transformStructurally(::Modia.Instantiation.Instance) at HOME\.julia\dev\Modia\src\symbolic\StructuralTransform.jl:682
[3] elaborateModel(::Modia.Instantiation.Instance) at HOME\.julia\dev\Modia\src\symbolic\ModelElaboration.jl:122
[4] #simulateModelWithOptions#7(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Modia.Instantiation.Model, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Ba
se.TwicePrecision{Float64}}) at HOME\.julia\dev\Modia\src\symbolic\ModelElaboration.jl:365
[5] #simulate#9 at .\none:0 [inlined]
[6] simulate(::Modia.Instantiation.Model, ::Int64) at HOME\.julia\dev\Modia\src\symbolic\ModelElaboration.jl:438
[7] top-level scope at none:0
[8] include at .\boot.jl:317 [inlined]
[9] include_relative(::Module, ::String) at .\loading.jl:1044
[10] include(::Module, ::String) at .\sysimg.jl:29
[11] include(::String) at .\client.jl:392
[12] top-level scope at none:0
in expression starting at HOME\.julia\dev\Modia\test\models\TestVariableTypes.jl:191
The first test model was temporarily fixed by replacing v6 = 10.0u"V"
with v6 = 10.0
. The second test model was completely deactivated.
Modia should be corrected so that the above two test can be activated again.
We should add an indication in the README.md what Julia version is used. I suppose there is a standard layout for how to present the build and covergage status for different Julia versions.
While Modia works now on Julia 0.7 in general, one test fails:
...
Simulating model: ManyFilters
Number of equations: 200
Number of variables: 210
Number of continuous states: 10
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ManyFilters
final F[1].C.v = 9.816758332322895
Simulation OK
Simulating model: ManyDifferentFilters
Number of equations: 200
Number of variables: 210
Number of continuous states: 10
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ManyDifferentFilters
Simulating model: AdvancedLPfilter
Number of equations: 20
Number of variables: 21
Number of continuous states: 1
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: AdvancedLPfilter
Rectifier: Demonstrating conditional components
logTranslation = true
Log file: /home/ufechner//home/ufechner/ModiaResults/ConditionalLoad.txt
Simulating model: ConditionalLoad
Number of equations: 39
Number of variables: 41
Number of continuous states: 2
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ConditionalLoad
logTranslation = true
Log file: /home/ufechner//home/ufechner/ModiaResults/NoExtraLoad.txt
Simulating model: NoExtraLoad
┌ Warning: Calling `print` on `nothing` is deprecated; use `show`, `repr`, or custom output instead.
│ caller = print(::IOStream, ::Nothing, ::Char) at io.jl:42
└ @ Base ./strings/io.jl:42
Number of equations: 33
Number of variables: 35
Number of continuous states: 2
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: NoExtraLoad
Demonstrating conditional equations
logTranslation = true
removeSingularities = false
Log file: /home/ufechner//home/ufechner/ModiaResults/Conditional.txt
Simulating model: Conditional
Conditional equation:
if !steadyState
der(x) + 2x = u
else
0 + 2x = u
end
condition = true
Conditional equation:
if !cond
y = 1
else
y = 2
end
condition = true
Number of equations: 3
Number of variables: 4
Number of continuous states: 1
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: Conditional
logTranslation = true
removeSingularities = false
Log file: /home/ufechner//home/ufechner/ModiaResults/ConditionalInstance1.txt
Simulating model: ConditionalInstance1
Conditional equation:
if !steadyState
der(x) + 2x = u
else
0 + 2x = u
end
condition = false
Conditional equation:
if !cond
y = 1
else
y = 2
end
condition = false
Number of equations: 3
Number of variables: 3
Number of continuous states: 0
logTranslation = true
removeSingularities = false
Log file: /home/ufechner//home/ufechner/ModiaResults/ConditionalInstance2.txt
Simulating model: ConditionalInstance2
Conditional equation:
if !steadyState
der(x) + 2x = u
else
0 + 2x = u
end
condition = true
Conditional equation:
if !cond
y = 1
else
y = 2
end
condition = true
Number of equations: 3
Number of variables: 4
Number of continuous states: 1
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ConditionalInstance2
logTranslation = true
removeSingularities = false
Log file: /home/ufechner//home/ufechner/ModiaResults/Conditional2.txt
Simulating model: Conditional2
Conditional equation:
if !steadyState
der(x) + 2x = u
else
0 + 2x = u
end
condition = true
Conditional equation:
if cond
y = 1
end
condition = false
Number of equations: 2
Number of variables: 3
Number of continuous states: 1
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: Conditional2
Simulating model: SpatialDiscretization
Number of equations: 1
Number of variables: 2
Number of continuous states: 1
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: SpatialDiscretization
logTranslation = true
storeEliminated = false
Log file: /home/ufechner//home/ufechner/ModiaResults/SpatialDiscretization2.txt
Simulating model: SpatialDiscretization2
Number of equations: 3
Number of variables: 4
Number of continuous states: 1
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: SpatialDiscretization2
----------------------
Number of simulations OK : 16
Number of simulations NOT OK: 0
Log category statistics:
StaticModel: 4
DynamicModel: 32
CalculatedResult: 16
----------------------
CurrentController: Demonstrating the ability to simulate mixed domain models
removeSingularities = true
Simulating model: CurrentController
Number of equations: 81
Number of variables: 89
Number of continuous states: 8
Number of non states: 3
┌ Warning: `a::AbstractArray + b::Number` is deprecated, use `a .+ b` instead.
│ caller = top-level scope at BasicStructuralTransform.jl:561
└ @ Core ~/.julia/packages/Modia/UQ96g/src/symbolic/DAEquations/BasicStructuralTransform.jl:561
┌ Warning: `a::Number - b::AbstractArray` is deprecated, use `a .- b` instead.
│ caller = top-level scope at BasicStructuralTransform.jl:561
└ @ Core ~/.julia/packages/Modia/UQ96g/src/symbolic/DAEquations/BasicStructuralTransform.jl:561
┌ Warning: `a::Number - b::AbstractArray` is deprecated, use `a .- b` instead.
│ caller = top-level scope at BasicStructuralTransform.jl:561
└ @ Core ~/.julia/packages/Modia/UQ96g/src/symbolic/DAEquations/BasicStructuralTransform.jl:561
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: CurrentController
final load.w = 0.07928692582634123
Simulation OK
Rectifier: Demonstrating the ability to simulate models with state events
Simulating model: Rectifier
Number of equations: 33
Number of variables: 35
Number of continuous states: 2
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: Rectifier
final C.v = 0.4774094787113099
Simulation OK
TestCauerLowPassFilter: Demonstrating the ability to simulate an electrical model translated from Modelica Standar Library
Simulating model: CauerLowPassOPVWithoutNodes
Number of equations: 172
Number of variables: 177
Number of continuous states: 5
Number of non states: 20
┌ Warning: `a::Number + b::AbstractArray` is deprecated, use `a .+ b` instead.
│ caller = top-level scope at BasicStructuralTransform.jl:561
└ @ Core ~/.julia/packages/Modia/UQ96g/src/symbolic/DAEquations/BasicStructuralTransform.jl:561
┌ Warning: `a::Number + b::AbstractArray` is deprecated, use `a .+ b` instead.
│ caller = top-level scope at BasicStructuralTransform.jl:561
└ @ Core ~/.julia/packages/Modia/UQ96g/src/symbolic/DAEquations/BasicStructuralTransform.jl:561
┌ Warning: `a::AbstractArray + b::Number` is deprecated, use `a .+ b` instead.
│ caller = top-level scope at BasicStructuralTransform.jl:561
└ @ Core ~/.julia/packages/Modia/UQ96g/src/symbolic/DAEquations/BasicStructuralTransform.jl:561
┌ Warning: `a::AbstractArray + b::Number` is deprecated, use `a .+ b` instead.
│ caller = top-level scope at BasicStructuralTransform.jl:561
└ @ Core ~/.julia/packages/Modia/UQ96g/src/symbolic/DAEquations/BasicStructuralTransform.jl:561
┌ Warning: `a::AbstractArray + b::Number` is deprecated, use `a .+ b` instead.
│ caller = top-level scope at BasicStructuralTransform.jl:561
└ @ Core ~/.julia/packages/Modia/UQ96g/src/symbolic/DAEquations/BasicStructuralTransform.jl:561
┌ Warning: `a::AbstractArray + b::Number` is deprecated, use `a .+ b` instead.
│ caller = top-level scope at BasicStructuralTransform.jl:561
└ @ Core ~/.julia/packages/Modia/UQ96g/src/symbolic/DAEquations/BasicStructuralTransform.jl:561
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: CauerLowPassOPVWithoutNodes
removeSingularities = false
useKinsol = true
Simulating model: CauerLowPassOPVWithoutNodes
Number of equations: 195
Number of variables: 200
Number of continuous states: 5
Number of non states: 4
----------------------
Simulation FAILED:
MethodError(Modia.Execution.get_name, (der(this.C3.v),), 0x0000000000006f62)
----------------------
RunExamples: Test Failed at /home/ufechner/.julia/packages/Modia/UQ96g/src/symbolic/ModelElaboration.jl:467
Expression: false
Stacktrace:
[1] #checkSimulation#10(::Int64, ::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol,Symbol},NamedTuple{(:useKinsol, :removeSingularities),Tuple{Bool,Bool}}}, ::Function, ::Modia.Instantiation.Model, ::Int64, ::String, ::Float64) at /home/ufechner/.julia/packages/Modia/UQ96g/src/symbolic/ModelElaboration.jl:467
[2] (::getfield(Modia.ModelElaboration, Symbol("#kw##checkSimulation")))(::NamedTuple{(:useKinsol, :removeSingularities),Tuple{Bool,Bool}}, ::typeof(checkSimulation), ::Modia.Instantiation.Model, ::Int64, ::String, ::Float64) at ./none:0
[3] top-level scope at none:0
[4] include at ./boot.jl:317 [inlined]
[5] include_relative(::Module, ::String) at ./loading.jl:1038
[6] include(::Module, ::String) at ./sysimg.jl:29
[7] include(::String) at ./client.jl:398
[8] macro expansion at /home/ufechner/.julia/packages/Modia/UQ96g/examples/runexamples.jl:18 [inlined]
[9] macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/Test/src/Test.jl:1079 [inlined]
[10] top-level scope at /home/ufechner/.julia/packages/Modia/UQ96g/examples/runexamples.jl:12
LinearSystems: Demonstrates type and size deduction.
logTranslation = true
Log file: /home/ufechner//home/ufechner/ModiaResults/MySISOABCD.txt
Simulating model: MySISOABCD
Number of equations: 2
Number of variables: 3
Number of continuous states: 1
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: MySISOABCD
final x = 0.5000001198147023
Simulation OK
storeEliminated = false
Simulating model: MyMIMOABCD
Number of equations: 5
Number of variables: 6
Number of continuous states: 1
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: MyMIMOABCD
final x = 0.004778288940817275
Simulation OK
SynchronousExamples: Demonstrating the ability to simulate models with synchronous semantics
storeEliminated = false
Simulating model: SpeedControl
Number of equations: 6
Number of variables: 9
Number of continuous states: 3
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: SpeedControl
storeEliminated = false
Simulating model: SpeedControlPI
Number of equations: 8
Number of variables: 11
Number of continuous states: 3
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: SpeedControlPI
(result["v"])[end] = 100.2849917097788
ElectricalVehicleAndCharger: Demonstrates the ability to change models from Julia.
Simulating model: Charger
Number of equations: 17
Number of variables: 17
Number of continuous states: 0
Simulating model: ElectricVehicle
Number of equations: 17
Number of variables: 18
Number of continuous states: 1
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricVehicle
Simulating model: ElectricalVehicleWithCharger
Standard Charger
Number of equations: 34
Number of variables: 35
Number of continuous states: 1
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricalVehicleWithCharger
┌ Warning: Deprecated syntax `implicit assignment to global variable `then``.
│ Use `global then` instead.
└ @ none:0
┌ Warning: Deprecated syntax `implicit assignment to global variable `now``.
│ Use `global now` instead.
└ @ none:0
┌ Warning: Deprecated syntax `implicit assignment to global variable `result``.
│ Use `global result` instead.
└ @ none:0
┌ Warning: Deprecated syntax `implicit assignment to global variable `Bv``.
│ Use `global Bv` instead.
└ @ none:0
┌ Warning: Deprecated syntax `implicit assignment to global variable `then``.
│ Use `global then` instead.
└ @ none:0
┌ Warning: Deprecated syntax `implicit assignment to global variable `now``.
│ Use `global now` instead.
└ @ none:0
┌ Warning: Deprecated syntax `implicit assignment to global variable `result``.
│ Use `global result` instead.
└ @ none:0
┌ Warning: Deprecated syntax `implicit assignment to global variable `Bv``.
│ Use `global Bv` instead.
└ @ none:0
Connecting Electric Vehicle to Charger
Standard Charger
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricalVehicleWithCharger
Disconnect
Standard Charger
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricalVehicleWithCharger
Connecting Electric Vehicle to Charger
Super Charger
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricalVehicleWithCharger
Disconnect
Super Charger
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricalVehicleWithCharger
Connecting Electric Vehicle to Charger
Standard Charger
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricalVehicleWithCharger
Disconnect
Standard Charger
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricalVehicleWithCharger
Connecting Electric Vehicle to Charger
Super Charger
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricalVehicleWithCharger
Disconnect
Standard Charger
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricalVehicleWithCharger
Connecting Electric Vehicle to Charger
Standard Charger
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricalVehicleWithCharger
Disconnect
Super Charger
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: ElectricalVehicleWithCharger
CollidingBalls: Demonstrating the use of allInstances to set up contact force between any number of balls
expandArrayIncidence = true
storeEliminated = false
Simulating model: Balls3
┌ Warning: `rsearchindex(s::AbstractString, t::AbstractString)` is deprecated, use `first(something(findlast(t, s), 0:-1))` instead.
│ caller = substituteAllInstances(::Expr, ::Modia.Instantiation.Instance, ::Symbol, ::Bool) at ModelElaboration.jl:241
└ @ Modia.ModelElaboration ~/.julia/packages/Modia/UQ96g/src/symbolic/ModelElaboration.jl:241
Number of equations: 24
Number of variables: 36
Number of continuous states: 12
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: Balls3
Simulating model: HeatTransfer
Number of equations: 1
Number of variables: 2
Number of continuous states: 1
... ModiaMath.simulate! (version 0.2.1 from 2018-09-14 09:30) to simulate model: HeatTransfer
----------------------
Number of simulations OK : 4
Number of simulations NOT OK: 1
Log category statistics:
StaticModel: 1
DynamicModel: 21
CalculatedResult: 4
----------------------
Test Summary: | Pass Fail Total
RunTests | 303 1 304
SymbolicTests | 210 210
RunSimulations | 65 65
RunExamples | 28 1 29
Synchronous | 4 4
ERROR: LoadError: Some tests did not pass: 303 passed, 1 failed, 0 errored, 0 broken.
in expression starting at /home/ufechner/.julia/packages/Modia/UQ96g/test/runtests.jl:9
ERROR: Package Modia errored during testing
Any idea?
I wanted to try Test_Media but got:
`julia> include("$(Modia.ModiaDir)/src/models/Test_Media.jl")
ERROR: LoadError: ArgumentError: Package Media not found in current path:
Pkg.add("Media")
to install the Media package.Stacktrace:
[1] require(::Module, ::Symbol) at .\loading.jl:817
[2] include at .\boot.jl:317 [inlined]
[3] include_relative(::Module, ::String) at .\loading.jl:1038
[4] include(::Module, ::String) at .\sysimg.jl:29
[5] include(::String) at .\client.jl:388
[6] top-level scope at none:0
in expression starting at C:\Users\Hilding Elmqvist.julia\packages\Modia\kJUT1\src\models\Test_Media.jl:45`
However, the Media module is present in the file.
Even last week I was able to use Modia with no complications. Today I was trying to continue my work but now I can't even open Modia. This is what appears to me:
julia> using Modia
[ Info: Precompiling Modia [cb905087-75eb-5f27-8515-1ce0ec8e839e]
Welcome to Modia - Dynamic Modeling and Simulation with Julia
Version 0.2.2 (2018-10-12)
Type "?Modia" for help.
Importing ModiaMath version 0.2.6 from 2018-12-02 14:35
ERROR: LoadError: LoadError: LoadError: LoadError: LoadError: MethodError: no method matching replace_value(::Symbol)
Closest candidates are:
replace_value(::Any, ::Expr) at /home/tsantos/.julia/packages/Unitful/A3sNy/src/user.jl:500
replace_value(::Any, ::Symbol) at /home/tsantos/.julia/packages/Unitful/A3sNy/src/user.jl:525
replace_value(::Any, ::Number) at /home/tsantos/.julia/packages/Unitful/A3sNy/src/user.jl:555
Stacktrace:
[1] replace_value(::Symbol) at /home/tsantos/.julia/packages/Modia/kJUT1/src/language/Unitful_U_str.jl:56
[2] @U_str(::LineNumberNode, ::Module, ::Any) at /home/tsantos/.julia/packages/Modia/kJUT1/src/language/Unitful_U_str.jl:27
[3] #macroexpand#32 at ./expr.jl:92 [inlined]
[4] macroexpand at ./expr.jl:91 [inlined]
[5] docm(::LineNumberNode, ::Module, ::Any, ::Any, ::Bool) at ./docs/Docs.jl:509 (repeats 2 times)
[6] @doc(::LineNumberNode, ::Module, ::String, ::Vararg{Any,N} where N) at ./boot.jl:451
[7] include at ./boot.jl:317 [inlined]
[8] include_relative(::Module, ::String) at ./loading.jl:1044
[9] include at ./sysimg.jl:29 [inlined]
[10] include(::String) at /home/tsantos/.julia/packages/Modia/kJUT1/src/Modia.jl:46
[11] top-level scope at none:0
[12] include at ./boot.jl:317 [inlined]
[13] include_relative(::Module, ::String) at ./loading.jl:1044
[14] include at ./sysimg.jl:29 [inlined]
[15] include(::String) at /home/tsantos/.julia/packages/Modia/kJUT1/src/Modia.jl:46
[16] top-level scope at none:0
[17] include at ./boot.jl:317 [inlined]
[18] include_relative(::Module, ::String) at ./loading.jl:1044
[19] include(::Module, ::String) at ./sysimg.jl:29
[20] top-level scope at none:2
[21] eval at ./boot.jl:319 [inlined]
[22] eval(::Expr) at ./client.jl:393
[23] top-level scope at ./none:3
in expression starting at /home/tsantos/.julia/packages/Modia/kJUT1/src/models/Rotational.jl:20
in expression starting at /home/tsantos/.julia/packages/Modia/kJUT1/src/models/Rotational.jl:18
in expression starting at /home/tsantos/.julia/packages/Modia/kJUT1/src/models/Rotational.jl:18
in expression starting at /home/tsantos/.julia/packages/Modia/kJUT1/src/models/models.jl:3
in expression starting at /home/tsantos/.julia/packages/Modia/kJUT1/src/Modia.jl:121
ERROR: Failed to precompile Modia [cb905087-75eb-5f27-8515-1ce0ec8e839e] to /home/tsantos/.julia/compiled/v1.0/Modia/CBgbi.ji.
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] macro expansion at ./logging.jl:311 [inlined]
[3] compilecache(::Base.PkgId, ::String) at ./loading.jl:1190
[4] macro expansion at ./logging.jl:309 [inlined]
[5] _require(::Base.PkgId) at ./loading.jl:947
[6] require(::Base.PkgId) at ./loading.jl:858
[7] macro expansion at ./logging.jl:309 [inlined]
[8] require(::Module, ::Symbol) at ./loading.jl:840
Does everyone know what's going on?
Thanks in advance
Hi,
I am trying to create model similar to SpeedControl2 in the SynchronousExamples testset. While the model named SpeedControl(which does not use the connect mechanism) works, SpeedControl2 (which uses the connect mechanism to couple the controller and the model) does not work. The following error occurs "ERROR: LoadError: UndefVarError: c.u not defined".
I assume this may be the reason for it not being run in the test set.
Kindly, could you let me know the reasons behind this failure, and if there are any workarounds. I have attached a script file with just SpeedControl2 code and the stacktrace as post script.
Thanks and Regards
Jagir
removeSingularities = false
Simulating model: SpeedControl2
Number of equations: 10
Number of variables: 13
Number of continuous states: 3
ERROR: LoadError: UndefVarError: c.u not defined
Stacktrace:
[1] top-level scope at none:0
[2] eval at .\boot.jl:319 [inlined]
[3] eval at .julia\packages\Modia\kJUT1\src\language\Execution.jl:10 [inlined]
[4] macro expansion at .\show.jl:555 [inlined]
[5] #prepare_ida#5(::Bool, ::Bool, ::Function, ::Modia.Instantiation.Instance, ::Array{Symbol,1}, :
:Dict{Symbol,Any}) at .julia\packages\Modia\kJUT1\src\language\Execution.jl:441
[6] (::getfield(Modia.Execution, Symbol("#kw##prepare_ida")))(::NamedTuple{(:store_eliminated, :nee
d_eliminated_f),Tuple{Bool,Bool}}, ::typeof(Modia.Execution.prepare_ida), ::Modia.Instantiation.Inst
ance, ::Array{Symbol,1}, ::Dict{Symbol,Any}) at .\none:0
[7] #simulate_ida#12(::Bool, ::Float64, ::Float64, ::Bool, ::Function, ::Modia.Instantiation.Instan
ce, ::Array{Float64,1}, ::Nothing) at .julia\packages\Modia\kJUT1\src\language\Execution.jl:590
[8] (::getfield(Modia.Execution, Symbol("#kw##simulate_ida")))(::NamedTuple{(:log,),Tuple{Bool}}, :
:typeof(Modia.Execution.simulate_ida), ::Modia.Instantiation.Instance, ::Array{Float64,1}, ::Nothing
) at .\none:0
[9] #simulate_ida#11 at .julia\packages\Modia\kJUT1\src\language\Execution.jl:573
[inlined]
[10] #simulate_ida at .\none:0 [inlined]
[11] #simulateModelWithOptions#7(::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol,Symbol},NamedTuple
{(:removeSingularities, :logSimulation),Tuple{Bool,Bool}}}, ::Function, ::Modia.Instantiation.Model,
::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}) at .julia\packages\Modia\kJUT1\src\symbolic\ModelElaboration.jl:359
[12] #simulate#9 at .\none:0 [inlined]
[13] (::getfield(Modia.ModelElaboration, Symbol("#kw##simulate")))(::NamedTuple{(:removeSingulariti
es, :logSimulation),Tuple{Bool,Bool}}, ::typeof(Modia.ModelElaboration.simulate), ::Modia.Instantiat
ion.Model, ::Float64) at .\none:0
[14] top-level scope at none:0
in expression starting at synchronoustest.jl:53
synchronoustest.txt
The examples/test in the examples/test directory use import/using statements, besides import Modia
. With the Julia 1.0 package manager, the versions of these packages are not defined. This might either just give a warning (as for Test, and Julia manages it), or it depends on the packages that the user has already loaded in his/her environment and then an error or no error might occur depending on this environment.
I have found a reasonable solution for this for ModiaMath and described it here.
I suggest to use this solution also for Modia.
Since Martin updated ModiaMath to version 0.2.2, I tried installing Modia on a clean installation of Julia 1.0. Unfortunately, I get some errors:
(v1.0) pkg> add Modia#master
Updating git-repo https://github.com/ModiaSim/Modia.jl.git
Resolving package versions...
ERROR: Unsatisfiable requirements detected for package ModiaMath [80923050]:
ModiaMath [80923050] log:
├─ModiaMath [80923050] has no known versions!
└─restricted to versions * by Modia [e4773e00] — no versions left
└─Modia [e4773e00] log:
├─possible versions are: 0.2.0 or uninstalled
└─Modia [e4773e00] is fixed to version 0.2.0-beta.12
Does it make sense to have a new release of Modia that is compatible with Julia 1.0? Or is there another way to get Modia to install given this new release of ModiaMath?
julia> using Modia
INFO: Precompiling module StaticArrays.
INFO: Precompiling module Unitful.
INFO: Precompiling module Sundials.
Welcome to Modia - Dynamic Modeling and Simulation with Julia
Version 0.2.0-beta.1 (2018-08-03)
Type "?Modia" for help.
ERROR: LoadError: LoadError: ArgumentError: Module SIUnits not found in current path.
Run `Pkg.add("SIUnits")` to install the SIUnits package.
The links don't work, probably because the slides folder was moved into the doc folder.
I have a model which sets initial values in a sub-model, but the initial values do not seem to propagate to the main model. The modia code (which is similar to my model) is:
@model SubModel begin
b = Float(start = 1.0)
end
@model MainModel begin
a = Float()
sMod = SubModel()
@equations begin
a = sMod.b
der(a) = 0.01
end
end
result = simulate(MainModel, 1.0)
which is simulated as:
Simulating model: MainModel
Number of equations: 2
Number of variables: 3
Number of continuous states: 1
... ModiaMath.simulate! (version 0.3.0 from 2018-12-04 11:57) to simulate model: MainModel
Dict{AbstractString,Any} with 4 entries:
"der(a)" => [0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 … 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01]
"time" => [0.0, 0.001001, 0.002002, 0.003003, 0.004004, 0.00500501, 0.00600601, 0.00700701, 0.00800801, 0.00900901 … 0.990991, 0.991992, 0.992993, 0.993994, 0.994995, 0.995996, 0.996997, 0.997998, 0.998999, 1.0]
"a" => [0.0, 1.001e-5, 2.002e-5, 3.003e-5, 4.004e-5, 5.00501e-5, 6.00601e-5, 7.00701e-5, 8.00801e-5, 9.00901e-5 … 0.00990991, 0.00991992, 0.00992993, 0.00993994, 0.00994995, 0.00995996, 0.00996997, 0.00997998, 0.00998999, 0.01]
"sMod.b" => [0.0, 1.001e-5, 2.002e-5, 3.003e-5, 4.004e-5, 5.00501e-5, 6.00601e-5, 7.00701e-5, 8.00801e-5, 9.00901e-5 … 0.00990991, 0.00991992, 0.00992993, 0.00993994, 0.00994995, 0.00995996, 0.00996997, 0.00997998, 0.00998999, 0.01]
where a and sMod.b's initial values start from 0.0, which should start from 1.0?
If I set 'start = 1.0' for a in MainModel instead of SubModel then it works fine.
The corresponding Modelica model seems to work with a and sMod.b start from 1.0:
package TestInitialValues
model SubModel
Real b(start=1.0);
end SubModel;
model MainModel
Real a;
SubModel sMod;
equation
a = sMod.b;
der(a) = 0.01;
end MainModel;
end TestInitialValues;
Could please give any suggestion? Thanks.
With the merge of #26, I can precompile Modia on julia 1.0.0 just fine, but I cannot get an example, even a simple one like the RC Low Pass Filter, to work.
One of the errors I'm getting seems to originate from /src/symbolic/DAEquations/BasicStructuralTransform.jl#L440 where G = Array{Any}(0)
is no longer valid code. I'm not really sure what the exact type of G
should be, and trying to fix it led me down a bit of a rabbit hole with more problems popping up in the same file.
Trying to run the examples in the src/examples/
folder, I ran into several issues. I guess there were quite a few breaking changes with 0.7/1.0. I'm afraid I can't be of much help with that. Maybe someone who knows better than I what they're doing here could have a look?
These are the errors I'm getting:
Running examples/SynchronousExamples.jl
gives:
Synchronous: Error During Test at /net/store/ni/users/jleugeri/julia/dev/Modia/examples/SynchronousExamples.jl:14
Got exception outside of a @test
MethodError: no method matching Array{Any,N} where N(::Int64)
Closest candidates are:
Array{Any,N} where N(!Matched::UndefInitializer, !Matched::Int64) where T at boot.jl:408
Array{Any,N} where N(!Matched::UndefInitializer, !Matched::Int64, !Matched::Int64) where T at boot.jl:409
Array{Any,N} where N(!Matched::UndefInitializer, !Matched::Int64, !Matched::Int64, !Matched::Int64) where T at boot.jl:410
...
Stacktrace:
[1] analyzeStructurally(::Array{Any,1}, ::DataStructures.OrderedDict{Symbol,Any}, ::Dict{Symbol,Int64}, ::Array{Any,1}, ::Array{Symbol,1}, ::Array{Int64,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Int64, ::Array{Any,1}, ::typeof(Modia.StructuralTransform.findIncidence!), ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::DataStructures.OrderedDict{Symbol,Any}, ::Bool) at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/DAEquations/BasicStructuralTransform.jl:440
[2] transformStructurally(::Modia.Instantiation.Instance) at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/StructuralTransform.jl:696
[3] elaborateModel at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/ModelElaboration.jl:109 [inlined]
[4] #simulateModelWithOptions#7(::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol,Symbol},NamedTuple{(:storeEliminated, :logSimulation),Tuple{Bool,Bool}}}, ::Function, ::Modia.Instantiation.Model, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}) at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/ModelElaboration.jl:316
[5] #simulateModelWithOptions at ./none:0 [inlined]
[6] #simulate#9 at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/ModelElaboration.jl:393 [inlined]
[7] (::getfield(Modia.ModelElaboration, Symbol("#kw##simulate")))(::NamedTuple{(:storeEliminated, :logSimulation),Tuple{Bool,Bool}}, ::typeof(simulate), ::Modia.Instantiation.Model, ::Float64) at ./none:0
[8] top-level scope at /net/store/ni/users/jleugeri/julia/dev/Modia/examples/SynchronousExamples.jl:35
[9] include at ./boot.jl:317 [inlined]
[10] include_relative(::Module, ::String) at ./loading.jl:1038
[11] include(::Module, ::String) at ./sysimg.jl:29
[12] include(::String) at ./client.jl:388
[13] macro expansion at /net/store/ni/users/jleugeri/julia/dev/Modia/examples/runexamples.jl:21 [inlined]
[14] macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Test/src/Test.jl:1083 [inlined]
[15] top-level scope at /net/store/ni/users/jleugeri/julia/dev/Modia/examples/runexamples.jl:12
[16] include at ./boot.jl:317 [inlined]
[17] include_relative(::Module, ::String) at ./loading.jl:1038
[18] include(::Module, ::String) at ./sysimg.jl:29
[19] include(::String) at ./client.jl:388
[20] top-level scope at none:0
[21] eval(::Module, ::Any) at ./boot.jl:319
[22] eval_user_input(::Any, ::REPL.REPLBackend) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:85
[23] macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:117 [inlined]
[24] (::getfield(REPL, Symbol("##28#29")){REPL.REPLBackend})() at ./task.jl:259
Running examples/CollidingBalls.jl
gives:
Simulating model: Balls3
ERROR: LoadError: UndefVarError: rsearchindex not defined
Stacktrace:
[1] substituteAllInstances(::Expr, ::Modia.Instantiation.Instance, ::Symbol, ::Bool) at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/ModelElaboration.jl:223
[2] (::getfield(Modia.ModelElaboration, Symbol("##4#6")){Modia.Instantiation.Instance,Symbol,Bool})(::Expr) at ./none:0
[3] iterate at ./generator.jl:47 [inlined]
[4] collect_to!(::Array{Any,1}, ::Base.Generator{Array{Any,1},getfield(Modia.ModelElaboration, Symbol("##4#6")){Modia.Instantiation.Instance,Symbol,Bool}}, ::Int64, ::Int64) at ./array.jl:656
[5] collect_to!(::Array{typeof(Main.TestBalls.getForce),1}, ::Base.Generator{Array{Any,1},getfield(Modia.ModelElaboration, Symbol("##4#6")){Modia.Instantiation.Instance,Symbol,Bool}}, ::Int64, ::Int64) at ./array.jl:667
[6] collect_to_with_first!(::Array{typeof(Main.TestBalls.getForce),1}, ::Function, ::Base.Generator{Array{Any,1},getfield(Modia.ModelElaboration, Symbol("##4#6")){Modia.Instantiation.Instance,Symbol,Bool}}, ::Int64) at ./array.jl:643
[7] collect(::Base.Generator{Array{Any,1},getfield(Modia.ModelElaboration, Symbol("##4#6")){Modia.Instantiation.Instance,Symbol,Bool}}) at ./array.jl:624
[8] substituteAllInstances(::Expr, ::Modia.Instantiation.Instance, ::Symbol, ::Bool) at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/ModelElaboration.jl:236
[9] (::getfield(Modia.ModelElaboration, Symbol("##4#6")){Modia.Instantiation.Instance,Symbol,Bool})(::Expr) at ./none:0
[10] iterate at ./generator.jl:47 [inlined]
[11] collect_to!(::Array{Modia.Instantiation.GetField,1}, ::Base.Generator{Array{Any,1},getfield(Modia.ModelElaboration, Symbol("##4#6")){Modia.Instantiation.Instance,Symbol,Bool}}, ::Int64, ::Int64) at ./array.jl:656
[12] collect_to_with_first!(::Array{Modia.Instantiation.GetField,1}, ::Modia.Instantiation.GetField, ::Base.Generator{Array{Any,1},getfield(Modia.ModelElaboration, Symbol("##4#6")){Modia.Instantiation.Instance,Symbol,Bool}}, ::Int64) at ./array.jl:643
[13] collect(::Base.Generator{Array{Any,1},getfield(Modia.ModelElaboration, Symbol("##4#6")){Modia.Instantiation.Instance,Symbol,Bool}}) at ./array.jl:624
[14] substituteAllInstances(::Expr, ::Modia.Instantiation.Instance, ::Symbol, ::Bool) at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/ModelElaboration.jl:236
[15] traverseAndSubstituteAllInstances(::Symbol, ::Modia.Instantiation.Instance, ::Modia.Instantiation.Instance, ::Bool) at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/ModelElaboration.jl:250
[16] traverseAndSubstituteAllInstances(::Expr, ::Modia.Instantiation.Instance, ::Modia.Instantiation.Instance, ::Bool) at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/ModelElaboration.jl:245
[17] macro expansion at ./util.jl:155 [inlined]
[18] #simulateModelWithOptions#7(::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol,Symbol},NamedTuple{(:expandArrayIncidence, :storeEliminated),Tuple{Bool,Bool}}}, ::Function, ::Modia.Instantiation.Model, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}) at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/ModelElaboration.jl:295
[19] #simulateModelWithOptions at ./none:0 [inlined]
[20] #simulate#9 at /net/store/users/jleugeri/julia/dev/Modia/src/symbolic/ModelElaboration.jl:393 [inlined]
[21] (::getfield(Modia.ModelElaboration, Symbol("#kw##simulate")))(::NamedTuple{(:expandArrayIncidence, :storeEliminated),Tuple{Bool,Bool}}, ::typeof(simulate), ::Modia.Instantiation.Model, ::Int64) at ./none:0
[22] top-level scope at none:0
[23] include at ./boot.jl:317 [inlined]
[24] include_relative(::Module, ::String) at ./loading.jl:1038
[25] include(::Module, ::String) at ./sysimg.jl:29
[26] include(::String) at ./client.jl:388
[27] top-level scope at none:0
in expression starting at /net/store/ni/users/jleugeri/julia/dev/Modia/examples/CollidingBalls.jl:86
Running examples/LinearSystems.jl
gives:
ERROR: LoadError: MethodError: no method matching resultTimeSeries(::Nothing, ::Symbol, ::Bool, ::Symbol)
Closest candidates are:
resultTimeSeries(::Dict{Symbol,AbstractArray{T,1} where T}, ::Any, ::Bool, ::Any) at /net/store/users/jleugeri/julia/packages/ModiaMath/k98Tm/src/Result/result.jl:35
resultTimeSeries(::Dict{String,AbstractArray{T,1} where T}, ::Any, ::Bool, ::Any) at /net/store/users/jleugeri/julia/packages/ModiaMath/k98Tm/src/Result/result.jl:58
resultTimeSeries(::Dict{AbstractString,Any}, ::Any, ::Bool, ::Any) at /net/store/users/jleugeri/julia/packages/ModiaMath/k98Tm/src/Result/result.jl:81
...
Stacktrace:
[1] addPlot(::Nothing, ::Symbol, ::Bool, ::Bool, ::Symbol) at /net/store/users/jleugeri/julia/packages/ModiaMath/k98Tm/src/Result/plotResult_with_PyPlot.jl:11
[2] #plot#3(::String, ::Bool, ::Symbol, ::Int64, ::Function, ::Nothing, ::Symbol) at /net/store/users/jleugeri/julia/packages/ModiaMath/k98Tm/src/Result/plotResult_with_PyPlot.jl:48
[3] (::getfield(ModiaMath.Result, Symbol("#kw##plot")))(::NamedTuple{(:heading, :grid, :xAxis, :figure),Tuple{String,Bool,Symbol,Int64}}, ::typeof(ModiaMath.Result.plot), ::Nothing, ::Symbol) at ./none:0
[4] #plot#1(::String, ::Bool, ::Symbol, ::Int64, ::Function, ::Nothing, ::String) at /net/store/users/jleugeri/julia/packages/ModiaMath/k98Tm/src/Result/plotResult.jl:87
[5] (::getfield(ModiaMath.Result, Symbol("#kw##plot")))(::NamedTuple{(:heading, :figure),Tuple{String,Int64}}, ::typeof(ModiaMath.Result.plot), ::Nothing, ::String) at ./none:0
[6] top-level scope at none:0
[7] include at ./boot.jl:317 [inlined]
[8] include_relative(::Module, ::String) at ./loading.jl:1038
[9] include(::Module, ::String) at ./sysimg.jl:29
[10] include(::String) at ./client.jl:388
[11] top-level scope at none:0
in expression starting at /net/store/ni/users/jleugeri/julia/dev/Modia/examples/LinearSystems.jl:19
As discussed offline as well as in ModiaSim/ModiaMath.jl#10, we should not attempt to maintain a codebase against several language versions simultaneously. As I said in that issue:
A pretty standard (and much less painful way, IMO) to continue maintaining support for older language major versions is to cut separate release branches for the different Modia major versions you wish to continue to support, and then backport any changes that need backporting. That way, you can support all the language version you want, but don't need to maintain a single codebase that supports multiple versions of the same language. It can be tricky if you have a lot of backports every update, but it's usually not too bad - even for larger packages/ecosystems (like JuMP). Dealing with fewer edge-cases makes it easier to iterate.
There are apparently a few complications to actually doing this (quoting @MartinOtter):
The trouble is that Modia and Modia3D depend on ModiaMath and neither Modia nor Modia3D have been yet fully converted to Julia 0.7/1.0 and there might be still issues in ModiaMath that need to be fixed before Modia/Modia3D have been fully converted. Furthermore, development is continuing in parallel. Therefore, the strategy is to have one version of Modia/ModiaMath/Modia3D supporting Julia 0.6, 0.7, 1.0 and making releases of these versions (and accepting that the code is not nice at some places). After these releases, the support for Julia 0.6 and 0.7 is dropped and the development of all three packages continues only on the basis of Julia 1.0.
The most critical issue preventing currently to switch to Julia 1.0 is a bug in Julia. Once this bug is fixed, switching to Julia 1.0 should be quick (a few days).
The referenced bug: JuliaLang/julia#28917
As far as I can tell, if you put docstrings before models, they are picked up fine by Julia's documentation system. Adding docs to the models in src/models
seems like a good crowd-sourced activity.
For adding docstrings for models, any guidance on what format to use?
Second question: for adding docstrings, is it okay to adapt text from the Modelica Standard Library equivalents? As far as I can tell, the Modelica license allows such adaptations. I have some docs from Sims I could adapt, but many of these were adapted from the MSL.
The following Modia codes work fine and are consistent with Dymola/Modelica and OMEdit/Modelica:
using Modia
@model Pin begin
v = Float()
i = Float(flow = true)
end
@model PositivePin begin
@extends Pin()
@inherits v,i
end
@model NegativePin begin
@extends Pin()
@inherits v,i
end
@model Ground begin
ground = PositivePin()
@equations begin
ground.v = 0
end
end
@model PartialTwoPin begin
p = PositivePin()
n = NegativePin()
v = Float()
i = Float()
@equations begin
v = p.v - n.v
i = p.i
p.i + n.i = 0.0
end
end
@model Resistor begin
R = Parameter(1.0)
@extends PartialTwoPin()
@inherits v,i
@equations begin
v = i*R
end
end
@model Capacitor begin
C = Parameter(1.0)
@extends PartialTwoPin()
@inherits v,i
@equations begin
C*der(v) = i
end
end
@model Inductor begin
L = Parameter(1.0)
@extends PartialTwoPin()
@inherits v,i
@equations begin
L*der(i) = v
end
end
@model StepVoltage begin
V0 = Parameter(0.0)
Vf = Parameter(1.0)
stepTime = Parameter(1.0)
@extends PartialTwoPin()
@inherits v
@equations begin
v = if (time >= stepTime)
Vf
else
V0
end
end
end
@model SwitchedRLC begin
Vs = StepVoltage(V0 = 0, Vf = 24, stepTime=0.5)
inductor = Inductor(L = 1, i = Float(start=0.0))
capacitor = Capacitor(C = 1e-3, v = Float(start=0.0))
resistor = Resistor(R = 100)
ground = Ground()
@equations begin
connect(inductor.n, resistor.n)
connect(capacitor.n, inductor.n)
connect(inductor.p, Vs.p)
connect(capacitor.p, ground.ground)
connect(resistor.p, ground.ground)
connect(Vs.n, ground.ground)
end
end
However, when I remove the capacitor from the SwitchedRLC:
@model SwitchedRLC begin
Vs = StepVoltage(V0 = 0, Vf = 24, stepTime=0.5)
inductor = Inductor(L = 1, i = Float(start=0.0))
resistor = Resistor(R = 100)
ground = Ground()
@equations begin
connect(inductor.n, resistor.n)
connect(inductor.p, Vs.p)
connect(resistor.p, ground.ground)
connect(Vs.n, ground.ground)
end
end
I have error:
ERROR: LoadError: The number of scalarized unknowns (= 21) is not equal to the number of scalarized equations (= 22).
If option `simulate(<model>, ...; logTranslation=true)` is set, inspect <user>/ModiaResults/<model>.txt for more info.
but the corresponding models work fine in Dymola/Modelica and OMEdit/Modelica. My guess is that the following connections:
connect(resistor.p, ground.ground)
connect(Vs.n, ground.ground)
generate some additional equation?
Also, it says "inspect /ModiaResults/.txt", but I cannot find this file to look at the generated equations?
Please help. Thank you!
I have been trying to implement a simple model, and ran across some odd behavior for a source implementing a step function. The output of the model appears to be equal to 1.0 for all time, regardless of the value of the if statement in its definition. Modia.Blocks.Step appears to have the same behavior.
A MWE is as follows:
using Modia, ModiaMath
using Modia.Electric
using Modia.Rotational
@model Step2 begin
height = Parameter(1.0, info="Height of pulse")
offset = Parameter(0.0, info="Offset of output signal")
startTime = Parameter(0.0, info="Output y = offset of time < startTime")
y = Variable(info="Output signal")
@equations begin
y = if (time < startTime); 0.0 else height end;
end
end;
result = simulate(Step2, 3)
Simulating model: Step2
Number of equations: 1
Number of variables: 1
Number of continuous states: 0
Dict{AbstractString,Any} with 5 entries:
"height" => 1.0
"startTime" => 0.0
"time" => [0.0, 0.003003, 0.00600601, 0.00900901, 0.012012, 0.015015, 0.018018, 0.021021, 0.024024, 0.027027 … …
"offset" => 0.0
"y" => [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 … 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
"y" = 1 for the duration of the simulation, despite my intent and all best efforts to the contrary. I would appreciate any suggestions for getting this to work or understanding where bugs in the code may lie.
Which GUI was used to create the schematic diagrams in the README.md?
Hey, are you guys still here? We should chat a little bit
I just want to know how if for loops can be used inside the @equations
macro, of if not, are there alternatives for for loops?
Thanks
The .jl
on the end of the name is standard for Julia packages and helps with google searches.
I'm looking forward to seeing this released!! Exciting.
Modia does not yet support the Julia Complex data type. Work has been started by me and @toivoh. We need to implement allocation of Complex into the Float vector used in the DAE integration routines.
As a comparison with Modelica, the Modelica Standard Library contains a package of overloaded operator functions toto support Complex data type. Such a package will not be needed for Modia.
Hi,
In the README file it says that there's a prototype code for sparse jacobian handling, and that prototype codes are available through flags. Such a flag is not represented in the examples and I was trying to find it in the core code. Does such a flag exist?
Thanks in advance.
Hi. The relevant bits of code for connecting electrical components stored in an array are commented out in test/models/TestArrayOfComponents.jl (fixed link) as not working
, so I was wondering, as the title suggests, if there is a current workaround to connect arrays of components like resistors and capacitors? If not (and it's not a monumental task to do that), is there a way to help with implementing this feature? That would make it possible to write much more compact model descriptions that would be the last nail in the coffin of SPICE for me ;)
I know it is supposed to work only in Julia v0.6, but I believe it should be reflected in the Issues.
julia> using Modia
[ Info: Precompiling Modia [cb905087-75eb-5f27-8515-1ce0ec8e839e]
ERROR: LoadError: LoadError: UndefVarError: @doc_str not defined
Stacktrace:
[1] top-level scope
[2] top-level scope at none:2
in expression starting at /home/jose/.julia/packages/Modia/A9BVO/src/Modia.jl:12
in expression starting at /home/jose/.julia/packages/Modia/A9BVO/src/Modia.jl:12
ERROR: Failed to precompile Modia [cb905087-75eb-5f27-8515-1ce0ec8e839e] to /home/jose/.julia/compiled/v1.0/Modia/CBgbi.ji.
Resolving the typeof(F) problem in Julialang issue #28917 unfortunately does not help getting Modia to run in Julia 1.0 since typeof(F) was not in the original Execution.jl code. It was introduced when Modia was decoupled from ModiaMath for isolation of the gc problem.
I just tested Modia in Julia Version 1.1.0-DEV.69 (2018-08-20) (nightly for Windows):
]add ModiaMath#master
]add Modia#master
]add Unitful
]add StaticArrays
]add Pyplot
using Modia
@time include("$(Modia.ModiaDir)/test/runtests.jl")
and got:
Welcome to Modia - Dynamic Modeling and Simulation with Julia
Version 0.2.0-beta.11 (2018-09-08)
...
GC error (probable corruption) :
Allocations: 176064029 (Pool: 175991605; Big: 72424); GC: 404
...
The GC error occurs after some simulations have been made. Sometimes alread during:
Simulating model: TestVariableTypes1
Stefan K. pointed out that: Keno has fixed a bunch of GC rooting issues recently.
So we should test using Julia#master. I don't know how to get Julia#master running on Windows. Could someone help out by running Modia#master as above to investigate if the GC bug is still there or hopefully not.
I'm confused by what these fields are used for. The result of Electric.Voltage()
is a Variable
with proper units (V
) set in the typ
field (via T
). The unit
and displayUnit
fields don't have units.
Is this right? How are unit
and displayUnit
supposed to be filled?
gives me error:
(v1.0) pkg> add Modia
Updating registry at ~/.julia/registries/General
Updating git-repo https://github.com/JuliaRegistries/General.git
Resolving package versions...
ERROR: Unsatisfiable requirements detected for package Modia [cb905087]:
Modia [cb905087] log:
├─possible versions are: 0.2.0-0.2.1 or uninstalled
├─restricted to versions * by an explicit requirement, leaving only versions 0.2.0-0.2.1
└─restricted by julia compatibility requirements to versions: uninstalled — no versions left
I was trying to construct an example of a rotational system today, and ran into some problems when coupling two inertias to either side of a spring damper. When I try to simulate the final model, I get a method error: MethodError: no method matching -(::Float64, ::Array{Float64,0})
. I constructed the same model in Dymola and ran it without problems. Any thoughts on how to address this problem (should my model be reformulated somehow? Is this functionality not expected to work yet in Modia?) would be much appreciated.
Many of these models are similar to those in Modia.Rotational, but I had redefine them to allow the compiler to select phi_rel as a state in PartialCompliant2.
using Modia, ModiaMath
using Modia.Blocks
using Modia.Rotational
@model Pulse begin
height = Parameter(1.0, info="Height of pulse")
offset = Parameter(0.0, info="Offset of output signal")
startTime = Parameter(0.0, info="Output y = offset of time < startTime")
duration = Parameter(1.0, info="Duration of pulse")
y = Variable(info="Output signal")
@equations begin
y = (time < startTime) ? 0.0 : (time < (startTime + duration)) ? height : 0.0
end
end;
@model AngleSensor begin
phi=Modia.Rotational.Angle()
flange=Flange()
@equations begin
0=flange.tau
phi=flange.phi
end
end;
@model PartialCompliant2 begin
phi_rel = Modia.Rotational.Angle(start=0.0)
tau = Modia.Rotational.TorqueVar()
flange_a = Flange(info = "Left flange of shaft")
flange_b = Flange(info = "Right flange of shaft")
@equations begin
phi_rel = flange_b.phi - flange_a.phi
flange_b.tau = tau
flange_a.tau = -tau
end
end;
@model SpringDamper2 begin
c = Parameter(min = 0, start = 1.0e5, info = "Spring constant", T = U"N*m/rad")
d = Parameter(info = "Damping constant", T = U"N*m*s/rad")
phi_rel0 = Parameter(0.0, start = 0.0, info = "Unstretched spring angle", T = U"rad")
w_rel = Variable(start=0.0)
@extends PartialCompliant2()
@inherits tau, phi_rel
@equations begin
w_rel = der(phi_rel)
tau = c * (phi_rel - phi_rel0) + d * w_rel
end
end;
@model SysTest1 begin
pulse=Pulse(startTime=1)
torque=Torque()
inertia1=Inertia(J=0.1)
springDamper=SpringDamper2(c=10, d=0.1)
inertia2=Inertia(J=10)
angleSensor=AngleSensor()
@equations begin
connect(pulse.y, torque.tau)
connect(torque.flange, inertia1.flange_a)
connect(inertia1.flange_b, springDamper.flange_a)
connect(springDamper.flange_b, inertia2.flange_a)
connect(inertia2.flange_b, angleSensor.flange)
end
end;
result=simulate(SysTest1, 3)
Simulating model: SysTest1
Number of equations: 29
Number of variables: 33
Number of continuous states: 5
Number of non states: 1
MethodError: no method matching -(::Float64, ::Array{Float64,0})
Closest candidates are:
-(::Float64, !Matched::Float64) at float.jl:397
-(::Float64) at float.jl:387
-(!Matched::PyCall.PyObject, ::Any) at C:\Users\laughman\.julia\packages\PyCall\0jMpb\src\pyoperators.jl:14
...
Stacktrace:
[1] top-level scope at none:0
[2] eval at .\boot.jl:319 [inlined]
[3] eval at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\language\Execution.jl:10 [inlined]
[4] macro expansion at .\show.jl:555 [inlined]
[5] #prepare_ida#5(::Bool, ::Bool, ::Function, ::Modia.Instantiation.Instance, ::Array{Symbol,1}, ::Dict{Symbol,Any}) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\language\Execution.jl:441
[6] (::getfield(Modia.Execution, Symbol("#kw##prepare_ida")))(::NamedTuple{(:store_eliminated, :need_eliminated_f),Tuple{Bool,Bool}}, ::typeof(Modia.Execution.prepare_ida), ::Modia.Instantiation.Instance, ::Array{Symbol,1}, ::Dict{Symbol,Any}) at .\none:0
[7] #simulate_ida#12(::Bool, ::Float64, ::Float64, ::Bool, ::Function, ::Modia.Instantiation.Instance, ::Array{Float64,1}, ::Nothing) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\language\Execution.jl:591
[8] (::getfield(Modia.Execution, Symbol("#kw##simulate_ida")))(::NamedTuple{(:log,),Tuple{Bool}}, ::typeof(Modia.Execution.simulate_ida), ::Modia.Instantiation.Instance, ::Array{Float64,1}, ::Nothing) at .\none:0
[9] #simulate_ida#11 at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\language\Execution.jl:574 [inlined]
[10] #simulate_ida at .\none:0 [inlined]
[11] #simulateModelWithOptions#7(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Modia.Instantiation.Model, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\ModelElaboration.jl:359
[12] #simulate#9 at .\none:0 [inlined]
[13] simulate(::Modia.Instantiation.Model, ::Int64) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\ModelElaboration.jl:424
[14] top-level scope at In[7]:1
I am continuing to work on the example referred to in #58, and have run into a different problem. Rather than drive the system with a torque, I am trying to drive it with a position, and have Modia calculate the torque signal required to achieve the particular output. This is a classic InverseBlockConstraints problem from Modelica that I am trying to implement in Modia. I am not using an InverseBlockConstraints block, since Modia has no semantics for input/output (as far as I know), but have tried implementing the InverseBlockConstraints model anyways in Modia and it doesn't change the behavior of the model.
I can now simulate the system when I drive the torque with an input source, but I get an error type Global has no field head
when I drive the position sensor with a desired angle. I enabled logging and looked at the flattened and structurally processed system, but can't find many clues to the source of this problem.
I have updated and cleaned up these models slightly from the previous issue, and am re-including them here.
using Modia, ModiaMath
using Modia.Blocks
using Modia.Rotational
@model Pulse begin
height = Parameter(1.0, info="Height of pulse")
duration = Parameter(1.0, info="Duration of pulse")
@extends Modia.Blocks.SignalSource()
@inherits y, offset, startTime
@equations begin
y = (time < startTime) ? 0.0 : (time < (startTime + duration)) ? height : 0.0
end
end;
@model AngleSensor begin
phi=Modia.Rotational.Angle()
flange=Flange()
@equations begin
0=flange.tau
phi=flange.phi
end
end;
@model ExpSine begin
amplitude = Parameter(1.0, info="Amplitude of sine wave")
freqHz = Parameter(2.0, info="Frequency of sine wave")
phase = Parameter(0.0, info="Phase of sine wave")
damping = Parameter(start=1.0, info="Damping coefficient of sine wave")
offset = Parameter(0.0, info="Offset of output signal")
startTime = Parameter(0.0, info="Output = offset for time < startTime")
@extends Modia.Blocks.SO()
@inherits y
@equations begin
y = offset + (time < startTime ? 0 : amplitude*exp(-
(time - startTime)*damping)*sin(2*pi*freqHz*(time -
startTime) + phase));
end
end;
@model SysTest2a begin
u = Float(info="input")
torque = Torque()
inertia1 = Inertia(J=0.1)
springDamper = SpringDamper(c=10, d=0.1)
inertia2 = Inertia(J=10)
angleSensor = AngleSensor()
expSine = ExpSine(freqHz=2, damping=0.5)
@equations begin
connect(u, torque.tau)
connect(torque.flange, inertia1.flange_a)
connect(inertia1.flange_b, springDamper.flange_a)
connect(springDamper.flange_b, inertia2.flange_a)
connect(inertia2.flange_b, angleSensor.flange)
connect(angleSensor.phi, expSine.y)
end
end;
result2 = simulate(SysTest2a, 10, removeSingularities=false, logTranslation=true, logSimulation=true)
logTranslation = true
removeSingularities = false
Log file: C:\Users\laughman/C:\Users\laughman/ModiaResults/SysTest2a.txt
Simulating model: SysTest2a
Number of equations: 63
Number of variables: 64
Number of continuous states: 4
Number of non states: 1
type Global has no field head
Stacktrace:
[1] getproperty(::Any, ::Symbol) at .\sysimg.jl:18
[2] differentiate(::Modia.Instantiation.Global) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\DAEquations\SymbolicTransform.jl:610
[3] differentiate(::Expr) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\DAEquations\SymbolicTransform.jl:660 (repeats 2 times)
[4] differentiate(::Expr) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\DAEquations\SymbolicTransform.jl:689
[5] differentiate(::Expr) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\DAEquations\SymbolicTransform.jl:758
[6] differentiate(::Expr) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\DAEquations\SymbolicTransform.jl:689
[7] differentiate(::Expr) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\DAEquations\SymbolicTransform.jl:632
[8] differentiate(::Expr) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\DAEquations\SymbolicTransform.jl:660
[9] differentiate(::Expr) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\DAEquations\SymbolicTransform.jl:611
[10] differentiateEquations(::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Int64,1}, ::Array{Int64,1}, ::Array{Int64,1}, ::Int64) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\DAEquations\SymbolicTransform.jl:877
[11] differentiateSortedEquations(::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Int64,1}, ::Array{Int64,1}, ::Array{Int64,1}) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\DAEquations\SymbolicTransform.jl:982
[12] macro expansion at .\util.jl:154 [inlined]
[13] elaborateModel(::Modia.Instantiation.Instance) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\ModelElaboration.jl:134
[14] #simulateModelWithOptions#7(::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol,Symbol,Symbol},NamedTuple{(:removeSingularities, :logTranslation, :logSimulation),Tuple{Bool,Bool,Bool}}}, ::Function, ::Modia.Instantiation.Model, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}) at C:\Users\laughman\.julia\packages\Modia\kJUT1\src\symbolic\ModelElaboration.jl:351
[15] #simulate#9 at .\none:0 [inlined]
[16] (::getfield(Modia.ModelElaboration, Symbol("#kw##simulate")))(::NamedTuple{(:removeSingularities, :logTranslation, :logSimulation),Tuple{Bool,Bool,Bool}}, ::typeof(simulate), ::Modia.Instantiation.Model, ::Int64) at .\none:0
[17] top-level scope at In[77]:1
Due to a bug in ModiaMath (see issue), ModiaMath.plot on arrays does not work. In order that runtests.jl works, temporarily deactivated ModiaMath.plot(...) calls that plot an array:
I have this strange behavior. I use Modia 0.2.3-beta.5 with ModiaMath 0.3.0.
The following simple model simulates fine:
using Modia
@model PartialTest begin
a = Float()
b = Float()
c = Float()
d = Float()
e = Float()
@equations begin
a = 0.1
b = 1
d = 0.1
0 = d+e
b+a = c
end
end;
but when I switch the last equation "b+a=c" into "b*a=c", I got this error:
Simulating model: PartialTest
ERROR: The number of scalarized unknowns (= 5) is not equal to the number of scalarized equations (= 6).
Thank you!
It'd be nice to have a way to look up information on a model component. For example, I'd like to be able to see what parameters and connections are available for Modia.Electric.Resistor
. The manual option is just to include this stuff in the docstrings, but it'd be nicer if it were auto-generated. A show
method for Modia.Instantiation.Model
could be defined to show this information. It might also be nice to have helper functions to return this sort of information.
IIUC, Modia currently dynamically instantiates Julia Module
s and directly eval
s code into them in order to construct models. I have some questions here:
eval
...
Executing code via eval
is essentially saying "dynamically evaluate the given Expr
at top-level within the given Module
". From the perspective of a local callsite, the Julia compiler can assume very little about what an eval
invocation will do to the state of the runtime. It certainly can't optimize through an eval
invocation, and it can't even know, for example, whether or not locally valid definitions of top-level constructs (e.g. methods) will be invalidated by the eval
invocation (which is why invokelatest
has to exist).
AFAIK, no other Julia-based modeling language takes this Module
/eval
approach. Instead, most Julia-based modeling languages represent their programs via custom data structures (if the language has separate semantics from Julia itself) and/or via normal Julia functions (if the language's semantics are a near-superset of Julia's). Some DSLs utilize macro-based front-ends, performing extra syntax checking at parse time (within the macro) and/or at runtime (via type propagation in the generated code), while others try to extract a reasonable program representation directly from Julia code via operator overloading/tracing/source code analysis/etc.
With so many potential strategies that already have found success in the Julia ecosystem, what is the advantage of a strategy that relies so heavily on traditionally dangerous escape hatches like eval
?
It is certainly possible that eval
ing into dynamically constructed Module
s is actually the appropriate design for some task; for example, it's what we do in Cassette, but that's to handle extremely specific situations where Cassette is essentially interacting directly with the Julia compiler/runtime. It doesn't seem like the same thing is going on here, though I could be mistaken.
Am I right that tests are currently broken on master? I've tried Julia v0.6.4 and v1.0.0 on Linux and Windows.
Modia allows to use arrays of components (test/models/TestArrayOfComponents.jl). However, there are no provisions yet to connect such array component elements. I and @toivoh have started to experiment.
It would be nice to have a delay
function. This needs dynamic access to variable history.
I am working on a recursive descent parser for Modelica written in Julia in order to automatically translate more Modelica models as test cases for Modia.
There is a fair bit of stylistic inconsistency across the Modia/ModiaMath codebases, both in self-consistency and in consistency with the Julia style guide. This can be a surprisingly large barrier to retaining and iterating with new contributors.
To resolve this, ModiaSim should adopt a style guide. This has already been done in various other large Julia projects (notably http://www.juliaopt.org/JuMP.jl/latest/style.html). I've also been developing a style guide derived from some of the JuMP style guide's ideas, the Base style guide, and my own years of Julia experience. My own packages moving forward will conform to this new guide.
ModiaSim doesn't have to adopt an existing guide if they wouldn't like to (though that would probably be easiest) - you could just roll our own if you'd like.
import Modia
(latest from master) gives the warning:
WARNING: using ModiaLogging.setOptions in module Instantiation conflicts with an existing identifier.
This should be fixed
Hi,
I tried to use quantities defined with units, say, 1.0u"V" in Modia models. Unfortunately, I get the following error "ERROR: LoadError: promotion of types Quantity... failed to change any arguments"
However, If I do not specify the units, then the model gets instantiated and solves. My setup details are
Julia Version 1.0.1 (2018-09-29)
Modia Version 0.2.2 2018-10-12
OS Windows 7
The sample model based on the given LPFilter example but with units and the error is given below. I would grateful, if you could share you comments and thoughts about this.
Thanks and Regards
Jagir
using Modia
using Modia.Electric
using Unitful
@model LPfilter begin
R=Resistor(R=100.0u"Ω")
C=Capacitor(C=2.5E-3u"F")
V=ConstantVoltage(V=10.0u"V")
@equations begin
connect(V.p, R.p)
connect(R.n, C.p)
connect(C.n, V.n)
end
end;
result = simulate(LPfilter, 2);
Simulating model: LPfilter
ERROR: LoadError: promotion of types Quantity{Float64,Unitful.Dimensions{()},Unitful.FreeUnits{(),Un
itful.Dimensions{()}}} and Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1),
Unitful.Dimension{:Length}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))},
Unitful.FreeUnits{(Unitful.Unit{:Volt,Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitfu
l.Dimension{:Length}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}}(0, 1/
/1),),Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:Length}(2//1), Unit
ful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}}} failed to change any arguments
Stacktrace:
[1] error(::String, ::String, ::String) at .\error.jl:42
[2] sametype_error(::Tuple{Quantity{Float64,Unitful.Dimensions{()},Unitful.FreeUnits{(),Unitful.Dim
ensions{()}}},Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimen
sion{:Length}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))},Unitful.FreeU
nits{(Unitful.Unit{:Volt,Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:
Length}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}}(0, 1//1),),Unitful
.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:Length}(2//1), Unitful.Dimension
{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}}}}) at .\promotion.jl:308
[3] not_sametype(::Tuple{Quantity{Float64,Unitful.Dimensions{()},Unitful.FreeUnits{(),Unitful.Dimen
sions{()}}},Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimensi
on{:Length}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))},Unitful.FreeUni
ts{(Unitful.Unit{:Volt,Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:Le
ngth}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}}(0, 1//1),),Unitful.D
imensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:Length}(2//1), Unitful.Dimension{:
Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}}}}, ::Tuple{Quantity{Float64,Unitful.Dimensions{()},U
nitful.FreeUnits{(),Unitful.Dimensions{()}}},Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{
:Current}(-1//1), Unitful.Dimension{:Length}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimensio
n{:Time}(-3//1))},Unitful.FreeUnits{(Unitful.Unit{:Volt,Unitful.Dimensions{(Unitful.Dimension{:Curre
nt}(-1//1), Unitful.Dimension{:Length}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Tim
e}(-3//1))}}(0, 1//1),),Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:L
ength}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}}}}) at .\promotion.j
l:302
[4] promote(::Quantity{Float64,Unitful.Dimensions{()},Unitful.FreeUnits{(),Unitful.Dimensions{()}}}
, ::Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:Leng
th}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))},Unitful.FreeUnits{(Unit
ful.Unit{:Volt,Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:Length}(2/
/1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}}(0, 1//1),),Unitful.Dimension
s{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:Length}(2//1), Unitful.Dimension{:Mass}(1/
/1), Unitful.Dimension{:Time}(-3//1))}}}) at .\promotion.jl:285
[5] deduceVariableAndEquationSizes(::Modia.Instantiation.Instance, ::OrderedCollections.OrderedDict
{Symbol,Any}, ::OrderedCollections.OrderedDict{Symbol,Any}, ::Array{Any,1}) at .jul
ia\packages\Modia\kJUT1\src\symbolic\StructuralTransform.jl:495
[6] transformStructurally(::Modia.Instantiation.Instance) at .julia\packages\Modia
\kJUT1\src\symbolic\StructuralTransform.jl:673
[7] elaborateModel(::Modia.Instantiation.Instance) at .julia\packages\Modia\kJUT1
src\symbolic\ModelElaboration.jl:122
[8] #simulateModelWithOptions#7(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{
}}}, ::Function, ::Modia.Instantiation.Model, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Ba
se.TwicePrecision{Float64}}) at .julia\packages\Modia\kJUT1\src\symbolic\ModelElabo
ration.jl:351
[9] #simulate#9 at .\none:0 [inlined]
[10] simulate(::Modia.Instantiation.Model, ::Int64) at .julia\packages\Modia\kJUT1
\src\symbolic\ModelElaboration.jl:424
[11] top-level scope at none:0
[12] include_string(::Module, ::String, ::String) at .\loading.jl:1005
[13] (::getfield(Atom, Symbol("##129#135")){String,String,Module})() at .julia\pac
kages\Atom\7rQ1O\src\eval.jl:125
[14] withpath(::getfield(Atom, Symbol("##129#135")){String,String,Module}, ::String) at D:\Users\rj
ag008.julia\packages\CodeTools\hB4Hy\src\utils.jl:30
[15] withpath at .julia\packages\Atom\7rQ1O\src\eval.jl:46 [inlined]
[16] #128 at .julia\packages\Atom\7rQ1O\src\eval.jl:122 [inlined]
[17] with_logstate(::getfield(Atom, Symbol("##128#134")){String,String,Module}, ::Base.CoreLogging.
LogState) at .\logging.jl:397
[18] #127 at .\logging.jl:493 [inlined]
[19] hideprompt(::getfield(Atom, Symbol("##127#133")){String,String,Module}) at .j
ulia\packages\Atom\7rQ1O\src\repl.jl:85
[20] macro expansion at .julia\packages\Atom\7rQ1O\src\eval.jl:120 [inlined]
[21] (::getfield(Atom, Symbol("##126#132")){Dict{String,Any}})() at .\task.jl:85
in expression starting at lpfilter.jl:17
Tried to install Modia on 0.7 today. Not working:
(v0.7) pkg> up
Updating registry at `~/.julia/registries/General`
Updating git-repo `https://github.com/JuliaRegistries/General.git`
Resolving package versions...
Updating `~/.julia/environments/v0.7/Project.toml`
[no changes]
Updating `~/.julia/environments/v0.7/Manifest.toml`
[no changes]
(v0.7) pkg> precompile
Precompiling project...
Precompiling Modia
[ Info: Precompiling Modia [cb905087-75eb-5f27-8515-1ce0ec8e839e]
┌ Warning: Deprecated syntax `doc" "` at /home/ufechner/.julia/packages/Modia/A9BVO/src/Modia.jl:46.
│ Use `@doc doc" "` instead.
└ @ ~/.julia/packages/Modia/A9BVO/src/Modia.jl:46
Welcome to Mod┌ Warning: `print_with_color(color, args...; kwargs...)` is deprecated, use `printstyled(args...; kwargs..., color=color)` instead.
│ caller = ip:0x0
└ @ Core :-1
ia - ┌ Warning: `print_with_color(color, args...; kwargs...)` is deprecated, use `printstyled(args...; kwargs..., color=color)` instead.
│ caller = top-level scope at none:0
└ @ Core none:0
Dynamic Mod┌ Warning: `print_with_color(color, args...; kwargs...)` is deprecated, use `printstyled(args...; kwargs..., color=color)` instead.
│ caller = top-level scope at none:0
└ @ Core none:0
eling and Simulation with Julia
Version 0.2.0-beta.2 (2018-08-08)
Type "?Modia" for help.
WARNING: importing deprecated binding Base.Pkg into Modia.
WARNING: Base.Pkg is deprecated, run `using Pkg` instead
likely near /home/ufechner/.julia/packages/Modia/A9BVO/src/Modia.jl:65
┌ Warning: `Pkg.dir(pkgname, paths...)` is deprecated; instead, do `import Modia; joinpath(dirname(pathof(Modia)), "..", paths...)`.
└ @ Pkg.API /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/Pkg/src/API.jl:454
ERROR: LoadError: LoadError: ArgumentError: Package Modia does not have DataStructures in its dependencies:
- If you have Modia checked out for development and have
added DataStructures as a dependency but haven't updated your primary
environment's manifest file, try `Pkg.resolve()`.
- Otherwise you may need to report an issue with Modia
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:830
[2] include at ./boot.jl:317 [inlined]
[3] include_relative(::Module, ::String) at ./loading.jl:1038
[4] include at ./sysimg.jl:29 [inlined]
[5] include(::String) at /home/ufechner/.julia/packages/Modia/A9BVO/src/Modia.jl:46
[6] top-level scope at none:0
[7] include at ./boot.jl:317 [inlined]
[8] include_relative(::Module, ::String) at ./loading.jl:1038
[9] include(::Module, ::String) at ./sysimg.jl:29
[10] top-level scope at none:2
[11] eval at ./boot.jl:319 [inlined]
[12] eval(::Expr) at ./client.jl:399
[13] top-level scope at ./none:3
in expression starting at /home/ufechner/.julia/packages/Modia/A9BVO/src/language/Instantiation.jl:24
in expression starting at /home/ufechner/.julia/packages/Modia/A9BVO/src/Modia.jl:77
ERROR: Failed to precompile Modia [cb905087-75eb-5f27-8515-1ce0ec8e839e] to /home/ufechner/.julia/compiled/v0.7/Modia/CBgbi.ji.
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] macro expansion at ./logging.jl:313 [inlined]
[3] compilecache(::Base.PkgId, ::String) at ./loading.jl:1185
[4] precompile(::Pkg.Types.Context) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/Pkg/src/API.jl:489
[5] do_precompile!(::Dict{Symbol,Any}, ::Array{String,1}, ::Dict{Symbol,Any}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/Pkg/src/REPLMode.jl:586
[6] #invokelatest#1(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Any, ::Any, ::Vararg{Any,N} where N) at ./essentials.jl:691
[7] invokelatest(::Any, ::Any, ::Vararg{Any,N} where N) at ./essentials.jl:690
[8] do_cmd!(::Pkg.REPLMode.PkgCommand, ::REPL.LineEditREPL) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/Pkg/src/REPLMode.jl:542
[9] #do_cmd#30(::Bool, ::Function, ::REPL.LineEditREPL, ::String) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/Pkg/src/REPLMode.jl:507
[10] do_cmd at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/Pkg/src/REPLMode.jl:503 [inlined]
[11] (::getfield(Pkg.REPLMode, Symbol("##41#44")){REPL.LineEditREPL,REPL.LineEdit.Prompt})(::REPL.LineEdit.MIState, ::Base.GenericIOBuffer{Array{UInt8,1}}, ::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/Pkg/src/REPLMode.jl:842
[12] #invokelatest#1 at ./essentials.jl:691 [inlined]
[13] invokelatest at ./essentials.jl:690 [inlined]
[14] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/REPL/src/LineEdit.jl:2261
[15] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:1029
[16] run_repl(::REPL.AbstractREPL, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:191
[17] (::getfield(Base, Symbol("##831#833")){Bool,Bool,Bool,Bool})(::Module) at ./logging.jl:311
[18] #invokelatest#1 at ./essentials.jl:691 [inlined]
[19] invokelatest at ./essentials.jl:690 [inlined]
[20] macro expansion at ./logging.jl:308 [inlined]
[21] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:340
[22] exec_options(::Base.JLOptions) at ./client.jl:252
[23] _start() at ./client.jl:432
(v0.7) pkg>
Any idea?
DAE index reduction requires that certain equations are differentiated versus time. The symbolic module of Modia contains partial differentiation of certain standard functions. A more general approach should be introduced for Modia. In particular, there will be many different fluid media functions calculating medium properties which needs to be differentiated.
The approach for Modelica is introduced in the paper Using Automatic Differentiation for Partial Derivatives of Functions in Modelica.
A good little first example might be the straightFlanksCam function which I translated to Julia:
function straightFlanksCam(
theta::Float64;
R1::Float64=1.0, # Base circle radii
R2::Float64=0.5, # Nose radii
d::Float64=2.0 # Centre distance
)
thetamod = atan(sin(theta), cos(theta)) # to get angle in interval -pi..pi
fi0 = asin((R1 - R2)/d)
if thetamod > 0
fi1 = pi/2 - fi0 - thetamod
else
fi1 = - pi/2 + fi0 - thetamod
end
fi2 = atan(R2*cos(fi0), d + R2*sin(fi0))
if abs(thetamod) > pi/2-fi0
x = R1*cos(theta)
y = R1*sin(theta)
elseif abs(thetamod) >= fi2
L = R1/cos(fi1)
x = L*cos(theta)
y = L*sin(theta)
else
L = d*cos(abs(thetamod)) + sqrt(R2^2 - d^2*sin(abs(thetamod))^2)
x = L*cos(theta)
y = L*sin(theta)
end
return r = [x, y]
end
This function is not used for index reduction but shows another need, i.e. finding the direction of the force on a body, by finding the normal to a parametric surface.
Using AD techniques could initially be tested without integration in Modia.
@MartinOtter will provide other examples involving media functions.
I needed to add:
]add Unitful
]add StaticArrays
]add Pyplot
When using Julia Version 1.1.0-DEV.69 (2018-08-20).
This should not be needed.
The @model
macro allows specialization of models such as :partial and :block:
@model Step(:block) begin
The Modelica to Modia translator #61 introduces such spcializations.
These specializations will enable better error diagnostics in the future, but are currently ignored.
I was wondering how could I implement algebraic and differential equations in the same array of variables, since der()
does not support slices.
For instance, if u = Float(start=zeros(5))
, how could I write differential equations for u[[2,4]]
and algebraic equations for u[[1,3,5]]
?
Thanks in advance
To avoid merge errors due to different TAB settings of different contributors it is useful to agree on a consistent indentation of the code, e.g. two or four spaces. Most Julia code - including ModiaMath.jl - is using four spaces, therefore I would suggest to use that.
Please comment!
using PyPlot
is present in the following files (and PyPlot commands are used):
In order that PyPlot need not be installed for TravisCL and JuliaBotCL, these PyPlot commands should be removed and/or replaced by ModiaMath.plot(..) commands.
This is currently an idea. Does it make sense?
How can duplicate effort for Modia and ModiaMath be avoided?
Most Julia packages have this, and it makes it easy to create a documentation as group effort.
Hi all,
I found something rather strange that I don't know why it doesn't work:
Assuming that I have a global constructor called pmt
which has several fields, such as model
, inlet
, NC
and equation
. My model is this:
@model model begin
Cout = Var( start=fill(0.0,pmt.NC) )
Cin = Var( start=fill(0.0,pmt.NC) )
Fin = Var( start=fill(0.0,pmt.NC) )
Fout = Var( start=fill(0.0,pmt.NC) )
τ = 1.0
Q0 = 1.0
V = 1.0
@equations begin
Cin[:] = pmt.inlet
Fin[:] = broadcast(*,Cin,Q0)
der(Cout) = pmt.equation(pmt,Cout,Cin,τ,Q0,V)
Fout[:] = broadcast(*,Cout,Q0)
end
end
pmt.model = model
If I try to simulate it with
res = simulate(pmt.model,1.0)
It says that the scalarized system is not square. However, if I do this
@model model begin
Cout = Var( start=fill(0.0,pmt.NC) )
Cin = Var( start=fill(0.0,pmt.NC) )
Fin = Var( start=fill(0.0,pmt.NC) )
Fout = Var( start=fill(0.0,pmt.NC) )
τ = 1.0
Q0 = 1.0
V = 1.0
inlet = pmt.inlet
@equations begin
Cin[:] = inlet
Fin[:] = broadcast(*,Cin,Q0)
der(Cout) = pmt.equation(pmt,Cout,Cin,τ,Q0,V)
Fout[:] = broadcast(*,Cout,Q0)
end
end
It works and gives me the expected results... Why pmt.inlet
inside the model does not work, but pmt.equation
works?
Thanks in advance!
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.