Opened 12 years ago

Last modified 3 years ago

#1931 assigned defect

Do not scalarize vector equations

Reported by: Martin Sjölund Owned by: Jens Frenkel
Priority: high Milestone:
Component: Frontend Version:
Keywords: Cc: Jens Frenkel

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 Martin Sjölund 12 years ago.
ArrayParam.diff (2.9 KB ) - added by Martin Sjölund 12 years ago.
Patch for adding a new equation type

Download all attachments as: .zip

Change History (24)

comment:1 by Martin Sjölund, 12 years ago

Owner: changed from somebody to Martin Sjölund
Status: newassigned

comment:2 by Martin Sjölund, 12 years ago

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

by Martin Sjölund, 12 years ago

Attachment: Inst.diff added

comment:3 by Martin Sjölund, 12 years ago

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 by Martin Sjölund, 12 years ago

Owner: changed from Martin Sjölund to Jens Frenkel

comment:5 by Jens Frenkel, 12 years ago

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 by Jens Frenkel, 12 years ago

Owner: changed from Jens Frenkel to Martin Sjölund

by Martin Sjölund, 12 years ago

Attachment: ArrayParam.diff added

Patch for adding a new equation type

comment:7 by Martin Sjölund, 12 years ago

Owner: changed from Martin Sjölund to Jens Frenkel

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

comment:8 by Martin Sjölund, 11 years ago

Milestone: 1.9.01.9.1

Postponed until 1.9.1

comment:9 by Martin Sjölund, 10 years ago

Milestone: 1.9.11.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 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:11 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:12 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

comment:13 by Martin Sjölund, 9 years ago

Milestone: 1.9.51.10.0

Milestone renamed

comment:14 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:15 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:16 by Francesco Casella, 7 years ago

Component: FrontendNew Instantiation
Milestone: 1.12.02.0.0

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

comment:17 by Martin Sjölund, 7 years ago

Component: New InstantiationFrontend
Milestone: 2.0.01.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 by Francesco Casella, 6 years ago

Milestone: 1.13.01.14.0

Rescheduled to 1.14.0 after 1.13.0 releasee

comment:19 by Francesco Casella, 5 years ago

Milestone: 1.14.01.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 by Francesco Casella, 4 years ago

Milestone: 1.16.01.17.0

Retargeted to 1.17.0 after 1.16.0 release

comment:21 by Francesco Casella, 4 years ago

Milestone: 1.17.01.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:22 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.