简体   繁体   English

如何总结提供给 Modelica 中 CombiTimeTable 的输入文件的列

[英]How to sum up a column of an input file given to a CombiTimeTable in Modelica

I have used a .txt file (T_in1) as an input in a 2D-CombiTimeTable in Modelica.我在 Modelica 的 2D-CombiTimeTable 中使用了一个 .txt 文件 (T_in1) 作为输入。 It contains an array with the size of (4,2);它包含一个大小为 (4,2) 的数组; the first column is time and the second one is the time-dependent variable.第一列是时间,第二列是时间相关变量。 I would like to sum or (to get an average of) the second column in every timestep.我想在每个时间步中对第二列求和或(求平均值)。 I would appreciate if there would be any help with this regard.如果在这方面有任何帮助,我将不胜感激。 The code is as follows:代码如下:

model integration
    import Modelica.Fluid.Types;


  Modelica.Blocks.Sources.CombiTimeTable T_in1(
    extrapolation=Modelica.Blocks.Types.Extrapolation.LastTwoPoints,
    fileName="C:/Users/Tin1.txt",
    smoothness=Modelica.Blocks.Types.Smoothness.LinearSegments,
    tableName="tab1",
    tableOnFile=true,
    timeEvents=Modelica.Blocks.Types.TimeEvents.Always,
    timeScale(displayUnit="min") = 60)                                                                                                                                                                                   annotation (
    Placement(visible = true, transformation(origin={-61,32.2828},     extent = {{-6, -6}, {6, 6}}, rotation = 0)));

equation 
 for i in 1:3 loop
  ...
  ...   
 end for;
  annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
        coordinateSystem(preserveAspectRatio=false)),
    experiment(StopTime=240, __Dymola_Algorithm="Dassl"));
end integration;

Thanks to built-in blocks of Modelica, there is no need to use for loop like other environments.由于内置了 Modelica 模块,因此无需像其他环境一样使用 for 循环。 I found combination of two blocks, called sampler (Modelica.Blocks.Discrete.Sampler) and integrator (Modelica.Blocks.Continuous.Integrator) useful as a solution.我发现两个块的组合,称为采样器 (Modelica.Blocks.Discrete.Sampler) 和积分器 (Modelica.Blocks.Continuous.Integrator) 作为解决方案很有用。 The first named bock needs to be connected to the CombiTimeTable and the integrator connected to the sampler.第一个命名的 bock 需要连接到 CombiTimeTable 和连接到采样器的积分器。 In this way, since I am going to use CombiTimeTable applying a linear fit between each point, this solution is to sample each time period, and then to integrate that value.这样,由于我将使用 CombiTimeTable 在每个点之间应用线性拟合,因此该解决方案是对每个时间段进行采样,然后对该值进行积分。 Using integrator solely, would not provide results close to the expected ones due to its configuration and model definition.由于其配置和模型定义,单独使用积分器不会提供接近预期的结果。 The following is the solution to sum up the values:以下是汇总值的解决方案:

model integration
    import Modelica.Fluid.Types;


  Modelica.Blocks.Sources.CombiTimeTable T_in1(
    extrapolation=Modelica.Blocks.Types.Extrapolation.LastTwoPoints,
    fileName="C:/Users/Tin1.txt",
    smoothness=Modelica.Blocks.Types.Smoothness.LinearSegments,
    tableName="tab1",
    tableOnFile=true,
    timeEvents=Modelica.Blocks.Types.TimeEvents.Always,
    timeScale(displayUnit="min") = 60)                                                                                                                                                                                   annotation (
    Placement(visible = true, transformation(origin={-61,32.2828},     extent = {{-6, -6}, {6, 6}}, rotation = 0)));

  Modelica.Blocks.Discrete.Sampler sampler1(samplePeriod(displayUnit="min") = 60)
                                                              annotation(Placement(visible = true, transformation(origin={4,-64},      extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Continuous.Integrator integrator2 annotation(Placement(visible = true, transformation(origin={52,-66},    extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation 
 for i in 1:4 loop

 end for;
  connect(sampler1.y,integrator2. u) annotation(Line(points={{15,-64},{28,-64},{
          28,-66},{40,-66},{40,-66}},                                                                                color = {0, 0, 127}));
  connect(T_in1.y[1], sampler1.u) annotation (Line(points={{-54.4,32.2828},{-54.4,
          -64},{-8,-64}}, color={0,0,127}));
  annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
        coordinateSystem(preserveAspectRatio=false)),
    experiment(StopTime=40500, __Dymola_Algorithm="Dassl"));
end integration;

***However, the question that still remains is that how to make an average of values at each timestep? ***然而,仍然存在的问题是如何在每个时间步取平均值?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM