LAPACK 3.12.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cgedmdq.f90
Go to the documentation of this file.
1
2!
3! =========== DOCUMENTATION ===========
4!
5! Definition:
6! ===========
7!
8! SUBROUTINE CGEDMDQ( JOBS, JOBZ, JOBR, JOBQ, JOBT, JOBF, &
9! WHTSVD, M, N, F, LDF, X, LDX, Y, &
10! LDY, NRNK, TOL, K, EIGS, &
11! Z, LDZ, RES, B, LDB, V, LDV, &
12! S, LDS, ZWORK, LZWORK, WORK, LWORK, &
13! IWORK, LIWORK, INFO )
14!.....
15! USE iso_fortran_env
16! IMPLICIT NONE
17! INTEGER, PARAMETER :: WP = real32
18!.....
19! Scalar arguments
20! CHARACTER, INTENT(IN) :: JOBS, JOBZ, JOBR, JOBQ, &
21! JOBT, JOBF
22! INTEGER, INTENT(IN) :: WHTSVD, M, N, LDF, LDX, &
23! LDY, NRNK, LDZ, LDB, LDV, &
24! LDS, LZWORK, LWORK, LIWORK
25! INTEGER, INTENT(OUT) :: INFO, K
26! REAL(KIND=WP), INTENT(IN) :: TOL
27! Array arguments
28! COMPLEX(KIND=WP), INTENT(INOUT) :: F(LDF,*)
29! COMPLEX(KIND=WP), INTENT(OUT) :: X(LDX,*), Y(LDY,*), &
30! Z(LDZ,*), B(LDB,*), &
31! V(LDV,*), S(LDS,*)
32! COMPLEX(KIND=WP), INTENT(OUT) :: EIGS(*)
33! COMPLEX(KIND=WP), INTENT(OUT) :: ZWORK(*)
34! REAL(KIND=WP), INTENT(OUT) :: RES(*)
35! REAL(KIND=WP), INTENT(OUT) :: WORK(*)
36! INTEGER, INTENT(OUT) :: IWORK(*)
37!
38!............................................................
40! =============
56!............................................................
58! ================
74!......................................................................
76! ================================
96!......................................................................
98! ================================
103!......................................................................
104! Arguments
105! =========
106!
127!.....
149!.....
160!.....
171!.....
182!.....
197!.....
221!.....
227!.....
235!.....
255!.....
261!.....
275!.....
281!.....
293!.....
299!.....
324!.....
331!.....
341!.....
349!.....
366!.....
372!.....
381!.....
398!.....
404!.....
414!.....
420!.....
429!.....
435!.....
449!.....
470!.....
483!.....
496!.....
506!.....
521!.....
542!
543! Authors:
544! ========
545!
547!
549!
550!.............................................................
551!.............................................................
552SUBROUTINE cgedmdq( JOBS, JOBZ, JOBR, JOBQ, JOBT, JOBF, &
553 WHTSVD, M, N, F, LDF, X, LDX, Y, &
554 LDY, NRNK, TOL, K, EIGS, &
555 Z, LDZ, RES, B, LDB, V, LDV, &
556 S, LDS, ZWORK, LZWORK, WORK, LWORK, &
557 IWORK, LIWORK, INFO )
558!
559! -- LAPACK driver routine --
560!
561! -- LAPACK is a software package provided by University of --
562! -- Tennessee, University of California Berkeley, University of --
563! -- Colorado Denver and NAG Ltd.. --
564!
565!.....
566 USE iso_fortran_env
567 IMPLICIT NONE
568 INTEGER, PARAMETER :: WP = real32
569!
570! Scalar arguments
571! ~~~~~~~~~~~~~~~~
572 CHARACTER, INTENT(IN) :: JOBS, JOBZ, JOBR, JOBQ, &
573 JOBT, JOBF
574 INTEGER, INTENT(IN) :: WHTSVD, M, N, LDF, LDX, &
575 LDY, NRNK, LDZ, LDB, LDV, &
576 LDS, LZWORK, LWORK, LIWORK
577 INTEGER, INTENT(OUT) :: INFO, K
578 REAL(KIND=wp), INTENT(IN) :: tol
579!
580! Array arguments
581! ~~~~~~~~~~~~~~~
582 COMPLEX(KIND=WP), INTENT(INOUT) :: F(LDF,*)
583 COMPLEX(KIND=WP), INTENT(OUT) :: X(LDX,*), Y(LDY,*), &
584 Z(LDZ,*), B(LDB,*), &
585 V(LDV,*), S(LDS,*)
586 COMPLEX(KIND=WP), INTENT(OUT) :: EIGS(*)
587 COMPLEX(KIND=WP), INTENT(OUT) :: ZWORK(*)
588 REAL(KIND=wp), INTENT(OUT) :: res(*)
589 REAL(KIND=wp), INTENT(OUT) :: work(*)
590 INTEGER, INTENT(OUT) :: IWORK(*)
591!
592! Parameters
593! ~~~~~~~~~~
594 REAL(KIND=wp), PARAMETER :: one = 1.0_wp
595 REAL(KIND=wp), PARAMETER :: zero = 0.0_wp
596! COMPLEX(KIND=WP), PARAMETER :: ZONE = ( 1.0_WP, 0.0_WP )
597 COMPLEX(KIND=WP), PARAMETER :: ZZERO = ( 0.0_wp, 0.0_wp )
598!
599! Local scalars
600! ~~~~~~~~~~~~~
601 INTEGER :: IMINWR, INFO1, MINMN, MLRWRK, &
602 MLWDMD, MLWGQR, MLWMQR, MLWORK, &
603 MLWQR, OLWDMD, OLWGQR, OLWMQR, &
604 OLWORK, OLWQR
605 LOGICAL :: LQUERY, SCCOLX, SCCOLY, WANTQ, &
606 WNTTRF, WNTRES, WNTVEC, WNTVCF, &
607 WNTVCQ, WNTREF, WNTEX
608 CHARACTER(LEN=1) :: JOBVL
609!
610! External functions (BLAS and LAPACK)
611! ~~~~~~~~~~~~~~~~~
612 LOGICAL LSAME
613 EXTERNAL lsame
614!
615! External subroutines (BLAS and LAPACK)
616! ~~~~~~~~~~~~~~~~~~~~
617 EXTERNAL cgedmd, cgeqrf, clacpy, claset, cungqr, &
619!
620! Intrinsic functions
621! ~~~~~~~~~~~~~~~~~~~
622 INTRINSIC max, min, int
623!..........................................................
624!
625! Test the input arguments
626 wntres = lsame(jobr,'R')
627 sccolx = lsame(jobs,'S') .OR. lsame( jobs, 'C' )
628 sccoly = lsame(jobs,'Y')
629 wntvec = lsame(jobz,'V')
630 wntvcf = lsame(jobz,'F')
631 wntvcq = lsame(jobz,'Q')
632 wntref = lsame(jobf,'R')
633 wntex = lsame(jobf,'E')
634 wantq = lsame(jobq,'Q')
635 wnttrf = lsame(jobt,'R')
636 minmn = min(m,n)
637 info = 0
638 lquery = ( ( lwork == -1 ) .OR. ( liwork == -1 ) )
639!
640 IF ( .NOT. (sccolx .OR. sccoly .OR. &
641 lsame(jobs,'N')) ) THEN
642 info = -1
643 ELSE IF ( .NOT. (wntvec .OR. wntvcf .OR. wntvcq &
644 .OR. lsame(jobz,'N')) ) THEN
645 info = -2
646 ELSE IF ( .NOT. (wntres .OR. lsame(jobr,'N')) .OR. &
647 ( wntres .AND. lsame(jobz,'N') ) ) THEN
648 info = -3
649 ELSE IF ( .NOT. (wantq .OR. lsame(jobq,'N')) ) THEN
650 info = -4
651 ELSE IF ( .NOT. ( wnttrf .OR. lsame(jobt,'N') ) ) THEN
652 info = -5
653 ELSE IF ( .NOT. (wntref .OR. wntex .OR. &
654 lsame(jobf,'N') ) ) THEN
655 info = -6
656 ELSE IF ( .NOT. ((whtsvd == 1).OR.(whtsvd == 2).OR. &
657 (whtsvd == 3).OR.(whtsvd == 4)) ) THEN
658 info = -7
659 ELSE IF ( m < 0 ) THEN
660 info = -8
661 ELSE IF ( ( n < 0 ) .OR. ( n > m+1 ) ) THEN
662 info = -9
663 ELSE IF ( ldf < m ) THEN
664 info = -11
665 ELSE IF ( ldx < minmn ) THEN
666 info = -13
667 ELSE IF ( ldy < minmn ) THEN
668 info = -15
669 ELSE IF ( .NOT. (( nrnk == -2).OR.(nrnk == -1).OR. &
670 ((nrnk >= 1).AND.(nrnk <=n ))) ) THEN
671 info = -16
672 ELSE IF ( ( tol < zero ) .OR. ( tol >= one ) ) THEN
673 info = -17
674 ELSE IF ( ldz < m ) THEN
675 info = -21
676 ELSE IF ( (wntref.OR.wntex ).AND.( ldb < minmn ) ) THEN
677 info = -24
678 ELSE IF ( ldv < n-1 ) THEN
679 info = -26
680 ELSE IF ( lds < n-1 ) THEN
681 info = -28
682 END IF
683!
684 IF ( wntvec .OR. wntvcf .OR. wntvcq ) THEN
685 jobvl = 'V'
686 ELSE
687 jobvl = 'N'
688 END IF
689 IF ( info == 0 ) THEN
690 ! Compute the minimal and the optimal workspace
691 ! requirements. Simulate running the code and
692 ! determine minimal and optimal sizes of the
693 ! workspace at any moment of the run.
694 IF ( ( n == 0 ) .OR. ( n == 1 ) ) THEN
695 ! All output except K is void. INFO=1 signals
696 ! the void input. In case of a workspace query,
697 ! the minimal workspace lengths are returned.
698 IF ( lquery ) THEN
699 iwork(1) = 1
700 work(1) = 2
701 work(2) = 2
702 ELSE
703 k = 0
704 END IF
705 info = 1
706 RETURN
707 END IF
708
709 mlrwrk = 2
710 mlwork = 2
711 olwork = 2
712 iminwr = 1
713 mlwqr = max(1,n) ! Minimal workspace length for CGEQRF.
714 mlwork = max(mlwork,minmn + mlwqr)
715
716 IF ( lquery ) THEN
717 CALL cgeqrf( m, n, f, ldf, zwork, zwork, -1, &
718 info1 )
719 olwqr = int(zwork(1))
720 olwork = max(olwork,minmn + olwqr)
721 END IF
722 CALL cgedmd( jobs, jobvl, jobr, jobf, whtsvd, minmn,&
723 n-1, x, ldx, y, ldy, nrnk, tol, k, &
724 eigs, z, ldz, res, b, ldb, v, ldv, &
725 s, lds, zwork, lzwork, work, -1, iwork,&
726 liwork, info1 )
727 mlwdmd = int(zwork(1))
728 mlwork = max(mlwork, minmn + mlwdmd)
729 mlrwrk = max(mlrwrk, int(work(1)))
730 iminwr = max(iminwr, iwork(1))
731 IF ( lquery ) THEN
732 olwdmd = int(zwork(2))
733 olwork = max(olwork, minmn+olwdmd)
734 END IF
735 IF ( wntvec .OR. wntvcf ) THEN
736 mlwmqr = max(1,n)
737 mlwork = max(mlwork, minmn+mlwmqr)
738 IF ( lquery ) THEN
739 CALL cunmqr( 'L','N', m, n, minmn, f, ldf, &
740 zwork, z, ldz, zwork, -1, info1 )
741 olwmqr = int(zwork(1))
742 olwork = max(olwork, minmn+olwmqr)
743 END IF
744 END IF
745 IF ( wantq ) THEN
746 mlwgqr = max(1,n)
747 mlwork = max(mlwork, minmn+mlwgqr)
748 IF ( lquery ) THEN
749 CALL cungqr( m, minmn, minmn, f, ldf, zwork, &
750 zwork, -1, info1 )
751 olwgqr = int(zwork(1))
752 olwork = max(olwork, minmn+olwgqr)
753 END IF
754 END IF
755 IF ( liwork < iminwr .AND. (.NOT.lquery) ) info = -34
756 IF ( lwork < mlrwrk .AND. (.NOT.lquery) ) info = -32
757 IF ( lzwork < mlwork .AND. (.NOT.lquery) ) info = -30
758 END IF
759 IF( info /= 0 ) THEN
760 CALL xerbla( 'CGEDMDQ', -info )
761 RETURN
762 ELSE IF ( lquery ) THEN
763! Return minimal and optimal workspace sizes
764 iwork(1) = iminwr
765 zwork(1) = mlwork
766 zwork(2) = olwork
767 work(1) = mlrwrk
768 work(2) = mlrwrk
769 RETURN
770 END IF
771!.....
772! Initial QR factorization that is used to represent the
773! snapshots as elements of lower dimensional subspace.
774! For large scale computation with M >>N , at this place
775! one can use an out of core QRF.
776!
777 CALL cgeqrf( m, n, f, ldf, zwork, &
778 zwork(minmn+1), lzwork-minmn, info1 )
779!
780! Define X and Y as the snapshots representations in the
781! orthogonal basis computed in the QR factorization.
782! X corresponds to the leading N-1 and Y to the trailing
783! N-1 snapshots.
784 CALL claset( 'L', minmn, n-1, zzero, zzero, x, ldx )
785 CALL clacpy( 'U', minmn, n-1, f, ldf, x, ldx )
786 CALL clacpy( 'A', minmn, n-1, f(1,2), ldf, y, ldy )
787 IF ( m >= 3 ) THEN
788 CALL claset( 'L', minmn-2, n-2, zzero, zzero, &
789 y(3,1), ldy )
790 END IF
791!
792! Compute the DMD of the projected snapshot pairs (X,Y)
793 CALL cgedmd( jobs, jobvl, jobr, jobf, whtsvd, minmn, &
794 n-1, x, ldx, y, ldy, nrnk, tol, k, &
795 eigs, z, ldz, res, b, ldb, v, ldv, &
796 s, lds, zwork(minmn+1), lzwork-minmn, &
797 work, lwork, iwork, liwork, info1 )
798 IF ( info1 == 2 .OR. info1 == 3 ) THEN
799 ! Return with error code. See CGEDMD for details.
800 info = info1
801 RETURN
802 ELSE
803 info = info1
804 END IF
805!
806! The Ritz vectors (Koopman modes) can be explicitly
807! formed or returned in factored form.
808 IF ( wntvec ) THEN
809 ! Compute the eigenvectors explicitly.
810 IF ( m > minmn ) CALL claset( 'A', m-minmn, k, zzero, &
811 zzero, z(minmn+1,1), ldz )
812 CALL cunmqr( 'L','N', m, k, minmn, f, ldf, zwork, z, &
813 ldz, zwork(minmn+1), lzwork-minmn, info1 )
814 ELSE IF ( wntvcf ) THEN
815 ! Return the Ritz vectors (eigenvectors) in factored
816 ! form Z*V, where Z contains orthonormal matrix (the
817 ! product of Q from the initial QR factorization and
818 ! the SVD/POD_basis returned by CGEDMD in X) and the
819 ! second factor (the eigenvectors of the Rayleigh
820 ! quotient) is in the array V, as returned by CGEDMD.
821 CALL clacpy( 'A', n, k, x, ldx, z, ldz )
822 IF ( m > n ) CALL claset( 'A', m-n, k, zzero, zzero, &
823 z(n+1,1), ldz )
824 CALL cunmqr( 'L','N', m, k, minmn, f, ldf, zwork, z, &
825 ldz, zwork(minmn+1), lzwork-minmn, info1 )
826 END IF
827!
828! Some optional output variables:
829!
830! The upper triangular factor R in the initial QR
831! factorization is optionally returned in the array Y.
832! This is useful if this call to CGEDMDQ is to be
833
834! followed by a streaming DMD that is implemented in a
835! QR compressed form.
836 IF ( wnttrf ) THEN ! Return the upper triangular R in Y
837 CALL claset( 'A', minmn, n, zzero, zzero, y, ldy )
838 CALL clacpy( 'U', minmn, n, f, ldf, y, ldy )
839 END IF
840!
841! The orthonormal/unitary factor Q in the initial QR
842! factorization is optionally returned in the array F.
843! Same as with the triangular factor above, this is
844! useful in a streaming DMD.
845 IF ( wantq ) THEN ! Q overwrites F
846 CALL cungqr( m, minmn, minmn, f, ldf, zwork, &
847 zwork(minmn+1), lzwork-minmn, info1 )
848 END IF
849!
850 RETURN
851!
852 END SUBROUTINE cgedmdq
853
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine cgedmdq(jobs, jobz, jobr, jobq, jobt, jobf, whtsvd, m, n, f, ldf, x, ldx, y, ldy, nrnk, tol, k, eigs, z, ldz, res, b, ldb, v, ldv, s, lds, zwork, lzwork, work, lwork, iwork, liwork, info)
CGEDMDQ computes the Dynamic Mode Decomposition (DMD) for a pair of data snapshot matrices.
Definition cgedmdq.f90:558
subroutine cgedmd(jobs, jobz, jobr, jobf, whtsvd, m, n, x, ldx, y, ldy, nrnk, tol, k, eigs, z, ldz, res, b, ldb, w, ldw, s, lds, zwork, lzwork, rwork, lrwork, iwork, liwork, info)
CGEDMD computes the Dynamic Mode Decomposition (DMD) for a pair of data snapshot matrices.
Definition cgedmd.f90:501
subroutine cgeqrf(m, n, a, lda, tau, work, lwork, info)
CGEQRF
Definition cgeqrf.f:146
subroutine clacpy(uplo, m, n, a, lda, b, ldb)
CLACPY copies all or part of one two-dimensional array to another.
Definition clacpy.f:103
subroutine claset(uplo, m, n, alpha, beta, a, lda)
CLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
Definition claset.f:106
subroutine cungqr(m, n, k, a, lda, tau, work, lwork, info)
CUNGQR
Definition cungqr.f:128
subroutine cunmqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMQR
Definition cunmqr.f:168