Opened 12 years ago

Last modified 3 years ago

#1931 assigned defect

Do not scalarize vector equations

Reported by: sjoelund.se Owned by: jfrenkel
Priority: high Milestone:
Component: Frontend Version:
Keywords: Cc: jfrenkel

Description

We should not scalarize equations, so we can reduce the number of function calls performed (here f is called once for each element in the matrix):

model M
  function f
    input Real r1,r2;
    output Real o[2] := {r1,r2};
  end f;
  Real rtime = time;
  Real r[:,:](each start = 1.5) = f(rtime,2:3);
end M;

model N
  M m;
end N;

With a better frontend, we can generate this flat code:

function M.f
  input Real r1;
  input Real r2;
  output Real[2] o = {r1, r2};
end M.f;

class N
  Real m.rtime = time;
  Real m.r[1,1](start = 1.5);
  Real m.r[1,2](start = 1.5);
  Real m.r[2,1](start = 1.5);
  Real m.r[2,2](start = 1.5);
equation
  m.r = {M.f(m.rtime, 2.0), M.f(m.rtime, 3.0)};
end N;

Attachments (2)

Inst.diff (2.2 KB) - added by sjoelund.se 12 years ago.
ArrayParam.diff (2.9 KB) - added by sjoelund.se 12 years ago.
Patch for adding a new equation type

Download all attachments as: .zip

Change History (24)

comment:1 Changed 12 years ago by sjoelund.se

  • Owner changed from somebody to sjoelund.se
  • Status changed from new to assigned

comment:2 Changed 12 years ago by sjoelund.se

Fixed for variables in r13830. Will look into also making this possible for parameter bindings.

Changed 12 years ago by sjoelund.se

comment:3 Changed 12 years ago by sjoelund.se

For parameters, some simulations start to spin for infinity. Others return 0 instead of calculating the parameter value. I have attached the diff so Jens can have a look.

These are some of the simulations that failed:

./simulation/libraries/msl32/Modelica.Blocks.Examples.BooleanNetwork1.mos
./simulation/libraries/msl32/Modelica.Blocks.Examples.Filter.mos
./simulation/libraries/msl32/Modelica.Blocks.Examples.FilterWithDifferentiation.mos
./simulation/libraries/msl32/Modelica.Blocks.Examples.FilterWithRiseTime.mos
./simulation/libraries/msl32/Modelica.Blocks.Examples.IntegerNetwork1.mos
./simulation/libraries/msl32/Modelica.Blocks.Examples.Interaction1.mos
./simulation/libraries/msl32/Modelica.Blocks.Examples.InverseModel.mos
./simulation/libraries/msl32/Modelica.Blocks.Examples.LogicalNetwork1.mos
./simulation/libraries/msl32/Modelica.Blocks.Examples.PID_Controller.mos
./simulation/libraries/msl32/Modelica.Blocks.Examples.RealNetwork1.mos
./simulation/libraries/msl32/Modelica.Blocks.Examples.ShowLogicalSources.mos
./simulation/libraries/msl32/Modelica.Electrical.Digital.Examples.MUX2x1.mos
./simulation/libraries/msl32/Modelica.Electrical.Machines.Examples.Transformers.AsymmetricalLoad.mos
./simulation/libraries/msl32/Modelica.Electrical.Machines.Examples.Transformers.TransformerTestbench.mos
./simulation/libraries/msl32/Modelica.Fluid.Examples.DrumBoiler.DrumBoiler.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Constraints.ConstrainRevoluteJoint.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Constraints.ConstrainSphericalJoint.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Constraints.ConstrainUniversalJoint.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulumInitTip.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulum.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.ForceAndTorque.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.FreeBody.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.HeatLosses.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.InitSpringConstant.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.LineForceWithTwoMasses.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.PendulumWithSpringDamper.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.PointGravity.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.PointGravityWithPointMasses2.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.PointGravityWithPointMasses.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.RollingWheel.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.RollingWheelSetDriving.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.RollingWheelSetPulling.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.SpringDamperSystem.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.SpringMassSystem.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.SpringWithMass.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Elementary.ThreeSprings.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Loops.Engine1a.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Loops.Engine1b_analytic.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Loops.Engine1b.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Loops.Fourbar1.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Loops.Fourbar2.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Loops.Fourbar_analytic.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Loops.PlanarLoops_analytic.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Rotational3DEffects.ActuatedDrive.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Rotational3DEffects.GearConstraint.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Rotational3DEffects.GyroscopicEffects.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Rotational3DEffects.MovingActuatedDrive.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.Components.GearType2.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.Components.MechanicalStructure.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.Components.PathPlanning1.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.Components.PathPlanning6.mos
./simulation/libraries/msl32/Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.oneAxis.mos
./simulation/libraries/msl32/Modelica.Mechanics.Rotational.Examples.CoupledClutches.mos
./simulation/libraries/msl32/Modelica.Mechanics.Rotational.Examples.Friction.mos
./simulation/libraries/msl32/Modelica.Mechanics.Rotational.Examples.HeatLosses.mos
./simulation/libraries/msl32/Modelica.Mechanics.Rotational.Examples.LossyGearDemo1.mos
./simulation/libraries/msl32/Modelica.Mechanics.Rotational.Examples.LossyGearDemo2.mos
./simulation/libraries/msl32/Modelica.Mechanics.Rotational.Examples.LossyGearDemo3.mos
./simulation/libraries/msl32/Modelica.Mechanics.Rotational.Examples.SimpleGearShift.mos
./simulation/libraries/msl32/Modelica.Mechanics.Translational.Examples.Brake.mos
./simulation/libraries/msl32/Modelica.Mechanics.Translational.Examples.Friction.mos
./simulation/libraries/msl32/Modelica.Mechanics.Translational.Examples.HeatLosses.mos
./simulation/libraries/msl32/Modelica.Media.Examples.MoistAir.mos
./simulation/libraries/msl32/Modelica.Media.Examples.TestOnly.FlueGas.mos
./simulation/libraries/msl32/Modelica.Media.Examples.Tests.MediaTestModels.Water.ConstantPropertyLiquidWater.mos
./simulation/libraries/msl32/Modelica.Thermal.HeatTransfer.Examples.Motor.mos
./simulation/modelica/algorithms-functions/AlgorithmForInClass.mos
./simulation/modelica/algorithms-functions/Interpolation.mos
./simulation/modelica/arrays/PolynomialEvaluatorA.mos
./simulation/modelica/arrays/PolynomialEvaluatorB.mos
./simulation/modelica/built-in-functions/MeasureTime.mos
./simulation/modelica/connectors/StepAdvanced.mos
./simulation/modelica/msl22/blockssources.mos
./simulation/modelica/msl22/IdealGearBrake.mos
./simulation/modelica/others/DiscreteVectorStateSpace.mos
./simulation/modelica/others/nonConstantIndex.mos
./simulation/modelica/others/Random.mos
./simulation/modelica/others/Riccati.mos
./simulation/modelica/others/Table2d.mos

