Opened 5 years ago

Last modified 3 years ago

#6014 assigned defect

OMPython: Set structural parameter at initialization

Reported by: lukas.koenemann@… Owned by: Adrian Pop
Priority: high Milestone:
Component: Interactive Environment Version: v1.14.1
Keywords: structural parameter Cc:

Description

Hello,
there a view parameters that can't be set after compilation. For example parameters that define an array size. Is it possible to set these kind of parameters while compiling? Is there any compilerflag that allows this?

best regards
Lukas Koenemann

Change History (7)

comment:1 by Francesco Casella, 5 years ago

Component: *unknown*Interactive Environment
Milestone: Future1.17.0
Owner: changed from somebody to Adrian Pop
Status: newassigned

This is related to #2174. Maybe it's time we finally provide this functionality in the interactive environment, so it can be used by all OMC tools?

@adrpo, what do you think?

comment:2 by Adrian Pop, 5 years ago

You can already do it via setParameterValue or setComponentModifierValue:
https://www.openmodelica.org/download/OMC_API-HowTo.pdf

This is really easy to do even now via:

loadString("model ChangeParametersInModel = Model(modifications)");
simulate(ChangeParametersInModel);

I guess what you want is to be able to give a short class definition in the translateModel, buildModel and simulate commands:

So which one would prefer?

// this way you would also have a name that goes with the modifications
simulate(model ChangeParametersInModel = Model(modifications));

or:

// this way you somehow hide the modifications
simulate(Model(modifications));

Now the question is what you should be able to put in the modification values?
Just literals or can they can also use parameters from the Model?

in reply to:  2 comment:3 by Francesco Casella, 5 years ago

Replying to adrpo:

You can already do it via setParameterValue or setComponentModifierValue:
https://www.openmodelica.org/download/OMC_API-HowTo.pdf

This is really easy to do even now via:

loadString("model ChangeParametersInModel = Model(modifications)");
simulate(ChangeParametersInModel);

Aha, I didn't think about short class definitions, in #2174 I was considering inheritance, but then the experiment annotations would be lost. Are they kept if I use short class definition like you propose here?

I guess what you want is to be able to give a short class definition in the translateModel, buildModel and simulate commands:

So which one would prefer?

// this way you somehow hide the modifications
simulate(Model(modifications));

This one would of course be nicer and more intuitive.

Now the question is what you should be able to put in the modification values?
Just literals or can they can also use parameters from the Model?

I was mostly thinking of providing either literals or top-level variables defined by the scripting environment (whatever that means), e.g.

Real p = {1, 2, 3};
for i in 1:3 loop
  simulate(MyModel(p = p[i]));
  // do stuff with the results
end for;

In principle I could also fetch those values from inside the model

for i in 1:3 loop
  simulate(MyModel(p = MyModel.data_p[i]));
  // do stuff with the results
end for;

but that's not what I had in mind. @lukas, what do you think?

Also, it is not fully clear if and how can I avoid to recompile the model all the times from the API. Of course I can call buildModel and then call the executable via system calls, but that's another approach.

It would be good to have some guides or tutorials you can do such things using the scripting language and OMPython/Matlab/Julia

comment:4 by lukas.koenemann@…, 5 years ago

Thank you for the fast reply. It works well with the solution mentioned above (via setParameterValue). With OMPython I just execute the model_name.exe to simulate my model. That's why I couldn't use the solution with the OpenModelica-command "simulate(MyModel(p=p[i]))"...

comment:5 by lukas.koenemann@…, 5 years ago

Is it possible to set a string via

loadString("model ChangeParametersInModel = Model(modifications)");

modifications? This one doesnt work:

loadString("model ChangeParametersInModel = Model(PV.filename = "modelica://path_to_file")");

comment:6 by Francesco Casella, 4 years ago

Milestone: 1.17.01.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:7 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.