在 Dymola 中解释平面代码和计数方程
Interpreting flat code and counting equations in Dymola
我无法在我正在进行的建模项目中找到其他未知数的来源。我收到一条错误消息,说我有 34 个未知数和 33 个方程。我决定查看 Dymola 中的扁平化代码,虽然我可以计算出正确的变量数量,但我找不到找到 33 个方程的方法。下面是扁平化的代码:
model HeatStorage
parameter Modelica.SIunits.Diameter D = 18.667 "Diameter";
parameter Modelica.SIunits.Height H = 20 "Height";
parameter Boolean enable_losses = false "= true enable thermal losses with environment";
parameter Modelica.SIunits.CoefficientOfHeatTransfer alpha = 1
"Constant heat transfer coefficient with the ambient";
parameter Real L_start = 0 "Start value of level in %";
parameter Modelica.SIunits.Temperature T_start = Modelica.SIunits.Conversions.from_degC
(300) "Start value of temperature";
parameter Modelica.SIunits.Temperature T_max = Modelica.SIunits.Conversions.from_degC
(550) "Maximum tank temperature";
parameter Modelica.SIunits.Temperature T_set = Modelica.SIunits.Conversions.from_degC
(300) "Tank Heater Temperature Set-Point";
parameter Modelica.SIunits.Power W_max = 3000000000.0 "Hot Tank Heater Capacity";
parameter Modelica.SIunits.Efficiency e_ht = 0.99 "Tank Heater Efficiency";
parameter Boolean medium.preferredMediumStates = false "= true if StateSelect.prefer shall be used for the independent property variables of the medium";
parameter Boolean medium.standardOrderComponents = true "If true, and reducedX = true, the last element of X will be computed from the other ones";
input Modelica.Blocks.Interfaces.RealInput Q_heater;
parameter Modelica.SIunits.Volume V_t = H*3.141592653589793*D^2/4;
Modelica.Media.Interfaces.PartialMedium.MassFlowRate fluid_a.m_flow
"Mass flow rate from the connection point into the component";
Modelica.Media.Interfaces.Types.AbsolutePressure fluid_a.p "Thermodynamic pressure in the connection point";
Modelica.Media.Interfaces.Types.SpecificEnthalpy fluid_a.h_outflow
"Specific thermodynamic enthalpy close to the connection point if m_flow < 0";
Modelica.Media.Interfaces.Types.MassFraction fluid_a.Xi_outflow[0]
"Independent mixture mass fractions m_i/m close to the connection point if m_flow < 0";
Modelica.Media.Interfaces.Types.ExtraProperty fluid_a.C_outflow[0](start =
fill(1.0, size(fluid_a.C_outflow, 1))) "Properties c_i/m close to the connection point if m_flow < 0";
Modelica.Media.Interfaces.PartialMedium.MassFlowRate fluid_b.m_flow
"Mass flow rate from the connection point into the component";
Modelica.Media.Interfaces.Types.AbsolutePressure fluid_b.p "Thermodynamic pressure in the connection point";
Modelica.Media.Interfaces.Types.SpecificEnthalpy fluid_b.h_outflow
"Specific thermodynamic enthalpy close to the connection point if m_flow < 0";
Modelica.Media.Interfaces.Types.MassFraction fluid_b.Xi_outflow[0]
"Independent mixture mass fractions m_i/m close to the connection point if m_flow < 0";
Modelica.Media.Interfaces.Types.ExtraProperty fluid_b.C_outflow[0](start =
fill(1.0, size(fluid_b.C_outflow, 1))) "Properties c_i/m close to the connection point if m_flow < 0";
Modelica.SIunits.Temperature heat_PB.T "Port temperature";
Modelica.SIunits.HeatFlowRate heat_PB.Q_flow "Heat flow rate (positive if flowing from outside into the component)";
Modelica.SIunits.Temperature heat_DS.T "Port temperature";
Modelica.SIunits.HeatFlowRate heat_DS.Q_flow "Heat flow rate (positive if flowing from outside into the component)";
Modelica.SIunits.Volume V;
Modelica.SIunits.Mass m;
Modelica.Media.Interfaces.PartialMedium.BaseProperties_D1.InputAbsolutePressure
medium.p(nominal = 100000.0, unit = "Pa", displayUnit = "bar", min = 0.0)
"Absolute pressure of medium";
Modelica.Media.Interfaces.PartialMedium.BaseProperties_D1.InputMassFraction
medium.Xi[0](start = {}, unit = "1", min = 0.0, max = 1.0) "Structurally independent mass fractions";
Modelica.Media.Interfaces.PartialMedium.BaseProperties_D1.InputSpecificEnthalpy
medium.h(unit = "J/kg") "Specific enthalpy of medium";
Modelica.Media.Interfaces.Types.Density medium.d "Density of medium";
Modelica.Media.Interfaces.Types.Temperature medium.T(start = 800, min = 573.15,
max = 873.15) "Temperature of medium";
Modelica.Media.Interfaces.Types.MassFraction medium.X[2](start = {0.5, 0.5})
"Mass fractions (= (component mass)/total mass m_i/m)";
Modelica.Media.Interfaces.Types.SpecificInternalEnergy medium.u
"Specific internal energy of medium";
Modelica.Media.Interfaces.Types.SpecificHeatCapacity medium.R "Gas constant (of mixture if applicable)";
Modelica.Media.Interfaces.Types.MolarMass medium.MM "Molar mass (of mixture or single fluid)";
Modelica.Media.Interfaces.Types.AbsolutePressure medium.state.p
"Absolute pressure of medium";
Modelica.Media.Interfaces.Types.SpecificEnthalpy medium.state.h
"Specific enthalpy";
Modelica.SIunits.Conversions.NonSIunits.Temperature_degC medium.T_degC =
Modelica.SIunits.Conversions.to_degC(medium.T) "Temperature of medium in [degC]";
Modelica.SIunits.Conversions.NonSIunits.Pressure_bar medium.p_bar =
Modelica.SIunits.Conversions.to_bar(medium.p) "Absolute pressure of medium in [bar]";
Modelica.SIunits.Area A;
Modelica.SIunits.HeatFlowRate Q_losses;
Modelica.Media.Interfaces.Types.AbsolutePressure state_i.p "Absolute pressure of medium";
Modelica.Media.Interfaces.Types.SpecificEnthalpy state_i.h "Specific enthalpy";
Modelica.SIunits.Power W_net;
Modelica.SIunits.Power W_loss;
output Modelica.Blocks.Interfaces.RealOutput L "Tank level in %";
Modelica.SIunits.HeatFlowRate Q_PB "Heat Flow to PowerBlock";
Modelica.SIunits.HeatFlowRate Q_desal "Heat Flow to Desalination";
// Equations and algorithms
// Component medium
// class SolarTherm.Media.MoltenSalt.MoltenSalt_base.BaseProperties
// extends Modelica.Media.Interfaces.PartialMedium.BaseProperties_D1
equation
if (medium.standardOrderComponents) then
medium.Xi = medium.X[1:0];
medium.X = {0.5, 0.5};
for i in (1:2) loop
assert(medium.X[i] >= -1E-005 and medium.X[i] <= 1.00001,
"Mass fraction X["+ String(i, true, 0)+"] = "+ String(
medium.X[i], true, 0)+"of substance "+{"NaNO3", "KNO3"}[i]+
"\nof medium "+"MoltenSalt"+" is not in the range 0..1");
end for;
end if;
assert(medium.p >= 0.0, "Pressure (= "+ String(medium.p, true, 0)+
" Pa) of medium \""+"MoltenSalt"+"\" is negative\n(Temperature = "+
String(medium.T, true, 0)+" K)");
// end of extends
equation
medium.d = SolarTherm.Media.MoltenSalt.MoltenSalt_Utilities.rho_T(medium.T);
medium.h = medium.state.h;
medium.u = medium.h-medium.p/medium.d;
medium.MM = 0.091438;
medium.R = 8.3144/medium.MM;
medium.state.p = medium.p;
medium.T = SolarTherm.Media.MoltenSalt.MoltenSalt_Utilities.T_h(medium.h);
// This model
// class PentakomoPlant.Storage.HeatStorage
equation
Q_losses = -0.939*exp(Modelica.SIunits.Conversions.to_degC(medium.T)*
0.005111)*1000*5/7;
fluid_a.p = medium.p;
fluid_b.p = medium.p;
fluid_a.h_outflow = medium.h;
fluid_b.h_outflow = medium.h;
der(m) = fluid_a.m_flow+fluid_b.m_flow;
m*der(medium.h)+der(m)*medium.h = Q_losses+Q_PB+Q_desal+W_net+fluid_a.m_flow
*inStream(fluid_a.h_outflow)+fluid_b.m_flow*medium.h;
V = m/medium.d;
L = 100*(max(medium.T, T_set)-T_set)/(T_max-T_set);
A = 6.283185307179586*(D/2)*H;
W_net = Q_heater;
W_loss = W_net/e_ht;
heat_PB.Q_flow = Q_PB;
heat_DS.Q_flow = Q_desal;
heat_PB.T = medium.T;
heat_DS.T = medium.T;
// Initial equations and algorithms
// This model
// class PentakomoPlant.Storage.HeatStorage
initial equation
medium.h = specificEnthalpy_Unique3(
state_i);
m = density_Unique4(
state_i)*V_t;
end HeatStorage;
如果有人能详细说明如何从平面代码中计算出方程式,以帮助我找到丢失的变量,我将不胜感激!
不幸的是,扁平化的代码没有包含所有必要的信息。
不过,这是一个好的开始,包含 27 个方程式:
- 2 个结合方程
- 扩展 Modelica.Media.Interfaces.PartialMedium.BaseProperties_D1
中的 2 个标量方程
- 7个方程在SolarTherm.Media.MoltenSalt.MoltenSalt_base.BaseProperties外基-class
- PentakomoPlant.Storage.HeatStorage 中的 16 个方程式。
但除此之外至少可以有:
- 记录绑定(本例中为none)
- 顶级 public 连接器中的流变量;在这种情况下,我假设它是 2+2+1+1 (fluid_a, fluid_b, heat_PB, heat_DS).
顶层 public 输入 Q_heater 可以用两种方式处理,我记得 Dymola 使用了两种变体:要么它既不对未知数也不对方程式(视为一个已知变量),或者将两者加一。
我无法在我正在进行的建模项目中找到其他未知数的来源。我收到一条错误消息,说我有 34 个未知数和 33 个方程。我决定查看 Dymola 中的扁平化代码,虽然我可以计算出正确的变量数量,但我找不到找到 33 个方程的方法。下面是扁平化的代码:
model HeatStorage
parameter Modelica.SIunits.Diameter D = 18.667 "Diameter";
parameter Modelica.SIunits.Height H = 20 "Height";
parameter Boolean enable_losses = false "= true enable thermal losses with environment";
parameter Modelica.SIunits.CoefficientOfHeatTransfer alpha = 1
"Constant heat transfer coefficient with the ambient";
parameter Real L_start = 0 "Start value of level in %";
parameter Modelica.SIunits.Temperature T_start = Modelica.SIunits.Conversions.from_degC
(300) "Start value of temperature";
parameter Modelica.SIunits.Temperature T_max = Modelica.SIunits.Conversions.from_degC
(550) "Maximum tank temperature";
parameter Modelica.SIunits.Temperature T_set = Modelica.SIunits.Conversions.from_degC
(300) "Tank Heater Temperature Set-Point";
parameter Modelica.SIunits.Power W_max = 3000000000.0 "Hot Tank Heater Capacity";
parameter Modelica.SIunits.Efficiency e_ht = 0.99 "Tank Heater Efficiency";
parameter Boolean medium.preferredMediumStates = false "= true if StateSelect.prefer shall be used for the independent property variables of the medium";
parameter Boolean medium.standardOrderComponents = true "If true, and reducedX = true, the last element of X will be computed from the other ones";
input Modelica.Blocks.Interfaces.RealInput Q_heater;
parameter Modelica.SIunits.Volume V_t = H*3.141592653589793*D^2/4;
Modelica.Media.Interfaces.PartialMedium.MassFlowRate fluid_a.m_flow
"Mass flow rate from the connection point into the component";
Modelica.Media.Interfaces.Types.AbsolutePressure fluid_a.p "Thermodynamic pressure in the connection point";
Modelica.Media.Interfaces.Types.SpecificEnthalpy fluid_a.h_outflow
"Specific thermodynamic enthalpy close to the connection point if m_flow < 0";
Modelica.Media.Interfaces.Types.MassFraction fluid_a.Xi_outflow[0]
"Independent mixture mass fractions m_i/m close to the connection point if m_flow < 0";
Modelica.Media.Interfaces.Types.ExtraProperty fluid_a.C_outflow[0](start =
fill(1.0, size(fluid_a.C_outflow, 1))) "Properties c_i/m close to the connection point if m_flow < 0";
Modelica.Media.Interfaces.PartialMedium.MassFlowRate fluid_b.m_flow
"Mass flow rate from the connection point into the component";
Modelica.Media.Interfaces.Types.AbsolutePressure fluid_b.p "Thermodynamic pressure in the connection point";
Modelica.Media.Interfaces.Types.SpecificEnthalpy fluid_b.h_outflow
"Specific thermodynamic enthalpy close to the connection point if m_flow < 0";
Modelica.Media.Interfaces.Types.MassFraction fluid_b.Xi_outflow[0]
"Independent mixture mass fractions m_i/m close to the connection point if m_flow < 0";
Modelica.Media.Interfaces.Types.ExtraProperty fluid_b.C_outflow[0](start =
fill(1.0, size(fluid_b.C_outflow, 1))) "Properties c_i/m close to the connection point if m_flow < 0";
Modelica.SIunits.Temperature heat_PB.T "Port temperature";
Modelica.SIunits.HeatFlowRate heat_PB.Q_flow "Heat flow rate (positive if flowing from outside into the component)";
Modelica.SIunits.Temperature heat_DS.T "Port temperature";
Modelica.SIunits.HeatFlowRate heat_DS.Q_flow "Heat flow rate (positive if flowing from outside into the component)";
Modelica.SIunits.Volume V;
Modelica.SIunits.Mass m;
Modelica.Media.Interfaces.PartialMedium.BaseProperties_D1.InputAbsolutePressure
medium.p(nominal = 100000.0, unit = "Pa", displayUnit = "bar", min = 0.0)
"Absolute pressure of medium";
Modelica.Media.Interfaces.PartialMedium.BaseProperties_D1.InputMassFraction
medium.Xi[0](start = {}, unit = "1", min = 0.0, max = 1.0) "Structurally independent mass fractions";
Modelica.Media.Interfaces.PartialMedium.BaseProperties_D1.InputSpecificEnthalpy
medium.h(unit = "J/kg") "Specific enthalpy of medium";
Modelica.Media.Interfaces.Types.Density medium.d "Density of medium";
Modelica.Media.Interfaces.Types.Temperature medium.T(start = 800, min = 573.15,
max = 873.15) "Temperature of medium";
Modelica.Media.Interfaces.Types.MassFraction medium.X[2](start = {0.5, 0.5})
"Mass fractions (= (component mass)/total mass m_i/m)";
Modelica.Media.Interfaces.Types.SpecificInternalEnergy medium.u
"Specific internal energy of medium";
Modelica.Media.Interfaces.Types.SpecificHeatCapacity medium.R "Gas constant (of mixture if applicable)";
Modelica.Media.Interfaces.Types.MolarMass medium.MM "Molar mass (of mixture or single fluid)";
Modelica.Media.Interfaces.Types.AbsolutePressure medium.state.p
"Absolute pressure of medium";
Modelica.Media.Interfaces.Types.SpecificEnthalpy medium.state.h
"Specific enthalpy";
Modelica.SIunits.Conversions.NonSIunits.Temperature_degC medium.T_degC =
Modelica.SIunits.Conversions.to_degC(medium.T) "Temperature of medium in [degC]";
Modelica.SIunits.Conversions.NonSIunits.Pressure_bar medium.p_bar =
Modelica.SIunits.Conversions.to_bar(medium.p) "Absolute pressure of medium in [bar]";
Modelica.SIunits.Area A;
Modelica.SIunits.HeatFlowRate Q_losses;
Modelica.Media.Interfaces.Types.AbsolutePressure state_i.p "Absolute pressure of medium";
Modelica.Media.Interfaces.Types.SpecificEnthalpy state_i.h "Specific enthalpy";
Modelica.SIunits.Power W_net;
Modelica.SIunits.Power W_loss;
output Modelica.Blocks.Interfaces.RealOutput L "Tank level in %";
Modelica.SIunits.HeatFlowRate Q_PB "Heat Flow to PowerBlock";
Modelica.SIunits.HeatFlowRate Q_desal "Heat Flow to Desalination";
// Equations and algorithms
// Component medium
// class SolarTherm.Media.MoltenSalt.MoltenSalt_base.BaseProperties
// extends Modelica.Media.Interfaces.PartialMedium.BaseProperties_D1
equation
if (medium.standardOrderComponents) then
medium.Xi = medium.X[1:0];
medium.X = {0.5, 0.5};
for i in (1:2) loop
assert(medium.X[i] >= -1E-005 and medium.X[i] <= 1.00001,
"Mass fraction X["+ String(i, true, 0)+"] = "+ String(
medium.X[i], true, 0)+"of substance "+{"NaNO3", "KNO3"}[i]+
"\nof medium "+"MoltenSalt"+" is not in the range 0..1");
end for;
end if;
assert(medium.p >= 0.0, "Pressure (= "+ String(medium.p, true, 0)+
" Pa) of medium \""+"MoltenSalt"+"\" is negative\n(Temperature = "+
String(medium.T, true, 0)+" K)");
// end of extends
equation
medium.d = SolarTherm.Media.MoltenSalt.MoltenSalt_Utilities.rho_T(medium.T);
medium.h = medium.state.h;
medium.u = medium.h-medium.p/medium.d;
medium.MM = 0.091438;
medium.R = 8.3144/medium.MM;
medium.state.p = medium.p;
medium.T = SolarTherm.Media.MoltenSalt.MoltenSalt_Utilities.T_h(medium.h);
// This model
// class PentakomoPlant.Storage.HeatStorage
equation
Q_losses = -0.939*exp(Modelica.SIunits.Conversions.to_degC(medium.T)*
0.005111)*1000*5/7;
fluid_a.p = medium.p;
fluid_b.p = medium.p;
fluid_a.h_outflow = medium.h;
fluid_b.h_outflow = medium.h;
der(m) = fluid_a.m_flow+fluid_b.m_flow;
m*der(medium.h)+der(m)*medium.h = Q_losses+Q_PB+Q_desal+W_net+fluid_a.m_flow
*inStream(fluid_a.h_outflow)+fluid_b.m_flow*medium.h;
V = m/medium.d;
L = 100*(max(medium.T, T_set)-T_set)/(T_max-T_set);
A = 6.283185307179586*(D/2)*H;
W_net = Q_heater;
W_loss = W_net/e_ht;
heat_PB.Q_flow = Q_PB;
heat_DS.Q_flow = Q_desal;
heat_PB.T = medium.T;
heat_DS.T = medium.T;
// Initial equations and algorithms
// This model
// class PentakomoPlant.Storage.HeatStorage
initial equation
medium.h = specificEnthalpy_Unique3(
state_i);
m = density_Unique4(
state_i)*V_t;
end HeatStorage;
如果有人能详细说明如何从平面代码中计算出方程式,以帮助我找到丢失的变量,我将不胜感激!
不幸的是,扁平化的代码没有包含所有必要的信息。
不过,这是一个好的开始,包含 27 个方程式:
- 2 个结合方程
- 扩展 Modelica.Media.Interfaces.PartialMedium.BaseProperties_D1 中的 2 个标量方程
- 7个方程在SolarTherm.Media.MoltenSalt.MoltenSalt_base.BaseProperties外基-class
- PentakomoPlant.Storage.HeatStorage 中的 16 个方程式。
但除此之外至少可以有:
- 记录绑定(本例中为none)
- 顶级 public 连接器中的流变量;在这种情况下,我假设它是 2+2+1+1 (fluid_a, fluid_b, heat_PB, heat_DS).
顶层 public 输入 Q_heater 可以用两种方式处理,我记得 Dymola 使用了两种变体:要么它既不对未知数也不对方程式(视为一个已知变量),或者将两者加一。