Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify version of additional Modelica libraries in ModelicaSystem #44

Closed
christiankral opened this issue Jul 2, 2021 · 13 comments

Comments

@christiankral
Copy link
Contributor

The documentation of ModelicaSystem shows the following text and example:

image

The third argument is apparently a list of additional libraries to be loaded. In the included example the library Modelica and others are loaded.

I have a user example that relies on the MSL 3.2.3:

model Test
  parameter Modelica.SIunits.Current I = 1 "Current";
equation

annotation(uses(Modelica(version="3.2.3")),
    experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.002));
end Test;

Consider the following cases after applying

using OMJulia
mod = OMJulia.OMCSession()

Case 1: Do not specify Modelica

mod.ModelicaSystem("Test.mo", "Test")
mod.simulate()
  • Everything is good, even though Modelica is not explicitly specified
  • Does mod.ModelicaSystem read the uses annotation, or why does it work?

Case 2: Specify Modelica

mod.ModelicaSystem("Test.mo", "Test", ["Modelica"])
  • A warning is caused, indicating that the wrong Modelica version is loaded
Warning: Test requested package Modelica of version 3.2.3. Modelica 4.0.0 
is used instead which states that it is only compatible with a conversion script...

Case 3: How to specify the Modelica 3.2.3 library explicitly?

  • How can I specify the version number of Modelica (or any other library) explicitly through mod.ModelicaSystem("Test.mo", "Test", ...)?
  • When I try to load the Modelica 3.2.3 library through sendExpression it seems the be loaded correctly, as no error message is drawn
  • Therefore, if I try to load the Modelica 4.0.0 library through sendExpression I would expect a warning message, as the Modelica 4.0.0 library is not compatible with model Test; the following, however, works with not error message:
OMJulia.sendExpression(mod,"load(Modelica,{\"4.0.0\"})")
mod.ModelicaSystem("Test.mo", "Test")
mod.simulate()
  • As this example draws no warning, this brings me to the conclusion, that the Modelica 4.0.0 library is not loaded / used

Summary

The main question is: How can I specify the version number of any library through mod.ModelicaSystem("Test.mo", "Test", ...)?

@adrpo
Copy link
Member

adrpo commented Jul 3, 2021

Yeah, we should make it so that you are be able to specify tuples: [("Modelica", "4.0.0"), ...].
For now just add uses annotation to you model with all the libraries you want and they will be loaded automatically.

@adrpo
Copy link
Member

adrpo commented Jul 3, 2021

OMJulia.sendExpression(mod,"load(Modelica,{\"4.0.0\"})")

This is wrong, it should be loadModel(Modelica, {"4.0.0")} instead of load(....) as latter doesn't exist.
See all the commands you can use here: https://build.openmodelica.org/Documentation/OpenModelica.Scripting.html

@christiankral
Copy link
Contributor Author

Yes indeed, the following works: OMJulia.sendExpression(mod,"loadModel(Modelica,{\"4.0.0\"})") causes a version incompatibility as expected.

@arun3688
Copy link
Contributor

arun3688 commented Jul 5, 2021

I will modify the API to specify library versions in the form of tuples

@arun3688
Copy link
Contributor

arun3688 commented Aug 9, 2021

@christiankral , the issue is fixed with this commit 8a6cf80, please test it

Usage

>>> ModelicaSystem(omc, "TestVersion.mo", "Test", ("Modelica","3.2.3")) # usage 1 as a tuple
>>> ModelicaSystem(omc, "TestVersion.mo", "Test", [("Modelica","3.2.3")]) # usage 2, as array of tuples 
>>> ModelicaSystem(omc, "TestVersion.mo", "Test", [("Modelica","3.2.3"), "PowerSystems"]) # usage 3, as Array of tuples and  String

@christiankral
Copy link
Contributor Author

OK, I am trying the following two examples:

Example Test3.mo:

model Test3
  parameter Modelica.SIunits.Current I = 1 "Current";
equation
annotation(experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.002));
end Test3;

Example Test4.mo:

model Test4
  parameter Modelica.Units.SI.Current I = 1 "Current";
equation
annotation(experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.002));
end Test4;

So Test3 only works with MSL 3.2.3 and Test4 only works with MSL 4.0.0.

In Julia I try (after updating OMJulia):

using OMJulia
mod = OMJulia.OMCSession()
ModelicaSystem(mod, "Test3.mo", "Test3", [("Modelica","3.2.3")])

causes the following error:

ERROR: MethodError: no method matching joinpath(::Tuple{String, String})
Closest candidates are:
  joinpath(::AbstractString) at path.jl:251
  joinpath(::AbstractString, ::AbstractString...) at path.jl:296
Stacktrace:
 [1] stat(path::Tuple{String, String})
   @ Base.Filesystem ./stat.jl:109
 [2] isfile(path::Tuple{String, String})
   @ Base.Filesystem ./stat.jl:311
 [3] ModelicaSystem(omc::OMJulia.OMCSession, filename::String, modelname::String, library::Vector{Tuple{String, String}}; commandLineOptions::Nothing)
   @ OMJulia ~/.julia/packages/OMJulia/P5JuJ/src/OMJulia.jl:241
 [4] ModelicaSystem(omc::OMJulia.OMCSession, filename::String, modelname::String, library::Vector{Tuple{String, String}})
   @ OMJulia ~/.julia/packages/OMJulia/P5JuJ/src/OMJulia.jl:201
 [5] top-level scope
   @ REPL[6]:1

If I use ("Modelica","3.2.3") instead of [("Modelica","3.2.3")]

ModelicaSystem(mod, "Test3.mo", "Test3", ("Modelica","3.2.3"))

it causes a different error:

"[/home/data/work/Test3.mo:2:3-2:53:writable] Error: Class Modelica.SIunits.Current not found in scope Test3.\n"

If I use instead

ModelicaSystem(mod, "Test4.mo", "Test4", ("Modelica","4.0.0"))

the following error is caused:

"[/home/data/work/Test4.mo:2:3-2:54:writable] Error: Class Modelica.Units.SI.Current not found in scope Test4.\n"

@arun3688
Copy link
Contributor

The following error msg is correct,
[/home/data/work/Test3.mo:2:3-2:53:writable] Error: Class Modelica.SIunits.Current not found in scope Test3.\n
It means the SIUnits.Current is not loaded with 4.0.0, but it should work with 3.2.3 and it worked for me with 3.2.3

@christiankral
Copy link
Contributor Author

The following error msg is correct,
[/home/data/work/Test3.mo:2:3-2:53:writable] Error: Class Modelica.SIunits.Current not found in scope Test3.\n
It means the SIUnits.Current is not loaded with 4.0.0, but it should work with 3.2.3 and it worked for me with 3.2.3

I don't understand why the error message caused by ModelicaSystem(mod, "Test3.mo", "Test3", ("Modelica","3.2.3")) is correct, as Modelica.SIunits.Current is a valid Modelica class in MSL 3.2.3. I tested it in OMEdit, and works OK with the MSL 3.2.3.

Note In the MSL 3.2.3 it's Modelica.SIunits not Modelica.SIUnits (lowercase u)

@arun3688
Copy link
Contributor

@christiankral I cannot reproduce the error, see below

julia> using OMJulia                                                                                                                                                                                                                                                                                                                                                                          
julia> omc = OMJulia.OMCSession() 
### expected error message                                                                                                                                                                                                                                                                                                                                                            
julia> ModelicaSystem(omc, "TestVersion.mo", "Test")                                                                                                                                           
[c:/juliatest/Test.jl/extendsbug/TestVersion.mo:2:3-2:53:writable] Error: Class Modelica.SIunits.Current not found in scope Test. 

### load Modelica with version 3.2.3                                                                                                                                                                                                                                                                                                                                                                                                                                                        
julia> ModelicaSystem(omc, "TestVersion.mo", "Test", ("Modelica", "3.2.3")) 
julia> getParameters(omc)
Dict{Any,Any} with 1 entry:
  "I" => "1.0"

@christiankral
Copy link
Contributor Author

@arun3688 Can you please paste the code of your file "TestVersion.mo"

@arun3688
Copy link
Contributor

@christiankral It is the same code what you posted for Test3.mo, I changed the filename, below is the code

model Test
  parameter Modelica.SIunits.Current I = 1 "Current";
equation
  annotation(experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.002));
end Test;

@christiankral
Copy link
Contributor Author

Oh I see: it was my fault: I had fixed OMJulia to a previous SHA1 hash number and forgot to switch to master. Therefore update had no impact before switching to master.

All the cases that should work, now work indeed. Thanks for your support, sorry for bothering you.

The ticket can now be closed from my point of view.

@arun3688
Copy link
Contributor

@christiankral great and thanks for testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants