forked from modelica/ModelicaStandardLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Math.mo
3358 lines (3129 loc) · 127 KB
/
Math.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 Math "Library of Real mathematical functions as input/output blocks"
import Modelica.Blocks.Interfaces;
extends Modelica.Icons.Package;
encapsulated package UnitConversions
"Conversion blocks to convert between SI and non-SI unit signals"
import Modelica;
import Modelica.Units.NonSI;
extends Modelica.Icons.Package;
block To_degC "Convert from Kelvin to degCelsius"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="K"), y(
unit="degC"));
equation
y = Modelica.Units.Conversions.to_degC(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="K"),Text(
extent={{100,-20},{20,-100}},
textString="degC")}), Documentation(info="<html>
<p>
This block converts the input signal from Kelvin to degCelsius and returns
the result as output signal.
</p>
</html>"));
end To_degC;
block From_degC "Convert from degCelsius to Kelvin"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="degC"),
y(unit="K"));
equation
y = Modelica.Units.Conversions.from_degC(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="degC"),Text(
extent={{100,-20},{20,-100}},
textString="K")}), Documentation(info="<html>
<p>
This block converts the input signal from degCelsius to Kelvin and returns
the result as output signal.
</p>
</html>"));
end From_degC;
block To_degF "Convert from Kelvin to degFahrenheit"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="K"), y(
unit="degF"));
equation
y = Modelica.Units.Conversions.to_degF(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="K"),Text(
extent={{100,-20},{20,-100}},
textString="degF")}), Documentation(info="<html>
<p>
This block converts the input signal from Kelvin to degFahrenheit and returns
the result as output signal.
</p>
</html>"));
end To_degF;
block From_degF "Convert from degFahrenheit to Kelvin"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="degF"),
y(unit="K"));
equation
y = Modelica.Units.Conversions.from_degF(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="degF"),Text(
extent={{100,-20},{20,-100}},
textString="K")}), Documentation(info="<html>
<p>
This block converts the input signal from degFahrenheit to Kelvin and returns
the result as output signal.
</p>
</html>"));
end From_degF;
block To_degRk "Convert from Kelvin to degRankine"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="K"), y(
unit="degRk"));
equation
y = Modelica.Units.Conversions.to_degRk(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="K"),Text(
extent={{100,-20},{20,-100}},
textString="degRk")}), Documentation(info="<html>
<p>
This block converts the input signal from Kelvin to degRankine and returns
the result as output signal.
</p>
</html>"));
end To_degRk;
block From_degRk "Convert from degRankine to Kelvin"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="degRk"),
y(unit="K"));
equation
y = Modelica.Units.Conversions.from_degRk(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="degRk"),Text(
extent={{100,-20},{20,-100}},
textString="K")}), Documentation(info="<html>
<p>
This block converts the input signal from degRankine to Kelvin and returns
the result as output signal.
</p>
</html>"));
end From_degRk;
block To_deg "Convert from radian to degree"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="rad"),
y(unit="deg"));
equation
y = Modelica.Units.Conversions.to_deg(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="rad"),Text(
extent={{100,-20},{20,-100}},
textString="deg")}), Documentation(info="<html>
<p>
This block converts the input signal from radian to degree and returns
the result as output signal.
</p>
</html>"));
end To_deg;
block From_deg "Convert from degree to radian"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="deg"),
y(unit="rad"));
equation
y = Modelica.Units.Conversions.from_deg(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="deg"),Text(
extent={{100,-20},{20,-100}},
textString="rad")}), Documentation(info="<html>
<p>
This block converts the input signal from degree to radian and returns
the result as output signal.
</p>
</html>"));
end From_deg;
block To_rpm "Convert from radian per second to revolutions per minute"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="rad/s"),
y(unit="rev/min"));
equation
y = Modelica.Units.Conversions.to_rpm(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{26,82},{-98,50}},
textString="rad/s"),Text(
extent={{100,-42},{-62,-74}},
textString="rev/min")}), Documentation(info="<html>
<p>
This block converts the input signal from radian per second to revolutions per minute and returns
the result as output signal.
</p>
</html>"));
end To_rpm;
block From_rpm "Convert from revolutions per minute to radian per second"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="rev/min"),
y(unit="rad/s"));
equation
y = Modelica.Units.Conversions.from_rpm(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{50,84},{-94,56}},
textString="rev/min"),Text(
extent={{94,-42},{-26,-74}},
textString="rad/s")}), Documentation(info="<html>
<p>
This block converts the input signal from revolutions per minute to radian per second and returns
the result as output signal.
</p>
</html>"));
end From_rpm;
block To_kmh "Convert from metre per second to kilometre per hour"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="m/s"),
y(unit="km/h"));
equation
y = Modelica.Units.Conversions.to_kmh(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{0,82},{-96,42}},
textString="m/s"),Text(
extent={{92,-40},{-14,-84}},
textString="km/h")}), Documentation(info="<html>
<p>
This block converts the input signal from metre per second to kilometre per hour and returns
the result as output signal.
</p>
</html>"));
end To_kmh;
block From_kmh "Convert from kilometre per hour to metre per second"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="km/h"),
y(unit="m/s"));
equation
y = Modelica.Units.Conversions.from_kmh(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{26,80},{-96,48}},
textString="km/h"),Text(
extent={{92,-46},{-20,-82}},
textString="m/s")}), Documentation(info="<html>
<p>
This block converts the input signal from kilometre per hour to metre per second and returns
the result as output signal.
</p>
</html>"));
end From_kmh;
block To_day "Convert from second to day"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="s"), y(
unit="d"));
equation
y = Modelica.Units.Conversions.to_day(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="s"),Text(
extent={{100,-20},{20,-100}},
textString="day")}), Documentation(info="<html>
<p>
This block converts the input signal from second to day and returns
the result as output signal.
</p>
</html>"));
end To_day;
block From_day "Convert from day to second"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="d"), y(
unit="s"));
equation
y = Modelica.Units.Conversions.from_day(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="day"),Text(
extent={{100,-20},{20,-100}},
textString="s")}), Documentation(info="<html>
<p>
This block converts the input signal from day to second and returns
the result as output signal.
</p>
</html>"));
end From_day;
block To_hour "Convert from second to hour"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="s"), y(
unit="h"));
equation
y = Modelica.Units.Conversions.to_hour(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="s"),Text(
extent={{100,-20},{20,-100}},
textString="hour")}), Documentation(info="<html>
<p>
This block converts the input signal from second to hour and returns
the result as output signal.
</p>
</html>"));
end To_hour;
block From_hour "Convert from hour to second"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="h"), y(
unit="s"));
equation
y = Modelica.Units.Conversions.from_hour(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="hour"),Text(
extent={{100,-20},{20,-100}},
textString="s")}), Documentation(info="<html>
<p>
This block converts the input signal from hour to second and returns
the result as output signal.
</p>
</html>"));
end From_hour;
block To_minute "Convert from second to minute"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="s"), y(
unit="min"));
equation
y = Modelica.Units.Conversions.to_minute(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="s"),Text(
extent={{100,-20},{20,-100}},
textString="minute")}), Documentation(info="<html>
<p>
This block converts the input signal from second to minute and returns
the result as output signal.
</p>
</html>"));
end To_minute;
block From_minute "Convert from minute to second"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="min"),
y(unit="s"));
equation
y = Modelica.Units.Conversions.from_minute(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="minute"),Text(
extent={{100,-20},{20,-100}},
textString="s")}), Documentation(info="<html>
<p>
This block converts the input signal from minute to second and returns
the result as output signal.
</p>
</html>"));
end From_minute;
block To_litre "Convert from cubic metre to litre"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="m3"), y(
unit="l"));
equation
y = Modelica.Units.Conversions.to_litre(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="m3"),Text(
extent={{100,-20},{20,-100}},
textString="litre")}), Documentation(info="<html>
<p>
This block converts the input signal from metre to litre and returns
the result as output signal.
</p>
</html>"));
end To_litre;
block From_litre "Convert from litre to cubic metre"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="l"), y(
unit="m3"));
equation
y = Modelica.Units.Conversions.from_litre(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="litre"),Text(
extent={{100,-20},{20,-100}},
textString="m3")}), Documentation(info="<html>
<p>
This block converts the input signal from litre to cubic metre and returns
the result as output signal.
</p>
</html>"));
end From_litre;
block To_kWh "Convert from Joule to kilo Watt hour"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="J"), y(
unit="kW.h"));
equation
y = Modelica.Units.Conversions.to_kWh(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="J"),Text(
extent={{100,-20},{20,-100}},
textString="kW.h")}), Documentation(info="<html>
<p>
This block converts the input signal from Joule to kilo Watt hour and returns
the result as output signal.
</p>
</html>"));
end To_kWh;
block From_kWh "Convert from kilo Watt hour to Joule"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="kW.h"),
y(unit="J"));
equation
y = Modelica.Units.Conversions.from_kWh(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="kW.h"),Text(
extent={{100,-20},{20,-100}},
textString="J")}), Documentation(info="<html>
<p>
This block converts the input signal from kilo Watt hour to Joule and returns
the result as output signal.
</p>
</html>"));
end From_kWh;
block To_bar "Convert from Pascal to bar"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="Pa"), y(
unit="bar"));
equation
y = Modelica.Units.Conversions.to_bar(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="Pa"),Text(
extent={{100,-20},{20,-100}},
textString="bar")}), Documentation(info="<html>
<p>
This block converts the input signal from Pascal to bar and returns
the result as output signal.
</p>
</html>"));
end To_bar;
block From_bar "Convert from bar to Pascal"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="bar"),
y(unit="Pa"));
equation
y = Modelica.Units.Conversions.from_bar(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="bar"),Text(
extent={{100,-20},{20,-100}},
textString="Pa")}), Documentation(info="<html>
<p>
This block converts the input signal from bar to Pascal and returns
the result as output signal.
</p>
</html>"));
end From_bar;
block To_gps "Convert from kilogram per second to gram per second"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="kg/s"),
y(unit="g/s"));
equation
y = Modelica.Units.Conversions.to_gps(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="kg/s"),Text(
extent={{100,-20},{20,-100}},
textString="g/s")}), Documentation(info="<html>
<p>
This block converts the input signal from kilogram per second to gram per seconds and returns
the result as output signal.
</p>
</html>"));
end To_gps;
block From_gps "Convert from gram per second to kilogram per second"
extends Modelica.Blocks.Interfaces.PartialConversionBlock(u(unit="g/s"),
y(unit="kg/s"));
equation
y = Modelica.Units.Conversions.from_gps(u);
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-20,100},{-100,20}},
textString="g/s"),Text(
extent={{100,-20},{20,-100}},
textString="kg/s")}), Documentation(info="<html>
<p>
This block converts the input signal from gram per second to kilogram per second and returns
the result as output signal.
</p>
</html>"));
end From_gps;
annotation (Documentation(info="<html>
<p>
This package consists of blocks that convert an input signal
with a specific unit to an output signal in another unit
(e.g., conversion of an angle signal from \"deg\" to \"rad\").
</p>
</html>"));
end UnitConversions;
block InverseBlockConstraints
"Construct inverse model by requiring that two inputs and two outputs are identical"
Modelica.Blocks.Interfaces.RealInput u1 "Input signal 1 (u1 = u2)"
annotation (Placement(transformation(extent={{-240,-20},{-200,20}}), iconTransformation(extent={{-240,-20},{-200,20}})));
Modelica.Blocks.Interfaces.RealInput u2 "Input signal 2 (u1 = u2)"
annotation (Placement(transformation(extent={{-140,-20},{-180,20}}), iconTransformation(extent={{-140,-20},{-180,20}})));
Modelica.Blocks.Interfaces.RealOutput y1 "Output signal 1 (y1 = y2)"
annotation (Placement(transformation(extent={{200,-10},{220,10}}), iconTransformation(extent={{200,-10},{220,10}})));
Modelica.Blocks.Interfaces.RealOutput y2 "Output signal 2 (y1 = y2)"
annotation (Placement(transformation(
extent={{10,-10},{-10,10}},
origin={170,0}), iconTransformation(extent={{180,-10},{160,10}})));
equation
u1 = u2;
y1 = y2;
annotation (
defaultConnectionStructurallyInconsistent=true,
Icon(coordinateSystem(preserveAspectRatio=false, extent={{-200,-120},{200,
120}}), graphics={
Line(
points={{180,0},{200,0}},
color={0,0,127}),
Line(
points={{-200,0},{-180,0}},
color={0,0,127}),
Rectangle(extent={{-190,120},{190,-120}}, lineColor={135,135,135})}),
Documentation(info="<html>
<p>
Exchange input and output signals of a block, i.e., the previous
block inputs become block outputs and the previous block outputs become
block inputs. This block is used to construct inverse models.
Its usage is demonstrated in example:
<a href=\"modelica://Modelica.Blocks.Examples.InverseModel\">Modelica.Blocks.Examples.InverseModel</a>.
</p>
<p>
Note, if a block shall be inverted that has several input and output blocks,
then this can be easily achieved by using a vector of InverseBlockConstraints
instances:
</p>
<blockquote><pre>
InverseBlockConstraint invert[3]; // Block to be inverted has 3 input signals
</pre></blockquote>
</html>"));
end InverseBlockConstraints;
block Gain "Output the product of a gain value with the input signal"
parameter Real k(start=1)
"Gain value multiplied with input signal";
public
Interfaces.RealInput u "Input signal connector" annotation (Placement(
transformation(extent={{-140,-20},{-100,20}})));
Interfaces.RealOutput y "Output signal connector" annotation (Placement(
transformation(extent={{100,-10},{120,10}})));
equation
y = k*u;
annotation (
Documentation(info="<html>
<p>
This block computes output <em>y</em> as
<em>product</em> of gain <em>k</em> with the
input <em>u</em>:
</p>
<blockquote><pre>
y = k * u;
</pre></blockquote>
</html>"),
Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,
100}}), graphics={
Polygon(
points={{-100,-100},{-100,100},{100,0},{-100,-100}},
lineColor={0,0,127},
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Text(
extent={{-150,-140},{150,-100}},
textString="k=%k"),
Text(
extent={{-150,140},{150,100}},
textString="%name",
textColor={0,0,255})}));
end Gain;
block MatrixGain
"Output the product of a gain matrix with the input signal vector"
parameter Real K[:, :]=[1, 0; 0, 1]
"Gain matrix which is multiplied with the input";
extends Interfaces.MIMO(final nin=size(K, 2), final nout=size(K, 1));
equation
y = K*u;
annotation (
Documentation(info="<html>
<p>
This blocks computes output vector <strong>y</strong> as <em>product</em> of the
gain matrix <strong>K</strong> with the input signal vector <strong>u</strong>:
</p>
<blockquote><pre>
<strong>y</strong> = <strong>K</strong> * <strong>u</strong>;
</pre></blockquote>
<p>
Example:
</p>
<blockquote><pre>
parameter: <strong>K</strong> = [0.12 2; 3 1.5]
results in the following equations:
| y[1] | | 0.12 2.00 | | u[1] |
| | = | | * | |
| y[2] | | 3.00 1.50 | | u[2] |
</pre></blockquote>
</html>"),
Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,
100}}), graphics={Text(
extent={{-90,-60},{90,60}},
textColor={160,160,164},
textString="*K")}));
end MatrixGain;
block MultiSum "Sum of Reals: y = k[1]*u[1] + k[2]*u[2] + ... + k[n]*u[n]"
extends Modelica.Blocks.Interfaces.PartialRealMISO;
parameter Real k[nu]=fill(1, nu) "Input gains";
equation
if size(u, 1) > 0 then
y = k*u;
else
y = 0;
end if;
annotation (Icon(graphics={Text(
extent={{-200,-110},{200,-140}},
textString="%k"), Text(
extent={{-72,68},{92,-68}},
textString="+")}), Documentation(info="<html>
<p>
This blocks computes the scalar Real output \"y\" as sum of the elements of the
Real input signal vector u:
</p>
<blockquote><pre>
y = k[1]*u[1] + k[2]*u[2] + ... k[N]*u[N];
</pre></blockquote>
<p>
The input connector is a vector of Real input signals.
When a connection line is drawn, the dimension of the input
vector is enlarged by one and the connection is automatically
connected to this new free index (thanks to the
connectorSizing annotation).
</p>
<p>
The usage is demonstrated, e.g., in example
<a href=\"modelica://Modelica.Blocks.Examples.RealNetwork1\">Modelica.Blocks.Examples.RealNetwork1</a>.
</p>
<p>
If no connection to the input connector \"u\" is present,
the output is set to zero: y=0.
</p>
</html>"));
end MultiSum;
block MultiProduct "Product of Reals: y = u[1]*u[2]* ... *u[n]"
extends Modelica.Blocks.Interfaces.PartialRealMISO;
equation
if size(u, 1) > 0 then
y = product(u);
else
y = 0;
end if;
annotation (Icon(graphics={Text(
extent={{-74,50},{94,-94}},
textString="*")}), Documentation(info="<html>
<p>
This blocks computes the scalar Real output \"y\" as product of the elements of the
Real input signal vector u:
</p>
<blockquote><pre>
y = u[1]*u[2]* ... *u[N];
</pre></blockquote>
<p>
The input connector is a vector of Real input signals.
When a connection line is drawn, the dimension of the input
vector is enlarged by one and the connection is automatically
connected to this new free index (thanks to the
connectorSizing annotation).
</p>
<p>
The usage is demonstrated, e.g., in example
<a href=\"modelica://Modelica.Blocks.Examples.RealNetwork1\">Modelica.Blocks.Examples.RealNetwork1</a>.
</p>
<p>
If no connection to the input connector \"u\" is present,
the output is set to zero: y=0.
</p>
</html>"));
end MultiProduct;
block MultiSwitch
"Set Real expression that is associated with the first active input signal"
input Real expr[nu]=fill(0.0, nu)
"y = if u[i] then expr[i] else y_default (time varying)"
annotation (Dialog);
parameter Real y_default=0.0
"Default value of output y if all u[i] = false";
parameter Integer nu(min=0) = 0 "Number of input connections"
annotation (Dialog(connectorSizing=true), HideResult=true);
parameter Integer precision(min=0) = 3
"Number of significant digits to be shown in dynamic diagram layer for y"
annotation (Dialog(tab="Advanced"));
Modelica.Blocks.Interfaces.BooleanVectorInput u[nu]
"Set y = expr[i], if u[i] = true"
annotation (Placement(transformation(extent={{-110,30},{-90,-30}})));
Modelica.Blocks.Interfaces.RealOutput y "Output depending on expression"
annotation (Placement(transformation(extent={{300,-10},{320,10}})));
protected
Integer firstActiveIndex;
initial equation
pre(u) = fill(false, nu);
equation
firstActiveIndex = Modelica.Math.BooleanVectors.firstTrueIndex(u);
y = if firstActiveIndex == 0 then y_default else expr[firstActiveIndex];
annotation (
defaultComponentName="multiSwitch1",
Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{300,
100}}), graphics={
Rectangle(
extent={{-100,-51},{300,50}},
lineThickness=5.0,
fillColor={170,213,255},
fillPattern=FillPattern.Solid,
borderPattern=BorderPattern.Raised),
Text(
extent={{-86,16},{295,-17}},
textString="%expr"),
Text(
extent={{310,-25},{410,-45}},
textString=DynamicSelect(" ", String(
y,
minimumLength=1,
significantDigits=precision))),
Text(
extent={{-100,-60},{300,-90}},
textString="else: %y_default"),
Text(
extent={{-100,100},{300,60}},
textString="%name",
textColor={0,0,255})}),
Documentation(info="<html>
<p>
This block has a vector of Boolean input signals u[nu] and a vector of
(time varying) Real expressions expr[nu]. The output signal y is
set to expr[i], if i is the first element in the input vector u that is true. If all input signals are
false, y is set to parameter \"y_default\".
</p>
<blockquote><pre>
// Conceptual equation (not valid Modelica)
i = 'first element of u[:] that is true';
y = <strong>if</strong> i==0 <strong>then</strong> y_default <strong>else</strong> expr[i];
</pre></blockquote>
<p>
The input connector is a vector of Boolean input signals.
When a connection line is drawn, the dimension of the input
vector is enlarged by one and the connection is automatically
connected to this new free index (thanks to the
connectorSizing annotation).
</p>
<p>
The usage is demonstrated, e.g., in example
<a href=\"modelica://Modelica.Blocks.Examples.RealNetwork1\">Modelica.Blocks.Examples.RealNetwork1</a>.
</p>
</html>"));
end MultiSwitch;
block Sum "Output the sum of the elements of the input vector"
extends Interfaces.MISO;
parameter Real k[nin]=ones(nin) "Optional: sum coefficients";
equation
y = k*u;
annotation (
defaultComponentName="sum1",
Documentation(info="<html>
<p>
This blocks computes output <strong>y</strong> as
<em>sum</em> of the elements of the input signal vector
<strong>u</strong>:
</p>
<blockquote><pre>
<strong>y</strong> = <strong>u</strong>[1] + <strong>u</strong>[2] + ...;
</pre></blockquote>
<p>
Example:
</p>
<blockquote><pre>
parameter: nin = 3;
results in the following equations:
y = u[1] + u[2] + u[3];
</pre></blockquote>
</html>"),
Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,
100}}), graphics={Line(
points={{26,42},{-34,42},{6,2},{-34,-38},{26,-38}})}));
end Sum;
block Feedback "Output difference between commanded and feedback input"
Interfaces.RealInput u1 "Commanded input" annotation (Placement(transformation(extent={{-100,
-20},{-60,20}})));
Interfaces.RealInput u2 "Feedback input" annotation (Placement(transformation(
origin={0,-80},
extent={{-20,-20},{20,20}},
rotation=90)));
Interfaces.RealOutput y annotation (Placement(transformation(extent={{80,-10},
{100,10}})));
equation
y = u1 - u2;
annotation (
Documentation(info="<html>
<p>
This blocks computes output <strong>y</strong> as <em>difference</em> of the
commanded input <strong>u1</strong> and the feedback
input <strong>u2</strong>:
</p>
<blockquote><pre>
<strong>y</strong> = <strong>u1</strong> - <strong>u2</strong>;
</pre></blockquote>
<p>
Example:
</p>
<blockquote><pre>
parameter: n = 2
results in the following equations:
y = u1 - u2
</pre></blockquote>
</html>"),
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={
Ellipse(
lineColor={0,0,127},
fillColor={235,235,235},
fillPattern=FillPattern.Solid,
extent={{-20,-20},{20,20}}),
Line(points={{-60,0},{-20,0}}, color={0,0,127}),
Line(points={{20,0},{80,0}}, color={0,0,127}),
Line(points={{0,-20},{0,-60}}, color={0,0,127}),
Text(extent={{-14,-94},{82,0}}, textString="-"),
Text(
textColor={0,0,255},
extent={{-150,40},{150,80}},
textString="%name")}));
end Feedback;
block Add "Output the sum of the two inputs"
extends Interfaces.SI2SO;
parameter Real k1=+1 "Gain of input signal 1";
parameter Real k2=+1 "Gain of input signal 2";
equation
y = k1*u1 + k2*u2;
annotation (
Documentation(info="<html>
<p>
This blocks computes output <strong>y</strong> as <em>sum</em> of the
two input signals <strong>u1</strong> and <strong>u2</strong>:
</p>
<blockquote><pre>
<strong>y</strong> = k1*<strong>u1</strong> + k2*<strong>u2</strong>;
</pre></blockquote>
<p>
Example:
</p>
<blockquote><pre>
parameter: k1= +2, k2= -3
results in the following equations:
y = 2 * u1 - 3 * u2
</pre></blockquote>
</html>"),
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={
Line(points={{-100,60},{-74,24},{-44,24}}, color={0,0,127}),
Line(points={{-100,-60},{-74,-24},{-44,-24}}, color={0,0,127}),
Ellipse(lineColor={0,0,127}, extent={{-50,-50},{50,50}}),
Line(points={{50,0},{100,0}}, color={0,0,127}),
Text(extent={{-40,40},{40,-40}}, textString="+"),
Text(extent={{-100,52},{5,92}}, textString="%k1"),
Text(extent={{-100,-92},{5,-52}}, textString="%k2")}),
Diagram(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{
100,100}}), graphics={ Line(points={{50,0},{100,0}},
color={0,0,255}), Line(
points={{50,0},{100,0}}, color={0,0,127})}));
end Add;
block Add3 "Output the sum of the three inputs"
extends Modelica.Blocks.Icons.Block;
parameter Real k1=+1 "Gain of input signal 1";
parameter Real k2=+1 "Gain of input signal 2";
parameter Real k3=+1 "Gain of input signal 3";
Interfaces.RealInput u1 "Connector of Real input signal 1" annotation (
Placement(transformation(extent={{-140,60},{-100,100}})));
Interfaces.RealInput u2 "Connector of Real input signal 2" annotation (
Placement(transformation(extent={{-140,-20},{-100,20}})));
Interfaces.RealInput u3 "Connector of Real input signal 3" annotation (
Placement(transformation(extent={{-140,-100},{-100,-60}})));
Interfaces.RealOutput y "Connector of Real output signal" annotation (
Placement(transformation(extent={{100,-10},{120,10}})));
equation
y = k1*u1 + k2*u2 + k3*u3;
annotation (
Documentation(info="<html>
<p>
This blocks computes output <strong>y</strong> as <em>sum</em> of the
three input signals <strong>u1</strong>, <strong>u2</strong> and <strong>u3</strong>:
</p>
<blockquote><pre>
<strong>y</strong> = k1*<strong>u1</strong> + k2*<strong>u2</strong> + k3*<strong>u3</strong>;
</pre></blockquote>
<p>
Example:
</p>
<blockquote><pre>
parameter: k1= +2, k2= -3, k3=1;
results in the following equations:
y = 2 * u1 - 3 * u2 + u3;
</pre></blockquote>
</html>"),
Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,
100}}), graphics={
Text(
extent={{-100,50},{5,90}},
textString="%k1"),
Text(
extent={{-100,-20},{5,20}},
textString="%k2"),
Text(
extent={{-100,-50},{5,-90}},
textString="%k3"),
Text(
extent={{10,40},{90,-40}},
textString="+")}));
end Add3;
block Product "Output product of the two inputs"
extends Interfaces.SI2SO;
equation
y = u1*u2;
annotation (
Documentation(info="<html>
<p>
This blocks computes the output <strong>y</strong>
as <em>product</em> of the two inputs <strong>u1</strong> and <strong>u2</strong>:
</p>
<blockquote><pre>
y = u1 * u2;
</pre></blockquote>
</html>"),
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={
Line(points={{-100,60},{-40,60},{-30,40}}, color={0,0,127}),
Line(points={{-100,-60},{-40,-60},{-30,-40}}, color={0,0,127}),
Line(points={{50,0},{100,0}}, color={0,0,127}),
Line(points={{-30,0},{30,0}}),
Line(points={{-15,25.99},{15,-25.99}}),
Line(points={{-15,-25.99},{15,25.99}}),
Ellipse(lineColor={0,0,127}, extent={{-50,-50},{50,50}})}));
end Product;
block Division "Output first input divided by second input"