0

In Modelica, I constructed a simple mapping (a pair of case structures) to reduced a table of MxN values into a table of 5x5 values. But when I simulate with an input that is at the boundary (row = M or column = N) the mapping returns "0" when it should return "5". I included an out-of-bounds case, but the returned value should be "3," not "0;" I never specify "0" as an output.

Could this be due to the function being time-invariant, perhaps a lack of initial conditions?

Here's the code:

model chooseTypeArrayPosition 
          Modelica.Blocks.Interfaces.IntegerInput ModuleRow "Module Row";
      Modelica.Blocks.Interfaces.IntegerInput ModuleCol "Module Column";
      Modelica.Blocks.Interfaces.IntegerInput ArrayRows "Rows in Array";
      Modelica.Blocks.Interfaces.IntegerInput ArrayCols "Columns in Array"; 

  output Modelica.Blocks.Interfaces.IntegerOutput FractExposedTypeRow;
  output Modelica.Blocks.Interfaces.IntegerOutput FractExposedTypeCol "Enumeration of FractExposed Column";
algorithm
  if ModuleCol > ArrayCols then
    FractExposedTypeCol := 3;
  elseif ModuleCol < 2 then
    FractExposedTypeCol := 1;
  elseif ModuleCol < 3 then
    FractExposedTypeCol := 2;
  elseif ModuleCol > ArrayCols - 1 then
    FractExposedTypeRow := 5;
  elseif ModuleCol > ArrayCols - 2 then
    FractExposedTypeCol := 4;
  else
    FractExposedTypeCol := 3;
  end if;

  if ModuleRow > ArrayRows then
    FractExposedTypeRow := 3;
  elseif ModuleRow < 2 then
    FractExposedTypeRow := 1;
  elseif ModuleRow < 3 then
    FractExposedTypeRow := 2;
  elseif ModuleRow > ArrayRows - 1 then
    FractExposedTypeRow := 5;
  elseif ModuleRow > ArrayRows - 2 then
    FractExposedTypeRow := 4;
  else
    FractExposedTypeRow := 3;
  end if;
end chooseTypeArrayPosition;

Thanks for any thoughts!

1 Answers1

1

You made a typo in the first section:

elseif ModuleCol > ArrayCols - 1 then
    FractExposedTypeRow := 5;

Should be FractExposedTypeRow := ...

sjoelund.se
  • 3,468
  • 12
  • 15