Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#5460 closed enhancement (invalid)

Enhance possibilities to re-simulate

Reported by: massimo ceraolo Owned by: somebody
Priority: normal Milestone: 1.14.0
Component: *unknown* Version:
Keywords: Cc:

Description (last modified by massimo ceraolo)

Consider the following model

model Test2 
  import Modelica.Constants.pi;
  parameter Real Ipm;
  parameter Real varPar (fixed=false);
initial equation
  if Ipm>1.0 then
    varPar=pi/2;
  else
    varPar=asin(Ipm);
  end if;
equation
end Test2;

This model does not run under Dymola, which issues the following error message:

The following parameter doesn't have any value: Ipm

It is instead brilliantly run by OpenModelica, which uses the available start value (start=0.0) for Ipm, and also allows changing Ipm and re-simulating.
I.e., OpenModelica is able to run this model without taking Ipm as a structural parameter.

If I change the row

  parameter Real Ipm;

into

  parameter Real Ipm=1.5;

OM runs it, but Ipm has become unchangeable.
I think that it is very good that OM succeeds in keeping Ipm non-structural, even though it is used in an if-clause condition. But since it is able to do so, why not allowing this also when an explicit value is given to the parameter?

I made my tests with OMEdit connected to OMC v1.14.0-dev-234-g5ef43cce8 (64-bit), under Windows.

I marked this ticket as "enhancement", but probably it requires just a very small change in what OM already does.

Change History (3)

comment:1 by massimo ceraolo, 6 years ago

Description: modified (diff)

comment:2 by Francesco Casella, 6 years ago

Resolution: invalid
Status: newclosed

According to the Modelica Specifcation 8.6,

If a parameter has a modifier for the start-attribute, does not have fixed=false , and neither has a binding equation nor is part of a record having a binding equation, the modifier for the start-attribute can be used to add a parameter binding equation assigning the parameter to that start-modifier. In this case a diagnostic message is recommended in a simulation model.

In this case Ipm does not have a modifier for the start value, so the model is invalid, and it should also be rejected by OMC.

In fact, this is the case if the new frontend is used.

If you add the (start = 0) modifier to Ipm and use the new front-end, Ipm is indeed evaluated, although the parameter still seems to be changeable while it's not, see #5454.

I can't see any easy way for the OMC front-end to avoid evaluating a parameter which is used in the selection of conditional equations. However, what you want to achieve can be obtained by using a conditional expression instead:

model Test3
  import Modelica.Constants.pi;
  parameter Real Ipm = 0;
  parameter Real varPar(fixed=false);
initial equation
   varPar = if Ipm > 1.0 then pi/2 else asin(Ipm);
end Test3;

comment:3 by massimo ceraolo, 6 years ago

Ah, ok.
It is very useful to have the chance to change run time parameters in (if-statement) if-clause conditions, and in fact I was happy, although somewhat surprised, that OM allowed it.

In reality, using the OF, in the model I have this works well, so I thought this feature was somewhat already implemented, even beyond specifications. Unfortunately, it happens not to be this way with the NF.

I mean OF is able to consider this parameter as being non-structural, so the parameter expression Ipm>1.

Last edited 6 years ago by massimo ceraolo (previous) (diff)
Note: See TracTickets for help on using tickets.