Modelica:在 Dymola 中使用 Openmodelica 包

Modelica: Using an Openmodelica Package in Dymola

我正在尝试在 Dymola 中使用 Openmodelica 包(包括一个模型和 3 个函数),但出现了一些错误(参见错误 1)。

当我尝试将受保护的参数(在函数 cal_mod 中)声明为变量时,出现另一个错误(请参阅错误 2)。

这是包的全部代码,下面是错误(错误 1 ​​和错误 2)。

代码:

package RC_Wall
model RCWall
Modelica.SIunits.Conversions.NonSIunits.Temperature_degC Tpa;
Modelica.SIunits.Conversions.NonSIunits.Temperature_degC Tpb;
Modelica.SIunits.Conversions.NonSIunits.Temperature_degC T[mNode](start = vector([24, 24, 24]), fixed = vector([true, true, true]));
Modelica.SIunits.HeatFlowRate Qa;
Modelica.SIunits.HeatFlowRate Qb;
Modelica.SIunits.Conversions.NonSIunits.Temperature_degC T1_end;
Modelica.SIunits.Conversions.NonSIunits.Temperature_degC T2_end;
Modelica.SIunits.Conversions.NonSIunits.Temperature_degC T3_end;
parameter Integer n;
parameter Modelica.SIunits.Area A;
parameter Modelica.SIunits.Length l[n];
parameter Modelica.SIunits.ThermalConductivity lambda[n];
parameter Modelica.SIunits.Density rho[n];
parameter Modelica.SIunits.SpecificHeatCapacity cp[n];
parameter Integer mNode = 3;
parameter Integer nNode(start = 2, fixed = false);
parameter Modelica.SIunits.SpecificHeatCapacity Ca(start = 24800, fixed = false);
parameter Modelica.SIunits.SpecificHeatCapacity Cb(start = 24800, fixed = false);
parameter Modelica.SIunits.SpecificHeatCapacity Cc(start = 102560, fixed = false);
parameter Modelica.SIunits.ThermalInsulance R1(start = 0.81, fixed = false);
parameter Modelica.SIunits.ThermalInsulance R2(start = 0.81, fixed = false);
parameter Modelica.SIunits.ThermalInsulance Ra(start = 0.03, fixed = false);
parameter Modelica.SIunits.ThermalInsulance Rb(start = 0.03, fixed = false);
Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a port_a annotation(Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a port_a1 annotation(Placement(visible = true, transformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
initial equation 
(Ca, Cb, Cc, Ra, Rb, R1, R2, nNode) = RC_Wall.rcopt(n, l, lambda, rho, cp);
equation 
Tpa = port_a.T;
Tpb = port_a1.T;
if R1 < 0.0001 or R2 < 0.0001 or Ra < 0.0001 or Rb < 0.0001 then
  Modelica.Utilities.Streams.error("Resistances too small or negative");
end if;
if Ca < 0.0001 or Cb < 0.0001 or Cc < 0.0001 and nNode == 3 then
  Modelica.Utilities.Streams.error("Capacities too small or negative");
end if;
Ca * A * der(T[1]) = Qa + A / R1 * (T[2] - T[1]);
for i in 2:mNode loop
  if i < nNode and i <> mNode then
    Cc * A * der(T[i]) = A / R1 * (T[i - 1] - T[i]) + A / R2 * (T[i + 1] - T[i]);
  else
    Cb * A * der(T[i]) = Qb + A / R2 * (T[nNode - 1] - T[i]);
  end if;
end for;
Qa = A * (Tpa - T[1]) / Ra;
Qb = A * (Tpb - T[nNode]) / Rb;
Qa = port_a.Q_flow;
Qb = port_a1.Q_flow;
T1_end = T[1];
T2_end = T[2];
T3_end = T[3];
end RCWall;

function rcopt

input Integer n;
input Real[:] l;
input Real[:] lbda;
input Real[:] rho;
input Real[:] specc;
output Real Ca;
output Real Cb;
output Real Cc;
output Real Ra;
output Real Rb;
output Real Ro1;
output Real Ro2;
output Integer nNode;
protected 
Integer i;
Integer nComps;
Integer k2;
Complex A_o;
Complex B_o;
Complex C_o;
Complex D_o;
Complex A_a;
Complex B_a;
Complex C_a;
Complex D_a;
Complex Re1;
Complex Im1;
Complex[2, 2] ma;
Complex[2, 2] mb;
Complex[13] YaComp;
Complex[13] YbComp;
Complex[13] TdComp;
Real[13] T_ev;
Real devat;
Real devbt;
Real[13] deva;
Real[13] devb;
Real[13] devc;
Real devCc;
Real devCcOld;
Real devatOld1;
Real devbtOld1;
Real devct;
Real Ra1;
Real Rb1;
Real Ca1;
Real Cb1;
Real Cc1;
Real Ro11;
Real Ro21;
Real[n] Rlay;
Real[n] Clay;
Real Rt;
Real Ct;
Real Rc;
Real Rsa;
Real Rsb;
Real Csa;
Real Csb;
Real R1s;
Real R2s;
Real Cs;
Real CaRoot1;
Real CbRoot1;
Real Ahelp;
Real Bhelp;
Real Chelp;
Real Ras1;
Real Rbs1;
Real Ro1s1;
Real Ro2s1;
Real Cas1;
Real Cbs1;
Real Xr;
Real Xi;
Real Yr;
Real Yi;
Real Zr;
Real Zi;
Real R11;
Real R21;
Real Ratio;
Real RaSide;
Real RbSide;
Real CcB_a;
Real CcD_a;
Real RaSide1;
Real RbSide1;
Real RaRoot1;
Real RbRoot1;
Real omega_hi;
Real omega_lo;
Real omega;
Real omegac;
Real T[145];
Real Ts;
Real PII;
Real Tc1;
Real Tc2;
Real tol;
algorithm 
nComps := 13;
devCcOld := 99999;
devatOld1 := 99999;
devbtOld1 := 99999;
Rt := 0;
Ct := 0;
Re1 := Complex(1, 0);
Im1 := Complex(0, 1);
PII := 4 * atan(1);
for i in 1:n loop
  Rlay[i] := l[i] / lbda[i];
  Rt := Rt + Rlay[i];
  Clay[i] := rho[i] * specc[i] * l[i];
  Ct := Ct + Clay[i];
end for;
Tc1 := Rt * Clay[1];
Tc2 := Rt * Clay[n];
if Tc1 >= Tc2 then
  Ts := 2 * PII * Tc1;
else
  Ts := 2 * PII * Tc2;
end if;
omega_lo := 2 * PII / Ts;
(A_a, B_a, C_a, D_a) := RC_Wall.cal_an(omega_lo, n, l, lbda, rho, specc);
Ra1 := (Modelica.ComplexMath.real(B_a) + Rt) / (1 - Modelica.ComplexMath.real(A_a));
Rb1 := (Modelica.ComplexMath.real(B_a) + Rt) / (1 - Modelica.ComplexMath.real(D_a));
Rc := Rt - Ra1 - Rb1;
Ca1 := (Modelica.ComplexMath.imag(B_a) + Modelica.ComplexMath.imag(A_a) * (Rc + Ra1)) / (Rc * (Rt - Ra1) * omega_lo);
Cb1 := (Modelica.ComplexMath.imag(B_a) + Modelica.ComplexMath.imag(D_a) * (Rc + Rb1)) / (Rc * (Rt - Rb1) * omega_lo);
Ro11 := Rc;
Ro21 := Rc;
Cc1 := 0;
T_ev := vector([1, 6, 12, 18, 24, 48, 96, 168, 240, 336, 504, 1008, 2016]);
for i in 1:nComps loop
  omega_hi := 2 * PII / (T_ev[i] * 3600);
  (A_a, B_a, C_a, D_a) := RC_Wall.cal_an(omega_hi, n, l, lbda, rho, specc);
  YaComp[i] := -A_a / B_a;
  YbComp[i] := D_a / B_a;
  TdComp[i] := -1 / B_a;
  (A_o, B_o, C_o, D_o) := RC_Wall.cal_mod(omega_hi, Ra1, Rb1, Ro11, Ro21, Ca1, Cb1, Cc1);
  deva[i] := Modelica.ComplexMath.'abs'((YaComp[i] - (-A_o) / B_o) / YaComp[i]);
  devb[i] := Modelica.ComplexMath.'abs'((YbComp[i] - D_o / B_o) / YbComp[i]);
  devc[i] := Modelica.ComplexMath.'abs'((TdComp[i] - 1 / B_o) / TdComp[i]);
end for;
devat := 0;
devbt := 0;
devct := 0;
for i in 1:nComps loop
  devat := devat + deva[i] / nComps;
  devbt := devbt + devb[i] / nComps;
  devct := devct + devc[i] / nComps;
end for;
tol := 0.3;
if devat < tol and devbt < tol and deva[2] < tol and devb[2] < tol and devc[2] < 2 * tol then
  Ra := Ra1;
  Rb := Rb1;
  Ro1 := Ro11 + Ro21;
  Ro2 := Ro11 + Ro21;
  Ca := Ca1;
  Cb := Cb1;
  Cc := 0;
  nNode := 2;
  else
  for k in 1:145 loop
    if k < 40 then
      T[k] := 0.5 * k;
    elseif k < 70 then
      T[k] := k - 20;
    elseif k < 95 then
      T[k] := (k - 70) * 2 + 50;
    else
      T[k] := (k - 95) * 4 + 100;
    end if;
    omega := 2 * PII / (3600 * T[k]);
    (A_a, B_a, C_a, D_a) := RC_Wall.cal_an(omega, n, l, lbda, rho, specc);
    Ratio := Modelica.ComplexMath.real((1 - A_a) / (1 - D_a));
    RaSide := Rt / (Ratio + 1);
    RbSide := Rt - RaSide;
    CcB_a := -Modelica.ComplexMath.imag(B_a / (omega * RaSide * RbSide));
    CcD_a := Modelica.ComplexMath.imag(D_a / (RaSide * omega));
    devCc := abs((CcB_a - CcD_a) / CcB_a);
    if CcB_a > 0 and devCc < devCcOld then
      Cc1 := 0.8 * CcB_a;
      RaSide1 := RaSide;
      RbSide1 := RbSide;
      devCcOld := devCc;
    end if;
    end for;
    for k in 1:145 loop
    omega := 2 * PII / (3600 * T[k]);
    (A_a, B_a, C_a, D_a) := RC_Wall.cal_an(omega, n, l, lbda, rho, specc);
    mb[1, 1] := 1 * Re1;
    mb[1, 2] := RbSide1 * Re1;
    mb[2, 1] := omega * Cc1 * Im1;
    mb[2, 2] := 1 * Re1 + RbSide1 * omega * Cc1 * Im1;
    Xr := Modelica.ComplexMath.real(mb[1, 2] / mb[2, 2]);
    Xi := Modelica.ComplexMath.imag(mb[1, 2] / mb[2, 2]);
    Yr := Modelica.ComplexMath.real(-A_a / B_a);
    Yi := Modelica.ComplexMath.imag(-A_a / B_a);
    Zr := Modelica.ComplexMath.real(mb[1, 2] / mb[2, 2] * (-A_a / B_a));
    Zi := Modelica.ComplexMath.imag(mb[1, 2] / mb[2, 2] * (-A_a / B_a));
    Chelp := (RaSide1 + Xr) * (Zr - 1 + Yr * RaSide1) + Xi * (Zi + RaSide1 * Yi);
    Bhelp := (-(Zr - 1 + Yr * RaSide1) * (1 + Zr)) - (Zi ^ 2 + RaSide1 * Yi * Zi) - (Zi * Yi + RaSide1 * Yi ^ 2) * RaSide1 - (Yr * Zr - Yr + RaSide1 * Yr ^ 2) * RaSide1;
    Ahelp := Zi * Yi + RaSide1 * Yi ^ 2 + Yr * Zr - Yr + Yr ^ 2 * RaSide1;
    RaRoot1 := ((-Bhelp) - sqrt(Bhelp ^ 2 - 4 * Ahelp * Chelp)) / (2 * Ahelp);
    R11 := RaSide1 - RaRoot1;
    CaRoot1 := (Zr - 1 + Yr * RaSide1) / (omega * (Zi * RaRoot1 - Xi + Yi * (RaSide1 - RaRoot1) * RaRoot1));
    devat := 0.0;
    for k2 in 1:nComps loop
      omegac := 2 * PII / (3600 * T_ev[k2]);
      (A_o, B_o, C_o, D_o) := RC_Wall.cal_mod(omegac, RaRoot1, 0.0, R11, RbSide1, CaRoot1, 0.0, Cc1);
      deva[k2] := Modelica.ComplexMath.'abs'(((-A_o / B_o) - YaComp[k2]) / YaComp[k2]);
      devb[k2] := Modelica.ComplexMath.'abs'((D_o / B_o - YbComp[k2]) / YbComp[k2]);
      devat := devat + deva[k2] / nComps;
    end for;
    if devat < devatOld1 then
      Ras1 := RaRoot1;
      Ro1s1 := R11;
      Cas1 := CaRoot1;
      devatOld1 := devat;
    end if;
    ma[1, 1] := 1 * Re1;
    ma[1, 2] := -RaSide1 * Re1;
    ma[2, 1] := -omega * Cc1 * Im1;
    ma[2, 2] := 1 * Re1 + RaSide1 * omega * Cc1 * Im1;
    Xr := -Modelica.ComplexMath.real(ma[1, 2] / ma[2, 2]);
    Xi := -Modelica.ComplexMath.imag(ma[1, 2] / ma[2, 2]);
    Yr := -Modelica.ComplexMath.real(D_a / B_a);
    Yi := -Modelica.ComplexMath.imag(D_a / B_a);
    Zr := Modelica.ComplexMath.real(ma[1, 2] / ma[2, 2] * (D_a / B_a));
    Zi := Modelica.ComplexMath.imag(ma[1, 2] / ma[2, 2] * (D_a / B_a));
    Chelp := (RbSide1 + Xr) * (Zr - 1.0 + Yr * RbSide1) + Xi * (Zi + RbSide1 * Yi);
    Bhelp := (-(Zr - 1.0 + Yr * RbSide1) * (1.0 + Zr)) - (Zi ^ 2 + RbSide1 * Yi * Zi) - (Zi * Yi + RbSide1 * Yi ^ 2) * RbSide1 - (Yr * Zr - Yr + RbSide1 * Yr ^ 2) * RbSide1;
    Ahelp := Zi * Yi + RbSide1 * Yi ^ 2 + Yr * Zr - Yr + Yr ^ 2 * RbSide1;
    RbRoot1 := ((-Bhelp) - sqrt(Bhelp ^ 2 - 4.0 * Ahelp * Chelp)) / (2.0 * Ahelp);
    R21 := RbSide1 - RbRoot1;
    CbRoot1 := (Zr - 1 + Yr * RbSide1) / (omega * (Zi * RbRoot1 - Xi + Yi * (RbSide1 - RbRoot1) * RbRoot1));
    devbt := 0;
    for k2 in 1:nComps loop
      omegac := 2 * PII / (3600 * T_ev[k2]);
      (A_o, B_o, C_o, D_o) := RC_Wall.cal_mod(omegac, 0.0, RbRoot1, RaSide1, Ro21, 0.0, CbRoot1, Cc1);
      deva[k2] := Modelica.ComplexMath.'abs'(((-A_o / B_o) - YaComp[k2]) / YaComp[k2]);
      devb[k2] := Modelica.ComplexMath.'abs'((D_o / B_o - YbComp[k2]) / YbComp[k2]);
      devbt := devbt + devb[k2] / nComps;
    end for;
    if devbt < devbtOld1 then
      Rbs1 := RbRoot1;
      Ro2s1 := R21;
      Cbs1 := CbRoot1;
      devbtOld1 := devbt;
    end if;
  end for;
  devatOld1 := 99999;
  devbtOld1 := 99999;
  for k in 1:145 loop
    omega := 2 * PII / (3600 * T[k]);
    (A_a, B_a, C_a, D_a) := RC_Wall.cal_an(omega, n, l, lbda, rho, specc);
    mb[1, 1] := 1 * Re1 + Ro2s1 * omega * Cbs1 * Im1;
    mb[1, 2] := (Rbs1 + Ro2s1) * Re1 + Rbs1 * Ro2s1 * omega * Cbs1 * Im1;
    mb[2, 1] := omega * (Cbs1 + Cc1) * Im1 - Ro2s1 * omega ^ 2 * Cbs1 * Cc1 * Re1;
    mb[2, 2] := (1 - Ro2s1 * Rbs1 * omega ^ 2 * Cbs1 * Cc1) * Re1 + (Rbs1 * omega * (Cbs1 + Cc1) + omega * Ro2s1 * Cc1) * Im1;
    Xr := Modelica.ComplexMath.real(mb[1, 2] / mb[2, 2]);
    Xi := Modelica.ComplexMath.imag(mb[1, 2] / mb[2, 2]);
    Yr := Modelica.ComplexMath.real(-A_a / B_a);
    Yi := Modelica.ComplexMath.imag(-A_a / B_a);
    Zr := Modelica.ComplexMath.real(mb[1, 2] / mb[2, 2] * (-A_a / B_a));
    Zi := Modelica.ComplexMath.imag(mb[1, 2] / mb[2, 2] * (-A_a / B_a));
    Chelp := (RaSide1 + Xr) * (Zr - 1 + Yr * RaSide1) + Xi * (Zi + RaSide1 * Yi);
    Bhelp := (-(Zr - 1 + Yr * RaSide1) * (1 + Zr)) - (Zi ^ 2 + RaSide1 * Yi * Zi) - (Zi * Yi + RaSide1 * Yi ^ 2) * RaSide1 - (Yr * Zr - Yr + RaSide1 * Yr ^ 2) * RaSide1;
    Ahelp := Zi * Yi + RaSide1 * Yi ^ 2 + Yr * Zr - Yr + Yr ^ 2 * RaSide1;
    RaRoot1 := ((-Bhelp) - sqrt(Bhelp ^ 2 - 4 * Ahelp * Chelp)) / (2 * Ahelp);
    R11 := RaSide1 - RaRoot1;
    CaRoot1 := (Zr - 1 + Yr * RaSide1) / (omega * (Zi * RaRoot1 - Xi + Yi * (RaSide1 - RaRoot1) * RaRoot1));
    devat := 0;
    for k2 in 1:nComps loop
      omegac := 2 * PII / (3600 * T_ev[k2]);
      (A_o, B_o, C_o, D_o) := RC_Wall.cal_mod(omegac, RaRoot1, Rbs1, R11, Ro2s1, CaRoot1, Cbs1, Cc1);
      deva[k2] := Modelica.ComplexMath.'abs'(((-A_o / B_o) - YaComp[k2]) / YaComp[k2]);
      devb[k2] := Modelica.ComplexMath.'abs'((D_o / B_o - YbComp[k2]) / YbComp[k2]);
      devat := devat + deva[k2] / nComps;
    end for;
    if devat < devatOld1 then
      Ra1 := RaRoot1;
      Ro11 := R11;
      Ca1 := CaRoot1;
      devatOld1 := devat;
    end if;
    ma[1, 1] := 1 * Re1 + Ro1s1 * omega * Cas1 * Im1;
    ma[1, 2] := (-(Ras1 + Ro1s1) * Re1) - Ras1 * Ro1s1 * omega * Cas1 * Im1;
    ma[2, 1] := (-omega * (Cas1 + Cc1) * Im1) + Ro1s1 * omega ^ 2 * Cas1 * Cc1 * Re1;
    ma[2, 2] := (1 - Ro1s1 * Ras1 * omega ^ 2 * Cas1 * Cc1) * Re1 + (Ras1 * omega * (Cas1 + Cc1) + omega * Ro1s1 * Cc1) * Im1;
    Xr := -Modelica.ComplexMath.real(ma[1, 2] / ma[2, 2]);
    Xi := -Modelica.ComplexMath.imag(ma[1, 2] / ma[2, 2]);
    Yr := -Modelica.ComplexMath.real(D_a / B_a);
    Yi := -Modelica.ComplexMath.imag(D_a / B_a);
    Zr := Modelica.ComplexMath.real(ma[1, 2] / ma[2, 2] * (D_a / B_a));
    Zi := Modelica.ComplexMath.imag(ma[1, 2] / ma[2, 2] * (D_a / B_a));
    Chelp := (RbSide1 + Xr) * (Zr - 1 + Yr * RbSide1) + Xi * (Zi + RbSide1 * Yi);
    Bhelp := (-(Zr - 1 + Yr * RbSide1) * (1 + Zr)) - (Zi ^ 2 + RbSide1 * Yi * Zi) - (Zi * Yi + RbSide1 * Yi ^ 2) * RbSide1 - (Yr * Zr - Yr + RbSide1 * Yr ^ 2) * RbSide1;
    Ahelp := Zi * Yi + RbSide1 * Yi ^ 2 + Yr * Zr - Yr + Yr ^ 2 * RbSide1;
    RbRoot1 := ((-Bhelp) - sqrt(Bhelp ^ 2 - 4 * Ahelp * Chelp)) / (2 * Ahelp);
    R21 := RbSide1 - RbRoot1;
    CbRoot1 := (Zr - 1 + Yr * RbSide1) / (omega * (Zi * RbRoot1 - Xi + Yi * (RbSide1 - RbRoot1) * RbRoot1));
    devbt := 0;
    for k2 in 1:nComps loop
      omegac := 2 * PII / (3600 * T_ev[k2]);
      (A_o, B_o, C_o, D_o) := RC_Wall.cal_mod(omegac, Ras1, RbRoot1, Ro1s1, R21, Cas1, CbRoot1, Cc1);
      deva[k2] := Modelica.ComplexMath.'abs'(((-A_o / B_o) - YaComp[k2]) / YaComp[k2]);
      devb[k2] := Modelica.ComplexMath.'abs'((D_o / B_o - YbComp[k2]) / YbComp[k2]);
      devbt := devbt + devb[k2] / nComps;
    end for;
    if devbt < devbtOld1 then
      Rb1 := RbRoot1;
      Ro21 := R21;
      Cb1 := CbRoot1;
      devbtOld1 := devbt;
    end if;
  end for;
  Ro1 := Ro11;
  Ro2 := Ro21;
  Cc := Cc1;
  Ra := Ra1;
  Rb := Rb1;
  Ca := Ca1;
  Cb := Cb1;
  nNode := 3;
end if;
end rcopt;

function cal_an

import Complex;
input Real omega;
input Integer n;
input Real[:] l1;
input Real[:] lbda1;
input Real[:] rho1;
input Real[:] specc1;
output Complex A_o;
output Complex B_o;
output Complex C_o;
output Complex D_o;
protected 
Complex A;
Complex A1;
Complex B;
Complex B1;
Complex C;
Complex C1;
Complex D;
Complex D1;
Complex X;
Complex PART1;
Complex PART2;
Real therm_d;
Real k;
Real kl;
Real klb;
Integer i;
algorithm 
X := Complex(1, 1);
for i in 1:n loop
  therm_d := lbda1[i] / (rho1[i] * specc1[i]);
  k := sqrt(omega / (2 * therm_d));
  kl := k * l1[i];
  klb := k * lbda1[i];
  PART1 := Modelica.ComplexMath.exp(kl * X);
  PART2 := Modelica.ComplexMath.exp(-kl * X);
  A := (PART1 + PART2) / 2;
  B := -(PART1 - PART2) / (2 * klb * X);
  C := -klb * X * (PART1 - PART2) / 2;
  D := (PART1 + PART2) / 2;
  if i == 1 then
    A_o := A;
    B_o := B;
    C_o := C;
    D_o := D;
  else
    A1 := A * A_o + B * C_o;
    B1 := A * B_o + B * D_o;
    C1 := C * A_o + D * C_o;
    D1 := C * B_o + D * D_o;
    A_o := A1;
    B_o := B1;
    C_o := C1;
    D_o := D1;
  end if;
end for;
end cal_an;

function cal_mod
import Complex;
input Real omega;
input Real RaM;
input Real RbM;
input Real Ro1M;
input Real Ro2M;
input Real CaM;
input Real CbM;
input Real CcM;
output Complex A_o;
output Complex B_o;
output Complex C_o;
output Complex D_o;
protected 
Complex A;
Complex A1;
Complex B;
Complex B1;
Complex C;
Complex C1;
Complex D;
Complex D1;
parameter Integer i;
algorithm 
for i in 1:7 loop
  A := Complex(1, 0);
  D := Complex(1, 0);
  if i == 1 then
    B := -RaM * Complex(1, 0);
    C := Complex(0, 0);
  elseif i == 2 then
    B := Complex(0, 0);
    C := Complex(0, 1) * (-CaM * omega);
  elseif i == 3 then
    B := (-Ro1M) * Complex(1, 0);
    C := Complex(0, 0);
  elseif i == 4 then
    B := Complex(0, 0);
    C := Complex(0, 1) * (-CcM * omega);
  elseif i == 5 then
    B := (-Ro2M) * Complex(1, 0);
    C := Complex(0, 0);
  elseif i == 6 then
    B := Complex(0, 0);
    C := Complex(0, 1) * (-CbM * omega);
  elseif i == 7 then
    B := (-RbM) * Complex(1, 0);
    C := Complex(0, 0);
  end if;
  if i == 1 then
    A_o := A;
    B_o := B;
    C_o := C;
    D_o := D;
  else
    A1 := A * A_o + B * C_o;
    B1 := A * B_o + B * D_o;
    C1 := C * A_o + D * C_o;
    D1 := C * B_o + D * D_o;
    A_o := A1;
    B_o := B1;
    C_o := C1;
    D_o := D1;
  end if;
end for;
end cal_mod;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end RC_Wall;

错误 1:

Check of Bachelorarbeit_Bloch.RC_Wall:

Checking model Bachelorarbeit_Bloch.RC_Wall.RCWall:

Assignment to parameter or constant: A In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: D In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: B In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: C In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: B In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: C In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: B In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: C In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: B In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: C In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: B In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: C In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: B In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: C In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: B In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: C In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: A1 In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: B1 In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: C1 In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Assignment to parameter or constant: D1 In function Bachelorarbeit_Bloch.RC_Wall.cal_mod

Errors detected in functions.

Check aborted.

Local classes checked, checking Bachelorarbeit_Bloch.RC_Wall:

ERROR: 20 errors were found

错误 2:

Check of Bachelorarbeit_Bloch.RC_Wall:

Checking model Bachelorarbeit_Bloch.RC_Wall.RCWall:

The model has the same number of unknowns and equations.

The parameter nNode has the attribute fixed = false indicating its value to be calculated from initial conditions. Error: However, it is used to specify a structural property and it must be possible to evaluate it at translation.

The parameter Ca has the attribute fixed = false indicating its value to be calculated from initial conditions. Error: However, it is used to specify a structural property and it must be possible to evaluate it at translation.

The parameter Cb has the attribute fixed = false indicating its value to be calculated from initial conditions. Error: However, it is used to specify a structural property and it must be possible to evaluate it at translation.

The parameter Cc has the attribute fixed = false indicating its value to be calculated from initial conditions. Error: However, it is used to specify a structural property and it must be possible to evaluate it at translation.

The parameter R1 has the attribute fixed = false indicating its value to be calculated from initial conditions. Error: However, it is used to specify a structural property and it must be possible to evaluate it at translation.

The parameter R2 has the attribute fixed = false indicating its value to be calculated from initial conditions. Error: However, it is used to specify a structural property and it must be possible to evaluate it at translation.

The parameter Ra has the attribute fixed = false indicating its value to be calculated from initial conditions. Error: However, it is used to specify a structural property and it must be possible to evaluate it at translation.

The parameter Rb has the attribute fixed = false indicating its value to be calculated from initial conditions. Error: However, it is used to specify a structural property and it must be possible to evaluate it at translation.

Errors detected in model.

Check aborted.

Local classes checked, checking Bachelorarbeit_Bloch.RC_Wall:

ERROR: 16 errors were found

这可以通过以下方式解决(至少用于检查)。

在 RCwall 中添加一个新的非参数

Integer nNode2=nNode;

然后修改主要代码如下:

initial equation 
  (Ca, Cb, Cc, Ra, Rb, R1, R2, nNode) = RC_Wall.rcopt(n, l, lambda, rho, cp);
initial algorithm 
 if R1 < 0.0001 or R2 < 0.0001 or Ra < 0.0001 or Rb < 0.0001 then
  Modelica.Utilities.Streams.error("Resistances too small or negative");
end if;
if Ca < 0.0001 or Cb < 0.0001 or Cc < 0.0001 and nNode2 == 3 then
  Modelica.Utilities.Streams.error("Capacities too small or negative");
end if;
equation 
Tpa = port_a.T;
Tpb = port_a1.T;

Ca * A * der(T[1]) = Qa + A / R1 * (T[2] - T[1]);
for i in 2:mNode loop
  if i < nNode2 and i <> mNode then
    Cc * A * der(T[i]) = A / R1 * (T[i - 1] - T[i]) + A / R2 * (T[i + 1] - T[i]);
  else
    Cb * A * der(T[i]) = Qb + A / R2 * (T[nNode2 - 1] - T[i]);
  end if;
end for;
Qa = A * (Tpa - T[1]) / Ra;
Qb = A * (Tpb - T[nNode2]) / Rb;
Qa = port_a.Q_flow;
Qb = port_a1.Q_flow;
T1_end = T[1];
T2_end = T[2];
T3_end = T[3];

问题是某些代码应该将带有 fixed=false 的参数视为非参数(并且处理非参数情况),但它不会,而是生成错误消息。

这有望在未来的 Dymola 版本中得到纠正。