我在 Modelica 语言的使用方面处于绝对的初学者水平。我正在尝试制作一个查找表,并希望在值之间进行线性插值。所以,我有温度和压力的数据,可以给我提供焓。在下表中,第一列是温度数据,第一行是压力数据,对于这些网格点,其余的是焓,这是我想要的输出。
我试图在这样的查找表上找到一个例子,但没能找到。我将感谢您的帮助。
model CalculateEnthalpy1
type Pressure =Real (unit="Pa");
type Temperature =Real (unit="K");
type Enthalpy =Real (unit= "J/kg");
Modelica.Blocks.Tables.CombiTable2Ds combiTable2Ds(
tableOnFile=true,
fileName="C:/Users/shyousa/Downloads/TPH.mat",
smoothness=Modelica.Blocks.Types.Smoothness.LinearSegments)
annotation (Placement(transformation(extent={{-52,22},{-32,42}})));
annotation (uses(Modelica(version="4.0.0")));
parameter Temperature T= 297; // input value for temperature
parameter Pressure P= 152500; // input value for pressure
Enthalpy h; // output value of enthalpy for the above mentioned inputs
equation
h = smoothness(table, T, P);
annotation (uses(Modelica(version="4.0.0")));
end CalculateEnthalpy1;
例如,对于 P= 490000 和 T= 344 ,焓= 494629.5
如果输入在表中但不完全在这个范围内,则应该进行插值,而不允许外推。
因此,您发布的代码需要考虑以下几点:
Modelica.Units.SI
中找到合适的。下面您将了解如何导入和使用它们。NoExtrapolation
。如果需要外推,这将中止模拟。您可以例如更改为 HoldLastPoint
以在定义的表之外启用模拟(具有相关风险)。Constant
块)和相应的连接(如下面代码中的输入(P、T)所示)来连接它们,或者设置一个方程(如为输出(h)所做的那样)。model CalculateEnthalpy
import Modelica.Units.SI;
// Parameters
parameter SI.Temperature T= 297; // input value for temperature
parameter SI.Pressure P= 152500; // input value for pressure
// Variables
SI.Enthalpy h; // output value of enthalpy for the above mentioned inputs
// Components
Modelica.Blocks.Sources.Constant temperature(k=T) annotation (Placement(transformation(extent={{-60,20},{-40,40}})));
Modelica.Blocks.Sources.Constant pressure(k=P) annotation (Placement(transformation(extent={{-60,-40},{-40,-20}})));
Modelica.Blocks.Tables.CombiTable2Ds combiTable2Ds(
tableOnFile=false,
table=[0,40000,152500,265000,377500,490000; 250,423315.2,419889.7,416118.2,165969.3,165995.8; 273.5,441261.1,438806.4,436236.1,433533.6,430676.7; 297,459931.2,458052.7,456121.8,454134.3,452084.8; 320.5,479386.9,477888.3,476356.9,474806.3,473219.7; 344,499557,498424.7,497176.4,495911.5,494629.5],
smoothness=Modelica.Blocks.Types.Smoothness.LinearSegments,
extrapolation=Modelica.Blocks.Types.Extrapolation.NoExtrapolation)
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
equation
h = combiTable2Ds.y;
connect(temperature.y, combiTable2Ds.u1) annotation (Line(points={{-39,30},{-20,30},{-20,6},{-12,6}}, color={0,0,127}));
connect(pressure.y, combiTable2Ds.u2) annotation (Line(points={{-39,-30},{-20,-30},{-20,-6},{-12,-6}}, color={0,0,127}));
annotation(uses(Modelica(version="4.0.0")));
end CalculateEnthalpy;