-
Notifications
You must be signed in to change notification settings - Fork 299
/
ModelicaBuiltin.mo
5321 lines (4736 loc) · 180 KB
/
ModelicaBuiltin.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
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
type StateSelect = enumeration(
never "Do not use as state at all.",
avoid "Use as state, if it cannot be avoided (but only if variable appears differentiated and no other potential state with attribute default, prefer, or always can be selected).",
default "Use as state if appropriate, but only if variable appears differentiated.",
prefer "Prefer it as state over those having the default value (also variables can be selected, which do not appear differentiated).",
always "Do use it as a state."
);
function der "Derivative of the input expression"
input Real x(unit="'p");
output Real dx(unit="'p/s");
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'der()'\">der()</a>
</html>"));
end der;
impure function initial "True if in initialization phase"
output Boolean isInitial;
external "builtin";
annotation(__OpenModelica_Impure=true, Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'initial()'\">initial()</a>
</html>"));
end initial;
impure function terminal "True after successful analysis"
output Boolean isTerminal;
external "builtin";
annotation(__OpenModelica_Impure=true, Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'terminal()'\">terminal()</a>
</html>"));
end terminal;
type AssertionLevel = enumeration(warning, error) annotation(__OpenModelica_builtin=true,
Documentation(info="<html>Used by <a href=\"modelica://assert\">assert()</a></html>"));
function assert "Check an assertion condition"
input Boolean condition;
input String message;
input AssertionLevel level = AssertionLevel.error;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'assert()'\">assert()</a>
</html>"));
end assert;
function ceil "Round a real number towards plus infinity"
input Real x;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'ceil()'\">ceil()</a>
</html>"));
end ceil;
function floor "Round a real number towards minus infinity"
input Real x;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'floor()'\">floor()</a>
</html>"));
end floor;
function integer "Returns the largest integer not greater than x. The argument shall have type Real. The result has type Integer. [Note, outside of a when-clause state events are triggered when the return value changes discontinuously.]."
input Real x;
output Integer y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'integer()'\">integer()</a>
</html>"));
end integer;
function sqrt "Square root"
input Real x(unit="'p");
output Real y(unit="'p(1/2)");
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'sqrt()'\">sqrt()</a>
</html>"));
end sqrt;
function sign "Sign of real or integer number"
input Real v;
output Integer _sign;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'sign()'\">sign()</a>
</html>"));
/* We do this with external "builtin" for now. But maybe we should inline it instead...
annotation(__OpenModelica_EarlyInline = true);
algorithm
_sign := noEvent(if v > 0 then 1 else if v < 0 then -1 else 0);
*/
end sign;
function identity "Identity matrix of given size"
input Integer arraySize;
output Integer[arraySize,arraySize] outArray;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'identity()'\">identity()</a>
</html>"));
end identity;
function semiLinear
input Real x;
input Real positiveSlope;
input Real negativeSlope;
output Real result;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'semiLinear()'\">semiLinear()</a>
</html>"));
end semiLinear;
function edge "Indicate rising edge"
input Boolean b;
output Boolean edgeEvent;
// TODO: Ceval parameters? Needed to remove the builtin handler
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'edge()'\">edge()</a>
</html>"));
end edge;
function sin "Sine"
input Real x;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'sin()'\">sin()</a>
</html>"));
end sin;
function cos "Cosine"
input Real x;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'cos()'\">cos()</a>
</html>"));
end cos;
function tan "Tangent (u shall not be -pi/2, pi/2, 3*pi/2, ...)"
input Real u;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'tan()'\">tan()</a>
</html>"));
end tan;
function sinh "Hyperbolic sine"
input Real x;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'sinh()'\">sinh()</a>
</html>"));
end sinh;
function cosh "Hyperbolic cosine"
input Real x;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'cosh()'\">cosh()</a>
</html>"));
end cosh;
function tanh "Hyperbolic tangent"
input Real x;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'tanh()'\">tanh()</a>
</html>"));
end tanh;
function asin "Inverse sine (-1 <= u <= 1)"
input Real u;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'asin()'\">asin()</a>
</html>"));
end asin;
function acos "Inverse cosine (-1 <= u <= 1)"
input Real u;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'acos()'\">acos()</a>
</html>"));
end acos;
function atan "Inverse tangent"
input Real x;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'atan()'\">atan()</a>
</html>"));
end atan;
function atan2 "Four quadrant inverse tangent"
input Real y;
input Real x;
output Real z;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'atan2()'\">atan2()</a>
</html>"));
end atan2;
function exp "Exponential, base e"
input Real x(unit="1");
output Real y(unit="1");
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'exp()'\">exp()</a>
</html>"));
end exp;
function log "Natural (base e) logarithm (u shall be > 0)"
input Real u(unit="1");
output Real y(unit="1");
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'log()'\">log()</a>
</html>"));
end log;
function log10 "Base 10 logarithm (u shall be > 0)"
input Real u(unit="1");
output Real y(unit="1");
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'log10()'\">log10()</a>
</html>"));
end log10;
function homotopy
input Real actual;
input Real simplified;
output Real outValue;
external "builtin";
annotation(version="Modelica 3.2",Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'homotopy()'\">homotopy()</a> (experimental implementation)
</html>"));
end homotopy;
function linspace "Real vector with equally spaced elements"
input Real x1 "start";
input Real x2 "end";
input Integer n "number";
output Real v[n];
algorithm
// assert(n >= 2, "linspace requires n>=2 but got " + String(n));
v := {x1 + (x2-x1)*(i-1)/(n-1) for i in 1:n};
annotation(__OpenModelica_builtin=true,__OpenModelica_EarlyInline=true,Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'linspace()'\">linspace()</a>
</html>"));
end linspace;
function div = $overload(OpenModelica.Internal.intDiv,OpenModelica.Internal.realDiv)
"Integer part of a division of two Real numbers"
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'div()'\">div()</a>
</html>"));
function mod = $overload(OpenModelica.Internal.intMod,OpenModelica.Internal.realMod)
"Integer modulus of a division of two Real numbers"
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'mod()'\">mod()</a>
</html>"));
function rem = $overload(OpenModelica.Internal.intRem,OpenModelica.Internal.realRem)
"Integer remainder of the division of two Real numbers"
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'rem()'\">rem()</a>
</html>"));
function abs = $overload(OpenModelica.Internal.intAbs,OpenModelica.Internal.realAbs)
"Absolute value"
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'abs()'\">abs()</a>
</html>"));
function outerProduct "Outer product of two vectors"
input Real[:] v1;
input Real[:] v2;
output Real[size(v1,1),size(v2,1)] o;
algorithm
o := matrix(v1) * transpose(matrix(v2));
annotation(__OpenModelica_builtin=true,__OpenModelica_EarlyInline=true,preferredView="text",Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'outerProduct()'\">outerProduct()</a>
</html>"));
end outerProduct;
function cross "Cross product of two 3-vectors"
input Real[3] x;
input Real[3] y;
output Real[3] z;
/* Not working due to problems with non-builtin overloaded functions? Maybe it works now. Maybe it's bad to inline due to evaluating the same element many times?
algorithm
z := { x[2]*y[3]-x[3]*y[2] , x[3]*y[1]-x[1]*y[3] , x[1]*y[2]-x[2]*y[1] };
*/
external "builtin" cross(x,y,z);
annotation(__OpenModelica_EarlyInline = true, preferredView="text",Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'cross()'\">cross()</a>
</html>"));
end cross;
function skew "The skew matrix associated with the vector"
input Real[3] x;
output Real[3,3] y;
external "builtin" skew(x,y);
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'skew()'\">skew()</a>
</html>"));
end skew;
// Dummy functions that can't be properly defined in Modelica, but used by
// SCodeFlatten to define which builtin functions exist (SCodeFlatten doesn't
// care how the functions are defined, only if they exist or not).
function delay = $overload(OpenModelica.Internal.delay2,OpenModelica.Internal.delay3) "Delay expression"
annotation(__OpenModelica_Impure=true, Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'delay()'\">delay()</a>
</html>"));
function min "Returns the smallest element"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'min()'\">min()</a>
</html>"));
end min;
function max "Returns the largest element"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'max()'\">max()</a>
</html>"));
end max;
function sum "Sum of all array elements"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'sum()'\">sum()</a>
</html>"));
end sum;
function product "Product of all array elements"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'product()'\">product()</a>
</html>"));
end product;
function transpose "Transpose a matrix"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'transpose()'\">transpose()</a>
</html>"));
end transpose;
function symmetric "Returns a symmetric matrix"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'symmetric()'\">symmetric()</a>
</html>"));
end symmetric;
function smooth "Indicate smoothness of expression"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'smooth()'\">smooth()</a>
</html>"));
end smooth;
function diagonal<T> "Returns a diagonal matrix"
input T v[:];
output T mat[size(v,1),size(v,1)];
external "builtin";
annotation(__OpenModelica_UnboxArguments=true, Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'diagonal()'\">diagonal()</a>
</html>"));
end diagonal;
function cardinality "Number of connectors in connection"
input Real c;
output Integer numOccurances;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'cardinality()'\">cardinality()</a>
</html>"),version="Deprecated");
end cardinality;
function array "Constructs an array"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'array()'\">array()</a>
</html>"));
end array;
function zeros "Returns a zero array"
input Integer n annotation(__OpenModelica_varArgs=true);
output Integer o[:];
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'zeros()'\">zeros()</a>
</html>"));
end zeros;
function ones "Returns a one array"
input Integer n annotation(__OpenModelica_varArgs=true);
output Integer o[:];
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'ones()'\">ones()</a>
</html>"));
end ones;
function fill "Returns an array with all elements equal"
input OpenModelica.Internal.BuiltinType s;
input Integer n annotation(__OpenModelica_varArgs=true);
output OpenModelica.Internal.BuiltinType o[:];
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'fill()'\">fill()</a>
</html>"));
end fill;
function noEvent "Turn off event triggering"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'noEvent()'\">noEvent()</a>
</html>"));
end noEvent;
function pre "Refer to left limit"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'pre()'\">pre()</a>
</html>"));
end pre;
function sample "Overloaded operator to either trigger time events or to convert between continuous-time and clocked-time representation"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'sample()'\">sample()</a>
</html>"));
end sample;
function shiftSample "First activation of clock is shifted in time"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'shiftSample()'\">shiftSample()</a>
</html>"));
end shiftSample;
function backSample "First activation of clock is shifted in time before activation of u"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'backSample()'\">backSample()</a>
</html>"));
end backSample;
function transition "Define state machine transition"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'transition()'\">transition()</a>
</html>"));
end transition;
function initialState "Define inital state of a state machine"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'initialState()'\">initialState()</a>
</html>"));
end initialState;
function activeState "Return true if instance of a state machine is active, otherwise false"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'activeState()'\">activeState()</a>
</html>"));
end activeState;
function change "Indicate discrete variable changing"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'change()'\">change()</a>
</html>"));
end change;
function reinit "Reinitialize state variable"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'reinit()'\">reinit()</a>
</html>"));
end reinit;
function ndims "Number of array dimensions"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'ndims()'\">ndims()</a>
</html>"));
end ndims;
function size "Returns dimensions of an array"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'size()'\">size()</a>
</html>"));
end size;
function scalar "Returns a one-element array as scalar"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'scalar()'\">scalar()</a>
</html>"));
end scalar;
function vector "Returns an array as vector"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'vector()'\">vector()</a>
</html>"));
end vector;
function matrix "Returns the first two dimensions of an array as matrix"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'matrix()'\">matrix()</a>
</html>"));
end matrix;
function cat "Concatenate arrays along given dimension"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'cat()'\">cat()</a>
</html>"));
end cat;
function actualStream
input Real x;
output Real y;
external "builtin";
end actualStream;
function inStream
input Real x;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'inStream()'\">inStream()</a>
</html>"));
end inStream;
/* Extension for uncertainty computations */
record Distribution
String name "the name of the distibution, e.g \"normal\" ";
Real params[:] "parameter values for the specified distribution, e.g {0,0.1} for a normal distribution";
String paramNames[:/*should be size(params,1) but doesn't work, cb issue #1682*/] "the parameter names for the specified distribution, e.g {\"my\",\"sigma\"} for a normal distribution";
end Distribution;
record Correlation "defines correlation between two uncertainty variables"
Real v1 "first variable";
Real v2 "second variable";
Real c "correlation value";
end Correlation;
encapsulated package Connections
import OpenModelica.$Code.VariableName;
function branch
input VariableName node1;
input VariableName node2;
external "builtin";
end branch;
function root
input VariableName node;
external "builtin";
end root;
function potentialRoot
input VariableName node;
parameter input Integer priority = 0;
external "builtin";
end potentialRoot;
function isRoot
input VariableName node;
output Boolean isroot;
external "builtin";
end isRoot;
function uniqueRoot
input VariableName root;
input String message = "";
external "builtin";
end uniqueRoot;
function uniqueRootIndices
input VariableName[:] roots;
input VariableName[:] nodes;
input String message = "";
output Integer[size(roots, 1)] rootIndices;
// adrpo: I would like an assert here: size(nodes) <= size (roots)
external "builtin";
end uniqueRootIndices;
function rooted
external "builtin";
annotation(Documentation(info="<html>
<h4>Syntax</h4>
<blockquote>
<pre><b>Connections.rooted</b>(x)</pre>
</blockquote>
<h4>Description</h4>
<p>The operator \"rooted\" was introduced to improve efficiency:
A tool that constructs the graph with the Connections.branch/.root etc.
built-in operators has to cut the graph in order to arrive at \"spanning trees\".
If there is a statement \"Connections.branch(A,B)\", then \"rooted(A)\" returns true,
if \"A\" is closer to the root of the spanning tree as \"B\". Otherwise false is returned.
For the MultiBody library this allows to avoid unnecessary small linear systems of equations.
</p>
<h4>Known Bugs</h4>
<p>
OpenModelica, <b>rooted</b>(x) always returns true.
See <a href=\"https://trac.modelica.org/Modelica/ticket/95\">rooted ticket in the Modelica Trac</a> for details.
</p>
</html>"));
end rooted;
end Connections;
encapsulated package Subtask
type SamplingType = enumeration(Disabled, Continuous, Periodic);
function decouple
external "builtin";
end decouple;
function activated
output Boolean activated;
external "builtin";
end activated;
function lastInterval
external "builtin";
end lastInterval;
end Subtask;
impure function print "Prints to stdout, useful for debugging."
input String str;
external "builtin";
annotation(__OpenModelica_Impure=true, version="OpenModelica extension");
end print;
function classDirectory "Non-standard operator"
output String str;
external "builtin";
annotation(Documentation(info="<html>
<p>classDirectory() is a <b>non-standard operator</b> that was replaced by <a href=\"modelica://Modelica.Utilities.Files.loadResource\">Modelica.Utilities.Files.loadResource(uri)</a> before it was added to the language specification.</p>
<p>Returns the directory of the file where the classDirectory() call came from.</p>
</html>"),version="Dymola / MSL 2.2.1");
end classDirectory;
function getInstanceName
output String instanceName;
external "builtin";
annotation(Documentation(info="<html>
<h4>
Modelica definition:
</h4>
<p>
Returns a string with the name of the model/block that is simulated,
appended with the fully qualified name of the instance in which this
function is called.
</p>
<p>
If MyLib.Vehicle is simulated, the call of <b>getInstanceName()</b> might return:
<em>Vehicle.engine.controller</em>
</p>
<p>
Outside of a model or block, the return value is not specified.
</p>
<h4>
OpenModelica specifics:
</h4>
<p>
When OpenModelica does not have a prefix (e.g. in functions or packages),
it returns the name of the function or package.
</p>
<p>
If no class was being simulated, the last simulated class or a default will be used
(applicable for functions called from the scripting environment).
</p>
</html>
"),version="Modelica 3.3");
end getInstanceName;
function spatialDistribution "Not yet implemented"
input Real in0;
input Real in1;
input Real x;
input Boolean positiveVelocity;
parameter input Real initialPoints[:](each min = 0, each max = 1) = {0.0, 1.0};
parameter input Real initialValues[size(initialPoints, 1)] = {0.0, 0.0};
output Real out0;
output Real out1;
external "builtin";
annotation(version="Modelica 3.3");
end spatialDistribution;
function previous<T> "Access previous value of a clocked variable"
input T u;
output T y;
external "builtin";
annotation(__OpenModelica_UnboxArguments=true, version="Modelica 3.3", Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'previous()'\">previous()</a>
</html>"));
end previous;
function subSample = $overload(OpenModelica.Internal.subSampleExpression, OpenModelica.Internal.subSampleClock)
"Conversion from faster clock to slower clock"
annotation(version="Modelica 3.3", Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'subSample()'\">subSample()</a>
</html>"));
function superSample = $overload(OpenModelica.Internal.superSampleExpression, OpenModelica.Internal.superSampleClock)
"Conversion from slower clock to faster clock"
annotation(version="Modelica 3.3", Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'superSample()'\">superSample()</a>
</html>"));
function hold<T> "Conversion from clocked discrete-time to continuous time"
input T u;
output T y;
external "builtin";
annotation(__OpenModelica_UnboxArguments=true, version="Modelica 3.3", Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'hold()'\">hold()</a>
</html>"));
end hold;
function noClock<T> "Clock of y=Clock(u) is always inferred"
input T u;
output T y;
external "builtin";
annotation(__OpenModelica_UnboxArguments=true, version="Modelica 3.3", Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'noClock()'\">noClock()</a>
</html>"));
end noClock;
function interval = $overload(OpenModelica.Internal.intervalInferred, OpenModelica.Internal.intervalExpression)
"Returns the interval between the previous and present tick of the clock of its argument"
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'interval()'\">interval()</a>
</html>"));
impure function ticksInState "Returns the number of clock ticks since a transition was made to the currently active state"
output Integer ticks;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'ticksInState()'\">ticksInState()</a>
</html>"));
end ticksInState;
impure function timeInState "Returns the time duration as Real in [s] since a transition was made to the currently active state"
output Real t;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'ticksInState()'\">ticksInState()</a>
</html>"));
end timeInState;
/* Actually contains more...
record SimulationResult
String resultFile;
String simulationOptions;
String messages;
end SimulationResult; */
encapsulated package OpenModelica "OpenModelica internal definitions and scripting functions"
type $Code "Code quoting is not a uniontype yet because that would require enabling MetaModelica extensions in the regular compiler.
Besides, it has special semantics."
type Expression "An expression of some kind" end Expression;
type ExpressionOrModification "An expression or modification of some kind" end ExpressionOrModification;
type TypeName "A path, for example the name of a class, e.g. A.B.C or .A.B" end TypeName;
type VariableName "A variable name, e.g. a.b or a[1].b[3].c" end VariableName;
type VariableNames "An array of variable names, e.g. {a.b,a[1].b[3].c}, or a single VariableName" end VariableNames;
end $Code;
function threadData
output ThreadData threadData;
protected
record ThreadData
end ThreadData;
external "builtin";
annotation(Documentation(info="<html>
<p>Used to access thread-specific data in external functions.</p>
</html>"));
end threadData;
package Internal "Contains internal implementations, e.g. overloaded builtin functions"
type BuiltinType "Integer,Real,String,enumeration or array of some kind"
end BuiltinType;
function ClockConstructor = $overload(OpenModelica.Internal.inferredClock, OpenModelica.Internal.rationalClock, OpenModelica.Internal.realClock, OpenModelica.Internal.booleanClock, OpenModelica.Internal.solverClock)
"Overloaded clock constructor"
annotation(version="Modelica 3.3", Documentation(info="<html>
The Clock constructors.</a>
</html>"));
function inferredClock
output Clock c;
external "builtin";
end inferredClock;
function rationalClock
input Integer intervalCounter(min=0);
parameter input Integer resolution(unit="Hz", min=1)=1;
output Clock c;
external "builtin";
end rationalClock;
function realClock
input Real interval(unit="s", min=0);
output Clock c;
external "builtin";
end realClock;
function booleanClock
input Boolean condition;
input Real startInterval=0.0;
output Clock c;
external "builtin";
end booleanClock;
function solverClock
input Clock c;
parameter input String solverMethod;
output Clock clk;
external "builtin";
end solverClock;
function intervalInferred
output Real interval;
external "builtin" interval=interval();
end intervalInferred;
function intervalExpression<T>
input T u;
output Real y;
external "builtin" y=interval(u);
annotation(__OpenModelica_UnboxArguments=true);
end intervalExpression;
impure function subSampleExpression<T>
input T u;
parameter input Integer factor(min=0)=0;
output T y;
external "builtin" y=subSample(u,factor);
annotation(__OpenModelica_UnboxArguments=true);
end subSampleExpression;
impure function subSampleClock
input Clock u;
parameter input Integer factor(min=0)=0;
output Clock y;
external "builtin" y=subSample(u,factor);
end subSampleClock;
impure function superSampleExpression<T>
input T u;
parameter input Integer factor(min=0)=0;
output T y;
external "builtin" y=superSample(u,factor);
annotation(__OpenModelica_UnboxArguments=true);
end superSampleExpression;
impure function superSampleClock
input Clock u;
parameter input Integer factor(min=0)=0;
output Clock y;
external "builtin" y=superSample(u,factor);
end superSampleClock;
impure function delay2
input Real expr;
parameter input Real delayTime;
output Real value;
external "builtin" value=delay(expr, delayTime);
end delay2;
impure function delay3
input Real expr, delayTime;
parameter input Real delayMax;
output Real value;
external "builtin" value=delay(expr, delayTime, delayMax);
end delay3;
function intAbs
input Integer v;
output Integer o;
external "builtin" o=abs(v);
annotation(preferredView="text");
end intAbs;
function realAbs
input Real v;
output Real o;
external "builtin" o=abs(v);
annotation(preferredView="text");
end realAbs;
function intDiv
input Integer x;
input Integer y;
output Integer z;
external "builtin" z=div(x,y);
annotation(preferredView="text");
end intDiv;
function realDiv
input Real x;
input Real y;
output Real z;
external "builtin" z=div(x,y);
annotation(preferredView="text");
end realDiv;
function intMod
input Integer x;
input Integer y;
output Integer z;
external "builtin" z=mod(x,y);
annotation(preferredView="text");
end intMod;
function realMod
input Real x;
input Real y;
output Real z;
external "builtin" z=mod(x,y);
annotation(preferredView="text");
end realMod;
function intRem
input Integer x;
input Integer y;
output Integer z;
algorithm
z := x - (div(x, y) * y);
annotation(preferredView="text", __OpenModelica_EarlyInline=true);