comment:4 Changed 12 years ago by sjoelund.se

  • Owner changed from sjoelund.se to jfrenkel

comment:5 Changed 12 years ago by jfrenkel

I guess the problem is that if parameter bindings are moved to initial equations the parameters should be fixed=false, otherwise the initial system became overconstrained.

Another idea is to add a new Equationtype "PARAMETER_EQUATION(cr,exp,source)". This equation could be moved directly to the parameter system and used in the simulation runtime to calculate the parameter value. Then it is maybe also easier to simplify equations like

CriticalDamping.x_start = {0.0, 0.0, 0.0}

comment:6 Changed 12 years ago by jfrenkel

  • Owner changed from jfrenkel to sjoelund.se

Changed 12 years ago by sjoelund.se

Patch for adding a new equation type

comment:7 Changed 12 years ago by sjoelund.se

  • Owner changed from sjoelund.se to jfrenkel

Ok, got a new patch. It needs backend support ;)

comment:8 Changed 11 years ago by sjoelund.se

  • Milestone changed from 1.9.0 to 1.9.1

Postponed until 1.9.1

comment:9 Changed 10 years ago by sjoelund.se

  • Milestone changed from 1.9.1 to 1.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:10 Changed 10 years ago by sjoelund.se

  • Milestone changed from 1.9.2 to 1.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:11 Changed 9 years ago by sjoelund.se

  • Milestone changed from 1.9.3 to 1.9.4

Moved to new milestone 1.9.4

comment:12 Changed 9 years ago by sjoelund.se

  • Milestone changed from 1.9.4 to 1.9.5

Milestone pushed to 1.9.5

comment:13 Changed 9 years ago by sjoelund.se

  • Milestone changed from 1.9.5 to 1.10.0

Milestone renamed

comment:14 Changed 8 years ago by sjoelund.se

  • Milestone changed from 1.10.0 to 1.11.0

Ticket retargeted after milestone closed

comment:15 Changed 8 years ago by sjoelund.se

  • Milestone changed from 1.11.0 to 1.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:16 Changed 7 years ago by casella

  • Component changed from Frontend to New Instantiation
  • Milestone changed from 1.12.0 to 2.0.0

@perost, can you give another look at this issue?

comment:17 Changed 7 years ago by sjoelund.se

  • Component changed from New Instantiation to Frontend
  • Milestone changed from 2.0.0 to 1.13.0

I thought with the cse module, this would have been resolved for parameters but it's not; the parameter equations are still called multiple times. The problem can be fixed either in the frontend (moving the equations and setting fixed=false like we do for records); in the backend (by performing some CSE); or both (by introducing an equation kind that is treated like having set fixed=false even though we have fixed=true set)

comment:18 Changed 6 years ago by casella

  • Milestone changed from 1.13.0 to 1.14.0

Rescheduled to 1.14.0 after 1.13.0 releasee

comment:19 Changed 5 years ago by casella

  • Milestone changed from 1.14.0 to 1.16.0

Releasing 1.14.0 which is stable and has many improvements w.r.t. 1.13.2. This issue is rescheduled to 1.16.0

comment:20 Changed 4 years ago by casella

  • Milestone changed from 1.16.0 to 1.17.0

Retargeted to 1.17.0 after 1.16.0 release

comment:21 Changed 4 years ago by casella

  • Milestone changed from 1.17.0 to 1.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:22 Changed 3 years ago by casella

  • Milestone 1.18.0 deleted

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.