OpenModelica


Forgot password? | Forgot username? | Register

OM shell

OM shell

I want to make some optimisations according to the example 8.3 of the OpenModelicaUsersGuide-latest.pdf.
The provided BatchReactor example makes usage of two different files BathReactor.mo and nmpcBatchReactor.mo.
Since I want to investigate several cases, instead to have many files I would like to put all models into a package, load it, and make optimisations by using models from that package.
Unfortunately I couldn’t do this: loadFile() command does not load a package. There exist the loadModel() command, but I could not understand how to use it to load a package.
Finally, I wonder whether the OMC command optimize will accept as a first parameter a name that contains dots, e.g. “myPackage.MyOptModel”.

Thanks.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: OM shell

Yeah you can combine both files into one file under a package and loadFile should work fine to load it. What is the error?

Yes optimize command accepts the qualified path.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: OM shell

Consider this:

Code:

package BangBangPkg

model BangBang "Model to verify that optimization gives bang-bang optimal control"
  Real a;
  Real v(start = 0, fixed=true);
  Real pos(start = 0, fixed=true);
  Real pow(min = -30, max = 30) = f * v ;
  input Real f(min = -10, max = 10);
equation
  der(pos) = v;
  der(v) = a;
  f = m * a;
end BangBang;
optimization optBangBang(objective=-pos)
  extends BangBang;
end optBangBang;
end BangBangPkg;

I have this in code in file BangBangPkg.mo, and the two models separately in BangBang.mo and optBangBang.mo.

If, in OMShell, I do

Code:


loadFile("BangBang.mo")
loadFile("optBangBang.mo")
optimize(optBangBang, numberOfIntervals=16, stopTime=1, tolerance=1e-8)

everything works well (and  list(BangBang) prints the rightcode).
If, on the contrary I issue

Code:


loadFile("BangBangPkg.mo")

I get false and list(BangBangPkg) prints nothing.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: OM shell

loadModel is a bit misnamed, a more accurate name would have been loadLibrary. That is to say, loadModel loads a library that can be found in the library path (e.g. loadModel(Modelica) will load the Modelica Standard Library). See the API documentation.

Anyway, most commands won't print any errors that occured, so you need to put getErrorString() after e.g. loadModel to get the actual reason for the failure.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: OM shell

I can load your model without any problem,

Code:

>> setCommandLineOptions("-g=Optimica")

true

>> loadFile("C:/Users/adeas31/Desktop/BangBangPkg.mo")
true

>> getClassNames()
{BangBangPkg}

>> getClassNames(BangBangPkg)
{BangBang,optBangBang}

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: OM shell

Now I can read the package and ask optimisation using qualified paths.
Basically there was a mistake in the code: inside the model BangBang I used for failing tests I had inadvertently deleted the row

Code:

  parameter Real m = 1;

Since I also did not use
getErrorString() I did not realise this.

Thank you both.

Edited by: ceraolo - Jun-07-18 07:22:50
Administrator has disabled public posting. Please login or register in order to proceed.
There are 0 guests and 0 other users also viewing this topic