forked from modelica/ModelicaStandardLibrary
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tables.mo
1368 lines (1331 loc) · 72.4 KB
/
Tables.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
within Modelica.Blocks;
package Tables
"Library of blocks to interpolate in one and two-dimensional tables"
extends Modelica.Icons.Package;
block CombiTable1Ds
"Table look-up in one dimension (matrix/file) with one input and n outputs"
extends Modelica.Blocks.Interfaces.SIMO(final nout=size(columns, 1));
parameter Boolean tableOnFile=false
"= true, if table is defined on file or in function usertab"
annotation (Dialog(group="Table data definition"));
parameter Real table[:, :] = fill(0.0, 0, 2)
"Table matrix (grid = first column; e.g., table=[0, 0; 1, 1; 2, 4])"
annotation (Dialog(group="Table data definition",enable=not tableOnFile));
parameter String tableName="NoName"
"Table name on file or in function usertab (see docu)"
annotation (Dialog(group="Table data definition",enable=tableOnFile));
parameter String fileName="NoName" "File where matrix is stored"
annotation (Dialog(
group="Table data definition",
enable=tableOnFile,
loadSelector(filter="Text files (*.txt);;MATLAB MAT-files (*.mat);;Comma-separated values files (*.csv)",
caption="Open file in which table is present")));
parameter String delimiter="," "Column delimiter character for CSV file"
annotation (Dialog(
group="Table data definition",
enable=tableOnFile and isCsvExt),
choices(choice=" " "Blank", choice="," "Comma", choice="\t" "Horizontal tabulator", choice=";" "Semicolon"));
parameter Integer nHeaderLines=0 "Number of header lines to ignore for CSV file"
annotation (Dialog(group="Table data definition",enable=tableOnFile and isCsvExt));
parameter Boolean verboseRead=true
"= true, if info message that file is loading is to be printed"
annotation (Dialog(group="Table data definition",enable=tableOnFile));
parameter Integer columns[:]=2:size(table, 2)
"Columns of table to be interpolated"
annotation (Dialog(group="Table data interpretation"));
parameter Modelica.Blocks.Types.Smoothness smoothness=Modelica.Blocks.Types.Smoothness.LinearSegments
"Smoothness of table interpolation"
annotation (Dialog(group="Table data interpretation"));
parameter Modelica.Blocks.Types.Extrapolation extrapolation=Modelica.Blocks.Types.Extrapolation.LastTwoPoints
"Extrapolation of data outside the definition range"
annotation (Dialog(group="Table data interpretation"));
parameter Boolean verboseExtrapolation=false
"= true, if warning messages are to be printed if table input is outside the definition range"
annotation (Dialog(group="Table data interpretation", enable=extrapolation == Modelica.Blocks.Types.Extrapolation.LastTwoPoints or extrapolation == Modelica.Blocks.Types.Extrapolation.HoldLastPoint));
final parameter Real u_min=Internal.getTable1DAbscissaUmin(tableID)
"Minimum abscissa value defined in table";
final parameter Real u_max=Internal.getTable1DAbscissaUmax(tableID)
"Maximum abscissa value defined in table";
protected
parameter Modelica.Blocks.Types.ExternalCombiTable1D tableID=
Modelica.Blocks.Types.ExternalCombiTable1D(
if tableOnFile then if isCsvExt then "Values" else tableName else "NoName",
if tableOnFile and fileName <> "NoName" and not Modelica.Utilities.Strings.isEmpty(fileName) then fileName else "NoName",
table,
columns,
smoothness,
extrapolation,
if tableOnFile then verboseRead else false,
delimiter,
nHeaderLines) "External table object";
final parameter Boolean isCsvExt = if tableOnFile then Modelica.Utilities.Strings.findLast(fileName, ".csv", caseSensitive=false) + 3 == Modelica.Utilities.Strings.length(fileName) else false;
equation
if tableOnFile then
assert(tableName <> "NoName" or isCsvExt,
"tableOnFile = true and no table name given");
else
assert(size(table, 1) > 0 and size(table, 2) > 0,
"tableOnFile = false and parameter table is an empty matrix");
end if;
if verboseExtrapolation and (
extrapolation == Modelica.Blocks.Types.Extrapolation.LastTwoPoints or
extrapolation == Modelica.Blocks.Types.Extrapolation.HoldLastPoint) then
assert(noEvent(u >= u_min), "
Extrapolation warning: The value u (=" + String(u) + ") must be greater or equal
than the minimum abscissa value u_min (=" + String(u_min) + ") defined in the table.
", level=AssertionLevel.warning);
assert(noEvent(u <= u_max), "
Extrapolation warning: The value u (=" + String(u) + ") must be less or equal
than the maximum abscissa value u_max (=" + String(u_max) + ") defined in the table.
", level=AssertionLevel.warning);
end if;
if smoothness == Modelica.Blocks.Types.Smoothness.ConstantSegments then
for i in 1:nout loop
y[i] = Internal.getTable1DValueNoDer(tableID, i, u);
end for;
elseif smoothness == Modelica.Blocks.Types.Smoothness.LinearSegments then
for i in 1:nout loop
y[i] = Internal.getTable1DValueNoDer2(tableID, i, u);
end for;
else
for i in 1:nout loop
y[i] = Internal.getTable1DValue(tableID, i, u);
end for;
end if;
annotation (
Documentation(info="<html>
<p>
<strong>Univariate constant</strong>, <strong>linear</strong> or <strong>cubic Hermite
spline interpolation</strong> in <strong>one</strong> dimension of a
<strong>table</strong>.
Via parameter <strong>columns</strong> it can be defined how many columns of the
table are interpolated. If, e.g., columns={2,4}, it is assumed that
2 output signals are present and that the first output interpolates
via column 2 and the second output interpolates via column 4 of the
table matrix.
</p>
<p>
The grid points and function values are stored in a matrix \"table[i,j]\",
where the first column \"table[:,1]\" contains the grid points and the
other columns contain the data to be interpolated. Example:
</p>
<blockquote><pre>
table = [0, 0;
1, 1;
2, 4;
4, 16]
If, e.g., the input u = 1.0, the output y = 1.0,
e.g., the input u = 1.5, the output y = 2.5,
e.g., the input u = 2.0, the output y = 4.0,
e.g., the input u =-1.0, the output y = -1.0 (i.e., extrapolation).
</pre></blockquote>
<ul>
<li>The interpolation interval is found by a binary search where the interval used in the
last call is used as start interval.</li>
<li>Via parameter <strong>smoothness</strong> it is defined how the data is interpolated:
<blockquote><pre>
smoothness = 1: Linear interpolation
= 2: Akima interpolation: Smooth interpolation by cubic Hermite
splines such that der(y) is continuous, also if extrapolated.
= 3: Constant segments
= 4: Fritsch-Butland interpolation: Smooth interpolation by cubic
Hermite splines such that y preserves the monotonicity and
der(y) is continuous, also if extrapolated.
= 5: Steffen interpolation: Smooth interpolation by cubic Hermite
splines such that y preserves the monotonicity and der(y)
is continuous, also if extrapolated.
= 6: Modified Akima interpolation: Smooth interpolation by cubic
Hermite splines such that der(y) is continuous, also if
extrapolated. Additionally, overshoots and edge cases of the
original Akima interpolation method are avoided.
</pre></blockquote></li>
<li>First and second <strong>derivatives</strong> are provided, with exception of the following two smoothness options.
<ol>
<li>No derivatives are provided for interpolation by constant segments.</li>
<li>No second derivative is provided for linear interpolation.</li>
</ol></li>
<li>Values <strong>outside</strong> of the table range, are computed by
extrapolation according to the setting of parameter <strong>extrapolation</strong>:
<blockquote><pre>
extrapolation = 1: Hold the first or last value of the table,
if outside of the table scope.
= 2: Extrapolate by using the derivative at the first/last table
points if outside of the table scope.
(If smoothness is LinearSegments or ConstantSegments
this means to extrapolate linearly through the first/last
two table points.).
= 3: Periodically repeat the table data (periodical function).
= 4: No extrapolation, i.e. extrapolation triggers an error
</pre></blockquote></li>
<li>If the table has only <strong>one row</strong>, the table value is returned,
independent of the value of the input signal.</li>
<li>The grid values (first column) have to be strictly increasing.</li>
</ul>
<p>
The table matrix can be defined in the following ways:
</p>
<ol>
<li>Explicitly supplied as <strong>parameter matrix</strong> \"table\",
and the other parameters have the following values:
<blockquote><pre>
tableName is \"NoName\" or has only blanks,
fileName is \"NoName\" or has only blanks.
</pre></blockquote></li>
<li><strong>Read</strong> from a <strong>file</strong> \"fileName\" where the matrix is stored as
\"tableName\". CSV, text and MATLAB MAT-file format is possible.
(The text format is described below).
The MAT-file format comes in four different versions: v4, v6, v7 and v7.3.
The library supports at least v4, v6 and v7 whereas v7.3 is optional.
It is most convenient to generate the MAT-file from FreeMat or MATLAB®
by command
<blockquote><pre>
save tables.mat tab1 tab2 tab3
</pre></blockquote>
or Scilab by command
<blockquote><pre>
savematfile tables.mat tab1 tab2 tab3
</pre></blockquote>
when the three tables tab1, tab2, tab3 should be used from the model.<br>
Note, a fileName can be defined as URI by using the helper function
<a href=\"modelica://Modelica.Utilities.Files.loadResource\">loadResource</a>.</li>
<li>Statically stored in function \"usertab\" in file \"usertab.c\".
The matrix is identified by \"tableName\". Parameter
fileName = \"NoName\" or has only blanks. Row-wise storage is always to be
preferred as otherwise the table is reallocated and transposed.
See the <a href=\"modelica://Modelica.Blocks.Tables\">Tables</a> package
documentation for more details.</li>
</ol>
<p>
When the constant \"NO_FILE_SYSTEM\" is defined, all file I/O related parts of the
source code are removed by the C-preprocessor, such that no access to files takes place.
</p>
<p>
If tables are read from a text file, the file needs to have the
following structure (\"-----\" is not part of the file content):
</p>
<blockquote><pre>
-----------------------------------------------------
#1
double tab1(5,2) # comment line
0 0
1 1
2 4
3 9
4 16
double tab2(5,2) # another comment line
0 0
2 2
4 8
6 18
8 32
-----------------------------------------------------
</pre></blockquote>
<p>
Note, that the first two characters in the file need to be
\"#1\" (a line comment defining the version number of the file format).
Afterwards, the corresponding matrix has to be declared
with type (= \"double\" or \"float\"), name and actual dimensions.
A valid matrix name (e.g., \"tab1\") must be ASCII encoded and not contain blanks, line breaks, tab (\\t), comma (,) or parentheses.
Finally, in successive rows of the file, the elements of the matrix
have to be given. The elements have to be provided as a sequence of
numbers in row-wise order (therefore a matrix row can span several
lines in the file and need not start at the beginning of a line).
Numbers have to be given according to C syntax (such as 2.3, -2, +2.e4).
Number separators are spaces, tab (\\t), comma (,), or semicolon (;).
Several matrices may be defined one after another. Line comments start
with the hash symbol (#) and can appear everywhere.
Text files should either be ASCII or UTF-8 encoded, where UTF-8 encoded strings are only allowed in line comments and an optional UTF-8 BOM at the start of the text file is ignored.
Other characters, like trailing non comments, are not allowed in the file.
</p>
<p>
MATLAB is a registered trademark of The MathWorks, Inc.
</p>
</html>"),
Icon(
coordinateSystem(preserveAspectRatio=true,
extent={{-100,-100},{100,100}}),
graphics={
Line(points={{-60,40},{-60,-40},{60,-40},{60,40},{30,40},{30,-40},{-30,-40},{-30,40},{-60,40},{-60,20},{60,20},{60,0},{-60,0},{-60,-20},{60,-20},{60,-40},{-60,-40},{-60,40},{60,40},{60,-40}}),
Line(points={{0,40},{0,-40}}),
Rectangle(fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-60,20},{-30,40}}),
Rectangle(fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-60,0},{-30,20}}),
Rectangle(fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-60,-20},{-30,0}}),
Rectangle(fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-60,-40},{-30,-20}}),
Text(extent={{-150,-150},{150,-110}}, textString="tableOnFile=%tableOnFile")}));
end CombiTable1Ds;
block CombiTable1Dv
"Table look-up in one dimension (matrix/file) with n inputs and n outputs"
extends Modelica.Blocks.Interfaces.MIMOs(final n=size(columns, 1));
parameter Boolean tableOnFile=false
"= true, if table is defined on file or in function usertab"
annotation (Dialog(group="Table data definition"));
parameter Real table[:, :] = fill(0.0, 0, 2)
"Table matrix (grid = first column; e.g., table=[0, 0; 1, 1; 2, 4])"
annotation (Dialog(group="Table data definition",enable=not tableOnFile));
parameter String tableName="NoName"
"Table name on file or in function usertab (see docu)"
annotation (Dialog(group="Table data definition",enable=tableOnFile));
parameter String fileName="NoName" "File where matrix is stored"
annotation (Dialog(
group="Table data definition",
enable=tableOnFile,
loadSelector(filter="Text files (*.txt);;MATLAB MAT-files (*.mat);;Comma-separated values files (*.csv)",
caption="Open file in which table is present")));
parameter String delimiter="," "Column delimiter character for CSV file"
annotation (Dialog(
group="Table data definition",
enable=tableOnFile and isCsvExt),
choices(choice=" " "Blank", choice="," "Comma", choice="\t" "Horizontal tabulator", choice=";" "Semicolon"));
parameter Integer nHeaderLines=0 "Number of header lines to ignore for CSV file"
annotation (Dialog(group="Table data definition",enable=tableOnFile and isCsvExt));
parameter Boolean verboseRead=true
"= true, if info message that file is loading is to be printed"
annotation (Dialog(group="Table data definition",enable=tableOnFile));
parameter Integer columns[:]=2:size(table, 2)
"Columns of table to be interpolated"
annotation (Dialog(group="Table data interpretation"));
parameter Modelica.Blocks.Types.Smoothness smoothness=Modelica.Blocks.Types.Smoothness.LinearSegments
"Smoothness of table interpolation"
annotation (Dialog(group="Table data interpretation"));
parameter Modelica.Blocks.Types.Extrapolation extrapolation=Modelica.Blocks.Types.Extrapolation.LastTwoPoints
"Extrapolation of data outside the definition range"
annotation (Dialog(group="Table data interpretation"));
parameter Boolean verboseExtrapolation=false
"= true, if warning messages are to be printed if table input is outside the definition range"
annotation (Dialog(group="Table data interpretation", enable=extrapolation == Modelica.Blocks.Types.Extrapolation.LastTwoPoints or extrapolation == Modelica.Blocks.Types.Extrapolation.HoldLastPoint));
final parameter Real u_min=Internal.getTable1DAbscissaUmin(tableID)
"Minimum abscissa value defined in table";
final parameter Real u_max=Internal.getTable1DAbscissaUmax(tableID)
"Maximum abscissa value defined in table";
protected
parameter Modelica.Blocks.Types.ExternalCombiTable1D tableID=
Modelica.Blocks.Types.ExternalCombiTable1D(
if tableOnFile then if isCsvExt then "Values" else tableName else "NoName",
if tableOnFile and fileName <> "NoName" and not Modelica.Utilities.Strings.isEmpty(fileName) then fileName else "NoName",
table,
columns,
smoothness,
extrapolation,
if tableOnFile then verboseRead else false,
delimiter,
nHeaderLines) "External table object";
final parameter Boolean isCsvExt = if tableOnFile then Modelica.Utilities.Strings.findLast(fileName, ".csv", caseSensitive=false) + 3 == Modelica.Utilities.Strings.length(fileName) else false;
equation
if tableOnFile then
assert(tableName <> "NoName" or isCsvExt,
"tableOnFile = true and no table name given");
else
assert(size(table, 1) > 0 and size(table, 2) > 0,
"tableOnFile = false and parameter table is an empty matrix");
end if;
if verboseExtrapolation and (
extrapolation == Modelica.Blocks.Types.Extrapolation.LastTwoPoints or
extrapolation == Modelica.Blocks.Types.Extrapolation.HoldLastPoint) then
for i in 1:n loop
assert(noEvent(u[i] >= u_min), "
Extrapolation warning: The value u[" + String(i) +"] (=" + String(u[i]) + ") must be greater or equal
than the minimum abscissa value u_min (=" + String(u_min) + ") defined in the table.
", level=AssertionLevel.warning);
assert(noEvent(u[i] <= u_max), "
Extrapolation warning: The value u[" + String(i) +"] (=" + String(u[i]) + ") must be less or equal
than the maximum abscissa value u_max (=" + String(u_max) + ") defined in the table.
", level=AssertionLevel.warning);
end for;
end if;
if smoothness == Modelica.Blocks.Types.Smoothness.ConstantSegments then
for i in 1:n loop
y[i] = Internal.getTable1DValueNoDer(tableID, i, u[i]);
end for;
elseif smoothness == Modelica.Blocks.Types.Smoothness.LinearSegments then
for i in 1:n loop
y[i] = Internal.getTable1DValueNoDer2(tableID, i, u[i]);
end for;
else
for i in 1:n loop
y[i] = Internal.getTable1DValue(tableID, i, u[i]);
end for;
end if;
annotation (
Documentation(info="<html>
<p>
<strong>Univariate constant</strong>, <strong>linear</strong> or <strong>cubic Hermite
spline interpolation</strong> in <strong>one</strong> dimension of a
<strong>table</strong>.
Via parameter <strong>columns</strong> it can be defined how many columns of the
table are interpolated. If, e.g., columns={2,4}, it is assumed that 2 input
and 2 output signals are present and that the first output interpolates
the first input via column 2 and the second output interpolates the
second input via column 4 of the table matrix.
</p>
<p>
The grid points and function values are stored in a matrix \"table[i,j]\",
where the first column \"table[:,1]\" contains the grid points and the
other columns contain the data to be interpolated. Example:
</p>
<blockquote><pre>
table = [0, 0;
1, 1;
2, 4;
4, 16]
If, e.g., the input u = 1.0, the output y = 1.0,
e.g., the input u = 1.5, the output y = 2.5,
e.g., the input u = 2.0, the output y = 4.0,
e.g., the input u =-1.0, the output y = -1.0 (i.e., extrapolation).
</pre></blockquote>
<ul>
<li>The interpolation interval is found by a binary search where the interval used in the
last call is used as start interval.</li>
<li>Via parameter <strong>smoothness</strong> it is defined how the data is interpolated:
<blockquote><pre>
smoothness = 1: Linear interpolation
= 2: Akima interpolation: Smooth interpolation by cubic Hermite
splines such that der(y) is continuous, also if extrapolated.
= 3: Constant segments
= 4: Fritsch-Butland interpolation: Smooth interpolation by cubic
Hermite splines such that y preserves the monotonicity and
der(y) is continuous, also if extrapolated.
= 5: Steffen interpolation: Smooth interpolation by cubic Hermite
splines such that y preserves the monotonicity and der(y)
is continuous, also if extrapolated.
= 6: Modified Akima interpolation: Smooth interpolation by cubic
Hermite splines such that der(y) is continuous, also if
extrapolated. Additionally, overshoots and edge cases of the
original Akima interpolation method are avoided.
</pre></blockquote></li>
<li>First and second <strong>derivatives</strong> are provided, with exception of the following two smoothness options.
<ol>
<li>No derivatives are provided for interpolation by constant segments.</li>
<li>No second derivative is provided for linear interpolation.</li>
</ol></li>
<li>Values <strong>outside</strong> of the table range, are computed by
extrapolation according to the setting of parameter <strong>extrapolation</strong>:
<blockquote><pre>
extrapolation = 1: Hold the first or last value of the table,
if outside of the table scope.
= 2: Extrapolate by using the derivative at the first/last table
points if outside of the table scope.
(If smoothness is LinearSegments or ConstantSegments
this means to extrapolate linearly through the first/last
two table points.).
= 3: Periodically repeat the table data (periodical function).
= 4: No extrapolation, i.e. extrapolation triggers an error
</pre></blockquote></li>
<li>If the table has only <strong>one row</strong>, the table value is returned,
independent of the value of the input signal.</li>
<li>The grid values (first column) have to be strictly increasing.</li>
</ul>
<p>
The table matrix can be defined in the following ways:
</p>
<ol>
<li>Explicitly supplied as <strong>parameter matrix</strong> \"table\",
and the other parameters have the following values:
<blockquote><pre>
tableName is \"NoName\" or has only blanks,
fileName is \"NoName\" or has only blanks.
</pre></blockquote></li>
<li><strong>Read</strong> from a <strong>file</strong> \"fileName\" where the matrix is stored as
\"tableName\". CSV, text and MATLAB MAT-file format is possible.
(The text format is described below).
The MAT-file format comes in four different versions: v4, v6, v7 and v7.3.
The library supports at least v4, v6 and v7 whereas v7.3 is optional.
It is most convenient to generate the MAT-file from FreeMat or MATLAB®
by command
<blockquote><pre>
save tables.mat tab1 tab2 tab3
</pre></blockquote>
or Scilab by command
<blockquote><pre>
savematfile tables.mat tab1 tab2 tab3
</pre></blockquote>
when the three tables tab1, tab2, tab3 should be used from the model.<br>
Note, a fileName can be defined as URI by using the helper function
<a href=\"modelica://Modelica.Utilities.Files.loadResource\">loadResource</a>.</li>
<li>Statically stored in function \"usertab\" in file \"usertab.c\".
The matrix is identified by \"tableName\". Parameter
fileName = \"NoName\" or has only blanks. Row-wise storage is always to be
preferred as otherwise the table is reallocated and transposed.
See the <a href=\"modelica://Modelica.Blocks.Tables\">Tables</a> package
documentation for more details.</li>
</ol>
<p>
When the constant \"NO_FILE_SYSTEM\" is defined, all file I/O related parts of the
source code are removed by the C-preprocessor, such that no access to files takes place.
</p>
<p>
If tables are read from a text file, the file needs to have the
following structure (\"-----\" is not part of the file content):
</p>
<blockquote><pre>
-----------------------------------------------------
#1
double tab1(5,2) # comment line
0 0
1 1
2 4
3 9
4 16
double tab2(5,2) # another comment line
0 0
2 2
4 8
6 18
8 32
-----------------------------------------------------
</pre></blockquote>
<p>
Note, that the first two characters in the file need to be
\"#1\" (a line comment defining the version number of the file format).
Afterwards, the corresponding matrix has to be declared
with type (= \"double\" or \"float\"), name and actual dimensions.
A valid matrix name (e.g., \"tab1\") must be ASCII encoded and not contain blanks, line breaks, tab (\\t), comma (,) or parentheses.
Finally, in successive rows of the file, the elements of the matrix
have to be given. The elements have to be provided as a sequence of
numbers in row-wise order (therefore a matrix row can span several
lines in the file and need not start at the beginning of a line).
Numbers have to be given according to C syntax (such as 2.3, -2, +2.e4).
Number separators are spaces, tab (\\t), comma (,), or semicolon (;).
Several matrices may be defined one after another. Line comments start
with the hash symbol (#) and can appear everywhere.
Text files should either be ASCII or UTF-8 encoded, where UTF-8 encoded strings are only allowed in line comments and an optional UTF-8 BOM at the start of the text file is ignored.
Other characters, like trailing non comments, are not allowed in the file.
</p>
<p>
MATLAB is a registered trademark of The MathWorks, Inc.
</p>
</html>"),
Icon(
coordinateSystem(preserveAspectRatio=true,
extent={{-100,-100},{100,100}}),
graphics={
Line(points={{-60,40},{-60,-40},{60,-40},{60,40},{30,40},{30,-40},{-30,-40},{-30,40},{-60,40},{-60,20},{60,20},{60,0},{-60,0},{-60,-20},{60,-20},{60,-40},{-60,-40},{-60,40},{60,40},{60,-40}}),
Line(points={{0,40},{0,-40}}),
Rectangle(fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-60,20},{-30,40}}),
Rectangle(fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-60,0},{-30,20}}),
Rectangle(fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-60,-20},{-30,0}}),
Rectangle(fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-60,-40},{-30,-20}}),
Text(extent={{-150,-150},{150,-110}}, textString="tableOnFile=%tableOnFile")}));
end CombiTable1Dv;
block CombiTable2Ds "Table look-up in two dimensions (matrix/file)"
extends Modelica.Blocks.Interfaces.SI2SO;
extends Internal.CombiTable2DBase;
equation
if verboseExtrapolation and (
extrapolation == Modelica.Blocks.Types.Extrapolation.LastTwoPoints or
extrapolation == Modelica.Blocks.Types.Extrapolation.HoldLastPoint) then
assert(noEvent(u1 >= u_min[1]), "
Extrapolation warning: The value u1 (=" + String(u1) + ") must be greater or equal
than the minimum abscissa value u_min[1] (=" + String(u_min[1]) + ") defined in the table.
", level=AssertionLevel.warning);
assert(noEvent(u1 <= u_max[1]), "
Extrapolation warning: The value u1 (=" + String(u1) + ") must be less or equal
than the maximum abscissa value u_max[1] (=" + String(u_max[1]) + ") defined in the table.
", level=AssertionLevel.warning);
assert(noEvent(u2 >= u_min[2]), "
Extrapolation warning: The value u2 (=" + String(u2) + ") must be greater or equal
than the minimum abscissa value u_min[2] (=" + String(u_min[2]) + ") defined in the table.
", level=AssertionLevel.warning);
assert(noEvent(u2 <= u_max[2]), "
Extrapolation warning: The value u2 (=" + String(u2) + ") must be less or equal
than the maximum abscissa value u_max[2] (=" + String(u_max[2]) + ") defined in the table.
", level=AssertionLevel.warning);
end if;
if smoothness == Modelica.Blocks.Types.Smoothness.ConstantSegments then
y = Internal.getTable2DValueNoDer(tableID, u1, u2);
elseif smoothness == Modelica.Blocks.Types.Smoothness.LinearSegments then
y = Internal.getTable2DValueNoDer2(tableID, u1, u2);
else
y = Internal.getTable2DValue(tableID, u1, u2);
end if;
annotation (
Documentation(info="<html>
<p>
<strong>Bivariate constant</strong>, <strong>bilinear</strong> or <strong>bivariate
Akima interpolation</strong> of a <strong>two-dimensional table</strong>.
The grid points and function values are stored in a matrix \"table[i,j]\",
where:
</p>
<ul>
<li>the first column \"table[2:,1]\" contains the u1 grid points,</li>
<li>the first row \"table[1,2:]\" contains the u2 grid points,</li>
<li>the other rows and columns contain the data to be interpolated.</li>
</ul>
<p>
Example:
</p>
<blockquote><pre>
| | | |
| 1.0 | 2.0 | 3.0 | // u2
----*-------*-------*-------*
1.0 | 1.0 | 3.0 | 5.0 |
----*-------*-------*-------*
2.0 | 2.0 | 4.0 | 6.0 |
----*-------*-------*-------*
// u1
is defined as
table = [0.0, 1.0, 2.0, 3.0;
1.0, 1.0, 3.0, 5.0;
2.0, 2.0, 4.0, 6.0]
If, e.g., the input u1 is 1.0, input u2 is 1.0 and smoothness is LinearSegments, the output y is 1.0,
e.g., the input u1 is 2.0, input u2 is 1.5 and smoothness is LinearSegments, the output y is 3.0.
</pre></blockquote>
<ul>
<li>The interpolation interval is found by a binary search where the interval used in the
last call is used as start interval.</li>
<li>Via parameter <strong>smoothness</strong> it is defined how the data is interpolated:
<blockquote><pre>
smoothness = 1: Bilinear interpolation
= 2: Bivariate Akima interpolation: Smooth interpolation by bicubic Hermite
splines such that der(y) is continuous, also if extrapolated.
= 3: Constant segments
= 4: Fritsch-Butland interpolation: Not supported
= 5: Steffen interpolation: Not supported
= 6: Modified Akima interpolation: Not supported
</pre></blockquote></li>
<li>First and second <strong>derivatives</strong> are provided, with exception of the following two smoothness options.
<ol>
<li>No derivatives are provided for interpolation by constant segments.</li>
<li>No second derivative is provided for linear interpolation.</li>
</ol></li>
<li>Values <strong>outside</strong> of the table range, are computed by
extrapolation according to the setting of parameter <strong>extrapolation</strong>:
<blockquote><pre>
extrapolation = 1: Hold the first or last values of the table,
if outside of the table scope.
= 2: Extrapolate by using the derivative at the first/last table
points if outside of the table scope.
(If smoothness is LinearSegments or ConstantSegments
this means to extrapolate linearly through the first/last
two table points.).
= 3: Periodically repeat the table data (periodical function).
= 4: No extrapolation, i.e. extrapolation triggers an error
</pre></blockquote></li>
<li>If the table has only <strong>one element</strong>, the table value is returned,
independent of the value of the input signal.</li>
<li>The grid values (first column and first row) have to be strictly
increasing.</li>
</ul>
<p>
The table matrix can be defined in the following ways:
</p>
<ol>
<li>Explicitly supplied as <strong>parameter matrix</strong> \"table\",
and the other parameters have the following values:
<blockquote><pre>
tableName is \"NoName\" or has only blanks,
fileName is \"NoName\" or has only blanks.
</pre></blockquote></li>
<li><strong>Read</strong> from a <strong>file</strong> \"fileName\" where the matrix is stored as
\"tableName\". CSV, text and MATLAB MAT-file format is possible.
(The text format is described below).
The MAT-file format comes in four different versions: v4, v6, v7 and v7.3.
The library supports at least v4, v6 and v7 whereas v7.3 is optional.
It is most convenient to generate the MAT-file from FreeMat or MATLAB®
by command
<blockquote><pre>
save tables.mat tab1 tab2 tab3
</pre></blockquote>
or Scilab by command
<blockquote><pre>
savematfile tables.mat tab1 tab2 tab3
</pre></blockquote>
when the three tables tab1, tab2, tab3 should be used from the model.<br>
Note, a fileName can be defined as URI by using the helper function
<a href=\"modelica://Modelica.Utilities.Files.loadResource\">loadResource</a>.</li>
<li>Statically stored in function \"usertab\" in file \"usertab.c\".
The matrix is identified by \"tableName\". Parameter
fileName = \"NoName\" or has only blanks. Row-wise storage is always to be
preferred as otherwise the table is reallocated and transposed.
See the <a href=\"modelica://Modelica.Blocks.Tables\">Tables</a> package
documentation for more details.</li>
</ol>
<p>
When the constant \"NO_FILE_SYSTEM\" is defined, all file I/O related parts of the
source code are removed by the C-preprocessor, such that no access to files takes place.
</p>
<p>
If tables are read from a text file, the file needs to have the
following structure (\"-----\" is not part of the file content):
</p>
<blockquote><pre>
-----------------------------------------------------
#1
double table2D_1(3,4) # comment line
0.0 1.0 2.0 3.0 # u[2] grid points
1.0 1.0 3.0 5.0
2.0 2.0 4.0 6.0
double table2D_2(4,4) # comment line
0.0 1.0 2.0 3.0 # u[2] grid points
1.0 1.0 3.0 5.0
2.0 2.0 4.0 6.0
3.0 3.0 5.0 7.0
-----------------------------------------------------
</pre></blockquote>
<p>
Note, that the first two characters in the file need to be
\"#1\" (a line comment defining the version number of the file format).
Afterwards, the corresponding matrix has to be declared
with type (= \"double\" or \"float\"), name and actual dimensions.
A valid matrix name (e.g., \"tab1\") must be ASCII encoded and not contain blanks, line breaks, tab (\\t), comma (,) or parentheses.
Finally, in successive rows of the file, the elements of the matrix
have to be given. The elements have to be provided as a sequence of
numbers in row-wise order (therefore a matrix row can span several
lines in the file and need not start at the beginning of a line).
Numbers have to be given according to C syntax (such as 2.3, -2, +2.e4).
Number separators are spaces, tab (\\t), comma (,), or semicolon (;).
Several matrices may be defined one after another. Line comments start
with the hash symbol (#) and can appear everywhere.
Text files should either be ASCII or UTF-8 encoded, where UTF-8 encoded strings are only allowed in line comments and an optional UTF-8 BOM at the start of the text file is ignored.
Other characters, like trailing non comments, are not allowed in the file.
The matrix elements are interpreted in exactly the same way
as if the matrix is given as a parameter. For example, the first
column \"table2D_1[2:,1]\" contains the u[1] grid points,
and the first row \"table2D_1[1,2:]\" contains the u[2] grid points.
</p>
<p>
MATLAB is a registered trademark of The MathWorks, Inc.
</p>
</html>"));
end CombiTable2Ds;
block CombiTable2Dv "Table look-up in two dimensions (matrix/file) with vector inputs and vector output of size n"
extends Modelica.Blocks.Interfaces.MI2MO;
extends Internal.CombiTable2DBase;
equation
if verboseExtrapolation and (
extrapolation == Modelica.Blocks.Types.Extrapolation.LastTwoPoints or
extrapolation == Modelica.Blocks.Types.Extrapolation.HoldLastPoint) then
for j in 1:n loop
assert(noEvent(u1[j] >= u_min[1]), "
Extrapolation warning: The value u1[" + String(j) + "] (=" + String(u1[j]) + ") must be greater or equal
than the minimum abscissa value u_min[1] (=" + String(u_min[1]) + ") defined in the table.
", level=AssertionLevel.warning);
assert(noEvent(u1[j] <= u_max[1]), "
Extrapolation warning: The value u1[" + String(j) + "] (=" + String(u1[j]) + ") must be less or equal
than the maximum abscissa value u_max[1] (=" + String(u_max[1]) + ") defined in the table.
", level=AssertionLevel.warning);
assert(noEvent(u2[j] >= u_min[2]), "
Extrapolation warning: The value u2[" + String(j) + "] (=" + String(u2[j]) + ") must be greater or equal
than the minimum abscissa value u_min[2] (=" + String(u_min[2]) + ") defined in the table.
", level=AssertionLevel.warning);
assert(noEvent(u2[j] <= u_max[2]), "
Extrapolation warning: The value u2[" + String(j) + "] (=" + String(u2[j]) + ") must be less or equal
than the maximum abscissa value u_max[2] (=" + String(u_max[2]) + ") defined in the table.
", level=AssertionLevel.warning);
end for;
end if;
if smoothness == Modelica.Blocks.Types.Smoothness.ConstantSegments then
for j in 1:n loop
y[j] = Modelica.Blocks.Tables.Internal.getTable2DValueNoDer(tableID, u1[j], u2[j]);
end for;
elseif smoothness == Modelica.Blocks.Types.Smoothness.LinearSegments then
for j in 1:n loop
y[j] = Modelica.Blocks.Tables.Internal.getTable2DValueNoDer2(tableID, u1[j], u2[j]);
end for;
else
for j in 1:n loop
y[j] = Modelica.Blocks.Tables.Internal.getTable2DValue(tableID, u1[j], u2[j]);
end for;
end if;
annotation(Documentation(info="<html>
<p>
<strong>Bivariate constant</strong>, <strong>bilinear</strong> or <strong>bivariate
Akima interpolation</strong> of a <strong>two-dimensional table</strong>.
The grid points and function values are stored in a matrix \"table[i,j]\",
where:
</p>
<ul>
<li>the first column \"table[2:,1]\" contains the u1 grid points,</li>
<li>the first row \"table[1,2:]\" contains the u2 grid points,</li>
<li>the other rows and columns contain the data to be interpolated.</li>
</ul>
<p>
Example:
</p>
<blockquote><pre>
| | | |
| 1.0 | 2.0 | 3.0 | // u2
----*-------*-------*-------*
1.0 | 1.0 | 3.0 | 5.0 |
----*-------*-------*-------*
2.0 | 2.0 | 4.0 | 6.0 |
----*-------*-------*-------*
// u1
is defined as
table = [0.0, 1.0, 2.0, 3.0;
1.0, 1.0, 3.0, 5.0;
2.0, 2.0, 4.0, 6.0]
If, e.g., the input u1 is {1.0}, input u2 is {1.0} and smoothness is LinearSegments, the output y is {1.0},
e.g., the input u1 is {2.0}, input u2 is {1.5} and smoothness is LinearSegments, the output y is {3.0}.
</pre></blockquote>
<ul>
<li>The interpolation interval is found by a binary search where the interval used in the
last call is used as start interval.</li>
<li>Via parameter <strong>smoothness</strong> it is defined how the data is interpolated:
<blockquote><pre>
smoothness = 1: Bilinear interpolation
= 2: Bivariate Akima interpolation: Smooth interpolation by bicubic Hermite
splines such that der(y) is continuous, also if extrapolated.
= 3: Constant segments
= 4: Fritsch-Butland interpolation: Not supported
= 5: Steffen interpolation: Not supported
= 6: Modified Akima interpolation: Not supported
</pre></blockquote></li>
<li>First and second <strong>derivatives</strong> are provided, with exception of the following two smoothness options.
<ol>
<li>No derivatives are provided for interpolation by constant segments.</li>
<li>No second derivative is provided for linear interpolation.</li>
</ol></li>
<li>Values <strong>outside</strong> of the table range, are computed by
extrapolation according to the setting of parameter <strong>extrapolation</strong>:
<blockquote><pre>
extrapolation = 1: Hold the first or last values of the table,
if outside of the table scope.
= 2: Extrapolate by using the derivative at the first/last table
points if outside of the table scope.
(If smoothness is LinearSegments or ConstantSegments
this means to extrapolate linearly through the first/last
two table points.).
= 3: Periodically repeat the table data (periodical function).
= 4: No extrapolation, i.e. extrapolation triggers an error
</pre></blockquote></li>
<li>If the table has only <strong>one element</strong>, the table value is returned,
independent of the value of the input signal.</li>
<li>The grid values (first column and first row) have to be strictly
increasing.</li>
</ul>
<p>
The table matrix can be defined in the following ways:
</p>
<ol>
<li>Explicitly supplied as <strong>parameter matrix</strong> \"table\",
and the other parameters have the following values:
<blockquote><pre>
tableName is \"NoName\" or has only blanks,
fileName is \"NoName\" or has only blanks.
</pre></blockquote></li>
<li><strong>Read</strong> from a <strong>file</strong> \"fileName\" where the matrix is stored as
\"tableName\". CSV, text and MATLAB MAT-file format is possible.
(The text format is described below).
The MAT-file format comes in four different versions: v4, v6, v7 and v7.3.
The library supports at least v4, v6 and v7 whereas v7.3 is optional.
It is most convenient to generate the MAT-file from FreeMat or MATLAB®
by command
<blockquote><pre>
save tables.mat tab1 tab2 tab3
</pre></blockquote>
or Scilab by command
<blockquote><pre>
savematfile tables.mat tab1 tab2 tab3
</pre></blockquote>
when the three tables tab1, tab2, tab3 should be used from the model.<br>
Note, a fileName can be defined as URI by using the helper function
<a href=\"modelica://Modelica.Utilities.Files.loadResource\">loadResource</a>.</li>
<li>Statically stored in function \"usertab\" in file \"usertab.c\".
The matrix is identified by \"tableName\". Parameter
fileName = \"NoName\" or has only blanks. Row-wise storage is always to be
preferred as otherwise the table is reallocated and transposed.
See the <a href=\"modelica://Modelica.Blocks.Tables\">Tables</a> package
documentation for more details.</li>
</ol>
<p>
When the constant \"NO_FILE_SYSTEM\" is defined, all file I/O related parts of the
source code are removed by the C-preprocessor, such that no access to files takes place.
</p>
<p>
If tables are read from a text file, the file needs to have the
following structure (\"-----\" is not part of the file content):
</p>
<blockquote><pre>
-----------------------------------------------------
#1
double table2D_1(3,4) # comment line
0.0 1.0 2.0 3.0 # u[2] grid points
1.0 1.0 3.0 5.0
2.0 2.0 4.0 6.0
double table2D_2(4,4) # comment line
0.0 1.0 2.0 3.0 # u[2] grid points
1.0 1.0 3.0 5.0
2.0 2.0 4.0 6.0
3.0 3.0 5.0 7.0
-----------------------------------------------------
</pre></blockquote>
<p>
Note, that the first two characters in the file need to be
\"#1\" (a line comment defining the version number of the file format).
Afterwards, the corresponding matrix has to be declared
with type (= \"double\" or \"float\"), name and actual dimensions.
A valid matrix name (e.g., \"tab1\") must be ASCII encoded and not contain blanks, line breaks, tab (\\t), comma (,) or parentheses.
Finally, in successive rows of the file, the elements of the matrix
have to be given. The elements have to be provided as a sequence of
numbers in row-wise order (therefore a matrix row can span several
lines in the file and need not start at the beginning of a line).
Numbers have to be given according to C syntax (such as 2.3, -2, +2.e4).
Number separators are spaces, tab (\\t), comma (,), or semicolon (;).
Several matrices may be defined one after another. Line comments start
with the hash symbol (#) and can appear everywhere.
Text files should either be ASCII or UTF-8 encoded, where UTF-8 encoded strings are only allowed in line comments and an optional UTF-8 BOM at the start of the text file is ignored.
Other characters, like trailing non comments, are not allowed in the file.
The matrix elements are interpreted in exactly the same way
as if the matrix is given as a parameter. For example, the first
column \"table2D_1[2:,1]\" contains the u[1] grid points,
and the first row \"table2D_1[1,2:]\" contains the u[2] grid points.
</p>
<p>
MATLAB is a registered trademark of The MathWorks, Inc.
</p>
</html>"));
end CombiTable2Dv;
package Internal "Internal external object definitions for table functions that should not be directly utilized by the user"
extends Modelica.Icons.InternalPackage;
partial block CombiTable2DBase "Base class for variants of table look-up in two dimensions"
parameter Boolean tableOnFile=false
"= true, if table is defined on file or in function usertab"
annotation (Dialog(group="Table data definition"));
parameter Real table[:, :] = fill(0.0, 0, 2)
"Table matrix (grid u1 = first column, grid u2 = first row; e.g., table=[0, 0; 0, 1])"
annotation (Dialog(group="Table data definition",enable=not tableOnFile));
parameter String tableName="NoName"
"Table name on file or in function usertab (see docu)"
annotation (Dialog(group="Table data definition",enable=tableOnFile));
parameter String fileName="NoName" "File where matrix is stored"
annotation (Dialog(
group="Table data definition",
enable=tableOnFile,
loadSelector(filter="Text files (*.txt);;MATLAB MAT-files (*.mat);;Comma-separated values files (*.csv)",
caption="Open file in which table is present")));
parameter String delimiter="," "Column delimiter character for CSV file"
annotation (Dialog(
group="Table data definition",
enable=tableOnFile and isCsvExt),
choices(choice=" " "Blank", choice="," "Comma", choice="\t" "Horizontal tabulator", choice=";" "Semicolon"));
parameter Integer nHeaderLines=0 "Number of header lines to ignore for CSV file"
annotation (Dialog(group="Table data definition",enable=tableOnFile and isCsvExt));
parameter Boolean verboseRead=true
"= true, if info message that file is loading is to be printed"
annotation (Dialog(group="Table data definition",enable=tableOnFile));
parameter Modelica.Blocks.Types.Smoothness smoothness=Modelica.Blocks.Types.Smoothness.LinearSegments
"Smoothness of table interpolation"
annotation (Dialog(group="Table data interpretation"));
parameter Modelica.Blocks.Types.Extrapolation extrapolation=Modelica.Blocks.Types.Extrapolation.LastTwoPoints
"Extrapolation of data outside the definition range"
annotation (Dialog(group="Table data interpretation"));
parameter Boolean verboseExtrapolation=false
"= true, if warning messages are to be printed if table input is outside the definition range"
annotation (Dialog(group="Table data interpretation", enable=extrapolation == Modelica.Blocks.Types.Extrapolation.LastTwoPoints or extrapolation == Modelica.Blocks.Types.Extrapolation.HoldLastPoint));
final parameter Real u_min[2]=getTable2DAbscissaUmin(tableID)
"Minimum abscissa value defined in table";
final parameter Real u_max[2]=getTable2DAbscissaUmax(tableID)
"Maximum abscissa value defined in table";
protected
parameter Modelica.Blocks.Types.ExternalCombiTable2D tableID=
Modelica.Blocks.Types.ExternalCombiTable2D(
if tableOnFile then if isCsvExt then "Values" else tableName else "NoName",
if tableOnFile and fileName <> "NoName" and not Modelica.Utilities.Strings.isEmpty(fileName) then fileName else "NoName",
table,
smoothness,
extrapolation,
if tableOnFile then verboseRead else false,
delimiter,
nHeaderLines) "External table object";
final parameter Boolean isCsvExt = if tableOnFile then Modelica.Utilities.Strings.findLast(fileName, ".csv", caseSensitive=false) + 3 == Modelica.Utilities.Strings.length(fileName) else false;
equation
if tableOnFile then
assert(tableName <> "NoName" or isCsvExt,
"tableOnFile = true and no table name given");
else
assert(size(table, 1) > 0 and size(table, 2) > 0,
"tableOnFile = false and parameter table is an empty matrix");
end if;
annotation(Icon(
coordinateSystem(preserveAspectRatio=true,
extent={{-100,-100},{100,100}}),
graphics={
Line(points={{-60,40},{-60,-40},{60,-40},{60,40},{30,40},{30,-40},{-30,-40},{-30,40},{-60,40},{-60,20},{60,20},{60,0},{-60,0},{-60,-20},{60,-20},{60,-40},{-60,-40},{-60,40},{60,40},{60,-40}}),
Line(points={{0,40},{0,-40}}),
Line(points={{-60,40},{-30,20}}),
Line(points={{-30,40},{-60,20}}),
Rectangle(origin={2.3077,0},
fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-62.3077,0},{-32.3077,20}}),
Rectangle(origin={2.3077,0},
fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-62.3077,-20},{-32.3077,0}}),
Rectangle(origin={2.3077,0},
fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-62.3077,-40},{-32.3077,-20}}),
Rectangle(fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-30,20},{0,40}}),
Rectangle(fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{0,20},{30,40}}),
Rectangle(origin={-2.3077,0},
fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{32.3077,20},{62.3077,40}}),
Text(extent={{-150,-150},{150,-110}}, textString="tableOnFile=%tableOnFile")}));
end CombiTable2DBase;
pure function getTimeTableValue