Faisal
Faisal

Reputation: 68

Dymola 2022 and 2023 Parallelisation failing to translate Fluid models

I have been using Dymola 2019 FD01 to develop my models and wanted to try the new Dymola versions.

I started with Dymola 2022, but came across an issue when Advanced.ParallelizeCode is enabled. I checked other new Dymola versions and the same error occurred (I tried 2021X, 2022, 2022X 2023) (2020X and below works). When ParallelizeCode is disabled the model runs. My colleague managed to create a small model to reproduce the error, which I have pasted below.

The model basically takes a vector input of temperatures, calculates the maximum of the vector and then passes it into the the two MassFlowSource objects which are connected to a volume object and a sink object. The volume object includes the dynamic energy and mass balances. These two flow branches do not interact with each other, and the branch without the volume was included to reproduce the error (without this it runs fine).

The sub model:

model paralellizationIssue
  parameter Integer N=2;
  parameter Real T_start=300;
  Modelica.Blocks.Interfaces.RealVectorInput Temp[N]
    annotation (Placement(transformation(extent={{-94,44},{-54,84}})));
  Modelica.Blocks.Math.MinMax minMax(nu=N)
    annotation (Placement(transformation(extent={{-44,54},{-24,76}})));
  Modelica.Fluid.Sources.MassFlowSource_T boundary(
    redeclare package Medium = Modelica.Media.IdealGases.SingleGases.CH4,
    use_T_in=true,
    m_flow=1,
    nPorts=1) annotation (Placement(transformation(extent={{-78,4},{-58,24}})));
  Modelica.Fluid.Sources.MassFlowSource_T boundary1(
    redeclare package Medium = Modelica.Media.IdealGases.SingleGases.CH4,
    use_T_in=true,
    m_flow=1,
    nPorts=1)
    annotation (Placement(transformation(extent={{-78,-50},{-58,-30}})));
  Modelica.Fluid.Sources.FixedBoundary boundary2(redeclare package Medium =
        Modelica.Media.IdealGases.SingleGases.CH4, nPorts=1)
    annotation (Placement(transformation(extent={{46,4},{26,24}})));
  Modelica.Fluid.Vessels.ClosedVolume volume(
    redeclare package Medium = Modelica.Media.IdealGases.SingleGases.CH4,
    T_start=303.15,
    use_portsData=false,
    V=1,
    nPorts=1)
    annotation (Placement(transformation(extent={{-18,-32},{2,-12}})));
equation 
  connect(Temp, minMax.u)
    annotation (Line(points={{-74,64},{-74,65},{-44,65}}, color={0,0,127}));
  connect(minMax.yMax, boundary.T_in) annotation (Line(points={{-23,71.6},{-14,71.6},
          {-14,42},{-90,42},{-90,18},{-80,18}}, color={0,0,127}));
  connect(boundary.ports[1], boundary2.ports[1])
    annotation (Line(points={{-58,14},{26,14}}, color={0,127,255}));
  connect(boundary1.ports[1], volume.ports[1]) annotation (Line(points={{-58,-40},
          {-8,-40},{-8,-32}},   color={0,127,255}));
  connect(minMax.yMax, boundary1.T_in) annotation (Line(points={{-23,71.6},{-14,
          71.6},{-14,42},{-90,42},{-90,18},{-86,18},{-86,-36},{-80,-36}}, color
        ={0,0,127}));
  annotation (
    Icon(coordinateSystem(preserveAspectRatio=false)),
    Diagram(coordinateSystem(preserveAspectRatio=false)),
    uses(Modelica(version="4.0.0")));
end paralellizationIssue;

screenshot of sub model

The issue here seems to be the evaluation of a vector input to calculate the temperature during translation. In a system model my colleague added three options to supply the temperature vector: case 1) A step input, case2 2) real expression and case 3) a constant. All three are given as vectors where each element has the same value and with the initial temperature being fed within the required temperature (~300K).

The system model:

model paralellizationIssueCaller
  paralellizationIssue paralellizationIssue1
    annotation (Placement(transformation(extent={{24,-14},{44,6}})));
  Modelica.Blocks.Sources.Step step[2](offset=300, y(each start=300))
    annotation (Placement(transformation(extent={{-62,30},{-42,50}})));
  Modelica.Blocks.Sources.RealExpression realExpression[2](y=100*time/(time +
        1e-20) + 200)
    annotation (Placement(transformation(extent={{-92,-6},{-4,14}})));
  Modelica.Blocks.Sources.Constant const[2](k=300)
    annotation (Placement(transformation(extent={{-62,-34},{-42,-14}})));
  inner Modelica.Fluid.System system
    annotation (Placement(transformation(extent={{80,60},{100,80}})));
equation 
  connect(step.y, paralellizationIssue1.Temp) annotation (Line(points={{-41,40},
          {16,40},{16,2.4},{26.6,2.4}}, color={0,0,127}));
  annotation (
    Icon(coordinateSystem(preserveAspectRatio=false)),
    Diagram(coordinateSystem(preserveAspectRatio=false)),
    uses(Modelica(version="4.0.0")));
end paralellizationIssueCaller;

screenshot of system model

Error

when running it for cases 1 and 2 the following error is given:

Translation of paralellizationIssueCaller:

Automatically introducing 'each' in definition equation for variable:
step[1].offset

Additional warnings of this type will not be written.

The DAE has 112 scalar unknowns and 112 scalar equations.

The initial conditions are not fully specified.
Dymola has selected default initial conditions.

Assuming fixed start value for the continuous states:
paralellizationIssue1.volume.medium.p(start = 101325.0)
paralellizationIssue1.volume.medium.T(start = 303.15)

Normal function call of function assert, but the function is declared with 0 outputs.
In call: assert(paralellizationIssue1.minMax.yMax >= 200 and paralellizationIssue1.minMax.yMax <= 6000, "
Temperature T (= "+ String(paralellizationIssue1.minMax.yMax, true, 0)+" K) is not in the allowed range
200 K <= T <= 6000 K required from medium model \"" +"Methane"+"\".
")

The function is declared as:
function assert "assert that a condition is true"
input Boolean x_0condition ;
input String x_0error ;
input Integer level := AssertionLevel.error;
end assert;

Normal function call of function assert, but the function is declared with 0 outputs.
In call: assert(paralellizationIssue1.minMax.yMax >= 200 and paralellizationIssue1.minMax.yMax <= 6000, "
Temperature T (= "+ String(paralellizationIssue1.minMax.yMax, true, 0)+" K) is not in the allowed range
200 K <= T <= 6000 K required from medium model \"" +"Methane"+"\".
")

The function is declared as:
function assert "assert that a condition is true"
input Boolean x_0condition ;
input String x_0error ;
input Integer level := AssertionLevel.error;
end assert;

Statistics

Original Model
Number of components: 28
Variables: 245
Constants: 21 (49 scalars)
Parameters: 90 (86 scalars)
Unknowns: 134 (112 scalars)
Differentiated variables: 4 scalars
Equations: 136
Nontrivial: 112

Translated Model
Constants: 183 scalars
Parameter depending: 3 scalars
Outputs: 2 scalars
Continuous time states: 2 scalars
Time-varying variables: 25 scalars
Alias variables: 36 scalars
Assumed default initial conditions: 2
Number of mixed real/discrete systems of equations: 0
Sizes of linear systems of equations: {2}
Sizes after manipulation of the linear systems: {0}
Sizes of nonlinear systems of equations: { }
Sizes after manipulation of the nonlinear systems: { }
Number of numerical Jacobians: 0

Initialization problem
Sizes of linear systems of equations: {2}
Sizes after manipulation of the linear systems: {0}

Settings

Evaluate = true

OutputCPUtime = true

Selected continuous time states

Statically selected continuous time states
paralellizationIssue1.volume.medium.p
paralellizationIssue1.volume.medium.T

No Parallelization

Error detected when generating code.

Translation aborted.

WARNINGS have been issued.

ERRORS have been issued.

To give context to the error: paralellizationIssue1 is the sub system model instance and paralellizationIssue1.minMax.yMax is the value that's passed into the massflowSource object for the temperature of the fluid, which has a operating range of 200K to 6000K from the NASA polynomials. So for the system, my initial value (at time=0) is {300, 300} (for N=2) but this is being fed via the vector of step objects (so variable input) and then after the max object, yMax should be just 300K which is in the appropriate range for the fluid. But dymola does not recognise this as can be seen with the assert error.

Observations:

  1. When Advanced.ParallelizeCode=true, the model translation works for the constant (case 3) input but not the other 2 (cases 1 and 2).
  2. When Advanced.ParallelizeCode=false, all three cases work
  3. When either one of the flow branches are removed, translation works with Advanced.ParallelizeCode=true
  4. When the any of the dynamic equations in the volume are turned off, translation works with Advanced.ParallelizeCode=true
  5. Replacing the volume model with a dynamic pipe model, translation fails with Advanced.ParallelizeCode=true, but works when false
  6. No difference with evaluate=false. Nor with the Advanced.Assert related flags shown in the tools menu
  7. The same behaviour is observed with MSL 3.2.3 run on the newer Dymola versions (Dymola 2021X +)

I assume that the translation process has changed significantly from Dymola 2022X to the newer versions, especially for the ParallelizeCode flag. It seems that the asserts are checked before the compilation, and somehow the start values for the non-constant inputs aren't considered for the assert checks. Is there a way to overcome this while still being able to run with parallelize enabled? For our larger models we notice a significant improvement in speed with this flag enabled.

Upvotes: 3

Views: 268

Answers (1)

Hans Olsson
Hans Olsson

Reputation: 12507

That issue will be corrected in Dymola 2023x.

A work-around in Dymola 2023 is to set Hidden.UseNewSortingOfAsserts = false;

However, this model is too small to parallelize effectively so it will not gain anything but just report that there is no parallelization.

An alternative would be to parallelize running the model if you want to simulate it for multiple parametrizations (by using sweep parameter).

Upvotes: 2

Related Questions