-
Notifications
You must be signed in to change notification settings - Fork 19
/
ObsoleteLinearSystems2.mo
1688 lines (1564 loc) · 68.6 KB
/
ObsoleteLinearSystems2.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 ;
package ObsoleteLinearSystems2
"Library that contains components from Modelica_LinearSystems2 Library 2.4.X that have been removed from version 3.0.0"
package Math "Package of additional functions for Modelica.Math"
extends Modelica.Icons.Package;
operator record Complex "Record defining a Complex number"
encapsulated function j "Obsolete imaginary unit function"
import Modelica;
import Complex;
output Complex c = Modelica.ComplexMath.j "= sqrt(-1)";
annotation(
obsolete = "Obsolete function. See function documentation for how to migrate imaginary unit j.",
Inline=true,
Documentation(info="<html>
<p>
A definition of complex number <code>c1</code> such as
</p>
<blockquote><pre>
Complex j = Modelica_LinearSystems2.Math.Complex.j();
Complex c1=2+3*j;
</pre></blockquote>
<p>
using Modelica_LinearSystems2 <strong>2.4.X</strong> shall be
automatically migrated now to (just the first line is affected)
</p>
<blockquote><pre>
Complex j = ObsoleteLinearSystems2.Math.Complex.j();
Complex c1=2+3*j;
</pre></blockquote>
<p>
The automatic conversion to proper <code>Modelica.ComplexMath.j</code> is
not possible since this is a complex constant. Therefore, you shall replace
the first line manually to
</p>
<blockquote><pre>
Complex j = Modelica.ComplexMath.j;
Complex c1=2+3*j; // this stays unchanged
</pre></blockquote>
<p>
if <code>j</code> is further needed in the class.
In many classes, <code>j</code> is used only for the abovementioned complex
number definion. Then, the import of <code>j</code> can be completely omitted and
only the second line can be modified as follows
</p>
<blockquote><pre>
Complex c1 = Complex(2, 3);
</pre></blockquote>
</html>"));
end j;
end Complex;
package LAPACK "Package of LAPACK functions"
extends Modelica.Icons.Package;
function dgeev
"Obsolete: Compute the eigenvalues and the (real) left and right eigenvectors of matrix A"
input Real A[:,size(A, 1)];
output Real alphaReal[size(A, 1)]
"Real part of alpha (eigenvalue=(alphaReal+i*alphaImag))";
output Real alphaImag[size(A, 1)]
"Imaginary part of alpha (eigenvalue=(alphaReal+i*alphaImag))";
output Real lEigenVectors[size(A, 1),size(A, 1)]
"left eigenvectors of matrix A";
output Real rEigenVectors[size(A, 1),size(A, 1)]
"right eigenvectors of matrix A";
output Integer info;
protected
Integer n=size(A, 1);
Integer lwork=4*n;
Real work[lwork];
external "Fortran 77" dgeev(
"V",
"V",
n,
A,
n,
alphaReal,
alphaImag,
lEigenVectors,
n,
rEigenVectors,
n,
work,
size(work, 1),
info) annotation(Library = {"lapack"});
annotation (
obsolete = "Deprecated function - use Modelica.Math.Matrices.LAPACK.dgeev instead",
Documentation(info="<html>
<p>
This function is obsolete. Use
<a href=\"modelica://Modelica.Math.Matrices.LAPACK.dgeev\">Modelica.Math.Matrices.LAPACK.dgeev</a>
instead.
</p>
<p>
Note: output <code>lEigenVector</code> is missing in the function from the Modelica
Standard Library and must be removed or resolved in another way.
</p>
</html>"));
end dgeev;
function dgegv "Compute generalized eigenvalues for a (A,B) system"
input Real A[:,size(A, 1)];
input Real B[size(A, 1),size(A, 1)];
output Real alphaReal[size(A, 1)]
"Real part of alpha (eigenvalue=(alphaReal+i*alphaImag)/beta)";
output Real alphaImag[size(A, 1)] "Imaginary part of alpha";
output Real beta[size(A, 1)] "Denominator of eigenvalue";
output Integer info;
protected
Integer n=size(A, 1);
Integer lwork=2*n + max(6*n, n*n + n);
Real Awork[n,n]=A;
Real Bwork[n,n]=B;
Real work[lwork];
Real dummy1[1,1];
Real dummy2[1,1];
external "Fortran 77" dgegv(
"N",
"N",
n,
Awork,
n,
Bwork,
n,
alphaReal,
alphaImag,
beta,
dummy1,
1,
dummy2,
1,
work,
size(work, 1),
info) annotation (Library="lapack");
annotation (
obsolete = "Deprecated function - use Modelica.Math.Matrices.LAPACK.dggev instead",
Documentation(info="<html>
<p>
This function is obsolete. Use
<a href=\"modelica://Modelica.Math.Matrices.LAPACK.dggev\">Modelica.Math.Matrices.LAPACK.dggev</a>
instead, see also below the documentation of the original routine DGEGV.
</p>
<p>
Note: there are two additional outputs in the abovementioned function
from the Modelica Standard Library: <code>lEigenVectors</code> and
<code>rEigenVectors</code>.
They must be added in a function call or resolved in another way.
</p>
<pre>
Lapack documentation:
Purpose
=======
This routine is deprecated and has been replaced by routine DGGEV.
DGEGV computes for a pair of n-by-n real nonsymmetric matrices A and
B, the generalized eigenvalues (alphar +/- alphai*i, beta), and
optionally, the left and/or right generalized eigenvectors (VL and
VR).
A generalized eigenvalue for a pair of matrices (A,B) is, roughly
speaking, a scalar w or a ratio alpha/beta = w, such that A - w*B
is singular. It is usually represented as the pair (alpha,beta),
as there is a reasonable interpretation for beta=0, and even for
both being zero. A good beginning reference is the book, \"Matrix
Computations\", by G. Golub & C. van Loan (Johns Hopkins U. Press)
A right generalized eigenvector corresponding to a generalized
eigenvalue w for a pair of matrices (A,B) is a vector r such
that (A - w B) r = 0 . A left generalized eigenvector is a vector
l such that l**H * (A - w B) = 0, where l**H is the
conjugate-transpose of l.
Note: this routine performs \"full balancing\" on A and B -- see
\"Further Details\", below.
Arguments
=========
JOBVL (input) CHARACTER*1
= 'N': do not compute the left generalized eigenvectors;
= 'V': compute the left generalized eigenvectors.
JOBVR (input) CHARACTER*1
= 'N': do not compute the right generalized eigenvectors;
= 'V': compute the right generalized eigenvectors.
N (input) INTEGER
The order of the matrices A, B, VL, and VR. N >= 0.
A (input/output) DOUBLE PRECISION array, dimension (LDA, N)
On entry, the first of the pair of matrices whose
generalized eigenvalues and (optionally) generalized
eigenvectors are to be computed.
On exit, the contents will have been destroyed. (For a
description of the contents of A on exit, see \"Further
Details\", below.)
LDA (input) INTEGER
The leading dimension of A. LDA >= max(1,N).
B (input/output) DOUBLE PRECISION array, dimension (LDB, N)
On entry, the second of the pair of matrices whose
generalized eigenvalues and (optionally) generalized
eigenvectors are to be computed.
On exit, the contents will have been destroyed. (For a
description of the contents of B on exit, see \"Further
Details\", below.)
LDB (input) INTEGER
The leading dimension of B. LDB >= max(1,N).
ALPHAR (output) DOUBLE PRECISION array, dimension (N)
ALPHAI (output) DOUBLE PRECISION array, dimension (N)
BETA (output) DOUBLE PRECISION array, dimension (N)
On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will
be the generalized eigenvalues. If ALPHAI(j) is zero, then
the j-th eigenvalue is real; if positive, then the j-th and
(j+1)-st eigenvalues are a complex conjugate pair, with
ALPHAI(j+1) negative.
Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j)
may easily over- or underflow, and BETA(j) may even be zero.
Thus, the user should avoid naively computing the ratio
alpha/beta. However, ALPHAR and ALPHAI will be always less
than and usually comparable with norm(A) in magnitude, and
BETA always less than and usually comparable with norm(B).
VL (output) DOUBLE PRECISION array, dimension (LDVL,N)
If JOBVL = 'V', the left generalized eigenvectors. (See
\"Purpose\", above.) Real eigenvectors take one column,
complex take two columns, the first for the real part and
the second for the imaginary part. Complex eigenvectors
correspond to an eigenvalue with positive imaginary part.
Each eigenvector will be scaled so the largest component
will have abs(real part) + abs(imag. part) = 1, *except*
that for eigenvalues with alpha=beta=0, a zero vector will
be returned as the corresponding eigenvector.
Not referenced if JOBVL = 'N'.
LDVL (input) INTEGER
The leading dimension of the matrix VL. LDVL >= 1, and
if JOBVL = 'V', LDVL >= N.
VR (output) DOUBLE PRECISION array, dimension (LDVR,N)
If JOBVR = 'V', the right generalized eigenvectors. (See
\"Purpose\", above.) Real eigenvectors take one column,
complex take two columns, the first for the real part and
the second for the imaginary part. Complex eigenvectors
correspond to an eigenvalue with positive imaginary part.
Each eigenvector will be scaled so the largest component
will have abs(real part) + abs(imag. part) = 1, *except*
that for eigenvalues with alpha=beta=0, a zero vector will
be returned as the corresponding eigenvector.
Not referenced if JOBVR = 'N'.
LDVR (input) INTEGER
The leading dimension of the matrix VR. LDVR >= 1, and
if JOBVR = 'V', LDVR >= N.
WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
LWORK (input) INTEGER
The dimension of the array WORK. LWORK >= max(1,8*N).
For good performance, LWORK must generally be larger.
To compute the optimal value of LWORK, call ILAENV to get
blocksizes (for DGEQRF, DORMQR, and DORGQR.) Then compute:
NB -- MAX of the blocksizes for DGEQRF, DORMQR, and DORGQR;
The optimal LWORK is:
2*N + MAX( 6*N, N*(NB+1) ).
If LWORK = -1, then a workspace query is assumed; the routine
only calculates the optimal size of the WORK array, returns
this value as the first entry of the WORK array, and no error
message related to LWORK is issued by XERBLA.
INFO (output) INTEGER
= 0: successful exit
< 0: if INFO = -i, the i-th argument had an illegal value.
= 1,...,N:
The QZ iteration failed. No eigenvectors have been
calculated, but ALPHAR(j), ALPHAI(j), and BETA(j)
should be correct for j=INFO+1,...,N.
> N: errors that usually indicate LAPACK problems:
=N+1: error return from DGGBAL
=N+2: error return from DGEQRF
=N+3: error return from DORMQR
=N+4: error return from DORGQR
=N+5: error return from DGGHRD
=N+6: error return from DHGEQZ (other than failed
iteration)
=N+7: error return from DTGEVC
=N+8: error return from DGGBAK (computing VL)
=N+9: error return from DGGBAK (computing VR)
=N+10: error return from DLASCL (various calls)
Further Details
===============
Balancing
---------
This driver calls DGGBAL to both permute and scale rows and columns
of A and B. The permutations PL and PR are chosen so that PL*A*PR
and PL*B*R will be upper triangular except for the diagonal blocks
A(i:j,i:j) and B(i:j,i:j), with i and j as close together as
possible. The diagonal scaling matrices DL and DR are chosen so
that the pair DL*PL*A*PR*DR, DL*PL*B*PR*DR have elements close to
one (except for the elements that start out zero.)
After the eigenvalues and eigenvectors of the balanced matrices
have been computed, DGGBAK transforms the eigenvectors back to what
they would have been (in perfect arithmetic) if they had not been
balanced.
Contents of A and B on Exit
-------- -- - --- - -- ----
If any eigenvectors are computed (either JOBVL='V' or JOBVR='V' or
both), then on exit the arrays A and B will contain the real Schur
form[*] of the \"balanced\" versions of A and B. If no eigenvectors
are computed, then only the diagonal blocks will be correct.
[*] See DHGEQZ, DGEGS, or read the book \"Matrix Computations\",
by Golub & van Loan, pub. by Johns Hopkins U. Press.
=====================================================================
</pre>
</html>"));
end dgegv;
function dgeqp3 "Obsolete: Computes a QR factorization with column pivoting"
input Real A[:,:];
input Integer lwork1=3*size(A, 2) + 1
"size of work array; should be optimized with Modelica_LinearSystems2.Math.Matrices.Internal.dgeqp3_workdim";
output Real Aout[size(A, 1),size(A, 2)]=A
"the upper triangle of the array contains the upper trapezoidal matrix R; the elements below the diagonal, together with the array TAU, represent the orthogonal matrix Q as a product of elementary reflectors";
output Integer jpvt[size(A, 2)] "pivoting indices";
output Real tau[min(size(A, 1), size(A, 2))]
"scalar factors of the elementary reflectors";
output Integer info;
output Real work[max(lwork1, 3*size(A, 2) + 1)];
protected
Integer m=size(A, 1);
Integer n=size(A, 2);
Integer lda=max(1, m);
Integer lwork2=if lwork1 == -1 then -1 else max(1, lwork1);
external "Fortran 77" dgeqp3(
m,
n,
Aout,
lda,
jpvt,
tau,
work,
lwork2,
info) annotation(Library = {"lapack"});
annotation (
obsolete = "Deprecated function - use Modelica.Math.Matrices.LAPACK.dgeqp3 instead",
Documentation(info="<html>
<p>
This function is obsolete. Use
<a href=\"modelica://Modelica.Math.Matrices.LAPACK.dgeqp3\">Modelica.Math.Matrices.LAPACK.dgeqp3</a>
instead.
</p>
<p>
Note: regarding the function from the Modelica Standard Library
</p>
<ul>
<li>
outputs <code>jpvt</code> and <code>tau</code> are interchanged,
</li>
<li>
output <code>work</code> is missing.
</li>
</ul>
<p>
This means a function call like
</p>
<blockquote><pre>
(Aout, jpvt, tau, info, work) :=
ObsoleteLinearSystems2.Math.LAPACK.dgeqp3(A, lwork1);
</pre></blockquote>
<p>
could be replaced with
</p>
<blockquote><pre>
(Aout, tau, jpvt, info) :=
Modelica.Math.Matrices.LAPACK.dgeqp3(A, lwork);
</pre></blockquote>
</html>"));
end dgeqp3;
function dgeqrf "Obsolete: Computes a QR factorization without pivoting"
input Real A[:,:];
input Integer lwork1=size(A, 2)
"size of work array; should be optimized with Modelica_LinearSystems2.Math.Matrices.Internal.dgeqp3_workdim";
output Real Aout[size(A, 1),size(A, 2)]=A
"the upper triangle of the array contains the upper trapezoidal matrix R; the elements below the diagonal, together with the array TAU, represent the orthogonal matrix Q as a product of elementary reflectors";
output Real tau[min(size(A, 1), size(A, 2))]
"scalar factors of the elementary reflectors";
output Integer info;
output Real work[max(lwork1, 3*size(A, 2) + 1)];
protected
Integer m=size(A, 1);
Integer n=size(A, 2);
Integer lda=max(1, m);
Integer lwork2=if lwork1 == -1 then -1 else max(1, lwork1);
external "Fortran 77" dgeqrf(
m,
n,
Aout,
lda,
tau,
work,
lwork2,
info) annotation(Library = {"lapack"});
annotation (
obsolete = "Deprecated function - use Modelica.Math.Matrices.LAPACK.dgeqrf instead",
Documentation(info="<html>
<p>
This function is obsolete. Use
<a href=\"modelica://Modelica.Math.Matrices.LAPACK.dgeqrf\">Modelica.Math.Matrices.LAPACK.dgeqrf</a>
instead.
</p>
<p>
Note: input <code>lwork1</code> is missing in the function from the Modelica
Standard Library and must be removed or resolved in another way.
</p>
</html>"));
end dgeqrf;
function dgetrs
"Obsolete: Solves a system of linear equations with the LU decomposition from dgetrf(..)"
input Real LU[:,size(LU, 1)] "LU factorization of dgetrf of a square matrix";
input Integer pivots[size(LU, 1)] "Pivot vector of dgetrf";
input Real B[size(LU, 1),:] "Right hand side matrix B";
output Real X[size(B, 1),size(B, 2)]=B "Solution matrix X";
protected
Real work[size(LU, 1),size(LU, 1)]=LU;
Integer info;
external "FORTRAN 77" dgetrs(
"N",
size(LU, 1),
size(B, 2),
work,
size(LU, 1),
pivots,
X,
size(B, 1),
info) annotation (Library="lapack");
annotation (
obsolete = "Deprecated function - use Modelica.Math.Matrices.LAPACK.dgetrs instead",
Documentation(info="<html>
<p>
This function is obsolete. Use
<a href=\"modelica://Modelica.Math.Matrices.LAPACK.dgetrs\">Modelica.Math.Matrices.LAPACK.dgetrs</a>
instead.
</p>
<p>
Note: additional output <code>info</code> exists in the function from the Modelica
Standard Library. It must be added or resolved in another way.
</p>
</html>"));
end dgetrs;
function dhseqr
"Obsolete: Compute eingenvalues of a matrix A using lapack routine DHSEQR for Hessenberg form matrix"
input Real H[:,size(H, 1)];
input Integer lwork=max(1, size(H, 1));
input Boolean eigenValuesOnly=true;
input String compz="N";
input Real Z[:,:]=H;
output Real alphaReal[size(H, 1)]
"Real part of alpha (eigenvalue=(alphaReal+i*alphaImag))";
output Real alphaImag[size(H, 1)]
"Imaginary part of alpha (eigenvalue=(alphaReal+i*alphaImag))";
output Integer info;
output Real Ho[:,:]=H;
output Real Zo[:,:]=Z;
output Real work[max({lwork, size(H, 1),1})];
protected
Integer n=size(H, 1);
String job=if eigenValuesOnly then "E" else "S";
Integer ilo=1;
Integer ihi=n;
Integer ldh=max(n, 1);
Integer lw=if lwork == -1 then -1 else max(lwork, size(H, 1));
external "Fortran 77" dhseqr(
job,
compz,
n,
ilo,
ihi,
Ho,
ldh,
alphaReal,
alphaImag,
Zo,
ldh,
work,
lw,
info) annotation(Library = {"lapack"});
annotation (
obsolete = "Deprecated function - use Modelica.Math.Matrices.LAPACK.dhseqr instead",
Documentation(info="<html>
<p>
This function is obsolete. Use
<a href=\"modelica://Modelica.Math.Matrices.LAPACK.dhseqr\">Modelica.Math.Matrices.LAPACK.dhseqr</a>
instead.
</p>
<p>
Note: input <code>lwork</code> is missing in the function from the Modelica
Standard Library and must be removed or resolved in another way.
</p>
</html>"));
end dhseqr;
annotation (Documentation(info="<html>
<p>
This package contains functions to call routines from software library
<a href=\"https://www.netlib.org/lapack/\">LAPACK </a>
(Linear Algebra PACKage) aimed for numerical linear algebra. The library is
provided by <a href=\"https://www.netlib.org/\">Netlib Repository</a>.
</p>
</html>"));
end LAPACK;
package Matrices "Package of functions operating on matrices"
extends Modelica.Icons.Package;
function printMatrix "Print matrix"
import Modelica.Utilities.Strings;
input Real M[:,:];
input Integer significantDigits=6
"Number of significant digits that are shown";
input String name="M" "Independent variable name used for printing";
output String s="";
protected
String blanks=Strings.repeat(significantDigits);
String space=Strings.repeat(8);
String space2=Strings.repeat(3);
Integer r=size(M, 1);
Integer c=size(M, 2);
algorithm
if r == 0 or c == 0 then
s := name + " = []";
else
s := "\n" + name + " = \n";
for i in 1:r loop
s := s + space;
for j in 1:c loop
if M[i, j] >= 0 then
s := s + " ";
end if;
s := s + String(M[i, j], significantDigits=significantDigits) +
Strings.repeat(significantDigits + 8 - Strings.length(String(abs(M[i,j]))));
end for;
s := s + "\n";
end for;
end if;
annotation (
obsolete = "Deprecated function - use Modelica.Math.Matrices.toString instead",
Documentation(info="<html>
<p>
This function is obsolete. Use
<a href=\"modelica://Modelica.Math.Matrices.toString\">Modelica.Math.Matrices.toString</a>
instead.
</p>
<p>
Note: the inputs two and three (<code>significantDigits</code> and <code>name</code>) are
interchanged in Modelica.Math.Matrices.toString. Consequently, a call like
</p>
<blockquote><pre>
ObsoleteLinearSystems2.Math.Matrices.printMatrix([3], 2, \"vec\");
</pre></blockquote>
<p>
shall be replaced with
</p>
<blockquote><pre>
Modelica.Math.Matrices.toString([3], \"vec\", 2);
</pre></blockquote>
</html>"));
end printMatrix;
package Internal
extends Modelica.Icons.InternalPackage;
function QR2 "QR decomposition of a square matrix with column pivoting (A(:,p) = Q*R)"
input Real A[:,:] "Rectangular matrix with size(A,1) >= size(A,2)";
output Real Q[size(A, 1),size(A, 2)]
"Rectangular matrix with orthonormal columns such that Q*R=A[:,p]";
output Real R[size(A, 2),size(A, 2)] "Square upper triangular matrix";
output Integer p[size(A, 2)] "Column permutation vector";
output Real tau[min(size(A, 1), size(A, 2))];
protected
Integer nrow=size(A, 1);
Integer ncol=size(A, 2);
Integer lwork=Internal.dgeqp3_workdim(A);
algorithm
assert(nrow >= ncol, "\nInput matrix A[" + String(nrow) + "," + String(ncol)
+ "] has more columns as rows.
This is not allowed when calling Modelica.Matrices.QR(A).");
if ncol > 0 then
(Q,tau,p) := Modelica.Math.Matrices.LAPACK.dgeqp3(A, lwork);
// determine R
R := zeros(ncol, ncol);
for i in 1:ncol loop
for j in i:ncol loop
R[i, j] := Q[i, j];
end for;
end for;
Q := Modelica.Math.Matrices.LAPACK.dorgqr(Q, tau);
else
Q := fill(
1,
size(A, 1),
0);
R := fill(
0,
0,
0);
end if;
annotation (
obsolete = "Deprecated function - use Modelica.Math.Matrices.QR instead",
Documentation(info="<html>
<p>
This function is obsolete. Use
<a href=\"modelica://Modelica.Math.Matrices.QR\">Modelica.Math.Matrices.QR</a>
instead.
</p>
<p>
Note: output <code>tau</code> is missing in the function from the Modelica
Standard Library and must be removed or resolved in another way.
</p>
</html>"));
end QR2;
function dgeqp3_workdim "Calculate the optimal size of the WORK array in dgeqp3"
input Real A[:,:];
output Integer lwork;
output Integer info;
protected
Real work[:];
algorithm
(,,,info,work) := LAPACK.dgeqp3(A, -1);
lwork := integer(work[1]);
annotation (
obsolete = "Deprecated function.",
Documentation(info="<html>
<p>
This function is deprecated without a substitute function.
</p>
</html>"));
end dgeqp3_workdim;
function dhseqr_workdim "Calculate the optimal size of the WORK array in dhseqr"
import Modelica_LinearSystems2.Math.Matrices.LAPACK;
input Real H[:,:];
output Integer lwork;
output Integer info;
protected
Real work[:];
algorithm
if min(size(H, 1), size(H, 2)) > 0 then
(,,info,,,work) := ObsoleteLinearSystems2.Math.LAPACK.dhseqr(H, -1);
lwork := integer(work[1]);
else
lwork := 1;
end if;
annotation (
obsolete = "Deprecated function - see ObsoleteLinearSystems2.Math.LAPACK.dhseqr for alternatives");
end dhseqr_workdim;
function dgeqrf_workdim "Calculate the optimal size of the WORK array in dgeqrf"
import Modelica_LinearSystems2.Math.Matrices.LAPACK;
input Real A[:,:];
output Integer lwork;
output Integer info;
protected
Real work[max(1,size(A,1))];
algorithm
(,,info,work) := ObsoleteLinearSystems2.Math.LAPACK.dgeqrf(A, -1);
lwork := integer(work[1]);
annotation (
obsolete = "Deprecated function - see ObsoleteLinearSystems2.Math.LAPACK.dgeqrf for alternatives");
end dgeqrf_workdim;
end Internal;
end Matrices;
package Vectors "Package of functions operating on vectors"
extends Modelica.Icons.Package;
function printVector "Print vector"
import Modelica.Utilities.Strings;
input Real v[:] "Vector of real numbers to be printed";
input Integer significantDigits=6
"Number of significant digits that are shown";
input String name="v" "Independent variable name used for printing";
output String s="" "String containing v";
protected
String blanks=Strings.repeat(significantDigits);
String space=Strings.repeat(8);
String space2=Strings.repeat(3);
Integer r=size(v, 1);
algorithm
if r == 0 then
s := name + " = []";
else
s := "\n" + name + " = \n";
for i in 1:r loop
s := s + space;
if v[i] >= 0 then
s := s + " ";
end if;
s := s + String(v[i], significantDigits=significantDigits) +
Strings.repeat(significantDigits + 8 - Strings.length(String(abs(v[i]))));
s := s + "\n";
end for;
end if;
annotation (
obsolete = "Deprecated function - use Modelica.Math.Vectors.toString instead",
Documentation(info="<html>
<p>
This function is obsolete. Use
<a href=\"modelica://Modelica.Math.Vectors.toString\">Modelica.Math.Vectors.toString</a>
instead.
</p>
<p>
Note: the inputs two and three (<code>significantDigits</code> and <code>name</code>) are
interchanged in Modelica.Math.Vectors.toString. Consequently, a call like
</p>
<blockquote><pre>
ObsoleteLinearSystems2.Math.Vectors.printVector({3,33,7}, 2, \"vec\");
</pre></blockquote>
<p>
shall be replaced with
</p>
<blockquote><pre>
Modelica.Math.Vectors.toString({3,33,7}, \"vec\", 2);
</pre></blockquote>
</html>"));
end printVector;
end Vectors;
end Math;
package Controller "Package of continuous and discrete input/output blocks"
extends Modelica.Icons.Package;
package Examples
extends Modelica.Icons.ExamplesPackage;
package Components
extends Modelica.Icons.UtilitiesPackage;
model DoublePendulum "crane trolley system"
extends Modelica.Icons.ObsoleteModel;
parameter Modelica.Units.SI.Mass m_trolley = 5;
parameter Modelica.Units.SI.Mass m_load = 20;
parameter Modelica.Units.SI.Length length = 2;
parameter Modelica.Units.SI.Angle phi1_start = -80.0/180*pi;
parameter Modelica.Units.SI.Angle phi2_start = 10;
parameter Modelica.Units.SI.AngularVelocity w1_start = 0.0;
parameter Modelica.Units.SI.AngularVelocity w2_start = 0.0;
constant Real pi = Modelica.Constants.pi;
inner Modelica.Mechanics.MultiBody.World world(animateWorld=false,
animateGravity=false)
annotation (Placement(transformation(extent={{-140,-80},{-120,-60}}, rotation=0)));
Modelica.Mechanics.MultiBody.Joints.Prismatic prismatic(useAxisFlange=true)
annotation (Placement(transformation(extent={{-96,0},{-76,20}})));
Modelica.Mechanics.Translational.Components.Damper damper1(d=0)
annotation (Placement(transformation(extent={{-96,14},{-76,34}})));
Modelica.Mechanics.MultiBody.Joints.Revolute rev(n={0,0,1},useAxisFlange=true,
phi(fixed=true, start=phi1_start),
w(fixed=true, start=w1_start))
annotation (Placement(transformation(extent={{-30,0},{-10,20}}, rotation=0)));
Modelica.Mechanics.Rotational.Components.Damper damper(d=0)
annotation (Placement(transformation(extent={{-22,40},{-2,60}},rotation=0)));
Modelica.Mechanics.MultiBody.Parts.Body body(
m=m_load,
r_CM={0,0,0},
specularCoefficient=4*world.defaultSpecularCoefficient,
sphereDiameter=1.5*world.defaultBodyDiameter)
annotation (Placement(transformation(extent={{78,0},{98,20}}, rotation=0)));
Modelica.Mechanics.MultiBody.Parts.BodyShape bodyShape(
shapeType="box",
m=m_trolley,
sphereDiameter=world.defaultBodyDiameter,
r={0,0,0},
r_CM={0,0,0})
annotation (Placement(transformation(extent={{-58,-2},{-38,18}})));
Modelica.Mechanics.Translational.Sources.Force force
annotation (Placement(transformation(extent={{-98,34},{-78,54}})));
Modelica.Mechanics.MultiBody.Sensors.RelativeAngles relativeAngles
annotation (Placement(transformation(extent={{-30,-30},{-10,-10}})));
Modelica.Mechanics.MultiBody.Sensors.RelativeVelocity relativeVelocity
annotation (Placement(transformation(extent={{-96,-30},{-76,-10}})));
Modelica.Mechanics.MultiBody.Sensors.RelativePosition relativePosition
annotation (Placement(transformation(extent={{-96,-60},{-76,-40}})));
Modelica.Blocks.Interfaces.RealInput u
annotation (Placement(transformation(extent={{-190,-20},{-150,20}})));
Modelica.Blocks.Interfaces.RealOutput s
annotation (Placement(transformation(extent={{150,90},{170,110}})));
Modelica.Blocks.Interfaces.RealOutput v
annotation (Placement(transformation(extent={{150,50},{170,70}})));
Modelica.Blocks.Interfaces.RealOutput phi
annotation (Placement(transformation(extent={{150,10},{170,30}})));
Modelica.Blocks.Interfaces.RealOutput w
annotation (Placement(transformation(extent={{150,-30},{170,-10}})));
Modelica.Mechanics.MultiBody.Sensors.RelativeAngularVelocity
relativeAngularVelocity
annotation (Placement(transformation(extent={{-30,-60},{-10,-40}})));
Modelica.Blocks.Sources.Constant const(k=0.5*Modelica.Constants.pi)
annotation (Placement(transformation(extent={{94,-22},{106,-10}})));
Modelica.Blocks.Math.Add add
annotation (Placement(transformation(extent={{116,-10},{136,10}})));
Modelica.Mechanics.MultiBody.Joints.Revolute revolute2(
phi(fixed=true, start=phi2_start),
w(fixed=true, start=w2_start),
cylinderDiameter=3*world.defaultJointWidth,
cylinderColor={0,0,200}) annotation (Placement(transformation(extent={{24,0},{
44,20}}, rotation=0)));
Modelica.Mechanics.MultiBody.Sensors.RelativeAngles relativeAngles1
annotation (Placement(transformation(extent={{24,-30},{44,-10}})));
Modelica.Mechanics.MultiBody.Sensors.RelativeAngularVelocity
relativeAngularVelocity1
annotation (Placement(transformation(extent={{24,-60},{44,-40}})));
Modelica.Blocks.Interfaces.RealOutput phi1
annotation (Placement(transformation(extent={{150,-70},{170,-50}})));
Modelica.Blocks.Interfaces.RealOutput w1
annotation (Placement(transformation(extent={{150,-110},{170,-90}})));
Modelica.Blocks.Math.Add add1
annotation (Placement(transformation(extent={{88,-50},{108,-30}})));
Modelica.Blocks.Sources.Constant const1(k=0)
annotation (Placement(transformation(extent={{66,-62},{78,-50}})));
Modelica.Mechanics.MultiBody.Parts.BodyCylinder bodyCylinder(
r={length/2,0,0},
specularCoefficient=0.7,
color={0,0,0},
diameter=0.05,
density=900)
annotation (Placement(transformation(extent={{-4,0},{16,20}})));
Modelica.Mechanics.MultiBody.Parts.BodyCylinder bodyCylinder1(
r={length/2,0,0},
specularCoefficient=0.7,
color={0,0,0},
diameter=0.05,
density=900)
annotation (Placement(transformation(extent={{52,0},{72,20}})));
equation
connect(damper.flange_b, rev.axis) annotation (Line(points={{-2,50},{0,50},{0,
24},{0,20},{-20,20}}, color={0,0,0}));
connect(rev.support, damper.flange_a) annotation (Line(points={{-26,20},{-26,
26},{-36,26},{-36,50},{-22,50}}, color={0,0,0}));
connect(bodyShape.frame_b, rev.frame_a) annotation (Line(
points={{-38,8},{-34,8},{-34,10},{-30,10}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(prismatic.frame_a, world.frame_b) annotation (Line(
points={{-96,10},{-110,10},{-110,-70},{-120,-70}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(force.flange, prismatic.axis) annotation (Line(
points={{-78,44},{-78,16}},
color={0,127,0},
smooth=Smooth.None));
connect(damper1.flange_a, prismatic.support) annotation (Line(
points={{-96,24},{-96,16},{-90,16}},
color={0,127,0},
smooth=Smooth.None));
connect(damper1.flange_b, prismatic.axis) annotation (Line(
points={{-76,24},{-78,24},{-78,16}},
color={0,127,0},
smooth=Smooth.None));
connect(prismatic.frame_b, bodyShape.frame_a) annotation (Line(
points={{-76,10},{-68,10},{-68,8},{-58,8}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(relativeVelocity.frame_b, prismatic.frame_b) annotation (Line(
points={{-76,-20},{-76,10}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(relativeVelocity.frame_a, prismatic.frame_a) annotation (Line(
points={{-96,-20},{-96,10}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(relativePosition.frame_b, relativeVelocity.frame_b) annotation (Line(
points={{-76,-50},{-76,-20}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(relativePosition.frame_a, relativeVelocity.frame_a) annotation (Line(
points={{-96,-50},{-96,-20}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(relativeAngles.frame_b, rev.frame_b) annotation (Line(
points={{-10,-20},{-10,10}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(relativeAngles.frame_a, rev.frame_a) annotation (Line(
points={{-30,-20},{-30,10}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(u, force.f) annotation (Line(
points={{-170,0},{-136,0},{-136,44},{-100,44}},
color={0,0,127},
smooth=Smooth.None));
connect(relativeAngularVelocity.frame_a, relativeAngles.frame_a) annotation (
Line(
points={{-30,-50},{-30,-20}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(relativeAngularVelocity.frame_b, relativeAngles.frame_b) annotation (
Line(
points={{-10,-50},{-10,-20}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(relativeAngularVelocity.w_rel[3], w) annotation (Line(
points={{-20,-60.6667},{-20,-66},{120,-66},{120,-20},{160,-20}},
color={0,0,127},
smooth=Smooth.None));
connect(relativeVelocity.v_rel[1], v) annotation (Line(
points={{-86,-31.3333},{-104,-31.3333},{-104,-32},{-118,-32},{-118,62},{42,62},{42,60},{160,60}},
color={0,0,127},
smooth=Smooth.None));
connect(relativePosition.r_rel[1], s) annotation (Line(
points={{-86,-61.3333},{-104,-61.3333},{-104,-58},{-120,-58},{-120,100},{160,100}},
color={0,0,127},
smooth=Smooth.None));
connect(phi, phi) annotation (Line(