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