I have used a .txt file (T_in1) as an input in a 2D-CombiTimeTable in Modelica. It contains an array with the size of (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. I found combination of two blocks, called sampler (Modelica.Blocks.Discrete.Sampler) and integrator (Modelica.Blocks.Continuous.Integrator) useful as a solution. The first named bock needs to be connected to the CombiTimeTable and the integrator connected to the sampler. 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. 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:
***However, the question that still remains is that how to make an average of values at each timestep?