﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3117	Evaluate functions of parameters/constants only once (required by data-based interpolation functions)	Francesco Casella	somebody	"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."	enhancement	new	high	Future	Backend	trunk			
