Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Set structural parameters at translation

Set structural parameters at translation

Hello,

is it possible to set structural parameters (via mos-script) at translation time?

Something in the lines of:

Code:


buildModel(Simple.Model(param1=7));
buildModel(Simple.Model(param1=9));

would be of great use. I couldn't find any information on that, but maybe I'm missing something current/smile

I'm grateful for any tips or hints!
Robert

Re: Set structural parameters at translation

You can use setParameterValue or setComponentModifierValue to change the parameter in a model before building. See an example below.

Code:


loadString("
model M
  parameter Real a = 1;
  parameter Real x[2,2];
  parameter Real y[2,2];
end M;"); getErrorString();

list(M); getErrorString();
// use setParameterValue
setParameterValue(M, x, fill(a, 2, 2)); getErrorString();
list(M); getErrorString();

// use setComponentModifierValue
setComponentModifierValue(M, y, $Code(= fill(a, size(x, 1), size(x, 2)))); getErrorString();
list(M); getErrorString();
setComponentModifierValue(M, y.start, $Code(= fill(a, size(x, 1), size(x, 2)))); getErrorString();
list(M); getErrorString();

instantiateModel(M); getErrorString();

Re: Set structural parameters at translation

Thank you, Adrian, that works like a charm! current/smile

There are 0 guests and 0 other users also viewing this topic
You are here: