1 | within ;
|
---|
2 | model TestMixtureLoop "Test different methods for computing the molecular mass. Two of them (method 1 and 2 computing respectively MM1 and MM2) work properly, while the other two methods (method 3 and 4 computing respectively MM3 and MM4) do not work and simply return the molecular mass of the last species of the array. The method implemented in MixtureGasNasa of the standard library (which computes MM) does not work as well. In the results compare MM, MM1 ... MM4. Summarizing the results:
|
---|
3 | 1) The expression MM3 = medium.X * array(Medium.data[i].MM for i in 1:Medium.nX) does not work both in the equation section and in a function;
|
---|
4 | 2) The for loop works in the equation section but not in the function;
|
---|
5 | 3) The function works properly only when it calls in a loop a second function to which only one element of the array is passed."
|
---|
6 | package Medium = Modelica.Media.IdealGases.MixtureGases.FlueGasSixComponents;
|
---|
7 |
|
---|
8 | package MolarMassFunctions
|
---|
9 | function molarMass2
|
---|
10 | input Modelica.SIunits.MolarMass[Medium.nX] X;
|
---|
11 | output Modelica.SIunits.MolarMass MM2;
|
---|
12 | algorithm
|
---|
13 | MM2 := X * array(mm_i(Medium.data[i]) for i in 1:Medium.nX);
|
---|
14 | annotation(Inline = true, smoothOrder = 2);
|
---|
15 | end molarMass2;
|
---|
16 |
|
---|
17 | function mm_i
|
---|
18 | input Modelica.Media.IdealGases.Common.DataRecord data;
|
---|
19 | output Modelica.SIunits.MolarMass mm;
|
---|
20 | algorithm
|
---|
21 | mm := data.MM;
|
---|
22 | end mm_i;
|
---|
23 |
|
---|
24 | function molarMass4
|
---|
25 | input Modelica.SIunits.MassFraction[Medium.nX] X;
|
---|
26 | output Modelica.SIunits.MolarMass MM4;
|
---|
27 | protected
|
---|
28 | Modelica.SIunits.MolarMass[Medium.nX] mm;
|
---|
29 | algorithm
|
---|
30 | for i in 1:Medium.nX loop
|
---|
31 | mm[i] := Medium.data[i].MM;
|
---|
32 | end for;
|
---|
33 | MM4 := X * mm;
|
---|
34 | annotation(Inline = true, smoothOrder = 2);
|
---|
35 | end molarMass4;
|
---|
36 | end MolarMassFunctions;
|
---|
37 |
|
---|
38 | Medium.BaseProperties medium;
|
---|
39 | Modelica.SIunits.MolarMass mm[Medium.nX] "Array of molecular masses";
|
---|
40 | Modelica.SIunits.MolarMass MM1 "Molecular Mass";
|
---|
41 | Modelica.SIunits.MolarMass MM2 "Molecular Mass";
|
---|
42 | Modelica.SIunits.MolarMass MM3 "Molecular Mass";
|
---|
43 | Modelica.SIunits.MolarMass MM4 "Molecular Mass";
|
---|
44 | equation
|
---|
45 | // First method for computing the molecular mass. IT WORKS
|
---|
46 | for i in 1:Medium.nX loop
|
---|
47 | mm[i] = Medium.data[i].MM;
|
---|
48 | end for;
|
---|
49 | MM1 = medium.X * mm;
|
---|
50 | // End first method
|
---|
51 | // Second method for computing the molecular mass. IT WORKS
|
---|
52 | MM2 = MolarMassFunctions.molarMass2(medium.X);
|
---|
53 | // End second method
|
---|
54 | // Third method for computing the molecular mass. IT DOES NOT WORK
|
---|
55 | MM3 = medium.X * array(Medium.data[i].MM for i in 1:Medium.nX);
|
---|
56 | // End third method
|
---|
57 | // Fourth method for computing the molecular mass. IT DOES NOT WORK
|
---|
58 | MM4 = MolarMassFunctions.molarMass4(medium.X);
|
---|
59 | // End fourth method
|
---|
60 | medium.p = 1e5;
|
---|
61 | medium.T = 300;
|
---|
62 | medium.X[1] = time;
|
---|
63 | medium.X[2] = 1 - time;
|
---|
64 | medium.X[3:6] = zeros(4);
|
---|
65 | annotation(experiment(StartTime = 0.0, StopTime = 1.0), uses(Modelica(version
|
---|
66 | ="3.2.1")));
|
---|
67 | end TestMixtureLoop;
|
---|