Opened 10 years ago

Last modified 7 years ago

#3117 new enhancement

Evaluate functions of parameters/constants only once (required by data-based interpolation functions)

Reported by: Francesco Casella Owned by: somebody
Priority: high Milestone: Future
Component: Backend Version: trunk
Keywords: Cc:

Description

Consider ThermoPower.Test.GasComponents.TestFanMech. The simulation in OMC takes 22 seconds, in Dymola 0.002 seconds, with a ratio of 10.000 (!!).

The fan model uses the following function:

  function flowChar = Functions.FanCharacteristics.quadraticFlowBlades (
      bladePos_nom={0.30,0.35,0.40,0.45,0.50,0.55,0.60,0.65,0.70,0.75,0.80,
          0.85},
      q_nom=[0, 0, 100, 300, 470, 620, 760, 900, 1000, 1100, 1300, 1500; 70,
          125, 310, 470, 640, 820, 1000, 1200, 1400, 1570, 1700, 1900; 100,
          200, 370, 530, 700, 900, 1100, 1300, 1500, 1750, 2000, 2300],
      H_nom=[3100, 3800, 3700, 3850, 4200, 4350, 4700, 4900, 5300, 5600,
          5850, 6200; 2000, 3000, 3000, 3000, 3000, 3200, 3200, 3300, 3600,
          4200, 5000, 5500; 1000, 2000, 2000, 2000, 2000, 1750, 1750, 2000,
          2350, 2500, 2850, 3200]);

to represent its characteristic curve. The quadraticFlowBlades function has the following body:

function quadraticFlowBlades 
  "Quadratic flow characteristic, movable blades"
  extends baseFlow;
  input Real bladePos_nom[:];
  input SI.VolumeFlowRate q_nom[3, :] 
    "Volume flow rate for three operating points at N_pos blade positionings";
  input SI.Height H_nom[3, :] 
    "Specific work for three operating points at N_pos blade positionings";
  input Real slope_s(
    unit="(J/kg)/(m3/s)",
    max=0) = 0 
    "Slope of flow characteristic at stalling conditions (must be negative)";
algorithm 
  H := Utilities.quadraticFlowBlades(
          q_flow,
          bladePos,
          bladePos_nom,
          Utilities.quadraticFlowBladesCoeff(
            bladePos_nom,
            q_nom,
            H_nom),
          slope_s);
end quadraticFlowBlades;

The last input to Utilities.quadraticFlowBlades is a function that computes the interpolation coefficients based on the nominal data, which requires nontrivial computations.

In our case, these nominal data turn out to be constants, so this function should be only called once at initialization, then subsituted by its constant output. If not, the entire set of interpolation coefficients is recomputed each time the interpolation function is called, which is horribly inefficient.

This mechanism is actually required to satisfactorily handle all kinds of data-based interpolation functions.

Change History (4)

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

@lochel: Can you close this ticket with the appropriate milestone? Or @casella needs to change the task. The simulation is still slow, with roughly 90% being taken by the torn equation FanMech1.H := if noEvent(FanMech1.s > 0.0) or not FanMech1.CheckValve then DIVISION(FanMech1.n, FanMech1.n0) ^ 2.0 * ThermoPower.Gas.FanMech$FanMech1.flowCharacteristic(FanMech1.q_single * DIVISION(FanMech1.n0, 1e-06 + FanMech1.n), FanMech1.in_bladePos, {0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85}, {{0.0, 0.0, 100.0, 300.0, 470.0, 620.0, 760.0, 900.0, 1000.0, 1100.0, 1300.0, 1500.0}, {70.0, 125.0, 310.0, 470.0, 640.0, 820.0, 1000.0, 1200.0, 1400.0, 1570.0, 1700.0, 1900.0}, {100.0, 200.0, 370.0, 530.0, 700.0, 900.0, 1100.0, 1300.0, 1500.0, 1750.0, 2000.0, 2300.0}}, {{3100.0, 3800.0, 3700.0, 3850.0, 4200.0, 4350.0, 4700.0, 4900.0, 5300.0, 5600.0, 5850.0, 6200.0}, {2000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3200.0, 3200.0, 3300.0, 3600.0, 4200.0, 5000.0, 5500.0}, {1000.0, 2000.0, 2000.0, 2000.0, 2000.0, 1750.0, 1750.0, 2000.0, 2350.0, 2500.0, 2850.0, 3200.0}}, 0.0) else 214.2857142856992 * DIVISION(FanMech1.n, FanMech1.n0) ^ 2.0 - FanMech1.s which is being called 32400 times.

comment:2 by Francesco Casella, 7 years ago

I checked the latest results on Hudson. The simulation time is now 1.32 s, which is way better than 22 s and shows that some significant improvement has been achieved in the meantime.

However, given Dymola's execution times, I guess there is still room for further optimization, so I would not close this ticket, but rather leave it for the Future milestone. If this issue becomes critical for some application we can bring it back to production.

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

The question is if we should open another ticket for it since what the ticket describes is a different, now solved, problem.

comment:4 by Francesco Casella, 7 years ago

I'm not sure the problem has actually been solved. From the html profiling information I can see that the function ThermoPower.Gas.FanMech$FanMech1.flowCharacteristic is called 32400 times and takes 74% of the time. On the other hand, the function ThermoPower.Functions.FanCharacteristics.Utilities.quadraticFlowBladesCoeff is called zero (!) times, which is weird because this function should be called once (and only once) to compute the constant interpolation coefficients.

It may be that this function has been inlined, so it is no longer reported as a separate function by the profiler? Or is it a bug of the profiler that does not report one single function call during initialization?

And, in any case, how can I be sure that the algorithm of Utilities.quadraticFlowBladesCoeff is only called once, which was the original topic of the ticket?

Note: See TracTickets for help on using tickets.