1
votes

I have several blocks "FixedCurrent" in my electrical circuit. I want to be able to change values of current for these block via FMU. I can change a value, using "parameter", as it presented in the code below:

type Current = Real(unit = "A", min = 0);

parameter Current CurrentTest1(start = 50) "Test current";

PowerSystems.Generic.FixedCurrent fixedCurrent3(
    I = CurrentTest1, 
    redeclare package PhaseSystem = PhaseSystem), 
  annotation(...);

PowerSystems.Generic.FixedCurrent fixedCurrent1(
    I = 55, 
    redeclare package PhaseSystem = PhaseSystem), 
  annotation(...);

But I can't assign input for them. for example, if I use input command(1) or RealInput block (2) to set value of current for the block fixedCurrent3:

// 1) 
input Real TZtest(start=50);
PowerSystems.Generic.FixedCurrent fixedCurrent3(
    I = TZtest, 
    redeclare package PhaseSystem = PhaseSystem),
  annotation(...);

// 2) 
Modelica.Blocks.Interfaces.RealInput TZTest2 annotation(...);
PowerSystems.Generic.FixedCurrent fixedCurrent3(
    I = TZtest, 
    redeclare package PhaseSystem = PhaseSystem),
  annotation(...);

I receive corresponding errors:

1) Translation Error
Component fixedCurrent3.I of variability PARAM has binding TZtest of higher variability VAR.

2)Translation Error
Component fixedCurrent3.I of variability PARAM has binding TZTest2 of higher variability VAR.

Thus I can't handle to set value for the parameter via FMU input. I will be grateful to get any solutions to this problem.

1

1 Answers

2
votes

In short: The problem lies in the variability of your variables. Replace your FixedCurrent block with a block that allows to set variable currents. So instead of a parameter it needs to have a real input for the current I.

In Modelica variables can have one of the following variabilities (from lowest to highest):

  • constant: not changeable by the user, same value for the entire simulation
  • parameter: changeable before simulation start, but same value for the entire simulation
  • discrete: change their values only at events (inside when-clauses)
  • continuous: regular variables

Variables can only be assigned to other variables with same or higher variability. A parameter for example can not be set with a continuous variable. And in your examples 1) and 2) you are trying to do exactly that.

For 1) you could set the variability of the input to parameter using the prefix parameter:

parameter input Real TZtest(start=50);

In case 2) you have the problem that the outputs of FMUs are continuous. Hence you should replace FixedCurrent block with a some kind of variable current block, as mentioned at the beginning of this answer.

Note that there is also a workaround, which allows to set parameters from continuous variables in initial equations (as described in this answer), but I would only use that if absolutely necessary.