repo_name
stringlengths
7
81
path
stringlengths
4
224
copies
stringclasses
221 values
size
stringlengths
4
7
content
stringlengths
975
1.04M
license
stringclasses
15 values
QEF/q-e
PP/src/punch_plot.f90
2
11211
! ! Copyright (C) 2001-2009 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !----------------------------------------------------------------------- SUBROUTINE punch_plot (filplot, plot_num, sample_bias, z, dz, & emin, emax, kpoint, kband, spin_component, lsign) !----------------------------------------------------------------------- ! ! This subroutine writes on output several quantities ! in a real space 3D mesh for subsequent processing or plotting ! The integer variable plot_num is used to choose the output quantity ! See file Doc/INPUT_PP.* for a description of plotted quantities ! ! The output quantity is written (formatted) on file filplot. ! USE kinds, ONLY : DP USE constants, ONLY : rytoev USE cell_base, ONLY : at, bg, omega, alat, celldm, ibrav USE ions_base, ONLY : nat, ntyp => nsp, ityp, tau, zv, atm USE run_info, ONLY : title USE extfield, ONLY : tefield, dipfield USE fft_base, ONLY : dfftp USE scatter_mod, ONLY : gather_grid USE fft_interfaces, ONLY : fwfft, invfft USE gvect, ONLY : gcutm USE gvecs, ONLY : dual USE klist, ONLY : nks, nkstot, xk USE lsda_mod, ONLY : nspin, lsda USE ener, ONLY : ehart USE io_global, ONLY : stdout, ionode USE scf, ONLY : rho, vltot, v USE wvfct, ONLY : nbnd, wg USE gvecw, ONLY : ecutwfc USE noncollin_module, ONLY : noncolin USE adduscore, ONLY : US_make_ae_charge USE paw_postproc, ONLY : PAW_make_ae_charge IMPLICIT NONE CHARACTER(len=*), INTENT(IN) :: filplot INTEGER, INTENT(IN) :: plot_num, kpoint, kband, spin_component LOGICAL, INTENT(IN) :: lsign REAL(DP), INTENT(IN) :: sample_bias, z, dz, & emin, emax REAL(DP) :: dummy, charge INTEGER :: is, ipol, istates #if defined(__MPI) ! auxiliary vector (parallel case) REAL(DP), ALLOCATABLE :: raux1 (:) #endif ! auxiliary vector REAL(DP), ALLOCATABLE :: raux (:), raux2(:,:) IF (filplot == ' ') RETURN #if defined(__MPI) ALLOCATE (raux1( dfftp%nr1x * dfftp%nr2x * dfftp%nr3x)) #endif WRITE( stdout, '(/5x,"Calling punch_plot, plot_num = ",i3)') plot_num IF (plot_num == 3 ) & WRITE(stdout, '(/5x,"Energy =", f10.5, " eV, broadening =", f10.5, "eV" )') & emin * rytoev, emax * rytoev IF (plot_num == 7) & WRITE( stdout, '(/5x,"Plotting k_point = ",i3," band =", i3 )') & kpoint, kband IF ((plot_num == 7) .and. noncolin .and. spin_component /= 0 ) & WRITE( stdout, '(/5x,"Plotting spin magnetization ipol = ",i3)') & spin_component ! ALLOCATE (raux(dfftp%nnr)) !IF ! Here we decide which quantity to plot ! IF (plot_num == 0) THEN ! ! plot of the charge density - total rho ! raux(:) = rho%of_r(:,1) ! ! plot of the charge density - up and down rho ! IF ( lsda ) THEN IF ( spin_component == 1 ) THEN raux(:) = (raux(:) + rho%of_r(:,nspin))/2.0_dp ELSE IF ( spin_component == 2 ) THEN raux(:) = (raux(:) - rho%of_r(:,nspin))/2.0_dp END IF ENDIF ! ELSEIF (plot_num == 1) THEN ! ! The total self-consistent potential V_loc+V_H+V_xc ! IF ( lsda ) THEN IF ( spin_component == 0 ) THEN raux(:) = (v%of_r(:,1) + v%of_r(:,2))/2.0_dp + vltot(:) ELSE raux(:) = v%of_r(:,spin_component) + vltot(:) END IF ELSE raux(:) = v%of_r(:,1) + vltot(:) END IF ! ELSEIF (plot_num == 2) THEN ! ! The local pseudopotential on output ! raux(:) = vltot(:) ! ELSEIF (plot_num == 3) THEN ! ! The local density of states at emin, with broadening emax ! WRITE (title, '(" Energy = ",f8.4," eV, ", "broadening = ",f8.4," eV")') & emin * rytoev, emax * rytoev IF (noncolin) CALL errore('punch_plot','not implemented yet',1) CALL local_dos(1, lsign, kpoint, kband, spin_component, emin, emax, raux) ELSEIF (plot_num == 4) THEN ! ! The local density of electronic entropy on output ! IF (noncolin) CALL errore('punch_plot','not implemented yet',1) CALL local_dos (2, lsign, kpoint, kband, spin_component, emin, emax, raux) ELSEIF (plot_num == 5) THEN IF (noncolin) CALL errore('punch_plot','not implemented yet',1) #if defined(__MPI) CALL stm (sample_bias, raux1, istates) #else CALL stm (sample_bias, raux, istates) #endif WRITE (title, '(" Bias in eV = ",f10.4," # states",i4)') & sample_bias * rytoev, istates ELSEIF (plot_num == 6) THEN ! ! plot of the spin polarisation ! IF ( lsda ) THEN raux(:) = rho%of_r (:,nspin) ELSE raux(:) = 0.d0 ENDIF ELSEIF (plot_num == 7) THEN WRITE (title, '("k_point ",i4,", band ",i4)') kpoint ,kband IF (noncolin) THEN IF (spin_component==0) THEN CALL local_dos (0, lsign, kpoint, kband, spin_component, emin, emax, raux) ELSE CALL local_dos_mag (spin_component, kpoint, kband, raux) ENDIF ELSE CALL local_dos (0, lsign, kpoint, kband, spin_component, emin, emax, raux) ENDIF ELSEIF (plot_num == 8) THEN IF (noncolin) & CALL errore('punch_plot','elf+noncolin not yet implemented',1) CALL do_elf (raux) ELSEIF (plot_num == 9) THEN ! ! plot of the charge density minus the atomic rho ! allocate (raux2(dfftp%nnr,nspin)) raux2 = 0.d0 call atomic_rho(raux2, nspin) rho%of_r(:,:) = rho%of_r(:,:) - raux2(:,:) deallocate (raux2) raux(:) = rho%of_r(:,1) ! total rho IF ( lsda ) THEN IF ( spin_component == 1 ) THEN raux(:) = (raux(:) + rho%of_r(:,nspin))/2.0_dp ELSE IF ( spin_component == 2 ) THEN raux(:) = (raux(:) - rho%of_r(:,nspin))/2.0_dp END IF ENDIF ELSEIF (plot_num == 10) THEN CALL local_dos (3, lsign, kpoint, kband, spin_component, emin, emax, raux) ELSEIF (plot_num == 11) THEN ALLOCATE( raux2(dfftp%nnr,nspin) ) raux2(:,1) = vltot(:) CALL v_h( rho%of_g(:,1), ehart, charge, raux2 ) raux(:) = raux2(:,1) IF (tefield.and.dipfield) CALL add_efield(raux, dummy, rho%of_r(:,1),.true.) DEALLOCATE( raux2 ) ELSEIF (plot_num == 12) THEN raux=0.d0 IF (tefield) THEN CALL add_efield(raux,dummy,rho%of_r(:,1),.true.) ELSE CALL infomsg ('punch_plot','e_field is not calculated') ENDIF ELSEIF (plot_num == 13) THEN IF (noncolin) THEN IF (spin_component==0) THEN raux(:) = sqrt(rho%of_r(:,2)**2 + rho%of_r(:,3)**2 + rho%of_r(:,4)**2 ) ELSEIF (spin_component >= 1 .or. spin_component <=3) THEN raux(:) = rho%of_r(:,spin_component+1) ELSE CALL errore('punch_plot','spin_component not allowed',2) ENDIF ELSE CALL errore('punch_plot','noncollinear spin required',1) ENDIF ELSEIF (plot_num == 14 .or. plot_num == 15 .or. plot_num == 16 ) THEN CALL errore('punch_plot','polarization no longer implemented',1) ! ipol = plot_num - 13 ! CALL polarization ( spin_component, ipol, epsilon, raux ) ELSEIF (plot_num == 17 .or. plot_num == 21) THEN WRITE(stdout, '(7x,a)') "Reconstructing all-electron valence charge." ! code partially duplicate from plot_num=0, should be unified ! CALL PAW_make_ae_charge(rho,(plot_num==21)) ! raux(:) = rho%of_r(:, 1) IF ( lsda ) THEN IF ( spin_component==1 ) THEN raux(:) = ( raux(:) + rho%of_r(:,nspin) )/2.0_dp ELSE IF ( spin_component==2 ) THEN raux(:) = ( raux(:) - rho%of_r(:,nspin) )/2.0_dp ENDIF END IF ! ELSEIF (plot_num == 18) THEN IF (noncolin) THEN IF (spin_component==0) THEN raux(:) = sqrt(v%of_r(:,2)**2 + v%of_r(:,3)**2 + v%of_r(:,4)**2 ) ELSEIF (spin_component >= 1 .or. spin_component <=3) THEN raux(:) = v%of_r(:,spin_component+1) ELSE CALL errore('punch_plot','spin_component not allowed',4) ENDIF ELSE CALL errore('punch_plot','B_xc available only when noncolin=.true.',1) ENDIF ELSEIF (plot_num == 19) THEN ! ! Reduced density gradient ! IF (noncolin) CALL errore('punch_plot','rdg+noncolin not yet implemented',1) CALL do_rdg (raux) ! in elf.f90 ELSEIF (plot_num == 20) THEN ! ! Density * second eigenvalue of Hessian of density (for coloring RDG plots) ! IF (noncolin) CALL errore('punch_plot','rdg+noncolin not yet implemented',1) CALL do_sl2rho (raux) ! in elf.f90 ELSEIF (plot_num == 22) THEN ! ! plot of the kinetic energy density ! IF ( lsda ) THEN IF (spin_component == 0) THEN raux(:) = rho%kin_r(:,1)+rho%kin_r(:,2) ELSE raux(:) = rho%kin_r(:, spin_component) ENDIF ELSE raux(:) = rho%kin_r(:,1) ENDIF ELSEIF (plot_num == 23) THEN ! ! plot of the charge density of states between emin & emax ! WRITE (title, '("Density for spins between",f8.4, " eV and ",f8.4," eV")') emin*rytoev, emax*rytoev CALL local_dos (4, lsign, kpoint, kband, spin_component, emin, emax, raux) ELSEIF (plot_num == 24) THEN WRITE(stdout, '(7x,a)') "Reconstructing all-electron charge." ! code partially duplicate from plot_num=21 (so 0) CALL US_make_ae_charge(rho) raux(:) = rho%of_r(:, 1) IF ( lsda ) THEN IF ( spin_component==1 ) THEN raux(:) = ( raux(:) + rho%of_r(:,nspin) )/2.0_dp ELSE IF ( spin_component==2 ) THEN raux(:) = ( raux(:) - rho%of_r(:,nspin) )/2.0_dp ENDIF ENDIF ! ELSEIF (plot_num == 123) THEN ! ! Density Overlap Regions Indicator ! IF (noncolin) CALL errore('punch_plot','dori+noncolin not yet implemented',1) CALL do_dori (raux) ! in elf.f90 ELSE CALL infomsg ('punch_plot', 'plot_num not implemented') ENDIF #if defined(__MPI) IF (.not. (plot_num == 5 ) ) CALL gather_grid (dfftp, raux, raux1) IF ( ionode ) & CALL plot_io (filplot, title, dfftp%nr1x, dfftp%nr2x, dfftp%nr3x, & dfftp%nr1, dfftp%nr2, dfftp%nr3, nat, ntyp, ibrav, celldm, at, & gcutm, dual, ecutwfc, plot_num, atm, ityp, zv, tau, raux1, + 1) DEALLOCATE (raux1) #else CALL plot_io (filplot, title, dfftp%nr1x, dfftp%nr2x, dfftp%nr3x, & dfftp%nr1, dfftp%nr2, dfftp%nr3, nat, ntyp, ibrav, celldm, at,& gcutm, dual, ecutwfc, plot_num, atm, ityp, zv, tau, raux, + 1) #endif DEALLOCATE (raux) RETURN END SUBROUTINE punch_plot
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/LIN/ddrvrf4.f
32
11010
*> \brief \b DDRVRF4 * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE DDRVRF4( NOUT, NN, NVAL, THRESH, C1, C2, LDC, CRF, A, * + LDA, D_WORK_DLANGE ) * * .. Scalar Arguments .. * INTEGER LDA, LDC, NN, NOUT * DOUBLE PRECISION THRESH * .. * .. Array Arguments .. * INTEGER NVAL( NN ) * DOUBLE PRECISION A( LDA, * ), C1( LDC, * ), C2( LDC, *), * + CRF( * ), D_WORK_DLANGE( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DDRVRF4 tests the LAPACK RFP routines: *> DSFRK *> \endverbatim * * Arguments: * ========== * *> \param[in] NOUT *> \verbatim *> NOUT is INTEGER *> The unit number for output. *> \endverbatim *> *> \param[in] NN *> \verbatim *> NN is INTEGER *> The number of values of N contained in the vector NVAL. *> \endverbatim *> *> \param[in] NVAL *> \verbatim *> NVAL is INTEGER array, dimension (NN) *> The values of the matrix dimension N. *> \endverbatim *> *> \param[in] THRESH *> \verbatim *> THRESH is DOUBLE PRECISION *> The threshold value for the test ratios. A result is *> included in the output file if RESULT >= THRESH. To *> have every test ratio printed, use THRESH = 0. *> \endverbatim *> *> \param[out] C1 *> \verbatim *> C1 is DOUBLE PRECISION array, *> dimension (LDC,NMAX) *> \endverbatim *> *> \param[out] C2 *> \verbatim *> C2 is DOUBLE PRECISION array, *> dimension (LDC,NMAX) *> \endverbatim *> *> \param[in] LDC *> \verbatim *> LDC is INTEGER *> The leading dimension of the array A. *> LDA >= max(1,NMAX). *> \endverbatim *> *> \param[out] CRF *> \verbatim *> CRF is DOUBLE PRECISION array, *> dimension ((NMAX*(NMAX+1))/2). *> \endverbatim *> *> \param[out] A *> \verbatim *> A is DOUBLE PRECISION array, *> dimension (LDA,NMAX) *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,NMAX). *> \endverbatim *> *> \param[out] D_WORK_DLANGE *> \verbatim *> D_WORK_DLANGE is DOUBLE PRECISION array, dimension (NMAX) *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup double_lin * * ===================================================================== SUBROUTINE DDRVRF4( NOUT, NN, NVAL, THRESH, C1, C2, LDC, CRF, A, + LDA, D_WORK_DLANGE ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER LDA, LDC, NN, NOUT DOUBLE PRECISION THRESH * .. * .. Array Arguments .. INTEGER NVAL( NN ) DOUBLE PRECISION A( LDA, * ), C1( LDC, * ), C2( LDC, *), + CRF( * ), D_WORK_DLANGE( * ) * .. * * ===================================================================== * .. * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) INTEGER NTESTS PARAMETER ( NTESTS = 1 ) * .. * .. Local Scalars .. CHARACTER UPLO, CFORM, TRANS INTEGER I, IFORM, IIK, IIN, INFO, IUPLO, J, K, N, + NFAIL, NRUN, IALPHA, ITRANS DOUBLE PRECISION ALPHA, BETA, EPS, NORMA, NORMC * .. * .. Local Arrays .. CHARACTER UPLOS( 2 ), FORMS( 2 ), TRANSS( 2 ) INTEGER ISEED( 4 ), ISEEDY( 4 ) DOUBLE PRECISION RESULT( NTESTS ) * .. * .. External Functions .. DOUBLE PRECISION DLAMCH, DLARND, DLANGE EXTERNAL DLAMCH, DLARND, DLANGE * .. * .. External Subroutines .. EXTERNAL DSYRK, DSFRK, DTFTTR, DTRTTF * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX * .. * .. Scalars in Common .. CHARACTER*32 SRNAMT * .. * .. Common blocks .. COMMON / SRNAMC / SRNAMT * .. * .. Data statements .. DATA ISEEDY / 1988, 1989, 1990, 1991 / DATA UPLOS / 'U', 'L' / DATA FORMS / 'N', 'T' / DATA TRANSS / 'N', 'T' / * .. * .. Executable Statements .. * * Initialize constants and the random number seed. * NRUN = 0 NFAIL = 0 INFO = 0 DO 10 I = 1, 4 ISEED( I ) = ISEEDY( I ) 10 CONTINUE EPS = DLAMCH( 'Precision' ) * DO 150 IIN = 1, NN * N = NVAL( IIN ) * DO 140 IIK = 1, NN * K = NVAL( IIN ) * DO 130 IFORM = 1, 2 * CFORM = FORMS( IFORM ) * DO 120 IUPLO = 1, 2 * UPLO = UPLOS( IUPLO ) * DO 110 ITRANS = 1, 2 * TRANS = TRANSS( ITRANS ) * DO 100 IALPHA = 1, 4 * IF ( IALPHA.EQ. 1) THEN ALPHA = ZERO BETA = ZERO ELSE IF ( IALPHA.EQ. 2) THEN ALPHA = ONE BETA = ZERO ELSE IF ( IALPHA.EQ. 3) THEN ALPHA = ZERO BETA = ONE ELSE ALPHA = DLARND( 2, ISEED ) BETA = DLARND( 2, ISEED ) END IF * * All the parameters are set: * CFORM, UPLO, TRANS, M, N, * ALPHA, and BETA * READY TO TEST! * NRUN = NRUN + 1 * IF ( ITRANS.EQ.1 ) THEN * * In this case we are NOTRANS, so A is N-by-K * DO J = 1, K DO I = 1, N A( I, J) = DLARND( 2, ISEED ) END DO END DO * NORMA = DLANGE( 'I', N, K, A, LDA, + D_WORK_DLANGE ) * ELSE * * In this case we are TRANS, so A is K-by-N * DO J = 1,N DO I = 1, K A( I, J) = DLARND( 2, ISEED ) END DO END DO * NORMA = DLANGE( 'I', K, N, A, LDA, + D_WORK_DLANGE ) * END IF * * Generate C1 our N--by--N symmetric matrix. * Make sure C2 has the same upper/lower part, * (the one that we do not touch), so * copy the initial C1 in C2 in it. * DO J = 1, N DO I = 1, N C1( I, J) = DLARND( 2, ISEED ) C2(I,J) = C1(I,J) END DO END DO * * (See comment later on for why we use DLANGE and * not DLANSY for C1.) * NORMC = DLANGE( 'I', N, N, C1, LDC, + D_WORK_DLANGE ) * SRNAMT = 'DTRTTF' CALL DTRTTF( CFORM, UPLO, N, C1, LDC, CRF, + INFO ) * * call dsyrk the BLAS routine -> gives C1 * SRNAMT = 'DSYRK ' CALL DSYRK( UPLO, TRANS, N, K, ALPHA, A, LDA, + BETA, C1, LDC ) * * call dsfrk the RFP routine -> gives CRF * SRNAMT = 'DSFRK ' CALL DSFRK( CFORM, UPLO, TRANS, N, K, ALPHA, A, + LDA, BETA, CRF ) * * convert CRF in full format -> gives C2 * SRNAMT = 'DTFTTR' CALL DTFTTR( CFORM, UPLO, N, CRF, C2, LDC, + INFO ) * * compare C1 and C2 * DO J = 1, N DO I = 1, N C1(I,J) = C1(I,J)-C2(I,J) END DO END DO * * Yes, C1 is symmetric so we could call DLANSY, * but we want to check the upper part that is * supposed to be unchanged and the diagonal that * is supposed to be real -> DLANGE * RESULT(1) = DLANGE( 'I', N, N, C1, LDC, + D_WORK_DLANGE ) RESULT(1) = RESULT(1) + / MAX( ABS( ALPHA ) * NORMA + + ABS( BETA ) , ONE ) + / MAX( N , 1 ) / EPS * IF( RESULT(1).GE.THRESH ) THEN IF( NFAIL.EQ.0 ) THEN WRITE( NOUT, * ) WRITE( NOUT, FMT = 9999 ) END IF WRITE( NOUT, FMT = 9997 ) 'DSFRK', + CFORM, UPLO, TRANS, N, K, RESULT(1) NFAIL = NFAIL + 1 END IF * 100 CONTINUE 110 CONTINUE 120 CONTINUE 130 CONTINUE 140 CONTINUE 150 CONTINUE * * Print a summary of the results. * IF ( NFAIL.EQ.0 ) THEN WRITE( NOUT, FMT = 9996 ) 'DSFRK', NRUN ELSE WRITE( NOUT, FMT = 9995 ) 'DSFRK', NFAIL, NRUN END IF * 9999 FORMAT( 1X, ' *** Error(s) or Failure(s) while testing DSFRK + ***') 9997 FORMAT( 1X, ' Failure in ',A5,', CFORM=''',A1,''',', + ' UPLO=''',A1,''',',' TRANS=''',A1,''',', ' N=',I3,', K =', I3, + ', test=',G12.5) 9996 FORMAT( 1X, 'All tests for ',A5,' auxiliary routine passed the ', + 'threshold ( ',I5,' tests run)') 9995 FORMAT( 1X, A6, ' auxiliary routine: ',I5,' out of ',I5, + ' tests failed to pass the threshold') * RETURN * * End of DDRVRF4 * END
gpl-2.0
omni-compiler/omni-compiler
tests/XMP/others/F/add_decl-block.F90
2
2373
!$xmp nodes p(2) #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \ || defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER) integer :: ary1(6) = (/1,2,3,4,5,6/) integer :: ary2(10) = (/1,2,3,4,5,6,7,8,9,10/) !print *, 'line 01 : ', ary1 !print *, 'line 02 : ', ary2 blkname1 : block integer :: ary1(10) integer :: ary2(10) !$xmp nodes p(2) !$xmp template t(10) !$xmp distribute t(block) onto p !$xmp align ary1(i) with t(i) !$xmp loop on t(i) do i=1,10 ary1(i)=i**2 end do !print *, 'line 03 : ', ary1 blkname2 : block integer :: ary1(10) integer :: ary2(10) !$xmp nodes p(2) !$xmp template t(12) !$xmp distribute t(block) onto p !$xmp align ary1(i) with t(i) !$xmp loop on t(i) do i=1,10 ary1(i)=i**3 end do !print *, 'line 04 : ', ary1 !$xmp task on p(1) if (ary1(6).eq.216) then print *, 'PASS 1' else print *, 'ERROR 1' call exit(1) end if !$xmp end task !$xmp gmove ary2(:)=ary1(:) !print *, 'line 05 : ', ary2 !!$xmp task on p(2) if (ary2(6).eq.216) then print *, 'PASS 2' else print *, 'ERROR 2' call exit(1) end if !!$xmp end task end block blkname2 !$xmp gmove ary2(:)=ary1(:) !print *, 'line 06 : ', ary2 blkname3 : block integer :: ary1(10) integer :: ary2(10) !$xmp nodes p(2) !$xmp template t(14) !$xmp distribute t(block) onto p !$xmp align ary1(i) with t(i) !$xmp loop on t(i) do i=1,10 ary1(i)=i**4 end do !print *, 'line 07 : ', ary1 !$xmp task on p(1) if (ary1(7).eq.2401) then print *, 'PASS 3' else print *, 'ERROR 3' call exit(1) end if !$xmp end task !$xmp gmove ary2(:)=ary1(:) !print *, 'line 08 : ', ary2 !$xmp task on p(2) if (ary2(7).eq.2401) then print *, 'PASS 4' else print *, 'ERROR 4' call exit(1) end if !$xmp end task end block blkname3 !print *, 'line 09 : ', ary1 !print *, 'line 10 : ', ary2 !$xmp task on p(1) if (ary1(5).eq.25) then print *, 'PASS 5' else print *, 'ERROR 5' call exit(1) end if !$xmp end task !$xmp task on p(2) if (ary2(5).eq.25) then print *, 'PASS 6' else print *, 'ERROR 6' call exit(1) end if !$xmp end task end block blkname1 !print *, 'line 11 : ', ary1 !print *, 'line 12 : ', ary2 !$xmp task on p(1) if (ary1(6).eq.6.and.ary2(10).eq.10) then print *, 'PASS 7' else print *, 'ERROR 7' call exit(1) end if !$xmp end task #else !$xmp task on p(1) print *, 'SKIPPED' !$xmp end task #endif end
lgpl-3.0
RBigData/pbdSLAP
src/ScaLAPACK/pdlaqsy.f
4
13375
SUBROUTINE PDLAQSY( UPLO, N, A, IA, JA, DESCA, SR, SC, SCOND, $ AMAX, EQUED ) * * -- ScaLAPACK auxiliary routine (version 1.7) -- * University of Tennessee, Knoxville, Oak Ridge National Laboratory, * and University of California, Berkeley. * May 1, 1997 * * .. Scalar Arguments .. CHARACTER EQUED, UPLO INTEGER IA, JA, N DOUBLE PRECISION AMAX, SCOND * .. * .. Array Arguments .. INTEGER DESCA( * ) DOUBLE PRECISION A( * ), SC( * ), SR( * ) * .. * * Purpose * ======= * * PDLAQSY equilibrates a symmetric distributed matrix * sub( A ) = A(IA:IA+N-1,JA:JA+N-1) using the scaling factors in the * vectors SR and SC. * * Notes * ===== * * Each global data object is described by an associated description * vector. This vector stores the information required to establish * the mapping between an object element and its corresponding process * and memory location. * * Let A be a generic term for any 2D block cyclicly distributed array. * Such a global array has an associated description vector DESCA. * In the following comments, the character _ should be read as * "of the global array". * * NOTATION STORED IN EXPLANATION * --------------- -------------- -------------------------------------- * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case, * DTYPE_A = 1. * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating * the BLACS process grid A is distribu- * ted over. The context itself is glo- * bal, but the handle (the integer * value) may vary. * M_A (global) DESCA( M_ ) The number of rows in the global * array A. * N_A (global) DESCA( N_ ) The number of columns in the global * array A. * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute * the rows of the array. * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute * the columns of the array. * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first * row of the array A is distributed. * CSRC_A (global) DESCA( CSRC_ ) The process column over which the * first column of the array A is * distributed. * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local * array. LLD_A >= MAX(1,LOCr(M_A)). * * Let K be the number of rows or columns of a distributed matrix, * and assume that its process grid has dimension p x q. * LOCr( K ) denotes the number of elements of K that a process * would receive if K were distributed over the p processes of its * process column. * Similarly, LOCc( K ) denotes the number of elements of K that a * process would receive if K were distributed over the q processes of * its process row. * The values of LOCr() and LOCc() may be determined via a call to the * ScaLAPACK tool function, NUMROC: * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ), * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ). * An upper bound for these quantities may be computed by: * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A * * Arguments * ========= * * UPLO (global input) CHARACTER * Specifies whether the upper or lower triangular part of the * symmetric distributed matrix sub( A ) is to be referenced: * = 'U': Upper triangular * = 'L': Lower triangular * * N (global input) INTEGER * The number of rows and columns to be operated on, i.e. the * order of the distributed submatrix sub( A ). N >= 0. * * A (input/output) DOUBLE PRECISION pointer into the local * memory to an array of local dimension (LLD_A,LOCc(JA+N-1)). * On entry, the local pieces of the distributed symmetric * matrix sub( A ). If UPLO = 'U', the leading N-by-N upper * triangular part of sub( A ) contains the upper triangular * part of the matrix, and the strictly lower triangular part * of sub( A ) is not referenced. If UPLO = 'L', the leading * N-by-N lower triangular part of sub( A ) contains the lower * triangular part of the matrix, and the strictly upper trian- * gular part of sub( A ) is not referenced. * On exit, if EQUED = 'Y', the equilibrated matrix: * diag(SR(IA:IA+N-1)) * sub( A ) * diag(SC(JA:JA+N-1)). * * IA (global input) INTEGER * The row index in the global array A indicating the first * row of sub( A ). * * JA (global input) INTEGER * The column index in the global array A indicating the * first column of sub( A ). * * DESCA (global and local input) INTEGER array of dimension DLEN_. * The array descriptor for the distributed matrix A. * * SR (local input) DOUBLE PRECISION array, dimension LOCr(M_A) * The scale factors for A(IA:IA+M-1,JA:JA+N-1). SR is aligned * with the distributed matrix A, and replicated across every * process column. SR is tied to the distributed matrix A. * * SC (local input) DOUBLE PRECISION array, dimension LOCc(N_A) * The scale factors for sub( A ). SC is aligned with the dis- * tributed matrix A, and replicated down every process row. * SC is tied to the distributed matrix A. * * SCOND (global input) DOUBLE PRECISION * Ratio of the smallest SR(i) (respectively SC(j)) to the * largest SR(i) (respectively SC(j)), with IA <= i <= IA+N-1 * and JA <= j <= JA+N-1. * * AMAX (global input) DOUBLE PRECISION * Absolute value of the largest distributed submatrix entry. * * EQUED (output) CHARACTER*1 * Specifies whether or not equilibration was done. * = 'N': No equilibration. * = 'Y': Equilibration was done, i.e., sub( A ) has been re- * placed by: * diag(SR(IA:IA+N-1)) * sub( A ) * diag(SC(JA:JA+N-1)). * * Internal Parameters * =================== * * THRESH is a threshold value used to decide if scaling should be done * based on the ratio of the scaling factors. If SCOND < THRESH, * scaling is done. * * LARGE and SMALL are threshold values used to decide if scaling should * be done based on the absolute size of the largest matrix element. * If AMAX > LARGE or AMAX < SMALL, scaling is done. * * ===================================================================== * * .. Parameters .. INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_, $ LLD_, MB_, M_, NB_, N_, RSRC_ PARAMETER ( BLOCK_CYCLIC_2D = 1, DLEN_ = 9, DTYPE_ = 1, $ CTXT_ = 2, M_ = 3, N_ = 4, MB_ = 5, NB_ = 6, $ RSRC_ = 7, CSRC_ = 8, LLD_ = 9 ) DOUBLE PRECISION ONE, THRESH PARAMETER ( ONE = 1.0D+0, THRESH = 0.1D+0 ) * .. * .. Local Scalars .. INTEGER IACOL, IAROW, ICTXT, II, IIA, IOFFA, IROFF, J, $ JB, JJ, JJA, JN, KK, LDA, LL, MYCOL, MYROW, NP, $ NPCOL, NPROW DOUBLE PRECISION CJ, LARGE, SMALL * .. * .. External Subroutines .. EXTERNAL BLACS_GRIDINFO, INFOG2L * .. * .. External Functions .. LOGICAL LSAME INTEGER ICEIL, NUMROC DOUBLE PRECISION PDLAMCH EXTERNAL ICEIL, LSAME, NUMROC, PDLAMCH * .. * .. Intrinsic Functions .. INTRINSIC MIN, MOD * .. * .. Executable Statements .. * * Quick return if possible * IF( N.LE.0 ) THEN EQUED = 'N' RETURN END IF * * Get grid parameters and compute local indexes * ICTXT = DESCA( CTXT_ ) CALL BLACS_GRIDINFO( ICTXT, NPROW, NPCOL, MYROW, MYCOL ) CALL INFOG2L( IA, JA, DESCA, NPROW, NPCOL, MYROW, MYCOL, IIA, JJA, $ IAROW, IACOL ) LDA = DESCA( LLD_ ) * * Initialize LARGE and SMALL. * SMALL = PDLAMCH( ICTXT, 'Safe minimum' ) / $ PDLAMCH( ICTXT, 'Precision' ) LARGE = ONE / SMALL * IF( SCOND.GE.THRESH .AND. AMAX.GE.SMALL .AND. AMAX.LE.LARGE ) THEN * * No equilibration * EQUED = 'N' * ELSE * II = IIA JJ = JJA JN = MIN( ICEIL( JA, DESCA( NB_ ) ) * DESCA( NB_ ), JA+N-1 ) JB = JN-JA+1 * * Replace A by diag(S) * A * diag(S). * IF( LSAME( UPLO, 'U' ) ) THEN * * Upper triangle of A(IA:IA+N-1,JA:JA+N-1) is stored. * Handle first block separately * IOFFA = (JJ-1)*LDA IF( MYCOL.EQ.IACOL ) THEN IF( MYROW.EQ.IAROW ) THEN DO 20 LL = JJ, JJ + JB -1 CJ = SC( LL ) DO 10 KK = IIA, II+LL-JJ+1 A( IOFFA + KK ) = CJ*SR( KK )*A( IOFFA + KK ) 10 CONTINUE IOFFA = IOFFA + LDA 20 CONTINUE ELSE IOFFA = IOFFA + JB*LDA END IF JJ = JJ + JB END IF * IF( MYROW.EQ.IAROW ) $ II = II + JB IAROW = MOD( IAROW+1, NPROW ) IACOL = MOD( IACOL+1, NPCOL ) * * Loop over remaining block of columns * DO 70 J = JN+1, JA+N-1, DESCA( NB_ ) JB = MIN( JA+N-J, DESCA( NB_ ) ) * IF( MYCOL.EQ.IACOL ) THEN IF( MYROW.EQ.IAROW ) THEN DO 40 LL = JJ, JJ + JB -1 CJ = SC( LL ) DO 30 KK = IIA, II+LL-JJ+1 A( IOFFA + KK ) = CJ*SR( KK )*A( IOFFA + KK ) 30 CONTINUE IOFFA = IOFFA + LDA 40 CONTINUE ELSE DO 60 LL = JJ, JJ + JB -1 CJ = SC( LL ) DO 50 KK = IIA, II-1 A( IOFFA + KK ) = CJ*SR( KK )*A( IOFFA + KK ) 50 CONTINUE IOFFA = IOFFA + LDA 60 CONTINUE END IF JJ = JJ + JB END IF * IF( MYROW.EQ.IAROW ) $ II = II + JB IAROW = MOD( IAROW+1, NPROW ) IACOL = MOD( IACOL+1, NPCOL ) * 70 CONTINUE * ELSE * * Lower triangle of A(IA:IA+N-1,JA:JA+N-1) is stored. * Handle first block separately * IROFF = MOD( IA-1, DESCA( MB_ ) ) NP = NUMROC( N+IROFF, DESCA( MB_ ), MYROW, IAROW, NPROW ) IF( MYROW.EQ.IAROW ) $ NP = NP-IROFF * IOFFA = (JJ-1)*LDA IF( MYCOL.EQ.IACOL ) THEN IF( MYROW.EQ.IAROW ) THEN DO 90 LL = JJ, JJ + JB -1 CJ = SC( LL ) DO 80 KK = II+LL-JJ, IIA+NP-1 A( IOFFA + KK ) = CJ*SR( KK )*A( IOFFA + KK ) 80 CONTINUE IOFFA = IOFFA + LDA 90 CONTINUE ELSE DO 110 LL = JJ, JJ + JB -1 CJ = SC( LL ) DO 100 KK = II, IIA+NP-1 A( IOFFA + KK ) = CJ*SR( KK )*A( IOFFA + KK ) 100 CONTINUE IOFFA = IOFFA + LDA 110 CONTINUE END IF JJ = JJ + JB END IF * IF( MYROW.EQ.IAROW ) $ II = II + JB IAROW = MOD( IAROW+1, NPROW ) IACOL = MOD( IACOL+1, NPCOL ) * * Loop over remaining block of columns * DO 160 J = JN+1, JA+N-1, DESCA( NB_ ) JB = MIN( JA+N-J, DESCA( NB_ ) ) * IF( MYCOL.EQ.IACOL ) THEN IF( MYROW.EQ.IAROW ) THEN DO 130 LL = JJ, JJ + JB -1 CJ = SC( LL ) DO 120 KK = II+LL-JJ, IIA+NP-1 A( IOFFA + KK ) = CJ*SR( KK )*A( IOFFA + KK ) 120 CONTINUE IOFFA = IOFFA + LDA 130 CONTINUE ELSE DO 150 LL = JJ, JJ + JB -1 CJ = SC( LL ) DO 140 KK = II, IIA+NP-1 A( IOFFA + KK ) = CJ*SR( KK )*A( IOFFA + KK ) 140 CONTINUE IOFFA = IOFFA + LDA 150 CONTINUE END IF JJ = JJ + JB END IF * IF( MYROW.EQ.IAROW ) $ II = II + JB IAROW = MOD( IAROW+1, NPROW ) IACOL = MOD( IACOL+1, NPCOL ) * 160 CONTINUE * END IF * EQUED = 'Y' * END IF * RETURN * * End of PDLAQSY * END
mpl-2.0
QEF/q-e
PHonon/PH/matdyn.f90
1
91050
! Copyright (C) 2001-2012 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! Module ifconstants ! !! All variables read from file that need dynamical allocation. ! USE kinds, ONLY: DP ! REAL(DP), ALLOCATABLE :: frc(:,:,:,:,:,:,:) !! interatomic force constants in real space REAL(DP), ALLOCATABLE :: tau_blk(:,:) !! atomic positions for the original cell REAL(DP), ALLOCATABLE :: zeu(:,:,:) !! effective charges for the original cell REAL(DP), ALLOCATABLE :: m_loc(:,:) !! the magnetic moments of each atom INTEGER, ALLOCATABLE :: ityp_blk(:) !! atomic types for each atom of the original cell ! CHARACTER(LEN=3), ALLOCATABLE :: atm(:) ! end Module ifconstants ! ! !--------------------------------------------------------------------- PROGRAM matdyn !----------------------------------------------------------------------- !! This program calculates the phonon frequencies for a list of generic !! q vectors starting from the interatomic force constants generated !! from the dynamical matrices as written by DFPT phonon code through !! the companion program \(\texttt{q2r}\). ! !! \(\texttt{matdyn}\) can generate a supercell of the original cell for !! mass approximation calculation. If supercell data are not specified !! in input, the unit cell, lattice vectors, atom types and positions !! are read from the force constant file. ! ! Input cards: namelist &input ! flfrc file produced by q2r containing force constants (needed) ! It is the same as in the input of q2r.x (+ the .xml extension ! if the dynamical matrices produced by ph.x were in xml ! format). No default value: must be specified. ! asr (character) indicates the type of Acoustic Sum Rule imposed ! - 'no': no Acoustic Sum Rules imposed (default) ! - 'simple': previous implementation of the asr used ! (3 translational asr imposed by correction of ! the diagonal elements of the force constants matrix) ! - 'crystal': 3 translational asr imposed by optimized ! correction of the force constants (projection). ! - 'one-dim': 3 translational asr + 1 rotational asr ! imposed by optimized correction of the force constants ! (the rotation axis is the direction of periodicity; ! it will work only if this axis considered is one of ! the cartesian axis). ! - 'zero-dim': 3 translational asr + 3 rotational asr ! imposed by optimized correction of the force constants ! Note that in certain cases, not all the rotational asr ! can be applied (e.g. if there are only 2 atoms in a ! molecule or if all the atoms are aligned, etc.). ! In these cases the supplementary asr are cancelled ! during the orthonormalization procedure (see below). ! dos if .true. calculate phonon Density of States (DOS) ! using tetrahedra and a uniform q-point grid (see below) ! NB: may not work properly in noncubic materials ! if .false. calculate phonon bands from the list of q-points ! supplied in input (default) ! nk1,nk2,nk3 uniform q-point grid for DOS calculation (includes q=0) ! (must be specified if dos=.true., ignored otherwise) ! deltaE energy step, in cm^(-1), for DOS calculation: from min ! to max phonon energy (default: 1 cm^(-1) if ndos, see ! below, is not specified) ! ndos number of energy steps for DOS calculations ! (default: calculated from deltaE if not specified) ! degauss DOS broadening (in cm^-1). Default 0 - meaning use tetrahedra ! fldos output file for dos (default: 'matdyn.dos') ! the dos is in states/cm(-1) plotted vs omega in cm(-1) ! and is normalised to 3*nat, i.e. the number of phonons ! flfrq output file for frequencies (default: 'matdyn.freq') ! flvec output file for normalized phonon displacements ! (default: 'matdyn.modes'). The normalized phonon displacements ! are the eigenvectors divided by the square root of the mass, ! then normalized. As such they are not orthogonal. ! fleig output file for phonon eigenvectors (default: 'matdyn.eig') ! The phonon eigenvectors are the eigenvectors of the dynamical ! matrix. They are orthogonal. ! fldyn output file for dynamical matrix (default: ' ' i.e. not written) ! at supercell lattice vectors - must form a superlattice of the ! original lattice (default: use original cell) ! l1,l2,l3 supercell lattice vectors are original cell vectors times ! l1, l2, l3 respectively (default: 1, ignored if at specified) ! ntyp number of atom types in the supercell (default: ntyp of the ! original cell) ! amass masses of atoms in the supercell (a.m.u.), one per atom type ! (default: use masses read from file flfrc) ! readtau read atomic positions of the supercell from input ! (used to specify different masses) (default: .false.) ! fltau write atomic positions of the supercell to file "fltau" ! (default: fltau=' ', do not write) ! la2F if .true. interpolates also the el-ph coefficients. ! q_in_band_form if .true. the q points are given in band form: ! Only the first and last point of one or more lines ! are given. See below. (default: .false.). ! q_in_cryst_coord if .true. input q points are in crystalline ! coordinates (default: .false.) ! eigen_similarity: use similarity of the displacements to order ! frequencies (default: .false.) ! NB: You cannot use this option with the symmetry ! analysis of the modes. ! fd (logical) if .t. the ifc come from the finite displacement calculation ! na_ifc (logical) add non analitic contributions to the interatomic force ! constants if finite displacement method is used (as in Wang et al. ! Phys. Rev. B 85, 224303 (2012)) [to be used in conjunction with fd.x] ! nosym if .true., no symmetry and no time reversal are imposed ! loto_2d set to .true. to activate two-dimensional treatment of LO-TO splitting. ! loto_disable (logical) if .true. do not apply LO-TO splitting for q=0 ! (default: .false.) ! ! if (readtau) atom types and positions in the supercell follow: ! (tau(i,na),i=1,3), ityp(na) ! IF (q_in_band_form.and..not.dos) THEN ! nq ! number of q points ! (q(i,n),i=1,3), nptq nptq is the number of points between this point ! and the next. These points are automatically ! generated. the q points are given in Cartesian ! coordinates, 2pi/a units (a=lattice parameters) ! ELSE, if (.not.dos) : ! nq number of q-points ! (q(i,n), i=1,3) nq q-points in cartesian coordinates, 2pi/a units ! If q = 0, the direction qhat (q=>0) for the non-analytic part ! is extracted from the sequence of q-points as follows: ! qhat = q(n) - q(n-1) or qhat = q(n) - q(n+1) ! depending on which one is available and nonzero. ! For low-symmetry crystals, specify twice q = 0 in the list ! if you want to have q = 0 results for two different directions ! USE kinds, ONLY : DP USE mp, ONLY : mp_bcast USE mp_world, ONLY : world_comm USE mp_global, ONLY : mp_startup, mp_global_end USE environment, ONLY : environment_start, environment_end USE io_global, ONLY : ionode, ionode_id, stdout USE io_dyn_mat, ONLY : read_dyn_mat_param, read_dyn_mat_header, & read_ifc_param, read_ifc USE cell_base, ONLY : at, bg, celldm USE constants, ONLY : RY_TO_THZ, RY_TO_CMM1, amu_ry USE symm_base, ONLY : set_sym USE rap_point_group, ONLY : code_group USE bz_form, ONLY : transform_label_coord USE parser, ONLY : read_line USE rigid, ONLY : dyndiag, nonanal, nonanal_ifc USE el_phon, ONLY : el_ph_nsigma USE ifconstants, ONLY : frc, atm, zeu, tau_blk, ityp_blk, m_loc ! IMPLICIT NONE ! INTEGER :: gid ! ! variables *_blk refer to the original cell, other variables ! to the (super)cell (which may coincide with the original cell) ! INTEGER:: nax, nax_blk INTEGER, PARAMETER:: ntypx=10, nrwsx=200 REAL(DP), PARAMETER :: eps=1.0d-6 INTEGER :: nr1, nr2, nr3, nsc, nk1, nk2, nk3, ibrav CHARACTER(LEN=256) :: flfrc, flfrq, flvec, fltau, fldos, filename, fldyn, & fleig, fildyn, fildyn_prefix CHARACTER(LEN=10) :: asr LOGICAL :: dos, has_zstar, q_in_cryst_coord, eigen_similarity, loto_disable COMPLEX(DP), ALLOCATABLE :: dyn(:,:,:,:), dyn_blk(:,:,:,:), frc_ifc(:,:,:,:) COMPLEX(DP), ALLOCATABLE :: z(:,:) REAL(DP), ALLOCATABLE:: tau(:,:), q(:,:), w2(:,:), freq(:,:), wq(:), & dynq(:,:,:), DOSofE(:), zq(:, :, :) INTEGER, ALLOCATABLE:: ityp(:), itau_blk(:) REAL(DP) :: omega,alat, &! cell parameters and volume at_blk(3,3), bg_blk(3,3), &! original cell omega_blk, &! original cell volume epsil(3,3), &! dielectric tensor amass(ntypx), &! atomic masses amass_blk(ntypx), &! original atomic masses atws(3,3), &! lattice vector for WS initialization rws(0:3,nrwsx) ! nearest neighbor list, rws(0,*) = norm^2 ! INTEGER :: nat, nat_blk, ntyp, ntyp_blk, & l1, l2, l3, &! supercell dimensions nrws, &! number of nearest neighbor code_group_old INTEGER :: nspin_mag, nqs, ios, ipol ! LOGICAL :: readtau, la2F, xmlifc, lo_to_split, na_ifc, fd, nosym, loto_2d ! REAL(DP) :: qhat(3), qh, DeltaE, Emin=0._dp, Emax, E, qq, degauss REAL(DP) :: delta, pathL REAL(DP), ALLOCATABLE :: xqaux(:,:) INTEGER, ALLOCATABLE :: nqb(:) INTEGER :: n, i, j, it, nq, nqx, na, nb, ndos, iout, nqtot, iout_dyn, iout_eig LOGICAL, EXTERNAL :: has_xml INTEGER, ALLOCATABLE :: num_rap_mode(:,:) LOGICAL, ALLOCATABLE :: high_sym(:) LOGICAL :: q_in_band_form ! .... variables for band plotting based on similarity of eigenvalues COMPLEX(DP), ALLOCATABLE :: tmp_z(:,:) REAL(DP), ALLOCATABLE :: abs_similarity(:,:), tmp_w2(:) COMPLEX(DP), ALLOCATABLE :: f_of_q(:,:,:,:) INTEGER :: location(1), isig CHARACTER(LEN=6) :: int_to_char LOGICAL, ALLOCATABLE :: mask(:) INTEGER :: npk_label, nch CHARACTER(LEN=3), ALLOCATABLE :: letter(:) INTEGER, ALLOCATABLE :: label_list(:) LOGICAL :: tend, terr CHARACTER(LEN=256) :: input_line, buffer CHARACTER(LEN=10) :: point_label_type CHARACTER(len=80) :: k_points = 'tpiba' ! REAL(DP), external :: dos_broad, dos_gam ! NAMELIST /input/ flfrc, amass, asr, flfrq, flvec, fleig, at, dos, & & fldos, nk1, nk2, nk3, l1, l2, l3, ntyp, readtau, fltau, & & la2F, ndos, DeltaE, degauss, q_in_band_form, q_in_cryst_coord, & & eigen_similarity, fldyn, na_ifc, fd, point_label_type, & & nosym, loto_2d, fildyn, fildyn_prefix, el_ph_nsigma, & & loto_disable ! CALL mp_startup() CALL environment_start('MATDYN') ! IF (ionode) CALL input_from_file ( ) ! ! ... all calculations are done by the first cpu ! ! set namelist default ! dos = .FALSE. deltaE = 1.0d0 degauss = 0 ndos = 1 nk1 = 0 nk2 = 0 nk3 = 0 asr ='no' readtau=.FALSE. flfrc=' ' fldos='matdyn.dos' flfrq='matdyn.freq' flvec='matdyn.modes' fleig=' ' fldyn=' ' fltau=' ' fildyn = ' ' fildyn_prefix = ' ' amass(:) =0.d0 amass_blk(:) =0.d0 at(:,:) = 0.d0 ntyp = 0 l1=1 l2=1 l3=1 la2F=.false. q_in_band_form=.FALSE. eigen_similarity=.FALSE. q_in_cryst_coord = .FALSE. na_ifc=.FALSE. fd=.FALSE. point_label_type='SC' nosym = .false. loto_2d=.false. el_ph_nsigma=10 loto_disable = .false. ! ! IF (ionode) READ (5,input,IOSTAT=ios) CALL mp_bcast(ios, ionode_id, world_comm) CALL errore('matdyn', 'reading input namelist', ABS(ios)) CALL mp_bcast(dos,ionode_id, world_comm) CALL mp_bcast(deltae,ionode_id, world_comm) CALL mp_bcast(ndos,ionode_id, world_comm) CALL mp_bcast(degauss,ionode_id, world_comm) CALL mp_bcast(nk1,ionode_id, world_comm) CALL mp_bcast(nk2,ionode_id, world_comm) CALL mp_bcast(nk3,ionode_id, world_comm) CALL mp_bcast(asr,ionode_id, world_comm) CALL mp_bcast(readtau,ionode_id, world_comm) CALL mp_bcast(flfrc,ionode_id, world_comm) CALL mp_bcast(fldos,ionode_id, world_comm) CALL mp_bcast(flfrq,ionode_id, world_comm) CALL mp_bcast(flvec,ionode_id, world_comm) CALL mp_bcast(fleig,ionode_id, world_comm) CALL mp_bcast(fldyn,ionode_id, world_comm) CALL mp_bcast(fltau,ionode_id, world_comm) CALL mp_bcast(fildyn,ionode_id, world_comm) CALL mp_bcast(fildyn_prefix,ionode_id, world_comm) CALL mp_bcast(amass,ionode_id, world_comm) CALL mp_bcast(amass_blk,ionode_id, world_comm) CALL mp_bcast(at,ionode_id, world_comm) CALL mp_bcast(ntyp,ionode_id, world_comm) CALL mp_bcast(l1,ionode_id, world_comm) CALL mp_bcast(l2,ionode_id, world_comm) CALL mp_bcast(l3,ionode_id, world_comm) CALL mp_bcast(na_ifc,ionode_id, world_comm) CALL mp_bcast(fd,ionode_id, world_comm) CALL mp_bcast(la2F,ionode_id, world_comm) CALL mp_bcast(q_in_band_form,ionode_id, world_comm) CALL mp_bcast(eigen_similarity,ionode_id, world_comm) CALL mp_bcast(q_in_cryst_coord,ionode_id, world_comm) CALL mp_bcast(point_label_type,ionode_id, world_comm) CALL mp_bcast(loto_2d,ionode_id, world_comm) CALL mp_bcast(loto_disable,ionode_id, world_comm) CALL mp_bcast(el_ph_nsigma,ionode_id, world_comm) ! IF (loto_2d .AND. loto_disable) CALL errore('matdyn', & 'loto_2d and loto_disable cannot be both true', 1) ! ! read force constants ! IF ( trim( fildyn ) /= ' ' ) THEN IF (ionode) THEN WRITE(stdout, *) WRITE(stdout, '(4x,a)') ' fildyn has been provided, running q2r...' END IF CALL do_q2r(fildyn, flfrc, fildyn_prefix, asr, la2F, loto_2d) END IF ! ntyp_blk = ntypx ! avoids fake out-of-bound error xmlifc=has_xml(flfrc) IF (xmlifc) THEN CALL read_dyn_mat_param(flfrc,ntyp_blk,nat_blk) ALLOCATE (m_loc(3,nat_blk)) ALLOCATE (tau_blk(3,nat_blk)) ALLOCATE (ityp_blk(nat_blk)) ALLOCATE (atm(ntyp_blk)) ALLOCATE (zeu(3,3,nat_blk)) CALL read_dyn_mat_header(ntyp_blk, nat_blk, ibrav, nspin_mag, & celldm, at_blk, bg_blk, omega_blk, atm, amass_blk, & tau_blk, ityp_blk, m_loc, nqs, has_zstar, epsil, zeu ) alat=celldm(1) call volume(alat,at_blk(1,1),at_blk(1,2),at_blk(1,3),omega_blk) CALL read_ifc_param(nr1,nr2,nr3) ALLOCATE(frc(nr1,nr2,nr3,3,3,nat_blk,nat_blk)) CALL read_ifc(nr1,nr2,nr3,nat_blk,frc) ELSE CALL readfc ( flfrc, nr1, nr2, nr3, epsil, nat_blk, & ibrav, alat, at_blk, ntyp_blk, & amass_blk, omega_blk, has_zstar) ENDIF ! CALL recips ( at_blk(1,1),at_blk(1,2),at_blk(1,3), & bg_blk(1,1),bg_blk(1,2),bg_blk(1,3) ) ! ! set up (super)cell ! if (ntyp < 0) then call errore ('matdyn','wrong ntyp ', abs(ntyp)) else if (ntyp == 0) then ntyp=ntyp_blk end if ! ! masses (for mass approximation) ! DO it=1,ntyp IF (amass(it) < 0.d0) THEN CALL errore ('matdyn','wrong mass in the namelist',it) ELSE IF (amass(it) == 0.d0) THEN IF (it.LE.ntyp_blk) THEN WRITE (stdout,'(a,i3,a,a)') ' mass for atomic type ',it, & & ' not given; uses mass from file ',flfrc amass(it) = amass_blk(it) ELSE CALL errore ('matdyn','missing mass in the namelist',it) END IF END IF END DO ! ! lattice vectors ! IF (SUM(ABS(at(:,:))) == 0.d0) THEN IF (l1.LE.0 .OR. l2.LE.0 .OR. l3.LE.0) CALL & & errore ('matdyn',' wrong l1,l2 or l3',1) at(:,1) = at_blk(:,1)*DBLE(l1) at(:,2) = at_blk(:,2)*DBLE(l2) at(:,3) = at_blk(:,3)*DBLE(l3) END IF ! CALL check_at(at,bg_blk,alat,omega) ! ! the supercell contains "nsc" times the original unit cell ! nsc = NINT(omega/omega_blk) IF (ABS(omega/omega_blk-nsc) > eps) & CALL errore ('matdyn', 'volume ratio not integer', 1) ! ! read/generate atomic positions of the (super)cell ! nat = nat_blk * nsc nax = nat nax_blk = nat_blk ! ALLOCATE ( tau (3, nat), ityp(nat), itau_blk(nat) ) ! IF (readtau) THEN CALL read_tau & (nat, nat_blk, ntyp, bg_blk, tau, tau_blk, ityp, itau_blk) ELSE CALL set_tau & (nat, nat_blk, at, at_blk, tau, tau_blk, ityp, ityp_blk, itau_blk) ENDIF ! IF (fltau.NE.' ') CALL write_tau (fltau, nat, tau, ityp) ! ! reciprocal lattice vectors ! CALL recips (at(1,1),at(1,2),at(1,3),bg(1,1),bg(1,2),bg(1,3)) ! ! build the WS cell corresponding to the force constant grid ! atws(:,1) = at_blk(:,1)*DBLE(nr1) atws(:,2) = at_blk(:,2)*DBLE(nr2) atws(:,3) = at_blk(:,3)*DBLE(nr3) ! initialize WS r-vectors CALL wsinit(rws,nrwsx,nrws,atws) ! ! end of (super)cell setup ! IF (dos) THEN IF (nk1 < 1 .OR. nk2 < 1 .OR. nk3 < 1) & CALL errore ('matdyn','specify correct q-point grid!',1) nqx = nk1*nk2*nk3 ALLOCATE ( q(3,nqx), wq(nqx) ) CALL gen_qpoints (ibrav, at, bg, nat, tau, ityp, nk1, nk2, nk3, & nqx, nq, q, nosym, wq) ELSE ! ! read q-point list ! IF (ionode) READ (5,*) nq CALL mp_bcast(nq, ionode_id, world_comm) ALLOCATE ( q(3,nq) ) IF (.NOT.q_in_band_form) THEN ALLOCATE(wq(nq)) DO n = 1,nq IF (ionode) READ (5,*) (q(i,n),i=1,3) END DO CALL mp_bcast(q, ionode_id, world_comm) ! IF (q_in_cryst_coord) CALL cryst_to_cart(nq,q,bg,+1) ELSE ALLOCATE( nqb(nq) ) ALLOCATE( xqaux(3,nq) ) ALLOCATE( letter(nq) ) ALLOCATE( label_list(nq) ) npk_label=0 DO n = 1, nq CALL read_line( input_line, end_of_file = tend, error = terr ) IF (tend) CALL errore('matdyn','Missing lines',1) IF (terr) CALL errore('matdyn','Error reading q points',1) DO j=1,256 ! loop over all characters of input_line IF ( (ICHAR(input_line(j:j)) < 58 .AND. & ! a digit ICHAR(input_line(j:j)) > 47) & .OR.ICHAR(input_line(j:j)) == 43 .OR. & ! the + sign ICHAR(input_line(j:j)) == 45 .OR. & ! the - sign ICHAR(input_line(j:j)) == 46 ) THEN ! a dot . ! ! This is a digit, therefore this line contains the coordinates of the ! k point. We read it and exit from the loop on characters ! READ(input_line,*) xqaux(1,n), xqaux(2,n), xqaux(3,n), & nqb(n) EXIT ELSEIF ((ICHAR(input_line(j:j)) < 123 .AND. & ICHAR(input_line(j:j)) > 64)) THEN ! ! This is a letter, not a space character. We read the next three ! characters and save them in the letter array, save also which k point ! it is ! npk_label=npk_label+1 READ(input_line(j:),'(a3)') letter(npk_label) label_list(npk_label)=n ! ! now we remove the letters from input_line and read the number of points ! of the line. The next two line should account for the case in which ! there is only one space between the letter and the number of points. ! nch=3 IF ( ICHAR(input_line(j+1:j+1))==32 .OR. & ICHAR(input_line(j+2:j+2))==32 ) nch=2 buffer=input_line(j+nch:) READ(buffer,*,err=20,iostat=ios) nqb(n) 20 IF (ios /=0) CALL errore('matdyn',& 'problem reading number of points',1) EXIT ENDIF ENDDO ENDDO IF (q_in_cryst_coord) k_points='crystal' IF ( npk_label > 0 ) & CALL transform_label_coord(ibrav, celldm, xqaux, letter, & label_list, npk_label, nq, k_points, point_label_type ) DEALLOCATE(letter) DEALLOCATE(label_list) CALL mp_bcast(xqaux, ionode_id, world_comm) CALL mp_bcast(nqb, ionode_id, world_comm) IF (q_in_cryst_coord) CALL cryst_to_cart(nq,xqaux,bg,+1) nqtot=SUM(nqb(1:nq-1))+1 DO i=1,nq-1 IF (nqb(i)==0) nqtot=nqtot+1 ENDDO DEALLOCATE(q) ALLOCATE(q(3,nqtot)) ALLOCATE(wq(nqtot)) CALL generate_k_along_lines(nq, xqaux, nqb, q, wq, nqtot) nq=nqtot DEALLOCATE(xqaux) DEALLOCATE(nqb) END IF ! END IF ! IF (asr /= 'no') THEN CALL set_asr (asr, nr1, nr2, nr3, frc, zeu, & nat_blk, ibrav, tau_blk) END IF ! IF (flvec.EQ.' ') THEN iout=0 ELSE iout=4 IF (ionode) OPEN (unit=iout,file=flvec,status='unknown',form='formatted') END IF IF (fldyn.EQ.' ') THEN iout_dyn=0 ELSE iout_dyn=44 OPEN (unit=iout_dyn,file=fldyn,status='unknown',form='formatted') END IF IF (fleig.EQ.' ') THEN iout_eig=0 ELSE iout_eig=313 IF (ionode) OPEN (unit=iout_eig,file=fleig,status='unknown',form='formatted') END IF ALLOCATE ( dyn(3,3,nat,nat), dyn_blk(3,3,nat_blk,nat_blk) ) ALLOCATE ( z(3*nat,3*nat), w2(3*nat,nq), f_of_q(3,3,nat,nat), & dynq(3*nat,nq,nat), DOSofE(nat), zq(nq, 3*nat, 3*nat) ) ALLOCATE ( tmp_w2(3*nat), abs_similarity(3*nat,3*nat), mask(3*nat) ) if(la2F.and.ionode) open(unit=300,file='dyna2F',status='unknown') IF (xmlifc) CALL set_sym(nat, tau, ityp, nspin_mag, m_loc ) ALLOCATE(num_rap_mode(3*nat,nq)) ALLOCATE(high_sym(nq)) num_rap_mode=-1 high_sym=.TRUE. zq(:, :, :) = (0.d0, 0.d0) DO n=1, nq dyn(:,:,:,:) = (0.d0, 0.d0) lo_to_split=.FALSE. f_of_q(:,:,:,:) = (0.d0,0.d0) IF(na_ifc) THEN qq=sqrt(q(1,n)**2+q(2,n)**2+q(3,n)**2) if(abs(qq) < 1d-8) qq=1.0 qhat(1)=q(1,n)/qq qhat(2)=q(2,n)/qq qhat(3)=q(3,n)/qq CALL nonanal_ifc (nat,nat_blk,itau_blk,epsil,qhat,zeu,omega,dyn, & nr1, nr2, nr3,f_of_q) END IF CALL setupmat (q(1,n), dyn, nat, at, bg, tau, itau_blk, nsc, alat, & dyn_blk, nat_blk, at_blk, bg_blk, tau_blk, omega_blk, & loto_2d, & epsil, zeu, frc, nr1,nr2,nr3, has_zstar, rws, nrws, na_ifc,f_of_q,fd) IF (.not.loto_2d) THEN qhat(1) = q(1,n)*at(1,1)+q(2,n)*at(2,1)+q(3,n)*at(3,1) qhat(2) = q(1,n)*at(1,2)+q(2,n)*at(2,2)+q(3,n)*at(3,2) qhat(3) = q(1,n)*at(1,3)+q(2,n)*at(2,3)+q(3,n)*at(3,3) IF ( ABS( qhat(1) - NINT (qhat(1) ) ) <= eps .AND. & ABS( qhat(2) - NINT (qhat(2) ) ) <= eps .AND. & ABS( qhat(3) - NINT (qhat(3) ) ) <= eps ) THEN ! ! q = 0 : we need the direction q => 0 for the non-analytic part ! IF ( n == 1 ) THEN ! if q is the first point in the list IF ( nq > 1 ) THEN ! one more point qhat(:) = q(:,n) - q(:,n+1) ELSE ! no more points qhat(:) = 0.d0 END IF ELSE IF ( n > 1 ) THEN ! if q is not the first point in the list IF ( q(1,n-1)==0.d0 .AND. & q(2,n-1)==0.d0 .AND. & q(3,n-1)==0.d0 .AND. n < nq ) THEN ! if the preceding q is also 0 : qhat(:) = q(:,n) - q(:,n+1) ELSE ! if the preceding q is npt 0 : qhat(:) = q(:,n) - q(:,n-1) END IF END IF qh = SQRT(qhat(1)**2+qhat(2)**2+qhat(3)**2) ! write(*,*) ' qh, has_zstar ',qh, has_zstar IF (qh /= 0.d0) qhat(:) = qhat(:) / qh IF (qh /= 0.d0 .AND. .NOT. has_zstar) THEN CALL infomsg & ('matdyn','Z* not found in file '//TRIM(flfrc)// & ', TO-LO splitting at q=0 will be absent!') ELSEIF (loto_disable) THEN CALL infomsg('matdyn', & 'loto_disable is true. Disable LO-TO splitting at q=0.') ELSE lo_to_split=.TRUE. ENDIF ! IF (lo_to_split) CALL nonanal (nat, nat_blk, itau_blk, epsil, qhat, zeu, omega, dyn) ! END IF ! END IF if(iout_dyn.ne.0) THEN call write_dyn_on_file(q(1,n),dyn,nat, iout_dyn) if(sum(abs(q(:,n)))==0._dp) call write_epsilon_and_zeu (zeu, epsil, nat, iout_dyn) endif CALL dyndiag(nat,ntyp,amass,ityp,dyn,w2(1,n),z) ! ! Convert from displacements to eigenvectors (see rigid.f90 :: dyndiag) do i = 1, 3*nat do na = 1, nat do ipol = 1,3 zq(n, (na-1)*3+ipol,i) = z((na-1)*3+ipol,i) * sqrt(amu_ry * amass(ityp(na))) end do end do end do ! ! Atom projection of dynamical matrix DO i = 1, 3*nat DO na = 1, nat dynq(i, n, na) = DOT_PRODUCT(z(3*(na-1)+1:3*na, i), & & z(3*(na-1)+1:3*na, i) ) & & * amu_ry * amass(ityp(na)) END DO END DO IF (ionode.and.iout_eig.ne.0) & & CALL write_eigenvectors(nat,ntyp,amass,ityp,q(1,n),w2(1,n),z,iout_eig) ! ! Cannot use the small group of \Gamma to analize the symmetry ! of the mode if there is an electric field. ! IF (xmlifc.AND..NOT.lo_to_split) THEN WRITE(stdout,'(10x,"xq=",3F8.4)') q(:,n) CALL find_representations_mode_q(nat,ntyp,q(:,n), & w2(:,n),z,tau,ityp,amass, num_rap_mode(:,n), nspin_mag) IF (code_group==code_group_old.OR.high_sym(n-1)) high_sym(n)=.FALSE. code_group_old=code_group ENDIF IF (eigen_similarity) THEN ! ... order phonon dispersions using similarity of eigenvalues ! ... Courtesy of Takeshi Nishimatsu, IMR, Tohoku University IF (.NOT.ALLOCATED(tmp_z)) THEN ALLOCATE(tmp_z(3*nat,3*nat)) ELSE abs_similarity = ABS ( MATMUL ( CONJG( TRANSPOSE(z)), tmp_z ) ) mask(:) = .true. DO na=1,3*nat location = maxloc( abs_similarity(:,na), mask(:) ) mask(location(1)) = .false. tmp_w2(na) = w2(location(1),n) tmp_z(:,na) = z(:,location(1)) END DO w2(:,n) = tmp_w2(:) z(:,:) = tmp_z(:,:) END IF tmp_z(:,:) = z(:,:) ENDIF ! if(la2F.and.ionode) then write(300,*) n do na=1,3*nat write(300,*) (z(na,nb),nb=1,3*nat) end do ! na endif ! IF (ionode.and.iout.ne.0) CALL writemodes(nat,q(1,n),w2(1,n),z,iout) ! END DO !nq DEALLOCATE (tmp_w2, abs_similarity, mask) IF (eigen_similarity) DEALLOCATE(tmp_z) if(la2F.and.ionode) close(300) ! IF(iout .NE. 0.and.ionode) CLOSE(unit=iout) IF(iout_dyn .NE. 0) CLOSE(unit=iout_dyn) IF(iout_eig .NE. 0) CLOSE(unit=iout_eig) ! ALLOCATE (freq(3*nat, nq)) DO n=1,nq ! freq(i,n) = frequencies in cm^(-1), with negative sign if omega^2 is negative DO i=1,3*nat freq(i,n)= SQRT(ABS(w2(i,n))) * RY_TO_CMM1 IF (w2(i,n) < 0.0d0) freq(i,n) = -freq(i,n) END DO END DO ! IF(flfrq.NE.' '.and.ionode) THEN OPEN (unit=2,file=flfrq ,status='unknown',form='formatted') WRITE(2, '(" &plot nbnd=",i4,", nks=",i4," /")') 3*nat, nq DO n=1, nq WRITE(2, '(10x,3f10.6)') q(1,n), q(2,n), q(3,n) WRITE(2,'(6f10.4)') (freq(i,n), i=1,3*nat) END DO CLOSE(unit=2) OPEN (unit=2,file=trim(flfrq)//'.gp' ,status='unknown',form='formatted') pathL = 0._dp WRITE(2, '(f10.6,3x,999f10.4)') pathL, (freq(i,1), i=1,3*nat) DO n=2, nq pathL=pathL+(SQRT(SUM( (q(:,n)-q(:,n-1))**2 ))) WRITE(2, '(f10.6,3x,999f10.4)') pathL, (freq(i,n), i=1,3*nat) END DO CLOSE(unit=2) END IF ! ! If the force constants are in the xml format we write also ! the file with the representations of each mode ! IF (flfrq.NE.' '.AND.xmlifc.AND.ionode) THEN filename=TRIM(flfrq)//'.rap' OPEN (unit=2,file=filename ,status='unknown',form='formatted') WRITE(2, '(" &plot_rap nbnd_rap=",i4,", nks_rap=",i4," /")') 3*nat, nq DO n=1, nq WRITE(2,'(10x,3f10.6,l6)') q(1,n), q(2,n), q(3,n), high_sym(n) WRITE(2,'(6i10)') (num_rap_mode(i,n), i=1,3*nat) END DO CLOSE(unit=2) END IF ! IF (dos) THEN Emin = 0.0d0 Emax = 0.0d0 DO n=1,nq DO i=1, 3*nat Emin = MIN (Emin, freq(i,n)) Emax = MAX (Emax, freq(i,n)) END DO END DO ! if (ndos > 1) then DeltaE = (Emax - Emin)/(ndos-1) else ndos = NINT ( (Emax - Emin) / DeltaE + 1.51d0 ) end if IF (ionode) OPEN (unit=2,file=fldos,status='unknown',form='formatted') IF (ionode) WRITE (2, *) "# Frequency[cm^-1] DOS PDOS" ! IF (degauss .EQ. 0) THEN ! Use tetrahedra DO na = 1, nat dynq(1:3*nat,1:nq,na) = dynq(1:3*nat,1:nq,na) * freq(1:3*nat,1:nq) END DO END IF ! DO n= 1, ndos E = Emin + (n - 1) * DeltaE DO na = 1, nat DOSofE(na) = 0d0 ! IF (degauss .EQ. 0) THEN ! Use tetrahedra DO i = 1, 3*nat DOSofE(na) = DOSofE(na) & & + dos_gam(3*nat, nq, i, dynq(1:3*nat,1:nq,na), freq, E) END DO ELSE ! Use broadening DOSofE(na) = DOSofE(na) & & + dos_broad(na, 3*nat, nq, freq, zq, wq, E, degauss) END IF ! END DO ! IF (ionode) WRITE (2, '(2ES18.10,1000ES12.4)') E, SUM(DOSofE(1:nat)), DOSofE(1:nat) END DO IF (ionode) CLOSE(unit=2) END IF !dos DEALLOCATE (z, zq, w2, dyn, dyn_blk) ! ! for a2F ! IF(la2F) THEN ! IF (.NOT. dos) THEN DO isig=1,el_ph_nsigma OPEN (unit=200+isig,file='elph.gamma.'//& TRIM(int_to_char(isig)), status='unknown',form='formatted') WRITE(200+isig, '(" &plot nbnd=",i4,", nks=",i4," /")') 3*nat, nq END DO END IF ! ! convert frequencies to Ry ! freq(:,:)= freq(:,:) / RY_TO_CMM1 Emin = Emin / RY_TO_CMM1 DeltaE=DeltaE/ RY_TO_CMM1 ! call a2Fdos (nat, nq, nr1, nr2, nr3, ibrav, at, bg, tau, alat, & nsc, nat_blk, at_blk, bg_blk, itau_blk, omega_blk, & rws, nrws, dos, Emin, DeltaE, ndos, & asr, q, freq,fd, wq) ! IF (.NOT.dos) THEN DO isig=1,el_ph_nsigma CLOSE(UNIT=200+isig) ENDDO ENDIF END IF DEALLOCATE ( freq) DEALLOCATE(num_rap_mode) DEALLOCATE(high_sym) ! CALL environment_end('MATDYN') ! CALL mp_global_end() ! STOP ! END PROGRAM matdyn ! !----------------------------------------------------------------------- SUBROUTINE readfc ( flfrc, nr1, nr2, nr3, epsil, nat, & ibrav, alat, at, ntyp, amass, omega, has_zstar ) !----------------------------------------------------------------------- ! USE kinds, ONLY : DP USE ifconstants,ONLY : tau => tau_blk, ityp => ityp_blk, frc, zeu USE cell_base, ONLY : celldm USE io_global, ONLY : ionode, ionode_id, stdout USE mp, ONLY : mp_bcast USE mp_world, ONLY : world_comm USE constants, ONLY : amu_ry ! IMPLICIT NONE ! I/O variable CHARACTER(LEN=256) :: flfrc INTEGER :: ibrav, nr1,nr2,nr3,nat, ntyp REAL(DP) :: alat, at(3,3), epsil(3,3) LOGICAL :: has_zstar ! local variables INTEGER :: i, j, na, nb, m1,m2,m3 INTEGER :: ibid, jbid, nabid, nbbid, m1bid,m2bid,m3bid REAL(DP) :: amass(ntyp), amass_from_file, omega INTEGER :: nt CHARACTER(LEN=3) :: atm ! ! IF (ionode) OPEN (unit=1,file=flfrc,status='old',form='formatted') ! ! read cell data ! IF (ionode)THEN READ(1,*) ntyp,nat,ibrav,(celldm(i),i=1,6) if (ibrav==0) then read(1,*) ((at(i,j),i=1,3),j=1,3) end if ENDIF CALL mp_bcast(ntyp, ionode_id, world_comm) CALL mp_bcast(nat, ionode_id, world_comm) CALL mp_bcast(ibrav, ionode_id, world_comm) CALL mp_bcast(celldm, ionode_id, world_comm) IF (ibrav==0) THEN CALL mp_bcast(at, ionode_id, world_comm) ENDIF ! CALL latgen(ibrav,celldm,at(1,1),at(1,2),at(1,3),omega) alat = celldm(1) at = at / alat ! bring at in units of alat CALL volume(alat,at(1,1),at(1,2),at(1,3),omega) ! ! read atomic types, positions and masses ! DO nt = 1,ntyp IF (ionode) READ(1,*) i,atm,amass_from_file CALL mp_bcast(i,ionode_id, world_comm) CALL mp_bcast(atm,ionode_id, world_comm) CALL mp_bcast(amass_from_file,ionode_id, world_comm) IF (i.NE.nt) CALL errore ('readfc','wrong data read',nt) IF (amass(nt).EQ.0.d0) THEN amass(nt) = amass_from_file/amu_ry ELSE WRITE(stdout,*) 'for atomic type',nt,' mass from file not used' END IF END DO ! ALLOCATE (tau(3,nat), ityp(nat), zeu(3,3,nat)) ! DO na=1,nat IF (ionode) READ(1,*) i,ityp(na),(tau(j,na),j=1,3) CALL mp_bcast(i,ionode_id, world_comm) IF (i.NE.na) CALL errore ('readfc','wrong data read',na) END DO CALL mp_bcast(ityp,ionode_id, world_comm) CALL mp_bcast(tau,ionode_id, world_comm) ! ! read macroscopic variable ! IF (ionode) READ (1,*) has_zstar CALL mp_bcast(has_zstar,ionode_id, world_comm) IF (has_zstar) THEN IF (ionode) READ(1,*) ((epsil(i,j),j=1,3),i=1,3) CALL mp_bcast(epsil,ionode_id, world_comm) IF (ionode) THEN DO na=1,nat READ(1,*) READ(1,*) ((zeu(i,j,na),j=1,3),i=1,3) END DO ENDIF CALL mp_bcast(zeu,ionode_id, world_comm) ELSE zeu (:,:,:) = 0.d0 epsil(:,:) = 0.d0 END IF ! IF (ionode) READ (1,*) nr1,nr2,nr3 CALL mp_bcast(nr1,ionode_id, world_comm) CALL mp_bcast(nr2,ionode_id, world_comm) CALL mp_bcast(nr3,ionode_id, world_comm) ! ! read real-space interatomic force constants ! ALLOCATE ( frc(nr1,nr2,nr3,3,3,nat,nat) ) frc(:,:,:,:,:,:,:) = 0.d0 DO i=1,3 DO j=1,3 DO na=1,nat DO nb=1,nat IF (ionode) READ (1,*) ibid, jbid, nabid, nbbid CALL mp_bcast(ibid,ionode_id, world_comm) CALL mp_bcast(jbid,ionode_id, world_comm) CALL mp_bcast(nabid,ionode_id, world_comm) CALL mp_bcast(nbbid,ionode_id, world_comm) IF(i .NE.ibid .OR. j .NE.jbid .OR. & na.NE.nabid .OR. nb.NE.nbbid) & CALL errore ('readfc','error in reading',1) IF (ionode) READ (1,*) (((m1bid, m2bid, m3bid, & frc(m1,m2,m3,i,j,na,nb), & m1=1,nr1),m2=1,nr2),m3=1,nr3) CALL mp_bcast(frc(:,:,:,i,j,na,nb),ionode_id, world_comm) END DO END DO END DO END DO ! IF (ionode) CLOSE(unit=1) ! RETURN END SUBROUTINE readfc ! !----------------------------------------------------------------------- SUBROUTINE frc_blk(dyn,q,tau,nat,nr1,nr2,nr3,frc,at,bg,rws,nrws,f_of_q,fd) !----------------------------------------------------------------------- ! calculates the dynamical matrix at q from the (short-range part of the) ! force constants ! USE kinds, ONLY : DP USE constants, ONLY : tpi USE io_global, ONLY : stdout ! IMPLICIT NONE INTEGER nr1, nr2, nr3, nat, n1, n2, n3, nr1_, nr2_, nr3_, & ipol, jpol, na, nb, m1, m2, m3, nint, i,j, nrws, nax COMPLEX(DP) dyn(3,3,nat,nat), f_of_q(3,3,nat,nat) REAL(DP) frc(nr1,nr2,nr3,3,3,nat,nat), tau(3,nat), q(3), arg, & at(3,3), bg(3,3), r(3), weight, r_ws(3), & total_weight, rws(0:3,nrws), alat REAL(DP), EXTERNAL :: wsweight REAL(DP),SAVE,ALLOCATABLE :: wscache(:,:,:,:,:) REAL(DP), ALLOCATABLE :: ttt(:,:,:,:,:), tttx(:,:) LOGICAL,SAVE :: first=.true. LOGICAL :: fd ! nr1_=2*nr1 nr2_=2*nr2 nr3_=2*nr3 FIRST_TIME : IF (first) THEN first=.false. ALLOCATE( wscache(-nr3_:nr3_, -nr2_:nr2_, -nr1_:nr1_, nat,nat) ) DO na=1, nat DO nb=1, nat total_weight=0.0d0 ! ! SUM OVER R VECTORS IN THE SUPERCELL - VERY VERY VERY SAFE RANGE! ! DO n1=-nr1_,nr1_ DO n2=-nr2_,nr2_ DO n3=-nr3_,nr3_ DO i=1, 3 r(i) = n1*at(i,1)+n2*at(i,2)+n3*at(i,3) r_ws(i) = r(i) + tau(i,na)-tau(i,nb) if (fd) r_ws(i) = r(i) + tau(i,nb)-tau(i,na) END DO wscache(n3,n2,n1,nb,na) = wsweight(r_ws,rws,nrws) total_weight=total_weight + wscache(n3,n2,n1,nb,na) ENDDO ENDDO ENDDO IF (ABS(total_weight-nr1*nr2*nr3).GT.1.0d-8) THEN WRITE(stdout,*) na,nb,total_weight CALL errore ('frc_blk','wrong total_weight',1) END IF ENDDO ENDDO ENDIF FIRST_TIME ! ALLOCATE(ttt(3,nat,nr1,nr2,nr3)) ALLOCATE(tttx(3,nat*nr1*nr2*nr3)) ttt(:,:,:,:,:)=0.d0 DO na=1, nat DO nb=1, nat DO n1=-nr1_,nr1_ DO n2=-nr2_,nr2_ DO n3=-nr3_,nr3_ ! ! SUM OVER R VECTORS IN THE SUPERCELL - VERY VERY SAFE RANGE! ! DO i=1, 3 r(i) = n1*at(i,1)+n2*at(i,2)+n3*at(i,3) END DO weight = wscache(n3,n2,n1,nb,na) IF (weight .GT. 0.0d0) THEN ! ! FIND THE VECTOR CORRESPONDING TO R IN THE ORIGINAL CELL ! m1 = MOD(n1+1,nr1) IF(m1.LE.0) m1=m1+nr1 m2 = MOD(n2+1,nr2) IF(m2.LE.0) m2=m2+nr2 m3 = MOD(n3+1,nr3) IF(m3.LE.0) m3=m3+nr3 ! write(*,'(6i4)') n1,n2,n3,m1,m2,m3 ! ! FOURIER TRANSFORM ! do i=1,3 ttt(i,na,m1,m2,m3)=tau(i,na)+m1*at(i,1)+m2*at(i,2)+m3*at(i,3) ttt(i,nb,m1,m2,m3)=tau(i,nb)+m1*at(i,1)+m2*at(i,2)+m3*at(i,3) end do arg = tpi*(q(1)*r(1) + q(2)*r(2) + q(3)*r(3)) DO ipol=1, 3 DO jpol=1, 3 dyn(ipol,jpol,na,nb) = dyn(ipol,jpol,na,nb) + & (frc(m1,m2,m3,ipol,jpol,na,nb)+f_of_q(ipol,jpol,na,nb)) & *CMPLX(COS(arg),-SIN(arg),kind=DP)*weight END DO END DO END IF END DO END DO END DO END DO END DO ! RETURN END SUBROUTINE frc_blk ! !----------------------------------------------------------------------- SUBROUTINE setupmat (q,dyn,nat,at,bg,tau,itau_blk,nsc,alat, & & dyn_blk,nat_blk,at_blk,bg_blk,tau_blk,omega_blk, & & loto_2d, & & epsil,zeu,frc,nr1,nr2,nr3,has_zstar,rws,nrws,na_ifc,f_of_q,fd) !----------------------------------------------------------------------- ! compute the dynamical matrix (the analytic part only) ! USE kinds, ONLY : DP USE constants, ONLY : tpi USE cell_base, ONLY : celldm USE rigid, ONLY : rgd_blk ! IMPLICIT NONE ! ! I/O variables ! INTEGER:: nr1, nr2, nr3, nat, nat_blk, nsc, nrws, itau_blk(nat) REAL(DP) :: q(3), tau(3,nat), at(3,3), bg(3,3), alat, & epsil(3,3), zeu(3,3,nat_blk), rws(0:3,nrws), & frc(nr1,nr2,nr3,3,3,nat_blk,nat_blk) REAL(DP) :: tau_blk(3,nat_blk), at_blk(3,3), bg_blk(3,3), omega_blk COMPLEX(DP) dyn_blk(3,3,nat_blk,nat_blk), f_of_q(3,3,nat,nat) COMPLEX(DP) :: dyn(3,3,nat,nat) LOGICAL :: has_zstar, na_ifc, fd, loto_2d ! ! local variables ! REAL(DP) :: arg COMPLEX(DP) :: cfac(nat) INTEGER :: i,j,k, na,nb, na_blk, nb_blk, iq REAL(DP) :: qp(3), qbid(3,nsc) ! automatic array ! ! CALL q_gen(nsc,qbid,at_blk,bg_blk,at,bg) ! DO iq=1,nsc ! DO k=1,3 qp(k)= q(k) + qbid(k,iq) END DO ! dyn_blk(:,:,:,:) = (0.d0,0.d0) CALL frc_blk (dyn_blk,qp,tau_blk,nat_blk, & & nr1,nr2,nr3,frc,at_blk,bg_blk,rws,nrws,f_of_q,fd) IF (has_zstar .and. .not.na_ifc) & CALL rgd_blk(nr1,nr2,nr3,nat_blk,dyn_blk,qp,tau_blk, & epsil,zeu,bg_blk,omega_blk,celldm(1), loto_2d,+1.d0) ! LOTO 2D added celldm(1)=alat to passed arguments ! DO na=1,nat na_blk = itau_blk(na) DO nb=1,nat nb_blk = itau_blk(nb) ! arg=tpi* ( qp(1) * ( (tau(1,na)-tau_blk(1,na_blk)) - & (tau(1,nb)-tau_blk(1,nb_blk)) ) + & qp(2) * ( (tau(2,na)-tau_blk(2,na_blk)) - & (tau(2,nb)-tau_blk(2,nb_blk)) ) + & qp(3) * ( (tau(3,na)-tau_blk(3,na_blk)) - & (tau(3,nb)-tau_blk(3,nb_blk)) ) ) ! cfac(nb) = CMPLX(COS(arg),SIN(arg),kind=DP)/nsc ! END DO ! nb ! DO i=1,3 DO j=1,3 ! DO nb=1,nat nb_blk = itau_blk(nb) dyn(i,j,na,nb) = dyn(i,j,na,nb) + cfac(nb) * & dyn_blk(i,j,na_blk,nb_blk) END DO ! nb ! END DO ! j END DO ! i END DO ! na ! END DO ! iq ! RETURN END SUBROUTINE setupmat ! ! !---------------------------------------------------------------------- SUBROUTINE set_asr (asr, nr1, nr2, nr3, frc, zeu, nat, ibrav, tau) !----------------------------------------------------------------------- ! USE kinds, ONLY : DP USE io_global, ONLY : stdout ! IMPLICIT NONE CHARACTER (LEN=10), intent(in) :: asr INTEGER, intent(in) :: nr1, nr2, nr3, nat, ibrav REAL(DP), intent(in) :: tau(3,nat) REAL(DP), intent(inout) :: frc(nr1,nr2,nr3,3,3,nat,nat), zeu(3,3,nat) ! INTEGER :: axis, n, i, j, na, nb, n1,n2,n3, m,p,k,l,q,r, i1,j1,na1 REAL(DP) :: zeu_new(3,3,nat) REAL(DP), ALLOCATABLE :: frc_new(:,:,:,:,:,:,:) type vector real(DP),pointer :: vec(:,:,:,:,:,:,:) end type vector ! type (vector) u(6*3*nat) ! These are the "vectors" associated with the sum rules on force-constants ! integer :: u_less(6*3*nat),n_less,i_less ! indices of the vectors u that are not independent to the preceding ones, ! n_less = number of such vectors, i_less = temporary parameter ! integer, allocatable :: ind_v(:,:,:) real(DP), allocatable :: v(:,:) ! These are the "vectors" associated with symmetry conditions, coded by ! indicating the positions (i.e. the seven indices) of the non-zero elements (there ! should be only 2 of them) and the value of that element. We do so in order ! to limit the amount of memory used. ! real(DP), allocatable :: w(:,:,:,:,:,:,:), x(:,:,:,:,:,:,:) ! temporary vectors and parameters real(DP) :: scal,norm2, sum ! real(DP) :: zeu_u(6*3,3,3,nat) ! These are the "vectors" associated with the sum rules on effective charges ! integer :: zeu_less(6*3),nzeu_less,izeu_less ! indices of the vectors zeu_u that are not independent to the preceding ones, ! nzeu_less = number of such vectors, izeu_less = temporary parameter ! real(DP) :: zeu_w(3,3,nat), zeu_x(3,3,nat) ! temporary vectors ! Initialization. n is the number of sum rules to be considered (if asr.ne.'simple') ! and 'axis' is the rotation axis in the case of a 1D system ! (i.e. the rotation axis is (Ox) if axis='1', (Oy) if axis='2' and (Oz) if axis='3') ! if((asr.ne.'simple').and.(asr.ne.'crystal').and.(asr.ne.'one-dim') & .and.(asr.ne.'zero-dim')) then call errore('set_asr','invalid Acoustic Sum Rule:' // asr, 1) endif ! if(asr.eq.'simple') then ! ! Simple Acoustic Sum Rule on effective charges ! do i=1,3 do j=1,3 sum=0.0d0 do na=1,nat sum = sum + zeu(i,j,na) end do do na=1,nat zeu(i,j,na) = zeu(i,j,na) - sum/nat end do end do end do ! ! Simple Acoustic Sum Rule on force constants in real space ! do i=1,3 do j=1,3 do na=1,nat sum=0.0d0 do nb=1,nat do n1=1,nr1 do n2=1,nr2 do n3=1,nr3 sum=sum+frc(n1,n2,n3,i,j,na,nb) end do end do end do end do frc(1,1,1,i,j,na,na) = frc(1,1,1,i,j,na,na) - sum ! write(6,*) ' na, i, j, sum = ',na,i,j,sum end do end do end do ! return ! end if if(asr.eq.'crystal') n=3 if(asr.eq.'one-dim') then ! the direction of periodicity is the rotation axis ! It will work only if the crystal axis considered is one of ! the cartesian axis (typically, ibrav=1, 6 or 8, or 4 along the ! z-direction) if (nr1*nr2*nr3.eq.1) axis=3 if ((nr1.ne.1).and.(nr2*nr3.eq.1)) axis=1 if ((nr2.ne.1).and.(nr1*nr3.eq.1)) axis=2 if ((nr3.ne.1).and.(nr1*nr2.eq.1)) axis=3 if (((nr1.ne.1).and.(nr2.ne.1)).or.((nr2.ne.1).and. & (nr3.ne.1)).or.((nr1.ne.1).and.(nr3.ne.1))) then call errore('set_asr','too many directions of & & periodicity in 1D system',axis) endif if ((ibrav.ne.1).and.(ibrav.ne.6).and.(ibrav.ne.8).and. & ((ibrav.ne.4).or.(axis.ne.3)) ) then write(stdout,*) 'asr: rotational axis may be wrong' endif write(stdout,'("asr rotation axis in 1D system= ",I4)') axis n=4 endif if(asr.eq.'zero-dim') n=6 ! ! Acoustic Sum Rule on effective charges ! ! generating the vectors of the orthogonal of the subspace to project ! the effective charges matrix on ! zeu_u(:,:,:,:)=0.0d0 do i=1,3 do j=1,3 do na=1,nat zeu_new(i,j,na)=zeu(i,j,na) enddo enddo enddo ! p=0 do i=1,3 do j=1,3 ! These are the 3*3 vectors associated with the ! translational acoustic sum rules p=p+1 zeu_u(p,i,j,:)=1.0d0 ! enddo enddo ! if (n.eq.4) then do i=1,3 ! These are the 3 vectors associated with the ! single rotational sum rule (1D system) p=p+1 do na=1,nat zeu_u(p,i,MOD(axis,3)+1,na)=-tau(MOD(axis+1,3)+1,na) zeu_u(p,i,MOD(axis+1,3)+1,na)=tau(MOD(axis,3)+1,na) enddo ! enddo endif ! if (n.eq.6) then do i=1,3 do j=1,3 ! These are the 3*3 vectors associated with the ! three rotational sum rules (0D system - typ. molecule) p=p+1 do na=1,nat zeu_u(p,i,MOD(j,3)+1,na)=-tau(MOD(j+1,3)+1,na) zeu_u(p,i,MOD(j+1,3)+1,na)=tau(MOD(j,3)+1,na) enddo ! enddo enddo endif ! ! Gram-Schmidt orthonormalization of the set of vectors created. ! nzeu_less=0 do k=1,p zeu_w(:,:,:)=zeu_u(k,:,:,:) zeu_x(:,:,:)=zeu_u(k,:,:,:) do q=1,k-1 r=1 do izeu_less=1,nzeu_less if (zeu_less(izeu_less).eq.q) r=0 enddo if (r.ne.0) then call sp_zeu(zeu_x,zeu_u(q,:,:,:),nat,scal) zeu_w(:,:,:) = zeu_w(:,:,:) - scal* zeu_u(q,:,:,:) endif enddo call sp_zeu(zeu_w,zeu_w,nat,norm2) if (norm2.gt.1.0d-16) then zeu_u(k,:,:,:) = zeu_w(:,:,:) / DSQRT(norm2) else nzeu_less=nzeu_less+1 zeu_less(nzeu_less)=k endif enddo ! ! Projection of the effective charge "vector" on the orthogonal of the ! subspace of the vectors verifying the sum rules ! zeu_w(:,:,:)=0.0d0 do k=1,p r=1 do izeu_less=1,nzeu_less if (zeu_less(izeu_less).eq.k) r=0 enddo if (r.ne.0) then zeu_x(:,:,:)=zeu_u(k,:,:,:) call sp_zeu(zeu_x,zeu_new,nat,scal) zeu_w(:,:,:) = zeu_w(:,:,:) + scal*zeu_u(k,:,:,:) endif enddo ! ! Final substraction of the former projection to the initial zeu, to get ! the new "projected" zeu ! zeu_new(:,:,:)=zeu_new(:,:,:) - zeu_w(:,:,:) call sp_zeu(zeu_w,zeu_w,nat,norm2) write(stdout,'("Norm of the difference between old and new effective ", & & "charges: ",F25.20)') SQRT(norm2) ! ! Check projection ! !write(6,'("Check projection of zeu")') !do k=1,p ! zeu_x(:,:,:)=zeu_u(k,:,:,:) ! call sp_zeu(zeu_x,zeu_new,nat,scal) ! if (DABS(scal).gt.1d-10) write(6,'("k= ",I8," zeu_new|zeu_u(k)= ",F15.10)') k,scal !enddo ! do i=1,3 do j=1,3 do na=1,nat zeu(i,j,na)=zeu_new(i,j,na) enddo enddo enddo ! ! Acoustic Sum Rule on force constants ! ! ! generating the vectors of the orthogonal of the subspace to project ! the force-constants matrix on ! do k=1,18*nat allocate(u(k) % vec(nr1,nr2,nr3,3,3,nat,nat)) u(k) % vec (:,:,:,:,:,:,:)=0.0d0 enddo ALLOCATE (frc_new(nr1,nr2,nr3,3,3,nat,nat)) do i=1,3 do j=1,3 do na=1,nat do nb=1,nat do n1=1,nr1 do n2=1,nr2 do n3=1,nr3 frc_new(n1,n2,n3,i,j,na,nb)=frc(n1,n2,n3,i,j,na,nb) enddo enddo enddo enddo enddo enddo enddo ! p=0 do i=1,3 do j=1,3 do na=1,nat ! These are the 3*3*nat vectors associated with the ! translational acoustic sum rules p=p+1 u(p) % vec (:,:,:,i,j,na,:)=1.0d0 ! enddo enddo enddo ! if (n.eq.4) then do i=1,3 do na=1,nat ! These are the 3*nat vectors associated with the ! single rotational sum rule (1D system) p=p+1 do nb=1,nat u(p) % vec (:,:,:,i,MOD(axis,3)+1,na,nb)=-tau(MOD(axis+1,3)+1,nb) u(p) % vec (:,:,:,i,MOD(axis+1,3)+1,na,nb)=tau(MOD(axis,3)+1,nb) enddo ! enddo enddo endif ! if (n.eq.6) then do i=1,3 do j=1,3 do na=1,nat ! These are the 3*3*nat vectors associated with the ! three rotational sum rules (0D system - typ. molecule) p=p+1 do nb=1,nat u(p) % vec (:,:,:,i,MOD(j,3)+1,na,nb)=-tau(MOD(j+1,3)+1,nb) u(p) % vec (:,:,:,i,MOD(j+1,3)+1,na,nb)=tau(MOD(j,3)+1,nb) enddo ! enddo enddo enddo endif ! allocate (ind_v(9*nat*nat*nr1*nr2*nr3,2,7), v(9*nat*nat*nr1*nr2*nr3,2) ) m=0 do i=1,3 do j=1,3 do na=1,nat do nb=1,nat do n1=1,nr1 do n2=1,nr2 do n3=1,nr3 ! These are the vectors associated with the symmetry constraints q=1 l=1 do while((l.le.m).and.(q.ne.0)) if ((ind_v(l,1,1).eq.n1).and.(ind_v(l,1,2).eq.n2).and. & (ind_v(l,1,3).eq.n3).and.(ind_v(l,1,4).eq.i).and. & (ind_v(l,1,5).eq.j).and.(ind_v(l,1,6).eq.na).and. & (ind_v(l,1,7).eq.nb)) q=0 if ((ind_v(l,2,1).eq.n1).and.(ind_v(l,2,2).eq.n2).and. & (ind_v(l,2,3).eq.n3).and.(ind_v(l,2,4).eq.i).and. & (ind_v(l,2,5).eq.j).and.(ind_v(l,2,6).eq.na).and. & (ind_v(l,2,7).eq.nb)) q=0 l=l+1 enddo if ((n1.eq.MOD(nr1+1-n1,nr1)+1).and.(n2.eq.MOD(nr2+1-n2,nr2)+1) & .and.(n3.eq.MOD(nr3+1-n3,nr3)+1).and.(i.eq.j).and.(na.eq.nb)) q=0 if (q.ne.0) then m=m+1 ind_v(m,1,1)=n1 ind_v(m,1,2)=n2 ind_v(m,1,3)=n3 ind_v(m,1,4)=i ind_v(m,1,5)=j ind_v(m,1,6)=na ind_v(m,1,7)=nb v(m,1)=1.0d0/DSQRT(2.0d0) ind_v(m,2,1)=MOD(nr1+1-n1,nr1)+1 ind_v(m,2,2)=MOD(nr2+1-n2,nr2)+1 ind_v(m,2,3)=MOD(nr3+1-n3,nr3)+1 ind_v(m,2,4)=j ind_v(m,2,5)=i ind_v(m,2,6)=nb ind_v(m,2,7)=na v(m,2)=-1.0d0/DSQRT(2.0d0) endif enddo enddo enddo enddo enddo enddo enddo ! ! Gram-Schmidt orthonormalization of the set of vectors created. ! Note that the vectors corresponding to symmetry constraints are already ! orthonormalized by construction. ! n_less=0 allocate (w(nr1,nr2,nr3,3,3,nat,nat), x(nr1,nr2,nr3,3,3,nat,nat)) do k=1,p w(:,:,:,:,:,:,:)=u(k) % vec (:,:,:,:,:,:,:) x(:,:,:,:,:,:,:)=u(k) % vec (:,:,:,:,:,:,:) do l=1,m ! call sp2(x,v(l,:),ind_v(l,:,:),nr1,nr2,nr3,nat,scal) do r=1,2 n1=ind_v(l,r,1) n2=ind_v(l,r,2) n3=ind_v(l,r,3) i=ind_v(l,r,4) j=ind_v(l,r,5) na=ind_v(l,r,6) nb=ind_v(l,r,7) w(n1,n2,n3,i,j,na,nb)=w(n1,n2,n3,i,j,na,nb)-scal*v(l,r) enddo enddo if (k.le.(9*nat)) then na1=MOD(k,nat) if (na1.eq.0) na1=nat j1=MOD((k-na1)/nat,3)+1 i1=MOD((((k-na1)/nat)-j1+1)/3,3)+1 else q=k-9*nat if (n.eq.4) then na1=MOD(q,nat) if (na1.eq.0) na1=nat i1=MOD((q-na1)/nat,3)+1 else na1=MOD(q,nat) if (na1.eq.0) na1=nat j1=MOD((q-na1)/nat,3)+1 i1=MOD((((q-na1)/nat)-j1+1)/3,3)+1 endif endif do q=1,k-1 r=1 do i_less=1,n_less if (u_less(i_less).eq.q) r=0 enddo if (r.ne.0) then call sp3(x,u(q) % vec (:,:,:,:,:,:,:), i1,na1,nr1,nr2,nr3,nat,scal) w(:,:,:,:,:,:,:) = w(:,:,:,:,:,:,:) - scal* u(q) % vec (:,:,:,:,:,:,:) endif enddo call sp1(w,w,nr1,nr2,nr3,nat,norm2) if (norm2.gt.1.0d-16) then u(k) % vec (:,:,:,:,:,:,:) = w(:,:,:,:,:,:,:) / DSQRT(norm2) else n_less=n_less+1 u_less(n_less)=k endif enddo ! ! Projection of the force-constants "vector" on the orthogonal of the ! subspace of the vectors verifying the sum rules and symmetry contraints ! w(:,:,:,:,:,:,:)=0.0d0 do l=1,m call sp2(frc_new,v(l,:),ind_v(l,:,:),nr1,nr2,nr3,nat,scal) do r=1,2 n1=ind_v(l,r,1) n2=ind_v(l,r,2) n3=ind_v(l,r,3) i=ind_v(l,r,4) j=ind_v(l,r,5) na=ind_v(l,r,6) nb=ind_v(l,r,7) w(n1,n2,n3,i,j,na,nb)=w(n1,n2,n3,i,j,na,nb)+scal*v(l,r) enddo enddo do k=1,p r=1 do i_less=1,n_less if (u_less(i_less).eq.k) r=0 enddo if (r.ne.0) then x(:,:,:,:,:,:,:)=u(k) % vec (:,:,:,:,:,:,:) call sp1(x,frc_new,nr1,nr2,nr3,nat,scal) w(:,:,:,:,:,:,:) = w(:,:,:,:,:,:,:) + scal*u(k)%vec(:,:,:,:,:,:,:) endif deallocate(u(k) % vec) enddo ! ! Final substraction of the former projection to the initial frc, to get ! the new "projected" frc ! frc_new(:,:,:,:,:,:,:)=frc_new(:,:,:,:,:,:,:) - w(:,:,:,:,:,:,:) call sp1(w,w,nr1,nr2,nr3,nat,norm2) write(stdout,'("Norm of the difference between old and new force-constants:",& & F25.20)') SQRT(norm2) ! ! Check projection ! !write(6,'("Check projection IFC")') !do l=1,m ! call sp2(frc_new,v(l,:),ind_v(l,:,:),nr1,nr2,nr3,nat,scal) ! if (DABS(scal).gt.1d-10) write(6,'("l= ",I8," frc_new|v(l)= ",F15.10)') l,scal !enddo !do k=1,p ! x(:,:,:,:,:,:,:)=u(k) % vec (:,:,:,:,:,:,:) ! call sp1(x,frc_new,nr1,nr2,nr3,nat,scal) ! if (DABS(scal).gt.1d-10) write(6,'("k= ",I8," frc_new|u(k)= ",F15.10)') k,scal ! deallocate(u(k) % vec) !enddo ! do i=1,3 do j=1,3 do na=1,nat do nb=1,nat do n1=1,nr1 do n2=1,nr2 do n3=1,nr3 frc(n1,n2,n3,i,j,na,nb)=frc_new(n1,n2,n3,i,j,na,nb) enddo enddo enddo enddo enddo enddo enddo deallocate (x, w) deallocate (v, ind_v) deallocate (frc_new) ! return end subroutine set_asr ! !---------------------------------------------------------------------- subroutine sp_zeu(zeu_u,zeu_v,nat,scal) !----------------------------------------------------------------------- ! ! does the scalar product of two effective charges matrices zeu_u and zeu_v ! (considered as vectors in the R^(3*3*nat) space, and coded in the usual way) ! USE kinds, ONLY: DP implicit none integer i,j,na,nat real(DP) zeu_u(3,3,nat) real(DP) zeu_v(3,3,nat) real(DP) scal ! ! scal=0.0d0 do i=1,3 do j=1,3 do na=1,nat scal=scal+zeu_u(i,j,na)*zeu_v(i,j,na) enddo enddo enddo ! return ! end subroutine sp_zeu ! ! !---------------------------------------------------------------------- subroutine sp1(u,v,nr1,nr2,nr3,nat,scal) !----------------------------------------------------------------------- ! ! does the scalar product of two force-constants matrices u and v (considered as ! vectors in the R^(3*3*nat*nat*nr1*nr2*nr3) space, and coded in the usual way) ! USE kinds, ONLY: DP implicit none integer nr1,nr2,nr3,i,j,na,nb,n1,n2,n3,nat real(DP) u(nr1,nr2,nr3,3,3,nat,nat) real(DP) v(nr1,nr2,nr3,3,3,nat,nat) real(DP) scal ! ! scal=0.0d0 do i=1,3 do j=1,3 do na=1,nat do nb=1,nat do n1=1,nr1 do n2=1,nr2 do n3=1,nr3 scal=scal+u(n1,n2,n3,i,j,na,nb)*v(n1,n2,n3,i,j,na,nb) enddo enddo enddo enddo enddo enddo enddo ! return ! end subroutine sp1 ! !---------------------------------------------------------------------- subroutine sp2(u,v,ind_v,nr1,nr2,nr3,nat,scal) !----------------------------------------------------------------------- ! ! does the scalar product of two force-constants matrices u and v (considered as ! vectors in the R^(3*3*nat*nat*nr1*nr2*nr3) space). u is coded in the usual way ! but v is coded as explained when defining the vectors corresponding to the ! symmetry constraints ! USE kinds, ONLY: DP implicit none integer nr1,nr2,nr3,i,nat real(DP) u(nr1,nr2,nr3,3,3,nat,nat) integer ind_v(2,7) real(DP) v(2) real(DP) scal ! ! scal=0.0d0 do i=1,2 scal=scal+u(ind_v(i,1),ind_v(i,2),ind_v(i,3),ind_v(i,4),ind_v(i,5),ind_v(i,6), & ind_v(i,7))*v(i) enddo ! return ! end subroutine sp2 ! !---------------------------------------------------------------------- subroutine sp3(u,v,i,na,nr1,nr2,nr3,nat,scal) !----------------------------------------------------------------------- ! ! like sp1, but in the particular case when u is one of the u(k)%vec ! defined in set_asr (before orthonormalization). In this case most of the ! terms are zero (the ones that are not are characterized by i and na), so ! that a lot of computer time can be saved (during Gram-Schmidt). ! USE kinds, ONLY: DP implicit none integer nr1,nr2,nr3,i,j,na,nb,n1,n2,n3,nat real(DP) u(nr1,nr2,nr3,3,3,nat,nat) real(DP) v(nr1,nr2,nr3,3,3,nat,nat) real(DP) scal ! ! scal=0.0d0 do j=1,3 do nb=1,nat do n1=1,nr1 do n2=1,nr2 do n3=1,nr3 scal=scal+u(n1,n2,n3,i,j,na,nb)*v(n1,n2,n3,i,j,na,nb) enddo enddo enddo enddo enddo ! return ! end subroutine sp3 ! !----------------------------------------------------------------------- SUBROUTINE q_gen(nsc,qbid,at_blk,bg_blk,at,bg) !----------------------------------------------------------------------- ! generate list of q (qbid) that are G-vectors of the supercell ! but not of the bulk ! USE kinds, ONLY : DP ! IMPLICIT NONE INTEGER :: nsc REAL(DP) qbid(3,nsc), at_blk(3,3), bg_blk(3,3), at(3,3), bg(3,3) ! INTEGER, PARAMETER:: nr1=4, nr2=4, nr3=4, & nrm=(2*nr1+1)*(2*nr2+1)*(2*nr3+1) REAL(DP), PARAMETER:: eps=1.0d-7 INTEGER :: i, j, k,i1, i2, i3, idum(nrm), iq REAL(DP) :: qnorm(nrm), qbd(3,nrm) ,qwork(3), delta LOGICAL lbho ! i = 0 DO i1=-nr1,nr1 DO i2=-nr2,nr2 DO i3=-nr3,nr3 i = i + 1 DO j=1,3 qwork(j) = i1*bg(j,1) + i2*bg(j,2) + i3*bg(j,3) END DO ! j ! qnorm(i) = qwork(1)**2 + qwork(2)**2 + qwork(3)**2 ! DO j=1,3 ! qbd(j,i) = at_blk(1,j)*qwork(1) + & at_blk(2,j)*qwork(2) + & at_blk(3,j)*qwork(3) END DO ! j ! idum(i) = 1 ! END DO ! i3 END DO ! i2 END DO ! i1 ! DO i=1,nrm-1 IF (idum(i).EQ.1) THEN DO j=i+1,nrm IF (idum(j).EQ.1) THEN lbho=.TRUE. DO k=1,3 delta = qbd(k,i)-qbd(k,j) lbho = lbho.AND. (ABS(NINT(delta)-delta).LT.eps) END DO ! k IF (lbho) THEN IF(qnorm(i).GT.qnorm(j)) THEN qbd(1,i) = qbd(1,j) qbd(2,i) = qbd(2,j) qbd(3,i) = qbd(3,j) qnorm(i) = qnorm(j) END IF idum(j) = 0 END IF END IF END DO ! j END IF END DO ! i ! iq = 0 DO i=1,nrm IF (idum(i).EQ.1) THEN iq=iq+1 qbid(1,iq)= bg_blk(1,1)*qbd(1,i) + & bg_blk(1,2)*qbd(2,i) + & bg_blk(1,3)*qbd(3,i) qbid(2,iq)= bg_blk(2,1)*qbd(1,i) + & bg_blk(2,2)*qbd(2,i) + & bg_blk(2,3)*qbd(3,i) qbid(3,iq)= bg_blk(3,1)*qbd(1,i) + & bg_blk(3,2)*qbd(2,i) + & bg_blk(3,3)*qbd(3,i) END IF END DO ! i ! IF (iq.NE.nsc) CALL errore('q_gen',' probably nr1,nr2,nr3 too small ', iq) RETURN END SUBROUTINE q_gen ! !----------------------------------------------------------------------- SUBROUTINE check_at(at,bg_blk,alat,omega) !----------------------------------------------------------------------- ! USE kinds, ONLY : DP USE io_global, ONLY : stdout ! IMPLICIT NONE ! REAL(DP) :: at(3,3), bg_blk(3,3), alat, omega REAL(DP) :: work(3,3) INTEGER :: i,j REAL(DP), PARAMETER :: small=1.d-6 ! work(:,:) = at(:,:) CALL cryst_to_cart(3,work,bg_blk,-1) ! DO j=1,3 DO i =1,3 IF ( ABS(work(i,j)-NINT(work(i,j))) > small) THEN WRITE (stdout,'(3f9.4)') work(:,:) CALL errore ('check_at','at not multiple of at_blk',1) END IF END DO END DO ! omega =alat**3 * ABS(at(1,1)*(at(2,2)*at(3,3)-at(3,2)*at(2,3))- & at(1,2)*(at(2,1)*at(3,3)-at(2,3)*at(3,1))+ & at(1,3)*(at(2,1)*at(3,2)-at(2,2)*at(3,1))) ! RETURN END SUBROUTINE check_at ! !----------------------------------------------------------------------- SUBROUTINE set_tau (nat, nat_blk, at, at_blk, tau, tau_blk, & ityp, ityp_blk, itau_blk) !----------------------------------------------------------------------- ! USE kinds, ONLY : DP ! IMPLICIT NONE INTEGER nat, nat_blk,ityp(nat),ityp_blk(nat_blk), itau_blk(nat) REAL(DP) at(3,3),at_blk(3,3),tau(3,nat),tau_blk(3,nat_blk) ! REAL(DP) bg(3,3), r(3) ! work vectors INTEGER i,i1,i2,i3,na,na_blk REAL(DP) small INTEGER NN1,NN2,NN3 PARAMETER (NN1=8, NN2=8, NN3=8, small=1.d-8) ! CALL recips (at(1,1),at(1,2),at(1,3),bg(1,1),bg(1,2),bg(1,3)) ! na = 0 ! DO i1 = -NN1,NN1 DO i2 = -NN2,NN2 DO i3 = -NN3,NN3 r(1) = i1*at_blk(1,1) + i2*at_blk(1,2) + i3*at_blk(1,3) r(2) = i1*at_blk(2,1) + i2*at_blk(2,2) + i3*at_blk(2,3) r(3) = i1*at_blk(3,1) + i2*at_blk(3,2) + i3*at_blk(3,3) CALL cryst_to_cart(1,r,bg,-1) ! IF ( r(1).GT.-small .AND. r(1).LT.1.d0-small .AND. & r(2).GT.-small .AND. r(2).LT.1.d0-small .AND. & r(3).GT.-small .AND. r(3).LT.1.d0-small ) THEN CALL cryst_to_cart(1,r,at,+1) ! DO na_blk=1, nat_blk na = na + 1 IF (na.GT.nat) CALL errore('set_tau','too many atoms',na) tau(1,na) = tau_blk(1,na_blk) + r(1) tau(2,na) = tau_blk(2,na_blk) + r(2) tau(3,na) = tau_blk(3,na_blk) + r(3) ityp(na) = ityp_blk(na_blk) itau_blk(na) = na_blk END DO ! END IF ! END DO END DO END DO ! IF (na.NE.nat) CALL errore('set_tau','too few atoms: increase NNs',na) ! RETURN END SUBROUTINE set_tau ! !----------------------------------------------------------------------- SUBROUTINE read_tau & (nat, nat_blk, ntyp, bg_blk, tau, tau_blk, ityp, itau_blk) !--------------------------------------------------------------------- ! USE kinds, ONLY : DP USE io_global, ONLY : ionode_id, ionode USE mp, ONLY : mp_bcast USE mp_world, ONLY : world_comm ! IMPLICIT NONE ! INTEGER nat, nat_blk, ntyp, ityp(nat),itau_blk(nat) REAL(DP) bg_blk(3,3),tau(3,nat),tau_blk(3,nat_blk) ! REAL(DP) r(3) ! work vectors INTEGER i,na,na_blk ! REAL(DP) small PARAMETER ( small = 1.d-6 ) ! DO na=1,nat IF (ionode) READ(5,*) (tau(i,na),i=1,3), ityp(na) CALL mp_bcast(tau(:,na),ionode_id, world_comm) CALL mp_bcast(ityp(na),ionode_id, world_comm) IF (ityp(na).LE.0 .OR. ityp(na) .GT. ntyp) & CALL errore('read_tau',' wrong atomic type', na) DO na_blk=1,nat_blk r(1) = tau(1,na) - tau_blk(1,na_blk) r(2) = tau(2,na) - tau_blk(2,na_blk) r(3) = tau(3,na) - tau_blk(3,na_blk) CALL cryst_to_cart(1,r,bg_blk,-1) IF (ABS( r(1)-NINT(r(1)) ) .LT. small .AND. & ABS( r(2)-NINT(r(2)) ) .LT. small .AND. & ABS( r(3)-NINT(r(3)) ) .LT. small ) THEN itau_blk(na) = na_blk go to 999 END IF END DO CALL errore ('read_tau',' wrong atomic position ', na) 999 CONTINUE END DO ! RETURN END SUBROUTINE read_tau ! !----------------------------------------------------------------------- SUBROUTINE write_tau(fltau,nat,tau,ityp) !----------------------------------------------------------------------- ! USE kinds, ONLY : DP USE io_global, ONLY : ionode ! IMPLICIT NONE ! INTEGER nat, ityp(nat) REAL(DP) tau(3,nat) CHARACTER(LEN=*) fltau ! INTEGER i,na ! IF (.NOT.ionode) RETURN OPEN (unit=4,file=fltau, status='new') DO na=1,nat WRITE(4,'(3(f12.6),i3)') (tau(i,na),i=1,3), ityp(na) END DO CLOSE (4) ! RETURN END SUBROUTINE write_tau ! !----------------------------------------------------------------------- SUBROUTINE gen_qpoints (ibrav, at_, bg_, nat, tau, ityp, nk1, nk2, nk3, & nqx, nq, q, nosym, wk) !----------------------------------------------------------------------- ! USE kinds, ONLY : DP USE cell_base, ONLY : at, bg USE symm_base, ONLY : set_sym_bl, find_sym, s, irt, nsym, & nrot, t_rev, time_reversal, sname USE ktetra, ONLY : tetra_init ! IMPLICIT NONE ! input INTEGER :: ibrav, nat, nk1, nk2, nk3, ityp(*) REAL(DP) :: at_(3,3), bg_(3,3), tau(3,nat) LOGICAL :: nosym ! output INTEGER :: nqx, nq REAL(DP) :: q(3,nqx), wk(nqx) ! local REAL(DP) :: xqq(3), mdum(3,nat) LOGICAL :: magnetic_sym=.FALSE., skip_equivalence=.FALSE. ! time_reversal = .true. if (nosym) time_reversal = .false. t_rev(:) = 0 xqq (:) =0.d0 at = at_ bg = bg_ CALL set_sym_bl ( ) ! if (nosym) then nrot = 1 nsym = 1 endif CALL kpoint_grid ( nrot, time_reversal, skip_equivalence, s, t_rev, bg, nqx, & 0,0,0, nk1,nk2,nk3, nq, q, wk) ! CALL find_sym ( nat, tau, ityp, .not.time_reversal, mdum ) ! CALL irreducible_BZ (nrot, s, nsym, time_reversal, magnetic_sym, & at, bg, nqx, nq, q, wk, t_rev) ! CALL tetra_init (nsym, s, time_reversal, t_rev, at, bg, nqx, 0, 0, 0, & nk1, nk2, nk3, nq, q) ! RETURN END SUBROUTINE gen_qpoints ! !--------------------------------------------------------------------- SUBROUTINE a2Fdos & (nat, nq, nr1, nr2, nr3, ibrav, at, bg, tau, alat, & nsc, nat_blk, at_blk, bg_blk, itau_blk, omega_blk, rws, nrws, & dos, Emin, DeltaE, ndos, asr, q, freq,fd, wq ) !----------------------------------------------------------------------- ! USE kinds, ONLY : DP USE io_global, ONLY : ionode, ionode_id USE mp, ONLY : mp_bcast USE mp_world, ONLY : world_comm USE mp_images, ONLY : intra_image_comm USE ifconstants, ONLY : zeu, tau_blk USE constants, ONLY : pi, RY_TO_THZ USE constants, ONLY : K_BOLTZMANN_RY USE el_phon, ONLY : el_ph_nsigma ! IMPLICIT NONE ! INTEGER, INTENT(in) :: nat, nq, nr1, nr2, nr3, ibrav, ndos LOGICAL, INTENT(in) :: dos,fd CHARACTER(LEN=*), INTENT(IN) :: asr REAL(DP), INTENT(in) :: freq(3*nat,nq), q(3,nq), wq(nq), at(3,3), bg(3,3), & tau(3,nat), alat, Emin, DeltaE ! INTEGER, INTENT(in) :: nsc, nat_blk, itau_blk(nat), nrws REAL(DP), INTENT(in) :: rws(0:3,nrws), at_blk(3,3), bg_blk(3,3), omega_blk ! REAL(DP), ALLOCATABLE :: gamma(:,:), frcg(:,:,:,:,:,:,:) COMPLEX(DP), ALLOCATABLE :: gam(:,:,:,:), gam_blk(:,:,:,:), z(:,:) real(DP) :: lambda, dos_a2F(3*nat), temp, dos_ee(el_ph_nsigma), dos_tot, & deg(el_ph_nsigma), fermi(el_ph_nsigma), E real(DP), parameter :: eps_w2 = 0.0000001d0 integer :: isig, ifn, n, m, na, nb, nc, nu, nmodes, & i,j,k, ngauss, jsig, p1, p2, p3, filea2F, ios character(len=256) :: name real(DP), external :: dos_gam CHARACTER(LEN=6) :: int_to_char ! ! nmodes = 3*nat do isig=1,el_ph_nsigma filea2F = 60 + isig name= 'elph_dir/a2Fmatdyn.' // TRIM(int_to_char(filea2F)) IF (ionode) open(unit=filea2F, file=TRIM(name), & STATUS = 'unknown', IOSTAT=ios) CALL mp_bcast(ios, ionode_id, intra_image_comm) IF (ios /= 0) CALL errore('a2Fdos','problem opening file'//TRIM(name),1) IF (ionode) & READ(filea2F,*) deg(isig), fermi(isig), dos_ee(isig) ENDDO call mp_bcast(deg, ionode_id, intra_image_comm) call mp_bcast(fermi, ionode_id, intra_image_comm) call mp_bcast(dos_ee, ionode_id, intra_image_comm) ! IF (ionode) THEN IF(dos) then open(unit=400,file='lambda',status='unknown') write(400,*) write(400,*) ' Electron-phonon coupling constant, lambda ' write(400,*) ELSE open (unit=20,file='gam.lines' ,status='unknown') write(20,*) write(20,*) ' Gamma lines for all modes [THz] ' write(20,*) write(6,*) write(6,*) ' Gamma lines for all modes [Rydberg] ' write(6,*) ENDIF ENDIF ! ALLOCATE ( frcg(nr1,nr2,nr3,3,3,nat,nat) ) ALLOCATE ( gamma(3*nat,nq), gam(3,3,nat,nat), gam_blk(3,3,nat_blk,nat_blk) ) ALLOCATE ( z(3*nat,3*nat) ) ! frcg(:,:,:,:,:,:,:) = 0.d0 DO isig = 1, el_ph_nsigma filea2F = 60 + isig CALL readfg ( filea2F, nr1, nr2, nr3, nat, frcg ) ! if ( asr /= 'no') then CALL set_asr (asr, nr1, nr2, nr3, frcg, zeu, nat_blk, ibrav, tau_blk) endif ! IF (ionode) open(unit=300,file='dyna2F',status='old') ! do n = 1 ,nq gam(:,:,:,:) = (0.d0, 0.d0) IF (ionode) THEN read(300,*) do na=1,nmodes read(300,*) (z(na,m),m=1,nmodes) end do ! na ENDIF CALL mp_bcast(z, ionode_id, world_comm) ! CALL setgam (q(1,n), gam, nat, at, bg, tau, itau_blk, nsc, alat, & gam_blk, nat_blk, at_blk,bg_blk,tau_blk, omega_blk, & frcg, nr1,nr2,nr3, rws, nrws, fd) ! ! here multiply dyn*gam*dyn for gamma and divide by w2 for lambda at given q ! do nc = 1, nat do k =1, 3 p1 = (nc-1)*3+k nu = p1 gamma(nu,n) = 0.0d0 do i=1,3 do na=1,nat p2 = (na-1)*3+i do j=1,3 do nb=1,nat p3 = (nb-1)*3+j gamma(nu,n) = gamma(nu,n) + DBLE(conjg(z(p2,p1)) * & gam(i,j,na,nb) * z(p3,p1)) enddo ! nb enddo ! j enddo ! na enddo !i gamma(nu,n) = gamma(nu,n) * pi / 2.0d0 enddo ! k enddo !nc ! ! EndDo !nq all points in BZ IF (ionode) close(300) ! file with dyn vectors ! ! after we know gamma(q) and lambda(q) calculate DOS(omega) for spectrum a2F ! if(dos.and.ionode) then ! name='a2F.dos'//int_to_char(isig) ifn = 200 + isig open (ifn,file=TRIM(name),status='unknown',form='formatted') write(ifn,*) write(ifn,*) '# Eliashberg function a2F (per both spin)' write(ifn,*) '# frequencies in Rydberg ' write(ifn,*) '# DOS normalized to E in Rydberg: a2F_total, a2F(mode) ' write(ifn,*) ! ! correction for small frequencies ! do n = 1, nq do i = 1, nmodes if (freq(i,n).LE.eps_w2) then gamma(i,n) = 0.0d0 endif enddo enddo ! lambda = 0.0d0 do n= 1, ndos ! E = Emin + (n-1)*DeltaE + 0.5d0*DeltaE dos_tot = 0.0d0 do j=1,nmodes ! dos_a2F(j) = dos_gam(nmodes, nq, j, gamma, freq, E) dos_a2F(j) = dos_a2F(j) / dos_ee(isig) / 2.d0 / pi dos_tot = dos_tot + dos_a2F(j) ! enddo lambda = lambda + 2.d0 * dos_tot/E * DeltaE write (ifn, '(3X,1000E16.6)') E, dos_tot, dos_a2F(1:nmodes) enddo !ndos write(ifn,*) " lambda =",lambda,' Delta = ',DeltaE close (ifn) ! ! lambda from alternative way, simple sum. ! Also Omega_ln is computed ! lambda = 0.0_dp E = 0.0_dp do n = 1, nq lambda = lambda & & + sum(gamma(1:nmodes,n)/freq(1:nmodes,n)**2, & & freq(1:nmodes,n) > 1.0e-5_dp) * wq(n) E = E & & + sum(log(freq(1:nmodes,n)) * gamma(1:nmodes,n)/freq(1:nmodes,n)**2, & & freq(1:nmodes,n) > 1.0e-5_dp) * wq(n) end do E = exp(E / lambda) / K_BOLTZMANN_RY lambda = lambda / (dos_ee(isig) * pi) write(400,'(" Broadening ",F8.4," lambda ",F12.4," dos(Ef)",F8.4," omega_ln [K]",F12.4)') & deg(isig),lambda, dos_ee(isig), E ! endif !dos ! ! OUTPUT ! if(.not.dos.and.ionode) then write(20,'(" Broadening ",F8.4)') deg(isig) write( 6,'(" Broadening ",F8.4)') deg(isig) do n=1, nq write(20,'(3x,i5)') n write( 6,'(3x,i5)') n write(20,'(9F8.4)') (gamma(i,n)*RY_TO_THZ,i=1,3*nat) write( 6,'(6F12.9)') (gamma(i,n),i=1,3*nat) ! ! write also in a format that can be read by plotband ! WRITE(200+isig, '(10x,3f10.6)') q(1,n), q(2,n), q(3,n) ! ! output in GHz ! WRITE(200+isig, '(6f10.4)') (gamma(nu,n)*RY_TO_THZ*1000.0_DP, & nu=1,3*nat) end do endif ! ENDDO !isig ! DEALLOCATE (z, frcg, gamma, gam, gam_blk ) ! IF (ionode) THEN close(400) !lambda close(20) ENDIF ! ! RETURN END SUBROUTINE a2Fdos ! !----------------------------------------------------------------------- subroutine setgam (q, gam, nat, at,bg,tau,itau_blk,nsc,alat, & & gam_blk, nat_blk, at_blk,bg_blk,tau_blk,omega_blk, & & frcg, nr1,nr2,nr3, rws,nrws, fd) !----------------------------------------------------------------------- ! compute the dynamical matrix (the analytic part only) ! USE kinds, ONLY : DP USE constants, ONLY : tpi implicit none ! ! I/O variables ! integer :: nr1, nr2, nr3, nat, nat_blk, & nsc, nrws, itau_blk(nat) real(DP) :: q(3), tau(3,nat), at(3,3), bg(3,3), alat, rws(0:3,nrws) real(DP) :: tau_blk(3,nat_blk), at_blk(3,3), bg_blk(3,3), omega_blk, & frcg(nr1,nr2,nr3,3,3,nat_blk,nat_blk) COMPLEX(DP) :: gam_blk(3,3,nat_blk,nat_blk),f_of_q(3,3,nat,nat) COMPLEX(DP) :: gam(3,3,nat,nat) LOGICAL :: fd ! ! local variables ! real(DP) :: arg complex(DP) :: cfac(nat) integer :: i,j,k, na,nb, na_blk, nb_blk, iq real(DP) :: qp(3), qbid(3,nsc) ! automatic array ! ! call q_gen(nsc,qbid,at_blk,bg_blk,at,bg) ! f_of_q=(0.0_DP,0.0_DP) do iq=1,nsc ! do k=1,3 qp(k)= q(k) + qbid(k,iq) end do ! gam_blk(:,:,:,:) = (0.d0,0.d0) CALL frc_blk (gam_blk,qp,tau_blk,nat_blk, & nr1,nr2,nr3,frcg,at_blk,bg_blk,rws,nrws,f_of_q,fd) ! do na=1,nat na_blk = itau_blk(na) do nb=1,nat nb_blk = itau_blk(nb) ! arg = tpi * ( qp(1) * ( (tau(1,na)-tau_blk(1,na_blk)) - & (tau(1,nb)-tau_blk(1,nb_blk)) ) + & qp(2) * ( (tau(2,na)-tau_blk(2,na_blk)) - & (tau(2,nb)-tau_blk(2,nb_blk)) ) + & qp(3) * ( (tau(3,na)-tau_blk(3,na_blk)) - & (tau(3,nb)-tau_blk(3,nb_blk)) ) ) ! cfac(nb) = CMPLX(cos(arg),sin(arg), kind=dp)/nsc ! end do ! nb do nb=1,nat do i=1,3 do j=1,3 nb_blk = itau_blk(nb) gam(i,j,na,nb) = gam(i,j,na,nb) + cfac(nb) * & gam_blk(i,j,na_blk,nb_blk) end do ! j end do ! i end do ! nb end do ! na ! end do ! iq ! return end subroutine setgam ! !-------------------------------------------------------------------- function dos_gam (nbndx, nq, jbnd, gamma, et, ef) !-------------------------------------------------------------------- ! calculates weights with the tetrahedron method (Bloechl version) ! this subroutine is based on tweights.f90 belonging to PW ! it calculates a2F on the surface of given frequency <=> histogram ! Band index means the frequency mode here ! and "et" means the frequency(mode,q-point) ! USE kinds, ONLY: DP USE parameters USE ktetra, ONLY : ntetra, tetra implicit none ! integer :: nq, nbndx, jbnd real(DP) :: et(nbndx,nq), gamma(nbndx,nq), func real(DP) :: ef real(DP) :: e1, e2, e3, e4, c1, c2, c3, c4, etetra(4) integer :: ik, ibnd, nt, nk, ns, i, ik1, ik2, ik3, ik4, itetra(4) real(DP) :: f12,f13,f14,f23,f24,f34, f21,f31,f41,f42,f32,f43 real(DP) :: P1,P2,P3,P4, G, o13, Y1,Y2,Y3,Y4, eps,vol, Tint real(DP) :: dos_gam Tint = 0.0d0 o13 = 1.0_dp/3.0_dp eps = 1.0d-14 vol = 1.0d0/ntetra P1 = 0.0_dp P2 = 0.0_dp P3 = 0.0_dp P4 = 0.0_dp do nt = 1, ntetra ibnd = jbnd ! ! etetra are the energies at the vertexes of the nt-th tetrahedron ! do i = 1, 4 etetra(i) = et(ibnd, tetra(i,nt)) enddo itetra(1) = 0 call hpsort (4,etetra,itetra) ! ! ...sort in ascending order: e1 < e2 < e3 < e4 ! e1 = etetra (1) e2 = etetra (2) e3 = etetra (3) e4 = etetra (4) ! ! kp1-kp4 are the irreducible k-points corresponding to e1-e4 ! ik1 = tetra(itetra(1),nt) ik2 = tetra(itetra(2),nt) ik3 = tetra(itetra(3),nt) ik4 = tetra(itetra(4),nt) Y1 = gamma(ibnd,ik1)/et(ibnd,ik1) Y2 = gamma(ibnd,ik2)/et(ibnd,ik2) Y3 = gamma(ibnd,ik3)/et(ibnd,ik3) Y4 = gamma(ibnd,ik4)/et(ibnd,ik4) IF ( e3 < ef .and. ef < e4) THEN f14 = (ef-e4)/(e1-e4) f24 = (ef-e4)/(e2-e4) f34 = (ef-e4)/(e3-e4) G = 3.0_dp * f14 * f24 * f34 / (e4-ef) P1 = f14 * o13 P2 = f24 * o13 P3 = f34 * o13 P4 = (3.0_dp - f14 - f24 - f34 ) * o13 ELSE IF ( e2 < ef .and. ef < e3 ) THEN f13 = (ef-e3)/(e1-e3) f31 = 1.0_dp - f13 f14 = (ef-e4)/(e1-e4) f41 = 1.0_dp-f14 f23 = (ef-e3)/(e2-e3) f32 = 1.0_dp - f23 f24 = (ef-e4)/(e2-e4) f42 = 1.0_dp - f24 G = 3.0_dp * (f23*f31 + f32*f24) P1 = f14 * o13 + f13*f31*f23 / G P2 = f23 * o13 + f24*f24*f32 / G P3 = f32 * o13 + f31*f31*f23 / G P4 = f41 * o13 + f42*f24*f32 / G G = G / (e4-e1) ELSE IF ( e1 < ef .and. ef < e2 ) THEN f12 = (ef-e2)/(e1-e2) f21 = 1.0_dp - f12 f13 = (ef-e3)/(e1-e3) f31 = 1.0_dp - f13 f14 = (ef-e4)/(e1-e4) f41 = 1.0_dp - f14 G = 3.0_dp * f21 * f31 * f41 / (ef-e1) P1 = o13 * (f12 + f13 + f14) P2 = o13 * f21 P3 = o13 * f31 P4 = o13 * f41 ELSE G = 0.0_dp END IF Tint = Tint + G * (Y1*P1 + Y2*P2 + Y3*P3 + Y4*P4) * vol enddo ! ntetra dos_gam = Tint !2 because DOS_ee is per 1 spin return end function dos_gam ! ! !------------------------------------------------------------------------------ function dos_broad(iatom, nbndx, nq, et, zq, wq, Ef, degauss) !------------------------------------------------------------------------------ ! ! Get atom projected ph DOS using Gaussian broadening. Inspired by ! thermo_pw/src/generalized_phdos.f90 (GPL) ! USE kinds, ONLY : DP ! IMPLICIT NONE INTEGER, INTENT(IN) :: iatom, nq, nbndx REAL(DP), INTENT(IN) :: et(nbndx, nq), zq(nq, nbndx, nbndx), wq(nq), Ef, degauss REAL(DP) :: ufact, weight INTEGER :: n, ik, ngauss, ipol, indi, jpol, indj COMPLEX(DP) :: u1, u2 REAL(DP), EXTERNAL :: w0gauss REAL(DP) :: dos_broad ! dos_broad = 0.0_DP ! ngauss = 0 ! DO ik = 1, nq DO n = 1, nbndx weight = w0gauss ( (Ef - et(n,ik) ) / degauss, ngauss) ! DO ipol=1, 3 indi = 3 * (iatom - 1) + ipol DO jpol = ipol, 3 indj = 3 * (iatom - 1) + jpol u1=zq(ik, indi, n) u2=zq(ik, indj, n) ufact = DBLE(u1*CONJG(u2)) dos_broad = dos_broad + wq(ik) * ufact * weight ENDDO ENDDO ! ENDDO ENDDO ! dos_broad = dos_broad / degauss ! RETURN end function dos_broad ! ! !----------------------------------------------------------------------- subroutine readfg ( ifn, nr1, nr2, nr3, nat, frcg ) !----------------------------------------------------------------------- ! USE kinds, ONLY : DP USE io_global, ONLY : ionode, ionode_id, stdout USE mp, ONLY : mp_bcast USE mp_world, ONLY : world_comm implicit none ! I/O variable integer, intent(in) :: nr1,nr2,nr3, nat real(DP), intent(out) :: frcg(nr1,nr2,nr3,3,3,nat,nat) ! local variables integer i, j, na, nb, m1,m2,m3, ifn integer ibid, jbid, nabid, nbbid, m1bid,m2bid,m3bid ! ! IF (ionode) READ (ifn,*) m1, m2, m3 CALL mp_bcast(m1, ionode_id, world_comm) CALL mp_bcast(m2, ionode_id, world_comm) CALL mp_bcast(m3, ionode_id, world_comm) if ( m1 /= nr1 .or. m2 /= nr2 .or. m3 /= nr3) & call errore('readfg','inconsistent nr1, nr2, nr3 read',1) do i=1,3 do j=1,3 do na=1,nat do nb=1,nat IF (ionode) read (ifn,*) ibid, jbid, nabid, nbbid CALL mp_bcast(ibid, ionode_id, world_comm) CALL mp_bcast(jbid, ionode_id, world_comm) CALL mp_bcast(nabid, ionode_id, world_comm) CALL mp_bcast(nbbid, ionode_id, world_comm) if(i.ne.ibid.or.j.ne.jbid.or.na.ne.nabid.or.nb.ne.nbbid) then write(stdout,*) i,j,na,nb,' <> ', ibid, jbid, nabid, nbbid call errore ('readfG','error in reading',1) else IF (ionode) read (ifn,*) (((m1bid, m2bid, m3bid, & frcg(m1,m2,m3,i,j,na,nb), & m1=1,nr1),m2=1,nr2),m3=1,nr3) endif CALL mp_bcast(frcg(:,:,:,i,j,na,nb), ionode_id, world_comm) end do end do end do end do ! IF (ionode) close(ifn) ! return end subroutine readfg ! ! SUBROUTINE find_representations_mode_q ( nat, ntyp, xq, w2, u, tau, ityp, & amass, num_rap_mode, nspin_mag ) USE kinds, ONLY : DP USE cell_base, ONLY : at, bg USE symm_base, ONLY : s, sr, ft, irt, nsym, nrot, t_rev, time_reversal,& sname, copy_sym, s_axis_to_cart IMPLICIT NONE INTEGER, INTENT(IN) :: nat, ntyp, nspin_mag REAL(DP), INTENT(IN) :: xq(3), amass(ntyp), tau(3,nat) REAL(DP), INTENT(IN) :: w2(3*nat) INTEGER, INTENT(IN) :: ityp(nat) COMPLEX(DP), INTENT(IN) :: u(3*nat,3*nat) INTEGER, INTENT(OUT) :: num_rap_mode(3*nat) REAL(DP) :: gi (3, 48), gimq (3), sr_is(3,3,48), rtau(3,48,nat) INTEGER :: irotmq, nsymq, nsym_is, isym, i, ierr LOGICAL :: minus_q, search_sym, sym(48), magnetic_sym ! ! find the small group of q ! time_reversal=.TRUE. IF (.NOT.time_reversal) minus_q=.FALSE. sym(1:nsym)=.true. call smallg_q (xq, 0, at, bg, nsym, s, sym, minus_q) nsymq=copy_sym(nsym,sym ) call s_axis_to_cart () CALL set_giq (xq,s,nsymq,nsym,irotmq,minus_q,gi,gimq) ! ! if the small group of q is non symmorphic, ! search the symmetries only if there are no G such that Sq -> q+G ! search_sym=.TRUE. IF ( ANY ( ABS(ft(:,1:nsymq)) > 1.0d-8 ) ) THEN DO isym=1,nsymq search_sym=( search_sym.and.(abs(gi(1,isym))<1.d-8).and. & (abs(gi(2,isym))<1.d-8).and. & (abs(gi(3,isym))<1.d-8) ) END DO END IF ! ! Set the representations tables of the small group of q and ! find the mode symmetry ! IF (search_sym) THEN magnetic_sym=(nspin_mag==4) CALL prepare_sym_analysis(nsymq,sr,t_rev,magnetic_sym) sym (1:nsym) = .TRUE. CALL sgam_lr (at, bg, nsym, s, irt, tau, rtau, nat) CALL find_mode_sym_new (u, w2, tau, nat, nsymq, s, sr, irt, xq, & rtau, amass, ntyp, ityp, 1, .FALSE., .FALSE., num_rap_mode, ierr) ENDIF RETURN END SUBROUTINE find_representations_mode_q
gpl-2.0
omni-compiler/omni-compiler
tests/XMP/others/F/block_tasks.F90
2
2051
program tasks !$xmp nodes p(8) #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \ || defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER) blkname1 : block #endif !$xmp tasks !$xmp task on p(1:4) #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \ || defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER) blkname2 : block #endif !$xmp barrier on p #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \ || defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER) end block blkname2 #endif !$xmp end task !$xmp task on p(5:8) !$xmp barrier on p !$xmp end task !$xmp end tasks #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \ || defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER) end block blkname1 #endif #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \ || defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER) blkname3 : block #endif !$xmp tasks !$xmp task on p(1:5) #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \ || defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER) blkname4 : block #endif !$xmp barrier on p #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \ || defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER) end block blkname4 #endif !$xmp end task !$xmp task on p(6:8) #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \ || defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER) blkname5 : block #endif !$xmp barrier on p #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \ || defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER) end block blkname5 #endif !$xmp end task !$xmp end tasks #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \ || defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER) end block blkname3 #endif !$xmp task on p(1) write(*,*) "PASS" !$xmp end task end program tasks
lgpl-3.0
QEF/q-e
GWW/gww/do_contour.f90
12
2077
! ! Copyright (C) 2001-2013 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !this subroutine add to the integral part of the self-energy the poles part SUBROUTINE do_contour(sr,wp,options) !NOT_TO_BE_INCLUDED_START USE contour, ONLY : w_poles, w_poles_value USE kinds, ONLY : DP USE self_energy_storage, ONLY : self_on_real USE basic_structures, ONLY : wannier_u,free_memory, initialize_memory USE input_gw, ONLY : input_options implicit none TYPE(self_on_real), INTENT(inout) :: sr TYPE(w_poles), INTENT(in) :: wp TYPE(input_options), INTENT(in) :: options TYPE(wannier_u) :: uu INTEGER :: ie,jj,ii,is COMPLEX(kind=DP) :: energy !reads KS eigen-energies call read_data_pw_u(uu,options%prefix) !loop on spin do is=1,sr%nspin !loop on real energy grid do ie=1,sr%n energy=sr%grid(ie) !divide by in valence and in conduction case if(dble(energy) <= uu%ene(uu%nums_occ(is),is)) then !consider valece states do jj=sr%i_min,uu%nums_occ(is)!ATTENZIONE !loop on poles !for selected poles add terms if(uu%ene(jj,is)>=dble(energy) )then do ii=sr%i_min,sr%i_max sr%diag(ie,ii,is)=sr%diag(ie,ii,is)-w_poles_value(uu%ene(jj,is)-energy,wp,jj,ii,is)!GIUSTO CUSSI' enddo endif enddo else do jj=uu%nums_occ(is)+1,sr%i_max !loop on poles !for selected poles add terms if(uu%ene(jj,is)<=dble(energy) )then do ii=sr%i_min,sr%i_max sr%diag(ie,ii,is)=sr%diag(ie,ii,is)+w_poles_value(uu%ene(jj,is)-energy,wp,jj,ii,is) enddo endif enddo endif enddo enddo call free_memory(uu) return !NOT_TO_BE_INCLUDED_END END SUBROUTINE do_contour
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/dgeqrt2.f
24
6290
*> \brief \b DGEQRT2 computes a QR factorization of a general real or complex matrix using the compact WY representation of Q. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DGEQRT2 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgeqrt2.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgeqrt2.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgeqrt2.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DGEQRT2( M, N, A, LDA, T, LDT, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, LDT, M, N * .. * .. Array Arguments .. * DOUBLE PRECISION A( LDA, * ), T( LDT, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DGEQRT2 computes a QR factorization of a real M-by-N matrix A, *> using the compact WY representation of Q. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. M >= N. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA,N) *> On entry, the real M-by-N matrix A. On exit, the elements on and *> above the diagonal contain the N-by-N upper triangular matrix R; the *> elements below the diagonal are the columns of V. See below for *> further details. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim *> *> \param[out] T *> \verbatim *> T is DOUBLE PRECISION array, dimension (LDT,N) *> The N-by-N upper triangular factor of the block reflector. *> The elements on and above the diagonal contain the block *> reflector T; the elements below the diagonal are not used. *> See below for further details. *> \endverbatim *> *> \param[in] LDT *> \verbatim *> LDT is INTEGER *> The leading dimension of the array T. LDT >= max(1,N). *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup doubleGEcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> The matrix V stores the elementary reflectors H(i) in the i-th column *> below the diagonal. For example, if M=5 and N=3, the matrix V is *> *> V = ( 1 ) *> ( v1 1 ) *> ( v1 v2 1 ) *> ( v1 v2 v3 ) *> ( v1 v2 v3 ) *> *> where the vi's represent the vectors which define H(i), which are returned *> in the matrix A. The 1's along the diagonal of V are not stored in A. The *> block reflector H is then given by *> *> H = I - V * T * V**T *> *> where V**T is the transpose of V. *> \endverbatim *> * ===================================================================== SUBROUTINE DGEQRT2( M, N, A, LDA, T, LDT, INFO ) * * -- LAPACK computational routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. INTEGER INFO, LDA, LDT, M, N * .. * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ), T( LDT, * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, ZERO PARAMETER( ONE = 1.0D+00, ZERO = 0.0D+00 ) * .. * .. Local Scalars .. INTEGER I, K DOUBLE PRECISION AII, ALPHA * .. * .. External Subroutines .. EXTERNAL DLARFG, DGEMV, DGER, DTRMV, XERBLA * .. * .. Executable Statements .. * * Test the input arguments * INFO = 0 IF( M.LT.0 ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = -4 ELSE IF( LDT.LT.MAX( 1, N ) ) THEN INFO = -6 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DGEQRT2', -INFO ) RETURN END IF * K = MIN( M, N ) * DO I = 1, K * * Generate elem. refl. H(i) to annihilate A(i+1:m,i), tau(I) -> T(I,1) * CALL DLARFG( M-I+1, A( I, I ), A( MIN( I+1, M ), I ), 1, $ T( I, 1 ) ) IF( I.LT.N ) THEN * * Apply H(i) to A(I:M,I+1:N) from the left * AII = A( I, I ) A( I, I ) = ONE * * W(1:N-I) := A(I:M,I+1:N)^H * A(I:M,I) [W = T(:,N)] * CALL DGEMV( 'T',M-I+1, N-I, ONE, A( I, I+1 ), LDA, $ A( I, I ), 1, ZERO, T( 1, N ), 1 ) * * A(I:M,I+1:N) = A(I:m,I+1:N) + alpha*A(I:M,I)*W(1:N-1)^H * ALPHA = -(T( I, 1 )) CALL DGER( M-I+1, N-I, ALPHA, A( I, I ), 1, $ T( 1, N ), 1, A( I, I+1 ), LDA ) A( I, I ) = AII END IF END DO * DO I = 2, N AII = A( I, I ) A( I, I ) = ONE * * T(1:I-1,I) := alpha * A(I:M,1:I-1)**T * A(I:M,I) * ALPHA = -T( I, 1 ) CALL DGEMV( 'T', M-I+1, I-1, ALPHA, A( I, 1 ), LDA, $ A( I, I ), 1, ZERO, T( 1, I ), 1 ) A( I, I ) = AII * * T(1:I-1,I) := T(1:I-1,1:I-1) * T(1:I-1,I) * CALL DTRMV( 'U', 'N', 'N', I-1, T, LDT, T( 1, I ), 1 ) * * T(I,I) = tau(I) * T( I, I ) = T( I, 1 ) T( I, 1) = ZERO END DO * * End of DGEQRT2 * END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/cheevr.f
28
25045
*> \brief <b> CHEEVR computes the eigenvalues and, optionally, the left and/or right eigenvectors for HE matrices</b> * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CHEEVR + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cheevr.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cheevr.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cheevr.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CHEEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU, * ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK, * RWORK, LRWORK, IWORK, LIWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER JOBZ, RANGE, UPLO * INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LRWORK, LWORK, * $ M, N * REAL ABSTOL, VL, VU * .. * .. Array Arguments .. * INTEGER ISUPPZ( * ), IWORK( * ) * REAL RWORK( * ), W( * ) * COMPLEX A( LDA, * ), WORK( * ), Z( LDZ, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CHEEVR computes selected eigenvalues and, optionally, eigenvectors *> of a complex Hermitian matrix A. Eigenvalues and eigenvectors can *> be selected by specifying either a range of values or a range of *> indices for the desired eigenvalues. *> *> CHEEVR first reduces the matrix A to tridiagonal form T with a call *> to CHETRD. Then, whenever possible, CHEEVR calls CSTEMR to compute *> the eigenspectrum using Relatively Robust Representations. CSTEMR *> computes eigenvalues by the dqds algorithm, while orthogonal *> eigenvectors are computed from various "good" L D L^T representations *> (also known as Relatively Robust Representations). Gram-Schmidt *> orthogonalization is avoided as far as possible. More specifically, *> the various steps of the algorithm are as follows. *> *> For each unreduced block (submatrix) of T, *> (a) Compute T - sigma I = L D L^T, so that L and D *> define all the wanted eigenvalues to high relative accuracy. *> This means that small relative changes in the entries of D and L *> cause only small relative changes in the eigenvalues and *> eigenvectors. The standard (unfactored) representation of the *> tridiagonal matrix T does not have this property in general. *> (b) Compute the eigenvalues to suitable accuracy. *> If the eigenvectors are desired, the algorithm attains full *> accuracy of the computed eigenvalues only right before *> the corresponding vectors have to be computed, see steps c) and d). *> (c) For each cluster of close eigenvalues, select a new *> shift close to the cluster, find a new factorization, and refine *> the shifted eigenvalues to suitable accuracy. *> (d) For each eigenvalue with a large enough relative separation compute *> the corresponding eigenvector by forming a rank revealing twisted *> factorization. Go back to (c) for any clusters that remain. *> *> The desired accuracy of the output can be specified by the input *> parameter ABSTOL. *> *> For more details, see DSTEMR's documentation and: *> - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations *> to compute orthogonal eigenvectors of symmetric tridiagonal matrices," *> Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. *> - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and *> Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, *> 2004. Also LAPACK Working Note 154. *> - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric *> tridiagonal eigenvalue/eigenvector problem", *> Computer Science Division Technical Report No. UCB/CSD-97-971, *> UC Berkeley, May 1997. *> *> *> Note 1 : CHEEVR calls CSTEMR when the full spectrum is requested *> on machines which conform to the ieee-754 floating point standard. *> CHEEVR calls SSTEBZ and CSTEIN on non-ieee machines and *> when partial spectrum requests are made. *> *> Normal execution of CSTEMR may create NaNs and infinities and *> hence may abort due to a floating point exception in environments *> which do not handle NaNs and infinities in the ieee standard default *> manner. *> \endverbatim * * Arguments: * ========== * *> \param[in] JOBZ *> \verbatim *> JOBZ is CHARACTER*1 *> = 'N': Compute eigenvalues only; *> = 'V': Compute eigenvalues and eigenvectors. *> \endverbatim *> *> \param[in] RANGE *> \verbatim *> RANGE is CHARACTER*1 *> = 'A': all eigenvalues will be found. *> = 'V': all eigenvalues in the half-open interval (VL,VU] *> will be found. *> = 'I': the IL-th through IU-th eigenvalues will be found. *> For RANGE = 'V' or 'I' and IU - IL < N - 1, SSTEBZ and *> CSTEIN are called *> \endverbatim *> *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': Upper triangle of A is stored; *> = 'L': Lower triangle of A is stored. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX array, dimension (LDA, N) *> On entry, the Hermitian matrix A. If UPLO = 'U', the *> leading N-by-N upper triangular part of A contains the *> upper triangular part of the matrix A. If UPLO = 'L', *> the leading N-by-N lower triangular part of A contains *> the lower triangular part of the matrix A. *> On exit, the lower triangle (if UPLO='L') or the upper *> triangle (if UPLO='U') of A, including the diagonal, is *> destroyed. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[in] VL *> \verbatim *> VL is REAL *> \endverbatim *> *> \param[in] VU *> \verbatim *> VU is REAL *> If RANGE='V', the lower and upper bounds of the interval to *> be searched for eigenvalues. VL < VU. *> Not referenced if RANGE = 'A' or 'I'. *> \endverbatim *> *> \param[in] IL *> \verbatim *> IL is INTEGER *> \endverbatim *> *> \param[in] IU *> \verbatim *> IU is INTEGER *> If RANGE='I', the indices (in ascending order) of the *> smallest and largest eigenvalues to be returned. *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. *> Not referenced if RANGE = 'A' or 'V'. *> \endverbatim *> *> \param[in] ABSTOL *> \verbatim *> ABSTOL is REAL *> The absolute error tolerance for the eigenvalues. *> An approximate eigenvalue is accepted as converged *> when it is determined to lie in an interval [a,b] *> of width less than or equal to *> *> ABSTOL + EPS * max( |a|,|b| ) , *> *> where EPS is the machine precision. If ABSTOL is less than *> or equal to zero, then EPS*|T| will be used in its place, *> where |T| is the 1-norm of the tridiagonal matrix obtained *> by reducing A to tridiagonal form. *> *> See "Computing Small Singular Values of Bidiagonal Matrices *> with Guaranteed High Relative Accuracy," by Demmel and *> Kahan, LAPACK Working Note #3. *> *> If high relative accuracy is important, set ABSTOL to *> SLAMCH( 'Safe minimum' ). Doing so will guarantee that *> eigenvalues are computed to high relative accuracy when *> possible in future releases. The current code does not *> make any guarantees about high relative accuracy, but *> furutre releases will. See J. Barlow and J. Demmel, *> "Computing Accurate Eigensystems of Scaled Diagonally *> Dominant Matrices", LAPACK Working Note #7, for a discussion *> of which matrices define their eigenvalues to high relative *> accuracy. *> \endverbatim *> *> \param[out] M *> \verbatim *> M is INTEGER *> The total number of eigenvalues found. 0 <= M <= N. *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. *> \endverbatim *> *> \param[out] W *> \verbatim *> W is REAL array, dimension (N) *> The first M elements contain the selected eigenvalues in *> ascending order. *> \endverbatim *> *> \param[out] Z *> \verbatim *> Z is COMPLEX array, dimension (LDZ, max(1,M)) *> If JOBZ = 'V', then if INFO = 0, the first M columns of Z *> contain the orthonormal eigenvectors of the matrix A *> corresponding to the selected eigenvalues, with the i-th *> column of Z holding the eigenvector associated with W(i). *> If JOBZ = 'N', then Z is not referenced. *> Note: the user must ensure that at least max(1,M) columns are *> supplied in the array Z; if RANGE = 'V', the exact value of M *> is not known in advance and an upper bound must be used. *> \endverbatim *> *> \param[in] LDZ *> \verbatim *> LDZ is INTEGER *> The leading dimension of the array Z. LDZ >= 1, and if *> JOBZ = 'V', LDZ >= max(1,N). *> \endverbatim *> *> \param[out] ISUPPZ *> \verbatim *> ISUPPZ is INTEGER array, dimension ( 2*max(1,M) ) *> The support of the eigenvectors in Z, i.e., the indices *> indicating the nonzero elements in Z. The i-th eigenvector *> is nonzero only in elements ISUPPZ( 2*i-1 ) through *> ISUPPZ( 2*i ). *> Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX array, dimension (MAX(1,LWORK)) *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The length of the array WORK. LWORK >= max(1,2*N). *> For optimal efficiency, LWORK >= (NB+1)*N, *> where NB is the max of the blocksize for CHETRD and for *> CUNMTR as returned by ILAENV. *> *> If LWORK = -1, then a workspace query is assumed; the routine *> only calculates the optimal sizes of the WORK, RWORK and *> IWORK arrays, returns these values as the first entries of *> the WORK, RWORK and IWORK arrays, and no error message *> related to LWORK or LRWORK or LIWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is REAL array, dimension (MAX(1,LRWORK)) *> On exit, if INFO = 0, RWORK(1) returns the optimal *> (and minimal) LRWORK. *> \endverbatim *> *> \param[in] LRWORK *> \verbatim *> LRWORK is INTEGER *> The length of the array RWORK. LRWORK >= max(1,24*N). *> *> If LRWORK = -1, then a workspace query is assumed; the *> routine only calculates the optimal sizes of the WORK, RWORK *> and IWORK arrays, returns these values as the first entries *> of the WORK, RWORK and IWORK arrays, and no error message *> related to LWORK or LRWORK or LIWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (MAX(1,LIWORK)) *> On exit, if INFO = 0, IWORK(1) returns the optimal *> (and minimal) LIWORK. *> \endverbatim *> *> \param[in] LIWORK *> \verbatim *> LIWORK is INTEGER *> The dimension of the array IWORK. LIWORK >= max(1,10*N). *> *> If LIWORK = -1, then a workspace query is assumed; the *> routine only calculates the optimal sizes of the WORK, RWORK *> and IWORK arrays, returns these values as the first entries *> of the WORK, RWORK and IWORK arrays, and no error message *> related to LWORK or LRWORK or LIWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> > 0: Internal error *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup complexHEeigen * *> \par Contributors: * ================== *> *> Inderjit Dhillon, IBM Almaden, USA \n *> Osni Marques, LBNL/NERSC, USA \n *> Ken Stanley, Computer Science Division, University of *> California at Berkeley, USA \n *> Jason Riedy, Computer Science Division, University of *> California at Berkeley, USA \n *> * ===================================================================== SUBROUTINE CHEEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU, $ ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK, $ RWORK, LRWORK, IWORK, LIWORK, INFO ) * * -- LAPACK driver routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. CHARACTER JOBZ, RANGE, UPLO INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LRWORK, LWORK, $ M, N REAL ABSTOL, VL, VU * .. * .. Array Arguments .. INTEGER ISUPPZ( * ), IWORK( * ) REAL RWORK( * ), W( * ) COMPLEX A( LDA, * ), WORK( * ), Z( LDZ, * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE, TWO PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 ) * .. * .. Local Scalars .. LOGICAL ALLEIG, INDEIG, LOWER, LQUERY, TEST, VALEIG, $ WANTZ, TRYRAC CHARACTER ORDER INTEGER I, IEEEOK, IINFO, IMAX, INDIBL, INDIFL, INDISP, $ INDIWO, INDRD, INDRDD, INDRE, INDREE, INDRWK, $ INDTAU, INDWK, INDWKN, ISCALE, ITMP1, J, JJ, $ LIWMIN, LLWORK, LLRWORK, LLWRKN, LRWMIN, $ LWKOPT, LWMIN, NB, NSPLIT REAL ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, $ SIGMA, SMLNUM, TMP1, VLL, VUU * .. * .. External Functions .. LOGICAL LSAME INTEGER ILAENV REAL CLANSY, SLAMCH EXTERNAL LSAME, ILAENV, CLANSY, SLAMCH * .. * .. External Subroutines .. EXTERNAL CHETRD, CSSCAL, CSTEMR, CSTEIN, CSWAP, CUNMTR, $ SCOPY, SSCAL, SSTEBZ, SSTERF, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN, REAL, SQRT * .. * .. Executable Statements .. * * Test the input parameters. * IEEEOK = ILAENV( 10, 'CHEEVR', 'N', 1, 2, 3, 4 ) * LOWER = LSAME( UPLO, 'L' ) WANTZ = LSAME( JOBZ, 'V' ) ALLEIG = LSAME( RANGE, 'A' ) VALEIG = LSAME( RANGE, 'V' ) INDEIG = LSAME( RANGE, 'I' ) * LQUERY = ( ( LWORK.EQ.-1 ) .OR. ( LRWORK.EQ.-1 ) .OR. $ ( LIWORK.EQ.-1 ) ) * LRWMIN = MAX( 1, 24*N ) LIWMIN = MAX( 1, 10*N ) LWMIN = MAX( 1, 2*N ) * INFO = 0 IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN INFO = -1 ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN INFO = -2 ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN INFO = -3 ELSE IF( N.LT.0 ) THEN INFO = -4 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -6 ELSE IF( VALEIG ) THEN IF( N.GT.0 .AND. VU.LE.VL ) $ INFO = -8 ELSE IF( INDEIG ) THEN IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN INFO = -9 ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN INFO = -10 END IF END IF END IF IF( INFO.EQ.0 ) THEN IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN INFO = -15 END IF END IF * IF( INFO.EQ.0 ) THEN NB = ILAENV( 1, 'CHETRD', UPLO, N, -1, -1, -1 ) NB = MAX( NB, ILAENV( 1, 'CUNMTR', UPLO, N, -1, -1, -1 ) ) LWKOPT = MAX( ( NB+1 )*N, LWMIN ) WORK( 1 ) = LWKOPT RWORK( 1 ) = LRWMIN IWORK( 1 ) = LIWMIN * IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN INFO = -18 ELSE IF( LRWORK.LT.LRWMIN .AND. .NOT.LQUERY ) THEN INFO = -20 ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN INFO = -22 END IF END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'CHEEVR', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Quick return if possible * M = 0 IF( N.EQ.0 ) THEN WORK( 1 ) = 1 RETURN END IF * IF( N.EQ.1 ) THEN WORK( 1 ) = 2 IF( ALLEIG .OR. INDEIG ) THEN M = 1 W( 1 ) = REAL( A( 1, 1 ) ) ELSE IF( VL.LT.REAL( A( 1, 1 ) ) .AND. VU.GE.REAL( A( 1, 1 ) ) ) $ THEN M = 1 W( 1 ) = REAL( A( 1, 1 ) ) END IF END IF IF( WANTZ ) THEN Z( 1, 1 ) = ONE ISUPPZ( 1 ) = 1 ISUPPZ( 2 ) = 1 END IF RETURN END IF * * Get machine constants. * SAFMIN = SLAMCH( 'Safe minimum' ) EPS = SLAMCH( 'Precision' ) SMLNUM = SAFMIN / EPS BIGNUM = ONE / SMLNUM RMIN = SQRT( SMLNUM ) RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) ) * * Scale matrix to allowable range, if necessary. * ISCALE = 0 ABSTLL = ABSTOL IF (VALEIG) THEN VLL = VL VUU = VU END IF ANRM = CLANSY( 'M', UPLO, N, A, LDA, RWORK ) IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN ISCALE = 1 SIGMA = RMIN / ANRM ELSE IF( ANRM.GT.RMAX ) THEN ISCALE = 1 SIGMA = RMAX / ANRM END IF IF( ISCALE.EQ.1 ) THEN IF( LOWER ) THEN DO 10 J = 1, N CALL CSSCAL( N-J+1, SIGMA, A( J, J ), 1 ) 10 CONTINUE ELSE DO 20 J = 1, N CALL CSSCAL( J, SIGMA, A( 1, J ), 1 ) 20 CONTINUE END IF IF( ABSTOL.GT.0 ) $ ABSTLL = ABSTOL*SIGMA IF( VALEIG ) THEN VLL = VL*SIGMA VUU = VU*SIGMA END IF END IF * Initialize indices into workspaces. Note: The IWORK indices are * used only if SSTERF or CSTEMR fail. * WORK(INDTAU:INDTAU+N-1) stores the complex scalar factors of the * elementary reflectors used in CHETRD. INDTAU = 1 * INDWK is the starting offset of the remaining complex workspace, * and LLWORK is the remaining complex workspace size. INDWK = INDTAU + N LLWORK = LWORK - INDWK + 1 * RWORK(INDRD:INDRD+N-1) stores the real tridiagonal's diagonal * entries. INDRD = 1 * RWORK(INDRE:INDRE+N-1) stores the off-diagonal entries of the * tridiagonal matrix from CHETRD. INDRE = INDRD + N * RWORK(INDRDD:INDRDD+N-1) is a copy of the diagonal entries over * -written by CSTEMR (the SSTERF path copies the diagonal to W). INDRDD = INDRE + N * RWORK(INDREE:INDREE+N-1) is a copy of the off-diagonal entries over * -written while computing the eigenvalues in SSTERF and CSTEMR. INDREE = INDRDD + N * INDRWK is the starting offset of the left-over real workspace, and * LLRWORK is the remaining workspace size. INDRWK = INDREE + N LLRWORK = LRWORK - INDRWK + 1 * IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and * stores the block indices of each of the M<=N eigenvalues. INDIBL = 1 * IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and * stores the starting and finishing indices of each block. INDISP = INDIBL + N * IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors * that corresponding to eigenvectors that fail to converge in * SSTEIN. This information is discarded; if any fail, the driver * returns INFO > 0. INDIFL = INDISP + N * INDIWO is the offset of the remaining integer workspace. INDIWO = INDIFL + N * * Call CHETRD to reduce Hermitian matrix to tridiagonal form. * CALL CHETRD( UPLO, N, A, LDA, RWORK( INDRD ), RWORK( INDRE ), $ WORK( INDTAU ), WORK( INDWK ), LLWORK, IINFO ) * * If all eigenvalues are desired * then call SSTERF or CSTEMR and CUNMTR. * TEST = .FALSE. IF( INDEIG ) THEN IF( IL.EQ.1 .AND. IU.EQ.N ) THEN TEST = .TRUE. END IF END IF IF( ( ALLEIG.OR.TEST ) .AND. ( IEEEOK.EQ.1 ) ) THEN IF( .NOT.WANTZ ) THEN CALL SCOPY( N, RWORK( INDRD ), 1, W, 1 ) CALL SCOPY( N-1, RWORK( INDRE ), 1, RWORK( INDREE ), 1 ) CALL SSTERF( N, W, RWORK( INDREE ), INFO ) ELSE CALL SCOPY( N-1, RWORK( INDRE ), 1, RWORK( INDREE ), 1 ) CALL SCOPY( N, RWORK( INDRD ), 1, RWORK( INDRDD ), 1 ) * IF (ABSTOL .LE. TWO*N*EPS) THEN TRYRAC = .TRUE. ELSE TRYRAC = .FALSE. END IF CALL CSTEMR( JOBZ, 'A', N, RWORK( INDRDD ), $ RWORK( INDREE ), VL, VU, IL, IU, M, W, $ Z, LDZ, N, ISUPPZ, TRYRAC, $ RWORK( INDRWK ), LLRWORK, $ IWORK, LIWORK, INFO ) * * Apply unitary matrix used in reduction to tridiagonal * form to eigenvectors returned by CSTEIN. * IF( WANTZ .AND. INFO.EQ.0 ) THEN INDWKN = INDWK LLWRKN = LWORK - INDWKN + 1 CALL CUNMTR( 'L', UPLO, 'N', N, M, A, LDA, $ WORK( INDTAU ), Z, LDZ, WORK( INDWKN ), $ LLWRKN, IINFO ) END IF END IF * * IF( INFO.EQ.0 ) THEN M = N GO TO 30 END IF INFO = 0 END IF * * Otherwise, call SSTEBZ and, if eigenvectors are desired, CSTEIN. * Also call SSTEBZ and CSTEIN if CSTEMR fails. * IF( WANTZ ) THEN ORDER = 'B' ELSE ORDER = 'E' END IF CALL SSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL, $ RWORK( INDRD ), RWORK( INDRE ), M, NSPLIT, W, $ IWORK( INDIBL ), IWORK( INDISP ), RWORK( INDRWK ), $ IWORK( INDIWO ), INFO ) * IF( WANTZ ) THEN CALL CSTEIN( N, RWORK( INDRD ), RWORK( INDRE ), M, W, $ IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ, $ RWORK( INDRWK ), IWORK( INDIWO ), IWORK( INDIFL ), $ INFO ) * * Apply unitary matrix used in reduction to tridiagonal * form to eigenvectors returned by CSTEIN. * INDWKN = INDWK LLWRKN = LWORK - INDWKN + 1 CALL CUNMTR( 'L', UPLO, 'N', N, M, A, LDA, WORK( INDTAU ), Z, $ LDZ, WORK( INDWKN ), LLWRKN, IINFO ) END IF * * If matrix was scaled, then rescale eigenvalues appropriately. * 30 CONTINUE IF( ISCALE.EQ.1 ) THEN IF( INFO.EQ.0 ) THEN IMAX = M ELSE IMAX = INFO - 1 END IF CALL SSCAL( IMAX, ONE / SIGMA, W, 1 ) END IF * * If eigenvalues are not in order, then sort them, along with * eigenvectors. * IF( WANTZ ) THEN DO 50 J = 1, M - 1 I = 0 TMP1 = W( J ) DO 40 JJ = J + 1, M IF( W( JJ ).LT.TMP1 ) THEN I = JJ TMP1 = W( JJ ) END IF 40 CONTINUE * IF( I.NE.0 ) THEN ITMP1 = IWORK( INDIBL+I-1 ) W( I ) = W( J ) IWORK( INDIBL+I-1 ) = IWORK( INDIBL+J-1 ) W( J ) = TMP1 IWORK( INDIBL+J-1 ) = ITMP1 CALL CSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 ) END IF 50 CONTINUE END IF * * Set WORK(1) to optimal workspace size. * WORK( 1 ) = LWKOPT RWORK( 1 ) = LRWMIN IWORK( 1 ) = LIWMIN * RETURN * * End of CHEEVR * END
gpl-2.0
omni-compiler/omni-compiler
tests/XMP/local-view/coarray/F/LIB/this_image.f90
1
2510
real a(1:2,3:5)[6:7,8:10,-3:*] n1 = this_image(a, 1) n2 = this_image(a, 2) n3 = this_image(a, 3) nerr=0 me=this_image() if (me==1) then if (n1.ne.6) nerr=nerr+1 if (n2.ne.8) nerr=nerr+1 if (n3.ne.-3) nerr=nerr+1 else if (me==2) then if (n1.ne.7) nerr=nerr+1 if (n2.ne.8) nerr=nerr+1 if (n3.ne.-3) nerr=nerr+1 else if (me==3) then if (n1.ne.6) nerr=nerr+1 if (n2.ne.9) nerr=nerr+1 if (n3.ne.-3) nerr=nerr+1 else if (me==4) then if (n1.ne.7) nerr=nerr+1 if (n2.ne.9) nerr=nerr+1 if (n3.ne.-3) nerr=nerr+1 else if (me==5) then if (n1.ne.6) nerr=nerr+1 if (n2.ne.10) nerr=nerr+1 if (n3.ne.-3) nerr=nerr+1 else if (me==6) then if (n1.ne.7) nerr=nerr+1 if (n2.ne.10) nerr=nerr+1 if (n3.ne.-3) nerr=nerr+1 else if (me==7) then if (n1.ne.6) nerr=nerr+1 if (n2.ne.8) nerr=nerr+1 if (n3.ne.-2) nerr=nerr+1 else if (me==8) then if (n1.ne.7) nerr=nerr+1 if (n2.ne.8) nerr=nerr+1 if (n3.ne.-2) nerr=nerr+1 else if (me==9) then if (n1.ne.6) nerr=nerr+1 if (n2.ne.9) nerr=nerr+1 if (n3.ne.-2) nerr=nerr+1 else if (me==10) then if (n1.ne.7) nerr=nerr+1 if (n2.ne.9) nerr=nerr+1 if (n3.ne.-2) nerr=nerr+1 else if (me==11) then if (n1.ne.6) nerr=nerr+1 if (n2.ne.10) nerr=nerr+1 if (n3.ne.-2) nerr=nerr+1 else if (me==12) then if (n1.ne.7) nerr=nerr+1 if (n2.ne.10) nerr=nerr+1 if (n3.ne.-2) nerr=nerr+1 else if (me==13) then if (n1.ne.6) nerr=nerr+1 if (n2.ne.8) nerr=nerr+1 if (n3.ne.-1) nerr=nerr+1 else if (me==14) then if (n1.ne.7) nerr=nerr+1 if (n2.ne.8) nerr=nerr+1 if (n3.ne.-1) nerr=nerr+1 else if (me==15) then if (n1.ne.6) nerr=nerr+1 if (n2.ne.9) nerr=nerr+1 if (n3.ne.-1) nerr=nerr+1 else if (me==16) then if (n1.ne.7) nerr=nerr+1 if (n2.ne.9) nerr=nerr+1 if (n3.ne.-1) nerr=nerr+1 else if (me==17) then if (n1.ne.6) nerr=nerr+1 if (n2.ne.10) nerr=nerr+1 if (n3.ne.-1) nerr=nerr+1 else if (me==18) then if (n1.ne.7) nerr=nerr+1 if (n2.ne.10) nerr=nerr+1 if (n3.ne.-1) nerr=nerr+1 end if call final_msg(nerr) end subroutine final_msg(nerr) !! include 'xmp_coarray.h' if (nerr==0) then print '("[",i0,"] OK")', this_image() else print '("[",i0,"] number of NGs: ",i0)', this_image(), nerr call exit(1) end if return end subroutine final_msg
lgpl-3.0
markusappel/McCode
support/MacOSX/pgplot/pgplot-src-mac/src/pgscr.f
6
1754
C*PGSCR -- set color representation C%void cpgscr(int ci, float cr, float cg, float cb); C+ SUBROUTINE PGSCR (CI, CR, CG, CB) INTEGER CI REAL CR, CG, CB C C Set color representation: i.e., define the color to be C associated with a color index. Ignored for devices which do not C support variable color or intensity. Color indices 0-15 C have predefined color representations (see the PGPLOT manual), but C these may be changed with PGSCR. Color indices 16-maximum have no C predefined representations: if these indices are used, PGSCR must C be called to define the representation. On monochrome output C devices (e.g. VT125 terminals with monochrome monitors), the C monochrome intensity is computed from the specified Red, Green, Blue C intensities as 0.30*R + 0.59*G + 0.11*B, as in US color television C systems, NTSC encoding. Note that most devices do not have an C infinite range of colors or monochrome intensities available; C the nearest available color is used. Examples: for black, C set CR=CG=CB=0.0; for white, set CR=CG=CB=1.0; for medium gray, C set CR=CG=CB=0.5; for medium yellow, set CR=CG=0.5, CB=0.0. C C Argument: C CI (input) : the color index to be defined, in the range 0-max. C If the color index greater than the device C maximum is specified, the call is ignored. Color C index 0 applies to the background color. C CR (input) : red, green, and blue intensities, C CG (input) in range 0.0 to 1.0. C CB (input) C-- C 5-Nov-1985 - new routine [TJP]. C----------------------------------------------------------------------- LOGICAL PGNOTO C IF (PGNOTO('PGSCR')) RETURN CALL GRSCR(CI,CR,CG,CB) END
gpl-2.0
markusappel/McCode
support/common/pgplot/src/pgerrb.f
6
3510
C*PGERRB -- horizontal or vertical error bar C%void cpgerrb(int dir, int n, const float *x, const float *y, \ C% const float *e, float t); C+ SUBROUTINE PGERRB (DIR, N, X, Y, E, T) INTEGER DIR, N REAL X(*), Y(*), E(*) REAL T C C Plot error bars in the direction specified by DIR. C This routine draws an error bar only; to mark the data point at C the start of the error bar, an additional call to PGPT is required. C C Arguments: C DIR (input) : direction to plot the error bar relative to C the data point. C One-sided error bar: C DIR is 1 for +X (X to X+E); C 2 for +Y (Y to Y+E); C 3 for -X (X to X-E); C 4 for -Y (Y to Y-E). C Two-sided error bar: C DIR is 5 for +/-X (X-E to X+E); C 6 for +/-Y (Y-E to Y+E). C N (input) : number of error bars to plot. C X (input) : world x-coordinates of the data. C Y (input) : world y-coordinates of the data. C E (input) : value of error bar distance to be added to the C data position in world coordinates. C T (input) : length of terminals to be drawn at the ends C of the error bar, as a multiple of the default C length; if T = 0.0, no terminals will be drawn. C C Note: the dimension of arrays X, Y, and E must be greater C than or equal to N. If N is 1, X, Y, and E may be scalar C variables, or expressions. C-- C 1-Mar-1991 - new routine [JM]. C 20-Apr-1992 - correct bug [ALF, TJP]. C 28-Mar-1995 - add options DIR = 5 or 6 [TJP]. C 31-Mar-1997 - use pgtikl [TJP]. C----------------------------------------------------------------------- INTEGER I LOGICAL PGNOTO REAL XTIK, YTIK, XX, YY C IF (PGNOTO('PGERRB')) RETURN IF (N.LT.1) RETURN IF (DIR.LT.1 .OR. DIR.GT.6) RETURN CALL PGBBUF C C Determine terminal length. C CALL PGTIKL(T, XTIK, YTIK) C C Loop through points. C DO 10 I=1,N C C Draw terminal at starting point if required. C IF (DIR.EQ.5) THEN XX = X(I)-E(I) YY = Y(I) ELSE IF (DIR.EQ.6) THEN XX = X(I) YY = Y(I)-E(I) ELSE XX = X(I) YY = Y(I) END IF IF (T.NE.0.0) THEN IF (DIR.EQ.5) THEN CALL GRMOVA(XX,YY-YTIK) CALL GRLINA(XX,YY+YTIK) ELSE IF (DIR.EQ.6) THEN CALL GRMOVA(XX-XTIK,YY) CALL GRLINA(XX+XTIK,YY) END IF END IF C C Draw the error bar itself. C CALL GRMOVA(XX,YY) IF (DIR.EQ.1 .OR. DIR.EQ.5) THEN XX = X(I)+E(I) YY = Y(I) ELSE IF (DIR.EQ.2 .OR. DIR.EQ.6) THEN XX = X(I) YY = Y(I)+E(I) ELSE IF (DIR.EQ.3) THEN XX = X(I)-E(I) YY = Y(I) ELSE IF (DIR.EQ.4) THEN XX = X(I) YY = Y(I)-E(I) END IF CALL GRLINA(XX,YY) C C Draw terminal at end point. C IF (T.NE.0.0) THEN IF (MOD(DIR,2).EQ.1) THEN CALL GRMOVA(XX,YY-YTIK) CALL GRLINA(XX,YY+YTIK) ELSE CALL GRMOVA(XX-XTIK,YY) CALL GRLINA(XX+XTIK,YY) END IF END IF C 10 CONTINUE CALL PGEBUF END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/zlacp2.f
24
4168
*> \brief \b ZLACP2 copies all or part of a real two-dimensional array to a complex array. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ZLACP2 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlacp2.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlacp2.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlacp2.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE ZLACP2( UPLO, M, N, A, LDA, B, LDB ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER LDA, LDB, M, N * .. * .. Array Arguments .. * DOUBLE PRECISION A( LDA, * ) * COMPLEX*16 B( LDB, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZLACP2 copies all or part of a real two-dimensional matrix A to a *> complex matrix B. *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> Specifies the part of the matrix A to be copied to B. *> = 'U': Upper triangular part *> = 'L': Lower triangular part *> Otherwise: All of the matrix A *> \endverbatim *> *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA,N) *> The m by n matrix A. If UPLO = 'U', only the upper trapezium *> is accessed; if UPLO = 'L', only the lower trapezium is *> accessed. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim *> *> \param[out] B *> \verbatim *> B is COMPLEX*16 array, dimension (LDB,N) *> On exit, B = A in the locations specified by UPLO. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of the array B. LDB >= max(1,M). *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup complex16OTHERauxiliary * * ===================================================================== SUBROUTINE ZLACP2( UPLO, M, N, A, LDA, B, LDB ) * * -- LAPACK auxiliary routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER LDA, LDB, M, N * .. * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ) COMPLEX*16 B( LDB, * ) * .. * * ===================================================================== * * .. Local Scalars .. INTEGER I, J * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. Intrinsic Functions .. INTRINSIC MIN * .. * .. Executable Statements .. * IF( LSAME( UPLO, 'U' ) ) THEN DO 20 J = 1, N DO 10 I = 1, MIN( J, M ) B( I, J ) = A( I, J ) 10 CONTINUE 20 CONTINUE * ELSE IF( LSAME( UPLO, 'L' ) ) THEN DO 40 J = 1, N DO 30 I = J, M B( I, J ) = A( I, J ) 30 CONTINUE 40 CONTINUE * ELSE DO 60 J = 1, N DO 50 I = 1, M B( I, J ) = A( I, J ) 50 CONTINUE 60 CONTINUE END IF * RETURN * * End of ZLACP2 * END
gpl-2.0
QEF/q-e
EPW/src/stop_epw.f90
2
14710
! ! Copyright (C) 2010-2016 Samuel Ponce', Roxana Margine, Carla Verdi, Feliciano Giustino ! ! Copyright (C) 2001 PWSCF group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! Modified from stop_ph ! !----------------------------------------------------------------------- SUBROUTINE stop_epw() !----------------------------------------------------------------------- !! !! Close all files and synchronize processes before stopping. !! Called at the end of the run !! USE mp, ONLY : mp_end, mp_barrier USE mp_global, ONLY : inter_pool_comm, mp_global_end USE io_global, ONLY : stdout USE printing, ONLY : print_clock_epw USE epwcom, ONLY : eliashberg, plselfen, specfun_pl, scattering, iterative_bte, lpolar USE elph2, ONLY : adapt_smearing USE io_var, ONLY : epwbib USE mp_world, ONLY : mpime USE io_global, ONLY : ionode_id ! IMPLICIT NONE ! CALL print_clock_epw() ! WRITE(stdout, '(a)') " ===============================================================================" WRITE(stdout, '(a)') " The functionality-dependent EPW.bib file was created with suggested citations. " WRITE(stdout, '(a)') " Please consider citing the papers listed in EPW.bib. " WRITE(stdout, '(a)') " ===============================================================================" WRITE(stdout, '(a)') " " ! IF (mpime == ionode_id) THEN ! OPEN(UNIT = epwbib, FILE = 'EPW.bib') ! WRITE(epwbib, '(a)') " % Copyright (C) 2010-2016 Samuel Ponce', Roxana Margine, Carla Verdi, Feliciano Giustino" WRITE(epwbib, '(a)') " " WRITE(epwbib, '(a)') " % Paper describing the method on which EPW relies " WRITE(epwbib, '(a)') " @Article{Giustino2007 " WRITE(epwbib, '(a)') " Title = {Electron-phonon interaction using Wannier functions}, " WRITE(epwbib, '(a)') " Author = {F. Giustino and M. L. Cohen and S. G. Louie}, " WRITE(epwbib, '(a)') " Journal = {Phys. Rev. B}, " WRITE(epwbib, '(a)') " Year = {2007}, " WRITE(epwbib, '(a)') " Volume = {76}, " WRITE(epwbib, '(a)') " Pages = {165108}, " WRITE(epwbib, '(a)') " Doi = {10.1103/PhysRevB.76.165108} " WRITE(epwbib, '(a)') " } " WRITE(epwbib, '(a)') " " WRITE(epwbib, '(a)') " % Paper describing the EPW software " WRITE(epwbib, '(a)') " @Article{Ponce2016, " WRITE(epwbib, '(a)') " Title = {EPW: Electron–phonon coupling, transport and superconducting properties & &using maximally localized Wannier functions}," WRITE(epwbib, '(a)') " Author = {S. Ponc\'e and E.R. Margine and C. Verdi and F. Giustino}, " WRITE(epwbib, '(a)') " Journal = {Computer Physics Communications}, " WRITE(epwbib, '(a)') " Year = {2016}, " WRITE(epwbib, '(a)') " Volume = {209}, " WRITE(epwbib, '(a)') " Pages = {116 - 133}, " WRITE(epwbib, '(a)') " Doi = {https://doi.org/10.1016/j.cpc.2016.07.028} " WRITE(epwbib, '(a)') " } " ! ! Specific functionalities WRITE(epwbib, '(a)') " " ! ! Eliashberg superconductivity IF (eliashberg) THEN WRITE(epwbib, '(a)') " " WRITE(epwbib, '(a)') " % Since you used the [eliashberg] input, please consider also citing " WRITE(epwbib, '(a)') " @Article{Margine2013, " WRITE(epwbib, '(a)') " Title = {Anisotropic Migdal-Eliashberg theory using Wannier functions}, " WRITE(epwbib, '(a)') " Author = {E. R. Margine and F. Giustino}, " WRITE(epwbib, '(a)') " Journal = {Phys. Rev. B}, " WRITE(epwbib, '(a)') " Year = {2013}, " WRITE(epwbib, '(a)') " Volume = {87} " WRITE(epwbib, '(a)') " Pages = {024505}, " WRITE(epwbib, '(a)') " Doi = {10.1103/PhysRevB.87.024505} " WRITE(epwbib, '(a)') " } " ENDIF ! ! Polar analytic interpolation IF (lpolar) THEN WRITE(epwbib, '(a)') " " WRITE(epwbib, '(a)') " % Since you used the [lpolar] input, please consider also citing " WRITE(epwbib, '(a)') " @Article{Verdi2015, " WRITE(epwbib, '(a)') " Title = {Frohlich Electron-Phonon Vertex from First Principles}, " WRITE(epwbib, '(a)') " Author = {C. Verdi and F. Giustino}, " WRITE(epwbib, '(a)') " Journal = {Phys. Rev. Lett.}, " WRITE(epwbib, '(a)') " Year = {2015}, " WRITE(epwbib, '(a)') " Volume = {115} " WRITE(epwbib, '(a)') " Pages = {176401}, " WRITE(epwbib, '(a)') " Doi = {10.1103/PhysRevLett.115.176401} " WRITE(epwbib, '(a)') " } " ENDIF ! ! Plasmons IF (plselfen .OR. specfun_pl) THEN WRITE(epwbib, '(a)') " " WRITE(epwbib, '(a)') " % Since you used the [plselfen] or [specfun_pl] input, please consider also citing " WRITE(epwbib, '(a)') " @Article{Caruso2018, " WRITE(epwbib, '(a)') " Title = {Electron-plasmon and electron-phonon satellites in the angle-resolved & &photoelectron spectra of $n$-doped anatase ${\mathrm{TiO}}_{2}$}," WRITE(epwbib, '(a)') " Author = {F. Caruso and C. Verdi and S. Ponc\'e and F. Giustino}, " WRITE(epwbib, '(a)') " Journal = {Phys. Rev. B}, " WRITE(epwbib, '(a)') " Year = {2018}, " WRITE(epwbib, '(a)') " Volume = {97} " WRITE(epwbib, '(a)') " Pages = {165113}, " WRITE(epwbib, '(a)') " Doi = {10.1103/PhysRevB.97.165113} " WRITE(epwbib, '(a)') " } " ENDIF ! ! Transport module IF (scattering .AND. .NOT. iterative_bte) THEN WRITE(epwbib, '(a)') " " WRITE(epwbib, '(a)') " % Since you used the [scattering] input, please consider also citing " WRITE(epwbib, '(a)') " @Article{Ponce2018, " WRITE(epwbib, '(a)') " Title = {Towards predictive many-body calculations of phonon-limited carrier & &mobilities in semiconductors}," WRITE(epwbib, '(a)') " Author = {S. Ponc\'e and E. R. Margine and F. Giustino}, " WRITE(epwbib, '(a)') " Journal = {Phys. Rev. B}, " WRITE(epwbib, '(a)') " Year = {2018}, " WRITE(epwbib, '(a)') " Volume = {97} " WRITE(epwbib, '(a)') " Pages = {121201}, " WRITE(epwbib, '(a)') " Doi = {10.1103/PhysRevB.97.121201} " WRITE(epwbib, '(a)') " } " ENDIF ! IF (iterative_bte) THEN WRITE(epwbib, '(a)') " " WRITE(epwbib, '(a)') " % Since you used the [iterative_bte] input, please consider also citing " WRITE(epwbib, '(a)') " @Article{Ponce2018, " WRITE(epwbib, '(a)') " Title = {Towards predictive many-body calculations of phonon-limited carrier & &mobilities in semiconductors}," WRITE(epwbib, '(a)') " Author = {S. Ponc\'e and E. R. Margine and F. Giustino}, " WRITE(epwbib, '(a)') " Journal = {Phys. Rev. B}, " WRITE(epwbib, '(a)') " Year = {2018}, " WRITE(epwbib, '(a)') " Volume = {97} " WRITE(epwbib, '(a)') " Pages = {121201}, " WRITE(epwbib, '(a)') " Doi = {10.1103/PhysRevB.97.121201} " WRITE(epwbib, '(a)') " } " WRITE(epwbib, '(a)') " " WRITE(epwbib, '(a)') " @Article{Macheda2018, " WRITE(epwbib, '(a)') " Title = {Magnetotransport phenomena in $p$-doped diamond from first principles}, " WRITE(epwbib, '(a)') " Author = {F. Macheda and N. Bonini}, " WRITE(epwbib, '(a)') " Journal = {Phys. Rev. B}, " WRITE(epwbib, '(a)') " Year = {2018}, " WRITE(epwbib, '(a)') " Volume = {98} " WRITE(epwbib, '(a)') " Pages = {201201}, " WRITE(epwbib, '(a)') " Doi = {10.1103/PhysRevB.98.201201} " WRITE(epwbib, '(a)') " } " ENDIF ! ! Improvements IF (adapt_smearing) THEN WRITE(epwbib, '(a)') " " WRITE(epwbib, '(a)') " % Since you used the [adapt_smearing] input, please consider also citing " WRITE(epwbib, '(a)') " @Article{Macheda2018, " WRITE(epwbib, '(a)') " Title = {Magnetotransport phenomena in $p$-doped diamond from first principles}, " WRITE(epwbib, '(a)') " Author = {F. Macheda and N. Bonini}, " WRITE(epwbib, '(a)') " Journal = {Phys. Rev. B}, " WRITE(epwbib, '(a)') " Year = {2018}, " WRITE(epwbib, '(a)') " Volume = {98} " WRITE(epwbib, '(a)') " Pages = {201201}, " WRITE(epwbib, '(a)') " Doi = {10.1103/PhysRevB.98.201201} " WRITE(epwbib, '(a)') " } " ENDIF ! CLOSE(epwbib) ! ENDIF ! CALL mp_end(inter_pool_comm) CALL mp_global_end() ! STOP ! RETURN !----------------------------------------------------------------------- END SUBROUTINE stop_epw !-----------------------------------------------------------------------
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/dlasdq.f
24
12989
*> \brief \b DLASDQ computes the SVD of a real bidiagonal matrix with diagonal d and off-diagonal e. Used by sbdsdc. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DLASDQ + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasdq.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasdq.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasdq.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DLASDQ( UPLO, SQRE, N, NCVT, NRU, NCC, D, E, VT, LDVT, * U, LDU, C, LDC, WORK, INFO ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU, SQRE * .. * .. Array Arguments .. * DOUBLE PRECISION C( LDC, * ), D( * ), E( * ), U( LDU, * ), * $ VT( LDVT, * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DLASDQ computes the singular value decomposition (SVD) of a real *> (upper or lower) bidiagonal matrix with diagonal D and offdiagonal *> E, accumulating the transformations if desired. Letting B denote *> the input bidiagonal matrix, the algorithm computes orthogonal *> matrices Q and P such that B = Q * S * P**T (P**T denotes the transpose *> of P). The singular values S are overwritten on D. *> *> The input matrix U is changed to U * Q if desired. *> The input matrix VT is changed to P**T * VT if desired. *> The input matrix C is changed to Q**T * C if desired. *> *> See "Computing Small Singular Values of Bidiagonal Matrices With *> Guaranteed High Relative Accuracy," by J. Demmel and W. Kahan, *> LAPACK Working Note #3, for a detailed description of the algorithm. *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> On entry, UPLO specifies whether the input bidiagonal matrix *> is upper or lower bidiagonal, and wether it is square are *> not. *> UPLO = 'U' or 'u' B is upper bidiagonal. *> UPLO = 'L' or 'l' B is lower bidiagonal. *> \endverbatim *> *> \param[in] SQRE *> \verbatim *> SQRE is INTEGER *> = 0: then the input matrix is N-by-N. *> = 1: then the input matrix is N-by-(N+1) if UPLU = 'U' and *> (N+1)-by-N if UPLU = 'L'. *> *> The bidiagonal matrix has *> N = NL + NR + 1 rows and *> M = N + SQRE >= N columns. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> On entry, N specifies the number of rows and columns *> in the matrix. N must be at least 0. *> \endverbatim *> *> \param[in] NCVT *> \verbatim *> NCVT is INTEGER *> On entry, NCVT specifies the number of columns of *> the matrix VT. NCVT must be at least 0. *> \endverbatim *> *> \param[in] NRU *> \verbatim *> NRU is INTEGER *> On entry, NRU specifies the number of rows of *> the matrix U. NRU must be at least 0. *> \endverbatim *> *> \param[in] NCC *> \verbatim *> NCC is INTEGER *> On entry, NCC specifies the number of columns of *> the matrix C. NCC must be at least 0. *> \endverbatim *> *> \param[in,out] D *> \verbatim *> D is DOUBLE PRECISION array, dimension (N) *> On entry, D contains the diagonal entries of the *> bidiagonal matrix whose SVD is desired. On normal exit, *> D contains the singular values in ascending order. *> \endverbatim *> *> \param[in,out] E *> \verbatim *> E is DOUBLE PRECISION array. *> dimension is (N-1) if SQRE = 0 and N if SQRE = 1. *> On entry, the entries of E contain the offdiagonal entries *> of the bidiagonal matrix whose SVD is desired. On normal *> exit, E will contain 0. If the algorithm does not converge, *> D and E will contain the diagonal and superdiagonal entries *> of a bidiagonal matrix orthogonally equivalent to the one *> given as input. *> \endverbatim *> *> \param[in,out] VT *> \verbatim *> VT is DOUBLE PRECISION array, dimension (LDVT, NCVT) *> On entry, contains a matrix which on exit has been *> premultiplied by P**T, dimension N-by-NCVT if SQRE = 0 *> and (N+1)-by-NCVT if SQRE = 1 (not referenced if NCVT=0). *> \endverbatim *> *> \param[in] LDVT *> \verbatim *> LDVT is INTEGER *> On entry, LDVT specifies the leading dimension of VT as *> declared in the calling (sub) program. LDVT must be at *> least 1. If NCVT is nonzero LDVT must also be at least N. *> \endverbatim *> *> \param[in,out] U *> \verbatim *> U is DOUBLE PRECISION array, dimension (LDU, N) *> On entry, contains a matrix which on exit has been *> postmultiplied by Q, dimension NRU-by-N if SQRE = 0 *> and NRU-by-(N+1) if SQRE = 1 (not referenced if NRU=0). *> \endverbatim *> *> \param[in] LDU *> \verbatim *> LDU is INTEGER *> On entry, LDU specifies the leading dimension of U as *> declared in the calling (sub) program. LDU must be at *> least max( 1, NRU ) . *> \endverbatim *> *> \param[in,out] C *> \verbatim *> C is DOUBLE PRECISION array, dimension (LDC, NCC) *> On entry, contains an N-by-NCC matrix which on exit *> has been premultiplied by Q**T dimension N-by-NCC if SQRE = 0 *> and (N+1)-by-NCC if SQRE = 1 (not referenced if NCC=0). *> \endverbatim *> *> \param[in] LDC *> \verbatim *> LDC is INTEGER *> On entry, LDC specifies the leading dimension of C as *> declared in the calling (sub) program. LDC must be at *> least 1. If NCC is nonzero, LDC must also be at least N. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension (4*N) *> Workspace. Only referenced if one of NCVT, NRU, or NCC is *> nonzero, and if N is at least 2. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> On exit, a value of 0 indicates a successful exit. *> If INFO < 0, argument number -INFO is illegal. *> If INFO > 0, the algorithm did not converge, and INFO *> specifies how many superdiagonals did not converge. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup auxOTHERauxiliary * *> \par Contributors: * ================== *> *> Ming Gu and Huan Ren, Computer Science Division, University of *> California at Berkeley, USA *> * ===================================================================== SUBROUTINE DLASDQ( UPLO, SQRE, N, NCVT, NRU, NCC, D, E, VT, LDVT, $ U, LDU, C, LDC, WORK, INFO ) * * -- LAPACK auxiliary routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU, SQRE * .. * .. Array Arguments .. DOUBLE PRECISION C( LDC, * ), D( * ), E( * ), U( LDU, * ), $ VT( LDVT, * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO PARAMETER ( ZERO = 0.0D+0 ) * .. * .. Local Scalars .. LOGICAL ROTATE INTEGER I, ISUB, IUPLO, J, NP1, SQRE1 DOUBLE PRECISION CS, R, SMIN, SN * .. * .. External Subroutines .. EXTERNAL DBDSQR, DLARTG, DLASR, DSWAP, XERBLA * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 IUPLO = 0 IF( LSAME( UPLO, 'U' ) ) $ IUPLO = 1 IF( LSAME( UPLO, 'L' ) ) $ IUPLO = 2 IF( IUPLO.EQ.0 ) THEN INFO = -1 ELSE IF( ( SQRE.LT.0 ) .OR. ( SQRE.GT.1 ) ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( NCVT.LT.0 ) THEN INFO = -4 ELSE IF( NRU.LT.0 ) THEN INFO = -5 ELSE IF( NCC.LT.0 ) THEN INFO = -6 ELSE IF( ( NCVT.EQ.0 .AND. LDVT.LT.1 ) .OR. $ ( NCVT.GT.0 .AND. LDVT.LT.MAX( 1, N ) ) ) THEN INFO = -10 ELSE IF( LDU.LT.MAX( 1, NRU ) ) THEN INFO = -12 ELSE IF( ( NCC.EQ.0 .AND. LDC.LT.1 ) .OR. $ ( NCC.GT.0 .AND. LDC.LT.MAX( 1, N ) ) ) THEN INFO = -14 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DLASDQ', -INFO ) RETURN END IF IF( N.EQ.0 ) $ RETURN * * ROTATE is true if any singular vectors desired, false otherwise * ROTATE = ( NCVT.GT.0 ) .OR. ( NRU.GT.0 ) .OR. ( NCC.GT.0 ) NP1 = N + 1 SQRE1 = SQRE * * If matrix non-square upper bidiagonal, rotate to be lower * bidiagonal. The rotations are on the right. * IF( ( IUPLO.EQ.1 ) .AND. ( SQRE1.EQ.1 ) ) THEN DO 10 I = 1, N - 1 CALL DLARTG( D( I ), E( I ), CS, SN, R ) D( I ) = R E( I ) = SN*D( I+1 ) D( I+1 ) = CS*D( I+1 ) IF( ROTATE ) THEN WORK( I ) = CS WORK( N+I ) = SN END IF 10 CONTINUE CALL DLARTG( D( N ), E( N ), CS, SN, R ) D( N ) = R E( N ) = ZERO IF( ROTATE ) THEN WORK( N ) = CS WORK( N+N ) = SN END IF IUPLO = 2 SQRE1 = 0 * * Update singular vectors if desired. * IF( NCVT.GT.0 ) $ CALL DLASR( 'L', 'V', 'F', NP1, NCVT, WORK( 1 ), $ WORK( NP1 ), VT, LDVT ) END IF * * If matrix lower bidiagonal, rotate to be upper bidiagonal * by applying Givens rotations on the left. * IF( IUPLO.EQ.2 ) THEN DO 20 I = 1, N - 1 CALL DLARTG( D( I ), E( I ), CS, SN, R ) D( I ) = R E( I ) = SN*D( I+1 ) D( I+1 ) = CS*D( I+1 ) IF( ROTATE ) THEN WORK( I ) = CS WORK( N+I ) = SN END IF 20 CONTINUE * * If matrix (N+1)-by-N lower bidiagonal, one additional * rotation is needed. * IF( SQRE1.EQ.1 ) THEN CALL DLARTG( D( N ), E( N ), CS, SN, R ) D( N ) = R IF( ROTATE ) THEN WORK( N ) = CS WORK( N+N ) = SN END IF END IF * * Update singular vectors if desired. * IF( NRU.GT.0 ) THEN IF( SQRE1.EQ.0 ) THEN CALL DLASR( 'R', 'V', 'F', NRU, N, WORK( 1 ), $ WORK( NP1 ), U, LDU ) ELSE CALL DLASR( 'R', 'V', 'F', NRU, NP1, WORK( 1 ), $ WORK( NP1 ), U, LDU ) END IF END IF IF( NCC.GT.0 ) THEN IF( SQRE1.EQ.0 ) THEN CALL DLASR( 'L', 'V', 'F', N, NCC, WORK( 1 ), $ WORK( NP1 ), C, LDC ) ELSE CALL DLASR( 'L', 'V', 'F', NP1, NCC, WORK( 1 ), $ WORK( NP1 ), C, LDC ) END IF END IF END IF * * Call DBDSQR to compute the SVD of the reduced real * N-by-N upper bidiagonal matrix. * CALL DBDSQR( 'U', N, NCVT, NRU, NCC, D, E, VT, LDVT, U, LDU, C, $ LDC, WORK, INFO ) * * Sort the singular values into ascending order (insertion sort on * singular values, but only one transposition per singular vector) * DO 40 I = 1, N * * Scan for smallest D(I). * ISUB = I SMIN = D( I ) DO 30 J = I + 1, N IF( D( J ).LT.SMIN ) THEN ISUB = J SMIN = D( J ) END IF 30 CONTINUE IF( ISUB.NE.I ) THEN * * Swap singular values and vectors. * D( ISUB ) = D( I ) D( I ) = SMIN IF( NCVT.GT.0 ) $ CALL DSWAP( NCVT, VT( ISUB, 1 ), LDVT, VT( I, 1 ), LDVT ) IF( NRU.GT.0 ) $ CALL DSWAP( NRU, U( 1, ISUB ), 1, U( 1, I ), 1 ) IF( NCC.GT.0 ) $ CALL DSWAP( NCC, C( ISUB, 1 ), LDC, C( I, 1 ), LDC ) END IF 40 CONTINUE * RETURN * * End of DLASDQ * END
gpl-2.0
bridgeW/Higuchi1988
main.f90
1
3967
PROGRAM FractalAnalysis ! Purpose: ! Calculating the fractal dimension ! Step1: Get the length of the curve,L(m,k) ! m:initial time ! k:interval time ! L(m,k)=sum(i=1,[(N-m)/k],|X(m+i*k)-X(m+(i-1)*k)|/k) ! ! Step2: Get the average of L(m,k)& its Standard_dev ! ave_Lmk=sum(m=1,k,L(m,k))/k ! std_dev_Lmk=sqrt(k*L(m,k)**2-sum(L(m,k))**2))/(k*(k-1)) ! ! References: ! 1.Higuchi,T.,1988.Approach to an irregular time ! series on the basis of fractal theory. ! Physica D 31.277-283 ! 2.Burlaga,L.F., Klein,L.W.,1986.Fractal structure of ! the interplanetary magnetic field. J.Geophys.Res.91,374-350 ! 3.Gotoh,K.,Hayakawa,M.,Smirnova,N.A.,etal.2004. Fractal ! analysis of seimogenic ULF emissions. Physis and Chemistry of ! the Earth.29,419-424 ! Record of revisions: ! Date Programmer Description of change ! ==== ========== ===================== ! 2012/1/5 Q.Wang Original code ! 2012/1/8 Q.Wang Revised ! 2012/1/9 Q.Wang Revised ! 01/14/12 Q.Wang Revised USE higuchi1988_type USE higuchi1988_subs use dflib IMPLICIT NONE !> for DFA CHARACTER(len=30)::filename,lmk CHARACTER(len=4)::nof !No. of file INTEGER(I4B)::nf !No. of file REAL(DP),SAVE,ALLOCATABLE,DIMENSION(:) :: x REAL(DP),SAVE,allocatable,DIMENSION(:) :: section1year integer,parameter:: Nsubsec=180 INTEGER(I1B)::fileindex INTEGER(I4B)::i, j, Nsec!Loop Index REAL(DP)::slope REAL(DP)::rcoef INTEGER(I1B)::status !> for cmd.exe character(len=255) :: cmd logical :: res !> input file's name WRITE(*,1) 1 FORMAT("Please Enter Other File's filename: ",$) READ(*,*)filename !filename='JIHminSr160' ! Open a file to output everyday's slope OPEN(100,FILE=trim(filename)//'slopes'//num2str(Nsubsec)//'.txt',STATUS='REPLACE',ACTION='WRITE') ! Open File & Read data CALL check_in(filename,x,status) IF(ALLOCATED(x))THEN allocate(section1year(Nsubsec)) Nsec=floor((size(x)-size(section1year)+10)/10.0) write(*,*)'Total section: ', Nsec do i=1,floor((size(x)-size(section1year)+10)/10.0) section1year(1:Nsubsec) = x(1 + (i-1)*10 : NsubSec + (i-1)*10 ) !>> output subsection's data into files open(90,file=trim(filename)//'sec'//num2strN(i,len_trim(num2str(Nsec)))//'.dat',status='replace',action='write') do j=1,Nsubsec write(90,*)section1year(j) enddo close(90) !> mkdir subdataBJIminSr160 cmd='mkdir subdata_'//trim(filename)//num2str(Nsubsec) res = systemqq(cmd) !> move LMKBJIminSr160section??? into LMK_BJIminSr160 cmd='move '//trim(filename)//'sec*.dat '//'subdata_'//trim(filename)//num2str(Nsubsec) res = systemqq(cmd) !>> DFA process CALL higuchi1988_v5(trim(filename)//'section'//num2str(i),section1year,lmk,slope,rcoef,status) WRITE(*,*)'STATUS=',status WRITE(100,10)ABS(slope),abs(rcoef) 10 FORMAT(1X,2F16.5) !> write xTickDays file for GMT5 plotting !if(mod(i,9)==0) write(10,*)i, 'a', (i-1)*10+1 enddo deallocate(section1year) close(100) IF(status/=0)STOP ELSE WRITE(*,*)'Sub chek_in: the array is not allocated.' ENDIF !> mkdir LMK_BJIminSr160 cmd='mkdir LMK_'//trim(filename)//num2str(Nsubsec) res = systemqq(cmd) !> move LMKBJIminSr160section??? into LMK_BJIminSr160 cmd='move LMK'//trim(filename)//'section* '//'LMK_'//trim(filename)//num2str(Nsubsec) res = systemqq(cmd) END PROGRAM FractalAnalysis
bsd-3-clause
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/sgesvxx.f
28
29963
*> \brief <b> SGESVXX computes the solution to system of linear equations A * X = B for GE matrices</b> * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download SGESVXX + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgesvxx.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgesvxx.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgesvxx.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE SGESVXX( FACT, TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, * EQUED, R, C, B, LDB, X, LDX, RCOND, RPVGRW, * BERR, N_ERR_BNDS, ERR_BNDS_NORM, * ERR_BNDS_COMP, NPARAMS, PARAMS, WORK, IWORK, * INFO ) * * .. Scalar Arguments .. * CHARACTER EQUED, FACT, TRANS * INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS, NPARAMS, * $ N_ERR_BNDS * REAL RCOND, RPVGRW * .. * .. Array Arguments .. * INTEGER IPIV( * ), IWORK( * ) * REAL A( LDA, * ), AF( LDAF, * ), B( LDB, * ), * $ X( LDX , * ),WORK( * ) * REAL R( * ), C( * ), PARAMS( * ), BERR( * ), * $ ERR_BNDS_NORM( NRHS, * ), * $ ERR_BNDS_COMP( NRHS, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SGESVXX uses the LU factorization to compute the solution to a *> real system of linear equations A * X = B, where A is an *> N-by-N matrix and X and B are N-by-NRHS matrices. *> *> If requested, both normwise and maximum componentwise error bounds *> are returned. SGESVXX will return a solution with a tiny *> guaranteed error (O(eps) where eps is the working machine *> precision) unless the matrix is very ill-conditioned, in which *> case a warning is returned. Relevant condition numbers also are *> calculated and returned. *> *> SGESVXX accepts user-provided factorizations and equilibration *> factors; see the definitions of the FACT and EQUED options. *> Solving with refinement and using a factorization from a previous *> SGESVXX call will also produce a solution with either O(eps) *> errors or warnings, but we cannot make that claim for general *> user-provided factorizations and equilibration factors if they *> differ from what SGESVXX would itself produce. *> \endverbatim * *> \par Description: * ================= *> *> \verbatim *> *> The following steps are performed: *> *> 1. If FACT = 'E', real scaling factors are computed to equilibrate *> the system: *> *> TRANS = 'N': diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B *> TRANS = 'T': (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B *> TRANS = 'C': (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B *> *> Whether or not the system will be equilibrated depends on the *> scaling of the matrix A, but if equilibration is used, A is *> overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if TRANS='N') *> or diag(C)*B (if TRANS = 'T' or 'C'). *> *> 2. If FACT = 'N' or 'E', the LU decomposition is used to factor *> the matrix A (after equilibration if FACT = 'E') as *> *> A = P * L * U, *> *> where P is a permutation matrix, L is a unit lower triangular *> matrix, and U is upper triangular. *> *> 3. If some U(i,i)=0, so that U is exactly singular, then the *> routine returns with INFO = i. Otherwise, the factored form of A *> is used to estimate the condition number of the matrix A (see *> argument RCOND). If the reciprocal of the condition number is less *> than machine precision, the routine still goes on to solve for X *> and compute error bounds as described below. *> *> 4. The system of equations is solved for X using the factored form *> of A. *> *> 5. By default (unless PARAMS(LA_LINRX_ITREF_I) is set to zero), *> the routine will use iterative refinement to try to get a small *> error and error bounds. Refinement calculates the residual to at *> least twice the working precision. *> *> 6. If equilibration was used, the matrix X is premultiplied by *> diag(C) (if TRANS = 'N') or diag(R) (if TRANS = 'T' or 'C') so *> that it solves the original system before equilibration. *> \endverbatim * * Arguments: * ========== * *> \verbatim *> Some optional parameters are bundled in the PARAMS array. These *> settings determine how refinement is performed, but often the *> defaults are acceptable. If the defaults are acceptable, users *> can pass NPARAMS = 0 which prevents the source code from accessing *> the PARAMS argument. *> \endverbatim *> *> \param[in] FACT *> \verbatim *> FACT is CHARACTER*1 *> Specifies whether or not the factored form of the matrix A is *> supplied on entry, and if not, whether the matrix A should be *> equilibrated before it is factored. *> = 'F': On entry, AF and IPIV contain the factored form of A. *> If EQUED is not 'N', the matrix A has been *> equilibrated with scaling factors given by R and C. *> A, AF, and IPIV are not modified. *> = 'N': The matrix A will be copied to AF and factored. *> = 'E': The matrix A will be equilibrated if necessary, then *> copied to AF and factored. *> \endverbatim *> *> \param[in] TRANS *> \verbatim *> TRANS is CHARACTER*1 *> Specifies the form of the system of equations: *> = 'N': A * X = B (No transpose) *> = 'T': A**T * X = B (Transpose) *> = 'C': A**H * X = B (Conjugate Transpose = Transpose) *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of linear equations, i.e., the order of the *> matrix A. N >= 0. *> \endverbatim *> *> \param[in] NRHS *> \verbatim *> NRHS is INTEGER *> The number of right hand sides, i.e., the number of columns *> of the matrices B and X. NRHS >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is REAL array, dimension (LDA,N) *> On entry, the N-by-N matrix A. If FACT = 'F' and EQUED is *> not 'N', then A must have been equilibrated by the scaling *> factors in R and/or C. A is not modified if FACT = 'F' or *> 'N', or if FACT = 'E' and EQUED = 'N' on exit. *> *> On exit, if EQUED .ne. 'N', A is scaled as follows: *> EQUED = 'R': A := diag(R) * A *> EQUED = 'C': A := A * diag(C) *> EQUED = 'B': A := diag(R) * A * diag(C). *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[in,out] AF *> \verbatim *> AF is REAL array, dimension (LDAF,N) *> If FACT = 'F', then AF is an input argument and on entry *> contains the factors L and U from the factorization *> A = P*L*U as computed by SGETRF. If EQUED .ne. 'N', then *> AF is the factored form of the equilibrated matrix A. *> *> If FACT = 'N', then AF is an output argument and on exit *> returns the factors L and U from the factorization A = P*L*U *> of the original matrix A. *> *> If FACT = 'E', then AF is an output argument and on exit *> returns the factors L and U from the factorization A = P*L*U *> of the equilibrated matrix A (see the description of A for *> the form of the equilibrated matrix). *> \endverbatim *> *> \param[in] LDAF *> \verbatim *> LDAF is INTEGER *> The leading dimension of the array AF. LDAF >= max(1,N). *> \endverbatim *> *> \param[in,out] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (N) *> If FACT = 'F', then IPIV is an input argument and on entry *> contains the pivot indices from the factorization A = P*L*U *> as computed by SGETRF; row i of the matrix was interchanged *> with row IPIV(i). *> *> If FACT = 'N', then IPIV is an output argument and on exit *> contains the pivot indices from the factorization A = P*L*U *> of the original matrix A. *> *> If FACT = 'E', then IPIV is an output argument and on exit *> contains the pivot indices from the factorization A = P*L*U *> of the equilibrated matrix A. *> \endverbatim *> *> \param[in,out] EQUED *> \verbatim *> EQUED is CHARACTER*1 *> Specifies the form of equilibration that was done. *> = 'N': No equilibration (always true if FACT = 'N'). *> = 'R': Row equilibration, i.e., A has been premultiplied by *> diag(R). *> = 'C': Column equilibration, i.e., A has been postmultiplied *> by diag(C). *> = 'B': Both row and column equilibration, i.e., A has been *> replaced by diag(R) * A * diag(C). *> EQUED is an input argument if FACT = 'F'; otherwise, it is an *> output argument. *> \endverbatim *> *> \param[in,out] R *> \verbatim *> R is REAL array, dimension (N) *> The row scale factors for A. If EQUED = 'R' or 'B', A is *> multiplied on the left by diag(R); if EQUED = 'N' or 'C', R *> is not accessed. R is an input argument if FACT = 'F'; *> otherwise, R is an output argument. If FACT = 'F' and *> EQUED = 'R' or 'B', each element of R must be positive. *> If R is output, each element of R is a power of the radix. *> If R is input, each element of R should be a power of the radix *> to ensure a reliable solution and error estimates. Scaling by *> powers of the radix does not cause rounding errors unless the *> result underflows or overflows. Rounding errors during scaling *> lead to refining with a matrix that is not equivalent to the *> input matrix, producing error estimates that may not be *> reliable. *> \endverbatim *> *> \param[in,out] C *> \verbatim *> C is REAL array, dimension (N) *> The column scale factors for A. If EQUED = 'C' or 'B', A is *> multiplied on the right by diag(C); if EQUED = 'N' or 'R', C *> is not accessed. C is an input argument if FACT = 'F'; *> otherwise, C is an output argument. If FACT = 'F' and *> EQUED = 'C' or 'B', each element of C must be positive. *> If C is output, each element of C is a power of the radix. *> If C is input, each element of C should be a power of the radix *> to ensure a reliable solution and error estimates. Scaling by *> powers of the radix does not cause rounding errors unless the *> result underflows or overflows. Rounding errors during scaling *> lead to refining with a matrix that is not equivalent to the *> input matrix, producing error estimates that may not be *> reliable. *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is REAL array, dimension (LDB,NRHS) *> On entry, the N-by-NRHS right hand side matrix B. *> On exit, *> if EQUED = 'N', B is not modified; *> if TRANS = 'N' and EQUED = 'R' or 'B', B is overwritten by *> diag(R)*B; *> if TRANS = 'T' or 'C' and EQUED = 'C' or 'B', B is *> overwritten by diag(C)*B. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of the array B. LDB >= max(1,N). *> \endverbatim *> *> \param[out] X *> \verbatim *> X is REAL array, dimension (LDX,NRHS) *> If INFO = 0, the N-by-NRHS solution matrix X to the original *> system of equations. Note that A and B are modified on exit *> if EQUED .ne. 'N', and the solution to the equilibrated system is *> inv(diag(C))*X if TRANS = 'N' and EQUED = 'C' or 'B', or *> inv(diag(R))*X if TRANS = 'T' or 'C' and EQUED = 'R' or 'B'. *> \endverbatim *> *> \param[in] LDX *> \verbatim *> LDX is INTEGER *> The leading dimension of the array X. LDX >= max(1,N). *> \endverbatim *> *> \param[out] RCOND *> \verbatim *> RCOND is REAL *> Reciprocal scaled condition number. This is an estimate of the *> reciprocal Skeel condition number of the matrix A after *> equilibration (if done). If this is less than the machine *> precision (in particular, if it is zero), the matrix is singular *> to working precision. Note that the error may still be small even *> if this number is very small and the matrix appears ill- *> conditioned. *> \endverbatim *> *> \param[out] RPVGRW *> \verbatim *> RPVGRW is REAL *> Reciprocal pivot growth. On exit, this contains the reciprocal *> pivot growth factor norm(A)/norm(U). The "max absolute element" *> norm is used. If this is much less than 1, then the stability of *> the LU factorization of the (equilibrated) matrix A could be poor. *> This also means that the solution X, estimated condition numbers, *> and error bounds could be unreliable. If factorization fails with *> 0<INFO<=N, then this contains the reciprocal pivot growth factor *> for the leading INFO columns of A. In SGESVX, this quantity is *> returned in WORK(1). *> \endverbatim *> *> \param[out] BERR *> \verbatim *> BERR is REAL array, dimension (NRHS) *> Componentwise relative backward error. This is the *> componentwise relative backward error of each solution vector X(j) *> (i.e., the smallest relative change in any element of A or B that *> makes X(j) an exact solution). *> \endverbatim *> *> \param[in] N_ERR_BNDS *> \verbatim *> N_ERR_BNDS is INTEGER *> Number of error bounds to return for each right hand side *> and each type (normwise or componentwise). See ERR_BNDS_NORM and *> ERR_BNDS_COMP below. *> \endverbatim *> *> \param[out] ERR_BNDS_NORM *> \verbatim *> ERR_BNDS_NORM is REAL array, dimension (NRHS, N_ERR_BNDS) *> For each right-hand side, this array contains information about *> various error bounds and condition numbers corresponding to the *> normwise relative error, which is defined as follows: *> *> Normwise relative error in the ith solution vector: *> max_j (abs(XTRUE(j,i) - X(j,i))) *> ------------------------------ *> max_j abs(X(j,i)) *> *> The array is indexed by the type of error information as described *> below. There currently are up to three pieces of information *> returned. *> *> The first index in ERR_BNDS_NORM(i,:) corresponds to the ith *> right-hand side. *> *> The second index in ERR_BNDS_NORM(:,err) contains the following *> three fields: *> err = 1 "Trust/don't trust" boolean. Trust the answer if the *> reciprocal condition number is less than the threshold *> sqrt(n) * slamch('Epsilon'). *> *> err = 2 "Guaranteed" error bound: The estimated forward error, *> almost certainly within a factor of 10 of the true error *> so long as the next entry is greater than the threshold *> sqrt(n) * slamch('Epsilon'). This error bound should only *> be trusted if the previous boolean is true. *> *> err = 3 Reciprocal condition number: Estimated normwise *> reciprocal condition number. Compared with the threshold *> sqrt(n) * slamch('Epsilon') to determine if the error *> estimate is "guaranteed". These reciprocal condition *> numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some *> appropriately scaled matrix Z. *> Let Z = S*A, where S scales each row by a power of the *> radix so all absolute row sums of Z are approximately 1. *> *> See Lapack Working Note 165 for further details and extra *> cautions. *> \endverbatim *> *> \param[out] ERR_BNDS_COMP *> \verbatim *> ERR_BNDS_COMP is REAL array, dimension (NRHS, N_ERR_BNDS) *> For each right-hand side, this array contains information about *> various error bounds and condition numbers corresponding to the *> componentwise relative error, which is defined as follows: *> *> Componentwise relative error in the ith solution vector: *> abs(XTRUE(j,i) - X(j,i)) *> max_j ---------------------- *> abs(X(j,i)) *> *> The array is indexed by the right-hand side i (on which the *> componentwise relative error depends), and the type of error *> information as described below. There currently are up to three *> pieces of information returned for each right-hand side. If *> componentwise accuracy is not requested (PARAMS(3) = 0.0), then *> ERR_BNDS_COMP is not accessed. If N_ERR_BNDS .LT. 3, then at most *> the first (:,N_ERR_BNDS) entries are returned. *> *> The first index in ERR_BNDS_COMP(i,:) corresponds to the ith *> right-hand side. *> *> The second index in ERR_BNDS_COMP(:,err) contains the following *> three fields: *> err = 1 "Trust/don't trust" boolean. Trust the answer if the *> reciprocal condition number is less than the threshold *> sqrt(n) * slamch('Epsilon'). *> *> err = 2 "Guaranteed" error bound: The estimated forward error, *> almost certainly within a factor of 10 of the true error *> so long as the next entry is greater than the threshold *> sqrt(n) * slamch('Epsilon'). This error bound should only *> be trusted if the previous boolean is true. *> *> err = 3 Reciprocal condition number: Estimated componentwise *> reciprocal condition number. Compared with the threshold *> sqrt(n) * slamch('Epsilon') to determine if the error *> estimate is "guaranteed". These reciprocal condition *> numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some *> appropriately scaled matrix Z. *> Let Z = S*(A*diag(x)), where x is the solution for the *> current right-hand side and S scales each row of *> A*diag(x) by a power of the radix so all absolute row *> sums of Z are approximately 1. *> *> See Lapack Working Note 165 for further details and extra *> cautions. *> \endverbatim *> *> \param[in] NPARAMS *> \verbatim *> NPARAMS is INTEGER *> Specifies the number of parameters set in PARAMS. If .LE. 0, the *> PARAMS array is never referenced and default values are used. *> \endverbatim *> *> \param[in,out] PARAMS *> \verbatim *> PARAMS is REAL array, dimension NPARAMS *> Specifies algorithm parameters. If an entry is .LT. 0.0, then *> that entry will be filled with default value used for that *> parameter. Only positions up to NPARAMS are accessed; defaults *> are used for higher-numbered parameters. *> *> PARAMS(LA_LINRX_ITREF_I = 1) : Whether to perform iterative *> refinement or not. *> Default: 1.0 *> = 0.0 : No refinement is performed, and no error bounds are *> computed. *> = 1.0 : Use the double-precision refinement algorithm, *> possibly with doubled-single computations if the *> compilation environment does not support DOUBLE *> PRECISION. *> (other values are reserved for future use) *> *> PARAMS(LA_LINRX_ITHRESH_I = 2) : Maximum number of residual *> computations allowed for refinement. *> Default: 10 *> Aggressive: Set to 100 to permit convergence using approximate *> factorizations or factorizations other than LU. If *> the factorization uses a technique other than *> Gaussian elimination, the guarantees in *> err_bnds_norm and err_bnds_comp may no longer be *> trustworthy. *> *> PARAMS(LA_LINRX_CWISE_I = 3) : Flag determining if the code *> will attempt to find a solution with small componentwise *> relative error in the double-precision algorithm. Positive *> is true, 0.0 is false. *> Default: 1.0 (attempt componentwise convergence) *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is REAL array, dimension (4*N) *> \endverbatim *> *> \param[out] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (N) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: Successful exit. The solution to every right-hand side is *> guaranteed. *> < 0: If INFO = -i, the i-th argument had an illegal value *> > 0 and <= N: U(INFO,INFO) is exactly zero. The factorization *> has been completed, but the factor U is exactly singular, so *> the solution and error bounds could not be computed. RCOND = 0 *> is returned. *> = N+J: The solution corresponding to the Jth right-hand side is *> not guaranteed. The solutions corresponding to other right- *> hand sides K with K > J may not be guaranteed as well, but *> only the first such right-hand side is reported. If a small *> componentwise error is not requested (PARAMS(3) = 0.0) then *> the Jth right-hand side is the first with a normwise error *> bound that is not guaranteed (the smallest J such *> that ERR_BNDS_NORM(J,1) = 0.0). By default (PARAMS(3) = 1.0) *> the Jth right-hand side is the first with either a normwise or *> componentwise error bound that is not guaranteed (the smallest *> J such that either ERR_BNDS_NORM(J,1) = 0.0 or *> ERR_BNDS_COMP(J,1) = 0.0). See the definition of *> ERR_BNDS_NORM(:,1) and ERR_BNDS_COMP(:,1). To get information *> about all of the right-hand sides check ERR_BNDS_NORM or *> ERR_BNDS_COMP. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date April 2012 * *> \ingroup realGEsolve * * ===================================================================== SUBROUTINE SGESVXX( FACT, TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, $ EQUED, R, C, B, LDB, X, LDX, RCOND, RPVGRW, $ BERR, N_ERR_BNDS, ERR_BNDS_NORM, $ ERR_BNDS_COMP, NPARAMS, PARAMS, WORK, IWORK, $ INFO ) * * -- LAPACK driver routine (version 3.4.1) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * April 2012 * * .. Scalar Arguments .. CHARACTER EQUED, FACT, TRANS INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS, NPARAMS, $ N_ERR_BNDS REAL RCOND, RPVGRW * .. * .. Array Arguments .. INTEGER IPIV( * ), IWORK( * ) REAL A( LDA, * ), AF( LDAF, * ), B( LDB, * ), $ X( LDX , * ),WORK( * ) REAL R( * ), C( * ), PARAMS( * ), BERR( * ), $ ERR_BNDS_NORM( NRHS, * ), $ ERR_BNDS_COMP( NRHS, * ) * .. * * ================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) INTEGER FINAL_NRM_ERR_I, FINAL_CMP_ERR_I, BERR_I INTEGER RCOND_I, NRM_RCOND_I, NRM_ERR_I, CMP_RCOND_I INTEGER CMP_ERR_I, PIV_GROWTH_I PARAMETER ( FINAL_NRM_ERR_I = 1, FINAL_CMP_ERR_I = 2, $ BERR_I = 3 ) PARAMETER ( RCOND_I = 4, NRM_RCOND_I = 5, NRM_ERR_I = 6 ) PARAMETER ( CMP_RCOND_I = 7, CMP_ERR_I = 8, $ PIV_GROWTH_I = 9 ) * .. * .. Local Scalars .. LOGICAL COLEQU, EQUIL, NOFACT, NOTRAN, ROWEQU INTEGER INFEQU, J REAL AMAX, BIGNUM, COLCND, RCMAX, RCMIN, ROWCND, $ SMLNUM * .. * .. External Functions .. EXTERNAL LSAME, SLAMCH, SLA_GERPVGRW LOGICAL LSAME REAL SLAMCH, SLA_GERPVGRW * .. * .. External Subroutines .. EXTERNAL SGEEQUB, SGETRF, SGETRS, SLACPY, SLAQGE, $ XERBLA, SLASCL2, SGERFSX * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. Executable Statements .. * INFO = 0 NOFACT = LSAME( FACT, 'N' ) EQUIL = LSAME( FACT, 'E' ) NOTRAN = LSAME( TRANS, 'N' ) SMLNUM = SLAMCH( 'Safe minimum' ) BIGNUM = ONE / SMLNUM IF( NOFACT .OR. EQUIL ) THEN EQUED = 'N' ROWEQU = .FALSE. COLEQU = .FALSE. ELSE ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' ) COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' ) END IF * * Default is failure. If an input parameter is wrong or * factorization fails, make everything look horrible. Only the * pivot growth is set here, the rest is initialized in SGERFSX. * RPVGRW = ZERO * * Test the input parameters. PARAMS is not tested until SGERFSX. * IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT. $ LSAME( FACT, 'F' ) ) THEN INFO = -1 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT. $ LSAME( TRANS, 'C' ) ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( NRHS.LT.0 ) THEN INFO = -4 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -6 ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN INFO = -8 ELSE IF( LSAME( FACT, 'F' ) .AND. .NOT. $ ( ROWEQU .OR. COLEQU .OR. LSAME( EQUED, 'N' ) ) ) THEN INFO = -10 ELSE IF( ROWEQU ) THEN RCMIN = BIGNUM RCMAX = ZERO DO 10 J = 1, N RCMIN = MIN( RCMIN, R( J ) ) RCMAX = MAX( RCMAX, R( J ) ) 10 CONTINUE IF( RCMIN.LE.ZERO ) THEN INFO = -11 ELSE IF( N.GT.0 ) THEN ROWCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM ) ELSE ROWCND = ONE END IF END IF IF( COLEQU .AND. INFO.EQ.0 ) THEN RCMIN = BIGNUM RCMAX = ZERO DO 20 J = 1, N RCMIN = MIN( RCMIN, C( J ) ) RCMAX = MAX( RCMAX, C( J ) ) 20 CONTINUE IF( RCMIN.LE.ZERO ) THEN INFO = -12 ELSE IF( N.GT.0 ) THEN COLCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM ) ELSE COLCND = ONE END IF END IF IF( INFO.EQ.0 ) THEN IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -14 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN INFO = -16 END IF END IF END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'SGESVXX', -INFO ) RETURN END IF * IF( EQUIL ) THEN * * Compute row and column scalings to equilibrate the matrix A. * CALL SGEEQUB( N, N, A, LDA, R, C, ROWCND, COLCND, AMAX, $ INFEQU ) IF( INFEQU.EQ.0 ) THEN * * Equilibrate the matrix. * CALL SLAQGE( N, N, A, LDA, R, C, ROWCND, COLCND, AMAX, $ EQUED ) ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' ) COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' ) END IF * * If the scaling factors are not applied, set them to 1.0. * IF ( .NOT.ROWEQU ) THEN DO J = 1, N R( J ) = 1.0 END DO END IF IF ( .NOT.COLEQU ) THEN DO J = 1, N C( J ) = 1.0 END DO END IF END IF * * Scale the right-hand side. * IF( NOTRAN ) THEN IF( ROWEQU ) CALL SLASCL2( N, NRHS, R, B, LDB ) ELSE IF( COLEQU ) CALL SLASCL2( N, NRHS, C, B, LDB ) END IF * IF( NOFACT .OR. EQUIL ) THEN * * Compute the LU factorization of A. * CALL SLACPY( 'Full', N, N, A, LDA, AF, LDAF ) CALL SGETRF( N, N, AF, LDAF, IPIV, INFO ) * * Return if INFO is non-zero. * IF( INFO.GT.0 ) THEN * * Pivot in column INFO is exactly 0 * Compute the reciprocal pivot growth factor of the * leading rank-deficient INFO columns of A. * RPVGRW = SLA_GERPVGRW( N, INFO, A, LDA, AF, LDAF ) RETURN END IF END IF * * Compute the reciprocal pivot growth factor RPVGRW. * RPVGRW = SLA_GERPVGRW( N, N, A, LDA, AF, LDAF ) * * Compute the solution matrix X. * CALL SLACPY( 'Full', N, NRHS, B, LDB, X, LDX ) CALL SGETRS( TRANS, N, NRHS, AF, LDAF, IPIV, X, LDX, INFO ) * * Use iterative refinement to improve the computed solution and * compute error bounds and backward error estimates for it. * CALL SGERFSX( TRANS, EQUED, N, NRHS, A, LDA, AF, LDAF, $ IPIV, R, C, B, LDB, X, LDX, RCOND, BERR, $ N_ERR_BNDS, ERR_BNDS_NORM, ERR_BNDS_COMP, NPARAMS, PARAMS, $ WORK, IWORK, INFO ) * * Scale solutions. * IF ( COLEQU .AND. NOTRAN ) THEN CALL SLASCL2 ( N, NRHS, C, X, LDX ) ELSE IF ( ROWEQU .AND. .NOT.NOTRAN ) THEN CALL SLASCL2 ( N, NRHS, R, X, LDX ) END IF * RETURN * * End of SGESVXX END
gpl-2.0
QEF/q-e
Modules/mbdlib.f90
1
6099
! ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !############################################################# ! This module computes the Many-Body Dispersion (MBD) ! van der Waals correction to the system. ! The implementation is based on a portable Fortran library ! by Jan Hermann. ! Written by S. Goger (Luxembourg) and H-Y. Ko (Cornell) !############################################################# MODULE libmbd_interface USE kinds, ONLY : DP USE io_global, ONLY : stdout USE tsvdw_module, ONLY : veff_pub, vfree_pub, vdw_isolated USE ions_base, ONLY : nat, atm, tau, ityp USE cell_base, ONLY : alat, at, ainv USE funct, ONLY : get_dft_short USE control_flags, ONLY : conv_elec USE constants, ONLY : ry_kbar #if !defined(__NOMBD) USE mbd, ONLY : mbd_input_t, mbd_calc_t #endif IMPLICIT NONE PUBLIC:: mbd_interface, init_mbd, clean_mbd REAL(dp), PUBLIC:: EmbdvdW ! MBD correction to the energy REAL(dp), DIMENSION(:,:), ALLOCATABLE, PUBLIC:: FmbdvdW ! Ionic force contribs. (-dE/dr) REAL(dp), DIMENSION(3, 3), PUBLIC:: HmbdvdW ! Cell derivative contribs. (-dE/da) REAL(dp), DIMENSION(3, 3) :: cell_derivs INTEGER:: na LOGICAL:: do_gradients #if !defined(__NOMBD) TYPE(mbd_input_t):: inp TYPE(mbd_calc_t):: calc #endif REAL(dp), DIMENSION(:), ALLOCATABLE:: ratios REAL(dp), DIMENSION(:,:), ALLOCATABLE:: mbd_gradient INTEGER:: code, ierr, my_rank, total CHARACTER(200):: origin, msg CONTAINS !############################################################# ! This subroutine sets up the library before the first call !############################################################# SUBROUTINE init_mbd ( nks_start, nk1, nk2, nk3, k1, k2, k3, tprnfor, tstress ) ! INTEGER, INTENT(IN) :: nks_start, nk1, nk2, nk3, k1, k2, k3 LOGICAL, INTENT(IN) :: tprnfor, tstress ! ! Allocation of variables that depend on the number of atoms ! #if defined(__NOMBD) CALL errore( 'libmbd_interface', 'Many-Body Dispersion not compiled',1) #else ALLOCATE(inp%atom_types(nat)) ! EmbdvdW = 0.0_dp do_gradients = tprnfor .OR. tstress IF ( do_gradients ) THEN ! IF(.NOT.ALLOCATED(mbd_gradient)) ALLOCATE(mbd_gradient(3, nat)) ! IF(.NOT.ALLOCATED(FmbdvdW)) ALLOCATE(FmbdvdW(3, nat)) ! END IF ! ALLOCATE(ratios(nat)) inp%log_level=1 ! ! Passing atom types and coordinates for LibMBD ! DO na = 1, nat inp%atom_types(na) = trim(atm(ityp(na))) ENDDO inp%coords = tau*alat ! HK-TODO: this one works for PW (check if it is for CP) ! ! If we pass lattice vectors to the library, it uses the algorithm for ! periodic system automatically ! IF( .NOT.vdw_isolated ) THEN inp%lattice_vectors = at*alat ! Lattice vector in real space ! IF ( nks_start == 0 ) THEN ! K-point mesh inp%k_grid = [nk1, nk2, nk3] inp%k_grid_shift = 0.5_DP ! IF (k1 .EQ. 0 .AND. k2 .EQ. 0 .AND. k3 .EQ. 0) & CALL infomsg('mbdlib','k-point shift ignored') ! ELSE inp%k_grid = [1, 1, 1] !set default k points grid inp%k_grid_shift = 0.5_DP ! set default shift ENDIF ! ENDIF ! WRITE(stdout, '(5x,"mbdlib: K-point grid set to ",3I3,", shift: ",F4.2)') & inp%k_grid, inp%k_grid_shift ! select case (TRIM(get_dft_short())) ! An empirical factor needs to be set based on the functiona CASE ('PBE') inp%xc = 'pbe' CASE ('PBE0') inp%xc = 'pbe0' CASE ('HSE') inp%xc = 'hse' CASE DEFAULT ! Block it off since parametrization is not possible CALL errore( 'libmbd_interface', 'current xc functional not yet supported for MBD@rsSCS, use PBE, PBE0 or HSE', 1 ) END SELECT CALL calc%init(inp) CALL calc%get_exception(code, origin, msg) IF (code > 0) THEN WRITE( stdout, * ) msg CALL errore( 'libmbd_interface', 'Many-Body Dispersion call crashed. This is most likely due to a numerical & & error, please check your system carefully.', 1 ) STOP ENDIF #endif END SUBROUTINE init_mbd !############################################################# ! This subroutine calculates the energy and (if needed) forces and stress !############################################################# SUBROUTINE mbd_interface() #if !defined(__NOMBD) IF (.NOT.conv_elec) RETURN ! Wavefunction derivatives are still in progress, !for now we only can add correction for converged wavefunction CALL infomsg('mbdlib','MBD wavefunction derivatives not yet supported. '//& & 'Performing non-self-consistent MBD calculation upon SCF convergence.') ! ! Passing the current parameters to the library CALL calc%update_coords(tau*alat) DO na = 1, nat ratios(na)=veff_pub(na)/vfree_pub(ityp(na)) ENDDO CALL calc%update_vdw_params_from_ratios(ratios) IF( .NOT.vdw_isolated ) THEN CALL calc%update_lattice_vectors(at*alat) ENDIF CALL calc%evaluate_vdw_method(EmbdvdW) !MBD energy IF ( do_gradients ) THEN CALL calc%get_gradients(mbd_gradient) FmbdvdW = -mbd_gradient ! Ionic forces with correct sign ENDIF ! IF( do_gradients .AND. .NOT.vdw_isolated ) THEN CALL calc%get_lattice_stress(cell_derivs) HmbdvdW=MATMUL(cell_derivs, TRANSPOSE(ainv)) ENDIF RETURN #endif END SUBROUTINE mbd_interface !############################################################# ! Subroutine to de-allocate internal variables !############################################################# SUBROUTINE clean_mbd() IMPLICIT NONE #if !defined(__NOMBD) CALL calc%destroy() IF(ALLOCATED(inp%atom_types)) DEALLOCATE(inp%atom_types) IF(ALLOCATED(ratios)) DEALLOCATE(ratios) IF(ALLOCATED(mbd_gradient)) DEALLOCATE(mbd_gradient) IF(ALLOCATED(veff_pub)) DEALLOCATE(veff_pub) IF(ALLOCATED(vfree_pub)) DEALLOCATE(vfree_pub) #endif END SUBROUTINE clean_mbd END MODULE libmbd_interface
gpl-2.0
QEF/q-e
atomic/src/scf.f90
2
5085
! ! Copyright (C) 2004i-2010 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !--------------------------------------------------------------- SUBROUTINE scf(ic) !--------------------------------------------------------------- ! ! this routine performs the atomic self-consistent procedure ! self-interaction-correction allowed ! USE kinds, ONLY : dp USE xc_lib, ONLY : xclib_dft_is USE radial_grids, ONLY : ndmx USE constants, ONLY: e2 USE ld1inc, ONLY : grid, zed, psi, isic, vpot, vh, vxt, rho, iter, & lsd, rel, latt, enne, beta, nspin, tr2, eps0, & nwf, nn, ll, jj, enl, oc, isw, core_state, frozen_core, & tau, vtau, vsic, vsicnew, vhn1, egc, relpert, noscf IMPLICIT NONE INTEGER, INTENT(in) :: ic LOGICAL:: meta, conv INTEGER:: nerr, nstop, n, i, is, id, nin real(DP) :: vnew(ndmx,2), vtaunew(ndmx), rhoc1(ndmx), ze2 INTEGER, PARAMETER :: maxter=200 real(DP), PARAMETER :: thresh=1.0e-10_dp ! ! meta = xclib_dft_is('meta') ze2 = - zed * e2 rhoc1=0.0_dp IF (.not.frozen_core.or.ic==1) psi=0.0_dp DO iter = 1,maxter nerr=0 vnew=vpot vtaunew=vtau DO n=1,nwf IF (oc(n) >= 0.0_dp) THEN IF (ic==1.or..not.frozen_core.or..not.core_state(n)) THEN is=isw(n) IF (isic /= 0 .and. iter > 1) vnew(:,is)=vpot(:,is)-vsic(:,n) IF (rel == 0) THEN ! nonrelativistic calculation IF ( meta ) THEN ! Meta-GGA version of lschps CALL lschps_meta (2, zed, thresh, grid, nin, nn(n), ll(n),& enl(n), vnew(1,is), vtaunew, psi(1,1,n), nstop) ELSE ! print *, "Solving nonrelativistic nonmeta equation" CALL ascheq (nn(n),ll(n),enl(n),grid%mesh,grid,& vnew(1,is), & ! potential ze2,thresh,psi(1,1,n),nstop) END IF ELSEIF (rel == 1) THEN ! relativistic scalar calculation IF ( meta ) THEN CALL lschps_meta (1, zed, thresh, grid, nin, nn(n), ll(n),& enl(n), vnew(1,is), vtaunew, psi(1,1,n), nstop) ELSE CALL lschps (1, zed, thresh, grid, nin, nn(n), ll(n),& enl(n), vnew(1,is), psi(1,1,n), nstop) END IF IF (nstop>0.and.oc(n)<1.e-10_DP) nstop=0 ELSEIF (rel == 2) THEN CALL dirsol (ndmx,grid%mesh,nn(n),ll(n),jj(n),iter,enl(n), & thresh,grid,psi(1,1,n),vnew(1,is),nstop) ELSE CALL errore('scf','relativistic not programmed',1) ENDIF ! write(6,*) nn(n),ll(n),enl(n) ! if (nstop /= 0) write(6,'(4i6)') iter,nn(n),ll(n),nstop nerr=nerr+nstop ENDIF ELSE enl(n)=0.0_dp psi(:,:,n)=0.0_dp ENDIF ENDDO ! ! calculate charge density (spherical approximation) ! rho=0.0_dp IF (noscf) GOTO 500 DO n=1,nwf rho(1:grid%mesh,isw(n))=rho(1:grid%mesh,isw(n)) + & oc(n)*(psi(1:grid%mesh,1,n)**2+psi(1:grid%mesh,2,n)**2) ENDDO ! ! calculate kinetc energy density (spherical approximation) ! IF ( meta ) CALL kin_e_density (ndmx, grid%mesh, nwf, & ll, oc, psi, grid%r, grid%r2, grid%dx, tau) ! ! calculate new potential ! CALL new_potential ( ndmx, grid%mesh, grid, zed, vxt, & lsd, .false., latt, enne, rhoc1, rho, vh, vnew, 1 ) ! ! calculate SIC correction potential (if present) ! IF (isic /= 0) THEN DO n=1,nwf IF (oc(n) >= 0.0_dp) THEN is=isw(n) CALL sic_correction(n,vhn1,vsicnew,egc) ! ! use simple mixing for SIC correction ! vsic(:,n) = (1.0_dp-beta)*vsic(:,n)+beta*vsicnew(:) ENDIF ENDDO ENDIF ! ! mix old and new potential ! id = 3 IF (isic /= 0 .and. relpert) id=1 ! CALL vpack(grid%mesh,ndmx,nspin,vnew,vpot,1) CALL dmixp(grid%mesh*nspin,vnew,vpot,beta,tr2,iter,id,eps0,conv,maxter) CALL vpack(grid%mesh,ndmx,nspin,vnew,vpot,-1) ! write(6,*) iter, eps0 ! ! mix old and new metaGGA potential - use simple mixing ! IF ( meta ) vtau(:) = (1.0_dp-beta)*vtaunew(:)+beta*vtau(:) ! 500 IF (noscf) THEN conv=.true. eps0 = 0.0_DP ENDIF IF (conv) THEN IF (nerr /= 0) CALL infomsg ('scf','warning: at least one error in KS equations') EXIT ! exit cycle ENDIF ENDDO IF ( .not. conv ) CALL infomsg('scf','warning: convergence not achieved') END SUBROUTINE scf
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/ilatrans.f
25
2575
*> \brief \b ILATRANS * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ILATRANS + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ilatrans.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ilatrans.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ilatrans.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * INTEGER FUNCTION ILATRANS( TRANS ) * * .. Scalar Arguments .. * CHARACTER TRANS * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> This subroutine translates from a character string specifying a *> transposition operation to the relevant BLAST-specified integer *> constant. *> *> ILATRANS returns an INTEGER. If ILATRANS < 0, then the input is not *> a character indicating a transposition operator. Otherwise ILATRANS *> returns the constant value corresponding to TRANS. *> \endverbatim * * Arguments: * ========== * * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup auxOTHERcomputational * * ===================================================================== INTEGER FUNCTION ILATRANS( TRANS ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER TRANS * .. * * ===================================================================== * * .. Parameters .. INTEGER BLAS_NO_TRANS, BLAS_TRANS, BLAS_CONJ_TRANS PARAMETER ( BLAS_NO_TRANS = 111, BLAS_TRANS = 112, $ BLAS_CONJ_TRANS = 113 ) * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. Executable Statements .. IF( LSAME( TRANS, 'N' ) ) THEN ILATRANS = BLAS_NO_TRANS ELSE IF( LSAME( TRANS, 'T' ) ) THEN ILATRANS = BLAS_TRANS ELSE IF( LSAME( TRANS, 'C' ) ) THEN ILATRANS = BLAS_CONJ_TRANS ELSE ILATRANS = -1 END IF RETURN * * End of ILATRANS * END
gpl-2.0
e-q/scipy
scipy/linalg/src/lapack_deprecations/sgegv.f
94
25204
*> \brief <b> SGEEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices</b> * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download SGEGV + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgegv.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgegv.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgegv.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE SGEGV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR, ALPHAI, * BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER JOBVL, JOBVR * INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N * .. * .. Array Arguments .. * REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), * $ B( LDB, * ), BETA( * ), VL( LDVL, * ), * $ VR( LDVR, * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> This routine is deprecated and has been replaced by routine SGGEV. *> *> SGEGV computes the eigenvalues and, optionally, the left and/or right *> eigenvectors of a real matrix pair (A,B). *> Given two square matrices A and B, *> the generalized nonsymmetric eigenvalue problem (GNEP) is to find the *> eigenvalues lambda and corresponding (non-zero) eigenvectors x such *> that *> *> A*x = lambda*B*x. *> *> An alternate form is to find the eigenvalues mu and corresponding *> eigenvectors y such that *> *> mu*A*y = B*y. *> *> These two forms are equivalent with mu = 1/lambda and x = y if *> neither lambda nor mu is zero. In order to deal with the case that *> lambda or mu is zero or small, two values alpha and beta are returned *> for each eigenvalue, such that lambda = alpha/beta and *> mu = beta/alpha. *> *> The vectors x and y in the above equations are right eigenvectors of *> the matrix pair (A,B). Vectors u and v satisfying *> *> u**H*A = lambda*u**H*B or mu*v**H*A = v**H*B *> *> are left eigenvectors of (A,B). *> *> Note: this routine performs "full balancing" on A and B *> \endverbatim * * Arguments: * ========== * *> \param[in] JOBVL *> \verbatim *> JOBVL is CHARACTER*1 *> = 'N': do not compute the left generalized eigenvectors; *> = 'V': compute the left generalized eigenvectors (returned *> in VL). *> \endverbatim *> *> \param[in] JOBVR *> \verbatim *> JOBVR is CHARACTER*1 *> = 'N': do not compute the right generalized eigenvectors; *> = 'V': compute the right generalized eigenvectors (returned *> in VR). *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrices A, B, VL, and VR. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is REAL array, dimension (LDA, N) *> On entry, the matrix A. *> If JOBVL = 'V' or JOBVR = 'V', then on exit A *> contains the real Schur form of A from the generalized Schur *> factorization of the pair (A,B) after balancing. *> If no eigenvectors were computed, then only the diagonal *> blocks from the Schur form will be correct. See SGGHRD and *> SHGEQZ for details. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of A. LDA >= max(1,N). *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is REAL array, dimension (LDB, N) *> On entry, the matrix B. *> If JOBVL = 'V' or JOBVR = 'V', then on exit B contains the *> upper triangular matrix obtained from B in the generalized *> Schur factorization of the pair (A,B) after balancing. *> If no eigenvectors were computed, then only those elements of *> B corresponding to the diagonal blocks from the Schur form of *> A will be correct. See SGGHRD and SHGEQZ for details. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of B. LDB >= max(1,N). *> \endverbatim *> *> \param[out] ALPHAR *> \verbatim *> ALPHAR is REAL array, dimension (N) *> The real parts of each scalar alpha defining an eigenvalue of *> GNEP. *> \endverbatim *> *> \param[out] ALPHAI *> \verbatim *> ALPHAI is REAL array, dimension (N) *> The imaginary parts of each scalar alpha defining an *> eigenvalue of GNEP. 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) = -ALPHAI(j). *> \endverbatim *> *> \param[out] BETA *> \verbatim *> BETA is REAL array, dimension (N) *> The scalars beta that define the eigenvalues of GNEP. *> *> Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and *> beta = BETA(j) represent the j-th eigenvalue of the matrix *> pair (A,B), in one of the forms lambda = alpha/beta or *> mu = beta/alpha. Since either lambda or mu may overflow, *> they should not, in general, be computed. *> \endverbatim *> *> \param[out] VL *> \verbatim *> VL is REAL array, dimension (LDVL,N) *> If JOBVL = 'V', the left eigenvectors u(j) are stored *> in the columns of VL, in the same order as their eigenvalues. *> If the j-th eigenvalue is real, then u(j) = VL(:,j). *> If the j-th and (j+1)-st eigenvalues form a complex conjugate *> pair, then *> u(j) = VL(:,j) + i*VL(:,j+1) *> and *> u(j+1) = VL(:,j) - i*VL(:,j+1). *> *> Each eigenvector is scaled so that its largest component has *> abs(real part) + abs(imag. part) = 1, except for eigenvectors *> corresponding to an eigenvalue with alpha = beta = 0, which *> are set to zero. *> Not referenced if JOBVL = 'N'. *> \endverbatim *> *> \param[in] LDVL *> \verbatim *> LDVL is INTEGER *> The leading dimension of the matrix VL. LDVL >= 1, and *> if JOBVL = 'V', LDVL >= N. *> \endverbatim *> *> \param[out] VR *> \verbatim *> VR is REAL array, dimension (LDVR,N) *> If JOBVR = 'V', the right eigenvectors x(j) are stored *> in the columns of VR, in the same order as their eigenvalues. *> If the j-th eigenvalue is real, then x(j) = VR(:,j). *> If the j-th and (j+1)-st eigenvalues form a complex conjugate *> pair, then *> x(j) = VR(:,j) + i*VR(:,j+1) *> and *> x(j+1) = VR(:,j) - i*VR(:,j+1). *> *> Each eigenvector is scaled so that its largest component has *> abs(real part) + abs(imag. part) = 1, except for eigenvalues *> corresponding to an eigenvalue with alpha = beta = 0, which *> are set to zero. *> Not referenced if JOBVR = 'N'. *> \endverbatim *> *> \param[in] LDVR *> \verbatim *> LDVR is INTEGER *> The leading dimension of the matrix VR. LDVR >= 1, and *> if JOBVR = 'V', LDVR >= N. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is REAL array, dimension (MAX(1,LWORK)) *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is 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 SGEQRF, SORMQR, and SORGQR.) Then compute: *> NB -- MAX of the blocksizes for SGEQRF, SORMQR, and SORGQR; *> 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. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is 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 SGGBAL *> =N+2: error return from SGEQRF *> =N+3: error return from SORMQR *> =N+4: error return from SORGQR *> =N+5: error return from SGGHRD *> =N+6: error return from SHGEQZ (other than failed *> iteration) *> =N+7: error return from STGEVC *> =N+8: error return from SGGBAK (computing VL) *> =N+9: error return from SGGBAK (computing VR) *> =N+10: error return from SLASCL (various calls) *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup realGEeigen * *> \par Further Details: * ===================== *> *> \verbatim *> *> Balancing *> --------- *> *> This driver calls SGGBAL 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, SGGBAK 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 SHGEQZ, SGEGS, or read the book "Matrix Computations", *> by Golub & van Loan, pub. by Johns Hopkins U. Press. *> \endverbatim *> * ===================================================================== SUBROUTINE SGEGV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR, ALPHAI, $ BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO ) * * -- LAPACK driver routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER JOBVL, JOBVR INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N * .. * .. Array Arguments .. REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), $ B( LDB, * ), BETA( * ), VL( LDVL, * ), $ VR( LDVR, * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 ) * .. * .. Local Scalars .. LOGICAL ILIMIT, ILV, ILVL, ILVR, LQUERY CHARACTER CHTEMP INTEGER ICOLS, IHI, IINFO, IJOBVL, IJOBVR, ILEFT, ILO, $ IN, IRIGHT, IROWS, ITAU, IWORK, JC, JR, LOPT, $ LWKMIN, LWKOPT, NB, NB1, NB2, NB3 REAL ABSAI, ABSAR, ABSB, ANRM, ANRM1, ANRM2, BNRM, $ BNRM1, BNRM2, EPS, ONEPLS, SAFMAX, SAFMIN, $ SALFAI, SALFAR, SBETA, SCALE, TEMP * .. * .. Local Arrays .. LOGICAL LDUMMA( 1 ) * .. * .. External Subroutines .. EXTERNAL SGEQRF, SGGBAK, SGGBAL, SGGHRD, SHGEQZ, SLACPY, $ SLASCL, SLASET, SORGQR, SORMQR, STGEVC, XERBLA * .. * .. External Functions .. LOGICAL LSAME INTEGER ILAENV REAL SLAMCH, SLANGE EXTERNAL ILAENV, LSAME, SLAMCH, SLANGE * .. * .. Intrinsic Functions .. INTRINSIC ABS, INT, MAX * .. * .. Executable Statements .. * * Decode the input arguments * IF( LSAME( JOBVL, 'N' ) ) THEN IJOBVL = 1 ILVL = .FALSE. ELSE IF( LSAME( JOBVL, 'V' ) ) THEN IJOBVL = 2 ILVL = .TRUE. ELSE IJOBVL = -1 ILVL = .FALSE. END IF * IF( LSAME( JOBVR, 'N' ) ) THEN IJOBVR = 1 ILVR = .FALSE. ELSE IF( LSAME( JOBVR, 'V' ) ) THEN IJOBVR = 2 ILVR = .TRUE. ELSE IJOBVR = -1 ILVR = .FALSE. END IF ILV = ILVL .OR. ILVR * * Test the input arguments * LWKMIN = MAX( 8*N, 1 ) LWKOPT = LWKMIN WORK( 1 ) = LWKOPT LQUERY = ( LWORK.EQ.-1 ) INFO = 0 IF( IJOBVL.LE.0 ) THEN INFO = -1 ELSE IF( IJOBVR.LE.0 ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -5 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -7 ELSE IF( LDVL.LT.1 .OR. ( ILVL .AND. LDVL.LT.N ) ) THEN INFO = -12 ELSE IF( LDVR.LT.1 .OR. ( ILVR .AND. LDVR.LT.N ) ) THEN INFO = -14 ELSE IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN INFO = -16 END IF * IF( INFO.EQ.0 ) THEN NB1 = ILAENV( 1, 'SGEQRF', ' ', N, N, -1, -1 ) NB2 = ILAENV( 1, 'SORMQR', ' ', N, N, N, -1 ) NB3 = ILAENV( 1, 'SORGQR', ' ', N, N, N, -1 ) NB = MAX( NB1, NB2, NB3 ) LOPT = 2*N + MAX( 6*N, N*(NB+1) ) WORK( 1 ) = LOPT END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'SGEGV ', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN * * Get machine constants * EPS = SLAMCH( 'E' )*SLAMCH( 'B' ) SAFMIN = SLAMCH( 'S' ) SAFMIN = SAFMIN + SAFMIN SAFMAX = ONE / SAFMIN ONEPLS = ONE + ( 4*EPS ) * * Scale A * ANRM = SLANGE( 'M', N, N, A, LDA, WORK ) ANRM1 = ANRM ANRM2 = ONE IF( ANRM.LT.ONE ) THEN IF( SAFMAX*ANRM.LT.ONE ) THEN ANRM1 = SAFMIN ANRM2 = SAFMAX*ANRM END IF END IF * IF( ANRM.GT.ZERO ) THEN CALL SLASCL( 'G', -1, -1, ANRM, ONE, N, N, A, LDA, IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 10 RETURN END IF END IF * * Scale B * BNRM = SLANGE( 'M', N, N, B, LDB, WORK ) BNRM1 = BNRM BNRM2 = ONE IF( BNRM.LT.ONE ) THEN IF( SAFMAX*BNRM.LT.ONE ) THEN BNRM1 = SAFMIN BNRM2 = SAFMAX*BNRM END IF END IF * IF( BNRM.GT.ZERO ) THEN CALL SLASCL( 'G', -1, -1, BNRM, ONE, N, N, B, LDB, IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 10 RETURN END IF END IF * * Permute the matrix to make it more nearly triangular * Workspace layout: (8*N words -- "work" requires 6*N words) * left_permutation, right_permutation, work... * ILEFT = 1 IRIGHT = N + 1 IWORK = IRIGHT + N CALL SGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, WORK( ILEFT ), $ WORK( IRIGHT ), WORK( IWORK ), IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 1 GO TO 120 END IF * * Reduce B to triangular form, and initialize VL and/or VR * Workspace layout: ("work..." must have at least N words) * left_permutation, right_permutation, tau, work... * IROWS = IHI + 1 - ILO IF( ILV ) THEN ICOLS = N + 1 - ILO ELSE ICOLS = IROWS END IF ITAU = IWORK IWORK = ITAU + IROWS CALL SGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ), $ WORK( IWORK ), LWORK+1-IWORK, IINFO ) IF( IINFO.GE.0 ) $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 ) IF( IINFO.NE.0 ) THEN INFO = N + 2 GO TO 120 END IF * CALL SORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB, $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWORK ), $ LWORK+1-IWORK, IINFO ) IF( IINFO.GE.0 ) $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 ) IF( IINFO.NE.0 ) THEN INFO = N + 3 GO TO 120 END IF * IF( ILVL ) THEN CALL SLASET( 'Full', N, N, ZERO, ONE, VL, LDVL ) CALL SLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB, $ VL( ILO+1, ILO ), LDVL ) CALL SORGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL, $ WORK( ITAU ), WORK( IWORK ), LWORK+1-IWORK, $ IINFO ) IF( IINFO.GE.0 ) $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 ) IF( IINFO.NE.0 ) THEN INFO = N + 4 GO TO 120 END IF END IF * IF( ILVR ) $ CALL SLASET( 'Full', N, N, ZERO, ONE, VR, LDVR ) * * Reduce to generalized Hessenberg form * IF( ILV ) THEN * * Eigenvectors requested -- work on whole matrix. * CALL SGGHRD( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL, $ LDVL, VR, LDVR, IINFO ) ELSE CALL SGGHRD( 'N', 'N', IROWS, 1, IROWS, A( ILO, ILO ), LDA, $ B( ILO, ILO ), LDB, VL, LDVL, VR, LDVR, IINFO ) END IF IF( IINFO.NE.0 ) THEN INFO = N + 5 GO TO 120 END IF * * Perform QZ algorithm * Workspace layout: ("work..." must have at least 1 word) * left_permutation, right_permutation, work... * IWORK = ITAU IF( ILV ) THEN CHTEMP = 'S' ELSE CHTEMP = 'E' END IF CALL SHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, $ WORK( IWORK ), LWORK+1-IWORK, IINFO ) IF( IINFO.GE.0 ) $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 ) IF( IINFO.NE.0 ) THEN IF( IINFO.GT.0 .AND. IINFO.LE.N ) THEN INFO = IINFO ELSE IF( IINFO.GT.N .AND. IINFO.LE.2*N ) THEN INFO = IINFO - N ELSE INFO = N + 6 END IF GO TO 120 END IF * IF( ILV ) THEN * * Compute Eigenvectors (STGEVC requires 6*N words of workspace) * IF( ILVL ) THEN IF( ILVR ) THEN CHTEMP = 'B' ELSE CHTEMP = 'L' END IF ELSE CHTEMP = 'R' END IF * CALL STGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL, LDVL, $ VR, LDVR, N, IN, WORK( IWORK ), IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 7 GO TO 120 END IF * * Undo balancing on VL and VR, rescale * IF( ILVL ) THEN CALL SGGBAK( 'P', 'L', N, ILO, IHI, WORK( ILEFT ), $ WORK( IRIGHT ), N, VL, LDVL, IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 8 GO TO 120 END IF DO 50 JC = 1, N IF( ALPHAI( JC ).LT.ZERO ) $ GO TO 50 TEMP = ZERO IF( ALPHAI( JC ).EQ.ZERO ) THEN DO 10 JR = 1, N TEMP = MAX( TEMP, ABS( VL( JR, JC ) ) ) 10 CONTINUE ELSE DO 20 JR = 1, N TEMP = MAX( TEMP, ABS( VL( JR, JC ) )+ $ ABS( VL( JR, JC+1 ) ) ) 20 CONTINUE END IF IF( TEMP.LT.SAFMIN ) $ GO TO 50 TEMP = ONE / TEMP IF( ALPHAI( JC ).EQ.ZERO ) THEN DO 30 JR = 1, N VL( JR, JC ) = VL( JR, JC )*TEMP 30 CONTINUE ELSE DO 40 JR = 1, N VL( JR, JC ) = VL( JR, JC )*TEMP VL( JR, JC+1 ) = VL( JR, JC+1 )*TEMP 40 CONTINUE END IF 50 CONTINUE END IF IF( ILVR ) THEN CALL SGGBAK( 'P', 'R', N, ILO, IHI, WORK( ILEFT ), $ WORK( IRIGHT ), N, VR, LDVR, IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 9 GO TO 120 END IF DO 100 JC = 1, N IF( ALPHAI( JC ).LT.ZERO ) $ GO TO 100 TEMP = ZERO IF( ALPHAI( JC ).EQ.ZERO ) THEN DO 60 JR = 1, N TEMP = MAX( TEMP, ABS( VR( JR, JC ) ) ) 60 CONTINUE ELSE DO 70 JR = 1, N TEMP = MAX( TEMP, ABS( VR( JR, JC ) )+ $ ABS( VR( JR, JC+1 ) ) ) 70 CONTINUE END IF IF( TEMP.LT.SAFMIN ) $ GO TO 100 TEMP = ONE / TEMP IF( ALPHAI( JC ).EQ.ZERO ) THEN DO 80 JR = 1, N VR( JR, JC ) = VR( JR, JC )*TEMP 80 CONTINUE ELSE DO 90 JR = 1, N VR( JR, JC ) = VR( JR, JC )*TEMP VR( JR, JC+1 ) = VR( JR, JC+1 )*TEMP 90 CONTINUE END IF 100 CONTINUE END IF * * End of eigenvector calculation * END IF * * Undo scaling in alpha, beta * * Note: this does not give the alpha and beta for the unscaled * problem. * * Un-scaling is limited to avoid underflow in alpha and beta * if they are significant. * DO 110 JC = 1, N ABSAR = ABS( ALPHAR( JC ) ) ABSAI = ABS( ALPHAI( JC ) ) ABSB = ABS( BETA( JC ) ) SALFAR = ANRM*ALPHAR( JC ) SALFAI = ANRM*ALPHAI( JC ) SBETA = BNRM*BETA( JC ) ILIMIT = .FALSE. SCALE = ONE * * Check for significant underflow in ALPHAI * IF( ABS( SALFAI ).LT.SAFMIN .AND. ABSAI.GE. $ MAX( SAFMIN, EPS*ABSAR, EPS*ABSB ) ) THEN ILIMIT = .TRUE. SCALE = ( ONEPLS*SAFMIN / ANRM1 ) / $ MAX( ONEPLS*SAFMIN, ANRM2*ABSAI ) * ELSE IF( SALFAI.EQ.ZERO ) THEN * * If insignificant underflow in ALPHAI, then make the * conjugate eigenvalue real. * IF( ALPHAI( JC ).LT.ZERO .AND. JC.GT.1 ) THEN ALPHAI( JC-1 ) = ZERO ELSE IF( ALPHAI( JC ).GT.ZERO .AND. JC.LT.N ) THEN ALPHAI( JC+1 ) = ZERO END IF END IF * * Check for significant underflow in ALPHAR * IF( ABS( SALFAR ).LT.SAFMIN .AND. ABSAR.GE. $ MAX( SAFMIN, EPS*ABSAI, EPS*ABSB ) ) THEN ILIMIT = .TRUE. SCALE = MAX( SCALE, ( ONEPLS*SAFMIN / ANRM1 ) / $ MAX( ONEPLS*SAFMIN, ANRM2*ABSAR ) ) END IF * * Check for significant underflow in BETA * IF( ABS( SBETA ).LT.SAFMIN .AND. ABSB.GE. $ MAX( SAFMIN, EPS*ABSAR, EPS*ABSAI ) ) THEN ILIMIT = .TRUE. SCALE = MAX( SCALE, ( ONEPLS*SAFMIN / BNRM1 ) / $ MAX( ONEPLS*SAFMIN, BNRM2*ABSB ) ) END IF * * Check for possible overflow when limiting scaling * IF( ILIMIT ) THEN TEMP = ( SCALE*SAFMIN )*MAX( ABS( SALFAR ), ABS( SALFAI ), $ ABS( SBETA ) ) IF( TEMP.GT.ONE ) $ SCALE = SCALE / TEMP IF( SCALE.LT.ONE ) $ ILIMIT = .FALSE. END IF * * Recompute un-scaled ALPHAR, ALPHAI, BETA if necessary. * IF( ILIMIT ) THEN SALFAR = ( SCALE*ALPHAR( JC ) )*ANRM SALFAI = ( SCALE*ALPHAI( JC ) )*ANRM SBETA = ( SCALE*BETA( JC ) )*BNRM END IF ALPHAR( JC ) = SALFAR ALPHAI( JC ) = SALFAI BETA( JC ) = SBETA 110 CONTINUE * 120 CONTINUE WORK( 1 ) = LWKOPT * RETURN * * End of SGEGV * END
bsd-3-clause
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/EIG/sdrges.f
32
36972
*> \brief \b SDRGES * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE SDRGES( NSIZES, NN, NTYPES, DOTYPE, ISEED, THRESH, * NOUNIT, A, LDA, B, S, T, Q, LDQ, Z, ALPHAR, * ALPHAI, BETA, WORK, LWORK, RESULT, BWORK, * INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, LDQ, LWORK, NOUNIT, NSIZES, NTYPES * REAL THRESH * .. * .. Array Arguments .. * LOGICAL BWORK( * ), DOTYPE( * ) * INTEGER ISEED( 4 ), NN( * ) * REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), * $ B( LDA, * ), BETA( * ), Q( LDQ, * ), * $ RESULT( 13 ), S( LDA, * ), T( LDA, * ), * $ WORK( * ), Z( LDQ, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SDRGES checks the nonsymmetric generalized eigenvalue (Schur form) *> problem driver SGGES. *> *> SGGES factors A and B as Q S Z' and Q T Z' , where ' means *> transpose, T is upper triangular, S is in generalized Schur form *> (block upper triangular, with 1x1 and 2x2 blocks on the diagonal, *> the 2x2 blocks corresponding to complex conjugate pairs of *> generalized eigenvalues), and Q and Z are orthogonal. It also *> computes the generalized eigenvalues (alpha(j),beta(j)), j=1,...,n, *> Thus, w(j) = alpha(j)/beta(j) is a root of the characteristic *> equation *> det( A - w(j) B ) = 0 *> Optionally it also reorder the eigenvalues so that a selected *> cluster of eigenvalues appears in the leading diagonal block of the *> Schur forms. *> *> When SDRGES is called, a number of matrix "sizes" ("N's") and a *> number of matrix "TYPES" are specified. For each size ("N") *> and each TYPE of matrix, a pair of matrices (A, B) will be generated *> and used for testing. For each matrix pair, the following 13 tests *> will be performed and compared with the threshhold THRESH except *> the tests (5), (11) and (13). *> *> *> (1) | A - Q S Z' | / ( |A| n ulp ) (no sorting of eigenvalues) *> *> *> (2) | B - Q T Z' | / ( |B| n ulp ) (no sorting of eigenvalues) *> *> *> (3) | I - QQ' | / ( n ulp ) (no sorting of eigenvalues) *> *> *> (4) | I - ZZ' | / ( n ulp ) (no sorting of eigenvalues) *> *> (5) if A is in Schur form (i.e. quasi-triangular form) *> (no sorting of eigenvalues) *> *> (6) if eigenvalues = diagonal blocks of the Schur form (S, T), *> i.e., test the maximum over j of D(j) where: *> *> if alpha(j) is real: *> |alpha(j) - S(j,j)| |beta(j) - T(j,j)| *> D(j) = ------------------------ + ----------------------- *> max(|alpha(j)|,|S(j,j)|) max(|beta(j)|,|T(j,j)|) *> *> if alpha(j) is complex: *> | det( s S - w T ) | *> D(j) = --------------------------------------------------- *> ulp max( s norm(S), |w| norm(T) )*norm( s S - w T ) *> *> and S and T are here the 2 x 2 diagonal blocks of S and T *> corresponding to the j-th and j+1-th eigenvalues. *> (no sorting of eigenvalues) *> *> (7) | (A,B) - Q (S,T) Z' | / ( | (A,B) | n ulp ) *> (with sorting of eigenvalues). *> *> (8) | I - QQ' | / ( n ulp ) (with sorting of eigenvalues). *> *> (9) | I - ZZ' | / ( n ulp ) (with sorting of eigenvalues). *> *> (10) if A is in Schur form (i.e. quasi-triangular form) *> (with sorting of eigenvalues). *> *> (11) if eigenvalues = diagonal blocks of the Schur form (S, T), *> i.e. test the maximum over j of D(j) where: *> *> if alpha(j) is real: *> |alpha(j) - S(j,j)| |beta(j) - T(j,j)| *> D(j) = ------------------------ + ----------------------- *> max(|alpha(j)|,|S(j,j)|) max(|beta(j)|,|T(j,j)|) *> *> if alpha(j) is complex: *> | det( s S - w T ) | *> D(j) = --------------------------------------------------- *> ulp max( s norm(S), |w| norm(T) )*norm( s S - w T ) *> *> and S and T are here the 2 x 2 diagonal blocks of S and T *> corresponding to the j-th and j+1-th eigenvalues. *> (with sorting of eigenvalues). *> *> (12) if sorting worked and SDIM is the number of eigenvalues *> which were SELECTed. *> *> Test Matrices *> ============= *> *> The sizes of the test matrices are specified by an array *> NN(1:NSIZES); the value of each element NN(j) specifies one size. *> The "types" are specified by a logical array DOTYPE( 1:NTYPES ); if *> DOTYPE(j) is .TRUE., then matrix type "j" will be generated. *> Currently, the list of possible types is: *> *> (1) ( 0, 0 ) (a pair of zero matrices) *> *> (2) ( I, 0 ) (an identity and a zero matrix) *> *> (3) ( 0, I ) (an identity and a zero matrix) *> *> (4) ( I, I ) (a pair of identity matrices) *> *> t t *> (5) ( J , J ) (a pair of transposed Jordan blocks) *> *> t ( I 0 ) *> (6) ( X, Y ) where X = ( J 0 ) and Y = ( t ) *> ( 0 I ) ( 0 J ) *> and I is a k x k identity and J a (k+1)x(k+1) *> Jordan block; k=(N-1)/2 *> *> (7) ( D, I ) where D is diag( 0, 1,..., N-1 ) (a diagonal *> matrix with those diagonal entries.) *> (8) ( I, D ) *> *> (9) ( big*D, small*I ) where "big" is near overflow and small=1/big *> *> (10) ( small*D, big*I ) *> *> (11) ( big*I, small*D ) *> *> (12) ( small*I, big*D ) *> *> (13) ( big*D, big*I ) *> *> (14) ( small*D, small*I ) *> *> (15) ( D1, D2 ) where D1 is diag( 0, 0, 1, ..., N-3, 0 ) and *> D2 is diag( 0, N-3, N-4,..., 1, 0, 0 ) *> t t *> (16) Q ( J , J ) Z where Q and Z are random orthogonal matrices. *> *> (17) Q ( T1, T2 ) Z where T1 and T2 are upper triangular matrices *> with random O(1) entries above the diagonal *> and diagonal entries diag(T1) = *> ( 0, 0, 1, ..., N-3, 0 ) and diag(T2) = *> ( 0, N-3, N-4,..., 1, 0, 0 ) *> *> (18) Q ( T1, T2 ) Z diag(T1) = ( 0, 0, 1, 1, s, ..., s, 0 ) *> diag(T2) = ( 0, 1, 0, 1,..., 1, 0 ) *> s = machine precision. *> *> (19) Q ( T1, T2 ) Z diag(T1)=( 0,0,1,1, 1-d, ..., 1-(N-5)*d=s, 0 ) *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0 ) *> *> N-5 *> (20) Q ( T1, T2 ) Z diag(T1)=( 0, 0, 1, 1, a, ..., a =s, 0 ) *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0, 0 ) *> *> (21) Q ( T1, T2 ) Z diag(T1)=( 0, 0, 1, r1, r2, ..., r(N-4), 0 ) *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0, 0 ) *> where r1,..., r(N-4) are random. *> *> (22) Q ( big*T1, small*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (23) Q ( small*T1, big*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (24) Q ( small*T1, small*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (25) Q ( big*T1, big*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (26) Q ( T1, T2 ) Z where T1 and T2 are random upper-triangular *> matrices. *> *> \endverbatim * * Arguments: * ========== * *> \param[in] NSIZES *> \verbatim *> NSIZES is INTEGER *> The number of sizes of matrices to use. If it is zero, *> SDRGES does nothing. NSIZES >= 0. *> \endverbatim *> *> \param[in] NN *> \verbatim *> NN is INTEGER array, dimension (NSIZES) *> An array containing the sizes to be used for the matrices. *> Zero values will be skipped. NN >= 0. *> \endverbatim *> *> \param[in] NTYPES *> \verbatim *> NTYPES is INTEGER *> The number of elements in DOTYPE. If it is zero, SDRGES *> does nothing. It must be at least zero. If it is MAXTYP+1 *> and NSIZES is 1, then an additional type, MAXTYP+1 is *> defined, which is to use whatever matrix is in A on input. *> This is only useful if DOTYPE(1:MAXTYP) is .FALSE. and *> DOTYPE(MAXTYP+1) is .TRUE. . *> \endverbatim *> *> \param[in] DOTYPE *> \verbatim *> DOTYPE is LOGICAL array, dimension (NTYPES) *> If DOTYPE(j) is .TRUE., then for each size in NN a *> matrix of that size and of type j will be generated. *> If NTYPES is smaller than the maximum number of types *> defined (PARAMETER MAXTYP), then types NTYPES+1 through *> MAXTYP will not be generated. If NTYPES is larger *> than MAXTYP, DOTYPE(MAXTYP+1) through DOTYPE(NTYPES) *> will be ignored. *> \endverbatim *> *> \param[in,out] ISEED *> \verbatim *> ISEED is INTEGER array, dimension (4) *> On entry ISEED specifies the seed of the random number *> generator. The array elements should be between 0 and 4095; *> if not they will be reduced mod 4096. Also, ISEED(4) must *> be odd. The random number generator uses a linear *> congruential sequence limited to small integers, and so *> should produce machine independent random numbers. The *> values of ISEED are changed on exit, and can be used in the *> next call to SDRGES to continue the same random number *> sequence. *> \endverbatim *> *> \param[in] THRESH *> \verbatim *> THRESH is REAL *> A test will count as "failed" if the "error", computed as *> described above, exceeds THRESH. Note that the error is *> scaled to be O(1), so THRESH should be a reasonably small *> multiple of 1, e.g., 10 or 100. In particular, it should *> not depend on the precision (single vs. double) or the size *> of the matrix. THRESH >= 0. *> \endverbatim *> *> \param[in] NOUNIT *> \verbatim *> NOUNIT is INTEGER *> The FORTRAN unit number for printing out error messages *> (e.g., if a routine returns IINFO not equal to 0.) *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is REAL array, *> dimension(LDA, max(NN)) *> Used to hold the original A matrix. Used as input only *> if NTYPES=MAXTYP+1, DOTYPE(1:MAXTYP)=.FALSE., and *> DOTYPE(MAXTYP+1)=.TRUE. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of A, B, S, and T. *> It must be at least 1 and at least max( NN ). *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is REAL array, *> dimension(LDA, max(NN)) *> Used to hold the original B matrix. Used as input only *> if NTYPES=MAXTYP+1, DOTYPE(1:MAXTYP)=.FALSE., and *> DOTYPE(MAXTYP+1)=.TRUE. *> \endverbatim *> *> \param[out] S *> \verbatim *> S is REAL array, dimension (LDA, max(NN)) *> The Schur form matrix computed from A by SGGES. On exit, S *> contains the Schur form matrix corresponding to the matrix *> in A. *> \endverbatim *> *> \param[out] T *> \verbatim *> T is REAL array, dimension (LDA, max(NN)) *> The upper triangular matrix computed from B by SGGES. *> \endverbatim *> *> \param[out] Q *> \verbatim *> Q is REAL array, dimension (LDQ, max(NN)) *> The (left) orthogonal matrix computed by SGGES. *> \endverbatim *> *> \param[in] LDQ *> \verbatim *> LDQ is INTEGER *> The leading dimension of Q and Z. It must *> be at least 1 and at least max( NN ). *> \endverbatim *> *> \param[out] Z *> \verbatim *> Z is REAL array, dimension( LDQ, max(NN) ) *> The (right) orthogonal matrix computed by SGGES. *> \endverbatim *> *> \param[out] ALPHAR *> \verbatim *> ALPHAR is REAL array, dimension (max(NN)) *> \endverbatim *> *> \param[out] ALPHAI *> \verbatim *> ALPHAI is REAL array, dimension (max(NN)) *> \endverbatim *> *> \param[out] BETA *> \verbatim *> BETA is REAL array, dimension (max(NN)) *> *> The generalized eigenvalues of (A,B) computed by SGGES. *> ( ALPHAR(k)+ALPHAI(k)*i ) / BETA(k) is the k-th *> generalized eigenvalue of A and B. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is REAL array, dimension (LWORK) *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The dimension of the array WORK. *> LWORK >= MAX( 10*(N+1), 3*N*N ), where N is the largest *> matrix dimension. *> \endverbatim *> *> \param[out] RESULT *> \verbatim *> RESULT is REAL array, dimension (15) *> The values computed by the tests described above. *> The values are currently limited to 1/ulp, to avoid overflow. *> \endverbatim *> *> \param[out] BWORK *> \verbatim *> BWORK is LOGICAL array, dimension (N) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value. *> > 0: A routine returned an error code. INFO is the *> absolute value of the INFO value returned. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup single_eig * * ===================================================================== SUBROUTINE SDRGES( NSIZES, NN, NTYPES, DOTYPE, ISEED, THRESH, $ NOUNIT, A, LDA, B, S, T, Q, LDQ, Z, ALPHAR, $ ALPHAI, BETA, WORK, LWORK, RESULT, BWORK, $ INFO ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER INFO, LDA, LDQ, LWORK, NOUNIT, NSIZES, NTYPES REAL THRESH * .. * .. Array Arguments .. LOGICAL BWORK( * ), DOTYPE( * ) INTEGER ISEED( 4 ), NN( * ) REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), $ B( LDA, * ), BETA( * ), Q( LDQ, * ), $ RESULT( 13 ), S( LDA, * ), T( LDA, * ), $ WORK( * ), Z( LDQ, * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) INTEGER MAXTYP PARAMETER ( MAXTYP = 26 ) * .. * .. Local Scalars .. LOGICAL BADNN, ILABAD CHARACTER SORT INTEGER I, I1, IADD, IERR, IINFO, IN, ISORT, J, JC, JR, $ JSIZE, JTYPE, KNTEIG, MAXWRK, MINWRK, MTYPES, $ N, N1, NB, NERRS, NMATS, NMAX, NTEST, NTESTT, $ RSUB, SDIM REAL SAFMAX, SAFMIN, TEMP1, TEMP2, ULP, ULPINV * .. * .. Local Arrays .. INTEGER IASIGN( MAXTYP ), IBSIGN( MAXTYP ), $ IOLDSD( 4 ), KADD( 6 ), KAMAGN( MAXTYP ), $ KATYPE( MAXTYP ), KAZERO( MAXTYP ), $ KBMAGN( MAXTYP ), KBTYPE( MAXTYP ), $ KBZERO( MAXTYP ), KCLASS( MAXTYP ), $ KTRIAN( MAXTYP ), KZ1( 6 ), KZ2( 6 ) REAL RMAGN( 0: 3 ) * .. * .. External Functions .. LOGICAL SLCTES INTEGER ILAENV REAL SLAMCH, SLARND EXTERNAL SLCTES, ILAENV, SLAMCH, SLARND * .. * .. External Subroutines .. EXTERNAL ALASVM, SGET51, SGET53, SGET54, SGGES, SLABAD, $ SLACPY, SLARFG, SLASET, SLATM4, SORM2R, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX, MIN, REAL, SIGN * .. * .. Data statements .. DATA KCLASS / 15*1, 10*2, 1*3 / DATA KZ1 / 0, 1, 2, 1, 3, 3 / DATA KZ2 / 0, 0, 1, 2, 1, 1 / DATA KADD / 0, 0, 0, 0, 3, 2 / DATA KATYPE / 0, 1, 0, 1, 2, 3, 4, 1, 4, 4, 1, 1, 4, $ 4, 4, 2, 4, 5, 8, 7, 9, 4*4, 0 / DATA KBTYPE / 0, 0, 1, 1, 2, -3, 1, 4, 1, 1, 4, 4, $ 1, 1, -4, 2, -4, 8*8, 0 / DATA KAZERO / 6*1, 2, 1, 2*2, 2*1, 2*2, 3, 1, 3, $ 4*5, 4*3, 1 / DATA KBZERO / 6*1, 1, 2, 2*1, 2*2, 2*1, 4, 1, 4, $ 4*6, 4*4, 1 / DATA KAMAGN / 8*1, 2, 3, 2, 3, 2, 3, 7*1, 2, 3, 3, $ 2, 1 / DATA KBMAGN / 8*1, 3, 2, 3, 2, 2, 3, 7*1, 3, 2, 3, $ 2, 1 / DATA KTRIAN / 16*0, 10*1 / DATA IASIGN / 6*0, 2, 0, 2*2, 2*0, 3*2, 0, 2, 3*0, $ 5*2, 0 / DATA IBSIGN / 7*0, 2, 2*0, 2*2, 2*0, 2, 0, 2, 9*0 / * .. * .. Executable Statements .. * * Check for errors * INFO = 0 * BADNN = .FALSE. NMAX = 1 DO 10 J = 1, NSIZES NMAX = MAX( NMAX, NN( J ) ) IF( NN( J ).LT.0 ) $ BADNN = .TRUE. 10 CONTINUE * IF( NSIZES.LT.0 ) THEN INFO = -1 ELSE IF( BADNN ) THEN INFO = -2 ELSE IF( NTYPES.LT.0 ) THEN INFO = -3 ELSE IF( THRESH.LT.ZERO ) THEN INFO = -6 ELSE IF( LDA.LE.1 .OR. LDA.LT.NMAX ) THEN INFO = -9 ELSE IF( LDQ.LE.1 .OR. LDQ.LT.NMAX ) THEN INFO = -14 END IF * * Compute workspace * (Note: Comments in the code beginning "Workspace:" describe the * minimal amount of workspace needed at that point in the code, * as well as the preferred amount for good performance. * NB refers to the optimal block size for the immediately * following subroutine, as returned by ILAENV. * MINWRK = 1 IF( INFO.EQ.0 .AND. LWORK.GE.1 ) THEN MINWRK = MAX( 10*( NMAX+1 ), 3*NMAX*NMAX ) NB = MAX( 1, ILAENV( 1, 'SGEQRF', ' ', NMAX, NMAX, -1, -1 ), $ ILAENV( 1, 'SORMQR', 'LT', NMAX, NMAX, NMAX, -1 ), $ ILAENV( 1, 'SORGQR', ' ', NMAX, NMAX, NMAX, -1 ) ) MAXWRK = MAX( 10*( NMAX+1 ), 2*NMAX+NMAX*NB, 3*NMAX*NMAX ) WORK( 1 ) = MAXWRK END IF * IF( LWORK.LT.MINWRK ) $ INFO = -20 * IF( INFO.NE.0 ) THEN CALL XERBLA( 'SDRGES', -INFO ) RETURN END IF * * Quick return if possible * IF( NSIZES.EQ.0 .OR. NTYPES.EQ.0 ) $ RETURN * SAFMIN = SLAMCH( 'Safe minimum' ) ULP = SLAMCH( 'Epsilon' )*SLAMCH( 'Base' ) SAFMIN = SAFMIN / ULP SAFMAX = ONE / SAFMIN CALL SLABAD( SAFMIN, SAFMAX ) ULPINV = ONE / ULP * * The values RMAGN(2:3) depend on N, see below. * RMAGN( 0 ) = ZERO RMAGN( 1 ) = ONE * * Loop over matrix sizes * NTESTT = 0 NERRS = 0 NMATS = 0 * DO 190 JSIZE = 1, NSIZES N = NN( JSIZE ) N1 = MAX( 1, N ) RMAGN( 2 ) = SAFMAX*ULP / REAL( N1 ) RMAGN( 3 ) = SAFMIN*ULPINV*REAL( N1 ) * IF( NSIZES.NE.1 ) THEN MTYPES = MIN( MAXTYP, NTYPES ) ELSE MTYPES = MIN( MAXTYP+1, NTYPES ) END IF * * Loop over matrix types * DO 180 JTYPE = 1, MTYPES IF( .NOT.DOTYPE( JTYPE ) ) $ GO TO 180 NMATS = NMATS + 1 NTEST = 0 * * Save ISEED in case of an error. * DO 20 J = 1, 4 IOLDSD( J ) = ISEED( J ) 20 CONTINUE * * Initialize RESULT * DO 30 J = 1, 13 RESULT( J ) = ZERO 30 CONTINUE * * Generate test matrices A and B * * Description of control parameters: * * KCLASS: =1 means w/o rotation, =2 means w/ rotation, * =3 means random. * KATYPE: the "type" to be passed to SLATM4 for computing A. * KAZERO: the pattern of zeros on the diagonal for A: * =1: ( xxx ), =2: (0, xxx ) =3: ( 0, 0, xxx, 0 ), * =4: ( 0, xxx, 0, 0 ), =5: ( 0, 0, 1, xxx, 0 ), * =6: ( 0, 1, 0, xxx, 0 ). (xxx means a string of * non-zero entries.) * KAMAGN: the magnitude of the matrix: =0: zero, =1: O(1), * =2: large, =3: small. * IASIGN: 1 if the diagonal elements of A are to be * multiplied by a random magnitude 1 number, =2 if * randomly chosen diagonal blocks are to be rotated * to form 2x2 blocks. * KBTYPE, KBZERO, KBMAGN, IBSIGN: the same, but for B. * KTRIAN: =0: don't fill in the upper triangle, =1: do. * KZ1, KZ2, KADD: used to implement KAZERO and KBZERO. * RMAGN: used to implement KAMAGN and KBMAGN. * IF( MTYPES.GT.MAXTYP ) $ GO TO 110 IINFO = 0 IF( KCLASS( JTYPE ).LT.3 ) THEN * * Generate A (w/o rotation) * IF( ABS( KATYPE( JTYPE ) ).EQ.3 ) THEN IN = 2*( ( N-1 ) / 2 ) + 1 IF( IN.NE.N ) $ CALL SLASET( 'Full', N, N, ZERO, ZERO, A, LDA ) ELSE IN = N END IF CALL SLATM4( KATYPE( JTYPE ), IN, KZ1( KAZERO( JTYPE ) ), $ KZ2( KAZERO( JTYPE ) ), IASIGN( JTYPE ), $ RMAGN( KAMAGN( JTYPE ) ), ULP, $ RMAGN( KTRIAN( JTYPE )*KAMAGN( JTYPE ) ), 2, $ ISEED, A, LDA ) IADD = KADD( KAZERO( JTYPE ) ) IF( IADD.GT.0 .AND. IADD.LE.N ) $ A( IADD, IADD ) = ONE * * Generate B (w/o rotation) * IF( ABS( KBTYPE( JTYPE ) ).EQ.3 ) THEN IN = 2*( ( N-1 ) / 2 ) + 1 IF( IN.NE.N ) $ CALL SLASET( 'Full', N, N, ZERO, ZERO, B, LDA ) ELSE IN = N END IF CALL SLATM4( KBTYPE( JTYPE ), IN, KZ1( KBZERO( JTYPE ) ), $ KZ2( KBZERO( JTYPE ) ), IBSIGN( JTYPE ), $ RMAGN( KBMAGN( JTYPE ) ), ONE, $ RMAGN( KTRIAN( JTYPE )*KBMAGN( JTYPE ) ), 2, $ ISEED, B, LDA ) IADD = KADD( KBZERO( JTYPE ) ) IF( IADD.NE.0 .AND. IADD.LE.N ) $ B( IADD, IADD ) = ONE * IF( KCLASS( JTYPE ).EQ.2 .AND. N.GT.0 ) THEN * * Include rotations * * Generate Q, Z as Householder transformations times * a diagonal matrix. * DO 50 JC = 1, N - 1 DO 40 JR = JC, N Q( JR, JC ) = SLARND( 3, ISEED ) Z( JR, JC ) = SLARND( 3, ISEED ) 40 CONTINUE CALL SLARFG( N+1-JC, Q( JC, JC ), Q( JC+1, JC ), 1, $ WORK( JC ) ) WORK( 2*N+JC ) = SIGN( ONE, Q( JC, JC ) ) Q( JC, JC ) = ONE CALL SLARFG( N+1-JC, Z( JC, JC ), Z( JC+1, JC ), 1, $ WORK( N+JC ) ) WORK( 3*N+JC ) = SIGN( ONE, Z( JC, JC ) ) Z( JC, JC ) = ONE 50 CONTINUE Q( N, N ) = ONE WORK( N ) = ZERO WORK( 3*N ) = SIGN( ONE, SLARND( 2, ISEED ) ) Z( N, N ) = ONE WORK( 2*N ) = ZERO WORK( 4*N ) = SIGN( ONE, SLARND( 2, ISEED ) ) * * Apply the diagonal matrices * DO 70 JC = 1, N DO 60 JR = 1, N A( JR, JC ) = WORK( 2*N+JR )*WORK( 3*N+JC )* $ A( JR, JC ) B( JR, JC ) = WORK( 2*N+JR )*WORK( 3*N+JC )* $ B( JR, JC ) 60 CONTINUE 70 CONTINUE CALL SORM2R( 'L', 'N', N, N, N-1, Q, LDQ, WORK, A, $ LDA, WORK( 2*N+1 ), IINFO ) IF( IINFO.NE.0 ) $ GO TO 100 CALL SORM2R( 'R', 'T', N, N, N-1, Z, LDQ, WORK( N+1 ), $ A, LDA, WORK( 2*N+1 ), IINFO ) IF( IINFO.NE.0 ) $ GO TO 100 CALL SORM2R( 'L', 'N', N, N, N-1, Q, LDQ, WORK, B, $ LDA, WORK( 2*N+1 ), IINFO ) IF( IINFO.NE.0 ) $ GO TO 100 CALL SORM2R( 'R', 'T', N, N, N-1, Z, LDQ, WORK( N+1 ), $ B, LDA, WORK( 2*N+1 ), IINFO ) IF( IINFO.NE.0 ) $ GO TO 100 END IF ELSE * * Random matrices * DO 90 JC = 1, N DO 80 JR = 1, N A( JR, JC ) = RMAGN( KAMAGN( JTYPE ) )* $ SLARND( 2, ISEED ) B( JR, JC ) = RMAGN( KBMAGN( JTYPE ) )* $ SLARND( 2, ISEED ) 80 CONTINUE 90 CONTINUE END IF * 100 CONTINUE * IF( IINFO.NE.0 ) THEN WRITE( NOUNIT, FMT = 9999 )'Generator', IINFO, N, JTYPE, $ IOLDSD INFO = ABS( IINFO ) RETURN END IF * 110 CONTINUE * DO 120 I = 1, 13 RESULT( I ) = -ONE 120 CONTINUE * * Test with and without sorting of eigenvalues * DO 150 ISORT = 0, 1 IF( ISORT.EQ.0 ) THEN SORT = 'N' RSUB = 0 ELSE SORT = 'S' RSUB = 5 END IF * * Call SGGES to compute H, T, Q, Z, alpha, and beta. * CALL SLACPY( 'Full', N, N, A, LDA, S, LDA ) CALL SLACPY( 'Full', N, N, B, LDA, T, LDA ) NTEST = 1 + RSUB + ISORT RESULT( 1+RSUB+ISORT ) = ULPINV CALL SGGES( 'V', 'V', SORT, SLCTES, N, S, LDA, T, LDA, $ SDIM, ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDQ, $ WORK, LWORK, BWORK, IINFO ) IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN RESULT( 1+RSUB+ISORT ) = ULPINV WRITE( NOUNIT, FMT = 9999 )'SGGES', IINFO, N, JTYPE, $ IOLDSD INFO = ABS( IINFO ) GO TO 160 END IF * NTEST = 4 + RSUB * * Do tests 1--4 (or tests 7--9 when reordering ) * IF( ISORT.EQ.0 ) THEN CALL SGET51( 1, N, A, LDA, S, LDA, Q, LDQ, Z, LDQ, $ WORK, RESULT( 1 ) ) CALL SGET51( 1, N, B, LDA, T, LDA, Q, LDQ, Z, LDQ, $ WORK, RESULT( 2 ) ) ELSE CALL SGET54( N, A, LDA, B, LDA, S, LDA, T, LDA, Q, $ LDQ, Z, LDQ, WORK, RESULT( 7 ) ) END IF CALL SGET51( 3, N, A, LDA, T, LDA, Q, LDQ, Q, LDQ, WORK, $ RESULT( 3+RSUB ) ) CALL SGET51( 3, N, B, LDA, T, LDA, Z, LDQ, Z, LDQ, WORK, $ RESULT( 4+RSUB ) ) * * Do test 5 and 6 (or Tests 10 and 11 when reordering): * check Schur form of A and compare eigenvalues with * diagonals. * NTEST = 6 + RSUB TEMP1 = ZERO * DO 130 J = 1, N ILABAD = .FALSE. IF( ALPHAI( J ).EQ.ZERO ) THEN TEMP2 = ( ABS( ALPHAR( J )-S( J, J ) ) / $ MAX( SAFMIN, ABS( ALPHAR( J ) ), ABS( S( J, $ J ) ) )+ABS( BETA( J )-T( J, J ) ) / $ MAX( SAFMIN, ABS( BETA( J ) ), ABS( T( J, $ J ) ) ) ) / ULP * IF( J.LT.N ) THEN IF( S( J+1, J ).NE.ZERO ) THEN ILABAD = .TRUE. RESULT( 5+RSUB ) = ULPINV END IF END IF IF( J.GT.1 ) THEN IF( S( J, J-1 ).NE.ZERO ) THEN ILABAD = .TRUE. RESULT( 5+RSUB ) = ULPINV END IF END IF * ELSE IF( ALPHAI( J ).GT.ZERO ) THEN I1 = J ELSE I1 = J - 1 END IF IF( I1.LE.0 .OR. I1.GE.N ) THEN ILABAD = .TRUE. ELSE IF( I1.LT.N-1 ) THEN IF( S( I1+2, I1+1 ).NE.ZERO ) THEN ILABAD = .TRUE. RESULT( 5+RSUB ) = ULPINV END IF ELSE IF( I1.GT.1 ) THEN IF( S( I1, I1-1 ).NE.ZERO ) THEN ILABAD = .TRUE. RESULT( 5+RSUB ) = ULPINV END IF END IF IF( .NOT.ILABAD ) THEN CALL SGET53( S( I1, I1 ), LDA, T( I1, I1 ), LDA, $ BETA( J ), ALPHAR( J ), $ ALPHAI( J ), TEMP2, IERR ) IF( IERR.GE.3 ) THEN WRITE( NOUNIT, FMT = 9998 )IERR, J, N, $ JTYPE, IOLDSD INFO = ABS( IERR ) END IF ELSE TEMP2 = ULPINV END IF * END IF TEMP1 = MAX( TEMP1, TEMP2 ) IF( ILABAD ) THEN WRITE( NOUNIT, FMT = 9997 )J, N, JTYPE, IOLDSD END IF 130 CONTINUE RESULT( 6+RSUB ) = TEMP1 * IF( ISORT.GE.1 ) THEN * * Do test 12 * NTEST = 12 RESULT( 12 ) = ZERO KNTEIG = 0 DO 140 I = 1, N IF( SLCTES( ALPHAR( I ), ALPHAI( I ), $ BETA( I ) ) .OR. SLCTES( ALPHAR( I ), $ -ALPHAI( I ), BETA( I ) ) ) THEN KNTEIG = KNTEIG + 1 END IF IF( I.LT.N ) THEN IF( ( SLCTES( ALPHAR( I+1 ), ALPHAI( I+1 ), $ BETA( I+1 ) ) .OR. SLCTES( ALPHAR( I+1 ), $ -ALPHAI( I+1 ), BETA( I+1 ) ) ) .AND. $ ( .NOT.( SLCTES( ALPHAR( I ), ALPHAI( I ), $ BETA( I ) ) .OR. SLCTES( ALPHAR( I ), $ -ALPHAI( I ), BETA( I ) ) ) ) .AND. $ IINFO.NE.N+2 ) THEN RESULT( 12 ) = ULPINV END IF END IF 140 CONTINUE IF( SDIM.NE.KNTEIG ) THEN RESULT( 12 ) = ULPINV END IF END IF * 150 CONTINUE * * End of Loop -- Check for RESULT(j) > THRESH * 160 CONTINUE * NTESTT = NTESTT + NTEST * * Print out tests which fail. * DO 170 JR = 1, NTEST IF( RESULT( JR ).GE.THRESH ) THEN * * If this is the first test to fail, * print a header to the data file. * IF( NERRS.EQ.0 ) THEN WRITE( NOUNIT, FMT = 9996 )'SGS' * * Matrix types * WRITE( NOUNIT, FMT = 9995 ) WRITE( NOUNIT, FMT = 9994 ) WRITE( NOUNIT, FMT = 9993 )'Orthogonal' * * Tests performed * WRITE( NOUNIT, FMT = 9992 )'orthogonal', '''', $ 'transpose', ( '''', J = 1, 8 ) * END IF NERRS = NERRS + 1 IF( RESULT( JR ).LT.10000.0 ) THEN WRITE( NOUNIT, FMT = 9991 )N, JTYPE, IOLDSD, JR, $ RESULT( JR ) ELSE WRITE( NOUNIT, FMT = 9990 )N, JTYPE, IOLDSD, JR, $ RESULT( JR ) END IF END IF 170 CONTINUE * 180 CONTINUE 190 CONTINUE * * Summary * CALL ALASVM( 'SGS', NOUNIT, NERRS, NTESTT, 0 ) * WORK( 1 ) = MAXWRK * RETURN * 9999 FORMAT( ' SDRGES: ', A, ' returned INFO=', I6, '.', / 9X, 'N=', $ I6, ', JTYPE=', I6, ', ISEED=(', 4( I4, ',' ), I5, ')' ) * 9998 FORMAT( ' SDRGES: SGET53 returned INFO=', I1, ' for eigenvalue ', $ I6, '.', / 9X, 'N=', I6, ', JTYPE=', I6, ', ISEED=(', $ 4( I4, ',' ), I5, ')' ) * 9997 FORMAT( ' SDRGES: S not in Schur form at eigenvalue ', I6, '.', $ / 9X, 'N=', I6, ', JTYPE=', I6, ', ISEED=(', 3( I5, ',' ), $ I5, ')' ) * 9996 FORMAT( / 1X, A3, ' -- Real Generalized Schur form driver' ) * 9995 FORMAT( ' Matrix types (see SDRGES for details): ' ) * 9994 FORMAT( ' Special Matrices:', 23X, $ '(J''=transposed Jordan block)', $ / ' 1=(0,0) 2=(I,0) 3=(0,I) 4=(I,I) 5=(J'',J'') ', $ '6=(diag(J'',I), diag(I,J''))', / ' Diagonal Matrices: ( ', $ 'D=diag(0,1,2,...) )', / ' 7=(D,I) 9=(large*D, small*I', $ ') 11=(large*I, small*D) 13=(large*D, large*I)', / $ ' 8=(I,D) 10=(small*D, large*I) 12=(small*I, large*D) ', $ ' 14=(small*D, small*I)', / ' 15=(D, reversed D)' ) 9993 FORMAT( ' Matrices Rotated by Random ', A, ' Matrices U, V:', $ / ' 16=Transposed Jordan Blocks 19=geometric ', $ 'alpha, beta=0,1', / ' 17=arithm. alpha&beta ', $ ' 20=arithmetic alpha, beta=0,1', / ' 18=clustered ', $ 'alpha, beta=0,1 21=random alpha, beta=0,1', $ / ' Large & Small Matrices:', / ' 22=(large, small) ', $ '23=(small,large) 24=(small,small) 25=(large,large)', $ / ' 26=random O(1) matrices.' ) * 9992 FORMAT( / ' Tests performed: (S is Schur, T is triangular, ', $ 'Q and Z are ', A, ',', / 19X, $ 'l and r are the appropriate left and right', / 19X, $ 'eigenvectors, resp., a is alpha, b is beta, and', / 19X, A, $ ' means ', A, '.)', / ' Without ordering: ', $ / ' 1 = | A - Q S Z', A, $ ' | / ( |A| n ulp ) 2 = | B - Q T Z', A, $ ' | / ( |B| n ulp )', / ' 3 = | I - QQ', A, $ ' | / ( n ulp ) 4 = | I - ZZ', A, $ ' | / ( n ulp )', / ' 5 = A is in Schur form S', $ / ' 6 = difference between (alpha,beta)', $ ' and diagonals of (S,T)', / ' With ordering: ', $ / ' 7 = | (A,B) - Q (S,T) Z', A, $ ' | / ( |(A,B)| n ulp ) ', / ' 8 = | I - QQ', A, $ ' | / ( n ulp ) 9 = | I - ZZ', A, $ ' | / ( n ulp )', / ' 10 = A is in Schur form S', $ / ' 11 = difference between (alpha,beta) and diagonals', $ ' of (S,T)', / ' 12 = SDIM is the correct number of ', $ 'selected eigenvalues', / ) 9991 FORMAT( ' Matrix order=', I5, ', type=', I2, ', seed=', $ 4( I4, ',' ), ' result ', I2, ' is', 0P, F8.2 ) 9990 FORMAT( ' Matrix order=', I5, ', type=', I2, ', seed=', $ 4( I4, ',' ), ' result ', I2, ' is', 1P, E10.3 ) * * End of SDRGES * END
gpl-2.0
omni-compiler/omni-compiler
tests/XMP/local-view/coarray/F/GET/a2d2.f90
2
1284
program putgettest !! include "xmp_coarray.h" integer*2 a2d2(10,8)[*] integer xmp_node_num integer nerr me = this_image() !---------------------------- switch on message !! call xmpf_coarray_msg(1) !---------------------------- initialization a2d2=0 sync all !---------------------------- exec if (me==1) then a2d2(1:3,1:8)[2] = reshape((/ & 11_2,21_2,31_2,12_2,22_2,32_2,13_2,23_2,33_2,& 14_2,24_2,34_2,15_2,25_2,35_2,16_2,26_2,36_2,& 17_2,27_2,37_2,18_2,28_2,38_2/), (/3,8/)) end if sync all !---------------------------- check and output start nerr = 0 do i2=1,8 do i1=1,10 if (me==2.and.(i1==1.or.i1==2.or.i1==3)) then ival=(i1*10+i2) else ival=0 end if if (a2d2(i1,i2).ne.ival) then write(*,101) i1,i2,me,a2d2(i1,i2),ival nerr=nerr+1 end if end do end do if (nerr==0) then print '("[",i0,"] OK")', me else print '("[",i0,"] number of NGs: ",i0)', me, nerr stop 1 end if !---------------------------- check and output end 101 format ("a2d2(",i0,",",i0,")[",i0,"]=",i0," should be ",i0) end program
lgpl-3.0
linzhaoming/origin
vendor/gonum.org/v1/gonum/lapack/internal/testdata/netlib/lsame.f
204
3170
*> \brief \b LSAME * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * LOGICAL FUNCTION LSAME( CA, CB ) * * .. Scalar Arguments .. * CHARACTER CA, CB * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> LSAME returns .TRUE. if CA is the same letter as CB regardless of *> case. *> \endverbatim * * Arguments: * ========== * *> \param[in] CA *> \verbatim *> \endverbatim *> *> \param[in] CB *> \verbatim *> CA and CB specify the single characters to be compared. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup auxOTHERauxiliary * * ===================================================================== LOGICAL FUNCTION LSAME( CA, CB ) * * -- LAPACK auxiliary routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER CA, CB * .. * * ===================================================================== * * .. Intrinsic Functions .. INTRINSIC ICHAR * .. * .. Local Scalars .. INTEGER INTA, INTB, ZCODE * .. * .. Executable Statements .. * * Test if the characters are equal * LSAME = CA.EQ.CB IF( LSAME ) $ RETURN * * Now test for equivalence if both characters are alphabetic. * ZCODE = ICHAR( 'Z' ) * * Use 'Z' rather than 'A' so that ASCII can be detected on Prime * machines, on which ICHAR returns a value with bit 8 set. * ICHAR('A') on Prime machines returns 193 which is the same as * ICHAR('A') on an EBCDIC machine. * INTA = ICHAR( CA ) INTB = ICHAR( CB ) * IF( ZCODE.EQ.90 .OR. ZCODE.EQ.122 ) THEN * * ASCII is assumed - ZCODE is the ASCII code of either lower or * upper case 'Z'. * IF( INTA.GE.97 .AND. INTA.LE.122 ) INTA = INTA - 32 IF( INTB.GE.97 .AND. INTB.LE.122 ) INTB = INTB - 32 * ELSE IF( ZCODE.EQ.233 .OR. ZCODE.EQ.169 ) THEN * * EBCDIC is assumed - ZCODE is the EBCDIC code of either lower or * upper case 'Z'. * IF( INTA.GE.129 .AND. INTA.LE.137 .OR. $ INTA.GE.145 .AND. INTA.LE.153 .OR. $ INTA.GE.162 .AND. INTA.LE.169 ) INTA = INTA + 64 IF( INTB.GE.129 .AND. INTB.LE.137 .OR. $ INTB.GE.145 .AND. INTB.LE.153 .OR. $ INTB.GE.162 .AND. INTB.LE.169 ) INTB = INTB + 64 * ELSE IF( ZCODE.EQ.218 .OR. ZCODE.EQ.250 ) THEN * * ASCII is assumed, on Prime machines - ZCODE is the ASCII code * plus 128 of either lower or upper case 'Z'. * IF( INTA.GE.225 .AND. INTA.LE.250 ) INTA = INTA - 32 IF( INTB.GE.225 .AND. INTB.LE.250 ) INTB = INTB - 32 END IF LSAME = INTA.EQ.INTB * * RETURN * * End of LSAME * END
apache-2.0
omni-compiler/omni-compiler
tests/old/F-test/OMP-test/do001.f
2
2220
C ******************************************************************** C OpenMP Fortran API Test Suite C ----------------------------- C C Test Name : do001 C C Summary : do construct with nowait clause C C Description : F77 version of example A.4 from specification. C C Verification : Execution self-checks verify results but not work C sharing. C C Origin : Example A.4 from OpenMP Fortran API specification C C Keywords : F77, do, nowait C C Source Form : Fixed C C Last Changed : $Date: 2004/02/06 18:15:44 $ C C ******************************************************************** SUBROUTINE D001S(M,N,A,B,Y,Z) INTEGER M,N,I INTEGER A(N), B(N), Y(M), Z(M), SQRT EXTERNAL SQRT C$OMP PARALLEL C$OMP DO DO 100 I=2,N B(I) = (A(I) + A(I-1)) / 2 100 CONTINUE C$OMP END DO NOWAIT C$OMP DO DO 200 I=1,M Y(I) = SQRT(Z(I)) 200 CONTINUE C$OMP END DO NOWAIT C$OMP END PARALLEL END INTEGER FUNCTION SQRT(K) J = 1 DO 250 I=1,K IF ( (J*J) .NE. K ) THEN J = (J + (K/J))/2 ELSE GOTO 260 ENDIF 250 CONTINUE 260 SQRT = J END PROGRAM D001 INTEGER M, N, I, ERRORS PARAMETER(M = 117) PARAMETER(N = 511) INTEGER A(N), B(N), Y(M), Z(M) DO 300 I=1,N A(I) = 2*I + 1 B(I) = 0 300 CONTINUE DO 400 I=1,M Z(I) = I*I Y(I) = 0 400 CONTINUE CALL D001S(M, N, A, B, Y, Z) ERRORS = 0 DO 500 I=2,N IF (B(I) .NE. 2*I) THEN ERRORS = ERRORS + 1 IF (ERRORS .EQ. 1) THEN write(6,*)'do001 - VALUES IN B ARE NOT AS EXPECTED' ENDIF write(6,*)'EXPECTED B(', I, ') = ', 2*I, ' OBSERVED ', B(I) ENDIF 500 CONTINUE DO 600 I=1,M IF (Y(I) .NE. I) THEN ERRORS = ERRORS + 1 IF (ERRORS .EQ. 1) THEN write(6,*)'do001 - VALUES IN Y ARE NOT AS EXPECTED' ENDIF write(6,*) 'EXPECTED Y(', I, ') = ', I, ' OBSERVED ', Y(I) ENDIF 600 CONTINUE IF (ERRORS .EQ. 0) THEN WRITE (*,'(A)') 'do001 PASSED' ELSE WRITE (*,'(A)') 'do001 FAILED' ENDIF END
lgpl-3.0
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/LIN/sdrvgt.f
32
19178
*> \brief \b SDRVGT * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE SDRVGT( DOTYPE, NN, NVAL, NRHS, THRESH, TSTERR, A, AF, * B, X, XACT, WORK, RWORK, IWORK, NOUT ) * * .. Scalar Arguments .. * LOGICAL TSTERR * INTEGER NN, NOUT, NRHS * REAL THRESH * .. * .. Array Arguments .. * LOGICAL DOTYPE( * ) * INTEGER IWORK( * ), NVAL( * ) * REAL A( * ), AF( * ), B( * ), RWORK( * ), WORK( * ), * $ X( * ), XACT( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SDRVGT tests SGTSV and -SVX. *> \endverbatim * * Arguments: * ========== * *> \param[in] DOTYPE *> \verbatim *> DOTYPE is LOGICAL array, dimension (NTYPES) *> The matrix types to be used for testing. Matrices of type j *> (for 1 <= j <= NTYPES) are used for testing if DOTYPE(j) = *> .TRUE.; if DOTYPE(j) = .FALSE., then type j is not used. *> \endverbatim *> *> \param[in] NN *> \verbatim *> NN is INTEGER *> The number of values of N contained in the vector NVAL. *> \endverbatim *> *> \param[in] NVAL *> \verbatim *> NVAL is INTEGER array, dimension (NN) *> The values of the matrix dimension N. *> \endverbatim *> *> \param[in] NRHS *> \verbatim *> NRHS is INTEGER *> The number of right hand sides, NRHS >= 0. *> \endverbatim *> *> \param[in] THRESH *> \verbatim *> THRESH is REAL *> The threshold value for the test ratios. A result is *> included in the output file if RESULT >= THRESH. To have *> every test ratio printed, use THRESH = 0. *> \endverbatim *> *> \param[in] TSTERR *> \verbatim *> TSTERR is LOGICAL *> Flag that indicates whether error exits are to be tested. *> \endverbatim *> *> \param[out] A *> \verbatim *> A is REAL array, dimension (NMAX*4) *> \endverbatim *> *> \param[out] AF *> \verbatim *> AF is REAL array, dimension (NMAX*4) *> \endverbatim *> *> \param[out] B *> \verbatim *> B is REAL array, dimension (NMAX*NRHS) *> \endverbatim *> *> \param[out] X *> \verbatim *> X is REAL array, dimension (NMAX*NRHS) *> \endverbatim *> *> \param[out] XACT *> \verbatim *> XACT is REAL array, dimension (NMAX*NRHS) *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is REAL array, dimension *> (NMAX*max(3,NRHS)) *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is REAL array, dimension *> (max(NMAX,2*NRHS)) *> \endverbatim *> *> \param[out] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (2*NMAX) *> \endverbatim *> *> \param[in] NOUT *> \verbatim *> NOUT is INTEGER *> The unit number for output. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup single_lin * * ===================================================================== SUBROUTINE SDRVGT( DOTYPE, NN, NVAL, NRHS, THRESH, TSTERR, A, AF, $ B, X, XACT, WORK, RWORK, IWORK, NOUT ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. LOGICAL TSTERR INTEGER NN, NOUT, NRHS REAL THRESH * .. * .. Array Arguments .. LOGICAL DOTYPE( * ) INTEGER IWORK( * ), NVAL( * ) REAL A( * ), AF( * ), B( * ), RWORK( * ), WORK( * ), $ X( * ), XACT( * ) * .. * * ===================================================================== * * .. Parameters .. REAL ONE, ZERO PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 ) INTEGER NTYPES PARAMETER ( NTYPES = 12 ) INTEGER NTESTS PARAMETER ( NTESTS = 6 ) * .. * .. Local Scalars .. LOGICAL TRFCON, ZEROT CHARACTER DIST, FACT, TRANS, TYPE CHARACTER*3 PATH INTEGER I, IFACT, IMAT, IN, INFO, ITRAN, IX, IZERO, J, $ K, K1, KL, KOFF, KU, LDA, M, MODE, N, NERRS, $ NFAIL, NIMAT, NRUN, NT REAL AINVNM, ANORM, ANORMI, ANORMO, COND, RCOND, $ RCONDC, RCONDI, RCONDO * .. * .. Local Arrays .. CHARACTER TRANSS( 3 ) INTEGER ISEED( 4 ), ISEEDY( 4 ) REAL RESULT( NTESTS ), Z( 3 ) * .. * .. External Functions .. REAL SASUM, SGET06, SLANGT EXTERNAL SASUM, SGET06, SLANGT * .. * .. External Subroutines .. EXTERNAL ALADHD, ALAERH, ALASVM, SCOPY, SERRVX, SGET04, $ SGTSV, SGTSVX, SGTT01, SGTT02, SGTT05, SGTTRF, $ SGTTRS, SLACPY, SLAGTM, SLARNV, SLASET, SLATB4, $ SLATMS, SSCAL * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Scalars in Common .. LOGICAL LERR, OK CHARACTER*32 SRNAMT INTEGER INFOT, NUNIT * .. * .. Common blocks .. COMMON / INFOC / INFOT, NUNIT, OK, LERR COMMON / SRNAMC / SRNAMT * .. * .. Data statements .. DATA ISEEDY / 0, 0, 0, 1 / , TRANSS / 'N', 'T', $ 'C' / * .. * .. Executable Statements .. * PATH( 1: 1 ) = 'Single precision' PATH( 2: 3 ) = 'GT' NRUN = 0 NFAIL = 0 NERRS = 0 DO 10 I = 1, 4 ISEED( I ) = ISEEDY( I ) 10 CONTINUE * * Test the error exits * IF( TSTERR ) $ CALL SERRVX( PATH, NOUT ) INFOT = 0 * DO 140 IN = 1, NN * * Do for each value of N in NVAL. * N = NVAL( IN ) M = MAX( N-1, 0 ) LDA = MAX( 1, N ) NIMAT = NTYPES IF( N.LE.0 ) $ NIMAT = 1 * DO 130 IMAT = 1, NIMAT * * Do the tests only if DOTYPE( IMAT ) is true. * IF( .NOT.DOTYPE( IMAT ) ) $ GO TO 130 * * Set up parameters with SLATB4. * CALL SLATB4( PATH, IMAT, N, N, TYPE, KL, KU, ANORM, MODE, $ COND, DIST ) * ZEROT = IMAT.GE.8 .AND. IMAT.LE.10 IF( IMAT.LE.6 ) THEN * * Types 1-6: generate matrices of known condition number. * KOFF = MAX( 2-KU, 3-MAX( 1, N ) ) SRNAMT = 'SLATMS' CALL SLATMS( N, N, DIST, ISEED, TYPE, RWORK, MODE, COND, $ ANORM, KL, KU, 'Z', AF( KOFF ), 3, WORK, $ INFO ) * * Check the error code from SLATMS. * IF( INFO.NE.0 ) THEN CALL ALAERH( PATH, 'SLATMS', INFO, 0, ' ', N, N, KL, $ KU, -1, IMAT, NFAIL, NERRS, NOUT ) GO TO 130 END IF IZERO = 0 * IF( N.GT.1 ) THEN CALL SCOPY( N-1, AF( 4 ), 3, A, 1 ) CALL SCOPY( N-1, AF( 3 ), 3, A( N+M+1 ), 1 ) END IF CALL SCOPY( N, AF( 2 ), 3, A( M+1 ), 1 ) ELSE * * Types 7-12: generate tridiagonal matrices with * unknown condition numbers. * IF( .NOT.ZEROT .OR. .NOT.DOTYPE( 7 ) ) THEN * * Generate a matrix with elements from [-1,1]. * CALL SLARNV( 2, ISEED, N+2*M, A ) IF( ANORM.NE.ONE ) $ CALL SSCAL( N+2*M, ANORM, A, 1 ) ELSE IF( IZERO.GT.0 ) THEN * * Reuse the last matrix by copying back the zeroed out * elements. * IF( IZERO.EQ.1 ) THEN A( N ) = Z( 2 ) IF( N.GT.1 ) $ A( 1 ) = Z( 3 ) ELSE IF( IZERO.EQ.N ) THEN A( 3*N-2 ) = Z( 1 ) A( 2*N-1 ) = Z( 2 ) ELSE A( 2*N-2+IZERO ) = Z( 1 ) A( N-1+IZERO ) = Z( 2 ) A( IZERO ) = Z( 3 ) END IF END IF * * If IMAT > 7, set one column of the matrix to 0. * IF( .NOT.ZEROT ) THEN IZERO = 0 ELSE IF( IMAT.EQ.8 ) THEN IZERO = 1 Z( 2 ) = A( N ) A( N ) = ZERO IF( N.GT.1 ) THEN Z( 3 ) = A( 1 ) A( 1 ) = ZERO END IF ELSE IF( IMAT.EQ.9 ) THEN IZERO = N Z( 1 ) = A( 3*N-2 ) Z( 2 ) = A( 2*N-1 ) A( 3*N-2 ) = ZERO A( 2*N-1 ) = ZERO ELSE IZERO = ( N+1 ) / 2 DO 20 I = IZERO, N - 1 A( 2*N-2+I ) = ZERO A( N-1+I ) = ZERO A( I ) = ZERO 20 CONTINUE A( 3*N-2 ) = ZERO A( 2*N-1 ) = ZERO END IF END IF * DO 120 IFACT = 1, 2 IF( IFACT.EQ.1 ) THEN FACT = 'F' ELSE FACT = 'N' END IF * * Compute the condition number for comparison with * the value returned by SGTSVX. * IF( ZEROT ) THEN IF( IFACT.EQ.1 ) $ GO TO 120 RCONDO = ZERO RCONDI = ZERO * ELSE IF( IFACT.EQ.1 ) THEN CALL SCOPY( N+2*M, A, 1, AF, 1 ) * * Compute the 1-norm and infinity-norm of A. * ANORMO = SLANGT( '1', N, A, A( M+1 ), A( N+M+1 ) ) ANORMI = SLANGT( 'I', N, A, A( M+1 ), A( N+M+1 ) ) * * Factor the matrix A. * CALL SGTTRF( N, AF, AF( M+1 ), AF( N+M+1 ), $ AF( N+2*M+1 ), IWORK, INFO ) * * Use SGTTRS to solve for one column at a time of * inv(A), computing the maximum column sum as we go. * AINVNM = ZERO DO 40 I = 1, N DO 30 J = 1, N X( J ) = ZERO 30 CONTINUE X( I ) = ONE CALL SGTTRS( 'No transpose', N, 1, AF, AF( M+1 ), $ AF( N+M+1 ), AF( N+2*M+1 ), IWORK, X, $ LDA, INFO ) AINVNM = MAX( AINVNM, SASUM( N, X, 1 ) ) 40 CONTINUE * * Compute the 1-norm condition number of A. * IF( ANORMO.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN RCONDO = ONE ELSE RCONDO = ( ONE / ANORMO ) / AINVNM END IF * * Use SGTTRS to solve for one column at a time of * inv(A'), computing the maximum column sum as we go. * AINVNM = ZERO DO 60 I = 1, N DO 50 J = 1, N X( J ) = ZERO 50 CONTINUE X( I ) = ONE CALL SGTTRS( 'Transpose', N, 1, AF, AF( M+1 ), $ AF( N+M+1 ), AF( N+2*M+1 ), IWORK, X, $ LDA, INFO ) AINVNM = MAX( AINVNM, SASUM( N, X, 1 ) ) 60 CONTINUE * * Compute the infinity-norm condition number of A. * IF( ANORMI.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN RCONDI = ONE ELSE RCONDI = ( ONE / ANORMI ) / AINVNM END IF END IF * DO 110 ITRAN = 1, 3 TRANS = TRANSS( ITRAN ) IF( ITRAN.EQ.1 ) THEN RCONDC = RCONDO ELSE RCONDC = RCONDI END IF * * Generate NRHS random solution vectors. * IX = 1 DO 70 J = 1, NRHS CALL SLARNV( 2, ISEED, N, XACT( IX ) ) IX = IX + LDA 70 CONTINUE * * Set the right hand side. * CALL SLAGTM( TRANS, N, NRHS, ONE, A, A( M+1 ), $ A( N+M+1 ), XACT, LDA, ZERO, B, LDA ) * IF( IFACT.EQ.2 .AND. ITRAN.EQ.1 ) THEN * * --- Test SGTSV --- * * Solve the system using Gaussian elimination with * partial pivoting. * CALL SCOPY( N+2*M, A, 1, AF, 1 ) CALL SLACPY( 'Full', N, NRHS, B, LDA, X, LDA ) * SRNAMT = 'SGTSV ' CALL SGTSV( N, NRHS, AF, AF( M+1 ), AF( N+M+1 ), X, $ LDA, INFO ) * * Check error code from SGTSV . * IF( INFO.NE.IZERO ) $ CALL ALAERH( PATH, 'SGTSV ', INFO, IZERO, ' ', $ N, N, 1, 1, NRHS, IMAT, NFAIL, $ NERRS, NOUT ) NT = 1 IF( IZERO.EQ.0 ) THEN * * Check residual of computed solution. * CALL SLACPY( 'Full', N, NRHS, B, LDA, WORK, $ LDA ) CALL SGTT02( TRANS, N, NRHS, A, A( M+1 ), $ A( N+M+1 ), X, LDA, WORK, LDA, $ RESULT( 2 ) ) * * Check solution from generated exact solution. * CALL SGET04( N, NRHS, X, LDA, XACT, LDA, RCONDC, $ RESULT( 3 ) ) NT = 3 END IF * * Print information about the tests that did not pass * the threshold. * DO 80 K = 2, NT IF( RESULT( K ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) WRITE( NOUT, FMT = 9999 )'SGTSV ', N, IMAT, $ K, RESULT( K ) NFAIL = NFAIL + 1 END IF 80 CONTINUE NRUN = NRUN + NT - 1 END IF * * --- Test SGTSVX --- * IF( IFACT.GT.1 ) THEN * * Initialize AF to zero. * DO 90 I = 1, 3*N - 2 AF( I ) = ZERO 90 CONTINUE END IF CALL SLASET( 'Full', N, NRHS, ZERO, ZERO, X, LDA ) * * Solve the system and compute the condition number and * error bounds using SGTSVX. * SRNAMT = 'SGTSVX' CALL SGTSVX( FACT, TRANS, N, NRHS, A, A( M+1 ), $ A( N+M+1 ), AF, AF( M+1 ), AF( N+M+1 ), $ AF( N+2*M+1 ), IWORK, B, LDA, X, LDA, $ RCOND, RWORK, RWORK( NRHS+1 ), WORK, $ IWORK( N+1 ), INFO ) * * Check the error code from SGTSVX. * IF( INFO.NE.IZERO ) $ CALL ALAERH( PATH, 'SGTSVX', INFO, IZERO, $ FACT // TRANS, N, N, 1, 1, NRHS, IMAT, $ NFAIL, NERRS, NOUT ) * IF( IFACT.GE.2 ) THEN * * Reconstruct matrix from factors and compute * residual. * CALL SGTT01( N, A, A( M+1 ), A( N+M+1 ), AF, $ AF( M+1 ), AF( N+M+1 ), AF( N+2*M+1 ), $ IWORK, WORK, LDA, RWORK, RESULT( 1 ) ) K1 = 1 ELSE K1 = 2 END IF * IF( INFO.EQ.0 ) THEN TRFCON = .FALSE. * * Check residual of computed solution. * CALL SLACPY( 'Full', N, NRHS, B, LDA, WORK, LDA ) CALL SGTT02( TRANS, N, NRHS, A, A( M+1 ), $ A( N+M+1 ), X, LDA, WORK, LDA, $ RESULT( 2 ) ) * * Check solution from generated exact solution. * CALL SGET04( N, NRHS, X, LDA, XACT, LDA, RCONDC, $ RESULT( 3 ) ) * * Check the error bounds from iterative refinement. * CALL SGTT05( TRANS, N, NRHS, A, A( M+1 ), $ A( N+M+1 ), B, LDA, X, LDA, XACT, LDA, $ RWORK, RWORK( NRHS+1 ), RESULT( 4 ) ) NT = 5 END IF * * Print information about the tests that did not pass * the threshold. * DO 100 K = K1, NT IF( RESULT( K ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) WRITE( NOUT, FMT = 9998 )'SGTSVX', FACT, TRANS, $ N, IMAT, K, RESULT( K ) NFAIL = NFAIL + 1 END IF 100 CONTINUE * * Check the reciprocal of the condition number. * RESULT( 6 ) = SGET06( RCOND, RCONDC ) IF( RESULT( 6 ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) WRITE( NOUT, FMT = 9998 )'SGTSVX', FACT, TRANS, N, $ IMAT, K, RESULT( K ) NFAIL = NFAIL + 1 END IF NRUN = NRUN + NT - K1 + 2 * 110 CONTINUE 120 CONTINUE 130 CONTINUE 140 CONTINUE * * Print a summary of the results. * CALL ALASVM( PATH, NOUT, NFAIL, NRUN, NERRS ) * 9999 FORMAT( 1X, A, ', N =', I5, ', type ', I2, ', test ', I2, $ ', ratio = ', G12.5 ) 9998 FORMAT( 1X, A, ', FACT=''', A1, ''', TRANS=''', A1, ''', N =', $ I5, ', type ', I2, ', test ', I2, ', ratio = ', G12.5 ) RETURN * * End of SDRVGT * END
gpl-2.0
markusappel/McCode
support/MacOSX/pgplot/pgplot-src-mac/sys_mac/grgenv.f
6
4059
C*GRGENV -- get value of PGPLOT environment parameter (MAC) C+ SUBROUTINE GRGENV(NAME, VALUE, L) CHARACTER*(*) NAME, VALUE INTEGER L C C Return the value of a PGPLOT environment parameter. In Sun/Convex-UNIX, C environment parameters are UNIX environment variables; e.g. parameter C ENVOPT is environment variable PGPLOT_ENVOPT. Translation is not C recursive and is case-sensitive. C C Arguments: C NAME : (input) the name of the parameter to evaluate. C VALUE : receives the value of the parameter, truncated or extended C with blanks as necessary. If the parameter is undefined, C a blank string is returned. C L : receives the number of characters in VALUE, excluding C trailing blanks. If the parameter is undefined, zero is C returned. C C On Macintosh, the environment variables are stored in file. This subroutine C first looks for the file PGPLOTENVNAMES, in the application directory. C If it can't be found, a standard file dialog box will be displayed, C so that you can find the file. Once it is found, the name and location are C stored so that you will not be prompted again. C-- C 19-Jan-1988 C 25-Sep-1995 Modified to work on mac with MPW Fortran 2.1. All environment C parameters are stored in the file. The file can have any name C but best thing to do is to put a file called pgplotenvnames C in the application directory. See Tech. Note 35 for more information C about Macintosh file system. Note: this subroutine C needs to be compiled with the -u switch to initialize volrefnum C to zero, since a value less than zero specifies a folder. C----------------------------------------------------------------------- INTEGER LIN, LUN,LStart,VolRefNum, JVRefNum CHARACTER*32 TEST, Line*120, FilNam*120 External JVRefNum Save FileName,VolRefNum C TEST = 'PGPLOT_'//NAME LIN = INDEX(TEST, ' ')-1 Value = ' ' L = 0 Call GrgLun(LUN) C If volume reference number has been set, switch to that volume. The C first time grgenv is called, volrefnum will not be set and the current C directory is the application directory. The volume reference number will C be set after pgplotenvnames is found. If (VolRefNum .lt. 0) Then Call F_SETVOLUME(VolRefNum) End If C Try to open FilNam. The first time that Grgenv is called Filnam will C be empty and the open will fail. So try to open pgplotenvnames in the C current directory. If that fails put up a standard file dialog box to C find pgplotenvnames. If FilNam has been set then after assigning a C unit number to the file reset the volume reference number to the application C directory. Open(Unit = lun,File=FilNam,Status='OLD',Err = 10,Readonly) Call F_SETVOLUME(JVREFNUM(-1)) Go to 1 10 Open(Unit = lun,File='pgplotenvnames',Status='OLD',Err = 20,Readonly) FilNam = 'pgplotenvnames' VolRefNum = JVREFNUM(Lun) Go to 1 C Put up standard file dialog box. Once found store the file name and volume C reference number. 20 CALL GRWARN('Could not find file PGPLOTENVNAMES in current directory.') CALL GRWARN('A dialog box will come up allowing you to find the file with the') CALL GRWARN('environment variables. Hit return for the dialog box to appear.') Pause Open(Unit=lun,File=*,STATUS='OLD',err=100,Readonly) Inquire(Unit=LUN,Name=FilNam) VolRefNum = JVREFNUM(Lun) C File has been found, so search for environmental variable and extract value. 1 Continue Read(Lun,'(A512)',End=2) Line If (Test(:Lin) .EQ. Line(:Lin)) Then Lstart = index(Line,"'")+1 L = index(Line(Lstart:),"'")-1 Value = Line(LStart:LStart+L-1) Close(Lun) Go to 2 End If Go to 1 2 Close(LUN) Return C Could not find PGPLOTENVNAMES. 100 Close(LUN) CALL GRWARN('Cancelled dialog box to find PGPLOTENVNAMES') Return END
gpl-2.0
piyush0609/scipy
scipy/optimize/cobyla/trstlp.f
128
17275
C------------------------------------------------------------------------------ SUBROUTINE TRSTLP (N,M,A,B,RHO,DX,IFULL,IACT,Z,ZDOTA,VMULTC, 1 SDIRN,DXNEW,VMULTD,IPRINT) IMPLICIT DOUBLE PRECISION (A-H,O-Z) DOUBLE PRECISION TEMP DIMENSION A(N,*),B(*),DX(*),IACT(*),Z(N,*),ZDOTA(*), 1 VMULTC(*),SDIRN(*),DXNEW(*),VMULTD(*) C C This subroutine calculates an N-component vector DX by applying the C following two stages. In the first stage, DX is set to the shortest C vector that minimizes the greatest violation of the constraints C A(1,K)*DX(1)+A(2,K)*DX(2)+...+A(N,K)*DX(N) .GE. B(K), K=2,3,...,M, C subject to the Euclidean length of DX being at most RHO. If its length is C strictly less than RHO, then we use the resultant freedom in DX to C minimize the objective function C -A(1,M+1)*DX(1)-A(2,M+1)*DX(2)-...-A(N,M+1)*DX(N) C subject to no increase in any greatest constraint violation. This C notation allows the gradient of the objective function to be regarded as C the gradient of a constraint. Therefore the two stages are distinguished C by MCON .EQ. M and MCON .GT. M respectively. It is possible that a C degeneracy may prevent DX from attaining the target length RHO. Then the C value IFULL=0 would be set, but usually IFULL=1 on return. C C In general NACT is the number of constraints in the active set and C IACT(1),...,IACT(NACT) are their indices, while the remainder of IACT C contains a permutation of the remaining constraint indices. Further, Z is C an orthogonal matrix whose first NACT columns can be regarded as the C result of Gram-Schmidt applied to the active constraint gradients. For C J=1,2,...,NACT, the number ZDOTA(J) is the scalar product of the J-th C column of Z with the gradient of the J-th active constraint. DX is the C current vector of variables and here the residuals of the active C constraints should be zero. Further, the active constraints have C nonnegative Lagrange multipliers that are held at the beginning of C VMULTC. The remainder of this vector holds the residuals of the inactive C constraints at DX, the ordering of the components of VMULTC being in C agreement with the permutation of the indices of the constraints that is C in IACT. All these residuals are nonnegative, which is achieved by the C shift RESMAX that makes the least residual zero. C C Initialize Z and some other variables. The value of RESMAX will be C appropriate to DX=0, while ICON will be the index of a most violated C constraint if RESMAX is positive. Usually during the first stage the C vector SDIRN gives a search direction that reduces all the active C constraint violations by one simultaneously. C IF (IPRINT .EQ. 3) THEN print *, ' ' print *, 'BEFORE trstlp:' PRINT *, ' **DX = ', (DX(I),I=1,N) PRINT *, ' **IACT = ', (IACT(I),I=1,M+1) PRINT *, 'M,N,RHO,IFULL =', M, N, RHO, IFULL PRINT *, ' **A = ', ((A(I,K),I=1,N),K=1,M+1) PRINT *, ' **B = ', (B(I),I=1,M) PRINT *, ' **Z = ', ((Z(I,K),I=1,N),K=1,N) PRINT *, ' **ZDOTA = ', (ZDOTA(I),I=1,N) PRINT *, ' **VMULTC = ', (VMULTC(I),I=1,M+1) PRINT *, ' **SDIRN = ', (SDIRN(I),I=1,N) PRINT *, ' **DXNEW = ', (DXNEW(I),I=1,N) PRINT *, ' **VMULTD = ', (VMULTD(I),I=1,M+1) PRINT *, ' ' END IF ICON=0 NACTX=0 RESOLD=0 IFULL=1 MCON=M NACT=0 RESMAX=0.0d0 DO 20 I=1,N DO 10 J=1,N 10 Z(I,J)=0.0d0 Z(I,I)=1.0d0 20 DX(I)=0.0d0 IF (M .GE. 1) THEN DO 30 K=1,M IF (B(K) .GT. RESMAX) THEN RESMAX=B(K) ICON=K END IF 30 CONTINUE DO 40 K=1,M IACT(K)=K 40 VMULTC(K)=RESMAX-B(K) END IF IF (IPRINT .EQ. 3) THEN PRINT *, ' 1. VMULTC = ', (VMULTC(I),I=1,M+1) END IF IF (RESMAX .EQ. 0.0d0) GOTO 480 DO 50 I=1,N 50 SDIRN(I)=0.0d0 C C End the current stage of the calculation if 3 consecutive iterations C have either failed to reduce the best calculated value of the objective C function or to increase the number of active constraints since the best C value was calculated. This strategy prevents cycling, but there is a C remote possibility that it will cause premature termination. C 60 OPTOLD=0.0d0 ICOUNT=0 70 IF (MCON .EQ. M) THEN OPTNEW=RESMAX ELSE OPTNEW=0.0d0 DO 80 I=1,N 80 OPTNEW=OPTNEW-DX(I)*A(I,MCON) END IF IF (IPRINT .EQ. 3) THEN PRINT *, ' ICOUNT, OPTNEW, OPTOLD = ', ICOUNT, OPTNEW, OPTOLD END IF IF (ICOUNT .EQ. 0 .OR. OPTNEW .LT. OPTOLD) THEN OPTOLD=OPTNEW NACTX=NACT ICOUNT=3 ELSE IF (NACT .GT. NACTX) THEN NACTX=NACT ICOUNT=3 ELSE ICOUNT=ICOUNT-1 IF (ICOUNT .EQ. 0) GOTO 490 END IF C C If ICON exceeds NACT, then we add the constraint with index IACT(ICON) to C the active set. Apply Givens rotations so that the last N-NACT-1 columns C of Z are orthogonal to the gradient of the new constraint, a scalar C product being set to zero if its nonzero value could be due to computer C rounding errors. The array DXNEW is used for working space. C IF (ICON .LE. NACT) GOTO 260 KK=IACT(ICON) DO 90 I=1,N 90 DXNEW(I)=A(I,KK) TOT=0.0D0 K=N 100 IF (K .GT. NACT) THEN SP=0.0d0 SPABS=0.0d0 DO 110 I=1,N TEMP=Z(I,K)*DXNEW(I) SP=SP+TEMP 110 SPABS=SPABS+DABS(TEMP) ACCA=SPABS+0.1d0*DABS(SP) ACCB=SPABS+0.2d0*DABS(SP) IF ((SPABS .GE. ACCA) .OR. (ACCA .GE. ACCB)) SP=0.0D0 IF (TOT .EQ. 0.0D0) THEN TOT=SP ELSE KP=K+1 TEMP=DSQRT(SP*SP+TOT*TOT) ALPHA=SP/TEMP BETA=TOT/TEMP TOT=TEMP DO 120 I=1,N TEMP=ALPHA*Z(I,K)+BETA*Z(I,KP) Z(I,KP)=ALPHA*Z(I,KP)-BETA*Z(I,K) 120 Z(I,K)=TEMP END IF K=K-1 GOTO 100 END IF C C Add the new constraint if this can be done without a deletion from the C active set. C IF (IPRINT .EQ. 3) THEN PRINT *, '*TOT, NACT, ICON = ', TOT, NACT, ICON END IF IF (TOT .NE. 0.0d0) THEN NACT=NACT+1 ZDOTA(NACT)=TOT VMULTC(ICON)=VMULTC(NACT) VMULTC(NACT)=0.0d0 GOTO 210 END IF C C The next instruction is reached if a deletion has to be made from the C active set in order to make room for the new active constraint, because C the new constraint gradient is a linear combination of the gradients of C the old active constraints. Set the elements of VMULTD to the multipliers C of the linear combination. Further, set IOUT to the index of the C constraint to be deleted, but branch if no suitable index can be found. C RATIO=-1.0d0 K=NACT 130 ZDOTV=0.0d0 ZDVABS=0.0d0 DO 140 I=1,N TEMP=Z(I,K)*DXNEW(I) ZDOTV=ZDOTV+TEMP 140 ZDVABS=ZDVABS+DABS(TEMP) ACCA=ZDVABS+0.1d0*DABS(ZDOTV) ACCB=ZDVABS+0.2d0*DABS(ZDOTV) IF (ZDVABS .LT. ACCA .AND. ACCA .LT. ACCB) THEN TEMP=ZDOTV/ZDOTA(K) IF (TEMP .GT. 0.0d0 .AND. IACT(K) .LE. M) THEN TEMPA=VMULTC(K)/TEMP IF (RATIO .LT. 0.0d0 .OR. TEMPA .LT. RATIO) THEN RATIO=TEMPA IOUT=K END IF END IF IF (K .GE. 2) THEN KW=IACT(K) DO 150 I=1,N 150 DXNEW(I)=DXNEW(I)-TEMP*A(I,KW) END IF VMULTD(K)=TEMP ELSE VMULTD(K)=0.0d0 END IF K=K-1 IF (K .GT. 0) GOTO 130 IF (IPRINT .EQ. 3) THEN PRINT *, ' 1. VMULTD = ', (VMULTD(I),I=1,M+1) END IF IF (RATIO .LT. 0.0d0) GOTO 490 C C Revise the Lagrange multipliers and reorder the active constraints so C that the one to be replaced is at the end of the list. Also calculate the C new value of ZDOTA(NACT) and branch if it is not acceptable. C DO 160 K=1,NACT 160 VMULTC(K)=DMAX1(0.0d0,VMULTC(K)-RATIO*VMULTD(K)) IF (IPRINT .EQ. 3) THEN PRINT *, ' 2. VMULTC = ', (VMULTC(I),I=1,M+1) END IF IF (ICON .LT. NACT) THEN ISAVE=IACT(ICON) VSAVE=VMULTC(ICON) K=ICON 170 KP=K+1 KW=IACT(KP) SP=0.0d0 DO 180 I=1,N 180 SP=SP+Z(I,K)*A(I,KW) TEMP=SQRT(SP*SP+ZDOTA(KP)**2) ALPHA=ZDOTA(KP)/TEMP BETA=SP/TEMP ZDOTA(KP)=ALPHA*ZDOTA(K) ZDOTA(K)=TEMP DO 190 I=1,N TEMP=ALPHA*Z(I,KP)+BETA*Z(I,K) Z(I,KP)=ALPHA*Z(I,K)-BETA*Z(I,KP) 190 Z(I,K)=TEMP IACT(K)=KW VMULTC(K)=VMULTC(KP) K=KP IF (K .LT. NACT) GOTO 170 IACT(K)=ISAVE VMULTC(K)=VSAVE END IF TEMP=0.0d0 DO 200 I=1,N 200 TEMP=TEMP+Z(I,NACT)*A(I,KK) IF (TEMP .EQ. 0.0d0) GOTO 490 ZDOTA(NACT)=TEMP VMULTC(ICON)=0.0d0 VMULTC(NACT)=RATIO C C Update IACT and ensure that the objective function continues to be C treated as the last active constraint when MCON>M. C 210 IACT(ICON)=IACT(NACT) IACT(NACT)=KK IF (MCON .GT. M .AND. KK .NE. MCON) THEN K=NACT-1 SP=0.0d0 DO 220 I=1,N 220 SP=SP+Z(I,K)*A(I,KK) TEMP=SQRT(SP*SP+ZDOTA(NACT)**2) ALPHA=ZDOTA(NACT)/TEMP BETA=SP/TEMP ZDOTA(NACT)=ALPHA*ZDOTA(K) ZDOTA(K)=TEMP DO 230 I=1,N TEMP=ALPHA*Z(I,NACT)+BETA*Z(I,K) Z(I,NACT)=ALPHA*Z(I,K)-BETA*Z(I,NACT) 230 Z(I,K)=TEMP IACT(NACT)=IACT(K) IACT(K)=KK TEMP=VMULTC(K) VMULTC(K)=VMULTC(NACT) VMULTC(NACT)=TEMP END IF C C If stage one is in progress, then set SDIRN to the direction of the next C change to the current vector of variables. C IF (MCON .GT. M) GOTO 320 KK=IACT(NACT) TEMP=0.0d0 DO 240 I=1,N 240 TEMP=TEMP+SDIRN(I)*A(I,KK) TEMP=TEMP-1.0d0 TEMP=TEMP/ZDOTA(NACT) DO 250 I=1,N 250 SDIRN(I)=SDIRN(I)-TEMP*Z(I,NACT) GOTO 340 C C Delete the constraint that has the index IACT(ICON) from the active set. C 260 IF (ICON .LT. NACT) THEN ISAVE=IACT(ICON) VSAVE=VMULTC(ICON) K=ICON 270 KP=K+1 KK=IACT(KP) SP=0.0d0 DO 280 I=1,N 280 SP=SP+Z(I,K)*A(I,KK) TEMP=SQRT(SP*SP+ZDOTA(KP)**2) ALPHA=ZDOTA(KP)/TEMP BETA=SP/TEMP ZDOTA(KP)=ALPHA*ZDOTA(K) ZDOTA(K)=TEMP DO 290 I=1,N TEMP=ALPHA*Z(I,KP)+BETA*Z(I,K) Z(I,KP)=ALPHA*Z(I,K)-BETA*Z(I,KP) 290 Z(I,K)=TEMP IACT(K)=KK VMULTC(K)=VMULTC(KP) K=KP IF (K .LT. NACT) GOTO 270 IACT(K)=ISAVE VMULTC(K)=VSAVE END IF NACT=NACT-1 C C If stage one is in progress, then set SDIRN to the direction of the next C change to the current vector of variables. C IF (MCON .GT. M) GOTO 320 TEMP=0.0d0 DO 300 I=1,N 300 TEMP=TEMP+SDIRN(I)*Z(I,NACT+1) DO 310 I=1,N 310 SDIRN(I)=SDIRN(I)-TEMP*Z(I,NACT+1) GO TO 340 C C Pick the next search direction of stage two. C 320 TEMP=1.0d0/ZDOTA(NACT) DO 330 I=1,N 330 SDIRN(I)=TEMP*Z(I,NACT) C C Calculate the step to the boundary of the trust region or take the step C that reduces RESMAX to zero. The two statements below that include the C factor 1.0E-6 prevent some harmless underflows that occurred in a test C calculation. Further, we skip the step if it could be zero within a C reasonable tolerance for computer rounding errors. C 340 DD=RHO*RHO SD=0.0d0 SS=0.0d0 DO 350 I=1,N IF (ABS(DX(I)) .GE. 1.0E-6*RHO) DD=DD-DX(I)**2 SD=SD+DX(I)*SDIRN(I) 350 SS=SS+SDIRN(I)**2 IF (DD .LE. 0.0d0) GOTO 490 TEMP=SQRT(SS*DD) IF (ABS(SD) .GE. 1.0E-6*TEMP) TEMP=SQRT(SS*DD+SD*SD) STPFUL=DD/(TEMP+SD) STEP=STPFUL IF (MCON .EQ. M) THEN ACCA=STEP+0.1d0*RESMAX ACCB=STEP+0.2d0*RESMAX IF (STEP .GE. ACCA .OR. ACCA .GE. ACCB) GOTO 480 STEP=DMIN1(STEP,RESMAX) END IF C C Set DXNEW to the new variables if STEP is the steplength, and reduce C RESMAX to the corresponding maximum residual if stage one is being done. C Because DXNEW will be changed during the calculation of some Lagrange C multipliers, it will be restored to the following value later. call s360_380(DXNEW,DX,STEP,SDIRN,N,M,MCON,RESMAX, 1 NACT,IACT,B,A,RESOLD) C C Set VMULTD to the VMULTC vector that would occur if DX became DXNEW. A C device is included to force VMULTD(K)=0.0 if deviations from this value C can be attributed to computer rounding errors. First calculate the new C Lagrange multipliers. C K=NACT 390 ZDOTW=0.0d0 ZDWABS=0.0d0 DO 400 I=1,N TEMP=Z(I,K)*DXNEW(I) ZDOTW=ZDOTW+TEMP 400 ZDWABS=ZDWABS+ABS(TEMP) ACCA=ZDWABS+0.1d0*ABS(ZDOTW) ACCB=ZDWABS+0.2d0*ABS(ZDOTW) IF (ZDWABS .GE. ACCA .OR. ACCA .GE. ACCB) ZDOTW=0.0d0 VMULTD(K)=ZDOTW/ZDOTA(K) IF (K .GE. 2) THEN KK=IACT(K) DO 410 I=1,N 410 DXNEW(I)=DXNEW(I)-VMULTD(K)*A(I,KK) K=K-1 GOTO 390 END IF IF (MCON .GT. M) VMULTD(NACT)=DMAX1(0.0d0,VMULTD(NACT)) IF (IPRINT .EQ. 3) THEN PRINT *, ' 2. VMULTD = ', (VMULTD(I),I=1,M+1) END IF C C Complete VMULTC by finding the new constraint residuals. C DO 420 I=1,N 420 DXNEW(I)=DX(I)+STEP*SDIRN(I) IF (MCON .GT. NACT) THEN KL=NACT+1 DO 440 K=KL,MCON KK=IACT(K) SUM=RESMAX-B(KK) SUMABS=RESMAX+DABS(B(KK)) DO 430 I=1,N TEMP=A(I,KK)*DXNEW(I) SUM=SUM+TEMP 430 SUMABS=SUMABS+DABS(TEMP) ACCA=SUMABS+0.1*DABS(SUM) ACCB=SUMABS+0.2*DABS(SUM) IF (SUMABS .GE. ACCA .OR. ACCA .GE. ACCB) SUM=0.0 440 VMULTD(K)=SUM END IF IF (IPRINT .EQ. 3) THEN PRINT *, ' 3. VMULTD = ', (VMULTD(I),I=1,M+1) END IF C C Calculate the fraction of the step from DX to DXNEW that will be taken. C RATIO=1.0d0 ICON=0 C EPS = 2.2E-16 DO 450 K=1,MCON IF (VMULTD(K) .GT. -EPS .AND. VMULTD(K) .LT. EPS) VMULTD(K)=0.0D0 IF (VMULTD(K) .LT. 0.0D0) THEN TEMP=VMULTC(K)/(VMULTC(K)-VMULTD(K)) IF (TEMP .LT. RATIO) THEN RATIO=TEMP ICON=K END IF END IF 450 CONTINUE C C Update DX, VMULTC and RESMAX. C TEMP=1.0d0-RATIO DO 460 I=1,N 460 DX(I)=TEMP*DX(I)+RATIO*DXNEW(I) DO 470 K=1,MCON 470 VMULTC(K)=DMAX1(0.0d0,TEMP*VMULTC(K)+RATIO*VMULTD(K)) IF (IPRINT .EQ. 3) THEN PRINT *, ' 3. VMULTC = ', (VMULTC(I),I=1,M+1) END IF IF (MCON .EQ. M) RESMAX=RESOLD+RATIO*(RESMAX-RESOLD) IF (IPRINT .EQ. 3) THEN PRINT *, ' RESMAX, MCON, M, ICON = ', 1 RESMAX, MCON, M, ICON END IF C C If the full step is not acceptable then begin another iteration. C Otherwise switch to stage two or end the calculation. C IF (ICON .GT. 0) GOTO 70 IF (STEP .EQ. STPFUL) GOTO 500 480 MCON=M+1 ICON=MCON IACT(MCON)=MCON VMULTC(MCON)=0.0d0 GOTO 60 C C We employ any freedom that may be available to reduce the objective C function before returning a DX whose length is less than RHO. C 490 IF (MCON .EQ. M) GOTO 480 IFULL=0 500 CONTINUE IF (IPRINT .EQ. 3) THEN print *, ' ' print *, 'AFTER trstlp:' PRINT *, ' **DX = ', (DX(I),I=1,N) PRINT *, ' **IACT = ', (IACT(I),I=1,M+1) PRINT *, 'M,N,RHO,IFULL =', M, N, RHO, IFULL PRINT *, ' **A = ', ((A(I,K),I=1,N),K=1,M+1) PRINT *, ' **B = ', (B(I),I=1,M) PRINT *, ' **Z = ', ((Z(I,K),I=1,N),K=1,N) PRINT *, ' **ZDOTA = ', (ZDOTA(I),I=1,N) PRINT *, ' **VMULTC = ', (VMULTC(I),I=1,M+1) PRINT *, ' **SDIRN = ', (SDIRN(I),I=1,N) PRINT *, ' **DXNEW = ', (DXNEW(I),I=1,N) PRINT *, ' **VMULTD = ', (VMULTD(I),I=1,M+1) PRINT *, ' ' END IF C 500 RETURN END subroutine s360_380(DXNEW,DX,STEP,SDIRN,N,M,MCON,RESMAX, 1 NACT,IACT,B,A,RESOLD) IMPLICIT DOUBLE PRECISION (A-H,O-Z) DIMENSION A(N,*),B(*),DX(*),IACT(*), SDIRN(*),DXNEW(*) DO 360 I=1,N 360 DXNEW(I)=DX(I)+STEP*SDIRN(I) IF (MCON .EQ. M) THEN RESOLD=RESMAX RESMAX=0.0d0 DO 380 K=1,NACT KK=IACT(K) TEMP=B(KK) DO 370 I=1,N 370 TEMP=TEMP-A(I,KK)*DXNEW(I) RESMAX=DMAX1(RESMAX,TEMP) 380 CONTINUE END IF end
bsd-3-clause
piyush0609/scipy
scipy/integrate/quadpack/dqawce.f
143
12260
subroutine dqawce(f,a,b,c,epsabs,epsrel,limit,result,abserr,neval, * ier,alist,blist,rlist,elist,iord,last) c***begin prologue dqawce c***date written 800101 (yymmdd) c***revision date 830518 (yymmdd) c***category no. h2a2a1,j4 c***keywords automatic integrator, special-purpose, c cauchy principal value, clenshaw-curtis method c***author piessens,robert,appl. math. & progr. div. - k.u.leuven c de doncker,elise,appl. math. & progr. div. - k.u.leuven c*** purpose the routine calculates an approximation result to a c cauchy principal value i = integral of f*w over (a,b) c (w(x) = 1/(x-c), (c.ne.a, c.ne.b), hopefully satisfying c following claim for accuracy c abs(i-result).le.max(epsabs,epsrel*abs(i)) c***description c c computation of a cauchy principal value c standard fortran subroutine c double precision version c c parameters c on entry c f - double precision c function subprogram defining the integrand c function f(x). the actual name for f needs to be c declared e x t e r n a l in the driver program. c c a - double precision c lower limit of integration c c b - double precision c upper limit of integration c c c - double precision c parameter in the weight function, c.ne.a, c.ne.b c if c = a or c = b, the routine will end with c ier = 6. c c epsabs - double precision c absolute accuracy requested c epsrel - double precision c relative accuracy requested c if epsabs.le.0 c and epsrel.lt.max(50*rel.mach.acc.,0.5d-28), c the routine will end with ier = 6. c c limit - integer c gives an upper bound on the number of subintervals c in the partition of (a,b), limit.ge.1 c c on return c result - double precision c approximation to the integral c c abserr - double precision c estimate of the modulus of the absolute error, c which should equal or exceed abs(i-result) c c neval - integer c number of integrand evaluations c c ier - integer c ier = 0 normal and reliable termination of the c routine. it is assumed that the requested c accuracy has been achieved. c ier.gt.0 abnormal termination of the routine c the estimates for integral and error are c less reliable. it is assumed that the c requested accuracy has not been achieved. c error messages c ier = 1 maximum number of subdivisions allowed c has been achieved. one can allow more sub- c divisions by increasing the value of c limit. however, if this yields no c improvement it is advised to analyze the c the integrand, in order to determine the c the integration difficulties. if the c position of a local difficulty can be c determined (e.g. singularity, c discontinuity within the interval) one c will probably gain from splitting up the c interval at this point and calling c appropriate integrators on the subranges. c = 2 the occurrence of roundoff error is detec- c ted, which prevents the requested c tolerance from being achieved. c = 3 extremely bad integrand behaviour c occurs at some interior points of c the integration interval. c = 6 the input is invalid, because c c = a or c = b or c (epsabs.le.0 and c epsrel.lt.max(50*rel.mach.acc.,0.5d-28)) c or limit.lt.1. c result, abserr, neval, rlist(1), elist(1), c iord(1) and last are set to zero. alist(1) c and blist(1) are set to a and b c respectively. c c alist - double precision c vector of dimension at least limit, the first c last elements of which are the left c end points of the subintervals in the partition c of the given integration range (a,b) c c blist - double precision c vector of dimension at least limit, the first c last elements of which are the right c end points of the subintervals in the partition c of the given integration range (a,b) c c rlist - double precision c vector of dimension at least limit, the first c last elements of which are the integral c approximations on the subintervals c c elist - double precision c vector of dimension limit, the first last c elements of which are the moduli of the absolute c error estimates on the subintervals c c iord - integer c vector of dimension at least limit, the first k c elements of which are pointers to the error c estimates over the subintervals, so that c elist(iord(1)), ..., elist(iord(k)) with k = last c if last.le.(limit/2+2), and k = limit+1-last c otherwise, form a decreasing sequence c c last - integer c number of subintervals actually produced in c the subdivision process c c***references (none) c***routines called d1mach,dqc25c,dqpsrt c***end prologue dqawce c double precision a,aa,abserr,alist,area,area1,area12,area2,a1,a2, * b,bb,blist,b1,b2,c,dabs,dmax1,d1mach,elist,epmach,epsabs,epsrel, * errbnd,errmax,error1,erro12,error2,errsum,f,result,rlist,uflow integer ier,iord,iroff1,iroff2,k,krule,last,limit,maxerr,nev, * neval,nrmax c dimension alist(limit),blist(limit),rlist(limit),elist(limit), * iord(limit) c external f c c list of major variables c ----------------------- c c alist - list of left end points of all subintervals c considered up to now c blist - list of right end points of all subintervals c considered up to now c rlist(i) - approximation to the integral over c (alist(i),blist(i)) c elist(i) - error estimate applying to rlist(i) c maxerr - pointer to the interval with largest c error estimate c errmax - elist(maxerr) c area - sum of the integrals over the subintervals c errsum - sum of the errors over the subintervals c errbnd - requested accuracy max(epsabs,epsrel* c abs(result)) c *****1 - variable for the left subinterval c *****2 - variable for the right subinterval c last - index for subdivision c c c machine dependent constants c --------------------------- c c epmach is the largest relative spacing. c uflow is the smallest positive magnitude. c c***first executable statement dqawce epmach = d1mach(4) uflow = d1mach(1) c c c test on validity of parameters c ------------------------------ c ier = 6 neval = 0 last = 0 alist(1) = a blist(1) = b rlist(1) = 0.0d+00 elist(1) = 0.0d+00 iord(1) = 0 result = 0.0d+00 abserr = 0.0d+00 if(c.eq.a.or.c.eq.b.or.(epsabs.le.0.0d+00.and * .epsrel.lt.dmax1(0.5d+02*epmach,0.5d-28))) go to 999 c c first approximation to the integral c ----------------------------------- c aa=a bb=b if (a.le.b) go to 10 aa=b bb=a 10 ier=0 krule = 1 call dqc25c(f,aa,bb,c,result,abserr,krule,neval) last = 1 rlist(1) = result elist(1) = abserr iord(1) = 1 alist(1) = a blist(1) = b c c test on accuracy c errbnd = dmax1(epsabs,epsrel*dabs(result)) if(limit.eq.1) ier = 1 if(abserr.lt.dmin1(0.1d-01*dabs(result),errbnd) * .or.ier.eq.1) go to 70 c c initialization c -------------- c alist(1) = aa blist(1) = bb rlist(1) = result errmax = abserr maxerr = 1 area = result errsum = abserr nrmax = 1 iroff1 = 0 iroff2 = 0 c c main do-loop c ------------ c do 40 last = 2,limit c c bisect the subinterval with nrmax-th largest c error estimate. c a1 = alist(maxerr) b1 = 0.5d+00*(alist(maxerr)+blist(maxerr)) b2 = blist(maxerr) if(c.le.b1.and.c.gt.a1) b1 = 0.5d+00*(c+b2) if(c.gt.b1.and.c.lt.b2) b1 = 0.5d+00*(a1+c) a2 = b1 krule = 2 call dqc25c(f,a1,b1,c,area1,error1,krule,nev) neval = neval+nev call dqc25c(f,a2,b2,c,area2,error2,krule,nev) neval = neval+nev c c improve previous approximations to integral c and error and test for accuracy. c area12 = area1+area2 erro12 = error1+error2 errsum = errsum+erro12-errmax area = area+area12-rlist(maxerr) if(dabs(rlist(maxerr)-area12).lt.0.1d-04*dabs(area12) * .and.erro12.ge.0.99d+00*errmax.and.krule.eq.0) * iroff1 = iroff1+1 if(last.gt.10.and.erro12.gt.errmax.and.krule.eq.0) * iroff2 = iroff2+1 rlist(maxerr) = area1 rlist(last) = area2 errbnd = dmax1(epsabs,epsrel*dabs(area)) if(errsum.le.errbnd) go to 15 c c test for roundoff error and eventually set error flag. c if(iroff1.ge.6.and.iroff2.gt.20) ier = 2 c c set error flag in the case that number of interval c bisections exceeds limit. c if(last.eq.limit) ier = 1 c c set error flag in the case of bad integrand behaviour c at a point of the integration range. c if(dmax1(dabs(a1),dabs(b2)).le.(0.1d+01+0.1d+03*epmach) * *(dabs(a2)+0.1d+04*uflow)) ier = 3 c c append the newly-created intervals to the list. c 15 if(error2.gt.error1) go to 20 alist(last) = a2 blist(maxerr) = b1 blist(last) = b2 elist(maxerr) = error1 elist(last) = error2 go to 30 20 alist(maxerr) = a2 alist(last) = a1 blist(last) = b1 rlist(maxerr) = area2 rlist(last) = area1 elist(maxerr) = error2 elist(last) = error1 c c call subroutine dqpsrt to maintain the descending ordering c in the list of error estimates and select the subinterval c with nrmax-th largest error estimate (to be bisected next). c 30 call dqpsrt(limit,last,maxerr,errmax,elist,iord,nrmax) c ***jump out of do-loop if(ier.ne.0.or.errsum.le.errbnd) go to 50 40 continue c c compute final result. c --------------------- c 50 result = 0.0d+00 do 60 k=1,last result = result+rlist(k) 60 continue abserr = errsum 70 if (aa.eq.b) result=-result 999 return end
bsd-3-clause
LucasGandel/ITK
Modules/ThirdParty/VNL/src/vxl/v3p/netlib/napack/cg.f
41
14263
C C ________________________________________________________ C | | C | MINIMIZE A FUNCTION USING THE FLETCHER-REEVES FORM | C | OF THE CONJUGATE GRADIENT METHOD | C | WITH (OR WITHOUT) PRECONDITIONING | C | | C | INPUT: | C | | C | X --ARRAY CONTAINING STARTING GUESS | C | | C | STEP --STARTING GUESS FOR MINIMIZER IN DIREC- | C | TION OF NEGATIVE GRADIENT DURING FIRST | C | ITERATION (E. G. STEP=1) WHEN STEP=0, | C | THE PROGRAM SELECTS A STARTING GUESS | C | | C | T --COMPUTING TOLERANCE (ITERATIONS STOP | C | WHEN MAX-NORM OF GRADIENT .LE. T) | C | | C | LIMIT --MAXIMUM NUMBER OF ITERATIONS | C | | C | N --NUMBER OF UNKNOWNS | C | | C | M --NUMBER OF ITERATIONS UNTIL THE SEARCH | C | DIRECTIONS ARE RENORMALIZED ALONG THE | C | NEGATIVE GRADIENT (TYPICALLY, M = N) | C | | C | VALUE --NAME OF COST EVALUATION FUNC. ROUTINE | C | (EXTERNAL IN MAIN PROGRAM) | C | VALUE(X) IS VALUE OF COST AT X | C | | C | GRAD --NAME OF GRADIENT EVALUATION SUBROUTINE | C | (EXTERNAL IN MAIN PROGRAM) | C | GRAD(G,X) PUTS IN G THE GRADIENT AT X | C | | C | BOTH --NAME SUBROUTINE TO EVALUATE BOTH COST | C | AND ITS GRADIENT (EXTERNAL IN MAIN | C | PROGRAM) BOTH(V,G,X) PUTS THE VALUE IN | C | V AND THE GRADIENT IN G FOR THE POINT X| C | | C | PRE --NAME OF PRECONDITIONING SUBROUTINE | C | (EXTERNAL IN MAIN PROGRAM) | C | PRE(Y,Z) APPLIES THE PRECONDITIONER TO | C | Z, STORING THE RESULT IN Y. | C | IF PRECONDITIONING NOT USED SET Y = Z | C | | C | H --WORK ARRAY (LENGTH AT LEAST 3N) | C | | C | OUTPUT: | C | | C | X --MINIMIZER | C | | C | E --MAX-NORM OF GRADIENT | C | | C | IT --NUMBER OF ITERATIONS PERFORMED | C | | C | STEP --STEP SIZE ALONG SEARCH DIRECTION FOR | C | FINAL ITERATION | C | | C | BUILTIN FUNCTIONS: DABS,DEXP,IDINT,DLOG,DSQRT,DMAX1,| C | DMIN1,DSIGN | C | PACKAGE ROUTINES: CUB,FD,FV,FVD,INS | C |________________________________________________________| C SUBROUTINE CG(X,E,IT,STEP,T,LIMIT,N,M,VALUE,GRAD,BOTH,PRE,H) INTEGER I,IT,J,K,L,LIMIT,M,N,NA,NB,NC,ND REAL*8 H(N,1),X(1),Y(50),Z(50),A1,A2,A3,A4,A5,A6,A7,A8,A,B,C,C0,C1 REAL*8 D,D0,DA,DB,E,F,F0,F1,FA,FB,FC,G,L3,P,Q,R,S,STEP,T,V,W REAL*8 FV,FD,VALUE EXTERNAL BOTH,GRAD,PRE,VALUE DATA A1/.1D0/,A2/.9D0/,A3/5.D0/,A4/.2D0/,A5/10.D0/,A6/.9D0/ DATA A7/.3D0/ A8 = A3 + .01D0 IT = 0 CALL BOTH(F,H(1,3),X) E = 0. DO 10 I = 1,N 10 IF ( DABS(H(I,3)) .GT. E ) E = DABS(H(I,3)) IF ( E .LE. T ) RETURN L3 = 1./DLOG(A3) CALL PRE(H(1,2),H(1,3)) A = STEP IF ( A .GT. 0. ) GOTO 30 DO 20 I = 1,N 20 IF ( DABS(X(I)) .GT. A ) A = DABS(X(I)) A = .01*A/E IF ( A .EQ. 0. ) A = 1. 30 G = 0. DO 40 I = 1,N 40 G = G + H(I,2)*H(I,3) IF ( G .LT. 0. ) GOTO 620 50 L = 0 DO 60 I = 1,N 60 H(I,1) = -H(I,2) D = -G 70 FA = FV(A,X,H,N,VALUE) C0 = A F0 = FA J = 2 Y(1) = 0. Z(1) = F Y(2) = A Z(2) = FA V = A1*D W = A2*D IQ = 0 IF ( FA .LE. F ) GOTO 80 C = A B = 0. A = 0. FC = FA FB = F FA = F GOTO 90 80 C = 0. B = 0. FC = F FB = F IQ = 1 90 NA = 0 NB = 0 NC = 0 ND = 0 Q = (D+(F-F0)/C0)/C0 IF ( Q .LT. 0. ) GOTO 110 Q = A 100 ND = ND + 1 IF ( ND .GT. 25 ) GOTO 610 Q = A3*Q P = FV(Q,X,H,N,VALUE) CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) IF ( P-F .LT. W*Q ) GOTO 100 GOTO 260 110 Q = .5*D/Q IF ( Q .LT. .01*C0 ) Q = .01*C0 P = FV(Q,X,H,N,VALUE) IF ( P .LE. F0 ) GOTO 120 F1 = F0 C1 = C0 F0 = P C0 = Q GOTO 130 120 F1 = P C1 = Q 130 CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) 135 IF ( A .EQ. 0. ) GOTO 140 IF ( FA-F .GE. V*A ) GOTO 160 IF ( FA-F .LT. W*A ) GOTO 210 GOTO 280 140 Q = C0 IF ( C1 .LT. Q ) Q = C1 150 NA = NA + 1 IF ( NA .GT. 25 ) GOTO 630 Q = A4*Q P = FV(Q,X,H,N,VALUE) CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) IF ( P-F .GE. V*Q ) GOTO 150 GOTO 250 160 IF ( C0 .GT. C1 ) GOTO 200 IF ( F0-F .GT. V*C0 ) GOTO 180 IF ( F0-F .GE. W*C0 ) GOTO 320 IF ( C1 .LE. A5*C0 ) GOTO 320 R = DLOG(C1/C0) S = -IDINT(R*L3+.999) R = .999*DEXP(R/S) Q = C1 170 Q = Q*R IF ( Q .LT. C0 ) GOTO 320 P = FV(Q,X,H,N,VALUE) CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) NA = NA + 1 IF ( P-F .GT. V*Q ) GOTO 170 GOTO 320 180 Q = C0 190 NA = NA + 1 IF ( NA .GT. 25 ) GOTO 630 Q = A4*Q P = FV(Q,X,H,N,VALUE) CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) IF ( P-F .GE. V*Q ) GOTO 190 GOTO 250 200 Q = A GOTO 190 210 IF ( C0 .LT. C1 ) GOTO 290 IF ( F0-F .GE. V*C0 ) GOTO 230 IF ( F0-F .GE. W*C0 ) GOTO 250 Q = C0 220 ND = ND + 1 IF ( ND .GT. 25 ) GOTO 610 Q = A3*Q P = FV(Q,X,H,N,VALUE) CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) IF ( P-F .LT. W*Q ) GOTO 220 GOTO 250 230 IF ( C0 .LE. A5*C1 ) GOTO 250 R = DLOG(C0/C1) S = IDINT(R*L3+.999) R = 1.001*DEXP(R/S) Q = A 240 Q = Q*R IF ( Q .GT. C0 ) GOTO 250 ND = ND + 1 P = FV(Q,X,H,N,VALUE) CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) IF ( P-F .LT. W*Q ) GOTO 240 250 IF ( IQ .EQ. 1 ) GOTO 320 260 IF ( B .EQ. 0. ) GOTO 280 IF ( C .EQ. 0. ) GOTO 270 V = C - A W = A - B R = 1./V S = 1./W P = FC - FA Q = FB - FA E = P*R + Q*S IF ( DSIGN(E,C-B) .NE. E ) GOTO 320 IF ( E .EQ. 0. ) GOTO 320 Q = (P*R)*W - (Q*S)*V Q = A - .5*Q/E P = FV(Q,X,H,N,VALUE) CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) GOTO 320 270 R = 1./A S = 1./B P = R*(FA-F) - D Q = S*(FB-F) - D E = A - B V = (R*P-S*Q)/E W = (A*Q*S-B*P*R)/E V = W*W-3.*V*D IF ( V .LT. 0. ) V = 0. V = DSQRT(V) IF ( W+V .EQ. 0. ) GOTO 320 Q = -D/(W+V) IF ( Q .LE. 0. ) GOTO 320 P = FV(Q,X,H,N,VALUE) CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) GOTO 320 280 IF ( IQ .EQ. 1 ) GOTO 320 Q = (D+(F-FA)/A)/A IF ( Q .GE. 0. ) GOTO 320 Q = .5*D/Q P = FV(Q,X,H,N,VALUE) CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) GOTO 320 290 IF ( F0-F .GT. V*C0 ) GOTO 300 IF ( F0-F .GT. W*C0 ) GOTO 320 300 Q = A 310 ND = ND + 1 IF ( ND .GT. 25 ) GOTO 610 Q = A3*Q P = FV(Q,X,H,N,VALUE) CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) IF ( P-F .LT. W*Q ) GOTO 310 GOTO 250 320 DA = FD(A,X,H,N,GRAD) IF ( DA .GT. A6*G ) GOTO 410 IF ( DA .GE. 0. ) GOTO 560 R = A Q = 0. DO 330 I = 1,J IF ( Y(I) .GT. A ) GOTO 370 IF ( Y(I) .LE. Q ) GOTO 330 IF ( Y(I) .EQ. A ) GOTO 330 Q = Y(I) 330 CONTINUE IF ( A .LE. A8*Q ) GOTO 560 Q = A 340 ND = ND + 1 IF ( ND .GT. 25 ) GOTO 610 Q = A3*Q P = FV(Q,X,H,N,VALUE) F1 = FA CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) IF ( P .LT. F1 ) GOTO 340 IF ( A .GT. R ) GOTO 360 DO 350 I = 1,N 350 H(I,2) = X(I) + A*H(I,1) GOTO 560 360 DA = FD(A,X,H,N,GRAD) IF ( DA .GT. A6*G ) GOTO 410 GOTO 560 370 Q = Y(I) DO 380 K = I,J IF ( Y(K) .LE. A ) GOTO 380 IF ( Y(K) .LT. Q ) Q = Y(K) 380 CONTINUE IF ( Q .LE. A5*A ) GOTO 560 F0 = DLOG(Q/A) S = IDINT(F0*L3+.999) F0 = 1.001*DEXP(F0/S) S = A 390 S = S*F0 IF ( S .GE. Q ) GOTO 320 P = FV(S,X,H,N,VALUE) F1 = FA CALL INS(S,P,A,B,C,FA,FB,FC,J,Y,Z) IF ( P .LT. F1 ) GOTO 390 IF ( A .GT. R ) GOTO 320 DO 400 I = 1,N 400 H(I,2) = X(I) + A*H(I,1) GOTO 560 410 B = 0. K = 1 I = K 420 I = I + 1 IF ( I .GT. J ) GOTO 430 IF ( Y(I) .GE. A ) GOTO 420 IF ( Y(I) .LT. B ) GOTO 420 B = Y(I) K = I GOTO 420 430 FB = Z(K) DB = D IF ( B .NE. 0. ) DB = FD(B,X,H,N,GRAD) 440 W = 2.*DABS(B-A) CALL CUB(C,A,B,FA,FB,DA,DB) NC = 1 GOTO 480 450 W = .5*W IF ( W .LT. DABS(C0-C) ) GOTO 550 IF ( C0 .LT. C ) GOTO 460 IF ( D0 .GE. D ) GOTO 470 GOTO 550 460 IF ( D0 .GT. D ) GOTO 550 470 CALL CUB(C,C,C0,F,F0,D,D0) NC = NC + 1 IF ( NC .GT. 30 ) GOTO 600 480 R = DMAX1(A,B) S = DMIN1(A,B) IF ( C .GT. R ) GOTO 490 IF ( C .GT. S ) GOTO 500 C = S + (S-C) S = .5*(A+B) IF ( C .GT. S ) C = S GOTO 500 490 C = R - (C-R) S = .5*(A+B) IF ( C .LT. S ) C = S 500 C0 = A F0 = FA D0 = DA CALL FVD(F,D,C,X,H,N,BOTH) IF ( F .LT. FA ) GOTO 510 B = C FB = F DB = D GOTO 450 510 IF ( C .LT. A ) GOTO 540 IF ( D .LT. 0. ) GOTO 530 520 B = A FB = FA DB = DA 530 A = C FA = F DA = D IF ( D .GT. A6*G ) GOTO 450 GOTO 560 540 IF ( D .LT. 0. ) GOTO 520 GOTO 530 550 C = .5*(A+B) NB = NB + 1 W = DABS(B-A) GOTO 500 560 E = 0. DO 570 I = 1,N IF ( DABS(H(I,3)) .GT. E ) E = DABS(H(I,3)) 570 X(I) = H(I,2) IT = IT + 1 IF ( E .LE. T ) GOTO 660 IF ( IT .GE. LIMIT ) GOTO 660 F = FA D = DA A = A7*A CALL PRE(H(1,2),H(1,3)) R = 0. DO 580 I = 1,N 580 R = R + H(I,2)*H(I,3) IF ( R .LT. 0. ) GOTO 620 S = R/G G = R L = L + 1 IF ( L .GE. M ) GOTO 50 D = 0. DO 590 I = 1,N H(I,1) = -H(I,2) + S*H(I,1) 590 D = D + H(I,1)*H(I,3) GOTO 70 600 IF ( D .LT. G ) GOTO 560 WRITE(6,*) 'UNABLE TO OBTAIN DESCENT DIRECTION' STOP 610 WRITE(6,*) 'THE FUNCTION DECREASES WITH NO MINIMUM' STOP 620 WRITE(6,*) 'PRECONDITIONER NOT POSITIVE DEFINITE' STOP 630 Q = Q*A3**25 ND = 0 640 ND = ND + 1 IF ( ND .GT. 25 ) GOTO 650 Q = A3*Q P = FV(Q,X,H,N,VALUE) CALL INS(Q,P,A,B,C,FA,FB,FC,J,Y,Z) IF ( P-F .GT. V*Q ) GOTO 640 GOTO 135 650 WRITE(6,*) 'UNABLE TO SATISFY ARMIJO CONDITION' RETURN 660 STEP = A RETURN END DOUBLE PRECISION FUNCTION FV(A,X,H,N,VALUE) REAL*8 H(N,1),X(1),A,VALUE EXTERNAL VALUE DO 10 I = 1 , N 10 H(I,2) = X(I) + A*H(I,1) FV = VALUE(H(1,2)) RETURN END DOUBLE PRECISION FUNCTION FD(A,X,H,N,GRAD) REAL*8 H(N,1),X(1),A,D EXTERNAL GRAD DO 10 I = 1 , N 10 H(I,2) = X(I) + A*H(I,1) CALL GRAD(H(1,3),H(1,2)) D = 0. DO 20 I = 1,N 20 D = D + H(I,1)*H(I,3) FD = D RETURN END SUBROUTINE FVD(V,D,A,X,H,N,BOTH) REAL*8 H(N,1),X(1),A,D,V EXTERNAL BOTH DO 10 I = 1 , N 10 H(I,2) = X(I) + A*H(I,1) CALL BOTH(V,H(1,3),H(1,2)) D = 0. DO 20 I = 1,N 20 D = D + H(I,1)*H(I,3) RETURN END SUBROUTINE CUB(X,A,B,C,D,E,F) REAL*8 A,B,C,D,E,F,G,V,W,X,Y,Z G = B - A IF ( G .EQ. 0. ) GOTO 50 V = E + F - 3*(D-C)/G W = V*V-E*F IF ( W .LT. 0. ) W = 0. W = DSIGN(DSQRT(W),G) Y = E + V Z = F + V IF ( DSIGN(Y,G) .NE. Y ) GOTO 30 IF ( DSIGN(Z,G) .NE. Z ) GOTO 20 IF ( Z .EQ. 0. ) GOTO 20 10 X = B - G*F/(Z+W) RETURN 20 IF ( C .LT. D ) X = A IF ( C .GE. D ) X = B RETURN 30 IF ( DSIGN(Z,G) .NE. Z ) GOTO 40 IF ( DABS(E) .GT. DABS(F) ) GOTO 10 40 X = A + G*E/(Y-W) RETURN 50 X = A RETURN END SUBROUTINE INS(S,F,A,B,C,FA,FB,FC,J,Y,Z) REAL*8 A,B,C,F,FA,FB,FC,S,Y(1),Z(1) INTEGER J J = J + 1 Y(J) = S Z(J) = F IF ( F .LE. FA ) GOTO 20 IF ( F .LE. FB ) GOTO 10 IF ( F .GT. FC ) RETURN C = S FC = F RETURN 10 C = B B = S FC = FB FB = F RETURN 20 C = B B = A A = S FC = FB FB = FA FA = F RETURN END
apache-2.0
QEF/q-e_schrodinger
atomic/src/export_upf.f90
2
15169
! ! Copyright (C) 2008 PWSCF group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !--------------------------------------------------------------------- SUBROUTINE export_upf(filename, unit_loc) !--------------------------------------------------------------------- ! use constants, only : fpi use kinds, only : dp use ld1inc, only : author, nlcc, zval, lpaw, write_coulomb, & etots, rel, ecutwfc, ecutrho, iswitch, & nwfts, nbeta, lmax, which_augfun, elts, octs, llts, & nnts, rcutusts, rcutts, rcut, rcutus, els, ikk, nwfs, & lls, nns, ocs, beta, bmat, qq, qvan, qvanl, rcloc, lloc, & betas, grid, rhos, phits, psipaw, vpsloc, phis, & rmatch_augfun, etot, etots, jjs, pawsetup, nn, & core_state, ll, el, nwf, psi, vpot, nconf, zed, & jjts, vpstot, lltsc, rcuttsc, rcutustsc, eltsc, & lsave_wfc, wfc_ae_recon, wfc_ps_recon, tm, enlts, & nstoaets, pseudotype, enls, rhoc, vnl, vpsloc, & lgipaw_reconstruction, use_paw_as_gipaw, use_xsd use funct, only: get_dft_name use global_version, only: version_number ! use pseudo_types, only : pseudo_upf, pseudo_config, & deallocate_pseudo_upf, deallocate_pseudo_config use write_upf_new, only: write_upf ! implicit none ! CHARACTER(len=*),INTENT(IN) :: filename INTEGER,INTENT(IN):: unit_loc ! integer :: ibeta, jbeta, kbeta, l, ind, l1, l2 ! ! Local variables ! integer :: nb, mesh TYPE (pseudo_upf) :: upf TYPE (pseudo_config) :: at_conf CHARACTER(len=2), external :: atom_name CHARACTER(len=9) :: day, hour call date_and_tim(day,hour) ! IF (iswitch < 4 ) THEN upf%generated='Generated using "atomic" code by A. Dal Corso & & v.' // TRIM (version_number) ELSE IF (iswitch==4) THEN upf%generated='Generated using LDA-1/2 implemented by Leonardo& & Matheus Marion Jorge' ENDIF upf%author=trim(author) upf%date=trim(day) upf%nv = "2.0.1" ! format version ! upf%zp = zval upf%nlcc = nlcc upf%dft = get_dft_name() upf%psd = atom_name(nint(zed)) if( pseudotype == 3) then upf%tvanp = .true. upf%typ='USPP' else upf%tvanp = .false. upf%typ='NC' endif if(lpaw) upf%typ='PAW' if(write_coulomb) upf%typ='1/r' upf%tpawp = lpaw upf%tcoulombp = write_coulomb upf%has_gipaw = lgipaw_reconstruction upf%paw_as_gipaw = use_paw_as_gipaw upf%etotps = etots upf%has_so = (rel == 2) IF (rel == 2) THEN upf%rel='full' ELSE IF (rel == 1) THEN upf%rel='scalar' ELSE IF (rel < 1) THEN upf%rel='no' ELSE call errore('export_upf', 'Unknown relativistic',1) ENDIF ! upf%ecutwfc = ecutwfc upf%ecutrho = max(ecutrho, ecutwfc*4._dp) ! upf%nwfc = nwfts upf%nbeta = nbeta ! if (.not. lpaw) then upf%lmax = lmax upf%q_with_l = (which_augfun == 'PSQ') else upf%lmax = pawsetup%lmax upf%q_with_l = .true. endif upf%lmax_rho = 2*upf%lmax upf%nqlc = 2* upf%lmax+1 upf%mesh = grid%mesh upf%dx = grid%dx upf%xmin = grid%xmin upf%zmesh = grid%zmesh upf%rmax = grid%rmax ! allocate( upf%r (upf%mesh) ) allocate( upf%rab(upf%mesh) ) ! upf%r = grid%r upf%rab = grid%rab ! ! when possible, write semilocal PP's in the UPF file - may be ! useful if one wants to use PPs in the UPF format in other codes ! if( pseudotype == 1 ) then if ( rel == 2 ) then allocate(upf%vnl(1:grid%mesh, 0:upf%lmax,2)) else allocate(upf%vnl(1:grid%mesh, 0:upf%lmax,1)) end if do nb=1, nbeta l=lls(nb) if ( rel < 2 .or. l == 0 .or. & abs(jjs(nb)-l+0.5_dp) < 0.001_dp) then ind = 1 else if ( rel == 2 .and. l > 0 .and. & abs(jjs(nb)-l-0.5_dp) < 0.001_dp) then ind = 2 endif upf%vnl(1:grid%mesh,l,ind) = vnl(1:grid%mesh,l,ind) + & vpsloc(1:grid%mesh) end do end if ! allocate(upf%lll(nbeta)) upf%lll(1:nbeta) = lls(1:nbeta) ! ! *initial* wavefunctions indexes and parameters allocate(upf%els(upf%nwfc), upf%oc(upf%nwfc), & upf%nchi(upf%nwfc), upf%lchi(upf%nwfc), & upf%epseu(upf%nwfc), upf%rcut_chi(upf%nwfc), & upf%rcutus_chi(upf%nwfc) ) upf%els(1:upf%nwfc) = elts(1:upf%nwfc) upf%oc(1:upf%nwfc) = octs(1:upf%nwfc) upf%lchi(1:upf%nwfc) = llts(1:upf%nwfc) upf%nchi(1:upf%nwfc) = nnts(1:upf%nwfc) upf%epseu(1:upf%nwfc) = enlts(1:upf%nwfc) upf%rcut_chi(1:upf%nwfc) = rcutts(1:upf%nwfc) upf%rcutus_chi(1:upf%nwfc) = rcutusts(1:upf%nwfc) ! ! projectors indexes and parameters ! allocate(upf%kbeta(nbeta), upf%els_beta(nbeta),& upf%rcut(nbeta), upf%rcutus(nbeta)) do nb=1,nbeta upf%kbeta(nb) = ikk(nb) upf%els_beta(nb)= els(nb) upf%rcut(nb) = rcut(nb) upf%rcutus(nb) = rcutus(nb) end do upf%kkbeta = maxval(upf%kbeta(1:nbeta)) ! ! Save GENERATION configuration: not needed to use the pseudopotential, ! but must be saved for reference and for re-generating the pseudo ! at_conf%nwfs = nwfs if (tm) then at_conf%pseud = 'troullier-martins' else at_conf%pseud = 'rrkj' endif allocate(at_conf%els (nwfs),& at_conf%nns (nwfs),& at_conf%lls (nwfs),& at_conf%ocs (nwfs),& at_conf%rcut (nwfs),& at_conf%rcutus(nwfs),& at_conf%enls (nwfs)) at_conf%els (1:nwfs) = els (1:nwfs) ! label (char*2) at_conf%nns (1:nwfs) = nns (1:nwfs) ! n at_conf%lls (1:nwfs) = lls (1:nwfs) ! l at_conf%ocs (1:nwfs) = ocs (1:nwfs) ! occupation at_conf%rcut (1:nwfs) = rcut (1:nwfs) ! inner cutoff radius at_conf%rcutus(1:nwfs) = rcutus(1:nwfs) ! outer cutoff radius at_conf%enls (1:nwfs) = enls (1:nwfs) ! one-particle energy ! projectors allocate(upf%beta(grid%mesh, upf%nbeta)) upf%beta(1:grid%mesh, 1:upf%nbeta) = betas(1:grid%mesh, 1:nbeta) ! ! hamiltonian terms allocate(upf%dion(upf%nbeta, upf%nbeta)) upf%dion(1:upf%nbeta, 1:upf%nbeta) = bmat(1:nbeta, 1:nbeta) ! if (pseudotype.eq.3) then allocate(upf%qqq(upf%nbeta, upf%nbeta)) upf%qqq(1:upf%nbeta,1:upf%nbeta) = qq(1:nbeta,1:nbeta) ! upf%qqq_eps = 1.e-12_dp ! (hardcoded) upf%nqf = 0 ! polinomial expansion of aug.charge is not supported by atomic ! if (upf%q_with_l .or. lpaw) then allocate(upf%qfuncl(upf%mesh, upf%nbeta*(upf%nbeta+1)/2, 0:2*upf%lmax)) else allocate(upf%qfunc(upf%mesh, upf%nbeta*(upf%nbeta+1)/2)) endif ! if(lpaw) qvanl(1:grid%mesh,:,:,:) = pawsetup%augfun(1:grid%mesh,:,:,:) do ibeta=1,nbeta do jbeta=ibeta,nbeta kbeta = jbeta * (jbeta-1) / 2 + ibeta if (upf%q_with_l .or. lpaw) then l1=upf%lll(ibeta) l2=upf%lll(jbeta) do l=abs(l1-l2), l1+l2 upf%qfuncl(1:grid%mesh,kbeta,l) = qvanl(1:grid%mesh,ibeta,jbeta,l) enddo else upf%qfunc(1:grid%mesh,kbeta) = qvan (1:grid%mesh, ibeta, jbeta) endif enddo enddo ! endif ! allocate(upf%rho_atc(upf%mesh)) if (upf%nlcc) then upf%rho_atc(1:grid%mesh) = rhoc(1:grid%mesh)/fpi/grid%r2(1:grid%mesh) else upf%rho_atc(:) = 0.0_dp end if allocate(upf%rho_at(upf%mesh)) upf%rho_at (1:grid%mesh) = rhos (1:grid%mesh,1) ! allocate(upf%chi(upf%mesh,upf%nwfc)) upf%chi(1:grid%mesh,1:upf%nwfc) = phits(1:grid%mesh,1:upf%nwfc) ! allocate(upf%vloc(upf%mesh)) upf%vloc(1:grid%mesh) = vpsloc(1:grid%mesh) upf%lloc = lloc upf%rcloc = rcloc ! ! if (upf%has_so) CALL export_upf_so() if (upf%tpawp) CALL export_upf_paw() if (upf%has_gipaw) CALL export_upf_gipaw() upf%has_wfc = lsave_wfc if (upf%has_wfc) CALL export_upf_wfc() ! if (use_xsd) then CALL write_upf( FILENAME = TRIM(filename) , UPF=upf, SCHEMA = 'qe_pp', CONF = at_conf, U_INPUT = unit_loc) else CALL write_upf( FILENAME = TRIM(filename), UPF= upf, SCHEMA = 'v2', CONF = at_conf, U_INPUT = unit_loc) endif ! CALL deallocate_pseudo_upf( upf ) CALL deallocate_pseudo_config( at_conf ) RETURN CONTAINS SUBROUTINE export_upf_wfc ALLOCATE( upf%aewfc(upf%mesh, upf%nbeta), upf%pswfc(upf%mesh, upf%nbeta) ) upf%aewfc(1:upf%mesh,1:upf%nbeta) = psipaw(1:upf%mesh,1:upf%nbeta) upf%pswfc(1:upf%mesh,1:upf%nbeta) = phis(1:upf%mesh,1:upf%nbeta) END SUBROUTINE export_upf_wfc SUBROUTINE export_upf_so ALLOCATE( upf%nn(upf%nwfc), upf%jchi(upf%nwfc), upf%jjj(upf%nbeta) ) upf%els(1:upf%nwfc) = elts(1:upf%nwfc) upf%nn(1:upf%nwfc) = nnts(1:upf%nwfc) upf%lchi(1:upf%nwfc) = llts(1:upf%nwfc) upf%jchi(1:upf%nwfc) = jjts(1:upf%nwfc) ! upf%lll(1:upf%nbeta) = lls(1:upf%nbeta) upf%jjj(1:upf%nbeta) = jjs(1:upf%nbeta) END SUBROUTINE export_upf_so ! SUBROUTINE export_upf_paw INTEGER :: co,n !EMINE upf%paw_data_format = 2 ! upf%paw%core_energy = etot -etots upf%paw%lmax_aug = 2*upf%lmax upf%paw%augshape = which_augfun upf%paw%raug = rmatch_augfun upf%paw%iraug = pawsetup%irc allocate(upf%paw%ae_rho_atc(upf%mesh)) upf%paw%ae_rho_atc(1:upf%mesh) = pawsetup%aeccharge(1:upf%mesh)/fpi/grid%r2(1:grid%mesh) ! allocate(upf%paw%ae_vloc(upf%mesh)) upf%paw%ae_vloc(1:upf%mesh) = pawsetup%aeloc(1:upf%mesh) ! allocate(upf%paw%oc(upf%nbeta)) do nb = 1,upf%nbeta upf%paw%oc(nb) = max(pawsetup%oc(nb),0._dp) enddo ! allocate(upf%paw%augmom(upf%nbeta, upf%nbeta, 0:2*upf%lmax)) upf%paw%augmom(1:upf%nbeta,1:upf%nbeta,0:2*upf%lmax) & = pawsetup%augmom(1:upf%nbeta,1:upf%nbeta,0:2*upf%lmax) ! upf%kkbeta = max(upf%kkbeta, upf%paw%iraug) IF (upf%has_so) THEN ALLOCATE( upf%paw%aewfc_rel(upf%mesh, upf%nbeta) ) upf%paw%aewfc_rel(1:upf%mesh,1:upf%nbeta) = & pawsetup%aewfc_rel(1:upf%mesh,1:upf%nbeta) ENDIF ! !upf%paw%pfunc(:) = not used when writing, reconstructed from upf%aewfc !upf%paw%ptfunc(:) = not used when writing, reconstructed from upf%pswfc !=============================================================== !For PAW pseudopotentials, now we also include core information: !even when lgipaw_reconstruction = .false. !EMINE upf%gipaw_ncore_orbitals = COUNT(core_state(1:nwf)) co = upf%gipaw_ncore_orbitals ALLOCATE ( & upf%gipaw_core_orbital_n(co), & upf%gipaw_core_orbital_l(co), & upf%gipaw_core_orbital_el(co), & upf%gipaw_core_orbital(upf%mesh,co)) upf%gipaw_core_orbital_n(1:co) = nn(1:co) upf%gipaw_core_orbital_l(1:co) = ll(1:co) upf%gipaw_core_orbital_el(1:co) = el(1:co) DO n = 1,co upf%gipaw_core_orbital(1:upf%mesh,n) & = psi(1:upf%mesh,1,n) ENDDO !================================================================ RETURN END SUBROUTINE export_upf_paw SUBROUTINE export_upf_gipaw INTEGER :: co,nw,n,nb IF ( nconf /= 1 ) CALL errore ( "write_gipaw_orbitals", & "The (GI)PAW reconstruction requires one test configuration", abs(nconf) ) upf%gipaw_data_format = 2 ! The version of the format upf%gipaw_ncore_orbitals = COUNT(core_state(1:nwf)) co = upf%gipaw_ncore_orbitals upf%gipaw_wfs_nchannels = nwfts nw = upf%gipaw_wfs_nchannels IF (allocated(upf%gipaw_core_orbital_n)) DEALLOCATE(upf%gipaw_core_orbital_n) IF (allocated(upf%gipaw_core_orbital_l)) DEALLOCATE(upf%gipaw_core_orbital_l) IF (allocated(upf%gipaw_core_orbital_el)) DEALLOCATE(upf%gipaw_core_orbital_el) IF (allocated(upf%gipaw_core_orbital)) DEALLOCATE(upf%gipaw_core_orbital) IF (allocated(upf%gipaw_wfs_el)) DEALLOCATE(upf%gipaw_wfs_el) IF (allocated(upf%gipaw_wfs_ll)) DEALLOCATE(upf%gipaw_wfs_ll) IF (allocated(upf%gipaw_wfs_ll)) DEALLOCATE(upf%gipaw_wfs_ll) IF (allocated(upf%gipaw_wfs_rcut)) DEALLOCATE(upf%gipaw_wfs_rcut) IF (allocated(upf%gipaw_wfs_rcutus)) DEALLOCATE(upf%gipaw_wfs_rcutus) IF (allocated(upf%gipaw_wfs_ae)) DEALLOCATE(upf%gipaw_wfs_ae) IF (allocated(upf%gipaw_wfs_ps)) DEALLOCATE(upf%gipaw_wfs_ps) IF (allocated(upf%gipaw_vlocal_ae)) DEALLOCATE(upf%gipaw_vlocal_ae) IF (allocated(upf%gipaw_vlocal_ps)) DEALLOCATE(upf%gipaw_vlocal_ps) ALLOCATE ( & upf%gipaw_core_orbital_n(co), & upf%gipaw_core_orbital_l(co), & upf%gipaw_core_orbital_el(co), & upf%gipaw_core_orbital(upf%mesh,co), & upf%gipaw_wfs_el(nw), & upf%gipaw_wfs_ll(nw), & upf%gipaw_wfs_rcut(nw), & upf%gipaw_wfs_rcutus(nw), & upf%gipaw_wfs_ae(upf%mesh,nw), & upf%gipaw_wfs_ps(upf%mesh,nw), & upf%gipaw_vlocal_ae(upf%mesh), & upf%gipaw_vlocal_ps(upf%mesh) & ) upf%gipaw_core_orbital_n(1:co) = nn(1:co) upf%gipaw_core_orbital_l(1:co) = ll(1:co) upf%gipaw_core_orbital_el(1:co) = el(1:co) DO n = 1,co upf%gipaw_core_orbital(1:upf%mesh,n) & = psi(1:upf%mesh,1,n) ENDDO upf%gipaw_vlocal_ae(1:upf%mesh) & = grid%r(1:upf%mesh) * vpot(1:upf%mesh,1) upf%gipaw_vlocal_ps(1:upf%mesh) & = grid%r(1:upf%mesh) * vpstot(1:upf%mesh,1) upf%gipaw_wfs_el(1:nw) = elts(1:nw) upf%gipaw_wfs_ll(1:nw) = lltsc(1:nw,1) ! Find the suitable core radii to be written out !*apsi WARNING: DOES NOT WORK WITH VANDERBILT PP YET DO nb = 1,nw upf%gipaw_wfs_rcut(nb) = -1.0_dp DO n = 1, nwfs IF ( els(n) == eltsc(nb,1) ) THEN upf%gipaw_wfs_rcut(nb) = rcuttsc(nb,1) upf%gipaw_wfs_rcutus(nb) = rcutustsc(nb,1) END IF END DO ! IF ( upf%gipaw_wfs_rcut(nb) < 0.0_dp ) THEN DO n = 1, nwfs ! If there is one with the same l... IF ( lltsc(nb,1) == lls(n) ) THEN upf%gipaw_wfs_rcut(nb) = rcuttsc(nb,1) upf%gipaw_wfs_rcutus(nb) = rcutustsc(nb,1) END IF END DO END IF ENDDO DO n = 1,nw ! upf%gipaw_wfs_ae(1:upf%mesh,n) = wfc_ae_recon(1:upf%mesh,nstoaets(n)) ! upf%gipaw_wfs_ps(1:upf%mesh,n) = wfc_ps_recon(1:upf%mesh,n) ENDDO RETURN END SUBROUTINE export_upf_gipaw ! END SUBROUTINE export_upf
gpl-2.0
QEF/q-e_schrodinger
CPV/src/print_out.f90
2
24425
! ! Copyright (C) 2002-2011 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !=----------------------------------------------------------------------------=! SUBROUTINE printout_new_x & ( nfi, tfirst, tfilei, tprint, tps, h, stress, tau0, vels, & fion, ekinc, temphc, tempp, temps, etot, enthal, econs, econt, & vnhh, xnhh0, vnhp, xnhp0, vnhe, xnhe0, atot, ekin, epot, print_forces, print_stress, & tstdout) !=----------------------------------------------------------------------------=! ! USE kinds, ONLY : DP USE control_flags, ONLY : iprint, textfor, do_makov_payne, conv_elec USE energies, ONLY : print_energies, dft_energy_type USE printout_base, ONLY : printout_base_open, printout_base_close, & printout_pos, printout_cell, printout_stress, & printout_vefftsvdw, printout_wfc, & save_print_counter USE constants, ONLY : au_gpa, bohr_radius_cm, amu_au, & BOHR_RADIUS_ANGS, pi USE ions_base, ONLY : na, nsp, nat, ityp, atm, amass, cdmi, & ions_cofmass, ions_displacement USE cell_base, ONLY : s_to_r, get_volume, ainv USE efield_module, ONLY : tefield, pberryel, pberryion, & tefield2, pberryel2, pberryion2 USE cg_module, ONLY : tcg, itercg USE sic_module, ONLY : self_interaction, sic_alpha, sic_epsilon USE electrons_module, ONLY : print_eigenvalues USE pres_ai_mod, ONLY : P_ext, Surf_t, volclu, surfclu, abivol, & abisur, pvar, n_ele USE cp_main_variables, ONLY : nprint_nfi, iprint_stdout USE control_flags, ONLY : ndw USE io_global, ONLY : ionode, ionode_id, stdout USE control_flags, ONLY : lwf, lwfpbe0nscf ! exx_wf related USE energies, ONLY : exx ! exx_wf related USE control_flags, ONLY : ts_vdw USE tsvdw_module, ONLY : EtsvdW, VefftsvdW USE input_parameters, ONLY : tcpbo USE exx_module, ONLY : exxalfa USE xc_lib, ONLY : xclib_dft_is, exx_is_active USE wannier_module, ONLY : wfc USE electrons_base, ONLY : nbsp, nspin, nupdwn, iupdwn USE clib_wrappers, ONLY : memstat ! IMPLICIT NONE ! INTEGER, INTENT(IN) :: nfi LOGICAL, INTENT(IN) :: tfirst, tfilei, tprint REAL(DP), INTENT(IN) :: tps REAL(DP), INTENT(IN) :: h( 3, 3 ) REAL(DP), INTENT(IN) :: stress( 3, 3 ) REAL(DP), INTENT(IN) :: tau0( :, : ) ! real positions REAL(DP), INTENT(IN) :: vels( :, : ) ! scaled velocities REAL(DP), INTENT(IN) :: fion( :, : ) ! real forces REAL(DP), INTENT(IN) :: ekinc, temphc, tempp, etot, enthal, econs, econt REAL(DP), INTENT(IN) :: temps( : ) ! partial temperature for different ionic species REAL(DP), INTENT(IN) :: vnhh( 3, 3 ), xnhh0( 3, 3 ), vnhp( 1 ), xnhp0( 1 ), vnhe, xnhe0 REAL(DP), INTENT(IN) :: atot! enthalpy of system for c.g. case REAL(DP), INTENT(IN) :: ekin REAL(DP), INTENT(IN) :: epot ! ( epseu + eht + exc ) LOGICAL, INTENT(IN) :: print_forces, print_stress, tstdout ! REAL(DP) :: stress_gpa( 3, 3 ) REAL(DP) :: cdm0( 3 ) REAL(DP) :: dis( SIZE(na) ) REAL(DP) :: out_press, volume REAL(DP) :: totalmass INTEGER :: isa, is, ia, kilobytes REAL(DP), ALLOCATABLE :: tauw(:, :), wfc_temp(:,:) LOGICAL :: tsic, tfile LOGICAL, PARAMETER :: nice_output_files=.false. ! ! avoid double printing to files by refering to nprint_nfi ! tfile = tfilei .and. ( nfi .gt. nprint_nfi ) ! CALL memstat( kilobytes ) ! IF( ionode .AND. tfile .AND. tprint ) THEN CALL printout_base_open() END IF ! IF( tprint ) THEN IF ( tfile ) THEN ! we're writing files, let's save nfi CALL save_print_counter( nfi, ndw ) ELSE IF ( tfilei ) then ! not there yet, save the old nprint_nfi CALL save_print_counter( nprint_nfi, ndw ) END IF END IF ! volume = get_volume( h ) ! stress_gpa = stress * au_gpa ! out_press = ( stress_gpa(1,1) + stress_gpa(2,2) + stress_gpa(3,3) ) / 3.0d0 ! IF( nfi > 0 ) THEN CALL update_accomulators & ( ekinc, ekin, epot, etot, tempp, enthal, econs, out_press, volume ) END IF ! ! Makov-Payne correction to the total energy (isolated systems only) ! IF( do_makov_payne .AND. tprint ) CALL makov_payne( etot ) ! IF( ionode ) THEN ! IF( tprint ) THEN ! tsic = ( self_interaction /= 0 ) ! IF(tstdout) & CALL print_energies( tsic, sic_alpha = sic_alpha, sic_epsilon = sic_epsilon, textfor = textfor ) ! CALL print_eigenvalues( 31, tfile, tstdout, nfi, tps ) ! IF(tstdout) WRITE( stdout, * ) IF( kilobytes > 0 .AND. tstdout ) & WRITE( stdout, fmt="(3X,'Allocated memory (kb) = ', I9 )" ) kilobytes IF(tstdout) WRITE( stdout, * ) ! IF( tstdout ) CALL printout_cell( stdout, h ) ! IF( tfile ) CALL printout_cell( 36, h, nfi, tps ) ! ! System density: ! totalmass = 0.0d0 DO is = 1, nsp totalmass = totalmass + amass(is) * na(is) END DO totalmass = totalmass / volume * 11.2061d0 ! AMU_SI * 1000.0 / BOHR_RADIUS_CM**3 IF(tstdout) & WRITE( stdout, fmt='(/,3X,"System Density [g/cm^3] : ",F25.10,/)' ) totalmass IF(tstdout) & WRITE( stdout, fmt='(/,3X,"System Volume [A.U.^3] : ",F25.10,/)' ) volume ! BS ! ! Compute Center of mass displacement since the initialization of step counter ! CALL ions_cofmass( tau0, amass, nat, ityp, cdm0 ) ! IF(tstdout) & WRITE( stdout,1000) SUM( ( cdm0(:)-cdmi(:) )**2 ) ! CALL ions_displacement( dis, tau0, nsp, nat, ityp ) ! IF( print_stress ) THEN ! IF(tstdout) & CALL printout_stress( stdout, stress_gpa ) ! IF( tfile ) CALL printout_stress( 38, stress_gpa, nfi, tps ) ! END IF ! ! ... write out a standard XYZ file in angstroms ! IF(tstdout) & CALL printout_pos( stdout, tau0, nat, ityp, what = 'pos', label = atm ) ! IF( tfile ) then if (.not.nice_output_files) then CALL printout_pos( 35, tau0, nat, ityp, nfi = nfi, tps = tps ) else CALL printout_pos( 35, tau0, nat, ityp, what = 'xyz', & nfi = nfi, tps = tps, label = atm, & fact= BOHR_RADIUS_ANGS ) endif END IF ! ALLOCATE( tauw( 3, nat ) ) ! DO ia = 1, nat ! CALL s_to_r( vels(:,ia), tauw(:,ia), h ) ! END DO ! IF(tstdout) WRITE( stdout, * ) ! IF(tstdout) & CALL printout_pos( stdout, tauw, nat, ityp, & what = 'vel', label = atm ) ! IF( tfile ) then if (.not.nice_output_files) then CALL printout_pos( 34, tauw, nat, ityp, nfi = nfi, tps = tps ) else CALL printout_pos( 34, tauw, nat, ityp, nfi = nfi, tps = tps, & what = 'vel', label = atm ) endif END IF ! IF( print_forces ) THEN ! IF(tstdout) WRITE( stdout, * ) ! IF(tstdout) & CALL printout_pos( stdout, fion, nat, ityp, & what = 'for', label = atm ) ! IF( tfile ) then if (.not.nice_output_files) then CALL printout_pos( 37, fion, nat, ityp, nfi = nfi, tps = tps ) else CALL printout_pos( 37, fion, nat, ityp, nfi = nfi, tps = tps, & what = 'for', label = atm ) endif END IF ! END IF ! DEALLOCATE( tauw ) ! ! ... Write partial temperature and MSD for each atomic specie tu stdout ! IF(tstdout) WRITE( stdout, * ) IF(tstdout) WRITE( stdout, 1944 ) ! DO is = 1, nsp IF( tstdout ) WRITE( stdout, 1945 ) is, temps(is), dis(is) END DO ! IF( tfile ) THEN ! IF(tcpbo) THEN ! WRITE( 33, 29484 ) nfi,tps,tempp,etot,enthal,econs,econt,(-exx*exxalfa),EtsvdW ! BS: different printing options need to be added .. ! ELSE ! IF((nfi/iprint).EQ.1) WRITE( 33, 29471 ) ! IF(xclib_dft_is('hybrid').AND.exx_is_active().AND.ts_vdw) THEN WRITE( 33, 29481 ) nfi,tps,ekinc,temphc,tempp,etot,enthal, & econs,econt,volume,out_press,(-exx*exxalfa),EtsvdW ELSEIF(ts_vdw) THEN WRITE( 33, 29482 ) nfi,tps,ekinc,temphc,tempp,etot,enthal, & econs,econt,volume,out_press,EtsvdW ELSEIF(xclib_dft_is('hybrid').AND.exx_is_active()) THEN WRITE( 33, 29482 ) nfi,tps,ekinc,temphc,tempp,etot,enthal, & econs,econt,volume,out_press,(-exx*exxalfa) ELSE #if defined(__OLD_FORMAT) WRITE( 33, '(I6,1X,F8.5,1X,F6.1,1X,F6.1,4(1X,F14.5),F10.2, F8.2, F8.5)') & nfi,ekinc,temphc,tempp,etot,enthal, & econs,econt,volume,out_press,tps #else WRITE( 33, 29483 ) nfi,tps,ekinc,temphc,tempp,etot,enthal, & econs,econt,volume,out_press #endif END IF ! END IF ! END IF ! IF( tfile ) WRITE( 39, 2949 ) nfi,tps,vnhh(3,3),xnhh0(3,3),vnhp(1),xnhp0(1), vnhe, xnhe0 ! !print Wannier centers at every iprint steps in .wfc file ! IF(tfile.AND.lwf) THEN ! IF (.NOT.tcpbo) THEN ! ALLOCATE( wfc_temp(3,nbsp) ); wfc_temp=0.0_DP ! wfc_temp(:,:) = MATMUL( ainv(:,:), wfc(:,:) ) ! wfc_temp(:,:) = wfc_temp(:,:) - FLOOR (wfc_temp(:,:)) ! wfc_temp(:,:) = MATMUL( h(:,:), wfc_temp(:,:) ) ! CALL printout_wfc( 42, wfc_temp(:,1:nupdwn(1)), nupdwn(1), nfi, tps, 1) IF(nspin.EQ.2)CALL printout_wfc( 42, wfc_temp(:,iupdwn(2):nbsp), nupdwn(2), nfi, tps, nspin ) ! DEALLOCATE( wfc_temp ) ! ELSE ! IF (conv_elec) THEN ! ALLOCATE( wfc_temp(3,nbsp) ); wfc_temp=0.0_DP ! wfc_temp(:,:) = MATMUL( ainv(:,:), wfc(:,:) ) ! wfc_temp(:,:) = wfc_temp(:,:) - FLOOR (wfc_temp(:,:)) ! wfc_temp(:,:) = MATMUL( h(:,:), wfc_temp(:,:) ) ! CALL printout_wfc( 42, wfc_temp(:,1:nupdwn(1)), nupdwn(1), nfi, tps, 1) IF(nspin.EQ.2)CALL printout_wfc( 42, wfc_temp(:,iupdwn(2):nbsp), nupdwn(2), nfi, tps, nspin ) ! DEALLOCATE( wfc_temp ) ! END IF ! END IF ! END IF ! !print TS-vdW effective Hirshfeld volume of each atom at every iprint steps in .hrs file ! IF(tfile.AND.ts_vdw) THEN ! IF (.NOT.tcpbo) THEN ! CALL printout_vefftsvdw( 43, VefftsvdW, nat, nfi, tps ) ! ELSE ! IF (conv_elec) CALL printout_vefftsvdw( 43, VefftsvdW, nat, nfi, tps ) ! END IF ! END IF ! END IF !tprint ! END IF !ionode ! IF( ionode .AND. tfile .AND. tprint ) THEN ! ! ... Close and flush unit 30, ... 40 ! CALL printout_base_close() ! END IF ! IF( ( MOD( nfi, iprint_stdout ) == 0 ) .OR. tfirst ) THEN ! WRITE( stdout, * ) !====================================================== !printing with better format IF(xclib_dft_is('hybrid').AND.exx_is_active()) THEN IF(ts_vdw)THEN IF(tcpbo) THEN WRITE( stdout, 19473 ) ELSE WRITE( stdout, 19472 ) END IF ELSE WRITE( stdout, 19470 ) END IF ELSE IF(ts_vdw)THEN WRITE( stdout, 19471 ) ELSE WRITE( stdout, 1947 ) END IF END IF !====================================================== ! IF ( abivol .AND. pvar ) write(stdout,*) 'P = ', P_ext*au_gpa ! END IF ! if (abivol) then write(stdout,*) nfi, 'ab-initio volume = ', volclu, ' a.u.^3' write(stdout,*) nfi, 'PV = ', P_ext*volclu, ' ha' end if if (abisur) then write(stdout,*) nfi, 'ab-initio surface = ', surfclu, ' a.u.^2' if (abivol) write(stdout,*) nfi, 'spherical surface = ', & 4.d0*pi*(0.75d0*volclu/pi)**(2.d0/3.d0), ' a.u.^2' write(stdout,*) nfi, 't*S = ', Surf_t*surfclu, ' ha' end if if (abivol.or.abisur) write(stdout,*) nfi, & ' # of electrons within the isosurface = ', n_ele IF( .not. tcg ) THEN ! IF(xclib_dft_is('hybrid').AND.exx_is_active()) THEN ! IF (ts_vdw) THEN ! IF(tcpbo) THEN ! WRITE(stdout,19483) nfi,tempp,etot,enthal,econs,econt,-exx*exxalfa,EtsvdW ! ELSE ! WRITE(stdout,19482) nfi,ekinc,temphc,tempp,-exx*exxalfa,etot,enthal,econs, & econt,vnhh(3,3),xnhh0(3,3),vnhp(1),xnhp0(1),EtsvdW ! END IF ! ELSE ! WRITE(stdout, 19480)nfi,ekinc,temphc,tempp,-exx*exxalfa,etot,enthal,econs, & econt,vnhh(3,3),xnhh0(3,3),vnhp(1),xnhp0(1) ! END IF ! ELSE IF (ts_vdw) THEN ! WRITE(stdout,19481) nfi,ekinc,temphc,tempp,etot,enthal,econs, & econt,vnhh(3,3),xnhh0(3,3),vnhp(1),xnhp0(1),EtsvdW ! ELSE ! WRITE(stdout, 1948) nfi, ekinc, temphc, tempp, etot, enthal, & econs, econt, vnhh(3,3), xnhh0(3,3), vnhp(1), xnhp0(1) ! END IF END IF ! ELSE IF ( MOD( nfi, iprint ) == 0 .OR. tfirst ) THEN ! WRITE( stdout, * ) WRITE( stdout, 255 ) 'nfi','tempp','E','-T.S-mu.nbsp','+K_p','#Iter' ! END IF ! WRITE( stdout, 256 ) nfi, INT( tempp ), etot, atot, econs, itercg ! END IF IF( tefield) THEN IF(ionode) write(stdout,'( A14,F12.6,2X,A14,F12.6)') 'Elct. dipole 1',-pberryel,'Ionic dipole 1',-pberryion ENDIF IF( tefield2) THEN IF(ionode) write(stdout,'( A14,F12.6,2X,A14,F12.6)') 'Elct. dipole 2',-pberryel2,'Ionic dipole 2',-pberryion2 ENDIF ! ! 255 FORMAT( ' ',A5,A8,3(1X,A12),A6 ) 256 FORMAT( 'Step ',I5,1X,I7,1X,F13.6,1X,F13.6,1X,F13.6,1X,I5 ) 1000 FORMAT(/,3X,'Center of mass square displacement (a.u.): ',F10.6,/) 1944 FORMAT(//' Partial temperatures (for each ionic specie) ', & /,' Species Temp (K) Mean Square Displacement (a.u.)') 1945 FORMAT(3X,I6,1X,ES10.2,1X,ES14.4) 1947 FORMAT( 2X,'nfi',5X,'ekinc',14X,'temph',2X,'tempp',5X,'etot',17X,'enthal', & & 15X,'econs',16X,'econt',14X,'vnhh',4X,'xnhh0',3X,'vnhp',4X,'xnhp0') ! GGA 19470 FORMAT(2X,'nfi',5X,'ekinc',14X,'temph',2X,'tempp',10X,'exx',15X,'etot',15X,'enthal', & & 15X,'econs',16X,'econt',12X,'vnhh',4X,'xnhh0',3X,'vnhp',4X,'xnhp0') ! PBE0 19471 FORMAT(2X,'nfi',5X,'ekinc',14X,'temph',2X,'tempp',5X,'etot',17X,'enthal', & & 15X,'econs',16X,'econt',16X,'vnhh',4X,'xnhh0',4X,'vnhp',4X,'xnhp0',8X,'evdw') ! GGA+vdW 19472 FORMAT(2X,'nfi',5X,'ekinc',14X,'temph',2X,'tempp',10X,'exx',15X,'etot',15X,'enthal', & & 15X,'econs',16X,'econt',16X,'vnhh',4X,'xnhh0',4X,'vnhp',4X,'xnhp0',8X,'evdw') ! PBE0+vdW 19473 FORMAT(2X,'nfi',8X,'tempp',15X,'etot',15X,'enthal',15X,'econs', & & 15X,'econt',15X,'exx',15X,'evdw') 1948 FORMAT( I7,1X,F20.15,1X,F6.1,1X,F7.2,4(1X,F20.12),4(1X,F8.4) ) ! GGA 19480 FORMAT( I7,1X,F20.15,1X,F6.1,1X,F7.2,5(1X,F20.12),4(1X,F8.4) ) ! PBE0 19481 FORMAT( I7,1X,F20.15,1X,F6.1,1X,F7.2,4(1X,F20.12),4(1X,F8.4),1X,F20.12 ) ! GGA+vdW 19482 FORMAT( I7,1X,F20.15,1X,F6.1,1X,F7.2,5(1X,F20.12),4(1X,F8.4),1X,F20.12 ) ! PBE0+vdW 19483 FORMAT( I7,1X,F10.5,6(1X,F18.10) ) 29471 FORMAT( '#',3X,'nfi',4X,'time(ps)',8X,'ekinc',8X,'T_cell(K)',5X,'Tion(K)',10X,'etot',15X,'enthal',15X,'econs', & & 15X,'econt',10X,'Volume',8X,'Pressure(GPa)',8X,'EXX',15X,'EVDW' ) 29481 FORMAT( I7,4(1X,ES13.6),4(2X,F18.8),1X,ES13.6,2X,F12.5,2(2X,F15.8) ) 29482 FORMAT( I7,4(1X,ES13.6),4(2X,F18.8),1X,ES13.6,2X,F12.5,2X,F15.8 ) 29483 FORMAT( I7,4(1X,ES13.6),4(2X,F18.8),1X,ES13.6,2X,F12.5 ) 29484 FORMAT( I7,2(1X,ES13.6),6(2X,F18.8) ) 2949 FORMAT( I7,1X,ES13.6,6(1X,F15.8) ) ! RETURN END SUBROUTINE printout_new_x ! ! !=----------------------------------------------------------------------------=! SUBROUTINE print_legend() !=----------------------------------------------------------------------------=! ! USE io_global, ONLY : ionode, stdout ! IMPLICIT NONE ! IF ( .NOT. ionode ) RETURN ! WRITE( stdout, *) WRITE( stdout, *) ' Short Legend and Physical Units in the Output' WRITE( stdout, *) ' ---------------------------------------------' WRITE( stdout, *) ' NFI [int] - step index' WRITE( stdout, *) ' EKINC [HARTREE A.U.] - kinetic energy of the fictitious electronic dynamics' WRITE( stdout, *) ' TEMPH [K] - Temperature of the fictitious cell dynamics' WRITE( stdout, *) ' TEMP [K] - Ionic temperature' WRITE( stdout, *) ' ETOT [HARTREE A.U.] - Scf total energy (Kohn-Sham hamiltonian)' WRITE( stdout, *) ' ENTHAL [HARTREE A.U.] - Enthalpy ( ETOT + P * V )' WRITE( stdout, *) ' ECONS [HARTREE A.U.] - Enthalpy + kinetic energy of ions and cell' WRITE( stdout, *) ' ECONT [HARTREE A.U.] - Constant of motion for the CP lagrangian' WRITE( stdout, *) ! RETURN ! END SUBROUTINE print_legend !=----------------------------------------------------------------------------=! SUBROUTINE printacc( ) !=----------------------------------------------------------------------------=! USE kinds, ONLY : DP USE cp_main_variables, ONLY : acc, acc_this_run, nfi, nfi_run USE io_global, ONLY : ionode, stdout IMPLICIT NONE ! REAL(DP) :: avgs(9) REAL(DP) :: avgs_run(9) avgs = 0.0d0 avgs_run = 0.0d0 ! IF ( nfi > 0 ) THEN avgs = acc( 1:9 ) / DBLE( nfi ) END IF ! IF ( nfi_run > 0 ) THEN avgs_run = acc_this_run(1:9) / DBLE( nfi_run ) END IF IF( ionode ) THEN WRITE( stdout,1949) WRITE( stdout,1951) avgs(1), avgs_run(1) WRITE( stdout,1952) avgs(2), avgs_run(2) WRITE( stdout,1953) avgs(3), avgs_run(3) WRITE( stdout,1954) avgs(4), avgs_run(4) WRITE( stdout,1955) avgs(5), avgs_run(5) WRITE( stdout,1956) avgs(6), avgs_run(6) WRITE( stdout,1957) avgs(7), avgs_run(7) WRITE( stdout,1958) avgs(8), avgs_run(8) WRITE( stdout,1959) avgs(9), avgs_run(9) WRITE( stdout,1990) 1949 FORMAT(//,3X,'Averaged Physical Quantities',/ & ,3X,' ',' accumulated',' this run') 1951 FORMAT(3X,'ekinc : ',F14.5,F14.5,' (AU)') 1952 FORMAT(3X,'ekin : ',F14.5,F14.5,' (AU)') 1953 FORMAT(3X,'epot : ',F14.5,F14.5,' (AU)') 1954 FORMAT(3X,'total energy : ',F14.5,F14.5,' (AU)') 1955 FORMAT(3X,'temperature : ',F14.5,F14.5,' (K )') 1956 FORMAT(3X,'enthalpy : ',F14.5,F14.5,' (AU)') 1957 FORMAT(3X,'econs : ',F14.5,F14.5,' (AU)') 1958 FORMAT(3X,'pressure : ',F14.5,F14.5,' (Gpa)') 1959 FORMAT(3X,'volume : ',F14.5,F14.5,' (AU)') 1990 FORMAT(/) END IF RETURN END SUBROUTINE printacc !=----------------------------------------------------------------------------=! SUBROUTINE open_and_append_x( iunit, file_name ) !=----------------------------------------------------------------------------=! USE io_global, ONLY: ionode IMPLICIT NONE INTEGER, INTENT(IN) :: iunit CHARACTER(LEN = *), INTENT(IN) :: file_name INTEGER :: ierr IF( ionode ) THEN OPEN( UNIT = iunit, FILE = trim( file_name ), & STATUS = 'unknown', POSITION = 'append', IOSTAT = ierr) IF( ierr /= 0 ) & CALL errore( ' open_and_append ', ' opening file '//trim(file_name), 1 ) END IF RETURN END SUBROUTINE open_and_append_x !=----------------------------------------------------------------------------=! SUBROUTINE update_accomulators & ( ekinc, ekin, epot, etot, tempp, enthal, econs, press, volume ) !=----------------------------------------------------------------------------=! USE kinds, ONLY : DP USE cp_main_variables, ONLY : acc, acc_this_run, nfi_run IMPLICIT NONE REAL(DP), INTENT(IN) :: ekinc, ekin, epot, etot, tempp REAL(DP), INTENT(IN) :: enthal, econs, press, volume nfi_run = nfi_run + 1 ! ... sum up values to be averaged acc(1) = acc(1) + ekinc acc(2) = acc(2) + ekin acc(3) = acc(3) + epot acc(4) = acc(4) + etot acc(5) = acc(5) + tempp acc(6) = acc(6) + enthal acc(7) = acc(7) + econs acc(8) = acc(8) + press ! pressure in GPa acc(9) = acc(9) + volume ! ... sum up values to be averaged acc_this_run(1) = acc_this_run(1) + ekinc acc_this_run(2) = acc_this_run(2) + ekin acc_this_run(3) = acc_this_run(3) + epot acc_this_run(4) = acc_this_run(4) + etot acc_this_run(5) = acc_this_run(5) + tempp acc_this_run(6) = acc_this_run(6) + enthal acc_this_run(7) = acc_this_run(7) + econs acc_this_run(8) = acc_this_run(8) + press ! pressure in GPa acc_this_run(9) = acc_this_run(9) + volume RETURN END SUBROUTINE
gpl-2.0
piyush0609/scipy
scipy/integrate/quadpack/dqk51.f
145
9707
subroutine dqk51(f,a,b,result,abserr,resabs,resasc) c***begin prologue dqk51 c***date written 800101 (yymmdd) c***revision date 830518 (yymmdd) c***category no. h2a1a2 c***keywords 51-point gauss-kronrod rules c***author piessens,robert,appl. math. & progr. div. - k.u.leuven c de doncker,elise,appl. math & progr. div. - k.u.leuven c***purpose to compute i = integral of f over (a,b) with error c estimate c j = integral of abs(f) over (a,b) c***description c c integration rules c standard fortran subroutine c double precision version c c parameters c on entry c f - double precision c function subroutine defining the integrand c function f(x). the actual name for f needs to be c declared e x t e r n a l in the calling program. c c a - double precision c lower limit of integration c c b - double precision c upper limit of integration c c on return c result - double precision c approximation to the integral i c result is computed by applying the 51-point c kronrod rule (resk) obtained by optimal addition c of abscissae to the 25-point gauss rule (resg). c c abserr - double precision c estimate of the modulus of the absolute error, c which should not exceed abs(i-result) c c resabs - double precision c approximation to the integral j c c resasc - double precision c approximation to the integral of abs(f-i/(b-a)) c over (a,b) c c***references (none) c***routines called d1mach c***end prologue dqk51 c double precision a,absc,abserr,b,centr,dabs,dhlgth,dmax1,dmin1, * d1mach,epmach,f,fc,fsum,fval1,fval2,fv1,fv2,hlgth,resabs,resasc, * resg,resk,reskh,result,uflow,wg,wgk,xgk integer j,jtw,jtwm1 external f c dimension fv1(25),fv2(25),xgk(26),wgk(26),wg(13) c c the abscissae and weights are given for the interval (-1,1). c because of symmetry only the positive abscissae and their c corresponding weights are given. c c xgk - abscissae of the 51-point kronrod rule c xgk(2), xgk(4), ... abscissae of the 25-point c gauss rule c xgk(1), xgk(3), ... abscissae which are optimally c added to the 25-point gauss rule c c wgk - weights of the 51-point kronrod rule c c wg - weights of the 25-point gauss rule c c c gauss quadrature weights and kronron quadrature abscissae and weights c as evaluated with 80 decimal digit arithmetic by l. w. fullerton, c bell labs, nov. 1981. c data wg ( 1) / 0.0113937985 0102628794 7902964113 235 d0 / data wg ( 2) / 0.0263549866 1503213726 1901815295 299 d0 / data wg ( 3) / 0.0409391567 0130631265 5623487711 646 d0 / data wg ( 4) / 0.0549046959 7583519192 5936891540 473 d0 / data wg ( 5) / 0.0680383338 1235691720 7187185656 708 d0 / data wg ( 6) / 0.0801407003 3500101801 3234959669 111 d0 / data wg ( 7) / 0.0910282619 8296364981 1497220702 892 d0 / data wg ( 8) / 0.1005359490 6705064420 2206890392 686 d0 / data wg ( 9) / 0.1085196244 7426365311 6093957050 117 d0 / data wg ( 10) / 0.1148582591 4571164833 9325545869 556 d0 / data wg ( 11) / 0.1194557635 3578477222 8178126512 901 d0 / data wg ( 12) / 0.1222424429 9031004168 8959518945 852 d0 / data wg ( 13) / 0.1231760537 2671545120 3902873079 050 d0 / c data xgk ( 1) / 0.9992621049 9260983419 3457486540 341 d0 / data xgk ( 2) / 0.9955569697 9049809790 8784946893 902 d0 / data xgk ( 3) / 0.9880357945 3407724763 7331014577 406 d0 / data xgk ( 4) / 0.9766639214 5951751149 8315386479 594 d0 / data xgk ( 5) / 0.9616149864 2584251241 8130033660 167 d0 / data xgk ( 6) / 0.9429745712 2897433941 4011169658 471 d0 / data xgk ( 7) / 0.9207471152 8170156174 6346084546 331 d0 / data xgk ( 8) / 0.8949919978 7827536885 1042006782 805 d0 / data xgk ( 9) / 0.8658470652 9327559544 8996969588 340 d0 / data xgk ( 10) / 0.8334426287 6083400142 1021108693 570 d0 / data xgk ( 11) / 0.7978737979 9850005941 0410904994 307 d0 / data xgk ( 12) / 0.7592592630 3735763057 7282865204 361 d0 / data xgk ( 13) / 0.7177664068 1308438818 6654079773 298 d0 / data xgk ( 14) / 0.6735663684 7346836448 5120633247 622 d0 / data xgk ( 15) / 0.6268100990 1031741278 8122681624 518 d0 / data xgk ( 16) / 0.5776629302 4122296772 3689841612 654 d0 / data xgk ( 17) / 0.5263252843 3471918259 9623778158 010 d0 / data xgk ( 18) / 0.4730027314 4571496052 2182115009 192 d0 / data xgk ( 19) / 0.4178853821 9303774885 1814394594 572 d0 / data xgk ( 20) / 0.3611723058 0938783773 5821730127 641 d0 / data xgk ( 21) / 0.3030895389 3110783016 7478909980 339 d0 / data xgk ( 22) / 0.2438668837 2098843204 5190362797 452 d0 / data xgk ( 23) / 0.1837189394 2104889201 5969888759 528 d0 / data xgk ( 24) / 0.1228646926 1071039638 7359818808 037 d0 / data xgk ( 25) / 0.0615444830 0568507888 6546392366 797 d0 / data xgk ( 26) / 0.0000000000 0000000000 0000000000 000 d0 / c data wgk ( 1) / 0.0019873838 9233031592 6507851882 843 d0 / data wgk ( 2) / 0.0055619321 3535671375 8040236901 066 d0 / data wgk ( 3) / 0.0094739733 8617415160 7207710523 655 d0 / data wgk ( 4) / 0.0132362291 9557167481 3656405846 976 d0 / data wgk ( 5) / 0.0168478177 0912829823 1516667536 336 d0 / data wgk ( 6) / 0.0204353711 4588283545 6568292235 939 d0 / data wgk ( 7) / 0.0240099456 0695321622 0092489164 881 d0 / data wgk ( 8) / 0.0274753175 8785173780 2948455517 811 d0 / data wgk ( 9) / 0.0307923001 6738748889 1109020215 229 d0 / data wgk ( 10) / 0.0340021302 7432933783 6748795229 551 d0 / data wgk ( 11) / 0.0371162714 8341554356 0330625367 620 d0 / data wgk ( 12) / 0.0400838255 0403238207 4839284467 076 d0 / data wgk ( 13) / 0.0428728450 2017004947 6895792439 495 d0 / data wgk ( 14) / 0.0455029130 4992178890 9870584752 660 d0 / data wgk ( 15) / 0.0479825371 3883671390 6392255756 915 d0 / data wgk ( 16) / 0.0502776790 8071567196 3325259433 440 d0 / data wgk ( 17) / 0.0523628858 0640747586 4366712137 873 d0 / data wgk ( 18) / 0.0542511298 8854549014 4543370459 876 d0 / data wgk ( 19) / 0.0559508112 2041231730 8240686382 747 d0 / data wgk ( 20) / 0.0574371163 6156783285 3582693939 506 d0 / data wgk ( 21) / 0.0586896800 2239420796 1974175856 788 d0 / data wgk ( 22) / 0.0597203403 2417405997 9099291932 562 d0 / data wgk ( 23) / 0.0605394553 7604586294 5360267517 565 d0 / data wgk ( 24) / 0.0611285097 1705304830 5859030416 293 d0 / data wgk ( 25) / 0.0614711898 7142531666 1544131965 264 d0 / c note: wgk (26) was calculated from the values of wgk(1..25) data wgk ( 26) / 0.0615808180 6783293507 8759824240 066 d0 / c c c list of major variables c ----------------------- c c centr - mid point of the interval c hlgth - half-length of the interval c absc - abscissa c fval* - function value c resg - result of the 25-point gauss formula c resk - result of the 51-point kronrod formula c reskh - approximation to the mean value of f over (a,b), c i.e. to i/(b-a) c c machine dependent constants c --------------------------- c c epmach is the largest relative spacing. c uflow is the smallest positive magnitude. c c***first executable statement dqk51 epmach = d1mach(4) uflow = d1mach(1) c centr = 0.5d+00*(a+b) hlgth = 0.5d+00*(b-a) dhlgth = dabs(hlgth) c c compute the 51-point kronrod approximation to c the integral, and estimate the absolute error. c fc = f(centr) resg = wg(13)*fc resk = wgk(26)*fc resabs = dabs(resk) do 10 j=1,12 jtw = j*2 absc = hlgth*xgk(jtw) fval1 = f(centr-absc) fval2 = f(centr+absc) fv1(jtw) = fval1 fv2(jtw) = fval2 fsum = fval1+fval2 resg = resg+wg(j)*fsum resk = resk+wgk(jtw)*fsum resabs = resabs+wgk(jtw)*(dabs(fval1)+dabs(fval2)) 10 continue do 15 j = 1,13 jtwm1 = j*2-1 absc = hlgth*xgk(jtwm1) fval1 = f(centr-absc) fval2 = f(centr+absc) fv1(jtwm1) = fval1 fv2(jtwm1) = fval2 fsum = fval1+fval2 resk = resk+wgk(jtwm1)*fsum resabs = resabs+wgk(jtwm1)*(dabs(fval1)+dabs(fval2)) 15 continue reskh = resk*0.5d+00 resasc = wgk(26)*dabs(fc-reskh) do 20 j=1,25 resasc = resasc+wgk(j)*(dabs(fv1(j)-reskh)+dabs(fv2(j)-reskh)) 20 continue result = resk*hlgth resabs = resabs*dhlgth resasc = resasc*dhlgth abserr = dabs((resk-resg)*hlgth) if(resasc.ne.0.0d+00.and.abserr.ne.0.0d+00) * abserr = resasc*dmin1(0.1d+01,(0.2d+03*abserr/resasc)**1.5d+00) if(resabs.gt.uflow/(0.5d+02*epmach)) abserr = dmax1 * ((epmach*0.5d+02)*resabs,abserr) return end
bsd-3-clause
davidandrewnew/uclales
src/rfft.f90
1
29802
! !--------------------------------------------------------------------- ! SUBROUTINE FFT2DC: This routine computes the two dimensional ! transform of a complex cubic array of square N and length NZ. ! FFT's are done for each square level for k=2->NZ inclusive. The ! first level is used as a scratch array for storing the transpose ! matrix for the second half of the transform. The code uses ! Swartztrauber's fft routines. ISGN=1 implies the backward ! transform otherwise the forward transform is carried out, ! normalization is done only on the backward transform ! SUBROUTINE FFT2DC_ALT(N,NZ,A,WSAVE,ISGN) ! ! In this alternate method we leave A in the transposed array space ! IMPLICIT NONE INTEGER N,NZ,ISGN,I,J,K REAL WSAVE(4*N+15),FACT COMPLEX A(N,N,NZ) IF(ISGN.NE.1)THEN CALL CFFTI(N,WSAVE) DO K=2,NZ DO J=1,N CALL CFFTF(N,A(1,J,K),WSAVE) ENDDO DO I=1,N-1 DO J=I+1,N A(I,J,1)=A(J,I,K) !transpose A(J,I,K)=A(I,J,K) A(I,J,K)=A(I,J,1) ENDDO ENDDO DO I=1,N CALL CFFTF(N,A(1,I,K),WSAVE) ENDDO ENDDO ELSE FACT=1./FLOAT(N) FACT=FACT*FACT DO K=2,NZ DO J=1,N CALL CFFTB(N,A(1,J,K),WSAVE) ENDDO DO I=1,N DO J=1,N A(I,J,1)=A(J,I,K) ENDDO ENDDO DO J=1,N CALL CFFTB(N,A(1,J,1),WSAVE) ENDDO DO I=1,N DO J=1,N A(I,J,K)=A(I,J,1)*FACT ENDDO ENDDO ENDDO ENDIF RETURN END ! !--------------------------------------------------------------------- ! SUBROUTINE FFT2DC: This routine computes the two dimensional ! transform of a complex cubic array of square N and length NZ. ! FFT's are done for each square level for k=2->NZ inclusive. The ! first level is used as a scratch array for storing the transpose ! matrix for the second half of the transform. The code uses ! Swartztrauber's fft routines. ISGN=1 implies the backward ! transform otherwise the forward transform is carried out, ! normalization is done only on the backward transform ! SUBROUTINE FFT2DC(N,NZ,A,WSAVE,ISGN) IMPLICIT NONE INTEGER N,NZ,ISGN,I,J,K REAL WSAVE(4*N+15),FACT COMPLEX A(N,N,NZ) IF(ISGN.NE.1)THEN CALL CFFTI(N,WSAVE) DO K=2,NZ DO J=1,N CALL CFFTF(N,A(1,J,K),WSAVE) ENDDO DO I=1,N DO J=1,N A(I,J,1)=A(J,I,K) !transpose ENDDO ENDDO DO J=1,N CALL CFFTF(N,A(1,J,1),WSAVE) ENDDO DO I=1,N DO J=1,N A(I,J,K)=A(J,I,1) ENDDO ENDDO ENDDO ELSE FACT=1./FLOAT(N) FACT=FACT*FACT DO K=2,NZ DO J=1,N CALL CFFTB(N,A(1,J,K),WSAVE) ENDDO DO I=1,N DO J=1,N A(I,J,1)=A(J,I,K) ENDDO ENDDO DO J=1,N CALL CFFTB(N,A(1,J,1),WSAVE) ENDDO DO I=1,N DO J=1,N A(I,J,K)=A(J,I,1)*FACT ENDDO ENDDO ENDDO ENDIF RETURN END ! !--------------------------------------------------------------------- ! SUBROUTINE FFT1DC: This routine computes the fourier transform of ! a complex N element vector defined at NZ levels, for levels 2 --> NZ ! inclusive. FFT's are done using Swartztrauber's fft routines. ! ISGN=1 implies the backward transform, otherwise the forward ! transform is carried out, normalization is done only on the backward ! transform ! SUBROUTINE FFT1DC(N,NZ,A,WSAVE,ISGN,FFTINI) IMPLICIT NONE INTEGER N,NZ,ISGN,I,K, FFTINI REAL WSAVE(4*N+100),FACT COMPLEX A(N,NZ) IF(FFTINI .EQ. 1) THEN CALL CFFTI(N,WSAVE) FFTINI = 0 ENDIF IF(ISGN.NE.1)THEN DO K=1,NZ CALL CFFTF(N,A(1,K),WSAVE) ENDDO ELSE FACT=1./FLOAT(N) DO K=1,NZ CALL CFFTB(N,A(1,K),WSAVE) DO I=1,N A(I,K)=A(I,K)*FACT ENDDO ENDDO ENDIF RETURN END ! ! ------------------------------------- Schwartztraubers routines ! SUBROUTINE CFFTB (N,C,WSAVE) DIMENSION C(*), WSAVE(*) IF (N .EQ. 1) RETURN IW1 = N+N+1 IW2 = IW1+N+N CALL CFFTB1 (N,C,WSAVE,WSAVE(IW1),WSAVE(IW2)) RETURN END SUBROUTINE CFFTB1 (N,C,CH,WA,IFAC) DIMENSION CH(*) ,C(*) ,WA(*) ,IFAC(*) NF = IFAC(2) NA = 0 L1 = 1 IW = 1 DO 116 K1=1,NF IP = IFAC(K1+2) L2 = IP*L1 IDO = N/L2 IDOT = IDO+IDO IDL1 = IDOT*L1 IF (IP .NE. 4) GO TO 103 IX2 = IW+IDOT IX3 = IX2+IDOT IF (NA .NE. 0) GO TO 101 CALL PASSB4 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3)) GO TO 102 101 CALL PASSB4 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3)) 102 NA = 1-NA GO TO 115 103 IF (IP .NE. 2) GO TO 106 IF (NA .NE. 0) GO TO 104 CALL PASSB2 (IDOT,L1,C,CH,WA(IW)) GO TO 105 104 CALL PASSB2 (IDOT,L1,CH,C,WA(IW)) 105 NA = 1-NA GO TO 115 106 IF (IP .NE. 3) GO TO 109 IX2 = IW+IDOT IF (NA .NE. 0) GO TO 107 CALL PASSB3 (IDOT,L1,C,CH,WA(IW),WA(IX2)) GO TO 108 107 CALL PASSB3 (IDOT,L1,CH,C,WA(IW),WA(IX2)) 108 NA = 1-NA GO TO 115 109 IF (IP .NE. 5) GO TO 112 IX2 = IW+IDOT IX3 = IX2+IDOT IX4 = IX3+IDOT IF (NA .NE. 0) GO TO 110 CALL PASSB5 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4)) GO TO 111 110 CALL PASSB5 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4)) 111 NA = 1-NA GO TO 115 112 IF (NA .NE. 0) GO TO 113 CALL PASSB (NAC,IDOT,IP,L1,IDL1,C,C,C,CH,CH,WA(IW)) GO TO 114 113 CALL PASSB (NAC,IDOT,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW)) 114 IF (NAC .NE. 0) NA = 1-NA 115 L1 = L2 IW = IW+(IP-1)*IDOT 116 CONTINUE IF (NA .EQ. 0) RETURN N2 = N+N DO 117 I=1,N2 C(I) = CH(I) 117 CONTINUE RETURN END SUBROUTINE CFFTF (N,C,WSAVE) DIMENSION C(*) ,WSAVE(*) IF (N .EQ. 1) RETURN IW1 = N+N+1 IW2 = IW1+N+N CALL CFFTF1 (N,C,WSAVE,WSAVE(IW1),WSAVE(IW2)) RETURN END SUBROUTINE CFFTF1 (N,C,CH,WA,IFAC) DIMENSION CH(*) ,C(*) ,WA(*) ,IFAC(*) NF = IFAC(2) NA = 0 L1 = 1 IW = 1 DO 116 K1=1,NF IP = IFAC(K1+2) L2 = IP*L1 IDO = N/L2 IDOT = IDO+IDO IDL1 = IDOT*L1 IF (IP .NE. 4) GO TO 103 IX2 = IW+IDOT IX3 = IX2+IDOT IF (NA .NE. 0) GO TO 101 CALL PASSF4 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3)) GO TO 102 101 CALL PASSF4 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3)) 102 NA = 1-NA GO TO 115 103 IF (IP .NE. 2) GO TO 106 IF (NA .NE. 0) GO TO 104 CALL PASSF2 (IDOT,L1,C,CH,WA(IW)) GO TO 105 104 CALL PASSF2 (IDOT,L1,CH,C,WA(IW)) 105 NA = 1-NA GO TO 115 106 IF (IP .NE. 3) GO TO 109 IX2 = IW+IDOT IF (NA .NE. 0) GO TO 107 CALL PASSF3 (IDOT,L1,C,CH,WA(IW),WA(IX2)) GO TO 108 107 CALL PASSF3 (IDOT,L1,CH,C,WA(IW),WA(IX2)) 108 NA = 1-NA GO TO 115 109 IF (IP .NE. 5) GO TO 112 IX2 = IW+IDOT IX3 = IX2+IDOT IX4 = IX3+IDOT IF (NA .NE. 0) GO TO 110 CALL PASSF5 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4)) GO TO 111 110 CALL PASSF5 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4)) 111 NA = 1-NA GO TO 115 112 IF (NA .NE. 0) GO TO 113 CALL PASSF (NAC,IDOT,IP,L1,IDL1,C,C,C,CH,CH,WA(IW)) GO TO 114 113 CALL PASSF (NAC,IDOT,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW)) 114 IF (NAC .NE. 0) NA = 1-NA 115 L1 = L2 IW = IW+(IP-1)*IDOT 116 CONTINUE IF (NA .EQ. 0) RETURN N2 = N+N DO 117 I=1,N2 C(I) = CH(I) 117 CONTINUE RETURN END SUBROUTINE CFFTI (N,WSAVE) DIMENSION WSAVE(*) IF (N .EQ. 1) RETURN IW1 = N+N+1 IW2 = IW1+N+N CALL CFFTI1 (N,WSAVE(IW1),WSAVE(IW2)) RETURN END SUBROUTINE CFFTI1 (N,WA,IFAC) DIMENSION WA(*) ,IFAC(*) ,NTRYH(4) DATA NTRYH(1),NTRYH(2),NTRYH(3),NTRYH(4)/3,4,2,5/ NL = N NF = 0 J = 0 101 J = J+1 IF (J-4) 102,102,103 102 NTRY = NTRYH(J) GO TO 104 103 NTRY = NTRY+2 104 NQ = NL/NTRY NR = NL-NTRY*NQ IF (NR) 101,105,101 105 NF = NF+1 IFAC(NF+2) = NTRY NL = NQ IF (NTRY .NE. 2) GO TO 107 IF (NF .EQ. 1) GO TO 107 DO 106 I=2,NF IB = NF-I+2 IFAC(IB+2) = IFAC(IB+1) 106 CONTINUE IFAC(3) = 2 107 IF (NL .NE. 1) GO TO 104 IFAC(1) = N IFAC(2) = NF TPI = 6.28318530717959 ARGH = TPI/FLOAT(N) I = 2 L1 = 1 DO 110 K1=1,NF IP = IFAC(K1+2) LD = 0 L2 = L1*IP IDO = N/L2 IDOT = IDO+IDO+2 IPM = IP-1 DO 109 J=1,IPM I1 = I WA(I-1) = 1. WA(I) = 0. LD = LD+L1 FI = 0. ARGLD = FLOAT(LD)*ARGH DO 108 II=4,IDOT,2 I = I+2 FI = FI+1. ARG = FI*ARGLD WA(I-1) = COS(ARG) WA(I) = SIN(ARG) 108 CONTINUE IF (IP .LE. 5) GO TO 109 WA(I1-1) = WA(I-1) WA(I1) = WA(I) 109 CONTINUE L1 = L2 110 CONTINUE RETURN END SUBROUTINE PASSB (NAC,IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA) DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) , & C1(IDO,L1,IP) ,WA(*) ,C2(IDL1,IP), & CH2(IDL1,IP) IDOT = IDO/2 NT = IP*IDL1 IPP2 = IP+2 IPPH = (IP+1)/2 IDP = IP*IDO ! IF (IDO .LT. L1) GO TO 106 DO 103 J=2,IPPH JC = IPP2-J DO 102 K=1,L1 DO 101 I=1,IDO CH(I,K,J) = CC(I,J,K)+CC(I,JC,K) CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K) 101 CONTINUE 102 CONTINUE 103 CONTINUE DO 105 K=1,L1 DO 104 I=1,IDO CH(I,K,1) = CC(I,1,K) 104 CONTINUE 105 CONTINUE GO TO 112 106 DO 109 J=2,IPPH JC = IPP2-J DO 108 I=1,IDO DO 107 K=1,L1 CH(I,K,J) = CC(I,J,K)+CC(I,JC,K) CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K) 107 CONTINUE 108 CONTINUE 109 CONTINUE DO 111 I=1,IDO DO 110 K=1,L1 CH(I,K,1) = CC(I,1,K) 110 CONTINUE 111 CONTINUE 112 IDL = 2-IDO INC = 0 DO 116 L=2,IPPH LC = IPP2-L IDL = IDL+IDO DO 113 IK=1,IDL1 C2(IK,L) = CH2(IK,1)+WA(IDL-1)*CH2(IK,2) C2(IK,LC) = WA(IDL)*CH2(IK,IP) 113 CONTINUE IDLJ = IDL INC = INC+IDO DO 115 J=3,IPPH JC = IPP2-J IDLJ = IDLJ+INC IF (IDLJ .GT. IDP) IDLJ = IDLJ-IDP WAR = WA(IDLJ-1) WAI = WA(IDLJ) DO 114 IK=1,IDL1 C2(IK,L) = C2(IK,L)+WAR*CH2(IK,J) C2(IK,LC) = C2(IK,LC)+WAI*CH2(IK,JC) 114 CONTINUE 115 CONTINUE 116 CONTINUE DO 118 J=2,IPPH DO 117 IK=1,IDL1 CH2(IK,1) = CH2(IK,1)+CH2(IK,J) 117 CONTINUE 118 CONTINUE DO 120 J=2,IPPH JC = IPP2-J DO 119 IK=2,IDL1,2 CH2(IK-1,J) = C2(IK-1,J)-C2(IK,JC) CH2(IK-1,JC) = C2(IK-1,J)+C2(IK,JC) CH2(IK,J) = C2(IK,J)+C2(IK-1,JC) CH2(IK,JC) = C2(IK,J)-C2(IK-1,JC) 119 CONTINUE 120 CONTINUE NAC = 1 IF (IDO .EQ. 2) RETURN NAC = 0 DO 121 IK=1,IDL1 C2(IK,1) = CH2(IK,1) 121 CONTINUE DO 123 J=2,IP DO 122 K=1,L1 C1(1,K,J) = CH(1,K,J) C1(2,K,J) = CH(2,K,J) 122 CONTINUE 123 CONTINUE IF (IDOT .GT. L1) GO TO 127 IDIJ = 0 DO 126 J=2,IP IDIJ = IDIJ+2 DO 125 I=4,IDO,2 IDIJ = IDIJ+2 DO 124 K=1,L1 C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J) C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J) 124 CONTINUE 125 CONTINUE 126 CONTINUE RETURN 127 IDJ = 2-IDO DO 130 J=2,IP IDJ = IDJ+IDO DO 129 K=1,L1 IDIJ = IDJ DO 128 I=4,IDO,2 IDIJ = IDIJ+2 C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J) C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J) 128 CONTINUE 129 CONTINUE 130 CONTINUE RETURN END SUBROUTINE PASSB2 (IDO,L1,CC,CH,WA1) DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2) , & WA1(*) IF (IDO .GT. 2) GO TO 102 DO 101 K=1,L1 CH(1,K,1) = CC(1,1,K)+CC(1,2,K) CH(1,K,2) = CC(1,1,K)-CC(1,2,K) CH(2,K,1) = CC(2,1,K)+CC(2,2,K) CH(2,K,2) = CC(2,1,K)-CC(2,2,K) 101 CONTINUE RETURN 102 DO 104 K=1,L1 DO 103 I=2,IDO,2 CH(I-1,K,1) = CC(I-1,1,K)+CC(I-1,2,K) TR2 = CC(I-1,1,K)-CC(I-1,2,K) CH(I,K,1) = CC(I,1,K)+CC(I,2,K) TI2 = CC(I,1,K)-CC(I,2,K) CH(I,K,2) = WA1(I-1)*TI2+WA1(I)*TR2 CH(I-1,K,2) = WA1(I-1)*TR2-WA1(I)*TI2 103 CONTINUE 104 CONTINUE RETURN END SUBROUTINE PASSB3 (IDO,L1,CC,CH,WA1,WA2) DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3) , & WA1(*) ,WA2(*) DATA TAUR,TAUI /-.5,.866025403784439/ IF (IDO .NE. 2) GO TO 102 DO 101 K=1,L1 TR2 = CC(1,2,K)+CC(1,3,K) CR2 = CC(1,1,K)+TAUR*TR2 CH(1,K,1) = CC(1,1,K)+TR2 TI2 = CC(2,2,K)+CC(2,3,K) CI2 = CC(2,1,K)+TAUR*TI2 CH(2,K,1) = CC(2,1,K)+TI2 CR3 = TAUI*(CC(1,2,K)-CC(1,3,K)) CI3 = TAUI*(CC(2,2,K)-CC(2,3,K)) CH(1,K,2) = CR2-CI3 CH(1,K,3) = CR2+CI3 CH(2,K,2) = CI2+CR3 CH(2,K,3) = CI2-CR3 101 CONTINUE RETURN 102 DO 104 K=1,L1 DO 103 I=2,IDO,2 TR2 = CC(I-1,2,K)+CC(I-1,3,K) CR2 = CC(I-1,1,K)+TAUR*TR2 CH(I-1,K,1) = CC(I-1,1,K)+TR2 TI2 = CC(I,2,K)+CC(I,3,K) CI2 = CC(I,1,K)+TAUR*TI2 CH(I,K,1) = CC(I,1,K)+TI2 CR3 = TAUI*(CC(I-1,2,K)-CC(I-1,3,K)) CI3 = TAUI*(CC(I,2,K)-CC(I,3,K)) DR2 = CR2-CI3 DR3 = CR2+CI3 DI2 = CI2+CR3 DI3 = CI2-CR3 CH(I,K,2) = WA1(I-1)*DI2+WA1(I)*DR2 CH(I-1,K,2) = WA1(I-1)*DR2-WA1(I)*DI2 CH(I,K,3) = WA2(I-1)*DI3+WA2(I)*DR3 CH(I-1,K,3) = WA2(I-1)*DR3-WA2(I)*DI3 103 CONTINUE 104 CONTINUE RETURN END SUBROUTINE PASSB4 (IDO,L1,CC,CH,WA1,WA2,WA3) DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4) , & WA1(*) ,WA2(*) ,WA3(*) IF (IDO .NE. 2) GO TO 102 DO 101 K=1,L1 TI1 = CC(2,1,K)-CC(2,3,K) TI2 = CC(2,1,K)+CC(2,3,K) TR4 = CC(2,4,K)-CC(2,2,K) TI3 = CC(2,2,K)+CC(2,4,K) TR1 = CC(1,1,K)-CC(1,3,K) TR2 = CC(1,1,K)+CC(1,3,K) TI4 = CC(1,2,K)-CC(1,4,K) TR3 = CC(1,2,K)+CC(1,4,K) CH(1,K,1) = TR2+TR3 CH(1,K,3) = TR2-TR3 CH(2,K,1) = TI2+TI3 CH(2,K,3) = TI2-TI3 CH(1,K,2) = TR1+TR4 CH(1,K,4) = TR1-TR4 CH(2,K,2) = TI1+TI4 CH(2,K,4) = TI1-TI4 101 CONTINUE RETURN 102 DO 104 K=1,L1 DO 103 I=2,IDO,2 TI1 = CC(I,1,K)-CC(I,3,K) TI2 = CC(I,1,K)+CC(I,3,K) TI3 = CC(I,2,K)+CC(I,4,K) TR4 = CC(I,4,K)-CC(I,2,K) TR1 = CC(I-1,1,K)-CC(I-1,3,K) TR2 = CC(I-1,1,K)+CC(I-1,3,K) TI4 = CC(I-1,2,K)-CC(I-1,4,K) TR3 = CC(I-1,2,K)+CC(I-1,4,K) CH(I-1,K,1) = TR2+TR3 CR3 = TR2-TR3 CH(I,K,1) = TI2+TI3 CI3 = TI2-TI3 CR2 = TR1+TR4 CR4 = TR1-TR4 CI2 = TI1+TI4 CI4 = TI1-TI4 CH(I-1,K,2) = WA1(I-1)*CR2-WA1(I)*CI2 CH(I,K,2) = WA1(I-1)*CI2+WA1(I)*CR2 CH(I-1,K,3) = WA2(I-1)*CR3-WA2(I)*CI3 CH(I,K,3) = WA2(I-1)*CI3+WA2(I)*CR3 CH(I-1,K,4) = WA3(I-1)*CR4-WA3(I)*CI4 CH(I,K,4) = WA3(I-1)*CI4+WA3(I)*CR4 103 CONTINUE 104 CONTINUE RETURN END SUBROUTINE PASSB5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4) DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5) , & WA1(*) ,WA2(*) ,WA3(*) ,WA4(*) DATA TR11,TI11,TR12,TI12 /.309016994374947,.951056516295154,-.809016994374947,.587785252292473/ IF (IDO .NE. 2) GO TO 102 DO 101 K=1,L1 TI5 = CC(2,2,K)-CC(2,5,K) TI2 = CC(2,2,K)+CC(2,5,K) TI4 = CC(2,3,K)-CC(2,4,K) TI3 = CC(2,3,K)+CC(2,4,K) TR5 = CC(1,2,K)-CC(1,5,K) TR2 = CC(1,2,K)+CC(1,5,K) TR4 = CC(1,3,K)-CC(1,4,K) TR3 = CC(1,3,K)+CC(1,4,K) CH(1,K,1) = CC(1,1,K)+TR2+TR3 CH(2,K,1) = CC(2,1,K)+TI2+TI3 CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3 CI2 = CC(2,1,K)+TR11*TI2+TR12*TI3 CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3 CI3 = CC(2,1,K)+TR12*TI2+TR11*TI3 CR5 = TI11*TR5+TI12*TR4 CI5 = TI11*TI5+TI12*TI4 CR4 = TI12*TR5-TI11*TR4 CI4 = TI12*TI5-TI11*TI4 CH(1,K,2) = CR2-CI5 CH(1,K,5) = CR2+CI5 CH(2,K,2) = CI2+CR5 CH(2,K,3) = CI3+CR4 CH(1,K,3) = CR3-CI4 CH(1,K,4) = CR3+CI4 CH(2,K,4) = CI3-CR4 CH(2,K,5) = CI2-CR5 101 CONTINUE RETURN 102 DO 104 K=1,L1 DO 103 I=2,IDO,2 TI5 = CC(I,2,K)-CC(I,5,K) TI2 = CC(I,2,K)+CC(I,5,K) TI4 = CC(I,3,K)-CC(I,4,K) TI3 = CC(I,3,K)+CC(I,4,K) TR5 = CC(I-1,2,K)-CC(I-1,5,K) TR2 = CC(I-1,2,K)+CC(I-1,5,K) TR4 = CC(I-1,3,K)-CC(I-1,4,K) TR3 = CC(I-1,3,K)+CC(I-1,4,K) CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3 CH(I,K,1) = CC(I,1,K)+TI2+TI3 CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3 CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3 CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3 CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3 CR5 = TI11*TR5+TI12*TR4 CI5 = TI11*TI5+TI12*TI4 CR4 = TI12*TR5-TI11*TR4 CI4 = TI12*TI5-TI11*TI4 DR3 = CR3-CI4 DR4 = CR3+CI4 DI3 = CI3+CR4 DI4 = CI3-CR4 DR5 = CR2+CI5 DR2 = CR2-CI5 DI5 = CI2-CR5 DI2 = CI2+CR5 CH(I-1,K,2) = WA1(I-1)*DR2-WA1(I)*DI2 CH(I,K,2) = WA1(I-1)*DI2+WA1(I)*DR2 CH(I-1,K,3) = WA2(I-1)*DR3-WA2(I)*DI3 CH(I,K,3) = WA2(I-1)*DI3+WA2(I)*DR3 CH(I-1,K,4) = WA3(I-1)*DR4-WA3(I)*DI4 CH(I,K,4) = WA3(I-1)*DI4+WA3(I)*DR4 CH(I-1,K,5) = WA4(I-1)*DR5-WA4(I)*DI5 CH(I,K,5) = WA4(I-1)*DI5+WA4(I)*DR5 103 CONTINUE 104 CONTINUE RETURN END SUBROUTINE PASSF (NAC,IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA) DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) , & C1(IDO,L1,IP) ,WA(*) ,C2(IDL1,IP), & CH2(IDL1,IP) IDOT = IDO/2 NT = IP*IDL1 IPP2 = IP+2 IPPH = (IP+1)/2 IDP = IP*IDO ! IF (IDO .LT. L1) GO TO 106 DO 103 J=2,IPPH JC = IPP2-J DO 102 K=1,L1 DO 101 I=1,IDO CH(I,K,J) = CC(I,J,K)+CC(I,JC,K) CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K) 101 CONTINUE 102 CONTINUE 103 CONTINUE DO 105 K=1,L1 DO 104 I=1,IDO CH(I,K,1) = CC(I,1,K) 104 CONTINUE 105 CONTINUE GO TO 112 106 DO 109 J=2,IPPH JC = IPP2-J DO 108 I=1,IDO DO 107 K=1,L1 CH(I,K,J) = CC(I,J,K)+CC(I,JC,K) CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K) 107 CONTINUE 108 CONTINUE 109 CONTINUE DO 111 I=1,IDO DO 110 K=1,L1 CH(I,K,1) = CC(I,1,K) 110 CONTINUE 111 CONTINUE 112 IDL = 2-IDO INC = 0 DO 116 L=2,IPPH LC = IPP2-L IDL = IDL+IDO DO 113 IK=1,IDL1 C2(IK,L) = CH2(IK,1)+WA(IDL-1)*CH2(IK,2) C2(IK,LC) = -WA(IDL)*CH2(IK,IP) 113 CONTINUE IDLJ = IDL INC = INC+IDO DO 115 J=3,IPPH JC = IPP2-J IDLJ = IDLJ+INC IF (IDLJ .GT. IDP) IDLJ = IDLJ-IDP WAR = WA(IDLJ-1) WAI = WA(IDLJ) DO 114 IK=1,IDL1 C2(IK,L) = C2(IK,L)+WAR*CH2(IK,J) C2(IK,LC) = C2(IK,LC)-WAI*CH2(IK,JC) 114 CONTINUE 115 CONTINUE 116 CONTINUE DO 118 J=2,IPPH DO 117 IK=1,IDL1 CH2(IK,1) = CH2(IK,1)+CH2(IK,J) 117 CONTINUE 118 CONTINUE DO 120 J=2,IPPH JC = IPP2-J DO 119 IK=2,IDL1,2 CH2(IK-1,J) = C2(IK-1,J)-C2(IK,JC) CH2(IK-1,JC) = C2(IK-1,J)+C2(IK,JC) CH2(IK,J) = C2(IK,J)+C2(IK-1,JC) CH2(IK,JC) = C2(IK,J)-C2(IK-1,JC) 119 CONTINUE 120 CONTINUE NAC = 1 IF (IDO .EQ. 2) RETURN NAC = 0 DO 121 IK=1,IDL1 C2(IK,1) = CH2(IK,1) 121 CONTINUE DO 123 J=2,IP DO 122 K=1,L1 C1(1,K,J) = CH(1,K,J) C1(2,K,J) = CH(2,K,J) 122 CONTINUE 123 CONTINUE IF (IDOT .GT. L1) GO TO 127 IDIJ = 0 DO 126 J=2,IP IDIJ = IDIJ+2 DO 125 I=4,IDO,2 IDIJ = IDIJ+2 DO 124 K=1,L1 C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)+WA(IDIJ)*CH(I,K,J) C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)-WA(IDIJ)*CH(I-1,K,J) 124 CONTINUE 125 CONTINUE 126 CONTINUE RETURN 127 IDJ = 2-IDO DO 130 J=2,IP IDJ = IDJ+IDO DO 129 K=1,L1 IDIJ = IDJ DO 128 I=4,IDO,2 IDIJ = IDIJ+2 C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)+WA(IDIJ)*CH(I,K,J) C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)-WA(IDIJ)*CH(I-1,K,J) 128 CONTINUE 129 CONTINUE 130 CONTINUE RETURN END SUBROUTINE PASSF2 (IDO,L1,CC,CH,WA1) DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2) , & WA1(*) IF (IDO .GT. 2) GO TO 102 DO 101 K=1,L1 CH(1,K,1) = CC(1,1,K)+CC(1,2,K) CH(1,K,2) = CC(1,1,K)-CC(1,2,K) CH(2,K,1) = CC(2,1,K)+CC(2,2,K) CH(2,K,2) = CC(2,1,K)-CC(2,2,K) 101 CONTINUE RETURN 102 DO 104 K=1,L1 DO 103 I=2,IDO,2 CH(I-1,K,1) = CC(I-1,1,K)+CC(I-1,2,K) TR2 = CC(I-1,1,K)-CC(I-1,2,K) CH(I,K,1) = CC(I,1,K)+CC(I,2,K) TI2 = CC(I,1,K)-CC(I,2,K) CH(I,K,2) = WA1(I-1)*TI2-WA1(I)*TR2 CH(I-1,K,2) = WA1(I-1)*TR2+WA1(I)*TI2 103 CONTINUE 104 CONTINUE RETURN END SUBROUTINE PASSF3 (IDO,L1,CC,CH,WA1,WA2) DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3) , & WA1(*) ,WA2(*) DATA TAUR,TAUI /-.5,-.866025403784439/ IF (IDO .NE. 2) GO TO 102 DO 101 K=1,L1 TR2 = CC(1,2,K)+CC(1,3,K) CR2 = CC(1,1,K)+TAUR*TR2 CH(1,K,1) = CC(1,1,K)+TR2 TI2 = CC(2,2,K)+CC(2,3,K) CI2 = CC(2,1,K)+TAUR*TI2 CH(2,K,1) = CC(2,1,K)+TI2 CR3 = TAUI*(CC(1,2,K)-CC(1,3,K)) CI3 = TAUI*(CC(2,2,K)-CC(2,3,K)) CH(1,K,2) = CR2-CI3 CH(1,K,3) = CR2+CI3 CH(2,K,2) = CI2+CR3 CH(2,K,3) = CI2-CR3 101 CONTINUE RETURN 102 DO 104 K=1,L1 DO 103 I=2,IDO,2 TR2 = CC(I-1,2,K)+CC(I-1,3,K) CR2 = CC(I-1,1,K)+TAUR*TR2 CH(I-1,K,1) = CC(I-1,1,K)+TR2 TI2 = CC(I,2,K)+CC(I,3,K) CI2 = CC(I,1,K)+TAUR*TI2 CH(I,K,1) = CC(I,1,K)+TI2 CR3 = TAUI*(CC(I-1,2,K)-CC(I-1,3,K)) CI3 = TAUI*(CC(I,2,K)-CC(I,3,K)) DR2 = CR2-CI3 DR3 = CR2+CI3 DI2 = CI2+CR3 DI3 = CI2-CR3 CH(I,K,2) = WA1(I-1)*DI2-WA1(I)*DR2 CH(I-1,K,2) = WA1(I-1)*DR2+WA1(I)*DI2 CH(I,K,3) = WA2(I-1)*DI3-WA2(I)*DR3 CH(I-1,K,3) = WA2(I-1)*DR3+WA2(I)*DI3 103 CONTINUE 104 CONTINUE RETURN END SUBROUTINE PASSF4 (IDO,L1,CC,CH,WA1,WA2,WA3) DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4) , & WA1(*) ,WA2(*) ,WA3(*) IF (IDO .NE. 2) GO TO 102 DO 101 K=1,L1 TI1 = CC(2,1,K)-CC(2,3,K) TI2 = CC(2,1,K)+CC(2,3,K) TR4 = CC(2,2,K)-CC(2,4,K) TI3 = CC(2,2,K)+CC(2,4,K) TR1 = CC(1,1,K)-CC(1,3,K) TR2 = CC(1,1,K)+CC(1,3,K) TI4 = CC(1,4,K)-CC(1,2,K) TR3 = CC(1,2,K)+CC(1,4,K) CH(1,K,1) = TR2+TR3 CH(1,K,3) = TR2-TR3 CH(2,K,1) = TI2+TI3 CH(2,K,3) = TI2-TI3 CH(1,K,2) = TR1+TR4 CH(1,K,4) = TR1-TR4 CH(2,K,2) = TI1+TI4 CH(2,K,4) = TI1-TI4 101 CONTINUE RETURN 102 DO 104 K=1,L1 DO 103 I=2,IDO,2 TI1 = CC(I,1,K)-CC(I,3,K) TI2 = CC(I,1,K)+CC(I,3,K) TI3 = CC(I,2,K)+CC(I,4,K) TR4 = CC(I,2,K)-CC(I,4,K) TR1 = CC(I-1,1,K)-CC(I-1,3,K) TR2 = CC(I-1,1,K)+CC(I-1,3,K) TI4 = CC(I-1,4,K)-CC(I-1,2,K) TR3 = CC(I-1,2,K)+CC(I-1,4,K) CH(I-1,K,1) = TR2+TR3 CR3 = TR2-TR3 CH(I,K,1) = TI2+TI3 CI3 = TI2-TI3 CR2 = TR1+TR4 CR4 = TR1-TR4 CI2 = TI1+TI4 CI4 = TI1-TI4 CH(I-1,K,2) = WA1(I-1)*CR2+WA1(I)*CI2 CH(I,K,2) = WA1(I-1)*CI2-WA1(I)*CR2 CH(I-1,K,3) = WA2(I-1)*CR3+WA2(I)*CI3 CH(I,K,3) = WA2(I-1)*CI3-WA2(I)*CR3 CH(I-1,K,4) = WA3(I-1)*CR4+WA3(I)*CI4 CH(I,K,4) = WA3(I-1)*CI4-WA3(I)*CR4 103 CONTINUE 104 CONTINUE RETURN END SUBROUTINE PASSF5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4) DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5) , & WA1(*) ,WA2(*) ,WA3(*) ,WA4(*) DATA TR11,TI11,TR12,TI12 /.309016994374947,-.951056516295154,-.809016994374947,-.587785252292473/ IF (IDO .NE. 2) GO TO 102 DO 101 K=1,L1 TI5 = CC(2,2,K)-CC(2,5,K) TI2 = CC(2,2,K)+CC(2,5,K) TI4 = CC(2,3,K)-CC(2,4,K) TI3 = CC(2,3,K)+CC(2,4,K) TR5 = CC(1,2,K)-CC(1,5,K) TR2 = CC(1,2,K)+CC(1,5,K) TR4 = CC(1,3,K)-CC(1,4,K) TR3 = CC(1,3,K)+CC(1,4,K) CH(1,K,1) = CC(1,1,K)+TR2+TR3 CH(2,K,1) = CC(2,1,K)+TI2+TI3 CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3 CI2 = CC(2,1,K)+TR11*TI2+TR12*TI3 CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3 CI3 = CC(2,1,K)+TR12*TI2+TR11*TI3 CR5 = TI11*TR5+TI12*TR4 CI5 = TI11*TI5+TI12*TI4 CR4 = TI12*TR5-TI11*TR4 CI4 = TI12*TI5-TI11*TI4 CH(1,K,2) = CR2-CI5 CH(1,K,5) = CR2+CI5 CH(2,K,2) = CI2+CR5 CH(2,K,3) = CI3+CR4 CH(1,K,3) = CR3-CI4 CH(1,K,4) = CR3+CI4 CH(2,K,4) = CI3-CR4 CH(2,K,5) = CI2-CR5 101 CONTINUE RETURN 102 DO 104 K=1,L1 DO 103 I=2,IDO,2 TI5 = CC(I,2,K)-CC(I,5,K) TI2 = CC(I,2,K)+CC(I,5,K) TI4 = CC(I,3,K)-CC(I,4,K) TI3 = CC(I,3,K)+CC(I,4,K) TR5 = CC(I-1,2,K)-CC(I-1,5,K) TR2 = CC(I-1,2,K)+CC(I-1,5,K) TR4 = CC(I-1,3,K)-CC(I-1,4,K) TR3 = CC(I-1,3,K)+CC(I-1,4,K) CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3 CH(I,K,1) = CC(I,1,K)+TI2+TI3 CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3 CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3 CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3 CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3 CR5 = TI11*TR5+TI12*TR4 CI5 = TI11*TI5+TI12*TI4 CR4 = TI12*TR5-TI11*TR4 CI4 = TI12*TI5-TI11*TI4 DR3 = CR3-CI4 DR4 = CR3+CI4 DI3 = CI3+CR4 DI4 = CI3-CR4 DR5 = CR2+CI5 DR2 = CR2-CI5 DI5 = CI2-CR5 DI2 = CI2+CR5 CH(I-1,K,2) = WA1(I-1)*DR2+WA1(I)*DI2 CH(I,K,2) = WA1(I-1)*DI2-WA1(I)*DR2 CH(I-1,K,3) = WA2(I-1)*DR3+WA2(I)*DI3 CH(I,K,3) = WA2(I-1)*DI3-WA2(I)*DR3 CH(I-1,K,4) = WA3(I-1)*DR4+WA3(I)*DI4 CH(I,K,4) = WA3(I-1)*DI4-WA3(I)*DR4 CH(I-1,K,5) = WA4(I-1)*DR5+WA4(I)*DI5 CH(I,K,5) = WA4(I-1)*DI5-WA4(I)*DR5 103 CONTINUE 104 CONTINUE RETURN END
gpl-3.0
LucasGandel/ITK
Modules/ThirdParty/Netlib/src/netlib/slatec/dlbeta.f
48
1910
*DECK DLBETA DOUBLE PRECISION FUNCTION DLBETA (A, B) C***BEGIN PROLOGUE DLBETA C***PURPOSE Compute the natural logarithm of the complete Beta C function. C***LIBRARY SLATEC (FNLIB) C***CATEGORY C7B C***TYPE DOUBLE PRECISION (ALBETA-S, DLBETA-D, CLBETA-C) C***KEYWORDS FNLIB, LOGARITHM OF THE COMPLETE BETA FUNCTION, C SPECIAL FUNCTIONS C***AUTHOR Fullerton, W., (LANL) C***DESCRIPTION C C DLBETA(A,B) calculates the double precision natural logarithm of C the complete beta function for double precision arguments C A and B. C C***REFERENCES (NONE) C***ROUTINES CALLED D9LGMC, DGAMMA, DLNGAM, DLNREL, XERMSG C***REVISION HISTORY (YYMMDD) C 770701 DATE WRITTEN C 890531 Changed all specific intrinsics to generic. (WRB) C 890531 REVISION DATE from Version 3.2 C 891214 Prologue converted to Version 4.0 format. (BAB) C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) C 900727 Added EXTERNAL statement. (WRB) C***END PROLOGUE DLBETA DOUBLE PRECISION A, B, P, Q, CORR, SQ2PIL, D9LGMC, DGAMMA, DLNGAM, 1 DLNREL EXTERNAL DGAMMA SAVE SQ2PIL DATA SQ2PIL / 0.9189385332 0467274178 0329736405 62 D0 / C***FIRST EXECUTABLE STATEMENT DLBETA P = MIN (A, B) Q = MAX (A, B) C IF (P .LE. 0.D0) CALL XERMSG ('SLATEC', 'DLBETA', + 'BOTH ARGUMENTS MUST BE GT ZERO', 1, 2) C IF (P.GE.10.D0) GO TO 30 IF (Q.GE.10.D0) GO TO 20 C C P AND Q ARE SMALL. C DLBETA = LOG (DGAMMA(P) * (DGAMMA(Q)/DGAMMA(P+Q)) ) RETURN C C P IS SMALL, BUT Q IS BIG. C 20 CORR = D9LGMC(Q) - D9LGMC(P+Q) DLBETA = DLNGAM(P) + CORR + P - P*LOG(P+Q) 1 + (Q-0.5D0)*DLNREL(-P/(P+Q)) RETURN C C P AND Q ARE BIG. C 30 CORR = D9LGMC(P) + D9LGMC(Q) - D9LGMC(P+Q) DLBETA = -0.5D0*LOG(Q) + SQ2PIL + CORR + (P-0.5D0)*LOG(P/(P+Q)) 1 + Q*DLNREL(-P/(P+Q)) RETURN C END
apache-2.0
kbai/specfem3d
utils/EXTERNAL_CODES_coupled_with_SPECFEM3D/DSM_for_SPECFEM3D/DSM-1-BIG_3D_storage_version/Part-3-modify_DSM_results_for_SPECFEM/FFT_MPI_FACES_VERT_SH/rotations_matrix.f90
15
5195
! ! ! ROUTINES POUR FAIRE DES ROTATIONS 3D ET DIVERS CHANGEMENTS DE REPERES ! ! Vadim Monteiller Mars 2013 ! !------------------------------------------------------------------------------- ! matrice de rotation 3D d'axe "axe" et d'angle theta (degres) ! cette matrice est en complexe subroutine rotation_matrix(R,axe,theta) implicit none double precision axe(3),theta,pi,deg2rad double complex R(3,3) double precision c,s,ux,uy,uz,norme_axe integer i,j pi=3.1415926535897932d0 deg2rad = pi / 180.d0 ! on normalise l'axe !write(100,*) 'axe rotation :',axe norme_axe=dsqrt(axe(1)**2 + axe(2)**2 + axe(3)**2) ! composantes de l'axe ux=axe(1)/norme_axe uy=axe(2)/norme_axe uz=axe(3)/norme_axe ! on calcule le cos et sin c=dcos(deg2rad * theta);s=dsin(deg2rad * theta) ! matrice de rotation complexe R(1,1)=dcmplx(ux**2 + (1.d0-ux**2)*c) R(1,2)=dcmplx(ux*uy*(1.d0-c)-uz*s) R(1,3)=dcmplx(ux*uz*(1.d0-c)+uy*s) R(2,1)=dcmplx(ux*uy*(1.d0-c)+uz*s) R(2,2)=dcmplx(uy**2+(1.d0-uy**2)*c) R(2,3)=dcmplx(uy*uz*(1.d0-c)-ux*s) R(3,1)=dcmplx(ux*uz*(1.d0-c)-uy*s) R(3,2)=dcmplx(uy*uz*(1.d0-c)+ux*s) R(3,3)=dcmplx(uz**2+(1.d0-uz**2)*c) end subroutine rotation_matrix !------------------------------------------------------------------------------- ! R=R2*R1*R0 subroutine compose3matrix(R,R0,R1,R2) implicit none double complex R(3,3),R0(3,3),R1(3,3),R2(3,3) integer i,j,k R(:,:)=dcmplx(0.d0) ! multiplication R=R1*R0 do j=1,3 do i=1,3 do k=1,3 R(i,j)=R(i,j) + R1(i,k)*R0(k,j) enddo enddo enddo R1(:,:)=R(:,:) R(:,:)=dcmplx(0.d0) ! multiplication R=R2*R1 do j=1,3 do i=1,3 do k=1,3 R(i,j)=R(i,j) + R2(i,k)*R1(k,j) enddo enddo enddo end subroutine compose3matrix !------------------------------------------------------------------------------ ! rotation pour passer d'un repere local a un autre subroutine local2localMatrix(lat0,lon0,lat1,lon1,R) implicit none double precision lat0,lon0,lat1,lon1 double precision distance_epicentrale,azi,bazi double complex R(3,3),axe_rotation(3) ! calcul de la distance epicentrale = angle de rotation call epitra1(lat0,lon0,lat1,lon1,distance_epicentrale,azi,bazi) ! calcul de l'axe de rotation = perendiculaire au plan (O,P0,P1) call calcule_axe_rotation(lat0,lon0,lat1,lon1,axe_rotation) ! on calcule la matrice de rotation call rotation_matrix(R,axe_rotation,distance_epicentrale) end subroutine local2localMatrix !------------------------------------------------------------------------------- !calcul de l'axe de rotation subroutine calcule_axe_rotation(lat0,lon0,lat1,lon1,axe) implicit none double precision lat0,lon0,lat1,lon1,axe(3) double precision X0(3),X1(3) ! on passe dans le repere global cartesien call geograph2cartglob(X0,lat0,lon0,1.d0) call geograph2cartglob(X1,lat1,lon1,1.d0) ! on fait le produit vectoriel X0^X1 call pdt_vectoriel(axe,X0,X1) end subroutine calcule_axe_rotation !------------------------------------------------------------------------------- ! passage geographique -> global subroutine geograph2cartglob(X,lat,lon,r) implicit none double precision deg2rad,lat,lon,r,X(3) integer i deg2rad=3.1415926535897932d0/180.d0 X(1)=r*dcos(deg2rad*lon)*cos(deg2rad*lat); X(2)=r*dsin(deg2rad*lon)*cos(deg2rad*lat); X(3)=r*dsin(deg2rad*lat); end subroutine geograph2cartglob !------------------------------------------------------------------------------- ! passage global -> geographique subroutine cartglob2geograph(X,lat,lon,r) implicit none double precision r,lat,lon,X(3),rad2deg rad2deg=180.d0/3.1415926535897932d0 r=dsqrt(X(1)**2+X(2)**2+X(3)**2); lon=datan2(X(2),X(1))*rad2deg; lat=dasin(X(3)/r)*rad2deg; end subroutine cartglob2geograph !------------------------------------------------------------------------------- ! produit vectoriel subroutine pdt_vectoriel(Z,X,Y) implicit none double precision X(3),Y(3),Z(3) z(1)=x(2)*y(3)-x(3)*y(2); z(2)=x(3)*y(1)-x(1)*y(3); z(3)=x(1)*y(2)-x(2)*y(1); end subroutine pdt_vectoriel !------------------------------------------------------------------------------- ! produit matrice vecteur Y=R*X subroutine matmulvect(Y,R,X) implicit none double complex Y(3),R(3,3),X(3) integer i,k Y(:)=dcmplx(0.d0) do i=1,3 do k=1,3 Y(i)=Y(i)+R(i,k)*X(k) enddo enddo end subroutine matmulvect !------------------------------------------------------------------------------ ! affichage d'une matrice complexe subroutine Display_matrix_complex(iunit,M) implicit none integer i,iunit double complex M(3,3) do i=1,3 write(iunit,'("|",2f10.5,5x,2f10.5,5x,2f10.5," |")') real(M(i,1)),aimag(M(i,1)),real(M(i,2)),aimag(M(i,2)),real(M(i,3)),aimag(M(i,3)) enddo end subroutine Display_matrix_complex !------------------------------------------------------------------------------ ! affichage d'une matrice complexe partie reele subroutine Display_matrix_realpart(iunit,M) implicit none integer i,iunit double complex M(3,3) do i=1,3 write(iunit,'("|",f10.5,5x,f10.5,5x,f10.5," |")') real(M(i,1)),real(M(i,2)),real(M(i,3)) enddo end subroutine Display_matrix_realpart
gpl-2.0
kbai/specfem3d
utils/EXTERNAL_CODES_coupled_with_SPECFEM3D/DSM_for_SPECFEM3D/DSM-1-BIG_3D_storage_version/Part-3-modify_DSM_results_for_SPECFEM/FFT_MPI_FACES_VERT_PSV/rotations_matrix.f90
15
5195
! ! ! ROUTINES POUR FAIRE DES ROTATIONS 3D ET DIVERS CHANGEMENTS DE REPERES ! ! Vadim Monteiller Mars 2013 ! !------------------------------------------------------------------------------- ! matrice de rotation 3D d'axe "axe" et d'angle theta (degres) ! cette matrice est en complexe subroutine rotation_matrix(R,axe,theta) implicit none double precision axe(3),theta,pi,deg2rad double complex R(3,3) double precision c,s,ux,uy,uz,norme_axe integer i,j pi=3.1415926535897932d0 deg2rad = pi / 180.d0 ! on normalise l'axe !write(100,*) 'axe rotation :',axe norme_axe=dsqrt(axe(1)**2 + axe(2)**2 + axe(3)**2) ! composantes de l'axe ux=axe(1)/norme_axe uy=axe(2)/norme_axe uz=axe(3)/norme_axe ! on calcule le cos et sin c=dcos(deg2rad * theta);s=dsin(deg2rad * theta) ! matrice de rotation complexe R(1,1)=dcmplx(ux**2 + (1.d0-ux**2)*c) R(1,2)=dcmplx(ux*uy*(1.d0-c)-uz*s) R(1,3)=dcmplx(ux*uz*(1.d0-c)+uy*s) R(2,1)=dcmplx(ux*uy*(1.d0-c)+uz*s) R(2,2)=dcmplx(uy**2+(1.d0-uy**2)*c) R(2,3)=dcmplx(uy*uz*(1.d0-c)-ux*s) R(3,1)=dcmplx(ux*uz*(1.d0-c)-uy*s) R(3,2)=dcmplx(uy*uz*(1.d0-c)+ux*s) R(3,3)=dcmplx(uz**2+(1.d0-uz**2)*c) end subroutine rotation_matrix !------------------------------------------------------------------------------- ! R=R2*R1*R0 subroutine compose3matrix(R,R0,R1,R2) implicit none double complex R(3,3),R0(3,3),R1(3,3),R2(3,3) integer i,j,k R(:,:)=dcmplx(0.d0) ! multiplication R=R1*R0 do j=1,3 do i=1,3 do k=1,3 R(i,j)=R(i,j) + R1(i,k)*R0(k,j) enddo enddo enddo R1(:,:)=R(:,:) R(:,:)=dcmplx(0.d0) ! multiplication R=R2*R1 do j=1,3 do i=1,3 do k=1,3 R(i,j)=R(i,j) + R2(i,k)*R1(k,j) enddo enddo enddo end subroutine compose3matrix !------------------------------------------------------------------------------ ! rotation pour passer d'un repere local a un autre subroutine local2localMatrix(lat0,lon0,lat1,lon1,R) implicit none double precision lat0,lon0,lat1,lon1 double precision distance_epicentrale,azi,bazi double complex R(3,3),axe_rotation(3) ! calcul de la distance epicentrale = angle de rotation call epitra1(lat0,lon0,lat1,lon1,distance_epicentrale,azi,bazi) ! calcul de l'axe de rotation = perendiculaire au plan (O,P0,P1) call calcule_axe_rotation(lat0,lon0,lat1,lon1,axe_rotation) ! on calcule la matrice de rotation call rotation_matrix(R,axe_rotation,distance_epicentrale) end subroutine local2localMatrix !------------------------------------------------------------------------------- !calcul de l'axe de rotation subroutine calcule_axe_rotation(lat0,lon0,lat1,lon1,axe) implicit none double precision lat0,lon0,lat1,lon1,axe(3) double precision X0(3),X1(3) ! on passe dans le repere global cartesien call geograph2cartglob(X0,lat0,lon0,1.d0) call geograph2cartglob(X1,lat1,lon1,1.d0) ! on fait le produit vectoriel X0^X1 call pdt_vectoriel(axe,X0,X1) end subroutine calcule_axe_rotation !------------------------------------------------------------------------------- ! passage geographique -> global subroutine geograph2cartglob(X,lat,lon,r) implicit none double precision deg2rad,lat,lon,r,X(3) integer i deg2rad=3.1415926535897932d0/180.d0 X(1)=r*dcos(deg2rad*lon)*cos(deg2rad*lat); X(2)=r*dsin(deg2rad*lon)*cos(deg2rad*lat); X(3)=r*dsin(deg2rad*lat); end subroutine geograph2cartglob !------------------------------------------------------------------------------- ! passage global -> geographique subroutine cartglob2geograph(X,lat,lon,r) implicit none double precision r,lat,lon,X(3),rad2deg rad2deg=180.d0/3.1415926535897932d0 r=dsqrt(X(1)**2+X(2)**2+X(3)**2); lon=datan2(X(2),X(1))*rad2deg; lat=dasin(X(3)/r)*rad2deg; end subroutine cartglob2geograph !------------------------------------------------------------------------------- ! produit vectoriel subroutine pdt_vectoriel(Z,X,Y) implicit none double precision X(3),Y(3),Z(3) z(1)=x(2)*y(3)-x(3)*y(2); z(2)=x(3)*y(1)-x(1)*y(3); z(3)=x(1)*y(2)-x(2)*y(1); end subroutine pdt_vectoriel !------------------------------------------------------------------------------- ! produit matrice vecteur Y=R*X subroutine matmulvect(Y,R,X) implicit none double complex Y(3),R(3,3),X(3) integer i,k Y(:)=dcmplx(0.d0) do i=1,3 do k=1,3 Y(i)=Y(i)+R(i,k)*X(k) enddo enddo end subroutine matmulvect !------------------------------------------------------------------------------ ! affichage d'une matrice complexe subroutine Display_matrix_complex(iunit,M) implicit none integer i,iunit double complex M(3,3) do i=1,3 write(iunit,'("|",2f10.5,5x,2f10.5,5x,2f10.5," |")') real(M(i,1)),aimag(M(i,1)),real(M(i,2)),aimag(M(i,2)),real(M(i,3)),aimag(M(i,3)) enddo end subroutine Display_matrix_complex !------------------------------------------------------------------------------ ! affichage d'une matrice complexe partie reele subroutine Display_matrix_realpart(iunit,M) implicit none integer i,iunit double complex M(3,3) do i=1,3 write(iunit,'("|",f10.5,5x,f10.5,5x,f10.5," |")') real(M(i,1)),real(M(i,2)),real(M(i,3)) enddo end subroutine Display_matrix_realpart
gpl-2.0
kbai/specfem3d
utils/Visualization/opendx_AVS/view_basin_model_box_dx.f90
8
2058
program test_opendx_hexahedra !------------------------------------------------------------------------- ! creates an OpenDX file showing the edges of the SEM grid !------------------------------------------------------------------------- implicit none include "../../../constants.h" double precision, parameter :: LONGMIN = -120.5d0,LONGMAX = -114.5d0 double precision, parameter :: LATMIN = 32.5d0,LATMAX = 36.5d0 double precision, dimension(4) :: x,y write(*,*) 'creating OpenDX grid' call utm_geo(LONGMIN,LATMIN,x(1),y(1),IZONE_UTM_LA,ILONGLAT2UTM) call utm_geo(LONGMAX,LATMIN,x(2),y(2),IZONE_UTM_LA,ILONGLAT2UTM) call utm_geo(LONGMAX,LATMAX,x(3),y(3),IZONE_UTM_LA,ILONGLAT2UTM) call utm_geo(LONGMIN,LATMAX,x(4),y(4),IZONE_UTM_LA,ILONGLAT2UTM) !--- !--- write OpenDX file !--- open(unit=10,file='basin_grid_edges.dx', status='unknown') !--- write nodal coordinates write(10,*) 'object 1 class array type float rank 1 shape 3 items 4 data follows' ! use fictitious height of 1. to place on top of the rest on top view write(10,*) sngl(x(1)),sngl(y(1)),' 1' write(10,*) sngl(x(2)),sngl(y(2)),' 1' write(10,*) sngl(x(3)),sngl(y(3)),' 1' write(10,*) sngl(x(4)),sngl(y(4)),' 1' !--- write connectivity pattern !--- OpenDX node numbers start at zero write(10,*) 'object 2 class array type int rank 1 shape 4 items 1 data follows' write(10,*) '0 3 1 2' write(10,*) 'attribute "element type" string "quads"' write(10,*) 'attribute "ref" string "positions"' !--- write element data write(10,*) 'object 3 class array type float rank 0 items 1 data follows' write(10,*) '100' write(10,*) 'attribute "dep" string "connections"' !--- define field write(10,*) 'object "irregular connections irregular positions" class field' write(10,*) 'component "positions" value 1' write(10,*) 'component "connections" value 2' write(10,*) 'component "data" value 3' write(10,*) 'end' close(10) end program test_opendx_hexahedra !! DK DK add UTM projection routine include "../../../utm_geo.f90"
gpl-2.0
skywalker00/sabermod_rom_toolchain
gcc/testsuite/gfortran.dg/iso_fortran_env_1.f90
136
1193
! { dg-do run } module iso_fortran_env real :: x end module iso_fortran_env subroutine bar use , intrinsic :: iso_fortran_env implicit none if (file_storage_size /= 8) call abort if (character_storage_size /= 8) call abort if (all (numeric_storage_size /= [ 8, 16, 32, 64, 128])) call abort if (input_unit /= 5) call abort if (output_unit /= 6) call abort if (error_unit /= 0) call abort if (iostat_end /= -1) call abort if (iostat_eor /= -2) call abort end subroutine bar2 use , intrinsic :: iso_fortran_env, only : file_storage_size, & character_storage_size, numeric_storage_size, input_unit, output_unit, & error_unit, iostat_end, iostat_eor implicit none if (file_storage_size /= 8) call abort if (character_storage_size /= 8) call abort if (all (numeric_storage_size /= [ 8, 16, 32, 64, 128])) call abort if (input_unit /= 5) call abort if (output_unit /= 6) call abort if (error_unit /= 0) call abort if (iostat_end /= -1) call abort if (iostat_eor /= -2) call abort end program test use , intrinsic :: iso_fortran_env, uu => output_unit implicit none if (input_unit /= 5 .or. uu /= 6) call abort call bar call bar2 end
gpl-2.0
QEF/q-e_schrodinger
PW/src/h_psi.f90
1
10060
! ! Copyright (C) 2002-2022 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !---------------------------------------------------------------------------- SUBROUTINE h_psi( lda, n, m, psi, hpsi ) !---------------------------------------------------------------------------- !! This routine computes the product of the Hamiltonian matrix with m !! wavefunctions contained in psi. ! !! \(\textit{Wrapper routine}\): performs bgrp parallelization on !! non-distributed bands. If suitable and required, calls old H\psi !! routine h_psi_ . ! USE kinds, ONLY: DP USE noncollin_module, ONLY: npol USE xc_lib, ONLY: exx_is_active USE mp_bands, ONLY: use_bgrp_in_hpsi, inter_bgrp_comm USE mp, ONLY: mp_allgather, mp_size, & mp_type_create_column_section, mp_type_free ! IMPLICIT NONE ! INTEGER, INTENT(IN) :: lda !! leading dimension of arrays psi, spsi, hpsi INTEGER, INTENT(IN) :: n !! true dimension of psi, spsi, hpsi INTEGER, INTENT(IN) :: m !! number of states psi COMPLEX(DP), INTENT(IN) :: psi(lda*npol,m) !! the wavefunction COMPLEX(DP), INTENT(OUT) :: hpsi(lda*npol,m) !! Hamiltonian dot psi ! ! ... local variables ! INTEGER :: m_start, m_end INTEGER :: column_type INTEGER, ALLOCATABLE :: recv_counts(:), displs(:) ! ! CALL start_clock( 'h_psi_bgrp' ); !write (*,*) 'start h_psi_bgrp'; FLUSH(6) ! ! band parallelization with non-distributed bands is performed if ! 1. enabled (variable use_bgrp_in_hpsi must be set to .T.) ! 2. exact exchange is not active (if it is, band parallelization is already ! used in exx routines called by Hpsi) ! 3. there is more than one band, otherwise there is nothing to parallelize ! IF (use_bgrp_in_hpsi .AND. .NOT. exx_is_active() .AND. m > 1) THEN ! ! use band parallelization here ALLOCATE( recv_counts(mp_size(inter_bgrp_comm)), displs(mp_size(inter_bgrp_comm)) ) CALL divide_all( inter_bgrp_comm, m, m_start, m_end, recv_counts,displs ) CALL mp_type_create_column_section( hpsi(1,1), 0, lda*npol, lda*npol, column_type ) ! ! Check if there at least one band in this band group IF (m_end >= m_start) & CALL h_psi_( lda, n, m_end-m_start+1, psi(1,m_start), hpsi(1,m_start) ) CALL mp_allgather( hpsi, column_type, recv_counts, displs, inter_bgrp_comm ) ! CALL mp_type_free( column_type ) DEALLOCATE( recv_counts ) DEALLOCATE( displs ) ! ELSE ! don't use band parallelization here CALL h_psi_( lda, n, m, psi, hpsi ) ! ENDIF ! CALL stop_clock( 'h_psi_bgrp' ) ! ! RETURN ! END SUBROUTINE h_psi ! !---------------------------------------------------------------------------- SUBROUTINE h_psi_( lda, n, m, psi, hpsi ) !---------------------------------------------------------------------------- !! This routine computes the product of the Hamiltonian matrix with m !! wavefunctions contained in psi. ! USE kinds, ONLY: DP USE bp, ONLY: lelfield, l3dstring, gdir, efield, efield_cry USE becmod, ONLY: bec_type, becp, calbec USE lsda_mod, ONLY: current_spin USE scf, ONLY: vrs USE wvfct, ONLY: g2kin USE uspp, ONLY: vkb, nkb USE ldaU, ONLY: lda_plus_u, Hubbard_projectors USE gvect, ONLY: gstart USE control_flags, ONLY: gamma_only USE noncollin_module, ONLY: npol, noncolin USE realus, ONLY: real_space, invfft_orbital_gamma, fwfft_orbital_gamma, & calbec_rs_gamma, add_vuspsir_gamma, invfft_orbital_k, & fwfft_orbital_k, calbec_rs_k, add_vuspsir_k, & v_loc_psir_inplace USE fft_base, ONLY: dffts USE exx, ONLY: use_ace, vexx, vexxace_gamma, vexxace_k USE xc_lib, ONLY: exx_is_active, xclib_dft_is USE fft_helper_subroutines ! USE wvfct_gpum, ONLY: using_g2kin USE scf_gpum, ONLY: using_vrs USE becmod_subs_gpum, ONLY: using_becp_auto ! IMPLICIT NONE ! INTEGER, INTENT(IN) :: lda !! leading dimension of arrays psi, spsi, hpsi INTEGER, INTENT(IN) :: n !! true dimension of psi, spsi, hpsi INTEGER, INTENT(IN) :: m !! number of states psi COMPLEX(DP), INTENT(IN) :: psi(lda*npol,m) !! the wavefunction COMPLEX(DP), INTENT(OUT) :: hpsi(lda*npol,m) !! Hamiltonian dot psi ! ! ... local variables ! INTEGER :: ipol, ibnd REAL(DP) :: ee ! ! CALL start_clock( 'h_psi' ); !write (*,*) 'start h_psi';FLUSH(6) CALL using_g2kin(0) CALL using_vrs(0) ! vloc_psi_gamma (intent:in) ! ! ... Here we set the kinetic energy (k+G)^2 psi and clean up garbage ! !$omp parallel do DO ibnd = 1, m hpsi(1:n,ibnd) = g2kin(1:n) * psi(1:n,ibnd) IF (n<lda) hpsi(n+1:lda, ibnd) = (0.0_dp, 0.0_dp) IF ( noncolin ) THEN hpsi(lda+1:lda+n, ibnd) = g2kin(1:n) * psi(lda+1:lda+n, ibnd) IF (n<lda) hpsi(lda+n+1:lda+lda, ibnd) = (0.0_dp, 0.0_dp) ENDIF ENDDO !$omp end parallel do CALL start_clock( 'h_psi:pot' ); !write (*,*) 'start h_psi:pot';FLUSH(6) ! ! ... Here the product with the local potential V_loc psi ! IF ( gamma_only ) THEN ! IF ( real_space .AND. nkb > 0 ) THEN CALL using_becp_auto(1) ! ! ... real-space algorithm ! ... fixme: real_space without beta functions does not make sense ! IF ( dffts%has_task_groups ) & CALL errore( 'h_psi', 'task_groups not implemented with real_space', 1 ) DO ibnd = 1, m, 2 ! ... transform psi to real space -> psic CALL invfft_orbital_gamma( psi, ibnd, m ) ! ... compute becp%r = < beta|psi> from psic in real space CALL start_clock( 'h_psi:calbec' ) CALL calbec_rs_gamma( ibnd, m, becp%r ) CALL stop_clock( 'h_psi:calbec' ) ! ... psic -> vrs * psic (psic overwritten will become hpsi) CALL v_loc_psir_inplace( ibnd, m ) ! ... psic (hpsi) -> psic + vusp CALL add_vuspsir_gamma( ibnd, m ) ! ... transform psic back in reciprocal space and add it to hpsi CALL fwfft_orbital_gamma( hpsi, ibnd, m, add_to_orbital=.TRUE. ) ENDDO ! ELSE ! ... usual reciprocal-space algorithm CALL vloc_psi_gamma( lda, n, m, psi, vrs(1,current_spin), hpsi ) ! ENDIF ! ELSEIF ( noncolin ) THEN ! CALL vloc_psi_nc( lda, n, m, psi, vrs, hpsi ) ! ELSE ! IF ( real_space .AND. nkb > 0 ) THEN ! ! ... real-space algorithm ! ... fixme: real_space without beta functions does not make sense ! CALL using_becp_auto(1) ! WHY IS THIS HERE? IF ( dffts%has_task_groups ) & CALL errore( 'h_psi', 'task_groups not implemented with real_space', 1 ) ! DO ibnd = 1, m ! ... transform psi to real space -> psic CALL invfft_orbital_k( psi, ibnd, m ) ! ... compute becp%r = < beta|psi> from psic in real space CALL start_clock( 'h_psi:calbec' ) CALL calbec_rs_k( ibnd, m ) CALL stop_clock( 'h_psi:calbec' ) ! ... psic -> vrs * psic (psic overwritten will become hpsi) CALL v_loc_psir_inplace( ibnd, m ) ! ... psic (hpsi) -> psic + vusp CALL add_vuspsir_k( ibnd, m ) ! ... transform psic back in reciprocal space and add it to hpsi CALL fwfft_orbital_k( hpsi, ibnd, m, add_to_orbital=.TRUE. ) ! ENDDO ! ELSE ! CALL vloc_psi_k( lda, n, m, psi, vrs(1,current_spin), hpsi ) ! ENDIF ! ENDIF ! ! ... Here the product with the non local potential V_NL psi ! ... (not in the real-space case: it is done together with V_loc) ! IF ( nkb > 0 .AND. .NOT. real_space) THEN ! CALL using_becp_auto(1) ! CALL start_clock( 'h_psi:calbec' ) CALL calbec( n, vkb, psi, becp, m ) CALL stop_clock( 'h_psi:calbec' ) CALL add_vuspsi( lda, n, m, hpsi ) ! ENDIF ! CALL stop_clock( 'h_psi:pot' ); !write (*,*) 'stop h_psi:pot';FLUSH(6) ! IF (xclib_dft_is('meta')) CALL h_psi_meta( lda, n, m, psi, hpsi ) ! ! ... Here we add the Hubbard potential times psi ! IF ( lda_plus_u .AND. Hubbard_projectors.NE."pseudo" ) THEN ! IF ( noncolin ) THEN CALL vhpsi_nc( lda, n, m, psi, hpsi ) ELSE CALL vhpsi( lda, n, m, psi, hpsi ) ENDIF ! ENDIF ! ! ... Here the exact-exchange term Vxx psi ! IF ( exx_is_active() ) THEN IF ( use_ace ) THEN IF ( gamma_only ) THEN CALL vexxace_gamma( lda, m, psi, ee, hpsi ) ELSE CALL vexxace_k( lda, m, psi, ee, hpsi ) ENDIF ELSE CALL using_becp_auto(0) CALL vexx( lda, n, m, psi, hpsi, becp ) ENDIF ENDIF ! ! ... electric enthalpy if required ! IF ( lelfield ) THEN ! IF ( .NOT.l3dstring ) THEN CALL h_epsi_her_apply( lda, n, m, psi, hpsi,gdir, efield ) ELSE DO ipol = 1, 3 CALL h_epsi_her_apply( lda, n, m, psi, hpsi,ipol,efield_cry(ipol) ) ENDDO ENDIF ! ENDIF ! ! ... With Gamma-only trick, Im(H*psi)(G=0) = 0 by definition, ! ... but it is convenient to explicitly set it to 0 to prevent trouble ! IF ( gamma_only .AND. gstart == 2 ) & hpsi(1,1:m) = CMPLX( DBLE( hpsi(1,1:m) ), 0.D0, KIND=DP) ! CALL stop_clock( 'h_psi' ) ! ! RETURN ! END SUBROUTINE h_psi_
gpl-2.0
yangf4/phasta
phSolver/compressible/itrfdi.f
1
8406
subroutine itrFDI (ypre, y, ac, x, & rmes, uBrg, BDiag, & iBC, BC, iper, & ilwork, shp, shgl, & shpb, shglb) c c---------------------------------------------------------------------- c c This subroutine computes the "optimum" finite difference c interval eps for the forward difference scheme c c Rmod(y + eps u) - Rmod(y) c --------------------------- c eps c c where u is the step and Rmod is the modified residual. c c Note: A good theoretical reference is 'Practical Optimization' by c P.E. Gill, W. Murray and M.H. Wright [1981]. c c input: c y (nshg,ndof) : Y-variables c ypre (nshg,ndof) : preconditioned Y-variables c x (numnp,nsd) : node coordinates c rmes (nshg,nflow) : modified residual c uBrg (nshg,nflow) : step c BDiag (nshg,nflow,nflow) : block-diagonal preconditioner c iBC (nshg) : BC codes c BC (nshg,ndofBC) : BC constraint parameters c c c c Zdenek Johan, Winter 1989. c Zdenek Johan, Winter 1991. (Fortran 90) c---------------------------------------------------------------------- c include "common.h" c dimension y(nshg,ndof), ypre(nshg,nflow), & x(numnp,nsd), ac(nshg,ndof), & rmes(nshg,nflow), & uBrg(nshg,nflow), BDiag(nshg,nflow,nflow), & iBC(nshg), BC(nshg,ndofBC), & ilwork(nlwork), & iper(nshg) c dimension ytmp(nshg,nflow), rtmp(nshg,nflow) dimension tmpy(nshg,ndof) c dimension shp(MAXTOP,maxsh,MAXQPT), & shgl(MAXTOP,nsd,maxsh,MAXQPT), & shpb(MAXTOP,maxsh,MAXQPT), & shglb(MAXTOP,nsd,maxsh,MAXQPT) c c.... compute the accuracy (cancellation error) -> epsA c rtmp = zero c ytmp = ypre c c call yshuffle(ytmp, 'new2old ') c call i3LU (BDiag, ytmp, 'backward') c call yshuffle(ytmp, 'old2new ') c iabres = 1 c call itrRes (ytmp, y, & x, shp, & shgl, iBC, & BC, shpb, & shglb, rtmp, & iper, ilwork, & ac) c iabres = 0 c call i3LU (BDiag, rtmp, 'forward ') c rtmp = rtmp**2 call sumgat (rtmp, nflow, summed, ilwork) epsA = (epsM**2) * sqrt(summed) c c.... compute the norm of the second derivative (truncation error) c c.... set interval c epsSD = sqrt(epsM) c c.... compute the first residual c rtmp = zero c c call yshuffle(ypre, 'new2old ') c ytmp = ypre + epsSD * uBrg c call i3LU (BDiag, ytmp, 'backward') c call yshuffle(ytmp, 'old2new ') c call itrRes (ytmp, y, & x, shp, & shgl, iBC, & BC, shpb, & shglb, rtmp, & iper, ilwork, ac) !Added ac to the end if itrRes, but not tested - Nicholas c c.... compute the second residual and add it to the first one c ytmp = ypre - epsSD * uBrg c c call yshuffle(ypre, 'old2new ') c call i3LU (BDiag, ytmp, 'backward') c call yshuffle(ytmp, 'old2new ') call itrRes (ytmp, y, & x, shp, & shgl, iBC, & BC, shpb, & shglb, rtmp, & iper, ilwork, ac) !Added ac to the end if itrRes, but not tested - Nicholas c call i3LU (BDiag, rtmp, 'forward ') c c.... compute the second derivative and its norm c rtmp = (( rtmp - two * rmes ) / epsM)**2 c call sumgat (rtmp, nflow, summed, ilwork) SDnrm = sqrt(summed) c c.... compute the 'optimum' interval c eGMRES = two * sqrt( epsA / SDnrm ) c c.... flop count c ! flops = flops + 10*nflow*nshg+3*nshg c c.... end c return end subroutine itrFDISclr (y, ypre, x, & rmes, uBrg, BDiag, & iBC, BC, engBC, iper, & ilwork) c c---------------------------------------------------------------------- c c This subroutine computes the "optimum" finite difference c interval eps for the forward difference scheme c c Rmod(y + eps u) - Rmod(y) c --------------------------- c eps c c where u is the step and Rmod is the modified residual. c c Note: A good theoretical reference is 'Practical Optimization' by c P.E. Gill, W. Murray and M.H. Wright [1981]. c c input: c y (nshg,ndof) : Y-variables c ypre (nshg,ndof) : preconditioned Y-variables c x (numnp,nsd) : node coordinates c rmes (nshg,nflow) : modified residual c uBrg (nshg,nflow) : step c BDiag (nshg,nflow,nflow) : block-diagonal preconditioner c iBC (nshg) : BC codes c BC (nshg,ndofBC) : BC constraint parameters c engBC (nshg) : energy for BC on density or pressure c c c Zdenek Johan, Winter 1989. c Zdenek Johan, Winter 1991. (Fortran 90) c---------------------------------------------------------------------- c include "common.h" c dimension y(nshg,ndof), ypre(nshg,ndof), & x(numnp,nsd), & rmes(nshg,nflow), & uBrg(nshg,nflow), BDiag(nshg,nflow,nflow), & iBC(nshg), BC(nshg,ndofBC), & engBC(nshg), ilwork(nlwork), & iper(nshg) c dimension ytmp(nshg,ndof), rtmp(nshg,nflow) c c.... compute the accuracy (cancellation error) -> epsA c rtmp = zero c ytmp = ypre c c call tnanq(ytmp,ndof,"ytmp ") iabres = 1 c call itrRes (ytmp, y, & x, a(mshp), & a(mshgl), a(mwght), iBC, & BC, engBC, a(mshpb), & a(mshglb), a(mwghtb), rtmp, & iper, ilwork, ac) !Added ac to the end if itrRes, but not tested - Nicholas c iabres = 0 c rtmp = rtmp**2 call sumgat (rtmp, nflow, summed, ilwork) epsA = (epsM**2) * sqrt(summed) c c.... compute the norm of the second derivative (truncation error) c c.... set interval c epsSD = sqrt(epsM) c c.... compute the first residual c rtmp = zero c ytmp = ypre + epsSD * uBrg c call itrRes (ytmp, y, & x, a(mshp), & a(mshgl), a(mwght), iBC, & BC, engBC, a(mshpb), & a(mshglb), a(mwghtb), rtmp, & iper, ilwork, ac) !Added ac to the end if itrRes, but not tested - Nicholas c c.... compute the second residual and add it to the first one c ytmp = ypre - epsSD * uBrg c call itrRes (ytmp, y, & x, a(mshp), & a(mshgl), a(mwght), iBC, & BC, engBC, a(mshpb), & a(mshglb), a(mwghtb), rtmp, & iper, ilwork, ac) !Added ac to the end if itrRes, but not tested - Nicholas c c.... compute the second derivative and its norm c rtmp = (( rtmp - two * rmes ) / epsM)**2 c call sumgat (rtmp, nflow, summed, ilwork) SDnrm = sqrt(summed) c c.... compute the 'optimum' interval c eGMRES = two * sqrt( epsA / SDnrm ) c c.... flop count c ! flops = flops + 10*nflow*nshg+3*nshg c c.... end c return end
bsd-3-clause
piyush0609/scipy
scipy/interpolate/fitpack/cualde.f
148
3040
subroutine cualde(idim,t,n,c,nc,k1,u,d,nd,ier) c subroutine cualde evaluates at the point u all the derivatives c (l) c d(idim*l+j) = sj (u) ,l=0,1,...,k, j=1,2,...,idim c of a spline curve s(u) of order k1 (degree k=k1-1) and dimension idim c given in its b-spline representation. c c calling sequence: c call cualde(idim,t,n,c,nc,k1,u,d,nd,ier) c c input parameters: c idim : integer, giving the dimension of the spline curve. c t : array,length n, which contains the position of the knots. c n : integer, giving the total number of knots of s(u). c c : array,length nc, which contains the b-spline coefficients. c nc : integer, giving the total number of coefficients of s(u). c k1 : integer, giving the order of s(u) (order=degree+1). c u : real, which contains the point where the derivatives must c be evaluated. c nd : integer, giving the dimension of the array d. nd >= k1*idim c c output parameters: c d : array,length nd,giving the different curve derivatives. c d(idim*l+j) will contain the j-th coordinate of the l-th c derivative of the curve at the point u. c ier : error flag c ier = 0 : normal return c ier =10 : invalid input data (see restrictions) c c restrictions: c nd >= k1*idim c t(k1) <= u <= t(n-k1+1) c c further comments: c if u coincides with a knot, right derivatives are computed c ( left derivatives if u = t(n-k1+1) ). c c other subroutines required: fpader. c c references : c de boor c : on calculating with b-splines, j. approximation theory c 6 (1972) 50-62. c cox m.g. : the numerical evaluation of b-splines, j. inst. maths c applics 10 (1972) 134-149. c dierckx p. : curve and surface fitting with splines, monographs on c numerical analysis, oxford university press, 1993. c c author : c p.dierckx c dept. computer science, k.u.leuven c celestijnenlaan 200a, b-3001 heverlee, belgium. c e-mail : Paul.Dierckx@cs.kuleuven.ac.be c c latest update : march 1987 c c ..scalar arguments.. integer idim,n,nc,k1,nd,ier real*8 u c ..array arguments.. real*8 t(n),c(nc),d(nd) c ..local scalars.. integer i,j,kk,l,m,nk1 c ..local array.. real*8 h(6) c .. c before starting computations a data check is made. if the input data c are invalid control is immediately repassed to the calling program. ier = 10 if(nd.lt.(k1*idim)) go to 500 nk1 = n-k1 if(u.lt.t(k1) .or. u.gt.t(nk1+1)) go to 500 c search for knot interval t(l) <= u < t(l+1) l = k1 100 if(u.lt.t(l+1) .or. l.eq.nk1) go to 200 l = l+1 go to 100 200 if(t(l).ge.t(l+1)) go to 500 ier = 0 c calculate the derivatives. j = 1 do 400 i=1,idim call fpader(t,n,c(j),k1,u,l,h) m = i do 300 kk=1,k1 d(m) = h(kk) m = m+idim 300 continue j = j+n 400 continue 500 return end
bsd-3-clause
LucasGandel/ITK
Modules/ThirdParty/VNL/src/vxl/v3p/netlib/blas/sdot.f
55
1229
real function sdot(n,sx,incx,sy,incy) c c forms the dot product of two vectors. c uses unrolled loops for increments equal to one. c jack dongarra, linpack, 3/11/78. c modified 12/3/93, array(1) declarations changed to array(*) c real sx(*),sy(*),stemp integer i,incx,incy,ix,iy,m,mp1,n c stemp = 0.0e0 sdot = 0.0e0 if(n.le.0)return if(incx.eq.1.and.incy.eq.1)go to 20 c c code for unequal increments or equal increments c not equal to 1 c ix = 1 iy = 1 if(incx.lt.0)ix = (-n+1)*incx + 1 if(incy.lt.0)iy = (-n+1)*incy + 1 do 10 i = 1,n stemp = stemp + sx(ix)*sy(iy) ix = ix + incx iy = iy + incy 10 continue sdot = stemp return c c code for both increments equal to 1 c c c clean-up loop c 20 m = mod(n,5) if( m .eq. 0 ) go to 40 do 30 i = 1,m stemp = stemp + sx(i)*sy(i) 30 continue if( n .lt. 5 ) go to 60 40 mp1 = m + 1 do 50 i = mp1,n,5 stemp = stemp + sx(i)*sy(i) + sx(i + 1)*sy(i + 1) + * sx(i + 2)*sy(i + 2) + sx(i + 3)*sy(i + 3) + sx(i + 4)*sy(i + 4) 50 continue 60 sdot = stemp return end
apache-2.0
aidanheerdegen/MOM6
src/core/MOM_PressureForce.F90
1
8767
module MOM_PressureForce !*********************************************************************** !* GNU General Public License * !* This file is a part of MOM. * !* * !* MOM is free software; you can redistribute it and/or modify it and * !* are expected to follow the terms of the GNU General Public License * !* as published by the Free Software Foundation; either version 2 of * !* the License, or (at your option) any later version. * !* * !* MOM is distributed in the hope that it will be useful, but WITHOUT * !* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * !* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * !* License for more details. * !* * !* For the full text of the GNU General Public License, * !* write to: Free Software Foundation, Inc., * !* 675 Mass Ave, Cambridge, MA 02139, USA. * !* or see: http://www.gnu.org/licenses/gpl.html * !*********************************************************************** !********+*********+*********+*********+*********+*********+*********+** !* * !* By Robert Hallberg, April 1994 - June 2008 * !* * !* This file contains the subroutine that directs the model to use * !* the code that determines the horizontal accelerations due to * !* pressure gradients. The two options currently available are a * !* traditional Montgomery potential form, and the analytic finite * !* volume form described in Adcroft, Hallberg and Harrison, 2008, * !* Ocean Modelling, 22, 106-113. * !* * !* PressureForce takes 9 arguments, which are described below. If * !* a non-split time stepping scheme is used, the last three arguments * !* are ignored. * !* * !* Macros written all in capital letters are defined in MOM_memory.h. * !* * !* A small fragment of the grid is shown below: * !* * !* j+1 x ^ x ^ x At x: q, CoriolisBu * !* j+1 > o > o > At ^: v, PFv * !* j x ^ x ^ x At >: u, PFu * !* j > o > o > At o: h, bathyT, M, e, p, pbce, T, S * !* j-1 x ^ x ^ x * !* i-1 i i+1 * !* i i+1 * !* * !* The boundaries always run through q grid points (x). * !* * !********+*********+*********+*********+*********+*********+*********+** use MOM_diag_mediator, only : diag_ctrl, time_type use MOM_error_handler, only : MOM_error, MOM_mesg, FATAL, WARNING, is_root_pe use MOM_file_parser, only : get_param, log_version, param_file_type use MOM_grid, only : ocean_grid_type use MOM_PressureForce_AFV, only : PressureForce_AFV_Bouss, PressureForce_AFV_nonBouss use MOM_PressureForce_AFV, only : PressureForce_AFV_init, PressureForce_AFV_CS use MOM_PressureForce_Mont, only : PressureForce_Mont_Bouss, PressureForce_Mont_nonBouss use MOM_PressureForce_Mont, only : PressureForce_Mont_init, PressureForce_Mont_CS use MOM_tidal_forcing, only : calc_tidal_forcing, tidal_forcing_CS use MOM_variables, only : thermo_var_ptrs use MOM_ALE, only: ALE_CS implicit none ; private #include <MOM_memory.h> public PressureForce, PressureForce_init, PressureForce_end type, public :: PressureForce_CS ; private logical :: Analytic_FV_PGF ! If true, use the analytic finite volume form ! (Adcroft et al., Ocean Mod. 2008) of the PGF. type(PressureForce_AFV_CS), pointer :: PressureForce_AFV_CSp => NULL() type(PressureForce_Mont_CS), pointer :: PressureForce_Mont_CSp => NULL() end type PressureForce_CS contains subroutine PressureForce(h, tv, PFu, PFv, G, CS, ALE_CSp, p_atm, pbce, eta) real, dimension(NIMEM_,NJMEM_,NKMEM_), intent(in) :: h type(thermo_var_ptrs), intent(in) :: tv real, dimension(NIMEMB_,NJMEM_,NKMEM_), intent(out) :: PFu real, dimension(NIMEM_,NJMEMB_,NKMEM_), intent(out) :: PFv type(ocean_grid_type), intent(in) :: G type(PressureForce_CS), pointer :: CS type(ALE_CS), pointer :: ALE_CSp real, dimension(:,:), optional, pointer :: p_atm real, dimension(NIMEM_,NJMEM_,NKMEM_), optional, intent(out) :: pbce real, dimension(NIMEM_,NJMEM_), optional, intent(out) :: eta ! This subroutine works as a temporary interface between the model and the ! Boussinesq and non-Boussinesq pressure force routines. ! Descriptions of the variables are in each of the routines called in the ! following conditional block. if (CS%Analytic_FV_PGF) then if (G%Boussinesq) then call PressureForce_AFV_Bouss(h, tv, PFu, PFv, G, CS%PressureForce_AFV_CSp, & ALE_CSp, p_atm, pbce, eta) else call PressureForce_AFV_nonBouss(h, tv, PFu, PFv, G, CS%PressureForce_AFV_CSp, & p_atm, pbce, eta) endif else if (G%Boussinesq) then call PressureForce_Mont_Bouss(h, tv, PFu, PFv, G, CS%PressureForce_Mont_CSp, & p_atm, pbce, eta) else call PressureForce_Mont_nonBouss(h, tv, PFu, PFv, G, CS%PressureForce_Mont_CSp, & p_atm, pbce, eta) endif endif end subroutine Pressureforce subroutine PressureForce_init(Time, G, param_file, diag, CS, tides_CSp) type(time_type), target, intent(in) :: Time type(ocean_grid_type), intent(in) :: G type(param_file_type), intent(in) :: param_file type(diag_ctrl), target, intent(inout) :: diag type(PressureForce_CS), pointer :: CS type(tidal_forcing_CS), optional, pointer :: tides_CSp ! Arguments: Time - The current model time. ! (in) G - The ocean's grid structure. ! (in) param_file - A structure indicating the open file to parse for ! model parameter values. ! (in) diag - A structure that is used to regulate diagnostic output. ! (in/out) CS - A pointer that is set to point to the control structure ! for this module. ! (in) tides_CSp - a pointer to the control structure of the tide module. ! This include declares and sets the variable "version". #include "version_variable.h" character(len=40) :: mod = "MOM_PressureForce" ! This module's name. if (associated(CS)) then call MOM_error(WARNING, "PressureForce_init called with an associated "// & "control structure.") return else ; allocate(CS) ; endif ! Read all relevant parameters and write them to the model log. call log_version(param_file, mod, version) call get_param(param_file, mod, "ANALYTIC_FV_PGF", CS%Analytic_FV_PGF, & "If true the pressure gradient forces are calculated \n"//& "with a finite volume form that analytically integrates \n"//& "the equations of state in pressure to avoid any \n"//& "possibility of numerical thermobaric instability, as \n"//& "described in Adcroft et al., O. Mod. (2008).", default=.true.) if (CS%Analytic_FV_PGF) then call PressureForce_AFV_init(Time, G, param_file, diag, & CS%PressureForce_AFV_CSp, tides_CSp) else call PressureForce_Mont_init(Time, G, param_file, diag, & CS%PressureForce_Mont_CSp, tides_CSp) endif end subroutine PressureForce_init subroutine PressureForce_end(CS) type(PressureForce_CS), pointer :: CS if (associated(CS)) deallocate(CS) end subroutine PressureForce_end end module MOM_PressureForce
gpl-3.0
skywalker00/sabermod_rom_toolchain
gcc/testsuite/gfortran.dg/used_before_typed_1.f90
193
1320
! { dg-do compile } ! { dg-options "-std=f95" } ! PR fortran/32095 ! PR fortran/34228 ! Check that standards-conforming mode rejects uses of variables that ! are used before they are typed. SUBROUTINE test1 (n, arr, m, arr2, k, arr3, a) ! { dg-error "has no IMPLICIT" } IMPLICIT NONE INTEGER :: arr(n) ! { dg-error "used before it is typed" } INTEGER :: n INTEGER :: m, arr2(m) ! { dg-bogus "used before it is typed" } INTEGER, DIMENSION(k) :: arr3 ! { dg-error "used before it is typed" } INTEGER :: k CHARACTER(len=LEN(a)) :: a ! { dg-error "'a' is used before it is typed" } REAL(KIND=l) :: x ! { dg-error "has no IMPLICIT type" } REAL(KIND=KIND(y)) :: y ! { dg-error "has no IMPLICIT type" } DATA str/'abc'/ ! { dg-error "used before it is typed" } CHARACTER(len=3) :: str, str2 DATA str2/'abc'/ ! { dg-bogus "used before it is typed" } END SUBROUTINE test1 SUBROUTINE test2 (n, arr, m, arr2) IMPLICIT INTEGER(a-z) INTEGER :: arr(n) REAL :: n ! { dg-error "already has basic type" } INTEGER :: m, arr2(m) ! { dg-bogus "already has an IMPLICIT type" } END SUBROUTINE test2 SUBROUTINE test3 (n, arr, m, arr2) IMPLICIT REAL(a-z) INTEGER :: arr(n) ! { dg-error "must be of INTEGER type" } INTEGER :: m, arr2(m) ! { dg-bogus "must be of INTEGER type" } END SUBROUTINE test3
gpl-2.0
QEF/q-e_schrodinger
LR_Modules/lr_dot_magnons.f90
2
3012
! ! Copyright (C) 2021 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !----------------------------------------------------------------------- FUNCTION lr_dot_magnons(x,y) !--------------------------------------------------------------------- ! ! Extension of lr_dot.f90 to magnons ! USE kinds, ONLY : dp USE io_global, ONLY : stdout USE klist, ONLY : nks, xk, wk, ngk USE lsda_mod, ONLY : nspin USE wvfct, ONLY : npwx,nbnd,wg USE gvecw, ONLY : gcutw USE control_flags, ONLY : gamma_only USE gvect, ONLY : gstart, ngm, g USE mp, ONLY : mp_sum USE mp_global, ONLY : inter_pool_comm, intra_bgrp_comm USE noncollin_module, ONLY : noncolin, npol USE control_lr, ONLY : nbnd_occ, nbnd_occx USE qpoint, ONLY : nksq ! IMPLICIT NONE ! COMPLEX(kind=dp) :: x(npwx*npol,nbnd_occx,nksq,2), & y(npwx*npol,nbnd_occx,nksq,2) COMPLEX(kind=dp) :: lr_dot_magnons REAL(kind=dp) :: degspin INTEGER :: ibnd, ik ! CALL start_clock ('lr_dot_magnons') ! lr_dot_magnons = (0.0d0,0.0d0) ! IF (nspin==2) THEN degspin = 1.0d0 ELSE degspin = 2.0d0 ENDIF IF (noncolin) degspin = 1.0d0 ! CALL lr_dot_k_magnons() ! ! lr_dot_magnons = lr_dot_magnons/degspin ! CALL stop_clock ('lr_dot_magnons') ! RETURN ! CONTAINS ! SUBROUTINE lr_dot_k_magnons ! ! MAGNONS ! Noncollinear case is implemented ! USE qpoint, ONLY : ikks, ikqs ! IMPLICIT NONE INTEGER :: ios INTEGER :: ik, & ikk, & ! index of the point k ikq, & ! index of the point k+q npwq, &! number of the plane-waves at point k+q imk ! DO ik = 1, nksq ! ikk = ikks(ik) ikq = ikqs(ik) npwq = ngk(ikq) ! IF ( mod(ik,2) == 0) THEN imk = ikk - 3 ! position of -k ELSE imk = ikk + 3 ! position of -k ENDIF ! ! Resonant part (upper batch) ! DO ibnd = 1, nbnd_occ(ikk) ! lr_dot_magnons = lr_dot_magnons + wk(ikk) * & dot_product(x(:,ibnd,ik,1),y(:,ibnd,ik,1)) ! ENDDO ! ! Anti - Resonant part (lower batch) ! DO ibnd = 1, nbnd_occ(imk) ! lr_dot_magnons = lr_dot_magnons + wk(imk) * & dot_product(x(:,ibnd,ik,2),y(:,ibnd,ik,2)) ! ENDDO ! ENDDO ! #if defined(__MPI) CALL mp_sum(lr_dot_magnons, intra_bgrp_comm) CALL mp_sum(lr_dot_magnons, inter_pool_comm) #endif ! RETURN ! END SUBROUTINE lr_dot_k_magnons ! END FUNCTION lr_dot_magnons
gpl-2.0
QEF/q-e_schrodinger
PW/src/init_nsg.f90
1
4463
! ! Copyright (C) 2001-2022 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !----------------------------------------------------------------------- SUBROUTINE init_nsg !----------------------------------------------------------------------- ! ! This routine computes the starting ns (for DFT+U+V calculation) filling ! up the Hubbard manifold (we are only interested in the on-site potential ! for the moment) according to the Hund's rule (valid for the isolated atoms ! on which starting potential is built), and to the starting_magnetization: ! majority spin levels are populated first, then the remaining electrons ! are equally distributed among the minority spin states ! USE kinds, ONLY : DP USE ions_base, ONLY : nat, ityp USE uspp_param, ONLY : upf USE lsda_mod, ONLY : nspin, starting_magnetization USE ldaU, ONLY : Hubbard_l, Hubbard_l2, Hubbard_l3, hubbard_occ, & nsg, ldim_u, backall, is_hubbard, is_hubbard_back ! IMPLICIT NONE REAL(DP) :: totoc, totoc_b INTEGER :: ldim, ldim2, na, nt, is, m1, majs, mins, viz LOGICAL :: nm ! true if the atom is non-magnetic INTEGER, EXTERNAL :: find_viz ! nsg(:,:,:,:,:) = (0.d0, 0.d0) ! DO na = 1, nat ! ! The index of atom 'na' in the neighbors list ! viz = find_viz(na,na) ! nt = ityp(na) ! IF ( is_hubbard(nt) ) THEN ! ldim = 2*Hubbard_l(nt)+1 nm = .TRUE. ! IF (hubbard_occ(nt,1)<0.0d0) CALL determine_hubbard_occ(nt,1) totoc = hubbard_occ(nt,1) ! IF (nspin.EQ.2) THEN IF (starting_magnetization(nt).GT.0.d0) THEN nm = .FALSE. majs = 1 mins = 2 ELSEIF (starting_magnetization(nt).LT.0.d0) THEN nm = .FALSE. majs = 2 mins = 1 ENDIF ENDIF ! IF (.NOT.nm) THEN ! Atom is magnetic IF (totoc.GT.ldim) THEN DO m1 = 1, ldim nsg (m1,m1,viz,na,majs) = 1.d0 nsg (m1,m1,viz,na,mins) = (totoc - ldim) / ldim ENDDO ELSE DO m1 = 1, ldim nsg (m1,m1,viz,na,majs) = totoc / ldim ENDDO ENDIF ELSE ! Atom is non-magnetic DO is = 1, nspin DO m1 = 1, ldim nsg (m1,m1,viz,na,is) = totoc / 2.d0 / ldim ENDDO ENDDO ENDIF ! ! Background part ! IF ( is_hubbard_back(nt) ) THEN ! IF (.NOT.backall(nt)) THEN ! Fill in the second Hubbard manifold ldim2 = 2*Hubbard_l2(nt)+1 IF (hubbard_occ(nt,2)<0.0d0) CALL determine_hubbard_occ(nt,2) totoc_b = hubbard_occ(nt,2) DO is = 1, nspin DO m1 = ldim+1, ldim_u(nt) nsg (m1,m1,viz,na,is) = totoc_b / 2.d0 / ldim2 ENDDO ENDDO ELSE ! Fill in the second Hubbard manifold ldim2 = 2*Hubbard_l2(nt)+1 IF (hubbard_occ(nt,2)<0.0d0) CALL determine_hubbard_occ(nt,2) totoc_b = hubbard_occ(nt,2) DO is = 1, nspin DO m1 = ldim+1, ldim+2*Hubbard_l2(nt)+1 nsg (m1,m1,viz,na,is) = totoc_b / 2.d0 / ldim2 ENDDO ENDDO ! Fill in the third Hubbard manifold ldim2 = 2*(Hubbard_l2(nt) + Hubbard_l3(nt)) + 2 IF (hubbard_occ(nt,3)<0.0d0) CALL determine_hubbard_occ(nt,3) totoc_b = hubbard_occ(nt,3) DO is = 1, nspin DO m1 = ldim+2*Hubbard_l2(nt)+2, ldim_u(nt) nsg (m1,m1,viz,na,is) = totoc_b / 2.d0 / ldim2 ENDDO ENDDO ENDIF ! ENDIF ! ENDIF ! ENDDO ! na ! RETURN ! END SUBROUTINE init_nsg !-----------------------------------------------------------------------
gpl-2.0
skywalker00/sabermod_rom_toolchain
gcc/testsuite/gfortran.dg/g77/980519-2.f
209
1605
c { dg-do compile } * Date: Fri, 17 Apr 1998 14:12:51 +0200 * From: Jean-Paul Jeannot <jeannot@gx-tech.fr> * Organization: GX Technology France * To: egcs-bugs@cygnus.com * Subject: identified bug in g77 on Alpha * * Dear Sir, * * You will find below the assembly code of a simple Fortran routine which * crashes with segmentation fault when storing the first element * in( jT_f-hd_T ) = Xsp * whereas everything is fine when commenting this line. * * The assembly code (generated with * -ffast-math -fexpensive-optimizations -fomit-frame-pointer -fno-inline * or with -O5) * uses a zapnot instruction to copy an address. * BUT the zapnot parameter is 15 (copuing 4 bytes) instead of 255 (to copy * 8 bytes). * * I guess this is typically a 64 bit issue. As, from my understanding, * zapnots are used a lot to copy registers, this may create problems * elsewhere. * * Thanks for your help * * Jean-Paul Jeannot * subroutine simul_trace( in, Xsp, Ysp, Xrcv, Yrcv ) c Next declaration added on transfer to gfortran testsuite integer hd_S, hd_Z, hd_T common /Idim/ jT_f, jT_l, nT, nT_dim common /Idim/ jZ_f, jZ_l, nZ, nZ_dim common /Idim/ jZ2_f, jZ2_l, nZ2, nZ2_dim common /Idim/ jzs_f, jzs_l, nzs, nzs_dim, l_amp common /Idim/ hd_S, hd_Z, hd_T common /Idim/ nlay, nlayz common /Idim/ n_work common /Idim/ nb_calls real Xsp, Ysp, Xrcv, Yrcv real in( jT_f-hd_T : jT_l ) in( jT_f-hd_T ) = Xsp in( jT_f-hd_T + 1 ) = Ysp in( jT_f-hd_T + 2 ) = Xrcv in( jT_f-hd_T + 3 ) = Yrcv end
gpl-2.0
piyush0609/scipy
scipy/linalg/src/det.f
121
4747
c Calculate determinant of square matrix c Author: Pearu Peterson, March 2002 c c prefixes: d,z,s,c (double,complex double,float,complex float) c suffixes: _c,_r (column major order,row major order) subroutine ddet_c(det,a,n,piv,info) integer n,piv(n),i double precision det,a(n,n) cf2py intent(in,copy) :: a cf2py intent(out) :: det,info cf2py integer intent(hide,cache),depend(n),dimension(n) :: piv cf2py integer intent(hide),depend(a) :: n = shape(a,0) cf2py check(shape(a,0)==shape(a,1)) :: a cf2py callprotoargument double*,double*,int*,int*,int* external dgetrf call dgetrf(n,n,a,n,piv,info) det = 0d0 if (info.ne.0) then return endif det = 1d0 do 10,i=1,n if (piv(i).ne.i) then det = -det * a(i,i) else det = det * a(i,i) endif 10 continue end subroutine ddet_r(det,a,n,piv,info) integer n,piv(n) double precision det,a(n,n) cf2py intent(c,in,copy) :: a cf2py intent(out) :: det,info cf2py integer intent(hide,cache),depend(n),dimension(n) :: piv cf2py integer intent(hide),depend(a) :: n = shape(a,0) cf2py check(shape(a,0)==shape(a,1)) :: a cf2py callprotoargument double*,double*,int*,int*,int* external ddet_c call ddet_c(det,a,n,piv,info) end subroutine sdet_c(det,a,n,piv,info) integer n,piv(n),i real det,a(n,n) cf2py intent(in,copy) :: a cf2py intent(out) :: det,info cf2py integer intent(hide,cache),depend(n),dimension(n) :: piv cf2py integer intent(hide),depend(a) :: n = shape(a,0) cf2py check(shape(a,0)==shape(a,1)) :: a cf2py callprotoargument float*,float*,int*,int*,int* external sgetrf call sgetrf(n,n,a,n,piv,info) det = 0e0 if (info.ne.0) then return endif det = 1e0 do 10,i=1,n if (piv(i).ne.i) then det = -det * a(i,i) else det = det * a(i,i) endif 10 continue end subroutine sdet_r(det,a,n,piv,info) integer n,piv(n) real det,a(n,n) cf2py intent(c,in,copy) :: a cf2py intent(out) :: det,info cf2py integer intent(hide,cache),depend(n),dimension(n) :: piv cf2py integer intent(hide),depend(a) :: n = shape(a,0) cf2py check(shape(a,0)==shape(a,1)) :: a cf2py callprotoargument float*,float*,int*,int*,int* external sdet_c call sdet_c(det,a,n,piv,info) end subroutine zdet_c(det,a,n,piv,info) integer n,piv(n),i complex*16 det,a(n,n) cf2py intent(in,copy) :: a cf2py intent(out) :: det,info cf2py integer intent(hide,cache),depend(n),dimension(n) :: piv cf2py integer intent(hide),depend(a) :: n = shape(a,0) cf2py check(shape(a,0)==shape(a,1)) :: a cf2py callprotoargument complex_double*,complex_double*,int*,int*,int* external zgetrf call zgetrf(n,n,a,n,piv,info) det = (0d0,0d0) if (info.ne.0) then return endif det = (1d0,0d0) do 10,i=1,n if (piv(i).ne.i) then det = -det * a(i,i) else det = det * a(i,i) endif 10 continue end subroutine zdet_r(det,a,n,piv,info) integer n,piv(n) complex*16 det,a(n,n) cf2py intent(c,in,copy) :: a cf2py intent(out) :: det,info cf2py integer intent(hide,cache),depend(n),dimension(n) :: piv cf2py integer intent(hide),depend(a) :: n = shape(a,0) cf2py check(shape(a,0)==shape(a,1)) :: a cf2py callprotoargument complex_double*,complex_double*,int*,int*,int* external zdet_c call zdet_c(det,a,n,piv,info) end subroutine cdet_c(det,a,n,piv,info) integer n,piv(n),i complex det,a(n,n) cf2py intent(in,copy) :: a cf2py intent(out) :: det,info cf2py integer intent(hide,cache),depend(n),dimension(n) :: piv cf2py integer intent(hide),depend(a) :: n = shape(a,0) cf2py check(shape(a,0)==shape(a,1)) :: a cf2py callprotoargument complex_float*,complex_float*,int*,int*,int* external cgetrf call cgetrf(n,n,a,n,piv,info) det = (0e0,0e0) if (info.ne.0) then return endif det = (1e0,0e0) do 10,i=1,n if (piv(i).ne.i) then det = -det * a(i,i) else det = det * a(i,i) endif 10 continue end subroutine cdet_r(det,a,n,piv,info) integer n,piv(n) complex det,a(n,n) cf2py intent(c,in,copy) :: a cf2py intent(out) :: det,info cf2py integer intent(hide,cache),depend(n),dimension(n) :: piv cf2py integer intent(hide),depend(a) :: n = shape(a,0) cf2py check(shape(a,0)==shape(a,1)) :: a cf2py callprotoargument complex_float*,complex_float*,int*,int*,int* external cdet_c call cdet_c(det,a,n,piv,info) end
bsd-3-clause
kbai/specfem3d
src/tomography/get_cg_direction.f90
2
17305
!===================================================================== ! ! S p e c f e m 3 D V e r s i o n 3 . 0 ! --------------------------------------- ! ! Main historical authors: Dimitri Komatitsch and Jeroen Tromp ! Princeton University, USA ! and CNRS / University of Marseille, France ! (there are currently many more authors!) ! (c) Princeton University and CNRS / University of Marseille, July 2012 ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along ! with this program; if not, write to the Free Software Foundation, Inc., ! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ! !===================================================================== subroutine get_cg_direction_tiso() ! calculates TI gradient based on a conjugate gradient method ! ! based on: Tarantola, inverse problem theory, 2005. ! section 6.22.7 conjugate directions, page 217. ! formula for alpha_n based on Polak & Ribiere (1969) ! ! note: we use a preconditioner F_0 = 1, thus lambda_n = gamma_n in (6.322) ! and use gamma_n as the smoothed kernel (for bulk_c, bulk_betav,..). ! ! however, one could see smoothing as preconditioner F_0, thus ! gamma_n would be un-smoothed kernel and lambda_n would be smoothed one... ! i'm not sure if this makes a difference. use tomography_kernels_tiso use tomography_kernels_tiso_cg implicit none ! local parameters real(kind=CUSTOM_REAL) :: alpha_bulk,alpha_betav,alpha_betah,alpha_eta,alpha_all real(kind=CUSTOM_REAL) :: minmax(4),depthmax(2),depthmax_radius(2),max real(kind=CUSTOM_REAL) :: r,rmax_vsv,rmax_vsh,depthmax_depth ! gradient vector norm ( v^T * v ) real(kind=CUSTOM_REAL) :: norm_bulk,norm_betav,norm_betah,norm_eta real(kind=CUSTOM_REAL) :: norm_bulk_old,norm_betav_old,norm_betah_old,norm_eta_old real(kind=CUSTOM_REAL) :: norm_bulk_sum,norm_betav_sum, & norm_betah_sum,norm_eta_sum real(kind=CUSTOM_REAL) :: min_vsv,min_vsh,max_vsv,max_vsh,min_eta,max_eta,min_bulk,max_bulk integer :: maxindex(1) real(kind=CUSTOM_REAL) :: ratio_bulk,ratio_betav,ratio_betah,ratio_eta integer :: iglob integer :: i,j,k,ispec,ier ! allocate arrays for storing gradient ! transversely isotropic arrays allocate(model_dbulk(NGLLX,NGLLY,NGLLZ,NSPEC), & model_dbetav(NGLLX,NGLLY,NGLLZ,NSPEC), & model_dbetah(NGLLX,NGLLY,NGLLZ,NSPEC), & model_deta(NGLLX,NGLLY,NGLLZ,NSPEC),stat=ier) if (ier /= 0) stop 'error allocating gradient arrays' ! initializes arrays model_dbulk = 0.0_CUSTOM_REAL model_dbetav = 0.0_CUSTOM_REAL model_dbetah = 0.0_CUSTOM_REAL model_deta = 0.0_CUSTOM_REAL ! old kernel/gradient ! length ( gamma_(n-1)^T * lambda_(n-1) ) norm_bulk_old = sum( kernel_bulk_old * kernel_bulk_old ) norm_betav_old = sum( kernel_betav_old * kernel_betav_old ) norm_betah_old = sum( kernel_betah_old * kernel_betah_old ) norm_eta_old = sum( kernel_eta_old * kernel_eta_old ) call sum_all_cr(norm_bulk_old,norm_bulk_sum) call sum_all_cr(norm_betav_old,norm_betav_sum) call sum_all_cr(norm_betah_old,norm_betah_sum) call sum_all_cr(norm_eta_old,norm_eta_sum) ! don't use square root, just take gamma^T * gamma norm_bulk_old = norm_bulk_sum norm_betav_old = norm_betav_sum norm_betah_old = norm_betah_sum norm_eta_old = norm_eta_sum if (myrank == 0) then print *,'norm squared old gradient:' print *,' bulk : ',norm_bulk_old print *,' betav: ',norm_betav_old print *,' betah: ',norm_betah_old print *,' eta : ',norm_eta_old print * ! checks lengths if (norm_bulk_old < 1.e-22) call exit_mpi(myrank,'norm old gradient bulk is zero') if (norm_betav_old < 1.e-22) call exit_mpi(myrank,'norm old gradient betav is zero') if (norm_betah_old < 1.e-22) call exit_mpi(myrank,'norm old gradient betah is zero') if (norm_eta_old < 1.e-22) call exit_mpi(myrank,'norm old gradient eta is zero') endif ! Powell, 1977: checks orthogonality between old and new gradient ! gets length of ( gamma_(n-1)^T * gamma_n ) norm_bulk = sum( kernel_bulk_old * kernel_bulk ) norm_betav = sum( kernel_betav_old * kernel_betav ) norm_betah = sum( kernel_betah_old * kernel_betah ) norm_eta = sum( kernel_eta_old * kernel_eta ) call sum_all_cr(norm_bulk,norm_bulk_sum) call sum_all_cr(norm_betav,norm_betav_sum) call sum_all_cr(norm_betah,norm_betah_sum) call sum_all_cr(norm_eta,norm_eta_sum) if (myrank == 0) then ! ratio: ( g_n * g_n-1) / ( g_n-1 * g_n-1) ratio_bulk = norm_bulk_sum / norm_bulk_old ratio_betav = norm_betav_sum / norm_betav_old ratio_betah = norm_betah_sum / norm_betah_old ratio_eta = norm_eta_sum / norm_eta_old ! if ratio > 0.2 (empirical threshold value), then one should restart with a steepest descent print *,'Powell ratio: (> 0.2 then restart with steepest descent)' print *,' bulk : ',ratio_bulk print *,' betav: ',ratio_betav print *,' betah: ',ratio_betah print *,' eta : ',ratio_eta print * if (ratio_bulk > 0.2 .and. ratio_betav > 0.2 .and. ratio_betah > 0.2 & .and. ratio_eta > 0.2) then print *,' critical ratio found!' print * print *,'****************' print * print *,' Please consider doing a steepest descent instead cg...' print * print *,'****************' endif endif ! difference kernel/gradient ! length ( ( gamma_n - gamma_(n-1))^T * lambda_n ) norm_bulk = sum( (kernel_bulk - kernel_bulk_old) * kernel_bulk ) norm_betav = sum( (kernel_betav - kernel_betav_old) * kernel_betav ) norm_betah = sum( (kernel_betah - kernel_betah_old) * kernel_betah ) norm_eta = sum( (kernel_eta - kernel_eta_old) * kernel_eta ) call sum_all_cr(norm_bulk,norm_bulk_sum) call sum_all_cr(norm_betav,norm_betav_sum) call sum_all_cr(norm_betah,norm_betah_sum) call sum_all_cr(norm_eta,norm_eta_sum) ! don't take square root, since norm_bulk_sum could be negative ! just use (gamma_n - gamma_n-1)^T * lambda_n norm_bulk = norm_bulk_sum norm_betav = norm_betav_sum norm_betah = norm_betah_sum norm_eta = norm_eta_sum if (myrank == 0) then print *,'norm squared difference gradient:' print *,' bulk : ',norm_bulk print *,' betav: ',norm_betav print *,' betah: ',norm_betah print *,' eta : ',norm_eta print * endif ! calculates ratio based on Polak & Ribiere (1969) if (myrank == 0) then if (USE_SEPARATE_CG_STEPLENGTHS) then ! calculates steplength alpha for each parameter alpha_bulk = norm_bulk / norm_bulk_old alpha_betav = norm_betav / norm_betav_old alpha_betah = norm_betah / norm_betah_old alpha_eta = norm_eta / norm_eta_old ! only if contribution is positive it will be considered, otherwise ! we set it to zero so that it becomes a steepest descent update if (alpha_bulk < 0.0) then alpha_bulk = 0.0 endif if (alpha_betav < 0.0) then alpha_betav = 0.0 endif if (alpha_betah < 0.0) then alpha_betah = 0.0 endif if (alpha_eta < 0.0) then alpha_eta = 0.0 endif else ! calculates only a single steplength applied to all alpha_all = (norm_bulk + norm_betav + norm_betah + norm_eta) & / (norm_bulk_old + norm_betav_old + norm_betah_old + norm_eta_old) ! only if contribution is positive it will be considered, otherwise ! we set it to zero so that it becomes a steepest descent update if (alpha_all < 0.0) then alpha_all = 0.0 endif ! sets each steplength to same single one alpha_bulk = alpha_all alpha_betav = alpha_all alpha_betah = alpha_all alpha_eta = alpha_all endif ! user output print *,'alpha gradient:' print *,' bulk : ',alpha_bulk print *,' betav: ',alpha_betav print *,' betah: ',alpha_betah print *,' eta : ',alpha_eta print * endif ! broadcast values from rank 0 to all others call bcast_all_singlecr(alpha_bulk) call bcast_all_singlecr(alpha_betav) call bcast_all_singlecr(alpha_betah) call bcast_all_singlecr(alpha_eta) ! initializes kernel maximum depthmax(:) = 0._CUSTOM_REAL ! gradient in negative direction if (USE_OLD_GRADIENT) then ! uses old kernel/gradient updates ( phi_n-1) do ispec = 1, NSPEC do k = 1, NGLLZ do j = 1, NGLLY do i = 1, NGLLX ! note: uses old gradient update (phi_(n-1) as model_bulk_old, but ! given in negative gradient direction ! for bulk model_dbulk(i,j,k,ispec) = - kernel_bulk(i,j,k,ispec) & + alpha_bulk * model_dbulk_old(i,j,k,ispec) ! for shear model_dbetav(i,j,k,ispec) = - kernel_betav(i,j,k,ispec) & + alpha_betav * model_dbetav_old(i,j,k,ispec) model_dbetah(i,j,k,ispec) = - kernel_betah(i,j,k,ispec) & + alpha_betah * model_dbetah_old(i,j,k,ispec) ! for eta model_deta(i,j,k,ispec) = - kernel_eta(i,j,k,ispec) & + alpha_eta * model_deta_old(i,j,k,ispec) ! determines maximum kernel betav value within given radius if (USE_DEPTH_RANGE_MAXIMUM) then ! get radius of point iglob = ibool(i,j,k,ispec) r = z(iglob) ! stores maximum kernel betav/betah value in this depth slice, ! since betav/betah are most likely dominating if (r < R_TOP .and. r > R_BOTTOM) then ! kernel betav value max_vsv = abs( model_dbetav(i,j,k,ispec) ) if (depthmax(1) < max_vsv) then depthmax(1) = max_vsv depthmax_radius(1) = r endif ! kernel betav value max_vsh = abs( model_dbetah(i,j,k,ispec) ) if (depthmax(2) < max_vsh) then depthmax(2) = max_vsh depthmax_radius(2) = r endif endif endif enddo enddo enddo enddo else ! uses only old kernel/gradient do ispec = 1, NSPEC do k = 1, NGLLZ do j = 1, NGLLY do i = 1, NGLLX ! note: uses old kernels (lambda_(n-1) ) in negative gradient direction ! for bulk model_dbulk(i,j,k,ispec) = - kernel_bulk(i,j,k,ispec) & - alpha_bulk * kernel_bulk_old(i,j,k,ispec) ! for shear model_dbetav(i,j,k,ispec) = - kernel_betav(i,j,k,ispec) & - alpha_betav * kernel_betav_old(i,j,k,ispec) model_dbetah(i,j,k,ispec) = - kernel_betah(i,j,k,ispec) & - alpha_betah * kernel_betah_old(i,j,k,ispec) ! for eta model_deta(i,j,k,ispec) = - kernel_eta(i,j,k,ispec) & - alpha_eta * kernel_eta_old(i,j,k,ispec) ! determines maximum kernel betav value within given radius if (USE_DEPTH_RANGE_MAXIMUM) then ! get radius of point iglob = ibool(i,j,k,ispec) r = z(iglob) ! stores maximum kernel betav/betah value in this depth slice, ! since betav/betah are most likely dominating if (r < R_TOP .and. r > R_BOTTOM) then ! kernel betav value max_vsv = abs( model_dbetav(i,j,k,ispec) ) if (depthmax(1) < max_vsv) then depthmax(1) = max_vsv depthmax_radius(1) = r endif ! kernel betav value max_vsh = abs( model_dbetah(i,j,k,ispec) ) if (depthmax(2) < max_vsh) then depthmax(2) = max_vsh depthmax_radius(2) = r endif endif endif enddo enddo enddo enddo endif ! stores model_dbulk, ... arrays ! note: stores these new gradient before we scale them with the step length call write_gradient_tiso() ! statistics call min_all_cr(minval(model_dbulk),min_bulk) call max_all_cr(maxval(model_dbulk),max_bulk) call min_all_cr(minval(model_dbetav),min_vsv) call max_all_cr(maxval(model_dbetav),max_vsv) call min_all_cr(minval(model_dbetah),min_vsh) call max_all_cr(maxval(model_dbetah),max_vsh) call min_all_cr(minval(model_deta),min_eta) call max_all_cr(maxval(model_deta),max_eta) if (myrank == 0) then print *,'initial gradient updates:' print *,' bulk min/max : ',min_bulk,max_bulk print *,' betav min/max: ',min_vsv,max_vsv print *,' betah min/max: ',min_vsh,max_vsh print *,' eta min/max : ',min_eta,max_eta print * endif ! determines maximum kernel betav value within given radius if (USE_DEPTH_RANGE_MAXIMUM) then ! maximum of all processes stored in max_vsv call max_all_cr(depthmax(1),max_vsv) call max_all_cr(depthmax(2),max_vsh) call max_all_cr(depthmax_radius(1),rmax_vsv) call max_all_cr(depthmax_radius(2),rmax_vsh) endif ! determines step length ! based on maximum gradient value (either vsv or vsh) if (myrank == 0) then ! determines maximum kernel betav value within given radius if (USE_DEPTH_RANGE_MAXIMUM) then depthmax(1) = max_vsv depthmax(2) = max_vsh depthmax_radius(1) = rmax_vsv depthmax_radius(2) = rmax_vsh max = maxval(depthmax) maxindex = maxloc(depthmax) depthmax_depth = depthmax_radius(maxindex(1)) ! maximum in given depth range print *,' using depth maximum: ' print *,' between depths (top/bottom) : ',R_TOP,R_BOTTOM print *,' maximum kernel value : ',max print *,' depth of maximum kernel value : ',depthmax_depth print * else ! maximum gradient values minmax(1) = abs(min_vsv) minmax(2) = abs(max_vsv) minmax(3) = abs(min_vsh) minmax(4) = abs(max_vsh) ! maximum value of all kernel maxima max = maxval(minmax) endif print *,'step length:' print *,' using kernel maximum: ',max ! checks maximum value if (max < 1.e-25) stop 'Error maximum kernel value too small for update' ! chooses step length such that it becomes the desired, given step factor as inputted step_length = step_fac/max print *,' step length : ',step_length print * endif call bcast_all_singlecr(step_length) ! gradient length sqrt( v^T * v ) norm_bulk = sum( model_dbulk * model_dbulk ) norm_betav = sum( model_dbetav * model_dbetav ) norm_betah = sum( model_dbetah * model_dbetah ) norm_eta = sum( model_deta * model_deta ) call sum_all_cr(norm_bulk,norm_bulk_sum) call sum_all_cr(norm_betav,norm_betav_sum) call sum_all_cr(norm_betah,norm_betah_sum) call sum_all_cr(norm_eta,norm_eta_sum) if (myrank == 0) then norm_bulk = sqrt(norm_bulk_sum) norm_betav = sqrt(norm_betav_sum) norm_betah = sqrt(norm_betah_sum) norm_eta = sqrt(norm_eta_sum) print *,'norm model updates:' print *,' bulk : ',norm_bulk print *,' betav: ',norm_betav print *,' betah: ',norm_betah print *,' eta : ',norm_eta print * endif ! multiply model updates by a subjective factor that will change the step model_dbulk(:,:,:,:) = step_length * model_dbulk(:,:,:,:) model_dbetav(:,:,:,:) = step_length * model_dbetav(:,:,:,:) model_dbetah(:,:,:,:) = step_length * model_dbetah(:,:,:,:) model_deta(:,:,:,:) = step_length * model_deta(:,:,:,:) ! statistics call min_all_cr(minval(model_dbulk),min_bulk) call max_all_cr(maxval(model_dbulk),max_bulk) call min_all_cr(minval(model_dbetav),min_vsv) call max_all_cr(maxval(model_dbetav),max_vsv) call min_all_cr(minval(model_dbetah),min_vsh) call max_all_cr(maxval(model_dbetah),max_vsh) call min_all_cr(minval(model_deta),min_eta) call max_all_cr(maxval(model_deta),max_eta) if (myrank == 0) then print *,'scaled gradient:' print *,' bulk min/max : ',min_bulk,max_bulk print *,' betav min/max: ',min_vsv,max_vsv print *,' betah min/max: ',min_vsh,max_vsh print *,' eta min/max : ',min_eta,max_eta print * endif call synchronize_all() end subroutine get_cg_direction_tiso
gpl-2.0
piyush0609/scipy
scipy/interpolate/fitpack/curfit.f
113
13785
subroutine curfit(iopt,m,x,y,w,xb,xe,k,s,nest,n,t,c,fp, * wrk,lwrk,iwrk,ier) c given the set of data points (x(i),y(i)) and the set of positive c numbers w(i),i=1,2,...,m,subroutine curfit determines a smooth spline c approximation of degree k on the interval xb <= x <= xe. c if iopt=-1 curfit calculates the weighted least-squares spline c according to a given set of knots. c if iopt>=0 the number of knots of the spline s(x) and the position c t(j),j=1,2,...,n is chosen automatically by the routine. the smooth- c ness of s(x) is then achieved by minimalizing the discontinuity c jumps of the k-th derivative of s(x) at the knots t(j),j=k+2,k+3,..., c n-k-1. the amount of smoothness is determined by the condition that c f(p)=sum((w(i)*(y(i)-s(x(i))))**2) be <= s, with s a given non- c negative constant, called the smoothing factor. c the fit s(x) is given in the b-spline representation (b-spline coef- c ficients c(j),j=1,2,...,n-k-1) and can be evaluated by means of c subroutine splev. c c calling sequence: c call curfit(iopt,m,x,y,w,xb,xe,k,s,nest,n,t,c,fp,wrk, c * lwrk,iwrk,ier) c c parameters: c iopt : integer flag. on entry iopt must specify whether a weighted c least-squares spline (iopt=-1) or a smoothing spline (iopt= c 0 or 1) must be determined. if iopt=0 the routine will start c with an initial set of knots t(i)=xb, t(i+k+1)=xe, i=1,2,... c k+1. if iopt=1 the routine will continue with the knots c found at the last call of the routine. c attention: a call with iopt=1 must always be immediately c preceded by another call with iopt=1 or iopt=0. c unchanged on exit. c m : integer. on entry m must specify the number of data points. c m > k. unchanged on exit. c x : real array of dimension at least (m). before entry, x(i) c must be set to the i-th value of the independent variable x, c for i=1,2,...,m. these values must be supplied in strictly c ascending order. unchanged on exit. c y : real array of dimension at least (m). before entry, y(i) c must be set to the i-th value of the dependent variable y, c for i=1,2,...,m. unchanged on exit. c w : real array of dimension at least (m). before entry, w(i) c must be set to the i-th value in the set of weights. the c w(i) must be strictly positive. unchanged on exit. c see also further comments. c xb,xe : real values. on entry xb and xe must specify the boundaries c of the approximation interval. xb<=x(1), xe>=x(m). c unchanged on exit. c k : integer. on entry k must specify the degree of the spline. c 1<=k<=5. it is recommended to use cubic splines (k=3). c the user is strongly dissuaded from choosing k even,together c with a small s-value. unchanged on exit. c s : real.on entry (in case iopt>=0) s must specify the smoothing c factor. s >=0. unchanged on exit. c for advice on the choice of s see further comments. c nest : integer. on entry nest must contain an over-estimate of the c total number of knots of the spline returned, to indicate c the storage space available to the routine. nest >=2*k+2. c in most practical situation nest=m/2 will be sufficient. c always large enough is nest=m+k+1, the number of knots c needed for interpolation (s=0). unchanged on exit. c n : integer. c unless ier =10 (in case iopt >=0), n will contain the c total number of knots of the spline approximation returned. c if the computation mode iopt=1 is used this value of n c should be left unchanged between subsequent calls. c in case iopt=-1, the value of n must be specified on entry. c t : real array of dimension at least (nest). c on succesful exit, this array will contain the knots of the c spline,i.e. the position of the interior knots t(k+2),t(k+3) c ...,t(n-k-1) as well as the position of the additional knots c t(1)=t(2)=...=t(k+1)=xb and t(n-k)=...=t(n)=xe needed for c the b-spline representation. c if the computation mode iopt=1 is used, the values of t(1), c t(2),...,t(n) should be left unchanged between subsequent c calls. if the computation mode iopt=-1 is used, the values c t(k+2),...,t(n-k-1) must be supplied by the user, before c entry. see also the restrictions (ier=10). c c : real array of dimension at least (nest). c on succesful exit, this array will contain the coefficients c c(1),c(2),..,c(n-k-1) in the b-spline representation of s(x) c fp : real. unless ier=10, fp contains the weighted sum of c squared residuals of the spline approximation returned. c wrk : real array of dimension at least (m*(k+1)+nest*(7+3*k)). c used as working space. if the computation mode iopt=1 is c used, the values wrk(1),...,wrk(n) should be left unchanged c between subsequent calls. c lwrk : integer. on entry,lwrk must specify the actual dimension of c the array wrk as declared in the calling (sub)program.lwrk c must not be too small (see wrk). unchanged on exit. c iwrk : integer array of dimension at least (nest). c used as working space. if the computation mode iopt=1 is c used,the values iwrk(1),...,iwrk(n) should be left unchanged c between subsequent calls. c ier : integer. unless the routine detects an error, ier contains a c non-positive value on exit, i.e. c ier=0 : normal return. the spline returned has a residual sum of c squares fp such that abs(fp-s)/s <= tol with tol a relat- c ive tolerance set to 0.001 by the program. c ier=-1 : normal return. the spline returned is an interpolating c spline (fp=0). c ier=-2 : normal return. the spline returned is the weighted least- c squares polynomial of degree k. in this extreme case fp c gives the upper bound fp0 for the smoothing factor s. c ier=1 : error. the required storage space exceeds the available c storage space, as specified by the parameter nest. c probably causes : nest too small. if nest is already c large (say nest > m/2), it may also indicate that s is c too small c the approximation returned is the weighted least-squares c spline according to the knots t(1),t(2),...,t(n). (n=nest) c the parameter fp gives the corresponding weighted sum of c squared residuals (fp>s). c ier=2 : error. a theoretically impossible result was found during c the iteration proces for finding a smoothing spline with c fp = s. probably causes : s too small. c there is an approximation returned but the corresponding c weighted sum of squared residuals does not satisfy the c condition abs(fp-s)/s < tol. c ier=3 : error. the maximal number of iterations maxit (set to 20 c by the program) allowed for finding a smoothing spline c with fp=s has been reached. probably causes : s too small c there is an approximation returned but the corresponding c weighted sum of squared residuals does not satisfy the c condition abs(fp-s)/s < tol. c ier=10 : error. on entry, the input data are controlled on validity c the following restrictions must be satisfied. c -1<=iopt<=1, 1<=k<=5, m>k, nest>2*k+2, w(i)>0,i=1,2,...,m c xb<=x(1)<x(2)<...<x(m)<=xe, lwrk>=(k+1)*m+nest*(7+3*k) c if iopt=-1: 2*k+2<=n<=min(nest,m+k+1) c xb<t(k+2)<t(k+3)<...<t(n-k-1)<xe c the schoenberg-whitney conditions, i.e. there c must be a subset of data points xx(j) such that c t(j) < xx(j) < t(j+k+1), j=1,2,...,n-k-1 c if iopt>=0: s>=0 c if s=0 : nest >= m+k+1 c if one of these conditions is found to be violated,control c is immediately repassed to the calling program. in that c case there is no approximation returned. c c further comments: c by means of the parameter s, the user can control the tradeoff c between closeness of fit and smoothness of fit of the approximation. c if s is too large, the spline will be too smooth and signal will be c lost ; if s is too small the spline will pick up too much noise. in c the extreme cases the program will return an interpolating spline if c s=0 and the weighted least-squares polynomial of degree k if s is c very large. between these extremes, a properly chosen s will result c in a good compromise between closeness of fit and smoothness of fit. c to decide whether an approximation, corresponding to a certain s is c satisfactory the user is highly recommended to inspect the fits c graphically. c recommended values for s depend on the weights w(i). if these are c taken as 1/d(i) with d(i) an estimate of the standard deviation of c y(i), a good s-value should be found in the range (m-sqrt(2*m),m+ c sqrt(2*m)). if nothing is known about the statistical error in y(i) c each w(i) can be set equal to one and s determined by trial and c error, taking account of the comments above. the best is then to c start with a very large value of s ( to determine the least-squares c polynomial and the corresponding upper bound fp0 for s) and then to c progressively decrease the value of s ( say by a factor 10 in the c beginning, i.e. s=fp0/10, fp0/100,...and more carefully as the c approximation shows more detail) to obtain closer fits. c to economize the search for a good s-value the program provides with c different modes of computation. at the first call of the routine, or c whenever he wants to restart with the initial set of knots the user c must set iopt=0. c if iopt=1 the program will continue with the set of knots found at c the last call of the routine. this will save a lot of computation c time if curfit is called repeatedly for different values of s. c the number of knots of the spline returned and their location will c depend on the value of s and on the complexity of the shape of the c function underlying the data. but, if the computation mode iopt=1 c is used, the knots returned may also depend on the s-values at c previous calls (if these were smaller). therefore, if after a number c of trials with different s-values and iopt=1, the user can finally c accept a fit as satisfactory, it may be worthwhile for him to call c curfit once more with the selected value for s but now with iopt=0. c indeed, curfit may then return an approximation of the same quality c of fit but with fewer knots and therefore better if data reduction c is also an important objective for the user. c c other subroutines required: c fpback,fpbspl,fpchec,fpcurf,fpdisc,fpgivs,fpknot,fprati,fprota c c references: c dierckx p. : an algorithm for smoothing, differentiation and integ- c ration of experimental data using spline functions, c j.comp.appl.maths 1 (1975) 165-184. c dierckx p. : a fast algorithm for smoothing data on a rectangular c grid while using spline functions, siam j.numer.anal. c 19 (1982) 1286-1304. c dierckx p. : an improved algorithm for curve fitting with spline c functions, report tw54, dept. computer science,k.u. c leuven, 1981. c dierckx p. : curve and surface fitting with splines, monographs on c numerical analysis, oxford university press, 1993. c c author: c p.dierckx c dept. computer science, k.u. leuven c celestijnenlaan 200a, b-3001 heverlee, belgium. c e-mail : Paul.Dierckx@cs.kuleuven.ac.be c c creation date : may 1979 c latest update : march 1987 c c .. c ..scalar arguments.. real*8 xb,xe,s,fp integer iopt,m,k,nest,n,lwrk,ier c ..array arguments.. real*8 x(m),y(m),w(m),t(nest),c(nest),wrk(lwrk) integer iwrk(nest) c ..local scalars.. real*8 tol integer i,ia,ib,ifp,ig,iq,iz,j,k1,k2,lwest,maxit,nmin c .. c we set up the parameters tol and maxit maxit = 20 tol = 0.1d-02 c before starting computations a data check is made. if the input data c are invalid, control is immediately repassed to the calling program. ier = 10 if(k.le.0 .or. k.gt.5) go to 50 k1 = k+1 k2 = k1+1 if(iopt.lt.(-1) .or. iopt.gt.1) go to 50 nmin = 2*k1 if(m.lt.k1 .or. nest.lt.nmin) go to 50 lwest = m*k1+nest*(7+3*k) if(lwrk.lt.lwest) go to 50 if(xb.gt.x(1) .or. xe.lt.x(m)) go to 50 do 10 i=2,m if(x(i-1).gt.x(i)) go to 50 10 continue if(iopt.ge.0) go to 30 if(n.lt.nmin .or. n.gt.nest) go to 50 j = n do 20 i=1,k1 t(i) = xb t(j) = xe j = j-1 20 continue call fpchec(x,m,t,n,k,ier) if (ier.eq.0) go to 40 go to 50 30 if(s.lt.0.) go to 50 if(s.eq.0. .and. nest.lt.(m+k1)) go to 50 c we partition the working space and determine the spline approximation. 40 ifp = 1 iz = ifp+nest ia = iz+nest ib = ia+nest*k1 ig = ib+nest*k2 iq = ig+nest*k2 call fpcurf(iopt,x,y,w,m,xb,xe,k,s,nest,tol,maxit,k1,k2,n,t,c,fp, * wrk(ifp),wrk(iz),wrk(ia),wrk(ib),wrk(ig),wrk(iq),iwrk,ier) 50 return end
bsd-3-clause
QEF/q-e_schrodinger
Modules/wgauss.f90
2
2505
! ! Copyright (C) 2001 PWSCF group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !----------------------------------------------------------------------- function wgauss (x, n) !----------------------------------------------------------------------- !! This function computes the approximate theta function for the !! given order n, at the point x: ! !! * \( n \geq 0 \): Methfessel-Paxton case. See PRB 40, 3616 (1989). !! * \( n=-1 \): cold smearing (Marzari-Vanderbilt-DeVita-Payne, !! see PRL 82, 3296 (1999)): !! $$ \frac{1}{2} \text{erf}\(x-\frac{1}{\sqrt(2)}\) + \frac{1}{\sqrt{2\pi}} \exp !! {-\(x-\frac{1}{sqrt{2}}\)^2} + 1/2 $$ !! * \( n=-99 \): Fermi-Dirac case: !! $$ \frac{1.0}{1.0+\exp{-x}} $$ ! USE kinds, ONLY : DP USE constants, ONLY : pi implicit none real(DP) :: wgauss !! output: the value of the function real(DP) :: x !! input: the argument of the function integer :: n !! input: the order of the function ! ! ... local variables ! real(DP) :: a, hp, arg, hd, xp ! the coefficient a_n ! the hermitean function ! the argument of the exponential ! the hermitean function ! auxiliary variable (cold smearing) integer :: i, ni ! counter on the n indices ! counter on 2n real(DP), parameter :: maxarg = 200.d0 ! maximum value for the argument of the exponential ! Fermi-Dirac smearing if (n.eq. - 99) then if (x.lt. - maxarg) then wgauss = 0.d0 elseif (x.gt.maxarg) then wgauss = 1.d0 else wgauss = 1.0d0 / (1.0d0 + exp ( - x) ) endif return endif ! Cold smearing if (n.eq. - 1) then xp = x - 1.0d0 / sqrt (2.0d0) arg = min (maxarg, xp**2) wgauss = 0.5d0 * erf(xp) + 1.0d0 / sqrt (2.0d0 * pi) * exp ( - & arg) + 0.5d0 return endif ! Methfessel-Paxton and plain gaussian cases arg = -x IF (arg .LT. sqrt(maxarg)) THEN wgauss = 0.5_DP * ERFC( arg) ELSE wgauss = 0._DP END IF if (n.eq.0) return hd = 0.d0 arg = min (maxarg, x**2) hp = exp ( - arg) ni = 0 a = 1.d0 / sqrt (pi) do i = 1, n hd = 2.0d0 * x * hp - 2.0d0 * DBLE (ni) * hd ni = ni + 1 a = - a / (DBLE (i) * 4.0d0) wgauss = wgauss - a * hd hp = 2.0d0 * x * hd-2.0d0 * DBLE (ni) * hp ni = ni + 1 enddo return end function wgauss
gpl-2.0
kbai/specfem3d
src/inverse_problem/program03_smooth_sem.f90
2
24106
!===================================================================== ! ! S p e c f e m 3 D V e r s i o n 3 . 0 ! --------------------------------------- ! ! Main historical authors: Dimitri Komatitsch and Jeroen Tromp ! Princeton University, USA ! and CNRS / University of Marseille, France ! (there are currently many more authors!) ! (c) Princeton University and CNRS / University of Marseille, July 2012 ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along ! with this program; if not, write to the Free Software Foundation, Inc., ! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ! !===================================================================== ! this program can be used for smoothing a kernel, ! where it smooths files with a given input kernel name: ! ! compile with: ! ! make xsmooth_sem ! ! Usage: ! mpirun -np nprocs ./xsmooth_sem sigma_h sigma_v kernel_file_name scratch_file_dir output_dir ! e.g. ! mpirun -np 8 ./xsmooth_sem 100 20 alpha_kernel DATABASES_MPI/ OUTPUT_SUM/ ! ! where: ! sigma_h - gaussian width for horizontal smoothing ! sigma_v - gaussian width for vertical smoothing ! kernel_file_name - takes file with this kernel name, ! e.g. "alpha_kernel" ! scratch_file_dir - directory containing kernel files, ! e.g. proc***_alpha_kernel.bin ! output_dir - directory for outputting files, ! e.g. proc***_alpha_kernel_smooth.bin ! outputs: ! puts the resulting, smoothed kernel files into the output_dir directory, ! with a file ending "proc***_kernel_smooth.bin" program smooth_sem ! this is the embarassingly-parallel program that smooths any specfem function (primarily the kernels) ! that has the dimension of (NGLLX,NGLLY,NGLLZ,NSPEC) ! ! NOTE: smoothing can be different in vertical & horizontal directions; mesh is in Cartesian geometry. ! algorithm uses vertical as Z, horizontal as X/Y direction use constants,only: CUSTOM_REAL,NGLLX,NGLLY,NGLLZ,NDIM,NGLLSQUARE, & MAX_STRING_LEN,IIN,IOUT, & GAUSSALPHA,GAUSSBETA,PI,TWO_PI use specfem_par use specfem_par_elastic,only: ELASTIC_SIMULATION,ispec_is_elastic,rho_vp,rho_vs,min_resolved_period use specfem_par_acoustic,only: ACOUSTIC_SIMULATION,ispec_is_acoustic use specfem_par_poroelastic,only: POROELASTIC_SIMULATION,ispec_is_poroelastic,rho_vpI,rho_vpII,rho_vsI, & phistore,tortstore,rhoarraystore use specfem_par_movie implicit none ! data must be of dimension: (NGLLX,NGLLY,NGLLZ,NSPEC_AB) real(kind=CUSTOM_REAL), dimension(:,:,:,:),allocatable :: dat,dat_smooth real(kind=CUSTOM_REAL), dimension(:,:,:,:),allocatable :: dummy integer :: NSPEC_N, NGLOB_N integer :: i,j,k,iglob,ier,ispec2,ispec,inum integer :: iproc integer,parameter :: MAX_NODE_LIST = 300 integer :: node_list(MAX_NODE_LIST) character(len=MAX_STRING_LEN) :: arg(5) character(len=MAX_STRING_LEN) :: filename, indir, outdir character(len=MAX_STRING_LEN) :: prname_lp character(len=MAX_STRING_LEN*2) :: local_data_file ! smoothing parameters character(len=MAX_STRING_LEN*2) :: ks_file real(kind=CUSTOM_REAL) :: sigma_h, sigma_h2, sigma_h3, sigma_v, sigma_v2, sigma_v3 real(kind=CUSTOM_REAL) :: x0, y0, z0, norm, norm_h, norm_v, max_old, max_new real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ) :: exp_val !,factor real(kind=CUSTOM_REAL), dimension(:,:,:,:),allocatable :: tk, bk real(kind=CUSTOM_REAL), dimension(:,:,:,:),allocatable :: xl, yl, zl real(kind=CUSTOM_REAL), dimension(:,:,:,:),allocatable :: xx, yy, zz real(kind=CUSTOM_REAL), dimension(:),allocatable :: cx0, cy0, cz0 real(kind=CUSTOM_REAL), dimension(:),allocatable :: cx, cy, cz real(kind=CUSTOM_REAL) :: dist_h,dist_v real(kind=CUSTOM_REAL) :: element_size real(kind=CUSTOM_REAL) :: distance_min_glob,distance_max_glob real(kind=CUSTOM_REAL) :: elemsize_min_glob,elemsize_max_glob real(kind=CUSTOM_REAL) :: x_min_glob,x_max_glob real(kind=CUSTOM_REAL) :: y_min_glob,y_max_glob real(kind=CUSTOM_REAL) :: z_min_glob,z_max_glob logical :: BROADCAST_AFTER_READ ! initialize the MPI communicator and start the NPROCTOT MPI processes call init_mpi() call world_size(sizeprocs) call world_rank(myrank) if (myrank == 0) print *,"smooth_sem:" call synchronize_all() ! reads arguments do i = 1, 5 call get_command_argument(i,arg(i)) if (i <= 5 .and. trim(arg(i)) == '') then if (myrank == 0) then print *, 'Usage: ' print *, ' xsmooth_data sigma_h sigma_v kernel_file_name input_dir/ output_dir/' print * print *, 'with ' print *, ' sigma_h - gaussian width for horizontal smoothing' print *, ' sigma_v - gaussian width for vertical smoothing' print * print *, ' possible kernel_file_names are: ' print *, ' alpha_kernel, beta_kernel, .., rho_vp, rho_vs, kappastore, mustore, etc.' print * print *, ' that are stored in the local directory as real(kind=CUSTOM_REAL) filename(NGLLX,NGLLY,NGLLZ,NSPEC_AB) ' print *, ' in filename.bin' print * print *, ' files have been collected in input_dir/, smooth output mesh file goes to output_dir/ ' print * endif call synchronize_all() stop ' Reenter command line options' endif enddo ! gets arguments read(arg(1),*) sigma_h read(arg(2),*) sigma_v filename = arg(3) indir= arg(4) outdir = arg(5) ! initializes lengths sigma_h2 = 2.0 * sigma_h ** 2 ! factor two for gaussian distribution with standard variance sigma sigma_v2 = 2.0 * sigma_v ** 2 ! checks if (sigma_h2 < 1.e-18) stop 'Error sigma_h2 zero, must non-zero' if (sigma_v2 < 1.e-18) stop 'Error sigma_v2 zero, must non-zero' ! adds margin to search radius element_size = max(sigma_h,sigma_v) * 0.5 ! search radius sigma_h3 = 3.0 * sigma_h + element_size sigma_v3 = 3.0 * sigma_v + element_size ! theoretic normal value ! (see integral over -inf to +inf of exp[- x*x/(2*sigma) ] = sigma * sqrt(2*pi) ) ! note: smoothing is using a gaussian (ellipsoid for sigma_h /= sigma_v), norm_h = 2.0*PI*sigma_h**2 norm_v = sqrt(2.0*PI) * sigma_v norm = norm_h * norm_v ! user output if (myrank == 0) then print *,"defaults:" print *," smoothing sigma_h , sigma_v : ",sigma_h,sigma_v ! scalelength: approximately S ~ sigma * sqrt(8.0) for a gaussian smoothing print *," smoothing scalelengths horizontal, vertical: ",sigma_h*sqrt(8.0),sigma_v*sqrt(8.0) print *," input dir : ",trim(indir) print *," output dir: ",trim(outdir) print * endif ! reads the parameter file BROADCAST_AFTER_READ = .true. call read_parameter_file(myrank,BROADCAST_AFTER_READ) if (ADIOS_ENABLED) stop 'Flag ADIOS_ENABLED not supported yet for smoothing, please rerun program...' ! check that the code is running with the requested nb of processes if (sizeprocs /= NPROC) then if (myrank == 0) then print *, 'Error number of processors supposed to run on: ',NPROC print *, 'Error number of MPI processors actually run on: ',sizeprocs print * print *, 'please rerun with: mpirun -np ',NPROC,' bin/xsmooth_sem .. ' endif call exit_MPI(myrank,'Error wrong number of MPI processes') endif ! read the value of NSPEC_AB and NGLOB_AB because we need it to define some array sizes below call read_mesh_for_init() ! allocate arrays for storing the databases allocate(ibool(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & xix(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & xiy(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & xiz(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & etax(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & etay(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & etaz(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & gammax(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & gammay(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & gammaz(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & jacobian(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier) if (ier /= 0) stop 'Error allocating arrays for databases' ! mesh node locations allocate(xstore(NGLOB_AB), & ystore(NGLOB_AB), & zstore(NGLOB_AB),stat=ier) if (ier /= 0) stop 'Error allocating arrays for mesh nodes' ! material properties allocate(kappastore(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & mustore(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier) if (ier /= 0) stop 'Error allocating arrays for material properties' ! material flags allocate(ispec_is_acoustic(NSPEC_AB), & ispec_is_elastic(NSPEC_AB), & ispec_is_poroelastic(NSPEC_AB),stat=ier) if (ier /= 0) stop 'Error allocating arrays for material flags' ispec_is_acoustic(:) = .false. ispec_is_elastic(:) = .false. ispec_is_poroelastic(:) = .false. ! reads in external mesh call read_mesh_databases() ! gets mesh dimensions call check_mesh_distances(myrank,NSPEC_AB,NGLOB_AB,ibool,xstore,ystore,zstore, & x_min_glob,x_max_glob,y_min_glob,y_max_glob,z_min_glob,z_max_glob, & elemsize_min_glob,elemsize_max_glob, & distance_min_glob,distance_max_glob) ! outputs infos if (myrank == 0) then print *,'mesh dimensions:' print *,' Xmin and Xmax of the model = ',x_min_glob,x_max_glob print *,' Ymin and Ymax of the model = ',y_min_glob,y_max_glob print *,' Zmin and Zmax of the model = ',z_min_glob,z_max_glob print * print *,' Max GLL point distance = ',distance_max_glob print *,' Min GLL point distance = ',distance_min_glob print *,' Max/min ratio = ',distance_max_glob/distance_min_glob print * print *,' Max element size = ',elemsize_max_glob print *,' Min element size = ',elemsize_min_glob print *,' Max/min ratio = ',elemsize_max_glob/elemsize_min_glob print * endif if (ELASTIC_SIMULATION) then call check_mesh_resolution(myrank,NSPEC_AB,NGLOB_AB, & ibool,xstore,ystore,zstore, & kappastore,mustore,rho_vp,rho_vs, & DT,model_speed_max,min_resolved_period, & LOCAL_PATH,SAVE_MESH_FILES) else if (POROELASTIC_SIMULATION) then allocate(rho_vp(NGLLX,NGLLY,NGLLZ,NSPEC_AB)) allocate(rho_vs(NGLLX,NGLLY,NGLLZ,NSPEC_AB)) rho_vp = 0.0_CUSTOM_REAL rho_vs = 0.0_CUSTOM_REAL call check_mesh_resolution_poro(myrank,NSPEC_AB,NGLOB_AB,ibool,xstore,ystore,zstore, & DT,model_speed_max,min_resolved_period, & phistore,tortstore,rhoarraystore,rho_vpI,rho_vpII,rho_vsI, & LOCAL_PATH,SAVE_MESH_FILES) deallocate(rho_vp,rho_vs) else if (ACOUSTIC_SIMULATION) then allocate(rho_vp(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier) if (ier /= 0) stop 'Error allocating array rho_vp' allocate(rho_vs(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier) if (ier /= 0) stop 'Error allocating array rho_vs' rho_vp = sqrt( kappastore / rhostore ) * rhostore rho_vs = 0.0_CUSTOM_REAL call check_mesh_resolution(myrank,NSPEC_AB,NGLOB_AB, & ibool,xstore,ystore,zstore, & kappastore,mustore,rho_vp,rho_vs, & DT,model_speed_max,min_resolved_period, & LOCAL_PATH,SAVE_MESH_FILES) deallocate(rho_vp,rho_vs) endif ! for smoothing, we use cell centers to find and locate nearby elements ! ! sets the location of the center of the elements and local points allocate(xl(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & yl(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & zl(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & cx0(NSPEC_AB), & cy0(NSPEC_AB), & cz0(NSPEC_AB),stat=ier) if (ier /= 0) stop 'Error allocating array xl etc.' ! sets element center location do ispec = 1, nspec_AB do k = 1, NGLLZ do j = 1, NGLLY do i = 1, NGLLX iglob = ibool(i,j,k,ispec) xl(i,j,k,ispec) = xstore(iglob) yl(i,j,k,ispec) = ystore(iglob) zl(i,j,k,ispec) = zstore(iglob) enddo enddo enddo cx0(ispec) = (xl(1,1,1,ispec) + xl(NGLLX,NGLLY,NGLLZ,ispec))/2.0 cy0(ispec) = (yl(1,1,1,ispec) + yl(NGLLX,NGLLY,NGLLZ,ispec))/2.0 cz0(ispec) = (zl(1,1,1,ispec) + zl(NGLLX,NGLLY,NGLLZ,ispec))/2.0 enddo ! frees memory deallocate(xstore,ystore,zstore) deallocate(xix,xiy,xiz,etax,etay,etaz,gammax,gammay,gammaz) deallocate(ibool) deallocate(jacobian) ! sets up slices to process if (num_interfaces_ext_mesh+1 > MAX_NODE_LIST) stop 'Error number of neighbor interfaces exceeds MAX_NODE_LIST' node_list(:) = -1 do i=1,num_interfaces_ext_mesh ! adds neighbors node_list(i) = my_neighbours_ext_mesh(i) enddo ! adds this partition itself node_list(num_interfaces_ext_mesh+1) = myrank ! user output if (myrank == 0) then print *,'slices:' print *,' rank:',myrank,' smoothing slices' print *,node_list(1:num_interfaces_ext_mesh+1) endif !do i=0,sizeprocs-1 ! if (myrank == i) then ! print *,'rank:',myrank,' smoothing slices' ! print *,node_list(1:num_interfaces_ext_mesh+1) ! print * ! endif !enddo ! GLL points weights call zwgljd(xigll,wxgll,NGLLX,GAUSSALPHA,GAUSSBETA) call zwgljd(yigll,wygll,NGLLY,GAUSSALPHA,GAUSSBETA) call zwgljd(zigll,wzgll,NGLLZ,GAUSSALPHA,GAUSSBETA) do k=1,NGLLZ do j=1,NGLLY do i=1,NGLLX wgll_cube(i,j,k) = wxgll(i)*wygll(j)*wzgll(k) enddo enddo enddo ! synchronizes call synchronize_all() ! loops over slices ! each process reads in his own neighbor slices and gaussian filters the values allocate(tk(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & bk(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier) if (ier /= 0) stop 'Error allocating array tk and bk' tk = 0.0_CUSTOM_REAL bk = 0.0_CUSTOM_REAL do inum = 1,num_interfaces_ext_mesh+1 iproc = node_list(inum) if (myrank == 0) print *,' reading slice:',iproc ! neighbor database file call create_name_database(prname,iproc,LOCAL_PATH) prname_lp = prname(1:len_trim(prname))//'external_mesh.bin' ! gets number of elements and global points for this partition open(unit=IIN,file=trim(prname_lp),status='old',action='read',form='unformatted',iostat=ier) if (ier /= 0) then print *,'Error could not open database file: ',trim(prname_lp) call exit_mpi(myrank, 'Error reading neighbors external mesh file') endif read(IIN) NSPEC_N read(IIN) NGLOB_N close(IIN) ! allocates arrays allocate(ibool(NGLLX,NGLLY,NGLLZ,NSPEC_N),stat=ier) if (ier /= 0) stop 'Error allocating array ibool' allocate(xstore(NGLOB_N),ystore(NGLOB_N),zstore(NGLOB_N),stat=ier) if (ier /= 0) stop 'Error allocating array xstore etc.' allocate(jacobian(NGLLX,NGLLY,NGLLZ,NSPEC_N),stat=ier) if (ier /= 0) stop 'Error allocating array jacobian' allocate(dummy(NGLLX,NGLLY,NGLLZ,NSPEC_N),stat=ier) if (ier /= 0) stop 'Error allocating array dummy' ! gets number of point locations (and jacobian, but jacobian not used by default) open(unit=IIN,file=trim(prname_lp),status='old',action='read',form='unformatted',iostat=ier) if (ier /= 0) then print *,'Error: could not open database file: ',trim(prname_lp) call exit_mpi(myrank, 'Error reading neighbors external mesh file') endif read(IIN) NSPEC_N read(IIN) NGLOB_N ! ibool file read(IIN) ibool ! global point arrays read(IIN) xstore read(IIN) ystore read(IIN) zstore ! reads in jacobian read(IIN) dummy ! xix read(IIN) dummy ! xiy read(IIN) dummy ! xiz read(IIN) dummy ! etax read(IIN) dummy ! etay read(IIN) dummy ! etaz read(IIN) dummy ! gammax read(IIN) dummy ! gammay read(IIN) dummy ! gammaz read(IIN) jacobian close(IIN) deallocate(dummy) ! get the location of the center of the elements and local points allocate(xx(NGLLX,NGLLY,NGLLZ,NSPEC_N), & yy(NGLLX,NGLLY,NGLLZ,NSPEC_N), & zz(NGLLX,NGLLY,NGLLZ,NSPEC_N), & cx(NSPEC_N), & cy(NSPEC_N), & cz(NSPEC_N),stat=ier) if (ier /= 0) stop 'Error allocating array xx etc.' ! sets element center location do ispec = 1, nspec_N do k = 1, NGLLZ do j = 1, NGLLY do i = 1, NGLLX iglob = ibool(i,j,k,ispec) xx(i,j,k,ispec) = xstore(iglob) yy(i,j,k,ispec) = ystore(iglob) zz(i,j,k,ispec) = zstore(iglob) enddo enddo enddo cx(ispec) = (xx(1,1,1,ispec) + xx(NGLLX,NGLLY,NGLLZ,ispec))/2.0 cy(ispec) = (yy(1,1,1,ispec) + yy(NGLLX,NGLLY,NGLLZ,ispec))/2.0 cz(ispec) = (zz(1,1,1,ispec) + zz(NGLLX,NGLLY,NGLLZ,ispec))/2.0 enddo deallocate(xstore,ystore,zstore) deallocate(ibool) ! data file write(prname,'(a,i6.6,a)') trim(indir)//'proc',iproc,'_' local_data_file = trim(prname) // trim(filename) // '.bin' open(unit = IIN,file = trim(local_data_file),status='old',action='read',form ='unformatted',iostat=ier) if (ier /= 0) then print *,'Error opening data file: ',trim(local_data_file) stop 'Error opening data file' endif allocate(dat(NGLLX,NGLLY,NGLLZ,NSPEC_N),stat=ier) if (ier /= 0) stop 'Error allocating dat array' read(IIN) dat close(IIN) if (iproc == myrank) max_old = maxval(abs(dat(:,:,:,:))) ! finds closest elements for smoothing !if (myrank==0) print *, ' start looping over elements and points for smoothing ...' ! loop over elements to be smoothed in the current slice do ispec = 1, nspec_AB ! --- only double loop over the elements in the search radius --- do ispec2 = 1, nspec_N ! calculates horizontal and vertical distance between two element centers call get_distance_vec(dist_h,dist_v,cx0(ispec),cy0(ispec),cz0(ispec),& cx(ispec2),cy(ispec2),cz(ispec2)) ! checks distance between centers of elements if (dist_h > sigma_h3 .or. dist_v > sigma_v3) cycle ! integration factors !factor(:,:,:) = jacobian(:,:,:,ispec2) * wgll_cube(:,:,:) !factor(:,:,:) = 1.0_CUSTOM_REAL ! loop over GLL points of the elements in current slice (ispec) do k = 1, NGLLZ do j = 1, NGLLY do i = 1, NGLLX ! reference location ! current point (i,j,k,ispec) location, cartesian coordinates x0 = xl(i,j,k,ispec) y0 = yl(i,j,k,ispec) z0 = zl(i,j,k,ispec) ! calculate weights based on gaussian smoothing exp_val = 0.0_CUSTOM_REAL call smoothing_weights_vec(x0,y0,z0,sigma_h2,sigma_v2,exp_val,& xx(:,:,:,ispec2),yy(:,:,:,ispec2),zz(:,:,:,ispec2)) ! adds GLL integration weights !exp_val(:,:,:) = exp_val(:,:,:) * factor(:,:,:) ! adds contribution of element ispec2 to smoothed kernel values tk(i,j,k,ispec) = tk(i,j,k,ispec) + sum(exp_val(:,:,:) * dat(:,:,:,ispec2)) ! normalization, integrated values of gaussian smoothing function bk(i,j,k,ispec) = bk(i,j,k,ispec) + sum(exp_val(:,:,:)) enddo enddo enddo ! i,j,k enddo ! ispec2 enddo ! ispec ! frees arrays deallocate(xx,yy,zz) deallocate(cx,cy,cz) deallocate(jacobian) deallocate(dat) enddo ! iproc if (myrank == 0) print * ! normalizes/scaling factor if (myrank == 0) print *, 'Scaling values: min/max = ',minval(bk),maxval(bk) allocate(dat_smooth(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier) if (ier /= 0) stop 'Error allocating array dat_smooth' dat_smooth(:,:,:,:) = 0.0_CUSTOM_REAL do ispec = 1, nspec_AB do k = 1, NGLLZ do j = 1, NGLLY do i = 1, NGLLX ! checks the normalization criterion !if (abs(bk(i,j,k,ispec) - norm) > 1.e-4) then ! print *, 'Problem norm here --- ', ispec, i, j, k, bk(i,j,k,ispec), norm !endif if (abs(bk(i,j,k,ispec)) < 1.e-18) then print *, 'Problem norm here --- ', ispec, i, j, k, bk(i,j,k,ispec), norm endif ! normalizes smoothed kernel values by integral value of gaussian weighting dat_smooth(i,j,k,ispec) = tk(i,j,k,ispec) / bk(i,j,k,ispec) enddo enddo enddo enddo ! ispec deallocate(tk,bk) max_new = maxval(abs(dat_smooth(:,:,:,:))) ! file output ! smoothed kernel file name write(ks_file,'(a,i6.6,a)') trim(outdir)//'/proc',myrank,'_'//trim(filename)//'_smooth.bin' open(IOUT,file=trim(ks_file),status='unknown',form='unformatted',iostat=ier) if (ier /= 0) stop 'Error opening smoothed kernel file' write(IOUT) dat_smooth(:,:,:,:) close(IOUT) if (myrank == 0) print *,'written: ',trim(ks_file) ! frees memory deallocate(dat_smooth) ! synchronizes call synchronize_all() ! the maximum value for the smoothed kernel norm = max_old call max_all_cr(norm, max_old) norm = max_new call max_all_cr(norm, max_new) if (myrank == 0) then print * print *,' Maximum data value before smoothing = ', max_old print *,' Maximum data value after smoothing = ', max_new print * close(IMAIN) endif ! stop all the processes and exit call finalize_mpi() end program smooth_sem ! ! ----------------------------------------------------------------------------- ! subroutine smoothing_weights_vec(x0,y0,z0,sigma_h2,sigma_v2,exp_val,& xx_elem,yy_elem,zz_elem) use constants implicit none real(kind=CUSTOM_REAL),dimension(NGLLX,NGLLY,NGLLZ),intent(out) :: exp_val real(kind=CUSTOM_REAL),dimension(NGLLX,NGLLY,NGLLZ),intent(in) :: xx_elem, yy_elem, zz_elem real(kind=CUSTOM_REAL),intent(in) :: x0,y0,z0,sigma_h2,sigma_v2 ! local parameters integer :: ii,jj,kk real(kind=CUSTOM_REAL) :: dist_h,dist_v real(kind=CUSTOM_REAL) :: sigma_h2_inv,sigma_v2_inv sigma_h2_inv = 1.0_CUSTOM_REAL / sigma_h2 sigma_v2_inv = 1.0_CUSTOM_REAL / sigma_v2 do kk = 1, NGLLZ do jj = 1, NGLLY do ii = 1, NGLLX ! point in second slice ! gets vertical and horizontal distance call get_distance_vec(dist_h,dist_v,x0,y0,z0, & xx_elem(ii,jj,kk),yy_elem(ii,jj,kk),zz_elem(ii,jj,kk)) ! gaussian function exp_val(ii,jj,kk) = exp(- sigma_h2_inv*(dist_h*dist_h) - sigma_v2_inv*(dist_v*dist_v)) enddo enddo enddo end subroutine smoothing_weights_vec ! ! ----------------------------------------------------------------------------- ! subroutine get_distance_vec(dist_h,dist_v,x0,y0,z0,x1,y1,z1) ! returns vector lengths as distances in radial and horizontal direction ! only for flat earth with z in vertical direction use constants implicit none real(kind=CUSTOM_REAL),intent(out) :: dist_h,dist_v real(kind=CUSTOM_REAL),intent(in) :: x0,y0,z0,x1,y1,z1 ! vertical distance dist_v = sqrt( (z0-z1)*(z0-z1) ) ! horizontal distance dist_h = sqrt( (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1) ) end subroutine get_distance_vec
gpl-2.0
QEF/q-e_schrodinger
Modules/eqn_lauevoid.f90
2
17227
! ! Copyright (C) 2016 National Institute of Advanced Industrial Science and Technology (AIST) ! [ This code is written by Satomichi Nishihara. ] ! ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !--------------------------------------------------------------------------- SUBROUTINE eqn_lauevoid(rismt, lboth, expand, ierr) !--------------------------------------------------------------------------- ! ! ... solve Laue-RISM equation from void-region, which is defined as ! ... ! ... / ! ... h1(gxy=0,z1) = | dz2 c2(gxy=0,z2) * x21(gxy=0,z2-z1) ! ... /void-region ! ... ! ... void-region is in right-hand side, left-hand side or between right- and left-hand side, ! ... where solvents does not exist and c2 is linear function. ! ... calculated total correlations are added to `hgz' or `hsgz'. ! ... ! USE err_rism, ONLY : IERR_RISM_NULL, IERR_RISM_INCORRECT_DATA_TYPE USE rism, ONLY : rism_type, ITYPE_LAUERISM USE solvmol, ONLY : get_nuniq_in_solVs ! IMPLICIT NONE ! TYPE(rism_type), INTENT(INOUT) :: rismt LOGICAL, INTENT(IN) :: lboth ! both-hands calculation, or not LOGICAL, INTENT(IN) :: expand ! expand-cell(.TRUE.) or unit-cell(.FALSE.) INTEGER, INTENT(OUT) :: ierr ! INTEGER :: nq ! ! ... number of sites in solvents nq = get_nuniq_in_solVs() ! ! ... check data type IF (rismt%itype /= ITYPE_LAUERISM) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! IF (rismt%mp_site%nsite < nq) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! IF (rismt%nrzs < rismt%dfft%nr3) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! IF (rismt%nrzl < rismt%lfft%nrz) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! IF (rismt%lfft%xright .AND. rismt%lfft%xleft) THEN ! ! ... void-region is between right- and left-hand side CALL eqn_lauevoid_between(rismt, lboth, expand) ! ELSE ! ! ... void-region is right-hand side or left-hand side CALL eqn_lauevoid_oneside(rismt, expand) ! END IF ! ierr = IERR_RISM_NULL ! END SUBROUTINE eqn_lauevoid ! !--------------------------------------------------------------------------- SUBROUTINE eqn_lauevoid_oneside(rismt, expand) !--------------------------------------------------------------------------- ! ! ... Laue-RISM equation from void-region of right-hand side or left-hand side. ! USE cell_base, ONLY : alat USE constants, ONLY : K_BOLTZMANN_RY USE kinds, ONLY : DP USE mp, ONLY : mp_sum USE rism, ONLY : rism_type USE solvmol, ONLY : solVs, get_nuniq_in_solVs, & & iuniq_to_isite, isite_to_isolV, isite_to_iatom ! IMPLICIT NONE ! TYPE(rism_type), INTENT(INOUT) :: rismt LOGICAL, INTENT(IN) :: expand ! expand-cell(.TRUE.) or unit-cell(.FALSE.) ! INTEGER :: nq INTEGER :: iq1, iq2 INTEGER :: iiq1, iiq2 INTEGER :: iv2 INTEGER :: isolV2 INTEGER :: iatom2 INTEGER :: iz INTEGER :: izsta INTEGER :: izend INTEGER :: izsolv INTEGER :: izvoid INTEGER :: nzint INTEGER :: izint INTEGER :: izdelt REAL(DP) :: beta REAL(DP) :: qv2 REAL(DP) :: z REAL(DP) :: zstep REAL(DP) :: zoffs REAL(DP) :: zedge REAL(DP) :: voppo REAL(DP) :: vsign REAL(DP) :: cz REAL(DP) :: dz REAL(DP), ALLOCATABLE :: c2(:) REAL(DP), ALLOCATABLE :: d2(:) REAL(DP), ALLOCATABLE :: h1(:) ! ! ... number of sites in solvents nq = get_nuniq_in_solVs() ! ! ... beta = 1 / (kB * T) beta = 1.0_DP / K_BOLTZMANN_RY / rismt%temp ! ! ... set integral regions as index of long Z-stick (i.e. expanded cell) IF (rismt%lfft%xright) THEN IF (expand) THEN izsta = rismt%lfft%izright_gedge izend = rismt%lfft%nrz ELSE izsta = rismt%lfft%izright_start0 izend = rismt%lfft%izright_end0 END IF ! izsolv = rismt%lfft%izright_start0 izvoid = izsolv - 1 ! IF (rismt%lfft%gxystart > 1) THEN voppo = DBLE(rismt%vleft(1)) / alat ELSE voppo = 0.0_DP END IF ! vsign = -1.0_DP ! ELSE !IF (rismt%lfft%xleft) THEN IF (expand) THEN izsta = 1 izend = rismt%lfft%izleft_gedge ELSE izsta = rismt%lfft%izleft_start0 izend = rismt%lfft%izleft_end0 END IF ! izsolv = rismt%lfft%izleft_end0 izvoid = izsolv + 1 ! IF (rismt%lfft%gxystart > 1) THEN voppo = DBLE(rismt%vright(1)) / alat ELSE voppo = 0.0_DP END IF ! vsign = +1.0_DP END IF ! ! ... count integral points along Z nzint = izend - izsta + 1 ! ! ... properties about length (in a.u.) zstep = alat * rismt%lfft%zstep zoffs = alat * (rismt%lfft%zleft + rismt%lfft%zoffset) zedge = zoffs + zstep * DBLE(izsolv - 1) ! ! ... allocate working memory IF (rismt%nsite > 0) THEN ALLOCATE(c2(rismt%nsite)) ALLOCATE(d2(rismt%nsite)) END IF IF (nzint > 0) THEN ALLOCATE(h1(nzint)) END IF ! ! ... calculate c2, d2 DO iq2 = rismt%mp_site%isite_start, rismt%mp_site%isite_end iiq2 = iq2 - rismt%mp_site%isite_start + 1 iv2 = iuniq_to_isite(1, iq2) isolV2 = isite_to_isolV(iv2) iatom2 = isite_to_iatom(iv2) qv2 = solVs(isolV2)%charge(iatom2) ! IF (rismt%lfft%gxystart > 1) THEN c2(iiq2) = rismt%csdg0(izsolv, iiq2) & & - beta * qv2 * DBLE(rismt%vlgz(izsolv)) d2(iiq2) = -beta * qv2 * voppo ELSE c2(iiq2) = 0.0_DP d2(iiq2) = 0.0_DP END IF END DO ! IF (rismt%nsite > 0) THEN CALL mp_sum(c2, rismt%mp_site%intra_sitg_comm) CALL mp_sum(d2, rismt%mp_site%intra_sitg_comm) END IF ! ! ... Laue-RISM equation of void-region DO iq1 = 1, nq IF (rismt%mp_site%isite_start <= iq1 .AND. iq1 <= rismt%mp_site%isite_end) THEN iiq1 = iq1 - rismt%mp_site%isite_start + 1 ELSE iiq1 = 0 END IF ! IF (nzint > 0) THEN h1 = 0.0_DP END IF ! DO iq2 = rismt%mp_site%isite_start, rismt%mp_site%isite_end iiq2 = iq2 - rismt%mp_site%isite_start + 1 ! ! ... h1(z1) !$omp parallel do default(shared) private(iz, izint, izdelt, z, cz, dz) DO iz = izsta, izend izint = iz - izsta + 1 izdelt = ABS(iz - izvoid) + 1 ! IF (izdelt <= rismt%lfft%nrz) THEN z = zoffs + zstep * DBLE(iz - 1) cz = c2(iiq2) + d2(iiq2) * (z - zedge) dz = d2(iiq2) * vsign h1(izint) = h1(izint) & & + cz * rismt%xgs0(izdelt, iiq2, iq1) & & + dz * rismt%xgs1(izdelt, iiq2, iq1) END IF END DO !$omp end parallel do END DO ! IF (nzint > 0) THEN CALL mp_sum(h1, rismt%mp_site%inter_sitg_comm) END IF ! IF (iiq1 > 0) THEN IF (expand) THEN ! ... add h1 -> hsgz IF (rismt%lfft%gxystart > 1) THEN !$omp parallel do default(shared) private(iz, izint) DO iz = izsta, izend izint = iz - izsta + 1 rismt%hsgz(iz, iiq1) = rismt%hsgz(iz, iiq1) + CMPLX(h1(izint), 0.0_DP, kind=DP) END DO !$omp end parallel do END IF ! ELSE ! ... add h1 -> hg0 !$omp parallel do default(shared) private(iz, izint) DO iz = izsta, izend izint = iz - izsta + 1 rismt%hg0(iz, iiq1) = rismt%hg0(iz, iiq1) + h1(izint) END DO !$omp end parallel do END IF END IF ! END DO ! ! ... deallocate working memory IF (rismt%nsite > 0) THEN DEALLOCATE(c2) DEALLOCATE(d2) END IF IF (nzint > 0) THEN DEALLOCATE(h1) END IF ! END SUBROUTINE eqn_lauevoid_oneside ! !--------------------------------------------------------------------------- SUBROUTINE eqn_lauevoid_between(rismt, lboth, expand) !--------------------------------------------------------------------------- ! ! ... Laue-RISM equation from void-region between right- and left-hand side. ! USE cell_base, ONLY : alat USE constants, ONLY : K_BOLTZMANN_RY USE kinds, ONLY : DP USE mp, ONLY : mp_sum USE rism, ONLY : rism_type USE solvmol, ONLY : solVs, get_nuniq_in_solVs, & & iuniq_to_isite, isite_to_isolV, isite_to_iatom ! IMPLICIT NONE ! TYPE(rism_type), INTENT(INOUT) :: rismt LOGICAL, INTENT(IN) :: lboth ! both-hands calculation, or not LOGICAL, INTENT(IN) :: expand ! expand-cell(.TRUE.) or unit-cell(.FALSE.) ! INTEGER :: nq INTEGER :: iq1, iq2 INTEGER :: iiq1, iiq2 INTEGER :: iv2 INTEGER :: isolV2 INTEGER :: iatom2 INTEGER :: iz INTEGER :: nzright INTEGER :: izright_sta INTEGER :: izright_end INTEGER :: izright_solv INTEGER :: izright_void INTEGER :: nzleft INTEGER :: izleft_sta INTEGER :: izleft_end INTEGER :: izleft_solv INTEGER :: izleft_void INTEGER :: izint INTEGER :: izdelt1 INTEGER :: izdelt2 REAL(DP) :: beta REAL(DP) :: qv2 REAL(DP) :: z REAL(DP) :: zstep REAL(DP) :: zoffs REAL(DP) :: zright_edge REAL(DP) :: zleft_edge REAL(DP) :: c2, cz REAL(DP) :: d2, dz REAL(DP), ALLOCATABLE :: xg0(:) REAL(DP), ALLOCATABLE :: xg1(:) REAL(DP), ALLOCATABLE :: cright(:) REAL(DP), ALLOCATABLE :: cleft(:) REAL(DP), ALLOCATABLE :: hright(:) REAL(DP), ALLOCATABLE :: hleft(:) ! ! ... has void-region ? IF ((rismt%lfft%izright_start0 - rismt%lfft%izleft_end0) <= 1) THEN RETURN END IF ! ! ... number of sites in solvents nq = get_nuniq_in_solVs() ! ! ... beta = 1 / (kB * T) beta = 1.0_DP / K_BOLTZMANN_RY / rismt%temp ! ! ... set integral regions as index of long Z-stick (i.e. expanded cell) IF (expand) THEN izright_sta = rismt%lfft%izright_gedge izright_end = rismt%lfft%nrz izleft_sta = 1 izleft_end = rismt%lfft%izleft_gedge ELSE izright_sta = rismt%lfft%izright_start0 izright_end = rismt%lfft%izright_end0 izleft_sta = rismt%lfft%izleft_start0 izleft_end = rismt%lfft%izleft_end0 END IF ! izright_solv = rismt%lfft%izright_start0 izright_void = izright_solv - 1 izleft_solv = rismt%lfft%izleft_end0 izleft_void = izleft_solv + 1 ! ! ... count integral points along Z nzright = izright_end - izright_sta + 1 nzleft = izleft_end - izleft_sta + 1 ! ! ... properties about length (in a.u.) zstep = alat * rismt%lfft%zstep zoffs = alat * (rismt%lfft%zleft + rismt%lfft%zoffset) ! zright_edge = zoffs + zstep * DBLE(izright_solv - 1) zleft_edge = zoffs + zstep * DBLE(izleft_solv - 1) ! ! ... allocate working memory IF (rismt%nrzl > 0) THEN ALLOCATE(xg0(rismt%nrzl)) ALLOCATE(xg1(rismt%nrzl)) END IF IF (rismt%nsite > 0) THEN ALLOCATE(cright(rismt%nsite)) ALLOCATE(cleft( rismt%nsite)) END IF IF (nzright > 0) THEN ALLOCATE(hright(nzright)) END IF IF (nzleft > 0) THEN ALLOCATE(hleft(nzleft)) END IF ! ! ... calculate cright(z2), cleft(z2) DO iq2 = rismt%mp_site%isite_start, rismt%mp_site%isite_end iiq2 = iq2 - rismt%mp_site%isite_start + 1 iv2 = iuniq_to_isite(1, iq2) isolV2 = isite_to_isolV(iv2) iatom2 = isite_to_iatom(iv2) qv2 = solVs(isolV2)%charge(iatom2) ! IF (rismt%lfft%gxystart > 1) THEN cright(iiq2) = rismt%csdg0(izright_solv, iiq2) & & - beta * qv2 * DBLE(rismt%vlgz(izright_solv)) cleft( iiq2) = rismt%csdg0(izleft_solv, iiq2) & & - beta * qv2 * DBLE(rismt%vlgz(izleft_solv)) ELSE cright(iiq2) = 0.0_DP cleft( iiq2) = 0.0_DP END IF END DO ! IF (rismt%nsite > 0) THEN CALL mp_sum(cright, rismt%mp_site%intra_sitg_comm) CALL mp_sum(cleft, rismt%mp_site%intra_sitg_comm) END IF ! ! ... Laue-RISM equation of void-region DO iq1 = 1, nq IF (rismt%mp_site%isite_start <= iq1 .AND. iq1 <= rismt%mp_site%isite_end) THEN iiq1 = iq1 - rismt%mp_site%isite_start + 1 ELSE iiq1 = 0 END IF ! IF (nzright > 0) THEN hright = 0.0_DP END IF IF (nzleft > 0) THEN hleft = 0.0_DP END IF ! DO iq2 = rismt%mp_site%isite_start, rismt%mp_site%isite_end iiq2 = iq2 - rismt%mp_site%isite_start + 1 ! d2 = (cright(iiq2) - cleft(iiq2)) / (zright_edge - zleft_edge) ! ! ... hleft(z1) c2 = cleft(iiq2) ! IF (.NOT. lboth) THEN xg0 = rismt%xgs0(1:rismt%nrzl, iiq2, iq1) xg1 = rismt%xgs1(1:rismt%nrzl, iiq2, iq1) ELSE xg0 = rismt%ygs0(1:rismt%nrzl, iiq2, iq1) xg1 = rismt%ygs1(1:rismt%nrzl, iiq2, iq1) END IF ! !$omp parallel do default(shared) private(iz, izint, izdelt1, izdelt2, z, cz, dz) DO iz = izleft_sta, izleft_end izint = iz - izleft_sta + 1 izdelt1 = ABS(iz - izleft_void ) + 1 izdelt2 = ABS(iz - izright_solv) + 1 ! IF (izdelt1 <= rismt%lfft%nrz) THEN z = zoffs + zstep * DBLE(iz - 1) cz = c2 + d2 * (z - zleft_edge) dz = d2 hleft(izint) = hleft(izint) & & + cz * xg0(izdelt1) & & + dz * xg1(izdelt1) END IF ! IF (izdelt2 <= rismt%lfft%nrz) THEN z = zoffs + zstep * DBLE(iz - 1) cz = c2 + d2 * (z - zleft_edge) dz = d2 hleft(izint) = hleft(izint) & & - cz * xg0(izdelt2) & & - dz * xg1(izdelt2) END IF END DO !$omp end parallel do ! ! ... hright(z1) c2 = cright(iiq2) ! xg0 = rismt%xgs0(1:rismt%nrzl, iiq2, iq1) xg1 = rismt%xgs1(1:rismt%nrzl, iiq2, iq1) ! !$omp parallel do default(shared) private(iz, izint, izdelt1, izdelt2, z, cz, dz) DO iz = izright_sta, izright_end izint = iz - izright_sta + 1 izdelt1 = ABS(iz - izright_void) + 1 izdelt2 = ABS(iz - izleft_solv ) + 1 ! IF (izdelt1 <= rismt%lfft%nrz) THEN z = zoffs + zstep * DBLE(iz - 1) cz = c2 + d2 * (z - zright_edge) dz = -d2 hright(izint) = hright(izint) & & + cz * xg0(izdelt1) & & + dz * xg1(izdelt1) END IF ! IF (izdelt2 <= rismt%lfft%nrz) THEN z = zoffs + zstep * DBLE(iz - 1) cz = c2 + d2 * (z - zright_edge) dz = -d2 hright(izint) = hright(izint) & & - cz * xg0(izdelt2) & & - dz * xg1(izdelt2) END IF END DO !$omp end parallel do END DO ! IF (nzright > 0) THEN CALL mp_sum(hright, rismt%mp_site%inter_sitg_comm) END IF IF (nzleft > 0) THEN CALL mp_sum(hleft, rismt%mp_site%inter_sitg_comm) END IF ! IF (iiq1 > 0) THEN IF (expand) THEN IF (rismt%lfft%gxystart > 1) THEN ! ... add hleft -> hsgz !$omp parallel do default(shared) private(iz, izint) DO iz = izleft_sta, izleft_end izint = iz - izleft_sta + 1 rismt%hsgz(iz, iiq1) = rismt%hsgz(iz, iiq1) + CMPLX(hleft(izint), 0.0_DP, kind=DP) END DO !$omp end parallel do ! ! ... add hright -> hsgz !$omp parallel do default(shared) private(iz, izint) DO iz = izright_sta, izright_end izint = iz - izright_sta + 1 rismt%hsgz(iz, iiq1) = rismt%hsgz(iz, iiq1) + CMPLX(hright(izint), 0.0_DP, kind=DP) END DO !$omp end parallel do END IF ! ELSE ! ... add hleft -> hg0 !$omp parallel do default(shared) private(iz, izint) DO iz = izleft_sta, izleft_end izint = iz - izleft_sta + 1 rismt%hg0(iz, iiq1) = rismt%hg0(iz, iiq1) + hleft(izint) END DO !$omp end parallel do ! ! ... add hright -> hg0 !$omp parallel do default(shared) private(iz, izint) DO iz = izright_sta, izright_end izint = iz - izright_sta + 1 rismt%hg0(iz, iiq1) = rismt%hg0(iz, iiq1) + hright(izint) END DO !$omp end parallel do END IF END IF ! END DO ! ! ... deallocate working memory IF (rismt%nrzl > 0) THEN DEALLOCATE(xg0) DEALLOCATE(xg1) END IF IF (rismt%nsite > 0) THEN DEALLOCATE(cright) DEALLOCATE(cleft) END IF IF (nzright > 0) THEN DEALLOCATE(hright) END IF IF (nzleft > 0) THEN DEALLOCATE(hleft) END IF ! END SUBROUTINE eqn_lauevoid_between
gpl-2.0
yangf4/phasta
M2NFixBnd/src/readnblk.f
5
27844
c readnblk.f (pronounce "Reed and Block Dot Eff") contains: c c module readarrays ("Red Arrays") -- contains the arrays that c are read in from binary files but not immediately blocked c through pointers. c c subroutine readnblk ("Reed and Block") -- allocates space for c and reads data to be contained in module readarrays. Reads c all remaining data and blocks them with pointers. c module readarrays real*8, allocatable :: point2x(:,:) real*8, allocatable :: qold(:,:) real*8, allocatable :: dwal(:) real*8, allocatable :: errors(:,:) real*8, allocatable :: ybar(:,:) real*8, allocatable :: yphbar(:,:,:) real*8, allocatable :: vort(:,:) real*8, allocatable :: uold(:,:) real*8, allocatable :: acold(:,:) integer, allocatable :: iBCtmp(:) real*8, allocatable :: BCinp(:,:) integer, allocatable :: point2ilwork(:) integer, allocatable :: nBC(:) integer, allocatable :: point2iper(:) integer, allocatable :: point2ifath(:) integer, allocatable :: point2nsons(:) end module subroutine readnblk c use readarrays include "commonM2NFixBnd.h" include "mpif.h" c real*8, allocatable :: xread(:,:), qread(:,:), qread1(:) real*8, allocatable :: uread(:,:), acread(:,:) real*8, allocatable :: BCinpread(:,:) real*8 globmax,globmin integer, allocatable :: iperread(:), iBCtmpread(:) integer, allocatable :: ilworkread(:), nBCread(:) character*10 cname2 character*30 fmt1 character*255 fname1,fnamer,fnamelr character*255 warning integer :: descriptor, color, nfiles, nfields integer :: numparts, nppf character*255 fname2, temp2 character*64 temp1 integer :: igeom, ibndc, irstin, ierr integer :: ndof, ndoferrors, ndofybar integer :: itmp, itmp2 integer :: irstart, irstartmap, iybar integer :: ierror, numphavg, ivort, idwal, idebug, iphavg integer intfromfile(50) ! integers read from headers logical exinput c c c.... determine the step number to start with c ! open(unit=72,file='numstart.dat',status='old') ! read(72,*) irstart ! close(72) if(myrank == 0) then fnamer='M2N_input.dat' fnamer = trim(fnamer) // char(0) inquire(file=fnamer,exist=exinput) if(exinput) then open(unit=72,file=fnamer,status='old') read(72,*) irstart read(72,*) irstartmap read(72,*) iybar read(72,*) ierror read(72,*) numphavg read(72,*) ivort read(72,*) idwal read(72,*) idebug close(72) else write(*,*) 'ERROR: Input file ', & trim(fnamer),' does not exist!' endif endif call mpi_barrier(mpi_comm_world, ierr) call mpi_bcast(exinput,1,MPI_LOGICAL,0,mpi_comm_world,ierr) if(.not. exinput) then ! M2NFixBnd_input.dat does not exist. Quit ! call mpi_abort(mpi_comm_world,911,ierr) ! call mpi_finalize(ierr) return else ! broadcast the information read by rank 0 call mpi_bcast(irstart,1,MPI_INTEGER,0,mpi_comm_world,ierr) call mpi_bcast(iybar,1,MPI_INTEGER,0,mpi_comm_world,ierr) call mpi_bcast(ierror,1,MPI_INTEGER,0,mpi_comm_world,ierr) call mpi_bcast(numphavg,1,MPI_INTEGER,0,mpi_comm_world,ierr) call mpi_bcast(ivort,1,MPI_INTEGER,0,mpi_comm_world,ierr) call mpi_bcast(idwal,1,MPI_INTEGER,0,mpi_comm_world,ierr) endif if(myrank == 0 ) then ! Print some info write(*,*) 'The solution field is reduced by default' if(iybar .gt. 0) then write(*,*) 'The ybar field will also be reduced' iybar = 1 ! security else write(*,*) 'The ybar field will NOT be reduced' endif if(ierror .gt. 0) then write(*,*) 'The error field will also be reduced' ierror = 1 ! security else write(*,*) 'The error field will NOT be reduced' endif if(numphavg .gt. 0) then write(*,*) 'The phase average fields (',numphavg, & ') will also be reduced' else write(*,*) 'The phase average fields will NOT be reduced' endif if(ivort .gt. 0) then write(*,*) 'The vorticity field will also be reduced' ivort = 1 ! security else write(*,*) 'The vorticity field will NOT be reduced' endif if(idwal .gt. 0) then write(*,*) 'The dwal field will also be reduced' idwal = 1 ! security else write(*,*) 'The dwal field will NOT be reduced' endif write(*,*) '' endif call mpi_barrier(mpi_comm_world, ierr) if(myrank == 0) then write(*,*) 'Reading the geombcRed-dat files' endif lstep=irstart ! in case restart files have no fields nfiles = nsynciofiles numparts = numpe !This is the common settings. Beware if you try to compute several parts per process c c.... input the geometry parameters c color = int(myrank/(numparts/nfiles)) !Should call the color routine in SyncIO here itmp2 = int(log10(float(color+1)))+1 write (temp2,"('(''geombcRed-dat.'',i',i1,')')") itmp2 write (fnamer,temp2) (color+1) fnamer = trim(fnamer)//char(0) ieleven=11 ione=1 itmp = int(log10(float(myrank+1)))+1 call queryphmpiio(fnamer, nfields, nppf); if (myrank == 0) then write(*,*) 'Number of fields in geombcRed-dat: ',nfields write(*,*) 'Number of parts per file geombcRed-dat: ',nppf endif call initphmpiio( nfields, nppf, nfiles, igeom, & 'read'//char(0)) call openfile( fnamer, 'read'//char(0), igeom ) write (temp1,"('(''number of nodes@'',i',i1,',A1)')") itmp write (fname2,temp1) (myrank+1),'?' call readheader(igeom,fname2//char(0),numnp,ione, & 'integer'//char(0), iotype) write (temp1,"('(''number of modes@'',i',i1,',A1)')") itmp write (fname2,temp1) (myrank+1),'?' call readheader(igeom,fname2//char(0),nshg,ione, & 'integer'//char(0), iotype) write (temp1,"('(''number of interior elements@'',i',i1,',A1)')") & itmp write (fname2,temp1) (myrank+1),'?' call readheader(igeom,fname2//char(0),numel,ione, & 'integer'//char(0), iotype) write (temp1,"('(''number of boundary elements@'',i',i1,',A1)')") & itmp write (fname2,temp1) (myrank+1),'?' call readheader(igeom,fname2//char(0),numelb,ione, & 'integer'//char(0),iotype) write (temp1, & "('(''maximum number of element nodes@'',i',i1,',A1)')") itmp write (fname2,temp1) (myrank+1),'?' call readheader(igeom,fname2//char(0),nen,ione, &'integer'//char(0),iotype) write (temp1,"('(''number of interior tpblocks@'',i',i1,',A1)')") & itmp write (fname2,temp1) (myrank+1),'?' call readheader(igeom,fname2//char(0),nelblk,ione, & 'integer'//char(0) ,iotype) write (temp1,"('(''number of boundary tpblocks@'',i',i1,',A1)')") & itmp write (fname2,temp1) (myrank+1),'?' call readheader(igeom,fname2//char(0),nelblb,ione, & 'integer'//char(0), iotype) write (temp1, & "('(''number of nodes with Dirichlet BCs@'',i',i1,',A1)')") itmp write (fname2,temp1) (myrank+1),'?' call readheader(igeom,fname2//char(0),numpbc,ione, & 'integer'//char(0),iotype) write (temp1,"('(''number of shape functions@'',i',i1,',A1)')") & itmp write (fname2,temp1) (myrank+1),'?' call readheader(igeom,fname2//char(0),ntopsh,ione, & 'integer'//char(0),iotype) call closefile( igeom, "read"//char(0) ) call finalizephmpiio( igeom ) c c.... calculate the maximum number of boundary element nodes c nenb = 3 !was initialized to 0 but do i = 1, melCat !melCat is 0 here if (nen .eq. nenCat(i,nsd)) nenb = max(nenCat(i,nsd-1), nenb) enddo c if (myrank == master) then if (nenb .eq. 0) call error ('input '//char(0), & 'nen '//char(0),nen) endif c c.... setup some useful constants c I3nsd = nsd / 3 ! nsd=3 integer flag E3nsd = float(I3nsd) ! nsd=3 real flag c if(matflg(1,1).lt.0) then nflow = nsd + 1 else nflow = nsd + 2 endif ndof = nsd + 2 nsclr=impl(1)/100 ndof=ndof+nsclr ! number of sclr transport equations to solve ndofBC = ndof + I3nsd ! dimension of BC array ndiBCB = 2 ! dimension of iBCB array ndBCB = ndof + 1 ! dimension of BCB array c nsymdf = (ndof*(ndof + 1)) / 2 ! symm. d.o.f.'s c c.... Read restart files c c.... read the header and check it against the run data c call mpi_barrier(mpi_comm_world, ierr) if(myrank == 0) then write(*,*) 'Reading the RestartRedTmp-dat files' endif ! Beware in what follows! nshg2 read from the header of the solution, ! dwal, errors and ybar can be different from nshg read from the geombc files ! This is due to the fact that nshg2 represents the largest vID referenced ! by the mapping and not the largest vID present in the mesh. ! qold, dwal, errors, ybar must be allocated to nshg and initialized ! to a large negative value. The unmapped vertices will be updated ! through communication with ilwork. itmp=1 if (irstart .gt. 0) itmp = int(log10(float(irstart+1)))+1 write (fmt1,"('(''restartRedTmp-dat.'',i',i1,',1x)')") itmp write (fnamer,fmt1) irstart fnamer = trim(fnamer) // cname2(color+1) call queryphmpiio(fnamer//char(0), nfields, nppf); if (myrank == 0) then write(*,*) 'Number of fields in restartRedTmp-dat: ',nfields write(*,*) 'Number of parts per file restartRedTmp-dat: ',nppf endif call initphmpiio(nfields,nppf,nfiles,descriptor, & 'read'//char(0)) call openfile( fnamer//char(0) , & 'read'//char(0), descriptor ) c c Read the solution c ithree=3 itmp = int(log10(float(myrank+1)))+1 write (temp1,"('(''solution@'',i',i1,',A1)')") itmp write (fname1,temp1) (myrank+1),'?' fname1 = trim(fname1) intfromfile=0 call readheader(descriptor,fname1//char(0) ,intfromfile, & ithree,'integer'//char(0), iotype) c c.... read the values of primitive variables into q c if(intfromfile(1).ne.0) then nshg2=intfromfile(1) ndof2=intfromfile(2) ndof=ndof2 !This must be the same anyway allocate( qold(nshg,ndof) ) qold(:,:) = -9.87654321e32 lstep=intfromfile(3) allocate( qread(nshg2,ndof2) ) if (nshg2 .ne. nshg) then write(*,*) 'nshg from geombc and nshg2 from restart differ' & //' on rank', myrank, ' :',nshg,nshg2, & ' - Probably mixing phasta files' endif call mpi_barrier(mpi_comm_world, ierr) iqsiz=nshg2*ndof2 call readdatablock(descriptor,fname1//char(0),qread,iqsiz, & 'double'//char(0),iotype) qold(1:nshg2,1:ndof2)=qread(1:nshg2,1:ndof2) deallocate(qread) else if (myrank.eq.master) then if (matflg(1,1).eq.0) then ! compressible warning='Solution is set to zero (with p and T to one)' else warning='Solution is set to zero' endif write(*,*) warning// char(0) endif qold=zero if (matflg(1,1).eq.0) then ! compressible qold(:,1)=one ! avoid zero pressure qold(:,nflow)=one ! avoid zero temperature endif endif c c Read the ybar c ndofybar = 0 if(iybar==1) then itmp = int(log10(float(myrank+1)))+1 write (temp1,"('(''ybar@'',i',i1,',a1)')") itmp write (fname1,temp1) (myrank+1),'?' fname1 = trim(fname1) intfromfile=0 call readheader(descriptor,fname1//char(0),intfromfile, & ithree,'integer'//char(0),iotype) nshg2=intfromfile(1) ndofybar=intfromfile(2) !lstep=intfromfile(3) if(ndofybar .ne. 0) then allocate( ybar(nshg,ndofybar) ) ybar(:,:) = -9.87654321e32 allocate( qread(nshg2,ndofybar) ) iqsiz=nshg2*ndofybar call readdatablock(descriptor,fname1//char(0) ,qread,iqsiz, & 'double'//char(0),iotype) ybar(1:nshg2,1:ndofybar)=qread(1:nshg2,1:ndofybar) deallocate(qread) else write(*,*) 'WARNING: ybar is missing in the restart files' iybar = 0 endif endif c c Read the errors c ndoferrors=0 if(ierror == 1) then write (temp1,"('(''errors@'',i',i1,',a1)')") & itmp write (fname1,temp1) (myrank+1),'?' fname1 = trim(fname1) intfromfile=0 call readheader(descriptor,fname1//char(0),intfromfile, & ithree,'integer'//char(0),iotype) nshg2=intfromfile(1) ndoferrors=intfromfile(2) !lstep=intfromfile(3) if(ndoferrors .ne. 0) then allocate( errors(nshg,ndoferrors) ) errors(:,:) = -9.87654321e32 allocate( qread(nshg2,ndoferrors) ) iqsiz=nshg2*ndoferrors call readdatablock(descriptor,fname1//char(0),qread,iqsiz, & 'double'//char(0),iotype) errors(1:nshg2,1:ndoferrors)=qread(1:nshg2,1:ndoferrors) deallocate(qread) else if(myrank==0) then write(*,*) 'WARNING: errors is missing in the restart files' endif ierror = 0 endif endif ! ! Read the phase_average fields ! ndofyphbar=0 if(numphavg .gt. 0) then do iphavg = 1,numphavg itmp = int(log10(float(myrank+1)))+1 itmp2 = int(log10(float(iphavg)))+1 write (temp1, & "('(''phase_average'',i',i1,',''@'',i',i1,',A1)')") & itmp2, itmp write (fname1,temp1) iphavg,(myrank+1),'?' fname1 = trim(fname1) intfromfile=0 call readheader(descriptor,fname1//char(0),intfromfile, & ithree,'integer'//char(0),iotype) nshg2=intfromfile(1) ndofyphbar=intfromfile(2) !lstep=intfromfile(3) if(ndofyphbar.ne.0) then ! Allocate some memory for the first ts only if(iphavg==1) then allocate( yphbar(nshg,ndofyphbar,numphavg) ) yphbar(:,:,:) = -9.87654321e32 endif allocate( qread(nshg2,ndofyphbar) ) iqsiz = nshg2*ndofyphbar call readdatablock(descriptor,fname1//char(0),qread,iqsiz, & 'double'//char(0),iotype) yphbar(1:nshg2,1:ndofyphbar,iphavg) = & qread(1:nshg2,1:ndofyphbar) deallocate(qread) else if(myrank==0) then write(*,*)'WARNING: phase_average is missing '// & 'in the restart files' endif numphavg = 0 if(iphavg > 1) then deallocate(yphbar) endif exit endif enddo endif ! ! follow the usual convention for loading the vorticity field ! ndofvort=0 if(ivort == 1) then itmp = int(log10(float(myrank+1)))+1 write (temp1,"('(''vorticity@'',i',i1,',a1)')") itmp write (fname1,temp1) (myrank+1),'?' fname1 = trim(fname1) intfromfile=0 call readheader(descriptor,fname1//char(0),intfromfile, & ithree,'integer'//char(0),iotype) nshg2=intfromfile(1) ndofvort=intfromfile(2) !lstep=intfromfile(3) if(ndofvort .ne. 0) then allocate(vort(nshg,ndofvort)) vort(:,:) = -9.87654321e32 allocate(qread(nshg2,ndofvort)) iqsiz = nshg2*ndofvort call readdatablock(descriptor,fname1//char(0),qread,iqsiz, & 'double'//char(0),iotype) vort(1:nshg2,1:ndofvort)=qread(1:nshg2,1:ndofvort) deallocate(qread) else if(myrank==0) then write(*,*) 'WARNING: vorticity is missing '// & 'in the restart files' endif ivort = 0 endif endif c c Read the dwal c ndofdwal=0 if(idwal==1) then write (temp1,"('(''dwal@'',i',i1,',a1)')") itmp write (fname1,temp1) (myrank+1),'?' fname1 = trim(fname1) intfromfile=0 call readheader(descriptor,fname1//char(0),intfromfile, & ithree,'integer'//char(0),iotype) nshg2=intfromfile(1) ndofdwal=intfromfile(2) if(ndofdwal .ne. 0) then if(ndofdwal.ne.1) then warning='WARNING: ndofdwal not equal 1' write(*,*) warning, ndofdwal endif allocate( dwal(nshg) ) dwal(:) = -9.87654321e32 allocate( qread1(nshg2) ) iqsiz=nshg2*1 call readdatablock(descriptor,fname1//char(0),qread1,iqsiz, & 'double'//char(0),iotype) dwal(1:nshg2)=qread1(1:nshg2) deallocate(qread1) else if(myrank==0) then write(*,*) 'WARNING: dwal is missing in the restart files' endif idwal = 0 endif endif ! !.... close c-binary files ! call closefile( descriptor, "read"//char(0) ) call finalizephmpiio( descriptor ) c.... ----------------------> Communication tasks <-------------------- c if(numpe > 1) then call mpi_barrier(mpi_comm_world, ierr) if(myrank == 0) then write(*,*) 'Reading the geombc-dat files again for ilwork' endif color = int(myrank/(numparts/nfiles)) !Should call the color routine in SyncIO here itmp2 = int(log10(float(color+1)))+1 write (temp2,"('(''geombcRed-dat.'',i',i1,')')") itmp2 write (fnamer,temp2) (color+1) fnamer = trim(fnamer)//char(0) ieleven=11 ione=1 itmp = int(log10(float(myrank+1)))+1 call queryphmpiio(fnamer, nfields, nppf); if (myrank == 0) then write(*,*) 'Number of fields in geombcRed-dat: ',nfields write(*,*) 'Number of parts per file geombcRed-dat: ',nppf endif call initphmpiio( nfields, nppf, nfiles, igeom, & 'read'//char(0)) call openfile( fnamer, 'read'//char(0), igeom ) write (temp1,"('(''size of ilwork array@'',i',i1,',A1)')") itmp write (fname2,temp1) (myrank+1),'?' call readheader(igeom,fname2//char(0),nlwork,ione, & 'integer' // char(0) ,iotype) write (temp1,"('(''ilwork@'',i',i1,',A1)')") itmp write (fname2,temp1) (myrank+1),'?' call readheader(igeom,fname2//char(0) ,nlwork,ione, & 'integer'//char(0) , iotype) allocate( point2ilwork(nlwork) ) allocate( ilworkread(nlwork) ) call readdatablock(igeom,fname2//char(0),ilworkread, & nlwork,'integer'//char(0) , iotype) point2ilwork = ilworkread deallocate(ilworkread) call closefile( igeom, "read"//char(0) ) call finalizephmpiio( igeom ) call ctypes (point2ilwork) else nlwork=1 allocate( point2ilwork(1)) nshg0 = nshg endif c c.... --------------------> communications <------------------------- c call mpi_barrier(mpi_comm_world, ierr) ! make sure every rank is synced here if(myrank == 0) then write(*,*) 'Updating the vertices on the part boundaries' endif if (numpe > 1) then ! solution call commuMax (qold, point2ilwork, ndof, 'in '//char(0)) call commuMax (qold, point2ilwork, ndof, 'out'//char(0)) call mpi_barrier(mpi_comm_world, ierr) ! make sure everybody is done with ilwork ! ybar if(iybar == 1) then call commuMax (ybar, point2ilwork, ndofybar, 'in '//char(0)) call commuMax (ybar, point2ilwork, ndofybar, 'out'//char(0)) call mpi_barrier(mpi_comm_world, ierr) ! make sure everybody is done with ilwork endif ! errors if(ierror == 1) then call commuMax (errors, point2ilwork, ndoferrors, & 'in '//char(0)) call commuMax (errors, point2ilwork, ndoferrors, & 'out'//char(0)) call mpi_barrier(mpi_comm_world, ierr) ! make sure everybody is done with ilwork endif ! phase_average if(numphavg .gt. 0) then do iphavg = 1,numphavg call commuMax (yphbar(:,:,iphavg), point2ilwork, & ndofyphbar, 'in '//char(0)) call commuMax (yphbar(:,:,iphavg), point2ilwork, & ndofyphbar, 'out'//char(0)) call mpi_barrier(mpi_comm_world, ierr) ! make sure everybody is done with ilwork enddo endif ! vorticity if(ivort == 1) then call commuMax (vort, point2ilwork, ndofvort, 'in '//char(0)) call commuMax (vort, point2ilwork, ndofvort, 'out'//char(0)) call mpi_barrier(mpi_comm_world, ierr) ! make sure everybody is done with ilwork endif ! dwal if(idwal == 1) then call commuMax (dwal, point2ilwork, 1, 'in '//char(0)) call commuMax (dwal, point2ilwork, 1, 'out'//char(0)) call mpi_barrier(mpi_comm_world, ierr) ! make sure everybody is done with ilwork endif endif c c.... --------------------> Print Min and Max of each field <------------------------- c call mpi_barrier(mpi_comm_world, ierr) if (myrank == 0) then write(*,*) 'Printing min and max of each field component' write(*,*) '' endif ! qold do idof=1,ndof call mpi_allreduce(maxval(qold(:,idof)),globmax,1,MPI_DOUBLE, & MPI_MAX, mpi_comm_world, ierr ) call mpi_allreduce(minval(qold(:,idof)),globmin,1,MPI_DOUBLE, & MPI_MIN, mpi_comm_world, ierr ) if (myrank == 0) then write(*,925) 'max/min qold(',idof,'): ',globmax,globmin endif enddo if (myrank == 0) then write(*,*) '' endif ! ybar if(iybar == 1) then do idof=1,ndofybar call mpi_allreduce(maxval(ybar(:,idof)),globmax,1,MPI_DOUBLE, & MPI_MAX, mpi_comm_world, ierr ) call mpi_allreduce(minval(ybar(:,idof)),globmin,1,MPI_DOUBLE, & MPI_MIN, mpi_comm_world, ierr ) if (myrank == 0) then write(*,925) 'max/min ybar(',idof,'): ',globmax,globmin endif enddo if (myrank == 0) then write(*,*) '' endif endif ! errors if(ierror == 1) then do idof=1,ndoferrors call mpi_allreduce(maxval(errors(:,idof)),globmax,1, & MPI_DOUBLE,MPI_MAX, mpi_comm_world, ierr ) call mpi_allreduce(minval(errors(:,idof)),globmin,1, & MPI_DOUBLE,MPI_MIN, mpi_comm_world, ierr ) if (myrank == 0) then write(*,925) 'max/min errors(',idof,'): ',globmax,globmin endif enddo if (myrank == 0) then write(*,*) '' endif endif ! phase_average if(numphavg .gt. 0) then do iphavg = 1,numphavg do idof=1,ndofyphbar call mpi_allreduce(maxval(yphbar(:,idof,iphavg)), globmax,1, & MPI_DOUBLE, MPI_MAX, mpi_comm_world, ierr ) call mpi_allreduce(minval(yphbar(:,idof,iphavg)), globmin,1, & MPI_DOUBLE, MPI_MIN, mpi_comm_world, ierr ) if (myrank == 0) then write(*,926) 'max/min yphbar(',idof,iphavg,'):', & globmax,globmin endif enddo if (myrank == 0) then write(*,*) '' endif enddo endif ! vorticity if(ivort == 1) then do idof=1,ndofvort call mpi_allreduce(maxval(vort(:,idof)),globmax,1, & MPI_DOUBLE,MPI_MAX, mpi_comm_world, ierr ) call mpi_allreduce(minval(vort(:,idof)),globmin,1, & MPI_DOUBLE,MPI_MIN, mpi_comm_world, ierr ) if (myrank == 0) then write(*,925) 'max/min vort(',idof,'): ',globmax,globmin endif enddo if (myrank == 0) then write(*,*) '' endif endif ! dwal if(idwal == 1) then call mpi_allreduce(maxval(dwal(:)), globmax, 1, MPI_DOUBLE, & MPI_MAX, mpi_comm_world, ierr ) call mpi_allreduce(minval(dwal(:)), globmin, 1, MPI_DOUBLE, & MPI_MIN, mpi_comm_world, ierr ) if (myrank == 0) then write(*,925) 'max/min dwal(',1,'):',globmax,globmin write(*,*) '' endif endif 925 format(A,i2,A,2(e24.17,1x)) 926 format(A,i2,i2,A,2(e24.17,1x)) c c.... e-------------------> Write data to disks <------------------------- c call mpi_barrier(mpi_comm_world, ierr) if(myrank == 0) then write(*,*) 'Writing the reduced restartRed-dat files' endif ! call Write_M2NFixBnd(myrank, lstep, nshg, ! & ndof, ndofybar, ndoferrors, ! & qold, ybar, errors, dwal) nsynciofieldswriterestart = 1+iybar+ierror+numphavg+ivort+idwal call Write_M2NFixBnd_SolOnly(myrank, lstep, nshg, & ndof, qold) deallocate(qold) ! ybar if(iybar == 1) then call Write_Field(myrank,'a','ybar',4,ybar,'d', & nshg,ndofybar,lstep) deallocate(ybar) endif ! errors if(ierror == 1) then call Write_Field(myrank,'a','errors',6,errors,'d', & nshg,ndoferrors,lstep) deallocate(errors) endif ! phase_average if(numphavg .gt. 0) then do iphavg=1,numphavg call write_phavg2(myrank,'a','phase_average',13, & iphavg,numphavg,yphbar(:,:,iphavg),'d', & nshg,ndofyphbar,lstep) enddo deallocate(yphbar) endif ! vorticity if(ivort == 1) then call Write_Field(myrank,'a','vorticity',9,vort,'d', & nshg,ndofvort,lstep) deallocate(vort) endif ! dwal if(idwal == 1) then call Write_Field(myrank,'a','dwal',4,dwal,'d', & nshg,1,lstep) deallocate(dwal) endif ! ! Deallocate some remaining memory ! if(numpe.gt.1) then deallocate(point2ilwork) endif return c 994 call error ('input ','opening ', igeom) 995 call error ('input ','opening ', igeom) 997 call error ('input ','end file', igeom) 998 call error ('input ','end file', igeom) c end
bsd-3-clause
khsk2/inc3d
module_param_diagp.f90
1
7018
module variables use decomp_2d, only : mytype ! Boundary conditions : ncl = 2 --> Dirichlet ! Boundary conditions : ncl = 1 --> Free-slip ! Boundary conditions : ncl = 0 --> Periodic ! l: power of 2,3,4,5 and 6 ! if ncl = 1 or 2, --> n = 2l+ 1 ! --> nm = n - 1 ! --> m = n + 1 ! If ncl = 0, --> n = 2*l ! --> nm = n ! --> m = n + 2 !nstat = size arrays for statistic collection !2-->every 2 mesh nodes !4-->every 4 mesh nodes !nvisu = size for visualization collection integer,parameter :: nx=128,ny=129,nz=128 integer,parameter :: nstat=1,nvisu=1 integer,parameter :: p_row=4,p_col=4 integer,parameter :: nxm=nx,nym=ny-1,nzm=nz real(mytype) :: re !end module variables !module derivative real(mytype), dimension(nx) :: ffx,fcx,fbx,sfx,scx,sbx,fsx,fwx,ssx,swx real(mytype), dimension(nx) :: ffxp,fsxp,fwxp,sfxp,ssxp,swxp real(mytype), dimension(ny) :: ffy,fcy,fby,sfy,scy,sby,fsy,fwy,ssy,swy real(mytype), dimension(ny) :: ffyp,fsyp,fwyp,sfyp,ssyp,swyp real(mytype), dimension(nz) :: ffz,fcz,fbz,sfz,scz,sbz,fsz,fwz,ssz,swz real(mytype), dimension(nz) :: ffzp,fszp,fwzp,sfzp,sszp,swzp real(mytype), save, allocatable, dimension(:,:) :: sx,vx real(mytype), save, allocatable, dimension(:,:) :: sy,vy real(mytype), save, allocatable, dimension(:,:) :: sz,vz !module pressure real(mytype), save, allocatable, dimension(:,:) :: dpdyx1,dpdyxn,dpdzx1,dpdzxn real(mytype), save, allocatable, dimension(:,:) :: dpdxy1,dpdxyn,dpdzy1,dpdzyn real(mytype), save, allocatable, dimension(:,:) :: dpdxz1,dpdxzn,dpdyz1,dpdyzn !module solid_body integer,parameter :: nxfin=(nx-1)*10+1,nyfin=ny*10,nzfin=(nz-1)*10+1 integer,dimension(ny,nz) :: nobjx integer,dimension(nx,nz) :: nobjy integer,dimension(nx,ny) :: nobjz real(mytype),dimension(20,ny,nz) :: xi,xf real(mytype),dimension(20,nx,nz) :: yi,yf real(mytype),dimension(20,nx,ny) :: zi,zf !module inflow real(mytype), save, allocatable, dimension(:,:) :: bxx1,bxy1,bxz1,bxxn,bxyn,bxzn,bxo,byo,bzo real(mytype), save, allocatable, dimension(:,:) :: byx1,byy1,byz1,byxn,byyn,byzn real(mytype), save, allocatable, dimension(:,:) :: bzx1,bzy1,bzz1,bzxn,bzyn,bzzn !module derpres real(mytype),dimension(nxm) :: cfx6,ccx6,cbx6,cfxp6,ciwxp6,csxp6,& cwxp6,csx6,cwx6,cifx6,cicx6,cisx6 real(mytype),dimension(nxm) :: cibx6,cifxp6,cisxp6,ciwx6 real(mytype),dimension(nx) :: cfi6,cci6,cbi6,cfip6,csip6,cwip6,csi6,& cwi6,cifi6,cici6,cibi6,cifip6 real(mytype),dimension(nx) :: cisip6,ciwip6,cisi6,ciwi6 real(mytype),dimension(nym) :: cfy6,ccy6,cby6,cfyp6,csyp6,cwyp6,csy6 real(mytype),dimension(nym) :: cwy6,cify6,cicy6,ciby6,cifyp6,cisyp6,& ciwyp6,cisy6,ciwy6 real(mytype),dimension(ny) :: cfi6y,cci6y,cbi6y,cfip6y,csip6y,cwip6y,& csi6y,cwi6y,cifi6y,cici6y real(mytype),dimension(ny) :: cibi6y,cifip6y,cisip6y,ciwip6y,cisi6y,ciwi6y real(mytype),dimension(nzm) :: cfz6,ccz6,cbz6,cfzp6,cszp6,cwzp6,csz6 real(mytype),dimension(nzm) :: cwz6,cifz6,cicz6,cibz6,cifzp6,ciszp6,& ciwzp6,cisz6,ciwz6 real(mytype),dimension(nz) :: cfi6z,cci6z,cbi6z,cfip6z,csip6z,cwip6z,& csi6z,cwi6z,cifi6z,cici6z real(mytype),dimension(nz) :: cibi6z,cifip6z,cisip6z,ciwip6z,cisi6z,ciwi6z !module waves complex(mytype), dimension(nz/2+1) :: zkz,zk2,ezs complex(mytype), dimension(ny) :: yky,yk2,eys complex(mytype), dimension(nx) :: xkx,xk2,exs !module mesh real(mytype), dimension(ny) :: ppy,pp2y,pp4y real(mytype), dimension(ny) :: ppyi,pp2yi,pp4yi real(mytype), dimension(ny) :: yp,ypi real(mytype), dimension(ny) :: yeta,yetai real(mytype) :: alpha,beta real(mytype), dimension(nx) :: xx real(mytype), dimension(nz) :: zz end module variables module param use decomp_2d, only : mytype integer :: nclx,ncly,nclz integer :: ifft, ivirt,istret,iforc_entree,iturb integer :: itype, iskew, iin, nscheme, ifirst, ilast, iles integer :: isave,ilit,idebmod, imodulo, idemarre, icommence, irecord integer :: iscalar integer :: nxboite, istat,iread,iadvance_time real(mytype) :: xlx,yly,zlz,dx,dy,dz,dx2,dy2,dz2 real(mytype) :: dt,xnu,noise,noise1,pi,twopi,u1,u2,sc real(mytype) :: t,xxk1,xxk2,re_tau integer :: itr,itime character :: filesauve*80, filenoise*80, & nchamp*80,filepath*80, fileturb*80, filevisu*80 character(len=200) :: datdir character(len=200) :: outdir real(mytype), dimension(5) :: adt,bdt,cdt,gdt end module param module derivX use decomp_2d, only : mytype real(mytype) :: alcaix6,acix6,bcix6 real(mytype) :: ailcaix6,aicix6,bicix6,cicix6 real(mytype) :: alfa1x,af1x,bf1x,cf1x,df1x,alfa2x,af2x,alfanx,afnx,bfnx real(mytype) :: cfnx,dfnx,alfamx,afmx,alfaix,afix,bfix,alsa1x,as1x,bs1x real(mytype) :: cs1x,ds1x,alsa2x,as2x,alsanx,asnx,bsnx,csnx,dsnx,alsamx real(mytype) :: asmx,alsaix,asix,bsix,csix,alsa3x,as3x,bs3x,alsatx,astx,bstx end module derivX module derivY use decomp_2d, only : mytype real(mytype) :: alcaiy6,aciy6,bciy6 real(mytype) :: ailcaiy6,aiciy6,biciy6,ciciy6 real(mytype) :: alfa1y,af1y,bf1y,cf1y,df1y,alfa2y,af2y,alfany,afny,bfny real(mytype) :: cfny,dfny,alfamy,afmy,alfajy,afjy,bfjy,alsa1y,as1y,bs1y real(mytype) :: cs1y,ds1y,alsa2y,as2y,alsany,asny,bsny,csny,dsny,alsamy real(mytype) :: asmy,alsajy,asjy,bsjy,csjy,alsa3y,as3y,bs3y,alsaty,asty,bsty end module derivY module derivZ use decomp_2d, only : mytype real(mytype) :: alcaiz6,aciz6,bciz6 real(mytype) :: ailcaiz6,aiciz6,biciz6,ciciz6 real(mytype) :: alfa1z,af1z,bf1z,cf1z,df1z,alfa2z,af2z,alfanz,afnz,bfnz real(mytype) :: cfnz,dfnz,alfamz,afmz,alfakz,afkz,bfkz,alsa1z,as1z,bs1z real(mytype) :: cs1z,ds1z,alsa2z,as2z,alsanz,asnz,bsnz,csnz,dsnz,alsamz real(mytype) :: asmz,alsakz,askz,bskz,cskz,alsa3z,as3z,bs3z,alsatz,astz,bstz end module derivZ module parfiX use decomp_2d, only : mytype real(mytype) :: fia1x, fib1x, fic1x, fid1x, fie1x, fia2x, fib2x, fic2x, fid2x real(mytype) :: fie2x, fia3x, fib3x, fic3x, fid3x, fie3x, fianx, fibnx, ficnx, fidnx real(mytype) :: fienx, fiamx, fibmx, ficmx, fidmx, fiemx, fiapx, fibpx, ficpx, fidpx real(mytype) :: fiepx, fiaix, fibix, ficix, fidix, fialx, fibex, fih1x, fih2x, fih3x,fih4x end module parfiX ! module parfiY use decomp_2d, only : mytype real(mytype) :: fia1y, fib1y, fic1y, fid1y, fie1y, fia2y, fib2y, fic2y, fid2y real(mytype) :: fie2y, fia3y, fib3y, fic3y, fid3y, fie3y, fiany, fibny, ficny, fidny real(mytype) :: fieny, fiamy, fibmy, ficmy, fidmy, fiemy, fiapy, fibpy, ficpy, fidpy real(mytype) :: fiepy, fiaiy, fibiy, ficiy, fidiy, fialy, fibey, fih1y, fih2y, fih3y,fih4y end module parfiY module parfiZ use decomp_2d, only : mytype real(mytype) :: fia1z, fib1z, fic1z, fid1z, fie1z, fia2z, fib2z, fic2z, fid2z real(mytype) :: fie2z, fia3z, fib3z, fic3z, fid3z, fie3z, fianz, fibnz, ficnz, fidnz real(mytype) :: fienz, fiamz, fibmz, ficmz, fidmz, fiemz, fiapz, fibpz, ficpz, fidpz real(mytype) :: fiepz, fiaiz, fibiz, ficiz, fidiz, fialz, fibez, fih1z, fih2z, fih3z,fih4z end module parfiZ
gpl-3.0
QEF/q-e_schrodinger
HP/src/hp_summary_q.f90
2
6652
! ! Copyright (C) 2001-2018 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !----------------------------------------------------------------------- SUBROUTINE hp_summary_q !----------------------------------------------------------------------- ! ! This routine writes on output the quantities which have been read ! from the punch file, and the quantities computed in hp_setup_q. ! If iverbosity = 1 only a partial summary is done. ! USE kinds, ONLY : DP USE io_global, ONLY : stdout USE cell_base, ONLY : at USE klist, ONLY : lgauss, smearing, degauss, nkstot, xk, wk USE fft_base, ONLY : dfftp USE gvect, ONLY : gcutm, ngm USE gvecs, ONLY : doublegrid, dual, gcutms, ngms USE gvecw, ONLY : ecutwfc USE fft_base, ONLY : dffts USE symm_base, ONLY : s, sr, ft, sname USE funct, ONLY : write_dft_name USE control_flags, ONLY : iverbosity USE lr_symm_base, ONLY : irotmq, minus_q, nsymq USE ldaU_hp, ONLY : conv_thr_chi IMPLICIT NONE ! INTEGER :: i, ipol, apol, na, nt, isymq, isym, ik, nsymtot ! generic counter ! counter on polarizations ! counter on polarizations ! counter on atoms ! counter on atomic types ! counter on symmetries ! counter on symmetries ! counter on k points ! REAL(DP) :: ft1, ft2, ft3, xkg(3) ! fractionary translations ! k point in crystal coordinates ! WRITE( stdout, '(/,19x,"WRITING LINEAR-RESPONSE SUMMARY:",/)') ! ! Now print the information specific for every q point ! ! Description of symmetries for a given q point ! IF (nsymq.le.1.and..not.minus_q) THEN WRITE( stdout, '(5x,"No symmetry (except the identity)!")') ELSE WRITE( stdout, '(/5x,"Number of symmetries in the small group of q, nsymq = ",i2)') nsymq IF (minus_q) WRITE( stdout, '(5x," + the symmetry q -> -q+G ")') ENDIF ! ! Description of the symmetry matrices (and vectors of fractional ! translations if f/=0) of the small group of q ! IF (iverbosity > 1) THEN ! WRITE( stdout, '(/5x,"Symmetry matrices (and vectors of fractional translations if f/=0):")') ! IF (minus_q) THEN nsymtot = nsymq + 1 ELSE nsymtot = nsymq ENDIF ! DO isymq = 1, nsymtot ! IF (isymq.GT.nsymq) THEN isym = irotmq WRITE( stdout, '(/5x,"This transformation sends q -> -q+G")') ELSE isym = isymq ENDIF ! WRITE( stdout, '(/5x,"isym = ",i2,5x,a45/)') isymq, sname (isym) ! IF ( ft(1,isym)**2 + ft(2,isym)**2 + ft(3,isym)**2 > 1.0d-8 ) THEN ! ft1 = at (1, 1) * ft(1, isym) + & at (1, 2) * ft(2, isym) + & at (1, 3) * ft(3, isym) ft2 = at (2, 1) * ft(1, isym) + & at (2, 2) * ft(2, isym) + & at (2, 3) * ft(3, isym) ft3 = at (3, 1) * ft(1, isym) + & at (3, 2) * ft(2, isym) + & at (3, 3) * ft(3, isym) ! WRITE( stdout, '(5x,"cryst.",3x,"s(",i2,") = (",3(i6,5x)," ) f =( ",f10.7," )")') & & isymq, (s(1,ipol,isym), ipol=1,3), ft(1,isym) WRITE( stdout, '(21x," (",3(i6,5x), " ) ( ",f10.7," )")') & & (s(2,ipol,isym), ipol=1,3), ft(2,isym) WRITE( stdout, '(21x," (",3(i6,5x)," ) ( ",f10.7," )"/)') & & (s(3,ipol,isym), ipol=1,3), ft(3,isym) WRITE( stdout, '(5x,"cart.",4x,"s(",i2,") = (",3f11.7, " ) f =( ",f10.7," )")') & & isymq, (sr(1,ipol,isym), ipol=1,3), ft1 WRITE( stdout, '(21x," (",3f11.7, " ) ( ",f10.7," )")') & & (sr(2,ipol,isym), ipol=1,3), ft2 WRITE( stdout, '(21x," (",3f11.7, " ) ( ",f10.7," )"/)') & & (sr(3,ipol,isym), ipol=1,3), ft3 ! ELSE ! WRITE( stdout, '(5x,"cryst.",3x,"s(",i2,") = (",3(i6,5x), " )")') & & isymq, (s(1,ipol,isym), ipol=1,3) WRITE( stdout, '(21x," (",3(i6,5x)," )")') & & (s (2,ipol,isym), ipol=1,3) WRITE( stdout, '(21x," (",3(i6,5x)," )"/)') & & (s(3,ipol,isym), ipol=1,3) WRITE( stdout, '(5x,"cart.",4x,"s(",i2,") = (",3f11.7, " )")') & & isymq, (sr(1,ipol,isym), ipol=1,3) WRITE( stdout, '(21x," (",3f11.7," )")') & & (sr(2,ipol,isym), ipol=1,3) WRITE( stdout, '(21x," (",3f11.7," )"/)') & & (sr(3,ipol,isym), ipol=1,3) ! ENDIF ! ENDDO ! isymq ! ENDIF ! ! Description of the G cutoff and the FFT grid ! WRITE( stdout, '(/5x,"G cutoff =",f10.4," (",i7," G-vectors)", & & " FFT grid: (",i3,",",i3,",",i3,")")') & & gcutm, ngm, dfftp%nr1, dfftp%nr2, dfftp%nr3 ! IF (doublegrid) & WRITE( stdout, '(5x,"G cutoff =",f10.4," (", i7," G-vectors)", & & " smooth grid: (",i3, ",",i3,",",i3,")")') & & gcutms, ngms, dffts%nr1, dffts%nr2, dffts%nr3 ! ! Number of k (and k+q if q/=0) points ! IF (.NOT.lgauss) THEN WRITE( stdout, '(/5x,"Number of k (and k+q if q/=0) points =",i6,/)') nkstot ELSE WRITE( stdout, '(/5x,"Number of k (and k+q if q/=0) points =", i6, 2x, & & a," smearing, width (Ry) =",f8.4,/)') & & nkstot, TRIM(smearing), degauss ENDIF ! ! Coordinates of the k (and k+q if q/=0) points ! IF ( iverbosity > 1 .OR. (nkstot<100) ) THEN ! ! cartesian coordinates ! WRITE( stdout, '(23x,"cart. coord. (in units 2pi/alat)")') DO ik = 1, nkstot WRITE( stdout, '(8x,"k (",i5,") = (",3f12.7,"), wk =",f10.7)') & & ik, (xk(ipol,ik), ipol=1,3), wk(ik) ENDDO ! ! crystal coordinates ! WRITE( stdout, '(/23x,"cryst. coord.")') DO ik = 1, nkstot DO ipol = 1, 3 xkg (ipol) = at (1, ipol) * xk (1, ik) + & at (2, ipol) * xk (2, ik) + & at (3, ipol) * xk (3, ik) ENDDO WRITE( stdout, '(8x,"k (",i5,") = (",3f12.7,"), wk =",f10.7)') & & ik, (xkg(ipol), ipol=1,3), wk(ik) ENDDO ! ENDIF ! RETURN ! END SUBROUTINE hp_summary_q
gpl-2.0
skywalker00/sabermod_rom_toolchain
gcc/testsuite/gfortran.dg/typebound_operator_15.f90
141
1943
! { dg-do run } ! ! PR fortran/53255 ! ! Contributed by Reinhold Bader. ! ! Before TYPE(ext)'s .tr. wrongly called the base type's trace ! instead of ext's trace_ext. ! module mod_base implicit none private integer, public :: base_cnt = 0 type, public :: base private real :: r(2,2) = reshape( (/ 1.0, 2.0, 3.0, 4.0 /), (/ 2, 2 /)) contains procedure, private :: trace generic :: operator(.tr.) => trace end type base contains complex function trace(this) class(base), intent(in) :: this base_cnt = base_cnt + 1 ! write(*,*) 'executing base' trace = this%r(1,1) + this%r(2,2) end function trace end module mod_base module mod_ext use mod_base implicit none private integer, public :: ext_cnt = 0 public :: base, base_cnt type, public, extends(base) :: ext private real :: i(2,2) = reshape( (/ 1.0, 1.0, 1.0, 1.5 /), (/ 2, 2 /)) contains procedure, private :: trace => trace_ext end type ext contains complex function trace_ext(this) class(ext), intent(in) :: this ! the following should be executed through invoking .tr. p below ! write(*,*) 'executing override' ext_cnt = ext_cnt + 1 trace_ext = .tr. this%base + (0.0, 1.0) * ( this%i(1,1) + this%i(2,2) ) end function trace_ext end module mod_ext program test_override use mod_ext implicit none type(base) :: o type(ext) :: p real :: r ! Note: ext's ".tr." (trace_ext) calls also base's "trace" ! write(*,*) .tr. o ! write(*,*) .tr. p if (base_cnt /= 0 .or. ext_cnt /= 0) call abort () r = .tr. o if (base_cnt /= 1 .or. ext_cnt /= 0) call abort () r = .tr. p if (base_cnt /= 2 .or. ext_cnt /= 1) call abort () if (abs(.tr. o - 5.0 ) < 1.0e-6 .and. abs( .tr. p - (5.0,2.5)) < 1.0e-6) & then if (base_cnt /= 4 .or. ext_cnt /= 2) call abort () ! write(*,*) 'OK' else call abort() ! write(*,*) 'FAIL' end if end program test_override
gpl-2.0
skywalker00/sabermod_rom_toolchain
gcc/testsuite/gfortran.dg/char_result_8.f90
188
1068
! Related to PR 15326. Compare functions that return string pointers with ! functions that return strings. ! { dg-do run } program main implicit none character (len = 30), target :: string call test (f1 (), 30) call test (f2 (50), 50) call test (f3 (), 30) call test (f4 (70), 70) call indirect (100) contains function f1 () character (len = 30) :: f1 f1 = '' end function f1 function f2 (i) integer :: i character (len = i) :: f2 f2 = '' end function f2 function f3 () character (len = 30), pointer :: f3 f3 => string end function f3 function f4 (i) integer :: i character (len = i), pointer :: f4 f4 => string end function f4 subroutine indirect (i) integer :: i call test (f1 (), 30) call test (f2 (i), i) call test (f3 (), 30) call test (f4 (i), i) end subroutine indirect subroutine test (string, length) character (len = *) :: string integer, intent (in) :: length if (len (string) .ne. length) call abort end subroutine test end program main
gpl-2.0
piyush0609/scipy
scipy/linalg/src/id_dist/src/idd_house.f
100
6886
c this file contains the following user-callable routines: c c c routine idd_house calculates the vector and scalar c needed to apply the Householder tranformation reflecting c a given vector into its first component. c c routine idd_houseapp applies a Householder matrix to a vector. c c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c c c c subroutine idd_houseapp(n,vn,u,ifrescal,scal,v) c c applies the Householder matrix c identity_matrix - scal * vn * transpose(vn) c to the vector u, yielding the vector v; c c scal = 2/(1 + vn(2)^2 + ... + vn(n)^2) c when vn(2), ..., vn(n) don't all vanish; c c scal = 0 c when vn(2), ..., vn(n) do all vanish c (including when n = 1). c c input: c n -- size of vn, u, and v, though the indexing on vn goes c from 2 to n c vn -- components 2 to n of the Householder vector vn; c vn(1) is assumed to be 1 c u -- vector to be transformed c ifrescal -- set to 1 to recompute scal from vn(2), ..., vn(n); c set to 0 to use scal as input c scal -- see the entry for ifrescal in the decription c of the input c c output: c scal -- see the entry for ifrescal in the decription c of the input c v -- result of applying the Householder matrix to u; c it's O.K. to have v be the same as u c in order to apply the matrix to the vector in place c c reference: c Golub and Van Loan, "Matrix Computations," 3rd edition, c Johns Hopkins University Press, 1996, Chapter 5. c implicit none save integer n,k,ifrescal real*8 vn(2:*),scal,u(n),v(n),fact,sum c c c Get out of this routine if n = 1. c if(n .eq. 1) then v(1) = u(1) return endif c c if(ifrescal .eq. 1) then c c c Calculate (vn(2))^2 + ... + (vn(n))^2. c sum = 0 do k = 2,n sum = sum+vn(k)**2 enddo ! k c c c Calculate scal. c if(sum .eq. 0) scal = 0 if(sum .ne. 0) scal = 2/(1+sum) c c endif c c c Calculate fact = scal * transpose(vn) * u. c fact = u(1) c do k = 2,n fact = fact+vn(k)*u(k) enddo ! k c fact = fact*scal c c c Subtract fact*vn from u, yielding v. c v(1) = u(1) - fact c do k = 2,n v(k) = u(k) - fact*vn(k) enddo ! k c c return end c c c c subroutine idd_house(n,x,rss,vn,scal) c c constructs the vector vn with vn(1) = 1 c and the scalar scal such that c H := identity_matrix - scal * vn * transpose(vn) is orthogonal c and Hx = +/- e_1 * the root-sum-square of the entries of x c (H is the Householder matrix corresponding to x). c c input: c n -- size of x and vn, though the indexing on vn goes c from 2 to n c x -- vector to reflect into its first component c c output: c rss -- first entry of the vector resulting from the application c of the Householder matrix to x; c its absolute value is the root-sum-square c of the entries of x c vn -- entries 2 to n of the Householder vector vn; c vn(1) is assumed to be 1 c scal -- scalar multiplying vn * transpose(vn); c c scal = 2/(1 + vn(2)^2 + ... + vn(n)^2) c when vn(2), ..., vn(n) don't all vanish; c c scal = 0 c when vn(2), ..., vn(n) do all vanish c (including when n = 1) c c reference: c Golub and Van Loan, "Matrix Computations," 3rd edition, c Johns Hopkins University Press, 1996, Chapter 5. c implicit none save integer n,k real*8 x(n),rss,sum,v1,scal,vn(2:*),x1 c c x1 = x(1) c c c Get out of this routine if n = 1. c if(n .eq. 1) then rss = x1 scal = 0 return endif c c c Calculate (x(2))^2 + ... (x(n))^2 c and the root-sum-square value of the entries in x. c c sum = 0 do k = 2,n sum = sum+x(k)**2 enddo ! k c c c Get out of this routine if sum = 0; c flag this case as such by setting v(2), ..., v(n) all to 0. c if(sum .eq. 0) then c rss = x1 do k = 2,n vn(k) = 0 enddo ! k scal = 0 c return c endif c c rss = x1**2 + sum rss = sqrt(rss) c c c Determine the first component v1 c of the unnormalized Householder vector c v = x - rss * (1 0 0 ... 0 0)^T. c c If x1 <= 0, then form x1-rss directly, c since that expression cannot involve any cancellation. c if(x1 .le. 0) v1 = x1-rss c c If x1 > 0, then use the fact that c x1-rss = -sum / (x1+rss), c in order to avoid potential cancellation. c if(x1 .gt. 0) v1 = -sum / (x1+rss) c c c Compute the vector vn and the scalar scal such that vn(1) = 1 c in the Householder transformation c identity_matrix - scal * vn * transpose(vn). c do k = 2,n vn(k) = x(k)/v1 enddo ! k c c scal = 2 c / ( vn(1)^2 + vn(2)^2 + ... + vn(n)^2 ) c c = 2 c / ( 1 + vn(2)^2 + ... + vn(n)^2 ) c c = 2*v(1)^2 c / ( v(1)^2 + (v(1)*vn(2))^2 + ... + (v(1)*vn(n))^2 ) c c = 2*v(1)^2 c / ( v(1)^2 + (v(2)^2 + ... + v(n)^2) ) c scal = 2*v1**2 / (v1**2+sum) c c return end c c c c subroutine idd_housemat(n,vn,scal,h) c c fills h with the Householder matrix c identity_matrix - scal * vn * transpose(vn). c c input: c n -- size of vn and h, though the indexing of vn goes c from 2 to n c vn -- entries 2 to n of the vector vn; c vn(1) is assumed to be 1 c scal -- scalar multiplying vn * transpose(vn) c c output: c h -- identity_matrix - scal * vn * transpose(vn) c implicit none save integer n,j,k real*8 vn(2:*),h(n,n),scal,factor1,factor2 c c c Fill h with the identity matrix. c do j = 1,n do k = 1,n c if(j .eq. k) h(k,j) = 1 if(j .ne. k) h(k,j) = 0 c enddo ! k enddo ! j c c c Subtract from h the matrix scal*vn*transpose(vn). c do j = 1,n do k = 1,n c if(j .eq. 1) factor1 = 1 if(j .ne. 1) factor1 = vn(j) c if(k .eq. 1) factor2 = 1 if(k .ne. 1) factor2 = vn(k) c h(k,j) = h(k,j) - scal*factor1*factor2 c enddo ! k enddo ! j c c return end
bsd-3-clause
crazyleen/msp430-gdb-7.2a
gdb/testsuite/gdb.fortran/array-element.f
5
1071
c Copyright 2005, 2010 Free Software Foundation, Inc. c This program is free software; you can redistribute it and/or modify c it under the terms of the GNU General Public License as published by c the Free Software Foundation; either version 3 of the License, or c (at your option) any later version. c c This program is distributed in the hope that it will be useful, c but WITHOUT ANY WARRANTY; without even the implied warranty of c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the c GNU General Public License for more details. c c You should have received a copy of the GNU General Public License c along with this program. If not, see <http://www.gnu.org/licenses/>. c Ihis file is the F77 source file for array-element.exp. It was written c by Wu Zhou. (woodzltc@cn.ibm.com) dimension a(10) write(*,*) 'This is a test.' call sub(a,10) write(*,*) a stop end subroutine sub(a,n) dimension a(n) do 100 i = 1, n a(i) = i 100 continue return end
gpl-2.0
LucasGandel/ITK
Modules/ThirdParty/VNL/src/vxl/v3p/netlib/minpack/fdjac2.f
173
3340
subroutine fdjac2(fcn,m,n,x,fvec,fjac,ldfjac,iflag,epsfcn,wa) integer m,n,ldfjac,iflag double precision epsfcn double precision x(n),fvec(m),fjac(ldfjac,n),wa(m) c ********** c c subroutine fdjac2 c c this subroutine computes a forward-difference approximation c to the m by n jacobian matrix associated with a specified c problem of m functions in n variables. c c the subroutine statement is c c subroutine fdjac2(fcn,m,n,x,fvec,fjac,ldfjac,iflag,epsfcn,wa) c c where c c fcn is the name of the user-supplied subroutine which c calculates the functions. fcn must be declared c in an external statement in the user calling c program, and should be written as follows. c c subroutine fcn(m,n,x,fvec,iflag) c integer m,n,iflag c double precision x(n),fvec(m) c ---------- c calculate the functions at x and c return this vector in fvec. c ---------- c return c end c c the value of iflag should not be changed by fcn unless c the user wants to terminate execution of fdjac2. c in this case set iflag to a negative integer. c c m is a positive integer input variable set to the number c of functions. c c n is a positive integer input variable set to the number c of variables. n must not exceed m. c c x is an input array of length n. c c fvec is an input array of length m which must contain the c functions evaluated at x. c c fjac is an output m by n array which contains the c approximation to the jacobian matrix evaluated at x. c c ldfjac is a positive integer input variable not less than m c which specifies the leading dimension of the array fjac. c c iflag is an integer variable which can be used to terminate c the execution of fdjac2. see description of fcn. c c epsfcn is an input variable used in determining a suitable c step length for the forward-difference approximation. this c approximation assumes that the relative errors in the c functions are of the order of epsfcn. if epsfcn is less c than the machine precision, it is assumed that the relative c errors in the functions are of the order of the machine c precision. c c wa is a work array of length m. c c subprograms called c c user-supplied ...... fcn c c minpack-supplied ... dpmpar c c fortran-supplied ... dabs,dmax1,dsqrt c c argonne national laboratory. minpack project. march 1980. c burton s. garbow, kenneth e. hillstrom, jorge j. more c c ********** integer i,j double precision eps,epsmch,h,temp,zero double precision dpmpar data zero /0.0d0/ c c epsmch is the machine precision. c epsmch = dpmpar(1) c eps = dsqrt(dmax1(epsfcn,epsmch)) do 20 j = 1, n temp = x(j) h = eps*dabs(temp) if (h .eq. zero) h = eps x(j) = temp + h call fcn(m,n,x,wa,iflag) if (iflag .lt. 0) go to 30 x(j) = temp do 10 i = 1, m fjac(i,j) = (wa(i) - fvec(i))/h 10 continue 20 continue 30 continue return c c last card of subroutine fdjac2. c end
apache-2.0
QEF/q-e_schrodinger
UtilXlib/nvtx_wrapper.f90
2
4160
!MIT License !Copyright (c) 2019 maxcuda !This module has been downloaded and adapted from ! https://github.com/maxcuda/NVTX_example ! ! Permission is hereby granted, free of charge, to any person obtaining a copy ! of this software and associated documentation files (the "Software"), to deal ! in the Software without restriction, including without limitation the rights ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ! copies of the Software, and to permit persons to whom the Software is ! furnished to do so, subject to the following conditions: ! The above copyright notice and this permission notice shall be included in all ! copies or substantial portions of the Software. ! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ! SOFTWARE. ! ---- ! nvtx ! ---- module nvtx use iso_c_binding #ifdef __CUDA use cudafor #endif implicit none #ifdef __PROFILE_NVTX integer,private :: col(7) = [ Z'0000ff00', Z'000000ff', Z'00ffff00',Z'00ff00ff',Z'0000ffff', & Z'00ff0000', Z'00ffffff'] character(len=256),private :: tempName ! logical, save :: __PROFILE_NVTX=.false. type, bind(C):: nvtxEventAttributes integer(C_INT16_T):: version=1 integer(C_INT16_T):: size=48 ! integer(C_INT):: category=0 integer(C_INT):: colorType=1 ! NVTX_COLOR_ARGB = 1 integer(C_INT):: color integer(C_INT):: payloadType=0 ! NVTX_PAYLOAD_UNKNOWN = 0 integer(C_INT):: reserved0 integer(C_INT64_T):: payload ! union uint,int,double integer(C_INT):: messageType=1 ! NVTX_MESSAGE_TYPE_ASCII = 1 type(C_PTR):: message ! ascii char end type nvtxEventAttributes interface nvtxRangePush ! push range with custom label and standard color subroutine nvtxRangePushA(name) bind(C, name='nvtxRangePushA') use iso_c_binding character(kind=C_CHAR,len=*) :: name end subroutine nvtxRangePushA ! push range with custom label and custom color subroutine nvtxRangePushEx(event) bind(C, name='nvtxRangePushEx') use iso_c_binding import:: nvtxEventAttributes type(nvtxEventAttributes):: event end subroutine nvtxRangePushEx end interface nvtxRangePush interface nvtxRangePop subroutine nvtxRangePop() bind(C, name='nvtxRangePop') end subroutine nvtxRangePop end interface nvtxRangePop #endif contains subroutine nvtxStartRange(name,id) character(kind=c_char,len=*) :: name integer, optional:: id #ifdef __PROFILE_NVTX type(nvtxEventAttributes):: event #if defined(__CUDA) && defined(__SYNC_NVPROF) integer :: istat istat = cudaDeviceSynchronize() #endif tempName=trim(name)//c_null_char if ( .not. present(id)) then call nvtxRangePush(tempName) else event%color=col(mod(id,7)+1) event%message=c_loc(tempName) call nvtxRangePushEx(event) end if #endif end subroutine nvtxStartRange subroutine nvtxStartRangeAsync(name,id) character(kind=c_char,len=*) :: name integer, optional:: id #ifdef __PROFILE_NVTX type(nvtxEventAttributes):: event tempName=trim(name)//c_null_char if ( .not. present(id)) then call nvtxRangePush(tempName) else event%color=col(mod(id,7)+1) event%message=c_loc(tempName) call nvtxRangePushEx(event) end if #endif end subroutine nvtxStartRangeAsync subroutine nvtxEndRange #ifdef __PROFILE_NVTX #if defined(__CUDA) && defined(__SYNC_NVPROF) integer :: istat istat = cudaDeviceSynchronize() #endif call nvtxRangePop #endif end subroutine nvtxEndRange subroutine nvtxEndRangeAsync #ifdef __PROFILE_NVTX call nvtxRangePop #endif end subroutine nvtxEndRangeAsync end module nvtx
gpl-2.0
QEF/q-e_schrodinger
TDDFPT/src/environ_td_module.f90
2
2447
!---------------------------------------------------------------------------------------- !> !! !---------------------------------------------------------------------------------------- MODULE environ_td_module !------------------------------------------------------------------------------------ #if defined (__ENVIRON) ! USE environ_base_module, ONLY: environ ! USE kinds, ONLY: DP USE io_global, ONLY: stdout ! USE fft_base, ONLY: dfftp ! USE lsda_mod, ONLY: nspin USE lr_variables, ONLY: davidson ! !------------------------------------------------------------------------------------ ! IMPLICIT NONE ! PRIVATE ! PUBLIC :: calc_environ_dpotential ! !------------------------------------------------------------------------------------ CONTAINS !------------------------------------------------------------------------------------ !> !! !------------------------------------------------------------------------------------ SUBROUTINE calc_environ_dpotential(drho, dv) !-------------------------------------------------------------------------------- ! IMPLICIT NONE ! REAL(DP), INTENT(IN) :: drho(dfftp%nnr, nspin) ! REAL(DP), INTENT(INOUT) :: dv(dfftp%nnr, nspin) ! !-------------------------------------------------------------------------------- ! IF (.NOT. davidson) WRITE (stdout, 1000) ! IF (environ%setup%optical_permittivity == 1.D0) WRITE (stdout, 1002) ! CALL environ%main%update_response(dfftp%nnr, drho(:, 1)) ! CALL environ%calc%dpotential(dfftp%nnr, dv(:, 1)) ! !-------------------------------------------------------------------------------- ! 1000 FORMAT(5X, "Calculate Environ contribution to response potential") ! 1002 FORMAT("Warning: permittivity is set to 1.0 - no Environ contribution") ! !-------------------------------------------------------------------------------- END SUBROUTINE calc_environ_dpotential !------------------------------------------------------------------------------------ ! #endif !------------------------------------------------------------------------------------ END MODULE environ_td_module !----------------------------------------------------------------------------------------
gpl-2.0
yangf4/phasta
phSolver/incompressible/soldir.f
5
3630
subroutine SolDir (y, ac, yold, acold, & x, & iBC, BC, & res, & iper, ilwork, & shp, shgl, shpb, shglb) c c---------------------------------------------------------------------- c direct solver c---------------------------------------------------------------------- c use pointer_data include "common.h" include "mpif.h" include "auxmpi.h" c dimension y(nshg,ndof), ac(nshg,ndof), & yold(nshg,ndof), acold(nshg,ndof), & x(numnp,nsd), & iBC(nshg), BC(nshg,ndofBC), & res(nshg,nflow), & ilwork(nlwork), iper(nshg) c dimension shp(MAXTOP,maxsh,MAXQPT), & shgl(MAXTOP,nsd,maxsh,MAXQPT), & shpb(MAXTOP,maxsh,MAXQPT), & shglb(MAXTOP,nsd,maxsh,MAXQPT) real*8 yAlpha(nshg,5), acAlpha(nshg,5) c dimension dyf(4*nshg), indx(4*nshg), solinc(nshg,4) dimension globMas(4*nshg,4*nshg) write (*,*) 'Warning: using direct solver...' c c.... set the element matrix flag c lhs = 1 ! always c c.... compute solution at n+alpha c call itrYAlpha( yold, acold, y, ac, yAlpha, acAlpha) c c.... *******************>> Element Data Formation <<****************** c c.... form the LHS matrices, the residual vector c call ElmGMR (yAlpha, acAlpha, x, & shp, shgl, iBC, & BC, shpb, shglb, & res, iper, ilwork, & rowp, colm, lhsK, & lhsP, rerr ) globMas = zero npro = numel c cccc need to assemble here! c call bc3Global(globMas, iBC) c cDEBUG: write the global matrix (nonzero blocks) c do i=1,nshg i0 = (i-1)*4 do j=1,nshg j0 = (j-1)*4 if (globMas(i0+1,j0+1) .ne. 0) then write (544,21) i,j do ii=1,4 write(543,20) (globMas(i0+ii,j0+kk), kk=1,4) enddo endif enddo enddo 20 format (4(2x,e14.7)) 21 format (2(2x,i8)) c$$$ stop c c.... LU factor the mass matrix c indx = 0 call ludcmp(globMas, 4*nshg, 4*nshg, indx, d) write(543,*) 'rhs' do i=1, nshg i0 = 4*(i-1) dyf(i0+1) = res(i,1) dyf(i0+2) = res(i,2) dyf(i0+3) = res(i,3) dyf(i0+4) = res(i,4) write(543,20) (dyf(i0+j),j=1,4) enddo c c.... back-substitute to find dY c call lubksb(globMas, 4*nshg, 4*nshg, indx, dyf) c write(543,*) 'soln' do i=1,nshg i0 = 4*(i-1) solinc(i,1) = dyf(i0+1) solinc(i,2) = dyf(i0+2) solinc(i,3) = dyf(i0+3) solinc(i,4) = dyf(i0+4) enddo c c c.... Now, you satisfy the boundary conditions to newly c obtained p,u,v,w c c c You have to set boundary conditions first so Dy distributes c call itrCorrect ( y, ac, solinc, iBC) call itrBC (y, ac, iBC, BC, iper, ilwork) c c.... output the statistics c call rstatic (res, y, solinc) c c.... end c return end
bsd-3-clause
yangf4/phasta
phSolver/compressible/i3ldu.f
4
6535
subroutine i3LDU (Diag, r, code) c c---------------------------------------------------------------------- c c This routine preforms a Cholesky factorization/solve of a set of c symmetric matrices for 3-D computations, used for block diagonal c preconditioning in the iterative driver. c c input: c Diag (numnp,nsymdf) : block diagonal (symmetric storage) c r (numnp,nflow) : residual c code : operation code c .eq. 'LDU_Fact', Cholesky Factor c .eq. 'forward ', forward reduction c .eq. 'backward', backward substitution c .eq. 'product ', product Diag.r c c output: c Diag (numnp,nsymdf) : Cholesky decomp. of block diagonal c r (numnp,nflow) : reduced residual c c c Note: the formulation used here to reduce the diagonal block to c symmetric Cholesky triangle is taken from Golub's "Matrix c Computations" Book, pages 89 algorithm 5.2-1. Followed by c standard solve. c c c Diag(1) Diag(2) Diag(4) Diag(7) Diag(11) c T 0 Diag(3) Diag(5) Diag(8) Diag(12) c L = U = 0 0 Diag(6) Diag(9) Diag(13) c 0 0 0 Diag(10) Diag(14) c 0 0 0 0 Diag(15) c c The diagonal terms 1, 3, 6, 10 and 15 are stored in inverted form. c c Farzin Shakib, Spring 1987. c Zdenek Johan, Fall 1989. (Modified for option 'product') c Zdenek Johan, Winter 1991. (Fortran 90) c---------------------------------------------------------------------- c include "common.h" c dimension Diag(nshg,nsymdf), r(nshg,nflow) c character*8 code c c.... perform Cholesky decomposition with the Diagonal terms inverted c if (code .eq. 'LDU_Fact') then c Diag(:, 1) = one / sqrt (Diag(:, 1)) c Diag(:, 2) = Diag(:, 1) * Diag(:, 2) Diag(:, 3) = Diag(:, 3) - Diag(:, 2) * Diag(:, 2) Diag(:, 3) = one / sqrt (Diag(:, 3)) c Diag(:, 4) = Diag(:, 1) * Diag(:, 4) Diag(:, 5) = Diag(:, 3) * (Diag(:, 5) & - Diag(:, 4) * Diag(:, 2)) Diag(:, 6) = Diag(:, 6) - Diag(:, 4) * Diag(:, 4) & - Diag(:, 5) * Diag(:, 5) Diag(:, 6) = one / sqrt (Diag(:, 6)) c Diag(:, 7) = Diag(:, 1) * Diag(:, 7) Diag(:, 8) = Diag(:, 3) * (Diag(:, 8) & - Diag(:, 7) * Diag(:, 2)) Diag(:, 9) = Diag(:, 6) * (Diag(:, 9) & - Diag(:, 7) * Diag(:, 4) & - Diag(:, 8) * Diag(:, 5)) c Diag(:,10) = Diag(:,10) - Diag(:, 7) * Diag(:, 7) & - Diag(:, 8) * Diag(:, 8) & - Diag(:, 9) * Diag(:, 9) Diag(:,10) = one / sqrt (Diag(:,10)) c Diag(:,11) = Diag(:, 1) * Diag(:,11) Diag(:,12) = Diag(:, 3) * (Diag(:,12) & - Diag(:,11) * Diag(:, 2)) Diag(:,13) = Diag(:, 6) * (Diag(:,13) & - Diag(:,11) * Diag(:, 4) & - Diag(:,12) * Diag(:, 5)) Diag(:,14) = Diag(:,10) * (Diag(:,14) & - Diag(:,11) * Diag(:, 7) & - Diag(:,12) * Diag(:, 8) & - Diag(:,13) * Diag(:, 9)) c Diag(:,15) = Diag(:,15) - Diag(:,11) * Diag(:,11) & - Diag(:,12) * Diag(:,12) & - Diag(:,13) * Diag(:,13) & - Diag(:,14) * Diag(:,14) Diag(:,15) = one / sqrt (Diag(:,15)) c c.... flop count c ! flops = flops + 110*nshg c return endif c c.... perform forward reduction c if (code .eq. 'forward ') then c r(:,1) = Diag(:, 1) * r(:,1) r(:,2) = Diag(:, 3) * ( r(:,2) & - r(:,1) * Diag(:, 2) ) r(:,3) = Diag(:, 6) * ( r(:,3) & - r(:,1) * Diag(:, 4) & - r(:,2) * Diag(:, 5) ) r(:,4) = Diag(:,10) * ( r(:,4) & - r(:,1) * Diag(:, 7) & - r(:,2) * Diag(:, 8) & - r(:,3) * Diag(:, 9) ) r(:,5) = Diag(:,15) * ( r(:,5) & - r(:,1) * Diag(:,11) & - r(:,2) * Diag(:,12) & - r(:,3) * Diag(:,13) & - r(:,4) * Diag(:,14) ) c c.... flop count c ! flops = flops + 25*nshg c return endif c c.... perform backward substitution c if (code .eq. 'backward') then c r(:,5) = Diag(:,15) * r(:,5) r(:,4) = Diag(:,10) * ( r(:,4) & - r(:,5) * Diag(:,14) ) r(:,3) = Diag(:, 6) * ( r(:,3) & - r(:,5) * Diag(:,13) & - r(:,4) * Diag(:, 9) ) r(:,2) = Diag(:, 3) * ( r(:,2) & - r(:,5) * Diag(:,12) & - r(:,4) * Diag(:, 8) & - r(:,3) * Diag(:, 5) ) r(:,1) = Diag(:, 1) * ( r(:,1) & - r(:,5) * Diag(:,11) & - r(:,4) * Diag(:, 7) & - r(:,3) * Diag(:, 4) & - r(:,2) * Diag(:, 2) ) c c.... flop count c ! flops = flops + 25*nshg c return endif c c.... perform product U.r c if (code .eq. 'product ') then c r(:,1) = r(:,1) / Diag(:, 1) + r(:,2) * Diag(:, 2) + & r(:,3) * Diag(:, 4) + r(:,4) * Diag(:, 7) + & r(:,5) * Diag(:,11) r(:,2) = r(:,2) / Diag(:, 3) + r(:,3) * Diag(:, 5) + & r(:,4) * Diag(:, 8) + r(:,5) * Diag(:,12) r(:,3) = r(:,3) / Diag(:, 6) + r(:,4) * Diag(:, 9) + & r(:,5) * Diag(:,13) r(:,4) = r(:,4) / Diag(:,10) + r(:,5) * Diag(:,14) r(:,5) = r(:,5) / Diag(:,15) c c.... flop count c ! flops = flops + 40*nshg c return endif c call error ('i3LDU ', code, 0) c c.... return c return end
bsd-3-clause
skywalker00/sabermod_rom_toolchain
gcc/testsuite/gfortran.dg/coarray/image_index_2.f90
147
2047
! { dg-do run } ! ! Scalar coarray ! ! Run-time test for IMAGE_INDEX with cobounds only known at ! the compile time, suitable for any number of NUM_IMAGES() ! For compile-time cobounds, the -fcoarray=lib version still ! needs to run-time evalulation if image_index returns > 1 ! as image_index is 0 if the index would exceed num_images(). ! ! Please set num_images() to >= 13, if possible. ! ! PR fortran/18918 ! program test_image_index implicit none integer :: index1, index2, index3 logical :: one integer, save :: d[-1:3, *] integer, save :: e[-1:-1, 3:*] one = num_images() == 1 index1 = image_index(d, [-1, 1] ) index2 = image_index(d, [0, 1] ) if (one .and. (index1 /= 1 .or. index2 /= 0)) & call abort() if (.not. one .and. (index1 /= 1 .or. index2 /= 2)) & call abort() index1 = image_index(e, [-1, 3] ) index2 = image_index(e, [-1, 4] ) if (one .and. (index1 /= 1 .or. index2 /= 0)) & call abort() if (.not. one .and. (index1 /= 1 .or. index2 /= 2)) & call abort() call test(1, e, d, e) call test(2, e, d, e) contains subroutine test(n, a, b, c) integer :: n integer :: a[3*n:3*n, -4*n:-3*n, 88*n:*], b[-1*n:0*n,0*n:*], c[*] index1 = image_index(a, [3*n, -4*n, 88*n] ) index2 = image_index(b, [-1, 0] ) index3 = image_index(c, [1] ) if (n == 1) then if (index1 /= 1 .or. index2 /= 1 .or. index3 /= 1) call abort() else if (num_images() == 1) then if (index1 /= 1 .or. index2 /= 0 .or. index3 /= 1) call abort() else if (index1 /= 1 .or. index2 /= 2 .or. index3 /= 1) call abort() end if index1 = image_index(a, [3*n, -3*n, 88*n] ) index2 = image_index(b, [0, 0] ) index3 = image_index(c, [2] ) if (one .and. (index1 /= 0 .or. index2 /= 0 .or. index3 /= 0)) & call abort() if (n == 1 .and. num_images() == 2) then if (index1 /= 2 .or. index2 /= 2 .or. index3 /= 2) & call abort() else if (n == 2 .and. num_images() == 2) then if (index1 /= 0 .or. index2 /= 0 .or. index3 /= 2) & call abort() end if end subroutine test end program test_image_index
gpl-2.0
kbai/specfem3d
utils/Cubit_or_Gmsh/convert_tetra_mesh_to_hexa_mesh_THex.f90
1
13971
!===================================================================== ! ! S p e c f e m 3 D V e r s i o n 3 . 0 ! --------------------------------------- ! ! Main historical authors: Dimitri Komatitsch and Jeroen Tromp ! Princeton University, USA ! and CNRS / University of Marseille, France ! (there are currently many more authors!) ! (c) Princeton University and CNRS / University of Marseille, July 2012 ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along ! with this program; if not, write to the Free Software Foundation, Inc., ! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ! !===================================================================== ! read an external mesh file (list of points and list of elements) composed of tetrahedra ! and create a mesh of hexahedra by cutting each tetrahedron into four hexahedra ! using the middle of each edge, each face and the barycenter. ! For a picture of what this gives, see e.g. http://www.tetgen.org/figs/Delaunay-Voronoi-3D.gif ! (or a copy of it in utils/Cubit_or_Gmsh/logo_of_TetGen_showing_Delaunay_Voronoi_3D_how_to_cut_a_tetra_into_four_hexas.gif) ! Dimitri Komatitsch, CNRS, Marseille, France, June 2015. program convert_tetra_mesh_to_hexa_mesh implicit none ! ! work in single or in double precision (4 or 8 bytes) ! integer, parameter :: CUSTOM_REAL = 4 ! 8 ! read list of elements stored in new Gmsh 2.9.3 format or in old Gmsh 2.4.2 format (the old one has one extra dummy value) logical, parameter :: USE_OLD_GMSH_MESH_FORMAT = .true. ! .false. real(kind=CUSTOM_REAL), parameter :: ONE_THIRD = 1._CUSTOM_REAL / 3._CUSTOM_REAL integer :: nglob,ntet,nelem_in_file integer :: i,k,ihexa,iread,itype,idummy1,idummy2,idummy3,ivolume real(kind=CUSTOM_REAL) :: xread,yread,zread real(kind=CUSTOM_REAL), allocatable, dimension(:) :: x,y,z integer, dimension(15) :: number_of_points_per_element_type integer, dimension(0:3) :: inode_read ! coordinates of nodes in the middle of the tetrahedron edges real(kind=CUSTOM_REAL) :: mid_0_1_x,mid_0_2_x,mid_0_3_x,mid_1_2_x,mid_1_3_x,mid_2_3_x real(kind=CUSTOM_REAL) :: mid_0_1_y,mid_0_2_y,mid_0_3_y,mid_1_2_y,mid_1_3_y,mid_2_3_y real(kind=CUSTOM_REAL) :: mid_0_1_z,mid_0_2_z,mid_0_3_z,mid_1_2_z,mid_1_3_z,mid_2_3_z ! coordinates of nodes in the middle of the tetrahedron faces real(kind=CUSTOM_REAL) :: mid_face_0_1_2_x,mid_face_0_1_3_x,mid_face_0_2_3_x,mid_face_1_2_3_x real(kind=CUSTOM_REAL) :: mid_face_0_1_2_y,mid_face_0_1_3_y,mid_face_0_2_3_y,mid_face_1_2_3_y real(kind=CUSTOM_REAL) :: mid_face_0_1_2_z,mid_face_0_1_3_z,mid_face_0_2_3_z,mid_face_1_2_3_z ! coordinates of the barycenter of the tetrahedron real(kind=CUSTOM_REAL) :: barycenter_x,barycenter_y,barycenter_z integer :: iglob_0,iglob_1,iglob_2,iglob_3 integer :: iglob_mid_0_1,iglob_mid_0_2,iglob_mid_0_3,iglob_mid_1_2,iglob_mid_1_3,iglob_mid_2_3,iglob_barycenter integer :: iglob_mid_face_0_1_2,iglob_mid_face_0_1_3,iglob_mid_face_0_2_3,iglob_mid_face_1_2_3 number_of_points_per_element_type(:) = 0 ! for Gmsh element types (from http://geuz.org/gmsh/doc/texinfo/gmsh.html#Low-order-elements ) number_of_points_per_element_type(1) = 2 ! 2-node line number_of_points_per_element_type(2) = 3 ! 3-node triangle number_of_points_per_element_type(4) = 4 ! 4-node tetrahedron number_of_points_per_element_type(15) = 1 ! 1-node point ! point numbering convention for tetrahedra in Gmsh (from http://geuz.org/gmsh/doc/texinfo/gmsh.html#Low-order-elements ) ! ! Tetrahedron4: Tetrahedron10: ! v ! . ! ,/ ! / ! 2 2 ! ,/|`\ ,/|`\ ! ,/ | `\ ,/ | `\ ! ,/ '. `\ ,6 '. `5 ! ,/ | `\ ,/ 8 `\ ! ,/ | `\ ,/ | `\ ! 0-----------'.--------1 --> u 0--------4--'.--------1 ! `\. | ,/ `\. | ,/ ! `\. | ,/ `\. | ,9 ! `\. '. ,/ `7. '. ,/ ! `\. |/ `\. |/ ! `3 `3 ! `\. ! ` w ! ! --------- read mesh points --------- open(unit=10,file='points.txt',status='old',action='read') read(10,*) nglob print *,'reading ',nglob,' mesh points from the Gmsh database' allocate(x(nglob)) allocate(y(nglob)) allocate(z(nglob)) do i = 1,nglob read(10,*) iread,xread,yread,zread if(iread < 1 .or. iread > nglob) stop 'incorrect point read' x(iread) = xread y(iread) = yread z(iread) = zread enddo close(10) print * print *,'x min max read = ',minval(x),maxval(x) print *,'y min max read = ',minval(y),maxval(y) print *,'z min max read = ',minval(z),maxval(z) print * ! --------- read mesh points --------- open(unit=10,file='elements.txt',status='old',action='read') read(10,*) nelem_in_file print *,'reading ',nelem_in_file,' mesh elements of any geometrical kind from the Gmsh database' ntet = 0 do i = 1,nelem_in_file inode_read(:) = 0 ! read list of elements stored in new Gmsh 2.9.3 format or in old Gmsh 2.4.2 format (the old one has one extra dummy value) if(USE_OLD_GMSH_MESH_FORMAT) then read(10,*) iread,itype,idummy1,idummy2,ivolume,idummy3,(inode_read(k), k=0,number_of_points_per_element_type(itype)-1) else read(10,*) iread,itype,idummy1,idummy2,ivolume,(inode_read(k), k=0,number_of_points_per_element_type(itype)-1) endif if(number_of_points_per_element_type(itype) <= 0) stop 'incorrect element type read' if(iread < 1 .or. iread > nelem_in_file) stop 'incorrect element read' if(itype == 4) then ntet = ntet + 1 endif enddo close(10) print * print *,'number of tetrahedra read = ',ntet ! writing the database for the hexahedral mesh print * print *,'writing the database for the new mesh consisting of hexahedra...' ! create the subdirectory to store the mesh if it does not exist call system('mkdir -p MESH') open(unit=9,file='points.txt',status='old',action='read') open(unit=10,file='elements.txt',status='old',action='read') ! file with hexahedra points (four hexahedra created out of each tetrahedron) open(unit=14,file='MESH/nodes_coords_file',status='unknown',action='write') ! file with hexahedra (four hexahedra created out of each tetrahedron) open(unit=15,file='MESH/mesh_file',status='unknown',action='write') read(10,*) nelem_in_file ! we need to copy the existing list of points and then add 11 new points in each tetrahedron write(14,*) nglob + 11*ntet ! out of each tetrahedron we create four hexahedra write(15,*) 4*ntet print * print *,'the mesh of hexahedra will have ',nglob + 11*ntet,' points' print *,'and ',4*ntet,' elements' print * read(9,*) nglob do i = 1,nglob read(9,*) iread,xread,yread,zread write(14,*) iread,xread,yread,zread enddo ntet = 0 ihexa = 0 do i = 1,nelem_in_file inode_read(:) = 0 ! read list of elements stored in new Gmsh 2.9.3 format or in old Gmsh 2.4.2 format (the old one has one extra dummy value) if(USE_OLD_GMSH_MESH_FORMAT) then read(10,*) iread,itype,idummy1,idummy2,ivolume,idummy3,(inode_read(k), k=0,number_of_points_per_element_type(itype)-1) else read(10,*) iread,itype,idummy1,idummy2,ivolume,(inode_read(k), k=0,number_of_points_per_element_type(itype)-1) endif if(number_of_points_per_element_type(itype) <= 0) stop 'incorrect element type read' if(iread < 1 .or. iread > nelem_in_file) stop 'incorrect element read' ! processing only the elements that are tetrahedra if(itype == 4) then ntet = ntet + 1 ! now let us cut each tetrahedron into four hexahedra using the middle of each edge, each face and the barycenter. ! For a picture of what this gives, see e.g. http://www.tetgen.org/figs/Delaunay-Voronoi-3D.gif ! (or a copy of it in utils/Cubit_or_Gmsh/logo_of_TetGen_showing_Delaunay_Voronoi_3D_how_to_cut_a_tetra_into_four_hexas.gif) ! new points located in the middle of the edges mid_0_1_x = 0.5_CUSTOM_REAL * (x(inode_read(0)) + x(inode_read(1))) mid_0_2_x = 0.5_CUSTOM_REAL * (x(inode_read(0)) + x(inode_read(2))) mid_0_3_x = 0.5_CUSTOM_REAL * (x(inode_read(0)) + x(inode_read(3))) mid_1_2_x = 0.5_CUSTOM_REAL * (x(inode_read(1)) + x(inode_read(2))) mid_1_3_x = 0.5_CUSTOM_REAL * (x(inode_read(1)) + x(inode_read(3))) mid_2_3_x = 0.5_CUSTOM_REAL * (x(inode_read(2)) + x(inode_read(3))) mid_0_1_y = 0.5_CUSTOM_REAL * (y(inode_read(0)) + y(inode_read(1))) mid_0_2_y = 0.5_CUSTOM_REAL * (y(inode_read(0)) + y(inode_read(2))) mid_0_3_y = 0.5_CUSTOM_REAL * (y(inode_read(0)) + y(inode_read(3))) mid_1_2_y = 0.5_CUSTOM_REAL * (y(inode_read(1)) + y(inode_read(2))) mid_1_3_y = 0.5_CUSTOM_REAL * (y(inode_read(1)) + y(inode_read(3))) mid_2_3_y = 0.5_CUSTOM_REAL * (y(inode_read(2)) + y(inode_read(3))) mid_0_1_z = 0.5_CUSTOM_REAL * (z(inode_read(0)) + z(inode_read(1))) mid_0_2_z = 0.5_CUSTOM_REAL * (z(inode_read(0)) + z(inode_read(2))) mid_0_3_z = 0.5_CUSTOM_REAL * (z(inode_read(0)) + z(inode_read(3))) mid_1_2_z = 0.5_CUSTOM_REAL * (z(inode_read(1)) + z(inode_read(2))) mid_1_3_z = 0.5_CUSTOM_REAL * (z(inode_read(1)) + z(inode_read(3))) mid_2_3_z = 0.5_CUSTOM_REAL * (z(inode_read(2)) + z(inode_read(3))) ! new points located in the middle of the faces mid_face_0_1_2_x = ONE_THIRD * (x(inode_read(0)) + x(inode_read(1)) + x(inode_read(2))) mid_face_0_1_3_x = ONE_THIRD * (x(inode_read(0)) + x(inode_read(1)) + x(inode_read(3))) mid_face_0_2_3_x = ONE_THIRD * (x(inode_read(0)) + x(inode_read(2)) + x(inode_read(3))) mid_face_1_2_3_x = ONE_THIRD * (x(inode_read(1)) + x(inode_read(2)) + x(inode_read(3))) mid_face_0_1_2_y = ONE_THIRD * (y(inode_read(0)) + y(inode_read(1)) + y(inode_read(2))) mid_face_0_1_3_y = ONE_THIRD * (y(inode_read(0)) + y(inode_read(1)) + y(inode_read(3))) mid_face_0_2_3_y = ONE_THIRD * (y(inode_read(0)) + y(inode_read(2)) + y(inode_read(3))) mid_face_1_2_3_y = ONE_THIRD * (y(inode_read(1)) + y(inode_read(2)) + y(inode_read(3))) mid_face_0_1_2_z = ONE_THIRD * (z(inode_read(0)) + z(inode_read(1)) + z(inode_read(2))) mid_face_0_1_3_z = ONE_THIRD * (z(inode_read(0)) + z(inode_read(1)) + z(inode_read(3))) mid_face_0_2_3_z = ONE_THIRD * (z(inode_read(0)) + z(inode_read(2)) + z(inode_read(3))) mid_face_1_2_3_z = ONE_THIRD * (z(inode_read(1)) + z(inode_read(2)) + z(inode_read(3))) ! new point located in the middle of the element (i.e. at its barycenter) barycenter_x = 0.25_CUSTOM_REAL * (x(inode_read(0)) + x(inode_read(1)) + x(inode_read(2)) + x(inode_read(3))) barycenter_y = 0.25_CUSTOM_REAL * (y(inode_read(0)) + y(inode_read(1)) + y(inode_read(2)) + y(inode_read(3))) barycenter_z = 0.25_CUSTOM_REAL * (z(inode_read(0)) + z(inode_read(1)) + z(inode_read(2)) + z(inode_read(3))) ! write these new points in the database of points iglob_mid_0_1 = nglob + 1 iglob_mid_0_2 = nglob + 2 iglob_mid_0_3 = nglob + 3 iglob_mid_1_2 = nglob + 4 iglob_mid_1_3 = nglob + 5 iglob_mid_2_3 = nglob + 6 iglob_mid_face_0_1_2 = nglob + 7 iglob_mid_face_0_1_3 = nglob + 8 iglob_mid_face_0_2_3 = nglob + 9 iglob_mid_face_1_2_3 = nglob + 10 iglob_barycenter = nglob + 11 write(14,*) iglob_mid_0_1,mid_0_1_x,mid_0_1_y,mid_0_1_z write(14,*) iglob_mid_0_2,mid_0_2_x,mid_0_2_y,mid_0_2_z write(14,*) iglob_mid_0_3,mid_0_3_x,mid_0_3_y,mid_0_3_z write(14,*) iglob_mid_1_2,mid_1_2_x,mid_1_2_y,mid_1_2_z write(14,*) iglob_mid_1_3,mid_1_3_x,mid_1_3_y,mid_1_3_z write(14,*) iglob_mid_2_3,mid_2_3_x,mid_2_3_y,mid_2_3_z write(14,*) iglob_mid_face_0_1_2,mid_face_0_1_2_x,mid_face_0_1_2_y,mid_face_0_1_2_z write(14,*) iglob_mid_face_0_1_3,mid_face_0_1_3_x,mid_face_0_1_3_y,mid_face_0_1_3_z write(14,*) iglob_mid_face_0_2_3,mid_face_0_2_3_x,mid_face_0_2_3_y,mid_face_0_2_3_z write(14,*) iglob_mid_face_1_2_3,mid_face_1_2_3_x,mid_face_1_2_3_y,mid_face_1_2_3_z write(14,*) iglob_barycenter,barycenter_x,barycenter_y,barycenter_z nglob = nglob + 11 ! because we have added eleven points ! define some useful aliases for the four existing points iglob_0 = inode_read(0) iglob_1 = inode_read(1) iglob_2 = inode_read(2) iglob_3 = inode_read(3) ! write the four new elements in the database of elements ihexa = ihexa + 1 write(15,"(9i12)") ihexa,iglob_1,iglob_mid_1_2,iglob_mid_face_0_1_2,iglob_mid_0_1, & iglob_mid_1_3,iglob_mid_face_1_2_3,iglob_barycenter,iglob_mid_face_0_1_3 ihexa = ihexa + 1 write(15,"(9i12)") ihexa,iglob_mid_1_2,iglob_2,iglob_mid_0_2,iglob_mid_face_0_1_2, & iglob_mid_face_1_2_3,iglob_mid_2_3,iglob_mid_face_0_2_3,iglob_barycenter ihexa = ihexa + 1 write(15,"(9i12)") ihexa,iglob_0,iglob_mid_0_1,iglob_mid_face_0_1_2,iglob_mid_0_2, & iglob_mid_0_3,iglob_mid_face_0_1_3,iglob_barycenter,iglob_mid_face_0_2_3 ihexa = ihexa + 1 write(15,"(9i12)") ihexa,iglob_mid_face_0_1_3,iglob_mid_1_3,iglob_mid_face_1_2_3,iglob_barycenter, & iglob_mid_0_3,iglob_3,iglob_mid_2_3,iglob_mid_face_0_2_3 endif enddo close(9) close(10) close(14) close(15) end program convert_tetra_mesh_to_hexa_mesh
gpl-2.0
kbai/specfem3d
utils/small_SEM_solvers_in_Fortran_and_C_without_MPI_to_learn/mesher_for_serial/add_missing_nodes.f90
6
5562
!===================================================================== ! ! S p e c f e m 3 D G l o b e V e r s i o n 4 . 0 ! -------------------------------------------------- ! ! Main authors: Dimitri Komatitsch and Jeroen Tromp ! Seismological Laboratory, California Institute of Technology, USA ! and University of Pau / CNRS / INRIA, France ! (c) California Institute of Technology and University of Pau / CNRS / INRIA ! February 2008 ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along ! with this program; if not, write to the Free Software Foundation, Inc., ! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ! !===================================================================== ! compute the missing nodes of a 27-node element when only the 8 corners have been given ! the topology of the nodes is described in file hex_nodes.f90 as well as in ! UTILS/chunk_notes_scanned/numbering_convention_27_nodes.* subroutine add_missing_nodes(offset_x,offset_y,offset_z) implicit none include "constants.h" double precision, dimension(NGNOD) :: offset_x,offset_y,offset_z ! list of corners defining the edges and the faces integer, parameter :: NEDGES = 12, NFACES = 6 integer, dimension(NEDGES,2) :: list_corners_edge integer, dimension(NFACES,4) :: list_corners_face integer :: iedge,iface,ignod ! list of corners defining the edges ! the edge number is sorted according to the numbering convention defined in file hex_nodes.f90 ! as well as in DATA/util/YYYYYYYYYYYYYYYYYYYYYYYYYYY DK DK UGLY YYYYYYYYYYYYYYYYYYY list_corners_edge( 1,1) = 1 list_corners_edge( 1,2) = 2 list_corners_edge( 2,1) = 2 list_corners_edge( 2,2) = 3 list_corners_edge( 3,1) = 3 list_corners_edge( 3,2) = 4 list_corners_edge( 4,1) = 4 list_corners_edge( 4,2) = 1 list_corners_edge( 5,1) = 1 list_corners_edge( 5,2) = 5 list_corners_edge( 6,1) = 2 list_corners_edge( 6,2) = 6 list_corners_edge( 7,1) = 3 list_corners_edge( 7,2) = 7 list_corners_edge( 8,1) = 4 list_corners_edge( 8,2) = 8 list_corners_edge( 9,1) = 5 list_corners_edge( 9,2) = 6 list_corners_edge(10,1) = 6 list_corners_edge(10,2) = 7 list_corners_edge(11,1) = 7 list_corners_edge(11,2) = 8 list_corners_edge(12,1) = 8 list_corners_edge(12,2) = 5 ! list of corners defining the faces ! the face number is sorted according to the numbering convention defined in file hex_nodes.f90 ! as well as in DATA/util/YYYYYYYYYYYYYYYYYYYYYYYYYYY DK DK UGLY YYYYYYYYYYYYYYYYYYY list_corners_face(1,1) = 1 list_corners_face(1,2) = 2 list_corners_face(1,3) = 3 list_corners_face(1,4) = 4 list_corners_face(2,1) = 1 list_corners_face(2,2) = 2 list_corners_face(2,3) = 6 list_corners_face(2,4) = 5 list_corners_face(3,1) = 2 list_corners_face(3,2) = 3 list_corners_face(3,3) = 7 list_corners_face(3,4) = 6 list_corners_face(4,1) = 4 list_corners_face(4,2) = 3 list_corners_face(4,3) = 7 list_corners_face(4,4) = 8 list_corners_face(5,1) = 1 list_corners_face(5,2) = 4 list_corners_face(5,3) = 8 list_corners_face(5,4) = 5 list_corners_face(6,1) = 5 list_corners_face(6,2) = 6 list_corners_face(6,3) = 7 list_corners_face(6,4) = 8 ! midside nodes (nodes located in the middle of an edge) do iedge = 1,NEDGES ! node numbers for edge centers start at 9 ignod = (iedge - 1) + 9 offset_x(ignod) = (offset_x(list_corners_edge(iedge,1)) + offset_x(list_corners_edge(iedge,2))) / 2.d0 offset_y(ignod) = (offset_y(list_corners_edge(iedge,1)) + offset_y(list_corners_edge(iedge,2))) / 2.d0 offset_z(ignod) = (offset_z(list_corners_edge(iedge,1)) + offset_z(list_corners_edge(iedge,2))) / 2.d0 enddo ! side center nodes (nodes located in the middle of a face) do iface = 1,NFACES ! node numbers for face centers start at 21 ignod = (iface - 1) + 21 offset_x(ignod) = (offset_x(list_corners_face(iface,1)) + & offset_x(list_corners_face(iface,2)) + & offset_x(list_corners_face(iface,3)) + & offset_x(list_corners_face(iface,4))) / 4.d0 offset_y(ignod) = (offset_y(list_corners_face(iface,1)) + & offset_y(list_corners_face(iface,2)) + & offset_y(list_corners_face(iface,3)) + & offset_y(list_corners_face(iface,4))) / 4.d0 offset_z(ignod) = (offset_z(list_corners_face(iface,1)) + & offset_z(list_corners_face(iface,2)) + & offset_z(list_corners_face(iface,3)) + & offset_z(list_corners_face(iface,4))) / 4.d0 enddo ! center node (barycenter of the eight corners) offset_x(27) = sum(offset_x(1:NGNOD_EIGHT_CORNERS)) / dble(NGNOD_EIGHT_CORNERS) offset_y(27) = sum(offset_y(1:NGNOD_EIGHT_CORNERS)) / dble(NGNOD_EIGHT_CORNERS) offset_z(27) = sum(offset_z(1:NGNOD_EIGHT_CORNERS)) / dble(NGNOD_EIGHT_CORNERS) end subroutine add_missing_nodes
gpl-2.0
skywalker00/sabermod_rom_toolchain
gcc/testsuite/gfortran.dg/transfer_assumed_size_1.f90
136
1340
! { dg-do run } ! Tests the fix for the regression PR34080, in which the character ! length of the assumed length arguments to TRANSFER were getting ! lost. ! ! Drew McCormack <drewmccormack@mac.com> ! module TransferBug type ByteType private character(len=1) :: singleByte end type type (ByteType), save :: BytesPrototype(1) contains function StringToBytes(v) result (bytes) character(len=*), intent(in) :: v type (ByteType) :: bytes(size(transfer(v, BytesPrototype))) bytes = transfer(v, BytesPrototype) end function subroutine BytesToString(bytes, string) type (ByteType), intent(in) :: bytes(:) character(len=*), intent(out) :: string character(len=1) :: singleChar(1) integer :: numChars numChars = size(transfer(bytes,singleChar)) string = '' string = transfer(bytes, string) string(numChars+1:) = '' end subroutine end module program main use TransferBug character(len=100) :: str call BytesToString( StringToBytes('Hi'), str ) if (trim(str) .ne. "Hi") call abort () end program
gpl-2.0
QEF/q-e_schrodinger
PHonon/PH/solve_e.f90
1
11512
! ! Copyright (C) 2001-2018 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !----------------------------------------------------------------------- subroutine solve_e !----------------------------------------------------------------------- !! This routine is a driver for the solution of the linear system which !! defines the change of the wavefunction due to an electric field. !! It performs the following tasks: !! a) computes the bare potential term times \(|\psi\rangle \); !! b) adds to it the screening term \(\Delta V_\text{SCF}|psi\rangle\). !! If \(\text{lda_plus_u}=\text{TRUE}\) compute also the SCF part !! of the response Hubbard potential; !! c) applies \(P_c^+\) (orthogonalization to valence states); !! d) calls \(\texttt{cgsolve_all}\) to solve the linear system; !! e) computes \(\Delta \rho\), \(\Delta V_\text{SCF}|psi\rangle\) and !! symmetrizes them; !! f) if \(\text{lda_plus_u}=\text{TRUE}\) compute also the response !! occupation matrices dnsscf. !! Step b, c, d are done in \(\text{sternheimer_kernel}\). ! USE kinds, ONLY : DP USE ions_base, ONLY : nat USE io_global, ONLY : stdout, ionode USE io_files, ONLY : diropn USE mp, ONLY : mp_sum USE mp_pools, ONLY : inter_pool_comm USE mp_bands, ONLY : intra_bgrp_comm USE klist, ONLY : ltetra, lgauss, xk, ngk, igk_k USE gvecs, ONLY : doublegrid USE fft_base, ONLY : dfftp, dffts USE lsda_mod, ONLY : nspin, lsda, current_spin, isk USE wvfct, ONLY : nbnd, npwx USE check_stop, ONLY : check_stop_now USE buffers, ONLY : get_buffer USE wavefunctions, ONLY : evc USE uspp, ONLY : okvan, vkb USE uspp_param, ONLY : nhm USE noncollin_module, ONLY : noncolin, npol, nspin_mag, domag USE scf, ONLY : rho USE paw_variables, ONLY : okpaw USE paw_onecenter, ONLY : paw_dpotential USE paw_symmetry, ONLY : paw_desymmetrize USE units_ph, ONLY : lrdrho, iudrho, lrebar, iuebar USE units_lr, ONLY : iuwfc, lrwfc USE output, ONLY : fildrho USE control_ph, ONLY : ext_recover, rec_code, & lnoloc, convt, tr2_ph, nmix_ph, & alpha_mix, lgamma_gamma, niter_ph, & flmixdpot, rec_code_read USE recover_mod, ONLY : read_rec, write_rec USE lrus, ONLY : int3_paw USE qpoint, ONLY : nksq, ikks USE control_lr, ONLY : lgamma USE dv_of_drho_lr, ONLY : dv_of_drho USE fft_interfaces, ONLY : fft_interpolate USE ldaU, ONLY : lda_plus_u USE apply_dpot_mod, ONLY : apply_dpot_allocate, apply_dpot_deallocate USE response_kernels, ONLY : sternheimer_kernel USE uspp_init, ONLY : init_us_2 ! IMPLICIT NONE ! LOGICAL :: exst !! LOGICAL :: all_conv !! True if sternheimer_kernel is converged at all k points and perturbations INTEGER :: ikk, npw, kter, iter0, ipol, iter, ik, is, ndim !! counters REAL(DP) :: thresh !! convergence threshold REAL(DP) :: averlt !! average number of iterations REAL(DP) :: dr2 !! self-consistency error REAL(DP) :: tcpu, get_clock !! timing variables COMPLEX(DP), ALLOCATABLE, TARGET :: dvscfin (:,:,:) !! change of the scf potential (input) COMPLEX(DP), POINTER :: dvscfins (:,:,:) !! change of the scf potential (smooth) COMPLEX(DP), ALLOCATABLE :: dvscfout (:,:,:) !! change of the scf potential (output) COMPLEX(DP), ALLOCATABLE :: dbecsum(:,:,:,:) !! the becsum with dpsi COMPLEX(DP), ALLOCATABLE :: dbecsum_nc(:,:,:,:,:) !! the becsum with dpsi COMPLEX(DP), ALLOCATABLE :: mixin(:), mixout(:) !! auxiliary for paw mixing ! call start_clock ('solve_e') ! ! This routine is task group aware ! allocate (dvscfin( dfftp%nnr, nspin_mag, 3)) dvscfin=(0.0_DP,0.0_DP) if (doublegrid) then allocate (dvscfins(dffts%nnr, nspin_mag, 3)) else dvscfins => dvscfin endif allocate (dvscfout(dfftp%nnr, nspin_mag, 3)) IF (okpaw) THEN ALLOCATE (mixin(dfftp%nnr*nspin_mag*3+(nhm*(nhm+1)*nat*nspin_mag*3)/2) ) ALLOCATE (mixout(dfftp%nnr*nspin_mag*3+(nhm*(nhm+1)*nat*nspin_mag*3)/2) ) mixin=(0.0_DP,0.0_DP) ENDIF allocate (dbecsum( nhm*(nhm+1)/2, nat, nspin_mag, 3)) IF (noncolin) allocate (dbecsum_nc (nhm, nhm, nat, nspin, 3)) CALL apply_dpot_allocate() if (rec_code_read == -20.AND.ext_recover) then ! restarting in Electric field calculation IF (okpaw) THEN CALL read_rec(dr2, iter0, 3, dvscfin, dvscfins, dvscfout, dbecsum) CALL setmixout(3*dfftp%nnr*nspin_mag,(nhm*(nhm+1)*nat*nspin_mag*3)/2, & mixin, dvscfin, dbecsum, ndim, -1 ) ELSE CALL read_rec(dr2, iter0, 3, dvscfin, dvscfins) ENDIF else if (rec_code_read > -20 .AND. rec_code_read <= -10) then ! restarting in Raman: proceed convt = .true. else convt = .false. iter0 = 0 endif ! IF ( ionode .AND. fildrho /= ' ') THEN INQUIRE (UNIT = iudrho, OPENED = exst) IF (exst) CLOSE (UNIT = iudrho, STATUS='keep') CALL diropn (iudrho, TRIM(fildrho)//'.E', lrdrho, exst) end if IF (rec_code_read > -20) convt=.TRUE. ! if (convt) go to 155 ! ! if q=0 for a metal: allocate and compute local DOS at Ef ! if ( (lgauss .or. ltetra) .or..not.lgamma) call errore ('solve_e', & 'called in the wrong case', 1) ! ! Compute P_c^+ x psi for all polarization and k points and store in buffer ! DO ik = 1, nksq DO ipol = 1, 3 ikk = ikks(ik) npw = ngk(ikk) IF (lsda) current_spin = isk(ikk) ! ! reads unperturbed wavefunctions psi_k in G_space, for all bands ! IF (nksq > 1) THEN CALL get_buffer(evc, lrwfc, iuwfc, ikk) ENDIF ! CALL init_us_2(npw, igk_k(1, ikk), xk(1, ikk), vkb) ! ! computes P_c^+ x psi_kpoint, written to buffer iuebar. ! CALL dvpsi_e(ik, ipol) ! ENDDO ! ipol ENDDO ! ik ! ! The outside loop is over the iterations ! do kter = 1, niter_ph ! FLUSH( stdout ) iter = kter + iter0 ! dvscfout = (0.d0,0.d0) dbecsum = (0.d0,0.d0) IF (noncolin) dbecsum_nc = (0.d0,0.d0) ! ! DFPT+U: at each iteration calculate dnsscf, ! i.e. the scf variation of the occupation matrix ns. ! IF (lda_plus_u .AND. (iter /= 1)) CALL dnsq_scf(3, .false., 0, 1, .false.) ! ! set threshold for the iterative solution of the linear system ! IF (iter == 1) THEN thresh = 1.d-2 IF (lnoloc) thresh = 1.d-5 ELSE thresh = MIN(0.1d0 * SQRT(dr2), 1.0d-2) ENDIF ! ! Compute dvscfout, the charge density response to the total potential ! CALL sternheimer_kernel(iter==1, .FALSE., 3, lrebar, iuebar, thresh, dvscfins, & all_conv, averlt, dvscfout, dbecsum, dbecsum_nc) ! ! The calculation of dbecsum is distributed across processors ! (see addusdbec) - we sum over processors the contributions ! coming from each slice of bands ! IF (noncolin) THEN call mp_sum ( dbecsum_nc, intra_bgrp_comm ) ELSE call mp_sum ( dbecsum, intra_bgrp_comm ) END IF if (doublegrid) then do is=1,nspin_mag do ipol=1,3 call fft_interpolate (dffts, dvscfout(:,is,ipol), dfftp, dvscfout(:,is,ipol)) enddo enddo endif ! IF (noncolin.and.okvan) CALL set_dbecsum_nc(dbecsum_nc, dbecsum, 3) ! call addusddense (dvscfout, dbecsum) ! ! dvscfout contains the (unsymmetrized) linear charge response ! for the three polarizations - symmetrize it ! call mp_sum ( dvscfout, inter_pool_comm ) IF (okpaw) call mp_sum ( dbecsum, inter_pool_comm ) if (.not.lgamma_gamma) then call psyme (dvscfout) IF ( noncolin.and.domag ) CALL psym_dmage(dvscfout) endif ! ! save the symmetrized linear charge response to file ! calculate the corresponding linear potential response ! do ipol=1,3 if (fildrho.ne.' ') call davcio_drho(dvscfout(1,1,ipol),lrdrho, & iudrho,ipol,+1) IF (lnoloc) then dvscfout(:,:,ipol)=(0.d0,0.d0) ELSE call dv_of_drho (dvscfout (1, 1, ipol), .false.) ENDIF enddo ! ! mix the new potential with the old ! IF (okpaw) THEN ! ! In this case we mix also dbecsum ! call setmixout(3*dfftp%nnr*nspin_mag,(nhm*(nhm+1)*nat*nspin_mag*3)/2, & mixout, dvscfout, dbecsum, ndim, -1 ) call mix_potential (2*3*dfftp%nnr*nspin_mag+2*ndim, mixout, mixin, & alpha_mix(kter), dr2, 3*tr2_ph/npol, iter, & nmix_ph, flmixdpot, convt) call setmixout(3*dfftp%nnr*nspin_mag,(nhm*(nhm+1)*nat*nspin_mag*3)/2, & mixin, dvscfin, dbecsum, ndim, 1 ) ELSE call mix_potential (2*3*dfftp%nnr*nspin_mag, dvscfout, dvscfin, alpha_mix ( & kter), dr2, 3 * tr2_ph / npol, iter, nmix_ph, flmixdpot, convt) ENDIF if (doublegrid) then do is=1,nspin_mag do ipol = 1, 3 call fft_interpolate (dfftp, dvscfin(:,is,ipol), dffts, dvscfins(:,is,ipol)) enddo enddo endif IF (okpaw) THEN IF (noncolin) THEN ! call PAW_dpotential(dbecsum_nc,becsum_nc,int3_paw,3) ELSE ! ! The presence of c.c. in the formula gives a factor 2.0 ! dbecsum=2.0_DP * dbecsum IF (.NOT. lgamma_gamma) CALL PAW_desymmetrize(dbecsum) call PAW_dpotential(dbecsum,rho%bec,int3_paw,3) ENDIF ENDIF call newdq(dvscfin,3) tcpu = get_clock ('PHONON') WRITE( stdout, '(/,5x," iter # ",i3," total cpu time :",f8.1, & & " secs av.it.: ",f5.1)') iter, tcpu, averlt dr2 = dr2 / 3 WRITE( stdout, "(5x,' thresh=',es10.3, ' alpha_mix = ',f6.3, & & ' |ddv_scf|^2 = ',es10.3 )") thresh, alpha_mix (kter), dr2 ! FLUSH( stdout ) ! ! rec_code: state of the calculation ! rec_code=-20 Electric Field ! rec_code=-20 IF (okpaw) THEN CALL write_rec('solve_e...', 0, dr2, iter, convt, 3, dvscfin, & dvscfout, dbecsum) ELSE CALL write_rec('solve_e...', 0, dr2, iter, convt, 3, dvscfin) ENDIF if (check_stop_now()) call stop_smoothly_ph (.false.) if (convt) goto 155 enddo 155 continue ! CALL apply_dpot_deallocate() deallocate (dbecsum) deallocate (dvscfout) IF (okpaw) THEN DEALLOCATE(mixin) DEALLOCATE(mixout) ENDIF if (doublegrid) deallocate (dvscfins) deallocate (dvscfin) if (noncolin) deallocate(dbecsum_nc) call stop_clock ('solve_e') return end subroutine solve_e
gpl-2.0
davidandrewnew/uclales
src/modnudge.f90
1
12306
!> \file modnudge.f90 !! Nudges theta_l and q_t profiles to the initial profiles on a timescale tnudgeT !> !> !! Nudges theta_l and q_t profiles to the initial profiles on a timescale tnudgeT !> !! \author Thijs Heus,MPI-M !! \par Revision list !! \todo Documentation ! This file is part of DALES. ! ! DALES is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 3 of the License, or ! (at your option) any later version. ! ! DALES is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. ! ! Copyright 1993-2009 Delft University of Technology, Wageningen University, Utrecht University, KNMI ! module modnudge implicit none PRIVATE PUBLIC :: nudge,lnudge,tnudgefac, qfloor, zfloor, znudgemin, znudgeplus, nudge_bound, lnudge_bound SAVE real, dimension(:,:), allocatable :: tnudge,unudge,vnudge,wnudge,thlnudge,qtnudge real, dimension(:,:), allocatable :: tuvnudge ! DAN real, dimension(:) , allocatable :: timenudge real :: tnudgefac = 1., qfloor = -1., zfloor = 1200., znudgemin = -1., znudgeplus = -1. logical :: lnudge,lunudge,lvnudge,lwnudge,lthlnudge,lqtnudge integer :: ntnudge = 100 logical :: firsttime = .true. ! LINDA, b ! arrays for nuding logical :: lnudge_bound = .false. ! arrays for initial values real, dimension(:),allocatable::tn,rn,un,vn,wn real, allocatable :: rlx(:,:) real::coef=1./60. ! LINDA, e contains subroutine initnudge(time) use grid, only : nzp,zt,th00,umean,vmean use mpi_interface, only : myid use defs, only : pi implicit none integer :: ierr,k,t,ifinput = 19 real,allocatable,dimension(:) :: height real, intent(in) :: time character(1) :: chmess1 real :: highheight,highqtnudge,highthlnudge,highunudge,highvnudge,highwnudge,hightnudge real :: lowheight,lowqtnudge,lowthlnudge,lowunudge,lowvnudge,lowwnudge,lowtnudge real :: fac real :: hightuvnudge, lowtuvnudge ! DAN allocate(tnudge(nzp,ntnudge),unudge(nzp,ntnudge),vnudge(nzp,ntnudge),wnudge(nzp,ntnudge),thlnudge(nzp,ntnudge),qtnudge(nzp,ntnudge)) allocate(timenudge(0:ntnudge), height(nzp)) allocate(tuvnudge(nzp,ntnudge)) ! DAN tnudge = 0 tuvnudge = 0 ! DAN unudge=0 vnudge=0 wnudge=0 thlnudge=0 qtnudge=0 timenudge=0 height = 0. if (.not. lnudge) return t = 0 open (ifinput,file='nudge_in') ierr = 0 readloop: do t = t + 1 chmess1 = "#" ierr = 1 ! not zero do while (.not.(chmess1 == "#" .and. ierr ==0)) !search for the next line consisting of "# time", from there onwards the profiles will be read read(ifinput,*,iostat=ierr) chmess1,timenudge(t) if (ierr < 0) exit readloop end do ! DAN ! write(6,*) ' height t_nudge u_nudge v_nudge w_nudge thl_nudge qt_nudge' ! read (ifinput,*) lowheight , lowtnudge , lowunudge , lowvnudge , lowwnudge , lowthlnudge, lowqtnudge ! read (ifinput,*) highheight , hightnudge , highunudge , highvnudge , highwnudge , highthlnudge, highqtnudge write(6,*) ' height t_nudge tuv_nudge u_nudge v_nudge w_nudge thl_nudge qt_nudge' read (ifinput,*) lowheight , lowtnudge , lowtuvnudge , lowunudge , lowvnudge , lowwnudge , lowthlnudge, lowqtnudge read (ifinput,*) highheight , hightnudge , hightuvnudge , highunudge , highvnudge , highwnudge , highthlnudge, highqtnudge do k=2,nzp-1 ! Christopher: bug fix (analog in modtimedep.f90) !if (highheight<zt(k)) then ! lowheight = highheight ! lowtnudge = hightnudge ! lowunudge = highunudge ! lowvnudge = highvnudge ! lowwnudge = highwnudge ! lowthlnudge= highthlnudge ! lowqtnudge=highqtnudge ! read (ifinput,*) highheight , hightnudge , highunudge , highvnudge , highwnudge , highthlnudge, highqtnudge !end if do if (highheight>=zt(k)) exit lowheight = highheight lowtnudge = hightnudge lowtuvnudge = hightuvnudge ! DAN lowunudge = highunudge lowvnudge = highvnudge lowwnudge = highwnudge lowthlnudge= highthlnudge lowqtnudge=highqtnudge ! DAN ! read (ifinput,*) highheight , hightnudge , highunudge , highvnudge , highwnudge , highthlnudge, highqtnudge read (ifinput,*) highheight , hightnudge , hightuvnudge , highunudge , highvnudge , highwnudge , highthlnudge, highqtnudge end do fac = (highheight-zt(k))/(highheight - lowheight) tnudge(k,t) = fac*lowtnudge + (1-fac)*hightnudge tuvnudge(k,t) = fac*lowtuvnudge + (1.-fac)*hightuvnudge ! DAN unudge(k,t) = fac*lowunudge + (1-fac)*highunudge vnudge(k,t) = fac*lowvnudge + (1-fac)*highvnudge wnudge(k,t) = fac*lowwnudge + (1-fac)*highwnudge thlnudge(k,t) = fac*lowthlnudge + (1-fac)*highthlnudge qtnudge(k,t) = fac*lowqtnudge + (1-fac)*highqtnudge end do if (myid == 0) then do k=nzp-1,1,-1 write (6,'(2f10.1,6e12.4)') & zt (k), & height (k), & tnudge (k,t), & tuvnudge(k,t), & ! DAN unudge (k,t), & vnudge (k,t), & wnudge (k,t), & thlnudge(k,t), & qtnudge(k,t) end do end if end do readloop close(ifinput) if (znudgemin>0) then do k = 1,nzp-1 if (zt(k)<=znudgemin) then tnudge(k,:) = 1e10 else if (zt(k)<=znudgeplus) then tnudge(k,:) = 2.*tnudgefac/(1-cos(pi*(zt(k)-znudgemin)/(znudgeplus-znudgemin))) else tnudge(k,:) = tnudgefac end if end do else tnudge = tnudgefac*tnudge end if thlnudge = thlnudge - th00 unudge = unudge - umean vnudge = vnudge - vmean lunudge = any(abs(unudge)>1e-8) lvnudge = any(abs(vnudge)>1e-8) lwnudge = any(abs(wnudge)>1e-8) lthlnudge = any(abs(thlnudge)>1e-8) lqtnudge = any(abs(qtnudge)>1e-8) end subroutine initnudge !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine nudge(timein) use grid, only : dt, nxp, nyp, nzp, a_ut, a_vt, a_wt, a_tt, a_rt, a_up,a_vp,a_tp,a_rp,zt,a_wp use util, only : get_avg3 implicit none real, intent (in) :: timein integer k,t,i,j real :: dtm,dtp,currtnudge, nudgefac real, dimension(nzp) :: uav, vav, tav, qav if (firsttime) then firsttime = .false. call initnudge(timein) end if if (.not.(lnudge)) return t=1 do while(timein>timenudge(t)) t=t+1 end do if (timein/=timenudge(1)) then t=t-1 end if dtm = ( timein-timenudge(t) ) / ( timenudge(t+1)-timenudge(t) ) dtp = ( timenudge(t+1)-timein)/ ( timenudge(t+1)-timenudge(t) ) call get_avg3(nzp, nxp, nyp,a_up,uav) call get_avg3(nzp, nxp, nyp,a_vp,vav) call get_avg3(nzp, nxp, nyp,a_tp,tav) call get_avg3(nzp, nxp, nyp,a_rp,qav) do j=3,nyp-2 do i=3,nxp-2 do k=2,nzp-1 ! DAN ! currtnudge = max(dt,tnudge(k,t)*dtp+tnudge(k,t+1)*dtm) currtnudge = max(dt,tuvnudge(k,t)*dtp+tuvnudge(k,t+1)*dtm) if(lunudge ) a_ut(k,i,j)=a_ut(k,i,j)-& (uav(k)-(unudge (k,t)*dtp+unudge (k,t+1)*dtm))/currtnudge if(lvnudge ) a_vt(k,i,j)=a_vt(k,i,j)-& (vav(k)-(vnudge (k,t)*dtp+vnudge (k,t+1)*dtm))/currtnudge end do end do end do do j=3,nyp-2 do i=3,nxp-2 do k=2,nzp-1 currtnudge = max(dt,tnudge(k,t)*dtp+tnudge(k,t+1)*dtm) if(lthlnudge ) a_tt(k,i,j)=a_tt(k,i,j)-& (tav(k) - (thlnudge (k,t)*dtp+thlnudge (k,t+1)*dtm))/currtnudge if(lqtnudge ) then if (qav(k) < qfloor .and. zt(k) < zfloor) then nudgefac = qfloor ! currtnudge = 3600. else nudgefac = qtnudge (k,t)*dtp+qtnudge (k,t+1)*dtm end if a_rt(k,i,j)= a_rt(k,i,j) - (qav(k)-nudgefac)/currtnudge end if end do end do end do end subroutine nudge ! LINDA, b !--------------------------------------------------------------------------! !This routine nudges simulated values of temperature, humidity ! !and horizontal and vertical wind speed back to their initial state at a ! !time scale tau. The nudging is only done in a small zone at the Eastern ! !and Western edge of the domain. ! !The effect of the nudging is to obtain relaxation boundary conditions ! !which can e.g. be used to model the development of a squall line ! ! ! ! Linda Schlemmer, December 2011 ! !--------------------------------------------------------------------------! subroutine nudge_bound use grid, only: nxp,nyp,nzp,a_tt,a_tp,a_rt,a_rp,& a_ut,a_up,a_vt,a_vp,a_wt,a_wp,liquid use mpi_interface, only : myid IMPLICIT NONE integer:: k,t,i,j if (firsttime) then firsttime = .false. allocate(rlx(nxp,nyp)) allocate(tn(nzp),rn(nzp),un(nzp),vn(nzp),wn(nzp)) rlx(:,:)=0.0 call initnudge_bound end if ! relax towards initial conditions do k=1,nzp do i=1,nxp do j=1,nyp a_tt(k,i,j)=a_tt(k,i,j)-(a_tp(k,i,j)-tn(k))*coef*rlx(i,j) a_rt(k,i,j)=a_rt(k,i,j)-(a_rp(k,i,j)-rn(k))*coef*rlx(i,j) a_ut(k,i,j)=a_ut(k,i,j)-(a_up(k,i,j)-un(k))*coef*rlx(i,j) a_vt(k,i,j)=a_vt(k,i,j)-(a_vp(k,i,j)-vn(k))*coef*rlx(i,j) a_wt(k,i,j)=a_wt(k,i,j)-(a_wp(k,i,j)-wn(k))*coef*rlx(i,j) enddo enddo enddo end subroutine nudge_bound !-------------------------------------------------------------------------- subroutine initnudge_bound use mpi_interface, only : myid,nxprocs,nyprocs use grid, only: nxp,nyp,nzp,a_tp,a_rp,a_up,a_vp,a_wp,deltax use defs, only: pi IMPLICIT NONE integer k,t,i,j real::eps=0.01 integer:: nnudge ! number of points where relaxation is done real:: xnudge ! relaxation zone [km], to be tested real:: rnudge ! relaxation zone [points] logical::flg flg=.false. xnudge=10.0 rnudge=xnudge*1000.0/deltax nnudge=int(rnudge) if (nnudge>nxp) flg=.true. ! western boundary if (mod(myid,nxprocs)<eps) then print*,'western boundary, myid=',myid if (flg) nnudge=nxp do i=1,nnudge ! rlx(i,:)=1.0 ! step function rlx(i,:)=(cos(real(i)*pi/(rnudge*2)))**2!cos2-function enddo endif ! relaxation zone extends over more than one processor if ((myid>0).and.(mod(myid-1,nxprocs)<eps).and.(flg)) then print*,'western boundary, 2nd proc, myid=',myid do i=1,nnudge-nxp+4 ! rlx(i,:)=1.0 ! step function rlx(i,:)=(cos(real(i+nxp-4)*pi/(rnudge*2)))**2!cos2-function enddo endif ! eastern boundary if (mod(myid+1,nxprocs)<eps) then print*,'eastern boundary, myid=',myid if (flg) nnudge=nxp do i=nxp-nnudge+1,nxp ! rlx(i,:)=1.0! step function rlx(i,:)=(cos(real(nxp-i+1)*pi/(rnudge*2)))**2!cos2-function enddo endif ! relaxation zone extends over more than one processor if ((mod(myid+2,nxprocs)<eps).and.(flg)) then print*,'eastern boundary, 2nd proc, myid=',myid do i=2*nxp-nnudge+1-4,nxp ! rlx(i,:)=1.0 ! step function rlx(i,:)=(cos(real(2*nxp-i+1-4)*pi/(rnudge*2)))**2!cos2-function enddo endif ! read in/save initial conditions do k=1,nzp tn(k)=a_tp(k,3,3) rn(k)=a_rp(k,3,3) un(k)=a_up(k,3,3) vn(k)=a_vp(k,3,3) wn(k)=0.0 enddo end subroutine initnudge_bound ! LINDA, e end module
gpl-3.0
yangf4/phasta
M2NFixBnd/src/commuMax.f
5
9995
subroutine commuMax (global, ilwork, n, code) c--------------------------------------------------------------------- c c This subroutine is responsible for interprocessor communication of c the residual and solution vectors. c c input: c global(nshg,n): global vector to be communicated. Note that c this vector is local to the processor, (i.e. c not distributed across processors) c ilwork(nlwork): this is the local interprocessor work array. c This array is local to the processor, (i.e. c each processor has a unique ilwork array. c n: second dimension of the array to be communicated c code: = 'in' for communicating with the residual c = 'out' for cummunicating the solution c c--------------------------------------------------------------------- c c The array ilwork describes the details of the communications. c Each communication step (call of this routine) consists of a c sequence of "tasks", where a task is defined as a communication c between two processors where data is exchanged. This would imply c that for a given processor, there will be as many tasks as there c are processors with which it must communicate. Details of the c ilwork array appear below. c c--------------------------------------------------------------------- c include "commonM2NFixBnd.h" include "mpif.h" include "auxmpiM2NFixBnd.h" integer status(MPI_STATUS_SIZE), ierr integer stat(MPI_STATUS_SIZE, 2*maxtask), req(2*maxtask) real*8 rDelISend, rDelIRecv, rDelWaitAll dimension global(nshg,n), & rtemp(maxfront*n,maxtask), & ilwork(nlwork) character*3 code if(impistat2.eq.1) call MPI_BARRIER (MPI_COMM_WORLD, ierr) if(impistat.eq.1) rDelIRecv = zero if(impistat.eq.1) rDelISend = zero if(impistat.eq.1) rDelWaitAll = zero if (code .ne. 'in ' .and. code .ne. 'out') & call error ('commu ','code ',0) if (n .eq. 1) then ! like a scalar kdof = 1 elseif (n .eq. nsd) then ! like the normal vectors kdof = 2 elseif (n .eq. ndof) then ! res, y, ac, krylov vectors.... kdof = 3 elseif (n .eq. nflow*nflow) then ! bdiag kdof = 4 elseif (n .eq. (nflow-1)*nsd) then ! qres kdof = 5 elseif (n .eq. nflow) then kdof = 6 elseif (n .eq. 24 ) then kdof = 7 elseif (n .eq. 9) then kdof = 8 elseif (n .eq. 11 ) then kdof = 9 elseif (n .eq. 7 ) then kdof = 10 ! elseif (n .eq. 33 ) then ! hack elseif (n .eq. 13 ) then ! for error kdof = 11 ! elseif (n .eq. 22 ) then elseif (n .eq. 17 ) then kdof = 12 elseif (n .eq. 16 ) then kdof = 13 elseif (n .eq. 10 ) then kdof = 14 elseif (n .eq. nflow*nsd ) then !surface tension + qres kdof = 15 else call error ('commuMax','n ',n) endif c... Note that when adding another kdof to the above set, we must c... also make changes in ctypes.f and auxmpi.h c--------------------------------------------------------------------- c ilwork(1): number of tasks c c The following information is contained in ilwork for each task: c itag: tag of the communication c iacc: == 0 if task is a send c == 1 if task is a recieve c iother: rank of processor with which this communication occurs c numseg: number of data "segments" to be sent or recieved. A c segment is defined as a continuous section of the global c vector to be communicated, (i.e. a group of nodes (or, c rather, "shape function coefficients") which occur c sequentially in the array global(nshg,n)). c isbeg: location of the first segment in the array owned by the c current processor. c c The two types of communication are 'in', where the residual is being c communicated, and 'out', where the solution is being communicated. c Note that when the type is 'out', senders recieve and recievers send. c c The following comment pertains to a communication of type 'in': c c If the task is a send, then all of the numseg segments are c sent with a single call to MPI_SEND. Where these segments live in c the array is built into the array sevsegtype, which is a common c array constructed in the subroutine "ctypes.f". In other words, c sevsegtype is a data type that describes the indices of the blocks c to be sent, in terms of there beginning index, and the length of c each segment. Using this, we can make a single send to take care of c all the segments for this task. c c If the task is a recieve, then once the vector is recieved, the c recieved segments must be added to the correct locations in the c current array. These locations are described in ilwork as the c beginning position, then the length of the segment. c c--------------------------------------------------------------------- numtask = ilwork(1) itkbeg = 1 m = 0 idl=0 DO itask = 1, numtask m = m + 1 itag = ilwork (itkbeg + 1) iacc = ilwork (itkbeg + 2) iother = ilwork (itkbeg + 3) numseg = ilwork (itkbeg + 4) isgbeg = ilwork (itkbeg + 5) c c.... if iacc == 0, then this task is a send. c slave c if (iacc .EQ. 0) then c c.... residual communication c if (code .eq. 'in ') then if(impistat.eq.1) iISend = iISend+1 if(impistat.eq.1) rmpitmr = TMRC() call MPI_ISEND(global(isgbeg, 1), 1, sevsegtype(itask,kdof), & iother, itag, MPI_COMM_WORLD, req(m), ierr) if(impistat.eq.1) rDelISend = TMRC()-rmpitmr if(impistat.eq.1) rISend = rISend+rDelISend endif c c.... solution communication c if (code .eq. 'out') then if(impistat.eq.1) iIRecv = iIRecv+1 if(impistat.eq.1) rmpitmr = TMRC() call MPI_IRECV(global(isgbeg, 1), 1, sevsegtype(itask,kdof), & iother, itag, MPI_COMM_WORLD, req(m), ierr) if(impistat.eq.1) rDelIRecv = TMRC()-rmpitmr if(impistat.eq.1) rIRecv = rIRecv+rDelIRecv endif c c.... if iacc == 1, then this task is a recieve. c master c else if (code .eq. 'in ') then c c.... determine the number of total number of nodes involved in this c communication (lfront), including all segments c lfront = 0 do is = 1,numseg lenseg = ilwork (itkbeg + 4 + 2*is) lfront = lfront + lenseg enddo c c.... recieve all segments for this task in a single step c idl=idl+1 ! stands for i Do Later, the number to fix later if(impistat.eq.1) iIRecv = iIRecv+1 if(impistat.eq.1) rmpitmr = TMRC() call MPI_IRECV(rtemp(1,idl), lfront*n, MPI_DOUBLE_PRECISION, & iother, itag, MPI_COMM_WORLD, req(m), ierr) if(impistat.eq.1) rDelIRecv = TMRC()-rmpitmr if(impistat.eq.1) rIRecv = rIRecv+rDelIRecv endif if (code .eq. 'out') then if(impistat.eq.1) iISend = iISend+1 if(impistat.eq.1) rmpitmr = TMRC() call MPI_ISEND(global(isgbeg, 1), 1, sevsegtype(itask,kdof), & iother, itag, MPI_COMM_WORLD, req(m), ierr) if(impistat.eq.1) rDelISend = TMRC()-rmpitmr if(impistat.eq.1) rISend = rISend+rDelISend endif endif itkbeg = itkbeg + 4 + 2*numseg enddo !! end tasks loop if(impistat.eq.1) iWaitAll = iWaitAll+1 if(impistat.eq.1) rmpitmr = TMRC() call MPI_WAITALL(m, req, stat, ierr) if(impistat.eq.1) rDelWaitAll = TMRC()-rmpitmr if(impistat.eq.1) rWaitAll = rWaitAll+rDelWaitAll if(impistat.eq.1) rCommu = rCommu+rDelIRecv+rDelISend+rDelWaitAll c c Stuff added below is a delayed assembly of that which was communicated c above but due to the switch to non-blocking receivves could not be c assembled until after the waitall. Only necessary for commu "in" c if(code .eq. 'in ') then itkbeg=1 jdl=0 do j=1,numtask ! time to do all the segments that needed to be ! assembled into the global vector iacc = ilwork (itkbeg + 2) numseg = ilwork (itkbeg + 4) isgbeg = ilwork (itkbeg + 5) if(iacc.eq.1) then jdl=jdl+1 ! keep track of order of rtemp's c c... add the recieved data to the global array on the current processor. c Note that this involves splitting up the chunk of recieved data c into its correct segment locations for the current processor. c itemp = 1 do idof = 1,n do is = 1,numseg isgbeg = ilwork (itkbeg + 3 + 2*is) lenseg = ilwork (itkbeg + 4 + 2*is) isgend = isgbeg + lenseg - 1 c global(isgbeg:isgend,idof) = global(isgbeg:isgend,idof) c & + rtemp (itemp:itemp+lenseg-1,jdl) do k=isgbeg,isgend ! break this into an explicit loop an max instead of accumulate global(k,idof) = max(global(k,idof),rtemp (itemp,jdl)) itemp=itemp+1 ! advance this index one at a time instead of in lenseg jumps enddo c itemp = itemp + lenseg enddo enddo endif ! end of receive (iacc=1) itkbeg = itkbeg + 4 + 2*numseg enddo endif ! commu "in" return end
bsd-3-clause
kbai/specfem3d
utils/ADJOINT_TOMOGRAPHY_TOOLS/iterate_adj/SEM2D_iterate/gji_paper/codes_18_06Aug2006/wave2d_constants.f90
7
6934
module wave2d_constants ! ! GRID, TIME-STEP, AND SOURCE PARAMETERS ! ! NFRAME : number of frames to save ! NSAVE : timestep increment to save the wavefield ! NSTEP : number of timesteps integer, parameter :: NFRAME = 10 ! 10,12,17 integer, parameter :: NSAVE = 400 ! 400 integer, parameter :: NSTEP = NFRAME*NSAVE ! time step in seconds double precision, parameter :: DT = 6.0d-02 ! (0.02) ! temporal properties of source (source time function) integer, parameter :: ISRC_TIME = 1 ! type (1) double precision, parameter :: hdur = 10.0 ! HALF-duration (s) double precision, parameter :: tshift = 2.*DT*NSAVE ! time shift (s) !double precision, parameter :: tshift = 8.*hdur logical, parameter :: SRC_TAPER = .true. ! spatial properties of sources ! (1) point source, (2) finite segment, (3) CA shelf boundary, (4) CA coast, (5) finite circle ! (6) a point source EVENT integer, parameter :: ISRC_SPACE = 6 ! see wave2d.f90 ! spatial properties of receivers ! IREC_SPACE ! (1) individual station(s) ! (2) SoCal (used for GJI paper) ! (3) regular mesh on land ! (4) regular mesh ! NMESH_REC : determines the number of receivers in a regular mesh (IREC_SPACE=3) ! STATION_GRID_BUFFER : exclude stations within this distance from edge of grid ! STATION_COAST_BUFFER : exclude stations within this distance from edge of coast integer, parameter :: IREC_SPACE = 2 ! see wave2d.f90 integer, parameter :: NMESH_REC = 10 double precision, parameter :: SOURCE_GRID_BUFFER = 4.0d+03 ! m double precision, parameter :: STATION_GRID_BUFFER = 15.0d+03 ! m double precision, parameter :: STATION_COAST_BUFFER = 0.0d+03 ! m ! model specification for c(th,ph) ! (0) het map, (1) homo map, (2) checkerboard, (3) read in !integer, parameter :: IMODEL = 3 ! bounds for bandpass filter (in seconds), see also below (fmin,etc) double precision, parameter :: hwid = 3.0 ! HALF-width of window double precision, parameter :: tmin = 2.*hdur-hwid double precision, parameter :: tmax = 2.*hdur+hwid ! mesh specifications double precision, parameter :: LENGTH = 480.0d+03 ! m (200) double precision, parameter :: HEIGHT = 480.0d+03 ! m (80) integer, parameter :: NEX = 40 !40 integer, parameter :: NEZ = 40 !40 double precision, parameter :: LAT_MIN = 32.0d0 double precision, parameter :: LON_MIN = -120.d0 ! boolean parameters ! IKER: (0) waveform ! (1) traveltime, cross-correlation, misfit ! (2) amplitude, cross-correlation, misfit ! (3) traveltime, multitaper ! (4) amplitude, multitaper ! (5) traveltime, cross-correlation, sampling ! (6) amplitude, cross-correlation, sampling integer, parameter :: IKER = 1 integer, parameter :: ISURFACE = 1, NCOMP = 1, NABSORB = 4 ! surface waves ! integer, parameter :: ISURFACE = 0, NCOMP = 3, NABSORB = 3 ! body waves ! iteration and smoothing parameters ! logical, parameter :: IUPDATE = .false. integer, parameter :: NITERATION = 0 integer, parameter :: POLY_ORDER = 2 ! 2 (equally good) or 3 !double precision, parameter :: SIGMA = 10.0d+03 ! m ! parameters controlling what to write to file ! NOTE: for the tomography simulations, ALL of these can be .false. logical, parameter :: WRITE_STF_F = .false. logical, parameter :: WRITE_SEISMO_F = .false. ! true logical, parameter :: WRITE_SPECTRA_F = .false. logical, parameter :: WRITE_SPECTRAL_MAP_F = .false. logical, parameter :: WRITE_STF_A = .false. logical, parameter :: WRITE_SEISMO_A = .false. logical, parameter :: WRITE_SPECTRA_A = .false. logical, parameter :: WRITE_SPECTRAL_MAP_A = .false. logical, parameter :: WRITE_KERNELS = .false. ! kernel snapshots logical, parameter :: WRITE_SNAPSHOTS = .false. ! wavefield snapshots ! MODEL (S.I. units) double precision, parameter :: DENSITY = 2.6d+03 ! kg/m^3 double precision, parameter :: INCOMPRESSIBILITY = 5.2d+10 ! Pa double precision, parameter :: RIGIDITY = 2.66d+10 ! Pa !--------------------------------------------------------------- ! CHT: do not change these ! UTM zone for Southern California region ! integer, parameter :: UTM_PROJECTION_ZONE = 11 ! to suppress UTM projection for SCEC benchmarks logical, parameter :: SUPPRESS_UTM_PROJECTION = .false. ! flag for projection from latitude/longitude to UTM, and back integer, parameter :: ILONGLAT2UTM = 0, IUTM2LONGLAT = 1 ! flag for projection from latitude/longitude to mesh-UTM, and back integer, parameter :: ILONLAT2MESH = 0, IMESH2LONLAT = 1 ! max number of fake receivers integer, parameter :: MAX_SR_FAKE = 1000 ! max number of events, receivers, and phass integer, parameter :: MAX_EVENT = 50 integer, parameter :: MAX_SR = 1400 integer, parameter :: MAX_PHASE = 1 integer, parameter :: MAX_COMP = NCOMP ! parameter for FFTW integer, parameter :: NOUT = NSTEP/2 + 1 ! filter parameters for bandpass double precision, parameter :: fmin = 1./tmax, fmax = 1./tmin double precision, parameter :: trbdndw = 0.3, a = 30. integer, parameter :: passes = 2, iord = 4 !--------------------------------------------------------------- ! ! GRID AND GLL POINTS ! integer, parameter :: NELE = MAX(NEX,NEZ) integer, parameter :: NSPEC = NEX*NEZ ! number of GLL points (polynomial degree plus one) integer, parameter :: NGLLX = 5 integer, parameter :: NGLLZ = 5 integer, parameter :: NGLL = MAX(NGLLX,NGLLZ) ! number of points per surface element integer, parameter :: NGLLSQUARE = NGLLX * NGLLZ ! number of global points integer, parameter :: NGLOB = ((NGLLX-1)*NEX + 1)*((NGLLZ-1)*NEZ +1) ! number of local points integer, parameter :: NLOCAL = NGLLX * NGLLZ * NSPEC ! number of nodes for 2D and 3D shape functions for hexahedra ! we use 8-node mesh bricks, which are more stable than 27-node elements integer, parameter :: NGNOD = 8, NGNOD2D = 4 ! number of iterations to solve the system for xi and eta integer, parameter :: NUM_ITER = 1 ! very large and very small values double precision, parameter :: HUGEVAL = 1.d+30, TINYVAL = 1.d-9 ! for the Gauss-Lobatto-Legendre points and weights double precision, parameter :: GAUSSALPHA = 0.d0,GAUSSBETA = 0.d0 ! ! CONSTANTS ! ! pi double precision, parameter :: PI = 3.141592653589793d+00 double precision, parameter :: FOUR_THIRDS = 4.d0/3.d0 double precision, parameter :: ONE_THIRD = 1.d0/3.d0 double precision, parameter :: ONEOVERTWO = 0.5d0 double precision, parameter :: EPS = 1.0d-35 double precision, parameter :: DEG = 180./PI ! normalization factor of point source force double precision, parameter :: FNORM = 1.0d10 ! factors from the multitaper method integer, parameter :: MAXTAPER=5, NDIM=8000*4, lnpt=14, npt=2**lnpt double precision, parameter :: wtr=0.02, ZZIGN=-1.0 end module wave2d_constants
gpl-2.0
skywalker00/sabermod_rom_toolchain
gcc/testsuite/gfortran.dg/interface_3.f90
155
1587
! { dg-do compile } ! Tests the fix for PR20880, which was due to failure to the failure ! to detect the USE association of a nameless interface for a ! procedure with the same name as the encompassing scope. ! ! Contributed by Joost VandeVondele <jv244@cam.ac.uk> ! ! Modified for PR fortran/34657 ! module test_mod interface subroutine my_sub (a) real a end subroutine end interface interface function my_fun (a) real a, my_fun end function end interface end module module test_mod2 interface function my_fun (a) real a, my_fun end function end interface end module ! This is the original PR, excepting that the error requires the symbol ! to be referenced. subroutine my_sub (a) use test_mod ! { dg-error "is also the name of the current program unit" } real a call my_sub (a) ! { dg-error "ambiguous reference" } print *, a end subroutine integer function my_fun (a) use test_mod ! { dg-error "is also the name of the current program unit" } real a print *, a my_fun = 1 ! { dg-error "ambiguous reference" } end function ! This was found whilst investigating => segfault subroutine thy_sub (a) interface subroutine thy_sub (a) ! { dg-error "enclosing procedure" } real a end subroutine end interface real a print *, a end subroutine subroutine thy_fun (a) use test_mod use test_mod2 ! OK because there is no reference to my_fun print *, a end subroutine thy_fun subroutine his_fun (a) use test_mod use test_mod2 print *, my_fun (a) ! { dg-error "ambiguous reference" } end subroutine his_fun
gpl-2.0
skywalker00/sabermod_rom_toolchain
gcc/testsuite/gfortran.dg/implicit_2.f90
157
1088
! { dg-do compile } module implicit_2 ! This should cause an error if function types are resolved from the ! module namespace. implicit none type t integer i end type contains ! This caused an ICE because we were trying to apply the implicit type ! after we had applied the explicit type. subroutine test() implicit type (t) (v) type (t) v1, v2 v1%i = 1 call foo (v2%i) end subroutine ! A similar error because we failed to apply the implicit type to a function. ! This is a contained function to check we lookup the type in the function ! namespace, not it's parent. function f() result (val) implicit type (t) (v) val%i = 1 end function ! And again for a result variable. function fun() implicit type (t) (f) fun%i = 1 end function ! intrinsic types are resolved later than derived type, so check those as well. function test2() implicit integer (t) test2 = 42 end function subroutine bar() ! Check that implicit types are applied to names already known to be ! variables. implicit type(t) (v) save v v%i = 42 end subroutine end module
gpl-2.0
skywalker00/sabermod_rom_toolchain
gcc/testsuite/gfortran.dg/aliasing_array_result_1.f90
136
3787
! { dg-do run } ! Tests the fic for PR44582, where gfortran was found to ! produce an incorrect result when the result of a function ! was aliased by a host or use associated variable, to which ! the function is assigned. In these cases a temporary is ! required in the function assignments. The check has to be ! rather restrictive. Whilst the cases marked below might ! not need temporaries, the TODOs are going to be tough. ! ! Reported by Yin Ma <yin@absoft.com> and ! elaborated by Tobias Burnus <burnus@gcc.gnu.org> ! module foo INTEGER, PARAMETER :: ONE = 1 INTEGER, PARAMETER :: TEN = 10 INTEGER, PARAMETER :: FIVE = TEN/2 INTEGER, PARAMETER :: TWO = 2 integer :: foo_a(ONE) integer :: check(ONE) = TEN LOGICAL :: abort_flag = .false. contains function foo_f() integer :: foo_f(ONE) foo_f = -FIVE foo_f = foo_a - foo_f end function foo_f subroutine bar foo_a = FIVE ! This aliases 'foo_a' by host association. foo_a = foo_f () if (any (foo_a .ne. check)) call myabort (0) end subroutine bar subroutine myabort(fl) integer :: fl print *, fl abort_flag = .true. end subroutine myabort end module foo function h_ext() use foo integer :: h_ext(ONE) h_ext = -FIVE h_ext = FIVE - h_ext end function h_ext function i_ext() result (h) use foo integer :: h(ONE) h = -FIVE h = FIVE - h end function i_ext subroutine tobias use foo integer :: a(ONE) a = FIVE call sub1(a) if (any (a .ne. check)) call myabort (1) contains subroutine sub1(x) integer :: x(ONE) ! 'x' is aliased by host association in 'f'. x = f() end subroutine sub1 function f() integer :: f(ONE) f = ONE f = a + FIVE end function f end subroutine tobias program test use foo implicit none common /foo_bar/ c integer :: a(ONE), b(ONE), c(ONE), d(ONE) interface function h_ext() use foo integer :: h_ext(ONE) end function h_ext end interface interface function i_ext() result (h) use foo integer :: h(ONE) end function i_ext end interface a = FIVE ! This aliases 'a' by host association a = f() if (any (a .ne. check)) call myabort (2) a = FIVE if (any (f() .ne. check)) call myabort (3) call bar foo_a = FIVE ! This aliases 'foo_a' by host association. foo_a = g () if (any (foo_a .ne. check)) call myabort (4) a = FIVE a = h() ! TODO: Needs no temporary if (any (a .ne. check)) call myabort (5) a = FIVE a = i() ! TODO: Needs no temporary if (any (a .ne. check)) call myabort (6) a = FIVE a = h_ext() ! Needs no temporary - was OK if (any (a .ne. check)) call myabort (15) a = FIVE a = i_ext() ! Needs no temporary - was OK if (any (a .ne. check)) call myabort (16) c = FIVE ! This aliases 'c' through the common block. c = j() if (any (c .ne. check)) call myabort (7) call aaa call tobias if (abort_flag) call abort contains function f() integer :: f(ONE) f = -FIVE f = a - f end function f function g() integer :: g(ONE) g = -FIVE g = foo_a - g end function g function h() integer :: h(ONE) h = -FIVE h = FIVE - h end function h function i() result (h) integer :: h(ONE) h = -FIVE h = FIVE - h end function i function j() common /foo_bar/ cc integer :: j(ONE), cc(ONE) j = -FIVE j = cc - j end function j subroutine aaa() d = TEN - TWO ! This aliases 'd' through 'get_d'. d = bbb() if (any (d .ne. check)) call myabort (8) end subroutine aaa function bbb() integer :: bbb(ONE) bbb = TWO bbb = bbb + get_d() end function bbb function get_d() integer :: get_d(ONE) get_d = d end function get_d end program test
gpl-2.0
khsk2/inc3d
io_diagp.f90
1
27717
!======================================================================= ! This is part of the 2DECOMP&FFT library ! ! 2DECOMP&FFT is a software framework for general-purpose 2D (pencil) ! decomposition. It also implements a highly scalable distributed ! three-dimensional Fast Fourier Transform (FFT). ! ! Copyright (C) 2009-2013 Ning Li, the Numerical Algorithms Group (NAG) ! !======================================================================= ! This module provides parallel IO facilities for applications based on ! 2D decomposition. module decomp_2d_io use decomp_2d use MPI #ifdef T3PIO use t3pio #endif implicit none private ! Make everything private unless declared public public :: decomp_2d_write_one, decomp_2d_read_one, & decomp_2d_write_var, decomp_2d_read_var, & decomp_2d_write_scalar, decomp_2d_read_scalar, & decomp_2d_write_plane, decomp_2d_write_every, & decomp_2d_write_subdomain ! Generic interface to handle multiple data types interface decomp_2d_write_one module procedure write_one_real module procedure write_one_complex module procedure mpiio_write_real_coarse end interface decomp_2d_write_one interface decomp_2d_read_one module procedure read_one_real module procedure read_one_complex end interface decomp_2d_read_one interface decomp_2d_write_var module procedure write_var_real module procedure write_var_complex end interface decomp_2d_write_var interface decomp_2d_read_var module procedure read_var_real module procedure read_var_complex end interface decomp_2d_read_var interface decomp_2d_write_scalar module procedure write_scalar_real module procedure write_scalar_complex module procedure write_scalar_integer module procedure write_scalar_logical end interface decomp_2d_write_scalar interface decomp_2d_read_scalar module procedure read_scalar_real module procedure read_scalar_complex module procedure read_scalar_integer module procedure read_scalar_logical end interface decomp_2d_read_scalar interface decomp_2d_write_plane module procedure write_plane_3d_real module procedure write_plane_3d_complex ! module procedure write_plane_2d end interface decomp_2d_write_plane interface decomp_2d_write_every module procedure write_every_real module procedure write_every_complex end interface decomp_2d_write_every interface decomp_2d_write_subdomain module procedure write_subdomain end interface decomp_2d_write_subdomain contains !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Using MPI-IO library to write a single 3D array to a file !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine write_one_real(ipencil,var,filename,opt_decomp) implicit none integer, intent(IN) :: ipencil real(mytype), dimension(:,:,:), intent(IN) :: var character(len=*), intent(IN) :: filename TYPE(DECOMP_INFO), intent(IN), optional :: opt_decomp TYPE(DECOMP_INFO) :: decomp integer(kind=MPI_OFFSET_KIND) :: filesize, disp integer, dimension(3) :: sizes, subsizes, starts integer :: ierror, newtype, fh, data_type, info, gs data_type = real_type #include "io_write_one.f90" return end subroutine write_one_real subroutine write_one_complex(ipencil,var,filename,opt_decomp) implicit none integer, intent(IN) :: ipencil complex(mytype), dimension(:,:,:), intent(IN) :: var character(len=*), intent(IN) :: filename TYPE(DECOMP_INFO), intent(IN), optional :: opt_decomp TYPE(DECOMP_INFO) :: decomp integer(kind=MPI_OFFSET_KIND) :: filesize, disp integer, dimension(3) :: sizes, subsizes, starts integer :: ierror, newtype, fh, data_type, info, gs data_type = complex_type #include "io_write_one.f90" return end subroutine write_one_complex !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Using MPI-IO library to read from a file a single 3D array !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine read_one_real(ipencil,var,filename,opt_decomp) implicit none integer, intent(IN) :: ipencil real(mytype), dimension(:,:,:), intent(INOUT) :: var character(len=*), intent(IN) :: filename TYPE(DECOMP_INFO), intent(IN), optional :: opt_decomp TYPE(DECOMP_INFO) :: decomp integer(kind=MPI_OFFSET_KIND) :: disp integer, dimension(3) :: sizes, subsizes, starts integer :: ierror, newtype, fh, data_type data_type = real_type #include "io_read_one.f90" return end subroutine read_one_real subroutine read_one_complex(ipencil,var,filename,opt_decomp) implicit none integer, intent(IN) :: ipencil complex(mytype), dimension(:,:,:), intent(INOUT) :: var character(len=*), intent(IN) :: filename TYPE(DECOMP_INFO), intent(IN), optional :: opt_decomp TYPE(DECOMP_INFO) :: decomp integer(kind=MPI_OFFSET_KIND) :: disp integer, dimension(3) :: sizes, subsizes, starts integer :: ierror, newtype, fh, data_type data_type = complex_type #include "io_read_one.f90" return end subroutine read_one_complex !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Write a 3D array as part of a big MPI-IO file, starting from ! displacement 'disp'; 'disp' will be updated after the writing ! operation to prepare the writing of next chunk of data. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine write_var_real(fh,disp,ipencil,var,opt_decomp) implicit none integer, intent(IN) :: fh integer(KIND=MPI_OFFSET_KIND), intent(INOUT) :: disp integer, intent(IN) :: ipencil real(mytype), dimension(:,:,:), intent(IN) :: var TYPE(DECOMP_INFO), intent(IN), optional :: opt_decomp TYPE(DECOMP_INFO) :: decomp integer, dimension(3) :: sizes, subsizes, starts integer :: ierror, newtype, data_type data_type = real_type #include "io_write_var.f90" return end subroutine write_var_real subroutine write_var_complex(fh,disp,ipencil,var,opt_decomp) implicit none integer, intent(IN) :: fh integer(KIND=MPI_OFFSET_KIND), intent(INOUT) :: disp integer, intent(IN) :: ipencil complex(mytype), dimension(:,:,:), intent(IN) :: var TYPE(DECOMP_INFO), intent(IN), optional :: opt_decomp TYPE(DECOMP_INFO) :: decomp integer, dimension(3) :: sizes, subsizes, starts integer :: ierror, newtype, data_type data_type = complex_type #include "io_write_var.f90" return end subroutine write_var_complex !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Read a 3D array as part of a big MPI-IO file, starting from ! displacement 'disp'; 'disp' will be updated after the reading ! operation to prepare the reading of next chunk of data. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine read_var_real(fh,disp,ipencil,var,opt_decomp) implicit none integer, intent(IN) :: fh integer(KIND=MPI_OFFSET_KIND), intent(INOUT) :: disp integer, intent(IN) :: ipencil real(mytype), dimension(:,:,:), intent(INOUT) :: var TYPE(DECOMP_INFO), intent(IN), optional :: opt_decomp TYPE(DECOMP_INFO) :: decomp integer, dimension(3) :: sizes, subsizes, starts integer :: ierror, newtype, data_type data_type = real_type #include "io_read_var.f90" return end subroutine read_var_real subroutine read_var_complex(fh,disp,ipencil,var,opt_decomp) implicit none integer, intent(IN) :: fh integer(KIND=MPI_OFFSET_KIND), intent(INOUT) :: disp integer, intent(IN) :: ipencil complex(mytype), dimension(:,:,:), intent(INOUT) :: var TYPE(DECOMP_INFO), intent(IN), optional :: opt_decomp TYPE(DECOMP_INFO) :: decomp integer, dimension(3) :: sizes, subsizes, starts integer :: ierror, newtype, data_type data_type = complex_type #include "io_read_var.f90" return end subroutine read_var_complex !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Write scalar variables as part of a big MPI-IO file, starting from ! displacement 'disp'; 'disp' will be updated after the reading ! operation to prepare the reading of next chunk of data. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine write_scalar_real(fh,disp,n,var) implicit none integer, intent(IN) :: fh ! file handle integer(KIND=MPI_OFFSET_KIND), & intent(INOUT) :: disp ! displacement integer, intent(IN) :: n ! number of scalars real(mytype), dimension(n), & intent(IN) :: var ! array of scalars integer :: m, ierror call MPI_FILE_SET_VIEW(fh,disp,real_type, & real_type,'native',MPI_INFO_NULL,ierror) if (nrank==0) then m = n ! only one rank needs to write else m = 0 end if call MPI_FILE_WRITE_ALL(fh, var, m, real_type, & MPI_STATUS_IGNORE, ierror) disp = disp + n*mytype_bytes return end subroutine write_scalar_real subroutine write_scalar_complex(fh,disp,n,var) implicit none integer, intent(IN) :: fh integer(KIND=MPI_OFFSET_KIND), intent(INOUT) :: disp integer, intent(IN) :: n complex(mytype), dimension(n), intent(IN) :: var integer :: m, ierror call MPI_FILE_SET_VIEW(fh,disp,complex_type, & complex_type,'native',MPI_INFO_NULL,ierror) if (nrank==0) then m = n else m = 0 end if call MPI_FILE_WRITE_ALL(fh, var, m, complex_type, & MPI_STATUS_IGNORE, ierror) disp = disp + n*mytype_bytes*2 return end subroutine write_scalar_complex subroutine write_scalar_integer(fh,disp,n,var) implicit none integer, intent(IN) :: fh integer(KIND=MPI_OFFSET_KIND), intent(INOUT) :: disp integer, intent(IN) :: n integer, dimension(n), intent(IN) :: var integer :: m, ierror call MPI_FILE_SET_VIEW(fh,disp,MPI_INTEGER, & MPI_INTEGER,'native',MPI_INFO_NULL,ierror) if (nrank==0) then m = n else m = 0 end if call MPI_FILE_WRITE_ALL(fh, var, m, MPI_INTEGER, & MPI_STATUS_IGNORE, ierror) call MPI_TYPE_SIZE(MPI_INTEGER,m,ierror) disp = disp + n*m return end subroutine write_scalar_integer subroutine write_scalar_logical(fh,disp,n,var) implicit none integer, intent(IN) :: fh integer(KIND=MPI_OFFSET_KIND), intent(INOUT) :: disp integer, intent(IN) :: n logical, dimension(n), intent(IN) :: var integer :: m, ierror call MPI_FILE_SET_VIEW(fh,disp,MPI_LOGICAL, & MPI_LOGICAL,'native',MPI_INFO_NULL,ierror) if (nrank==0) then m = n else m = 0 end if call MPI_FILE_WRITE_ALL(fh, var, m, MPI_LOGICAL, & MPI_STATUS_IGNORE, ierror) call MPI_TYPE_SIZE(MPI_LOGICAL,m,ierror) disp = disp + n*m return end subroutine write_scalar_logical !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Read scalar variables as part of a big MPI-IO file, starting from ! displacement 'disp'; 'disp' will be updated after the reading ! operation to prepare the reading of next chunk of data. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine read_scalar_real(fh,disp,n,var) implicit none integer, intent(IN) :: fh ! file handle integer(KIND=MPI_OFFSET_KIND), & intent(INOUT) :: disp ! displacement integer, intent(IN) :: n ! number of scalars real(mytype), dimension(n), & intent(INOUT) :: var ! array of scalars integer :: ierror call MPI_FILE_SET_VIEW(fh,disp,real_type, & real_type,'native',MPI_INFO_NULL,ierror) call MPI_FILE_READ_ALL(fh, var, n, real_type, & MPI_STATUS_IGNORE, ierror) disp = disp + n*mytype_bytes return end subroutine read_scalar_real subroutine read_scalar_complex(fh,disp,n,var) implicit none integer, intent(IN) :: fh integer(KIND=MPI_OFFSET_KIND), intent(INOUT) :: disp integer, intent(IN) :: n complex(mytype), dimension(n), intent(INOUT) :: var integer :: ierror call MPI_FILE_SET_VIEW(fh,disp,complex_type, & complex_type,'native',MPI_INFO_NULL,ierror) call MPI_FILE_READ_ALL(fh, var, n, complex_type, & MPI_STATUS_IGNORE, ierror) disp = disp + n*mytype_bytes*2 return end subroutine read_scalar_complex subroutine read_scalar_integer(fh,disp,n,var) implicit none integer, intent(IN) :: fh integer(KIND=MPI_OFFSET_KIND), intent(INOUT) :: disp integer, intent(IN) :: n integer, dimension(n), intent(INOUT) :: var integer :: m, ierror call MPI_FILE_SET_VIEW(fh,disp,MPI_INTEGER, & MPI_INTEGER,'native',MPI_INFO_NULL,ierror) call MPI_FILE_READ_ALL(fh, var, n, MPI_INTEGER, & MPI_STATUS_IGNORE, ierror) call MPI_TYPE_SIZE(MPI_INTEGER,m,ierror) disp = disp + n*m return end subroutine read_scalar_integer subroutine read_scalar_logical(fh,disp,n,var) implicit none integer, intent(IN) :: fh integer(KIND=MPI_OFFSET_KIND), intent(INOUT) :: disp integer, intent(IN) :: n logical, dimension(n), intent(INOUT) :: var integer :: m, ierror call MPI_FILE_SET_VIEW(fh,disp,MPI_LOGICAL, & MPI_LOGICAL,'native',MPI_INFO_NULL,ierror) call MPI_FILE_READ_ALL(fh, var, n, MPI_LOGICAL, & MPI_STATUS_IGNORE, ierror) call MPI_TYPE_SIZE(MPI_LOGICAL,m,ierror) disp = disp + n*m return end subroutine read_scalar_logical !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Write a 2D slice of the 3D data to a file !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine write_plane_3d_real(ipencil,var,iplane,n,filename, & opt_decomp) implicit none integer, intent(IN) :: ipencil !(x-pencil=1; y-pencil=2; z-pencil=3) real(mytype), dimension(:,:,:), intent(IN) :: var integer, intent(IN) :: iplane !(x-plane=1; y-plane=2; z-plane=3) integer, intent(IN) :: n ! which plane to write (global coordinate) character(len=*), intent(IN) :: filename TYPE(DECOMP_INFO), intent(IN), optional :: opt_decomp real(mytype), allocatable, dimension(:,:,:) :: wk, wk2 real(mytype), allocatable, dimension(:,:,:) :: wk2d TYPE(DECOMP_INFO) :: decomp integer(kind=MPI_OFFSET_KIND) :: filesize, disp integer, dimension(3) :: sizes, subsizes, starts integer :: i,j,k, ierror, newtype, fh, data_type data_type = real_type #include "io_write_plane.f90" return end subroutine write_plane_3d_real subroutine write_plane_3d_complex(ipencil,var,iplane,n, & filename,opt_decomp) implicit none integer, intent(IN) :: ipencil !(x-pencil=1; y-pencil=2; z-pencil=3) complex(mytype), dimension(:,:,:), intent(IN) :: var integer, intent(IN) :: iplane !(x-plane=1; y-plane=2; z-plane=3) integer, intent(IN) :: n ! which plane to write (global coordinate) character(len=*), intent(IN) :: filename TYPE(DECOMP_INFO), intent(IN), optional :: opt_decomp complex(mytype), allocatable, dimension(:,:,:) :: wk, wk2 complex(mytype), allocatable, dimension(:,:,:) :: wk2d TYPE(DECOMP_INFO) :: decomp integer(kind=MPI_OFFSET_KIND) :: filesize, disp integer, dimension(3) :: sizes, subsizes, starts integer :: i,j,k, ierror, newtype, fh, data_type data_type = complex_type #include "io_write_plane.f90" return end subroutine write_plane_3d_complex !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Write a 2D array to a file !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !************** TO DO *************** !* Consider handling distributed 2D data set ! subroutine write_plane_2d(ipencil,var,filename) ! integer, intent(IN) :: ipencil !(x-pencil=1; y-pencil=2; z-pencil=3) ! real(mytype), dimension(:,:), intent(IN) :: var ! 2D array ! character(len=*), intent(IN) :: filename ! ! if (ipencil==1) then ! ! var should be defined as var(xsize(2) ! ! else if (ipencil==2) then ! ! else if (ipencil==3) then ! ! end if ! ! return ! end subroutine write_plane_2d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Write 3D array data for every specified mesh point !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine write_every_real(ipencil,var,iskip,jskip,kskip, & filename, from1) implicit none integer, intent(IN) :: ipencil !(x-pencil=1; y-pencil=2; z-pencil=3) real(mytype), dimension(:,:,:), intent(IN) :: var integer, intent(IN) :: iskip,jskip,kskip character(len=*), intent(IN) :: filename logical, intent(IN) :: from1 ! .true. - save 1,n+1,2n+1... ! .false. - save n,2n,3n... real(mytype), allocatable, dimension(:,:,:) :: wk, wk2 integer(kind=MPI_OFFSET_KIND) :: filesize, disp integer, dimension(3) :: sizes, subsizes, starts integer :: i,j,k, ierror, newtype, fh, key,color,newcomm, data_type integer, dimension(3) :: xsz,ysz,zsz,xst,yst,zst,xen,yen,zen,skip data_type = real_type #include "io_write_every.f90" return end subroutine write_every_real subroutine write_every_complex(ipencil,var,iskip,jskip,kskip, & filename, from1) implicit none integer, intent(IN) :: ipencil !(x-pencil=1; y-pencil=2; z-pencil=3) complex(mytype), dimension(:,:,:), intent(IN) :: var integer, intent(IN) :: iskip,jskip,kskip character(len=*), intent(IN) :: filename logical, intent(IN) :: from1 ! .true. - save 1,n+1,2n+1... ! .false. - save n,2n,3n... complex(mytype), allocatable, dimension(:,:,:) :: wk, wk2 integer(kind=MPI_OFFSET_KIND) :: filesize, disp integer, dimension(3) :: sizes, subsizes, starts integer :: i,j,k, ierror, newtype, fh, key,color,newcomm, data_type integer, dimension(3) :: xsz,ysz,zsz,xst,yst,zst,xen,yen,zen,skip data_type = complex_type #include "io_write_every.f90" return end subroutine write_every_complex subroutine mpiio_write_real_coarse(ipencil,var,filename,icoarse) USE param USE variables implicit none integer, intent(IN) :: ipencil !(x-pencil=1; y-pencil=2; z-pencil=3) integer, intent(IN) :: icoarse !(nstat=1; nvisu=2) real(mytype), dimension(:,:,:), intent(IN) :: var character(len=*) :: filename integer (kind=MPI_OFFSET_KIND) :: filesize, disp integer, dimension(3) :: sizes, subsizes, starts integer :: i,j,k, ierror, newtype, fh if (icoarse==1) then sizes(1) = xszS(1) sizes(2) = yszS(2) sizes(3) = zszS(3) if (ipencil == 1) then subsizes(1) = xszS(1) subsizes(2) = xszS(2) subsizes(3) = xszS(3) starts(1) = xstS(1)-1 ! 0-based index starts(2) = xstS(2)-1 starts(3) = xstS(3)-1 else if (ipencil == 2) then subsizes(1) = yszS(1) subsizes(2) = yszS(2) subsizes(3) = yszS(3) starts(1) = ystS(1)-1 starts(2) = ystS(2)-1 starts(3) = ystS(3)-1 else if (ipencil == 3) then subsizes(1) = zszS(1) subsizes(2) = zszS(2) subsizes(3) = zszS(3) starts(1) = zstS(1)-1 starts(2) = zstS(2)-1 starts(3) = zstS(3)-1 endif endif if (icoarse==2) then sizes(1) = xszV(1) sizes(2) = yszV(2) sizes(3) = zszV(3) if (ipencil == 1) then subsizes(1) = xszV(1) subsizes(2) = xszV(2) subsizes(3) = xszV(3) starts(1) = xstV(1)-1 ! 0-based index starts(2) = xstV(2)-1 starts(3) = xstV(3)-1 else if (ipencil == 2) then subsizes(1) = yszV(1) subsizes(2) = yszV(2) subsizes(3) = yszV(3) starts(1) = ystV(1)-1 starts(2) = ystV(2)-1 starts(3) = ystV(3)-1 else if (ipencil == 3) then subsizes(1) = zszV(1) subsizes(2) = zszV(2) subsizes(3) = zszV(3) starts(1) = zstV(1)-1 starts(2) = zstV(2)-1 starts(3) = zstV(3)-1 endif endif call MPI_TYPE_CREATE_SUBARRAY(3, sizes, subsizes, starts, & MPI_ORDER_FORTRAN, real_type, newtype, ierror) call MPI_TYPE_COMMIT(newtype,ierror) call MPI_FILE_OPEN(MPI_COMM_WORLD, filename, & MPI_MODE_CREATE+MPI_MODE_WRONLY, MPI_INFO_NULL, & fh, ierror) filesize = 0_MPI_OFFSET_KIND call MPI_FILE_SET_SIZE(fh,filesize,ierror) ! guarantee overwriting disp = 0_MPI_OFFSET_KIND call MPI_FILE_SET_VIEW(fh,disp,real_type, & newtype,'native',MPI_INFO_NULL,ierror) call MPI_FILE_WRITE_ALL(fh, var, & subsizes(1)*subsizes(2)*subsizes(3), & real_type, MPI_STATUS_IGNORE, ierror) call MPI_FILE_CLOSE(fh,ierror) call MPI_TYPE_FREE(newtype,ierror) return end subroutine mpiio_write_real_coarse !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Write a 3D data set covering a smaller sub-domain only !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine write_subdomain(ipencil,var,is,ie,js,je,ks,ke,filename) implicit none integer, intent(IN) :: ipencil !(x-pencil=1; y-pencil=2; z-pencil=3) real(mytype), dimension(:,:,:), intent(IN) :: var integer, intent(IN) :: is, ie, js, je, ks, ke character(len=*), intent(IN) :: filename real(mytype), allocatable, dimension(:,:,:) :: wk, wk2 integer(kind=MPI_OFFSET_KIND) :: filesize, disp integer, dimension(3) :: sizes, subsizes, starts integer :: color, key, errorcode, newcomm, ierror integer :: newtype, fh, data_type, i, j, k integer :: i1, i2, j1, j2, k1, k2 data_type = real_type ! validate the input paramters if (is<1 .OR. ie>nx_global .OR. js<1 .OR. je>ny_global .OR. & ks<1 .OR. ke>nz_global) then errorcode = 10 call decomp_2d_abort(errorcode, & 'Invalid subdomain specified in I/O') end if ! create a communicator for all those MPI ranks containing the subdomain color = 1 key = 1 if (ipencil==1) then if (xstart(1)>ie .OR. xend(1)<is .OR. xstart(2)>je .OR. xend(2)<js & .OR. xstart(3)>ke .OR. xend(3)<ks) then color = 2 end if else if (ipencil==2) then if (ystart(1)>ie .OR. yend(1)<is .OR. ystart(2)>je .OR. yend(2)<js & .OR. ystart(3)>ke .OR. yend(3)<ks) then color = 2 end if else if (ipencil==3) then if (zstart(1)>ie .OR. zend(1)<is .OR. zstart(2)>je .OR. zend(2)<js & .OR. zstart(3)>ke .OR. zend(3)<ks) then color = 2 end if end if call MPI_COMM_SPLIT(MPI_COMM_WORLD,color,key,newcomm,ierror) if (color==1) then ! only ranks in this group do IO collectively ! generate MPI-IO subarray information ! global size of the sub-domain to write sizes(1) = ie - is + 1 sizes(2) = je - js + 1 sizes(3) = ke - ks + 1 ! 'subsizes' & 'starts' as required by MPI_TYPE_CREATE_SUBARRAY ! note the special code whe subdomain only occupy part of the pencil if (ipencil==1) then subsizes(1) = xsize(1) starts(1) = xstart(1) - is if (xend(1)>ie .AND. xstart(1)<is) then subsizes(1) = ie - is + 1 starts(1) = 0 else if (xstart(1)<is) then subsizes(1) = xend(1) - is + 1 starts(1) = 0 else if (xend(1)>ie) then subsizes(1) = ie - xstart(1) + 1 end if subsizes(2) = xsize(2) starts(2) = xstart(2) - js if (xend(2)>je .AND. xstart(2)<js) then subsizes(2) = je - js + 1 starts(2) = 0 else if (xstart(2)<js) then subsizes(2) = xend(2) - js + 1 starts(2) = 0 else if (xend(2)>je) then subsizes(2) = je - xstart(2) + 1 end if subsizes(3) = xsize(3) starts(3) = xstart(3) - ks if (xend(3)>ke .AND. xstart(3)<ks) then subsizes(3) = ke - ks + 1 starts(3) = 0 else if (xstart(3)<ks) then subsizes(3) = xend(3) - ks + 1 starts(3) = 0 else if (xend(3)>ke) then subsizes(3) = ke - xstart(3) + 1 end if else if (ipencil==2) then ! TODO else if (ipencil==3) then ! TODO end if ! copy data from orginal to a temp array ! pay attention to blocks only partially cover the sub-domain if (ipencil==1) then if (xend(1)>ie .AND. xstart(1)<is) then i1 = is i2 = ie else if (xend(1)>ie) then i1 = xstart(1) i2 = ie else if (xstart(1)<is) then i1 = is i2 = xend(1) else i1 = xstart(1) i2 = xend(1) end if if (xend(2)>je .AND. xstart(2)<js) then j1 = js j2 = je else if (xend(2)>je) then j1 = xstart(2) j2 = je else if (xstart(2)<js) then j1 = js j2 = xend(2) else j1 = xstart(2) j2 = xend(2) end if if (xend(3)>ke .AND. xstart(3)<ks) then k1 = ks k2 = ke else if (xend(3)>ke) then k1 = xstart(3) k2 = ke else if (xstart(3)<ks) then k1 = ks k2 = xend(3) else k1 = xstart(3) k2 = xend(3) end if allocate(wk(i1:i2, j1:j2, k1:k2)) allocate(wk2(xstart(1):xend(1),xstart(2):xend(2),xstart(3):xend(3))) wk2 = var do k=k1,k2 do j=j1,j2 do i=i1,i2 wk(i,j,k) = wk2(i,j,k) end do end do end do else if (ipencil==2) then ! TODO else if (ipencil==3) then ! TODO end if deallocate(wk2) ! MPI-IO call MPI_TYPE_CREATE_SUBARRAY(3, sizes, subsizes, starts, & MPI_ORDER_FORTRAN, data_type, newtype, ierror) call MPI_TYPE_COMMIT(newtype,ierror) call MPI_FILE_OPEN(newcomm, filename, & MPI_MODE_CREATE+MPI_MODE_WRONLY, MPI_INFO_NULL, & fh, ierror) filesize = 0_MPI_OFFSET_KIND call MPI_FILE_SET_SIZE(fh,filesize,ierror) ! guarantee overwriting disp = 0_MPI_OFFSET_KIND call MPI_FILE_SET_VIEW(fh,disp,data_type, & newtype,'native',MPI_INFO_NULL,ierror) call MPI_FILE_WRITE_ALL(fh, wk, & subsizes(1)*subsizes(2)*subsizes(3), & data_type, MPI_STATUS_IGNORE, ierror) call MPI_FILE_CLOSE(fh,ierror) call MPI_TYPE_FREE(newtype,ierror) deallocate(wk) end if return end subroutine write_subdomain end module decomp_2d_io
gpl-3.0
QEF/q-e_schrodinger
Modules/suscept_laue.f90
2
20583
! ! Copyright (C) 2016 National Institute of Advanced Industrial Science and Technology (AIST) ! [ This code is written by Satomichi Nishihara. ] ! ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !--------------------------------------------------------------------------- SUBROUTINE suscept_laue(rism1t, rismlt, alpha, lhand, ierr) !--------------------------------------------------------------------------- ! ! ... create inter-site susceptibility for Laue-RISM (from 1D-RISM) ! ... ! ... 1 / inf ! ... x21(gxy,z'-z) = ---- | dgz [ w21(g) + rho2 * h21(g) ] * cos(gz*(z'-z)) ! ... pi / 0 ! ... ! ... x21 depends on norm of gxy, and is even along z'-z. ! USE constants, ONLY : pi, sqrtpi, eps12 USE cell_base, ONLY : alat, tpiba2 USE err_rism, ONLY : IERR_RISM_NULL, IERR_RISM_INCORRECT_DATA_TYPE, & & IERR_RISM_1DRISM_IS_NOT_AVAIL, IERR_RISM_LARGE_LAUE_BOX USE io_files, ONLY : tmp_dir, prefix USE io_global, ONLY : ionode USE kinds, ONLY : DP USE mp, ONLY : mp_size, mp_rank, mp_max, mp_sum, mp_get, mp_gather, mp_bcast, mp_barrier USE rism, ONLY : rism_type, ITYPE_1DRISM, ITYPE_LAUERISM USE solvavg, ONLY : solvavg_init, solvavg_clear, solvavg_print, solvavg_put USE solvmol, ONLY : nsolV, solVs, get_nsite_in_solVs, get_nuniq_in_solVs, & & iuniq_to_nsite, iuniq_to_isite, isite_to_isolV, isite_to_iatom USE splinelib, ONLY : spline, splint ! IMPLICIT NONE ! TYPE(rism_type), INTENT(IN) :: rism1t TYPE(rism_type), INTENT(INOUT) :: rismlt REAL(DP), INTENT(IN) :: alpha ! in bohr LOGICAL, INTENT(IN) :: lhand ! if true, right-hand. if false, left-hand. INTEGER, INTENT(OUT) :: ierr ! INTEGER :: nv INTEGER :: nq INTEGER :: iq1, iq2 INTEGER :: iv1, iv2 INTEGER :: iw1, iw2 INTEGER :: isolV1, isolV2 INTEGER :: iatom1, iatom2 CHARACTER(LEN=6) :: satom1, satom2 INTEGER :: iiq2 INTEGER :: nv2, iiv2 REAL(DP) :: qv2 INTEGER :: ivv INTEGER :: irz INTEGER :: igz INTEGER :: igxy INTEGER :: jgxy INTEGER :: irank INTEGER :: nproc INTEGER, ALLOCATABLE :: rank_map(:,:) INTEGER, ALLOCATABLE :: root_spline(:) REAL(DP) :: rfft_1d REAL(DP) :: rfft_laue REAL(DP) :: rho2 REAL(DP) :: rz REAL(DP) :: gz, ggz REAL(DP) :: ggxy REAL(DP) :: gs REAL(DP) :: gsmax REAL(DP) :: dg REAL(DP) :: pidg REAL(DP) :: xgs REAL(DP) :: dxg0 REAL(DP) :: ddxg0 REAL(DP), ALLOCATABLE :: xg_1d(:) REAL(DP), ALLOCATABLE :: xg_spl(:) REAL(DP), ALLOCATABLE :: xg_d2y(:) REAL(DP), ALLOCATABLE :: gs_t(:,:) REAL(DP), ALLOCATABLE :: xg_t(:,:) REAL(DP), ALLOCATABLE :: xg_0(:,:) REAL(DP), ALLOCATABLE :: xgs21(:) REAL(DP), ALLOCATABLE :: cosgz(:,:) ! REAL(DP), PARAMETER :: LAUE_BOX_SCALE = 1.2_DP ! EXTERNAL :: dgemm ! ! ... number of sites in solvents nv = get_nsite_in_solVs() nq = get_nuniq_in_solVs() ! IF (rism1t%itype /= ITYPE_1DRISM) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! IF (rism1t%nr /= rism1t%ng) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! IF (rism1t%nsite < (nv * (nv + 1) / 2)) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! IF (rism1t%rfft%ngrid < rism1t%mp_task%nvec) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! IF (.NOT. rism1t%avail) THEN ierr = IERR_RISM_1DRISM_IS_NOT_AVAIL RETURN END IF ! ! ... check data type of Laue-RISM IF (rismlt%itype /= ITYPE_LAUERISM) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! IF (rismlt%mp_site%nsite < nq) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! IF (rismlt%ngs < rismlt%lfft%nglxy) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! IF (rismlt%nrzl < rismlt%lfft%nrz) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! ! ... check alpha IF (alpha <= 0.0_DP) THEN ierr = IERR_RISM_INCORRECT_DATA_TYPE RETURN END IF ! ! ... check FFT-range rfft_1d = rism1t%rfft%rgrid(rism1t%rfft%ngrid) rfft_laue = (rismlt%lfft%zright - rismlt%lfft%zleft) * alat IF ((LAUE_BOX_SCALE * rfft_laue) > rfft_1d) THEN ierr = IERR_RISM_LARGE_LAUE_BOX RETURN END IF ! ! ... allocate working memory ALLOCATE(rank_map(3, nq)) ALLOCATE(root_spline(nq)) ALLOCATE(xg_1d(rism1t%ng)) ALLOCATE(xg_spl(rism1t%mp_task%nvec)) ALLOCATE(xg_d2y(rism1t%mp_task%nvec)) IF ((rism1t%rfft%ngrid * rismlt%lfft%nglxy) > 0) THEN ALLOCATE(gs_t(rism1t%rfft%ngrid, rismlt%lfft%nglxy)) END IF IF ((rism1t%rfft%ngrid * rismlt%lfft%nglxy) > 0) THEN ALLOCATE(xg_t(rism1t%rfft%ngrid, rismlt%lfft%nglxy)) END IF IF (rismlt%nsite > 0) THEN ALLOCATE(xg_0(rismlt%nsite, nq)) END IF IF ((rismlt%nrzl * rismlt%ngs) > 0) THEN ALLOCATE(xgs21(rismlt%nrzl * rismlt%ngs)) END IF IF ((rism1t%rfft%ngrid * rismlt%lfft%nrz) > 0) THEN ALLOCATE(cosgz(rism1t%rfft%ngrid, rismlt%lfft%nrz)) END IF ! ! ... setup roots to prepare spline DO iq1 = 1, nq rank_map(1, iq1) = mp_rank(rismlt%intra_comm) rank_map(2, iq1) = 0 rank_map(3, iq1) = 0 ! root_spline(iq1) = 0 IF (rismlt%mp_site%isite_start <= iq1 .AND. iq1 <= rismlt%mp_site%isite_end) THEN IF (rismlt%mp_site%me_sitg == rismlt%mp_site%root_sitg) THEN rank_map(2, iq1) = rank_map(1, iq1) + 1 IF (rism1t%is_intra) THEN root_spline(iq1) = rism1t%mp_task%me_task + 1 END IF END IF END IF ! CALL mp_max(rank_map(2, iq1), rismlt%intra_comm) rank_map(2, iq1) = rank_map(2, iq1) - 1 ! CALL mp_max(root_spline(iq1), rismlt%intra_comm) root_spline(iq1) = root_spline(iq1) - 1 IF (root_spline(iq1) < 0) THEN root_spline(iq1) = rism1t%mp_task%root_task END IF ! IF (rism1t%is_intra .AND. rism1t%mp_task%me_task == root_spline(iq1)) THEN rank_map(3, iq1) = rank_map(1, iq1) + 1 END IF ! CALL mp_max(rank_map(3, iq1), rismlt%intra_comm) rank_map(3, iq1) = rank_map(3, iq1) - 1 END DO ! ! ... set variables gsmax = rism1t%rfft%ggrid(rism1t%rfft%ngrid) dg = rism1t%rfft%ggrid(2) - rism1t%rfft%ggrid(1) pidg = dg / pi ! ! ... calculate list of gs DO igxy = 1, rismlt%lfft%nglxy ggxy = tpiba2 * rismlt%lfft%glxy(igxy) !$omp parallel do default(shared) private(igz, gz, ggz, gs) DO igz = 1, rism1t%rfft%ngrid gz = rism1t%rfft%ggrid(igz) ggz = gz * gz gs = SQRT(ggxy + ggz) gs_t(igz, igxy) = gs END DO !$omp end parallel do END DO ! ! ... calculate cos(gz*rz) cosgz = 0.0_DP irank = mp_rank(rismlt%intra_comm) nproc = mp_size(rismlt%intra_comm) ! DO irz = 1, rismlt%lfft%nrz IF (irank /= MOD(irz - 1, nproc)) THEN CYCLE END IF ! rz = alat * DBLE(irz - 1) * rismlt%lfft%zstep !$omp parallel do default(shared) private(igz, gz) DO igz = 1, rism1t%rfft%ngrid gz = rism1t%rfft%ggrid(igz) cosgz(igz, irz) = COS(gz * rz) END DO !$omp end parallel do cosgz(1, irz) = 0.5_DP * cosgz(1, irz) END DO ! CALL mp_sum(cosgz, rismlt%intra_comm) ! ! ... calculate susceptibility DO iq1 = 1, nq ! ... properties of unique site1 iv1 = iuniq_to_isite(1, iq1) ! DO iq2 = 1, nq ! ... properties of unique site2 nv2 = iuniq_to_nsite(iq2) IF (rismlt%mp_site%isite_start <= iq2 .AND. iq2 <= rismlt%mp_site%isite_end) THEN iiq2 = iq2 - rismlt%mp_site%isite_start + 1 ELSE iiq2 = 0 END IF ! IF (iiq2 > 0) THEN IF (rismlt%nsite > 0) THEN xg_0(iiq2, iq1) = 0.0_DP END IF IF ((rismlt%nrzl * rismlt%ngs) > 0) THEN xgs21(:) = 0.0_DP END IF END IF ! DO iiv2 = 1, nv2 ! ... properties of a site2 iv2 = iuniq_to_isite(iiv2, iq2) isolV2 = isite_to_isolV(iv2) IF (lhand) THEN rho2 = solVs(isolV2)%density ELSE rho2 = solVs(isolV2)%subdensity END IF ! iw1 = MAX(iv1, iv2) iw2 = MIN(iv1, iv2) ivv = iw1 * (iw1 - 1) / 2 + iw2 ! ! ... create h21(g) or x21(g) of 1D-RISM IF (rism1t%is_intra) THEN IF (iv1 == iv2) THEN xg_1d(:) = rho2 * rism1t%hg(:, ivv) ELSE xg_1d(:) = rism1t%wg(:, ivv) + rho2 * rism1t%hg(:, ivv) END IF CALL mp_gather(xg_1d, xg_spl, rism1t%mp_task%ilen_vecs, rism1t%mp_task%idis_vecs, & & root_spline(iq2), rism1t%mp_task%itask_comm) END IF ! IF (rank_map(2, iq2) /= rank_map(3, iq2)) THEN CALL mp_get(xg_spl, xg_spl, rank_map(1, iq2), & & rank_map(2, iq2), rank_map(3, iq2), ivv, rismlt%intra_comm) END IF ! IF (iiq2 > 0) THEN ! ... prepare spline correction IF (rismlt%mp_site%me_sitg == rismlt%mp_site%root_sitg) THEN CALL suscept_g0(rism1t%mp_task%nvec, rism1t%rfft%ggrid, xg_spl, dxg0, ddxg0) CALL spline(rism1t%rfft%ggrid(1:rism1t%mp_task%nvec), xg_spl, dxg0, ddxg0, xg_d2y) END IF ! CALL mp_bcast(xg_spl, rismlt%mp_site%root_sitg, rismlt%mp_site%intra_sitg_comm) CALL mp_bcast(xg_d2y, rismlt%mp_site%root_sitg, rismlt%mp_site%intra_sitg_comm) ! ! ... perform spline correction fitting h21(g) or x21(g) from 1D-RISM to Laue-RISM DO igxy = 1, rismlt%lfft%nglxy !$omp parallel do default(shared) private(igz, gs, xgs) DO igz = 1, rism1t%rfft%ngrid gs = gs_t(igz, igxy) IF (gs <= (gsmax + eps12)) THEN xgs = splint(rism1t%rfft%ggrid(1:rism1t%mp_task%nvec), xg_spl, xg_d2y, gs) xg_t(igz, igxy) = xgs ELSE xg_t(igz, igxy) = 0.0_DP END IF END DO !$omp end parallel do END DO ! ! ... calculate x21(rz,gxy) IF (rismlt%nsite > 0) THEN IF (iv1 == iv2) THEN xg_0(iiq2, iq1) = xg_0(iiq2, iq1) + xg_spl(1) + 1.0_DP ELSE xg_0(iiq2, iq1) = xg_0(iiq2, iq1) + xg_spl(1) END IF END IF ! IF ((rismlt%nrzl * rismlt%ngs) > 0) THEN CALL dgemm('T', 'N', rismlt%lfft%nrz, rismlt%lfft%nglxy, rism1t%rfft%ngrid, & & pidg, cosgz, rism1t%rfft%ngrid, xg_t, rism1t%rfft%ngrid, & & 1.0_DP, xgs21, rismlt%nrzl) END IF ! IF (iv1 == iv2) THEN DO igxy = 1, rismlt%lfft%nglxy jgxy = (igxy - 1) * rismlt%nrzl ggxy = tpiba2 * rismlt%lfft%glxy(igxy) !$omp parallel do default(shared) private(irz, rz) DO irz = 1, rismlt%lfft%nrz rz = alat * DBLE(irz - 1) * rismlt%lfft%zstep xgs21(irz + jgxy) = xgs21(irz + jgxy) + & & EXP(-rz * rz / alpha / alpha - 0.25_DP * alpha * alpha * ggxy) / alpha / sqrtpi END DO !$omp end parallel do END DO END IF END IF ! CALL mp_barrier(rismlt%intra_comm) ! END DO ! IF (iiq2 > 0) THEN IF ((rismlt%nrzl * rismlt%ngs) > 0) THEN IF (lhand) THEN rismlt%xgs(:, iiq2, iq1) = xgs21(:) ELSE rismlt%ygs(:, iiq2, iq1) = xgs21(:) END IF END IF END IF ! END DO END DO ! ! ... renormalize at G = 0 CALL renormalize_g0() ! ! ... correct at Gxy = 0 CALL correct_gxy0() ! ! ... print data CALL print_x21() ! ! ... deallocate working memory DEALLOCATE(rank_map) DEALLOCATE(root_spline) DEALLOCATE(xg_1d) DEALLOCATE(xg_spl) DEALLOCATE(xg_d2y) IF ((rism1t%rfft%ngrid * rismlt%lfft%nglxy) > 0) THEN DEALLOCATE(gs_t) END IF IF ((rism1t%rfft%ngrid * rismlt%lfft%nglxy) > 0) THEN DEALLOCATE(xg_t) END IF IF (rismlt%nsite > 0) THEN DEALLOCATE(xg_0) END IF IF ((rismlt%nrzl * rismlt%ngs) > 0) THEN DEALLOCATE(xgs21) END IF IF ((rism1t%rfft%ngrid * rismlt%lfft%nrz) > 0) THEN DEALLOCATE(cosgz) END IF ! ! ... normally done ierr = IERR_RISM_NULL ! CONTAINS ! SUBROUTINE renormalize_g0() IMPLICIT NONE ! REAL(DP), ALLOCATABLE :: msol(:) REAL(DP), ALLOCATABLE :: qsol(:) REAL(DP) :: qtot REAL(DP) :: qsqr ! ALLOCATE(msol(nsolV)) ALLOCATE(qsol(nsolV)) ! DO iq1 = 1, nq ! ! ... sum numbers and charges of solvent atoms in a molecule msol = 0.0_DP qsol = 0.0_DP ! DO iq2 = rismlt%mp_site%isite_start, rismlt%mp_site%isite_end iiq2 = iq2 - rismlt%mp_site%isite_start + 1 iv2 = iuniq_to_isite(1, iq2) nv2 = iuniq_to_nsite(iq2) isolV2 = isite_to_isolV(iv2) iatom2 = isite_to_iatom(iv2) qv2 = solVs(isolV2)%charge(iatom2) ! msol(isolV2) = msol(isolV2) + xg_0(iiq2, iq1) qsol(isolV2) = qsol(isolV2) + DBLE(nv2) * qv2 END DO ! CALL mp_sum(msol, rismlt%mp_site%inter_sitg_comm) CALL mp_sum(qsol, rismlt%mp_site%inter_sitg_comm) ! DO isolV2 = 1, nsolV IF (solVs(isolV2)%natom > 0) THEN msol(isolV2) = msol(isolV2) / DBLE(solVs(isolV2)%natom) qsol(isolV2) = qsol(isolV2) / DBLE(solVs(isolV2)%natom) ELSE msol(isolV2) = 0.0_DP qsol(isolV2) = 0.0_DP END IF END DO ! ! ... renormalize: to correct stoichiometry DO iq2 = rismlt%mp_site%isite_start, rismlt%mp_site%isite_end iiq2 = iq2 - rismlt%mp_site%isite_start + 1 iv2 = iuniq_to_isite(1, iq2) nv2 = iuniq_to_nsite(iq2) isolV2 = isite_to_isolV(iv2) ! xg_0(iiq2, iq1) = DBLE(nv2) * msol(isolV2) END DO ! ! ... total charge and square sum of charge qtot = 0.0_DP qsqr = 0.0_DP ! DO iq2 = rismlt%mp_site%isite_start, rismlt%mp_site%isite_end iiq2 = iq2 - rismlt%mp_site%isite_start + 1 iv2 = iuniq_to_isite(1, iq2) nv2 = iuniq_to_nsite(iq2) isolV2 = isite_to_isolV(iv2) ! qtot = qtot + qsol(isolV2) * xg_0(iiq2, iq1) qsqr = qsqr + DBLE(nv2) * qsol(isolV2) * qsol(isolV2) END DO ! CALL mp_sum(qtot, rismlt%mp_site%inter_sitg_comm) CALL mp_sum(qsqr, rismlt%mp_site%inter_sitg_comm) ! ! ... renormalize: to correct total charge IF (ABS(qtot) > eps12) THEN IF (ABS(qsqr) <= eps12) THEN ! will not be occurred CALL errore('renormalize_g0', 'qsqr is zero', 1) END IF ! DO iq2 = rismlt%mp_site%isite_start, rismlt%mp_site%isite_end iiq2 = iq2 - rismlt%mp_site%isite_start + 1 iv2 = iuniq_to_isite(1, iq2) nv2 = iuniq_to_nsite(iq2) isolV2 = isite_to_isolV(iv2) ! xg_0(iiq2, iq1) = xg_0(iiq2, iq1) - DBLE(nv2) * qsol(isolV2) * qtot / qsqr END DO END IF ! END DO ! DEALLOCATE(msol) DEALLOCATE(qsol) ! END SUBROUTINE renormalize_g0 ! SUBROUTINE correct_gxy0() IMPLICIT NONE REAL(DP) :: dz REAL(DP) :: xg_int REAL(DP) :: xg_scale ! dz = alat * rismlt%lfft%zstep ! DO iq1 = 1, nq DO iq2 = rismlt%mp_site%isite_start, rismlt%mp_site%isite_end iiq2 = iq2 - rismlt%mp_site%isite_start + 1 ! IF (rismlt%lfft%gxystart > 1) THEN ! ! ... integrate at Gxy = 0 IF (lhand) THEN xg_int = 0.0_DP !$omp parallel do default(shared) private(irz) reduction(+:xg_int) DO irz = 2, rismlt%lfft%nrz xg_int = xg_int + 2.0_DP * dz * rismlt%xgs(irz, iiq2, iq1) END DO !$omp end parallel do xg_int = xg_int + dz * rismlt%xgs(1, iiq2, iq1) ELSE xg_int = 0.0_DP !$omp parallel do default(shared) private(irz) reduction(+:xg_int) DO irz = 2, rismlt%lfft%nrz xg_int = xg_int + 2.0_DP * dz * rismlt%ygs(irz, iiq2, iq1) END DO !$omp end parallel do xg_int = xg_int + dz * rismlt%ygs(1, iiq2, iq1) END IF ! ! ... rescale x21 at Gxy = 0 IF (ABS(xg_int) > eps12) THEN xg_scale = xg_0(iiq2, iq1) / xg_int IF (lhand) THEN !$omp parallel do default(shared) private(irz) DO irz = 1, rismlt%lfft%nrz rismlt%xgs(irz, iiq2, iq1) = rismlt%xgs(irz, iiq2, iq1) * xg_scale END DO !$omp end parallel do ELSE !$omp parallel do default(shared) private(irz) DO irz = 1, rismlt%lfft%nrz rismlt%ygs(irz, iiq2, iq1) = rismlt%ygs(irz, iiq2, iq1) * xg_scale END DO !$omp end parallel do END IF END IF ! END IF END DO END DO ! END SUBROUTINE correct_gxy0 ! SUBROUTINE print_x21() IMPLICIT NONE #if defined (__DEBUG_RISM) INTEGER :: ista INTEGER :: my_group_id INTEGER :: io_group_id INTEGER :: owner_group_id COMPLEX(DP), ALLOCATABLE :: xtmp(:) ! ! ... get process info. my_group_id = mp_rank(rismlt%mp_site%inter_sitg_comm) ! ! ... find the index of the group which includes ionode io_group_id = 0 IF (ionode) THEN io_group_id = my_group_id END IF CALL mp_sum(io_group_id, rismlt%mp_site%intra_sitg_comm) CALL mp_sum(io_group_id, rismlt%mp_site%inter_sitg_comm) ! ! ... init solvavg IF (my_group_id == io_group_id) THEN CALL solvavg_init(rismlt%lfft, rismlt%mp_site%intra_sitg_comm, .TRUE.) END IF ! ! ... put data to solvavg ALLOCATE(xtmp(rismlt%nrzl * rismlt%ngs)) ! DO iq1 = 1, nq iv1 = iuniq_to_isite(1, iq1) isolV1 = isite_to_isolV(iv1) iatom1 = isite_to_iatom(iv1) satom1 = ADJUSTL(solVs(isolV1)%aname(iatom1)) ! DO iq2 = 1, nq iv2 = iuniq_to_isite(1, iq2) isolV2 = isite_to_isolV(iv2) iatom2 = isite_to_iatom(iv2) satom2 = ADJUSTL(solVs(isolV2)%aname(iatom2)) ! IF (rismlt%mp_site%isite_start <= iq2 .AND. iq2 <= rismlt%mp_site%isite_end) THEN owner_group_id = my_group_id IF (lhand) THEN xtmp = rismlt%xgs(:, iq2 - rismlt%mp_site%isite_start + 1, iq1) ELSE xtmp = rismlt%ygs(:, iq2 - rismlt%mp_site%isite_start + 1, iq1) END IF ELSE owner_group_id = 0 xtmp = CMPLX(0.0_DP, 0.0_DP, kind=DP) END IF ! CALL mp_sum(owner_group_id, rismlt%mp_site%inter_sitg_comm) CALL mp_get(xtmp, xtmp, my_group_id, io_group_id, & & owner_group_id, iq2, rismlt%mp_site%inter_sitg_comm) ! IF (my_group_id == io_group_id) THEN CALL solvavg_put('x_' // TRIM(satom2) // ':' // TRIM(satom1), .FALSE., xtmp, rismlt%nrzl, .TRUE.) END IF ! CALL mp_barrier(rismlt%mp_site%inter_sitg_comm) END DO END DO ! DEALLOCATE(xtmp) ! ! ... print solvavg IF (my_group_id == io_group_id) THEN IF (lhand) THEN CALL solvavg_print(TRIM(tmp_dir) // TRIM(prefix) // '.rism1_x21', 'solvent susceptibility', ista) ELSE CALL solvavg_print(TRIM(tmp_dir) // TRIM(prefix) // '.rism1_y21', 'solvent susceptibility', ista) END IF ista = ABS(ista) ELSE ista = 0 END IF ! IF (ista /= 0) THEN CALL errore('print_x21', 'cannot write file', ista) END IF ! ! ... finalize solvavg IF (my_group_id == io_group_id) THEN CALL solvavg_clear() END IF ! #endif END SUBROUTINE print_x21 ! END SUBROUTINE suscept_laue
gpl-2.0
kbai/specfem3d
utils/EXTERNAL_CODES_coupled_with_SPECFEM3D/DSM_for_SPECFEM3D/Notes_Olds_and_Utils/OLD--VM_mesher_now_handled_by_meshfem3d/mesh_chunk.f90
3
36091
! ! ! MAILLAGE D'UN CHUNK POUR INTERFACE SPECFEM/DSM ! !!!!!!! cas 8 noeuds ! ! Vadim Monteiler, Fevrier 2013 ! ! ! J'ai une convention propre pour le mapping de la sphere cubique (a completer ... ) !!!!!! ! program mesh_chunk implicit none integer nel_lat,nel_lon,nel_depth,NX,NY,NZ,Ndepth integer NGLLX,NGLLY,NGLLZ,NGNOD,NDIM parameter(NGLLX=5,NGLLY=5,NGLLZ=5,NGNOD=8,NDIM=3) integer ilat,ilon,ispec,iz,i,j,k,nspec,ia integer ispec2Dxmin,ispec2Dxmax,ispec2Dymin,ispec2Dymax,ispec2Dzmin,ispec2Dzmax double precision ratio_eta,ratio_xi,ratio_depth,theta,colat double precision ANGULAR_WIDTH_ETA_RAD,ANGULAR_WIDTH_XI_RAD double precision lat_center_chunk, lon_center_chunk, chunk_depth,chunk_azi double precision R_EARTH,deg2rad,PI, TINYVAL,ZERO double precision x,y,z,px,py,pz double precision long,lati,x_bot,y_bot,z_bot,rayon double precision rotation_matrix(3,3), vector_ori(3), vector_rotated(3) double precision xelm(NGNOD),yelm(NGNOD),zelm(NGNOD) double precision xstore(NGLLX,NGLLY,NGLLZ),ystore(NGLLX,NGLLY,NGLLZ),zstore(NGLLX,NGLLY,NGLLZ) ! 3D shape functions and their derivatives double precision shape3D(NGNOD,NGLLX,NGLLY,NGLLZ),dershape3D(NDIM,NGNOD,NGLLX,NGLLY,NGLLZ) ! Gauss-Lobatto-Legendre points and weights of integration double precision xigll(NGLLX),yigll(NGLLY),zigll(NGLLZ),wxgll(NGLLX),wygll(NGLLY),wzgll(NGLLZ) integer nglob,kglob,ilocnum,ieoff,npointot double precision, allocatable :: xp(:),yp(:),zp(:),xgrid(:,:,:,:),ygrid(:,:,:,:), zgrid(:,:,:,:) integer, allocatable :: inum_loc(:,:,:,:),iglob(:),loc(:),current_layer(:) logical, allocatable :: ifseg(:) double precision z_bottom integer iaddx(NGNOD),iaddy(NGNOD),iaddz(NGNOD) ! boundary locator logical, dimension(:,:), allocatable :: iboun ! nb couches dans modele iasp91 ou ak135 ou prem integer nlayer parameter (nlayer=12) ! 1 couche de plus que le modele double precision zlayer(nlayer),vpv(nlayer,4),vsv(nlayer,4),density(nlayer,4) double precision, dimension(:,:), allocatable :: ProfForGemini double precision Z_DEPTH_BLOCK,UTM_X_MIN,UTM_X_MAX double precision, parameter :: GAUSSALPHA = 0.d0,GAUSSBETA = 0.d0 integer, parameter :: myrank=0 integer ilayer_current,ilayer logical test double precision, allocatable :: lon_zmin(:,:),lat_zmin(:,:) integer nlat_dsm,nlon_dsm integer iii,jjj,kkk,izshift,index_mat logical,parameter :: RUN_BENCHMARK=.false. character(len=100) line character(len=250) model1D_file !! CONVENTION : (lon,lat) -> (xi,eta) (k=6 avec -z pour le mapping sphere cubique (cf Chervot 2012) ! on definit le maillage d'un chunk dans la sphere cubique------------------------------------------------------- PI = 3.141592653589793d0 deg2rad = 3.141592653589793d0/180.d0 R_EARTH=6371000.d0 TINYVAL = 1.d-9 ZERO=0.d0 open(49,file='output_mesher_chunk.txt') if (RUN_BENCHMARK) then ! parametres codes en du pour le moment ANGULAR_WIDTH_ETA_RAD = deg2rad * 10.d0 ! latitude 2.5 ANGULAR_WIDTH_XI_RAD = deg2rad * 20.d0 ! longitude 2. ! centre du chunk lat_center_chunk= 0.d0 !42.35d0 !42.5d0 !* deg2rad lon_center_chunk=60.d0 ! 1.3d0 ! 1.2d0 !* deg2rad ! azimuth chunk_azi=0.d0 !90.d0 !80.d0 !10.d0 !* deg2rad ! depth chunk_depth = 1000.d0 *1000.d0 ! 250.d0 * 1000.d0 ! nb d'elements nel_lat = 20 !120 nel_lon = 40 !96 nel_depth = 20 !100 !nel_lat = 15 !nel_lon = 15 !nel_depth = 10 else open(10,file='ParFileMeshChunk') read(10,'(a)') line read(10,*) ANGULAR_WIDTH_XI_RAD,ANGULAR_WIDTH_ETA_RAD read(10,'(a)') line read(10,*) lon_center_chunk,lat_center_chunk,chunk_azi read(10,'(a)') line read(10,*) chunk_depth read(10,'(a)') line read(10,*) nel_lon,nel_lat,nel_depth read(10,'(a)') line read(10,'(a)') model1D_file close(10) ANGULAR_WIDTH_XI_RAD = deg2rad * ANGULAR_WIDTH_XI_RAD ANGULAR_WIDTH_ETA_RAD = deg2rad * ANGULAR_WIDTH_ETA_RAD chunk_depth = chunk_depth * 1000.d0 endif !?????chunk????????,??ParFileMeshChunk?? NX = nel_lon NY = nel_lat NZ = nel_depth !-------------------------------------------------------------------------------- !! TO DO : il faut que le chunk de refernece soit tout le temps symetrique (EW) et (NS) nlon_dsm=(ngllx-1)*NX+1 nlat_dsm=(nglly-1)*NY+1 nglob=(nel_lat+1)*(nel_lon+1)*(nel_depth+1) nspec= (nel_lat) * (nel_lon ) * (nel_depth ) npointot=8*nspec allocate(xp(npointot),yp(npointot),zp(npointot)) allocate(iglob(npointot),loc(npointot)) allocate(ifseg(npointot)) allocate(ProfForGemini(0:NZ-1,3)) allocate(current_layer(0:NZ-1)) allocate(inum_loc(2,2,2,nspec)) allocate(xgrid(2,2,2,nspec),ygrid(2,2,2,nspec),zgrid(2,2,2,nspec)) allocate(lon_zmin(nlon_dsm,nlat_dsm),lat_zmin(nlon_dsm,nlat_dsm)) ! boundary locator allocate(iboun(6,nspec)) iboun(:,:)=.false. iaddx(1)=0 iaddy(1)=0 iaddz(1)=0 iaddx(2)=1 iaddy(2)=0 iaddz(2)=0 iaddx(3)=1 iaddy(3)=1 iaddz(3)=0 iaddx(4)=0 iaddy(4)=1 iaddz(4)=0 iaddx(5)=0 iaddy(5)=0 iaddz(5)=1 iaddx(6)=1 iaddy(6)=0 iaddz(6)=1 iaddx(7)=1 iaddy(7)=1 iaddz(7)=1 iaddx(8)=0 iaddy(8)=1 iaddz(8)=1 ! ------------------------------------------------------------------------------------------------------------------------------------- ! set up coordinates of the Gauss-Lobatto-Legendre points call zwgljd(xigll,wxgll,NGLLX,GAUSSALPHA,GAUSSBETA) call zwgljd(yigll,wygll,NGLLY,GAUSSALPHA,GAUSSBETA) call zwgljd(zigll,wzgll,NGLLZ,GAUSSALPHA,GAUSSBETA) ! if number of points is odd, the middle abscissa is exactly zero if(mod(NGLLX,2) /= 0) xigll((NGLLX-1)/2+1) = ZERO if(mod(NGLLY,2) /= 0) yigll((NGLLY-1)/2+1) = ZERO if(mod(NGLLZ,2) /= 0) zigll((NGLLZ-1)/2+1) = ZERO ! get the 3-D shape functions call get_shape3D(myrank,shape3D,dershape3D,xigll,yigll,zigll,NGNOD,NGLLX,NGLLY,NGLLZ) ! matrice de rotation pour passes en coordoennees geographique !call euler_angles(rotation_matrix, lon_center_chunk,lat_center_chunk, chunk_azi) ! nouvelle matrice de rotation call compute_rotation_matrix(rotation_matrix, lon_center_chunk,lat_center_chunk, chunk_azi) !call ReadIasp91(vpv,vsv,density,zlayer,nlayer) call Read_dsm_model(model1D_file,vpv,vsv,density,zlayer,nlayer) ! calcul de la discretisation verticale des layers Z_DEPTH_BLOCK=chunk_depth /1000.d0 !!!! je passe en km call CalGridProf(ProfForGemini,current_layer,zlayer,nlayer,NZ,Z_DEPTH_BLOCK) !stop !---------------------------------------------- GRILLE DU MAILLAGE ------------------------------------------------- izshift=0 ispec = 0 kglob = 0 Ndepth=0 ispec2Dxmin=0;ispec2Dxmax=0;ispec2Dymin=0;ispec2Dymax=0;ispec2Dzmin=0;;ispec2Dzmax=0 ! fichier interface DSM - SPECFEM3D open(27,file='.recdepth') ! recepteurs sur la verticale open(28,file='stxmin');write(28,*) nlat_dsm ! face xmin open(29,file='stxmax');write(29,*) nlat_dsm ! face xmax open(30,file='stymin');write(30,*) nlon_dsm ! face ymin open(31,file='stymax'); write(31,*) nlon_dsm ! face ymax open(38,file='IgXmin') open(39,file='IgXmax') open(40,file='IgYmin') open(41,file='IgYmax') open(42,file='IgZmin') ! MESH pour SPECFEM3D open(86,file='nummaterial_velocity_file') open(87,file='materials_file') !open(88,file='model_1D.in') open(89,file='flags_boundary.txt') open(90,file='Nb_ielm_faces.txt') open(88,file='OrigRepSpecfm') write(88,*) lon_center_chunk,lat_center_chunk write(88,*) chunk_azi, ANGULAR_WIDTH_XI_RAD/deg2rad,ANGULAR_WIDTH_ETA_RAD/deg2rad close(88) !open(32,file='gll_zmin') !open(125,file='ggl_elemts') ! boucle sur la grille des elements spectraux ilayer=0 index_mat=0 do iz =0,nel_depth-1 ilayer_current=current_layer(iz)-1 ! attention entre piquets et intervalles !!!!! if (iz/=0) then if (current_layer(iz-1)/=current_layer(iz)) then izshift=izshift+1 ! on repete le point sur l'interface pour DSM index_mat=index_mat-1 write(86,'(a1,2x,i10,2x,a10,2x,a7,2x,a20,2x,a1)') & '2',index_mat,'tomography','elastic','tomography_model.xyz','1' endif else ! on ecrit le premier materiau index_mat=index_mat-1 write(86,'(a1,2x,i10,2x,a10,2x,a7,2x,a20,2x,a1)') & '2',index_mat,'tomography','elastic','tomography_model.xyz','1' endif do ilat=0,nel_lat-1 do ilon=0,nel_lon-1 ispec = ispec + 1 ! mateiral file write(87 ,*) ispec,index_mat ! get boundary !on boundary 1: x=xmin if(ilon == 0 ) then iboun(1,ispec)=.true. ispec2Dxmin=ispec2Dxmin+1 write(89,*) ispec,ispec2Dxmin,1 endif ! on boundary 2: xmax if(ilon == nel_lon-1) then iboun(2,ispec)=.true. ispec2Dxmax=ispec2Dxmax+1 !write(*,*) '------ TOZ',ispec,ilon write(89,*) ispec,ispec2Dxmax,2 endif ! on boundary 3: ymin if(ilat == 0) then iboun(3,ispec)=.true. ispec2Dymin=ispec2Dymin+1 write(89,*) ispec,ispec2Dymin,3 endif ! on boundary 4: ymax if(ilat == nel_lat-1 ) then iboun(4,ispec) =.true. ispec2Dymax=ispec2Dymax+1 write(89,*) ispec,ispec2Dymax,4 endif ! on boundary 5: bottom if(iz == 0) then iboun(5,ispec)=.true. ispec2Dzmin=ispec2Dzmin+1 write(89,*) ispec,ispec2Dzmin,5 endif ! on boundary 6: top if(iz == nel_depth-1) then ispec2Dzmax= ispec2Dzmax+1 iboun(6,ispec)=.true. endif ! 8 sommet de l'element ispec do ia=1,NGNOD i=iaddx(ia) j=iaddy(ia) k=iaddz(ia) z = 1000d0*ProfForGemini(iz,1+k) ! longitude ratio_xi = (dble(ilon+i)) / dble(NX) x = 2.d0*ratio_xi-1.d0 x = tan((ANGULAR_WIDTH_XI_RAD/2.d0) * x) ! latitude ratio_eta = (dble(ilat+j)) / dble(NY) y = 2.d0*ratio_eta-1.d0 y = tan((ANGULAR_WIDTH_ETA_RAD/2.d0) * y) !if (ilat==0.and.iz==0) write(49,*) ia,i,ratio_xi !mapping sphere cubique (k=5) (Chevrot et al 2012) (il y a un signe oppose) !pz = z/dsqrt(1.d0 + y*y + x*x) !px = x*pz !py = y*pz ! mapping qui permet d'avoir le chunk au pole Nord ! mapping sphere cubique (k=6, Chevrot at al 2012, avec -z) pz= z/dsqrt(1.d0 + y*y + x*x) !(=r/s) px= pz * x !(tan(xi) * r/s) py= pz * y !(tan(eta) * r/s) ! ancienne version xgrid(i+1,j+1,k+1,ispec) = px !px ygrid(i+1,j+1,k+1,ispec) = py !py zgrid(i+1,j+1,k+1,ispec) = pz !xgrid(i+1,j+1,k+1,ispec) = py ! long !ygrid(i+1,j+1,k+1,ispec) = pz ! lat !zgrid(i+1,j+1,k+1,ispec) = px ! prof xelm(ia)=xgrid(i+1,j+1,k+1,ispec) yelm(ia)=ygrid(i+1,j+1,k+1,ispec) zelm(ia)=zgrid(i+1,j+1,k+1,ispec) enddo ! INTERFACE POUR DSM ------ ! recepteurs verticaux if (ilat==0 .and. ilon==0) then call calc_gll_points(xelm,yelm,zelm,xstore,ystore,zstore,shape3D,NGNOD,NGLLX,NGLLY,NGLLZ) call write_gllz_points(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,current_layer,nel_depth,ilayer,iz,Ndepth) endif ! recepteurs horizontaux ! stxmin if (ilon==0.and.iz==nel_depth-1) then call calc_gll_points(xelm,yelm,zelm,xstore,ystore,zstore,shape3D,NGNOD,NGLLX,NGLLY,NGLLZ) if (ilat==nel_lat-1) then ! ce test sert a rajouter le dernier point GLL test=.true. else test=.false. endif call write_stxmin(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,rotation_matrix,test) endif if (ilon==0) call write_Igm_file(38,ispec2Dxmin,NGLLY,NGLLZ,ilat,iz,izshift,ilayer_current) ! stxmax if (ilon==nel_lon - 1 .and. iz==nel_depth-1) then call calc_gll_points(xelm,yelm,zelm,xstore,ystore,zstore,shape3D,NGNOD,NGLLX,NGLLY,NGLLZ) if (ilat==nel_lat-1) then ! ce test sert a rajouter le dernier point GLL test=.true. else test=.false. endif call write_stxmax(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,rotation_matrix,test) endif if (ilon==nel_lon-1) call write_Igm_file(39,ispec2Dxmax,NGLLY,NGLLZ,ilat,iz,izshift,ilayer_current) ! stymin if (ilat==0.and. iz==nel_depth-1) then call calc_gll_points(xelm,yelm,zelm,xstore,ystore,zstore,shape3D,NGNOD,NGLLX,NGLLY,NGLLZ) if (ilon==nel_lon-1) then ! ce test sert a rajouter le dernier point GLL test=.true. else test=.false. endif call write_stymin(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,rotation_matrix,test) endif if (ilat==0) call write_Igm_file(40,ispec2Dymin,NGLLX,NGLLZ,ilon,iz,izshift,ilayer_current) ! stymax if (ilat==nel_lat-1.and. iz==nel_depth-1) then call calc_gll_points(xelm,yelm,zelm,xstore,ystore,zstore,shape3D,NGNOD,NGLLX,NGLLY,NGLLZ) if (ilon==nel_lon-1) then ! ce test sert a rajouter le dernier point GLL test=.true. else test=.false. endif call write_stymax(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,rotation_matrix,test) endif if (ilat==nel_lat-1) call write_Igm_file(41,ispec2Dymax,NGLLX,NGLLZ,ilon,iz,izshift,ilayer_current) ! stzmin if (iz==0) then ! pas besoin du test comme precedemment car je stocke tout dans des tableaux et c'est pas ! grave si on recrit les memes choses call calc_gll_points(xelm,yelm,zelm,xstore,ystore,zstore,shape3D,NGNOD,NGLLX,NGLLY,NGLLZ) call write_Igm_file(42,ispec2Dzmin,NGLLX,NGLLY,ilon,ilat,0,ilayer_current) !open(125,file='ggl_elemts') !!$ do kkk=1,1!NGLLZ !!$ do jjj=1,NGLLY !!$ do iii=1,NGLLX !!$ write(125,'(3f20.10)') xstore(iii,jjj,kkk)/1000.d0, ystore(iii,jjj,kkk)/1000.d0, zstore(iii,jjj,kkk)/1000.d0 !!$ !write(*,*) xstore !!$ enddo !!$ enddo !!$ enddo !close(125) ! read(*,*) ia call store_zmin_points(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,rotation_matrix,& lon_zmin,lat_zmin,nlon_dsm,nlat_dsm,ilon,ilat,nel_lon,nel_lat) endif enddo enddo enddo close(27) close(28) close(29) close(30) close(31) !close(32) ! ecriture des profondeurs de calcul pour DSM call write_recdepth_dsm(Ndepth,R_EARTH) ! ecriture de stzmin call write_stzmin(lon_zmin,lat_zmin,nlon_dsm,nlat_dsm) ! z_bottom = minval(zgrid(:,:,:,:)) zgrid(:,:,:,:) = zgrid(:,:,:,:) - z_bottom UTM_X_MIN=minval(xgrid) UTM_X_MAX=maxval(xgrid) ! modele 1D open(88,file='model_1D.in') write(88,*) nlayer,4 do i=1,nlayer write(88,*) zlayer(i) write(88,'(4f20.10)') vpv(i,:) write(88,'(4f20.10)') vsv(i,:) write(88,'(4f20.10)') density(i,:) enddo write(88,*) z_bottom write(88,*) lon_center_chunk, lat_center_chunk, chunk_azi close(88) !-------------------------------------------- NUMEROTATION DES POINTS DE LA GRILLE --------------------------------------------------------------- ! on stocke touts les points de tous les elements do ispec=1,nspec ieoff = 8 * (ispec - 1) ilocnum = 0 do k=1,2 do j=1,2 do i=1,2 ilocnum = ilocnum + 1 xp(ilocnum + ieoff)= xgrid(i,j,k,ispec) yp(ilocnum + ieoff)= ygrid(i,j,k,ispec) zp(ilocnum + ieoff)= zgrid(i,j,k,ispec) enddo enddo enddo enddo ! on identifie les points semblables et on les numerote call get_global1(nspec,xp,yp,zp,iglob,loc,ifseg,nglob,npointot,UTM_X_MIN,UTM_X_MAX) deallocate(xp,yp,zp) allocate(xp(nglob),yp(nglob),zp(nglob)) ! on ne stocke que les points de la grille et leur numeros do ispec=1,nspec ieoff = 8 * (ispec - 1) ilocnum = 0 do k=1,2 do j=1,2 do i=1,2 ilocnum=ilocnum+1 inum_loc(i,j,k,ispec) = iglob(ilocnum+ieoff) xp(iglob(ilocnum+ieoff)) = xgrid(i,j,k,ispec) yp(iglob(ilocnum+ieoff)) = ygrid(i,j,k,ispec) zp(iglob(ilocnum+ieoff)) = zgrid(i,j,k,ispec) enddo enddo enddo enddo !--------------------------------------------------------------------------------------------------------------------------------------------------------------------- write(90,*) ispec2Dxmin write(90,*) ispec2Dxmax write(90,*) ispec2Dymin write(90,*) ispec2Dymax write(90,*) ispec2Dzmin close(27) close(28) close(29) close(30) close(31) close(32) close(37) close(38) close(39) close(40) close(41) close(42) close(81) close(82) close(83) close(84) close(85) close(86) close(87) close(88) close(89) close(90) !stop ! -------------------------------- SAUVEGARDE DES MESH FILES -------------------------------------------------------------------------------- open(27,file='nodes_coords_file') write(27,*) nglob ! nb de sommets do kglob=1,nglob write(27,'(i14,3x,3(f20.5,1x))') kglob,xp(kglob),yp(kglob),zp(kglob) enddo close(27) open(27,file='mesh_file') write(27,*) nspec do ispec=1,nspec write(27,'(9i15)') ispec,inum_loc(1,1,1,ispec),inum_loc(2,1,1,ispec),& inum_loc(2,2,1,ispec),inum_loc(1,2,1,ispec),& inum_loc(1,1,2,ispec),inum_loc(2,1,2,ispec),& inum_loc(2,2,2,ispec),inum_loc(1,2,2,ispec) enddo close(27) ! open(27,file='absorbing_surface_file_xmin') write(27,*) ispec2Dxmin do ispec=1,nspec if (iboun(1,ispec)) write(27,'(5(i10,1x))') ispec,inum_loc(1,1,1,ispec),inum_loc(1,2,1,ispec),& inum_loc(1,2,2,ispec),inum_loc(1,1,2,ispec) enddo close(27) open(27,file='absorbing_surface_file_xmax') write(27,*) ispec2Dxmax do ispec=1,nspec if (iboun(2,ispec)) write(27,'(5(i10,1x))') ispec,inum_loc(2,1,1,ispec),inum_loc(2,2,1,ispec),& inum_loc(2,2,2,ispec),inum_loc(2,1,2,ispec) enddo close(27) open(27,file='absorbing_surface_file_ymin') write(27,*) ispec2Dymin do ispec=1,nspec if (iboun(3,ispec)) write(27,'(5(i10,1x))') ispec,inum_loc(1,1,1,ispec),inum_loc(2,1,1,ispec),& inum_loc(2,1,2,ispec),inum_loc(1,1,2,ispec) enddo close(27) open(27,file='absorbing_surface_file_ymax') write(27,*) ispec2Dymax do ispec=1,nspec if (iboun(4,ispec)) write(27,'(5(i10,1x))') ispec,inum_loc(1,2,1,ispec),inum_loc(2,2,1,ispec),& inum_loc(2,2,2,ispec),inum_loc(1,2,2,ispec) enddo close(27) open(27,file='absorbing_surface_file_bottom') write(27,*) ispec2Dzmin do ispec=1,nspec if (iboun(5,ispec)) write(27,'(5(i10,1x))') ispec,inum_loc(1,1,1,ispec),inum_loc(1,2,1,ispec),& inum_loc(2,2,1,ispec),inum_loc(2,1,1,ispec) enddo close(27) open(27,file='free_surface') write(27,*) ispec2Dzmax do ispec=1,nspec if (iboun(1,ispec)) write(27,'(5(i10,1x))') ispec,inum_loc(1,1,2,ispec),inum_loc(1,2,2,ispec),& inum_loc(2,2,2,ispec),inum_loc(2,1,2,ispec) enddo close(27) close(49) write(*,*) 'END ' stop end program mesh_chunk !===================================================================== ! compute the Euler angles and the associated rotation matrix subroutine euler_angles(rotation_matrix,CENTER_LONGITUDE_IN_DEGREES,CENTER_LATITUDE_IN_DEGREES,GAMMA_ROTATION_AZIMUTH) implicit none !include "constants.h" double precision rotation_matrix(3,3) double precision CENTER_LONGITUDE_IN_DEGREES,CENTER_LATITUDE_IN_DEGREES,GAMMA_ROTATION_AZIMUTH double precision alpha,beta,gamma double precision sina,cosa,sinb,cosb,sing,cosg double precision DEGREES_TO_RADIANS DEGREES_TO_RADIANS = 3.141592653589793d0/180.d0 ! compute colatitude and longitude and convert to radians alpha = CENTER_LONGITUDE_IN_DEGREES * DEGREES_TO_RADIANS beta = (90.0d0 - CENTER_LATITUDE_IN_DEGREES) * DEGREES_TO_RADIANS gamma = GAMMA_ROTATION_AZIMUTH * DEGREES_TO_RADIANS sina = dsin(alpha) cosa = dcos(alpha) sinb = dsin(beta) cosb = dcos(beta) sing = dsin(gamma) cosg = dcos(gamma) ! define rotation matrix rotation_matrix(1,1) = cosg*cosb*cosa-sing*sina rotation_matrix(1,2) = -sing*cosb*cosa-cosg*sina rotation_matrix(1,3) = sinb*cosa rotation_matrix(2,1) = cosg*cosb*sina+sing*cosa rotation_matrix(2,2) = -sing*cosb*sina+cosg*cosa rotation_matrix(2,3) = sinb*sina rotation_matrix(3,1) = -cosg*sinb rotation_matrix(3,2) = sing*sinb rotation_matrix(3,3) = cosb end subroutine euler_angles subroutine write_gllz_points(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,current_layer,nel_depth,ilayer,iz,Ndepth) implicit none integer NGLLX,NGLLY,NGLLZ,nel_depth,iz,Ndepth double precision xstore(NGLLX,NGLLY,NGLLZ),ystore(NGLLX,NGLLY,NGLLZ),zstore(NGLLX,NGLLY,NGLLZ) double precision profondeur integer current_layer(0:nel_depth-1),ilayer,k !write(*,*) ilayer, current_layer(iz) !profondeur = dsqrt(xstore(1,1,k)**2 + ystore(1,1,k)**2 + (zstore(1,1,k) )**2 ) !write(27,*) profondeur/1000., ilayer if (ilayer == current_layer(iz)) then do k=2,NGLLZ profondeur = dsqrt(xstore(1,1,k)**2 + ystore(1,1,k)**2 + (zstore(1,1,k) )**2 ) write(27,*) profondeur/1000., ilayer-1,1 Ndepth=Ndepth+1 enddo else ! new layer k=1 profondeur = dsqrt(xstore(1,1,k)**2 + ystore(1,1,k)**2 + (zstore(1,1,k) )**2 ) if (ilayer==0) then ilayer = current_layer(iz) write(27,*) profondeur/1000., ilayer-1,1 Ndepth=Ndepth+1 else ilayer = current_layer(iz) write(27,*) profondeur/1000., ilayer-1,-1 Ndepth=Ndepth+1 endif do k=2,NGLLZ ! on duplique le dernier point profondeur = dsqrt(xstore(1,1,k)**2 + ystore(1,1,k)**2 + (zstore(1,1,k) )**2 ) write(27,*) profondeur/1000., ilayer-1,1 Ndepth=Ndepth+1 enddo endif end subroutine write_gllz_points subroutine write_recdepth_dsm(Ndepth,R_EARTH) implicit none integer Ndepth,i double precision R_EARTH,prof double precision, allocatable :: z(:) integer, allocatable :: zindex(:),ziflag(:) integer ilayer,flag open(27,file='.recdepth') allocate(zindex(Ndepth),ziflag(Ndepth)) allocate(z(Ndepth)) do i=1,Ndepth read(27,*) prof,ilayer,flag z(Ndepth-i+1)=R_EARTH/1000.d0-prof zindex(Ndepth-i+1)=ilayer ziflag(Ndepth-i+1)=flag enddo close(27) open(27,file='recdepth') write(27,*) Ndepth i=1 write(27,*) z(i),zindex(i),ziflag(i) do i=2,Ndepth-1 if (ziflag(i-1) == -1 ) then write(27,*) z(i),zindex(i),-1 else write(27,*) z(i),zindex(i),1 endif enddo i=Ndepth write(27,*) z(i),zindex(i),ziflag(i) end subroutine write_recdepth_dsm subroutine write_stxmin(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,rotation_matrix,test) implicit none integer NDIM,NGLLX,NGLLY,NGLLZ,jgll,i,j,NGLLY_eff double precision xstore(NGLLX,NGLLY,NGLLZ),ystore(NGLLX,NGLLY,NGLLZ),zstore(NGLLX,NGLLY,NGLLZ) double precision rotation_matrix(3,3) double precision vector_ori(3),vector_rotated(3) double precision rayon,x,y,z,deg2rad,long,lati logical test deg2rad=3.141592653589793d0/180.d0 NDIM=3 if (test) then NGLLY_eff = NGLLY else NGLLY_eff = NGLLY - 1 endif do jgll=1,NGLLY_eff vector_ori(1)=xstore(1,jgll,NGLLZ) vector_ori(2)=ystore(1,jgll,NGLLZ) vector_ori(3)=zstore(1,jgll,NGLLZ) do i = 1,NDIM vector_rotated(i) = 0.d0 do j = 1,NDIM vector_rotated(i) = vector_rotated(i) + rotation_matrix(i,j)*vector_ori(j) enddo enddo x=vector_rotated(1);y=vector_rotated(2);z=vector_rotated(3) rayon = dsqrt(vector_rotated(1)**2 + vector_rotated(2)**2 + vector_rotated(3)**2) long=atan2(y,x) lati=asin(z/rayon) ! passage de geocentique a geographique !!theta = PI/2.D0 - lati ! convert the geocentric colatitude to a geographic colatitude !!colat = PI/2.0d0 - datan(1.006760466d0*dcos(theta)/dmax1(TINYVAL,dsin(theta))) !!lati = PI/2.0d0 - colat !write(28,*) xstore(1,jgll,NGLLZ), ystore(1,jgll,NGLLZ), zstore(1,jgll,NGLLZ)!x,y !long/deg2rad,lati/deg2rad write(28,*) long/deg2rad,lati/deg2rad !,rayon/1000 !write(38,'()') 1,(NGLLY-1)*jy_elm+jgll write(49,*) write(49,*) vector_ori(:) write(49,*) vector_rotated(:) enddo end subroutine write_stxmin subroutine write_stxmax(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,rotation_matrix,test) implicit none integer NDIM,NGLLX,NGLLY,NGLLZ,jgll,i,j,NGLLY_eff double precision xstore(NGLLX,NGLLY,NGLLZ),ystore(NGLLX,NGLLY,NGLLZ),zstore(NGLLX,NGLLY,NGLLZ) double precision rotation_matrix(3,3) double precision vector_ori(3),vector_rotated(3) double precision rayon,x,y,z,deg2rad,long,lati logical test if (test) then NGLLY_eff = NGLLY else NGLLY_eff = NGLLY - 1 endif deg2rad=3.141592653589793d0/180.d0 NDIM=3 do jgll=1,NGLLY_eff vector_ori(1)=xstore(NGLLX,jgll,NGLLZ) vector_ori(2)=ystore(NGLLX,jgll,NGLLZ) vector_ori(3) =zstore(NGLLX,jgll,NGLLZ) do i = 1,NDIM vector_rotated(i) = 0.d0 do j = 1,NDIM vector_rotated(i) = vector_rotated(i) + rotation_matrix(i,j)*vector_ori(j) enddo enddo x=vector_rotated(1);y=vector_rotated(2);z=vector_rotated(3) rayon = dsqrt(vector_rotated(1)**2 + vector_rotated(2)**2 + vector_rotated(3)**2) long=atan2(y,x) lati=asin(z/rayon) ! passage de geocentique a geographique !!theta = PI/2.D0 - lati ! convert the geocentric colatitude to a geographic colatitude !!colat = PI/2.0d0 - datan(1.006760466d0*dcos(theta)/dmax1(TINYVAL,dsin(theta))) !!lati = PI/2.0d0 - colat !write(28,*) xstore(1,jgll,NGLLZ), ystore(1,jgll,NGLLZ), zstore(1,jgll,NGLLZ)!x,y !long/deg2rad,lati/deg2rad write(29,*) long/deg2rad,lati/deg2rad !,rayon/1000 enddo end subroutine write_stxmax subroutine write_stymin(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,rotation_matrix,test) implicit none integer NDIM,NGLLX,NGLLY,NGLLZ,jgll,i,j,NGLLX_eff double precision xstore(NGLLX,NGLLY,NGLLZ),ystore(NGLLX,NGLLY,NGLLZ),zstore(NGLLX,NGLLY,NGLLZ) double precision rotation_matrix(3,3) double precision vector_ori(3),vector_rotated(3) double precision rayon,x,y,z,deg2rad,long,lati logical test deg2rad=3.141592653589793d0/180.d0 NDIM=3 if (test) then NGLLX_eff = NGLLX else NGLLX_eff = NGLLX - 1 endif do jgll=1,NGLLX_eff vector_ori(1)=xstore(jgll,1,NGLLZ) vector_ori(2)=ystore(jgll,1,NGLLZ) vector_ori(3) =zstore(jgll,1,NGLLZ) do i = 1,NDIM vector_rotated(i) = 0.d0 do j = 1,NDIM vector_rotated(i) = vector_rotated(i) + rotation_matrix(i,j)*vector_ori(j) enddo enddo x=vector_rotated(1);y=vector_rotated(2);z=vector_rotated(3) rayon = dsqrt(vector_rotated(1)**2 + vector_rotated(2)**2 + vector_rotated(3)**2) long=atan2(y,x) lati=asin(z/rayon) ! passage de geocentique a geographique !!theta = PI/2.D0 - lati ! convert the geocentric colatitude to a geographic colatitude !!colat = PI/2.0d0 - datan(1.006760466d0*dcos(theta)/dmax1(TINYVAL,dsin(theta))) !!lati = PI/2.0d0 - colat !write(28,*) xstore(1,jgll,NGLLZ), ystore(1,jgll,NGLLZ), zstore(1,jgll,NGLLZ)!x,y !long/deg2rad,lati/deg2rad write(30,*) long/deg2rad,lati/deg2rad !,rayon/1000 enddo end subroutine write_stymin subroutine write_stymax(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,rotation_matrix,test) implicit none integer NDIM,NGLLX,NGLLY,NGLLZ,jgll,i,j,NGLLX_eff double precision xstore(NGLLX,NGLLY,NGLLZ),ystore(NGLLX,NGLLY,NGLLZ),zstore(NGLLX,NGLLY,NGLLZ) double precision rotation_matrix(3,3) double precision vector_ori(3),vector_rotated(3) double precision rayon,x,y,z,deg2rad,long,lati logical test if (test) then NGLLX_eff = NGLLX else NGLLX_eff = NGLLX - 1 endif deg2rad=3.141592653589793d0/180.d0 NDIM=3 do jgll=1,NGLLX_eff vector_ori(1)=xstore(jgll,NGLLY,NGLLZ) vector_ori(2)=ystore(jgll,NGLLY,NGLLZ) vector_ori(3) =zstore(jgll,NGLLY,NGLLZ) do i = 1,NDIM vector_rotated(i) = 0.d0 do j = 1,NDIM vector_rotated(i) = vector_rotated(i) + rotation_matrix(i,j)*vector_ori(j) enddo enddo x=vector_rotated(1);y=vector_rotated(2);z=vector_rotated(3) rayon = dsqrt(vector_rotated(1)**2 + vector_rotated(2)**2 + vector_rotated(3)**2) long=atan2(y,x) lati=asin(z/rayon) ! passage de geocentique a geographique !!theta = PI/2.D0 - lati ! convert the geocentric colatitude to a geographic colatitude !!colat = PI/2.0d0 - datan(1.006760466d0*dcos(theta)/dmax1(TINYVAL,dsin(theta))) !!lati = PI/2.0d0 - colat !write(28,*) xstore(1,jgll,NGLLZ), ystore(1,jgll,NGLLZ), zstore(1,jgll,NGLLZ)!x,y !long/deg2rad,lati/deg2rad write(31,*) long/deg2rad,lati/deg2rad !,rayon/1000 enddo end subroutine write_stymax subroutine store_zmin_points(xstore,ystore,zstore,NGLLX,NGLLY,NGLLZ,rotation_matrix,& lon_zmin,lat_zmin,nlon_dsm,nlat_dsm,ilon,ilat,nel_lon,nel_lat) implicit none integer NDIM,NGLLX,NGLLY,NGLLZ,igll,jgll,i,j,NGLLX_eff integer ilon,ilat,nel_lon,nel_lat,iglob,jglob,nlat_dsm,nlon_dsm double precision xstore(NGLLX,NGLLY,NGLLZ),ystore(NGLLX,NGLLY,NGLLZ),zstore(NGLLX,NGLLY,NGLLZ) double precision rotation_matrix(3,3) double precision vector_ori(3),vector_rotated(3) double precision rayon,x,y,z,deg2rad,long,lati double precision lon_zmin(nlon_dsm,nlat_dsm),lat_zmin(nlon_dsm,nlat_dsm) logical test deg2rad=3.141592653589793d0/180.d0 NDIM=3 do jgll=1,NGLLY do igll=1,NGLLX vector_ori(1)=xstore(igll,jgll,1) vector_ori(2)=ystore(igll,jgll,1) vector_ori(3) =zstore(igll,jgll,1) do i = 1,NDIM vector_rotated(i) = 0.d0 do j = 1,NDIM vector_rotated(i) = vector_rotated(i) + rotation_matrix(i,j)*vector_ori(j) enddo enddo x=vector_rotated(1);y=vector_rotated(2);z=vector_rotated(3) rayon = dsqrt(vector_rotated(1)**2 + vector_rotated(2)**2 + vector_rotated(3)**2) long=atan2(y,x) lati=asin(z/rayon) ! passage de geocentique a geographique !!theta = PI/2.D0 - lati ! convert the geocentric colatitude to a geographic colatitude !!colat = PI/2.0d0 - datan(1.006760466d0*dcos(theta)/dmax1(TINYVAL,dsin(theta))) !!lati = PI/2.0d0 - colat !write(28,*) xstore(1,jgll,NGLLZ), ystore(1,jgll,NGLLZ), zstore(1,jgll,NGLLZ)!x,y !long/deg2rad,lati/deg2rad !write(31,*) long/deg2rad,lati/deg2rad !,rayon/1000 iglob=(ilon)*(NGLLX-1)+igll jglob=(ilat)*(NGLLY-1)+jgll lon_zmin(iglob,jglob)= long/deg2rad lat_zmin(iglob,jglob)= lati/deg2rad !write(32,'(3f20.10)') xstore(igll,jgll,1)/1000.d0, ystore(igll,jgll,1)/1000.d0,zstore(igll,jgll,1)/1000.d0 !write(32,*) xstore(igll,jgll,NGLLZ), ystore(igll,igll,NGLLZ),zstore(igll,jgll,NGLLZ) enddo enddo end subroutine store_zmin_points subroutine write_stzmin(x,y,nx,ny) implicit none integer i,j,nx,ny double precision x(nx,ny),y(nx,ny) open(27,file='stzmin') write(27,*) nx*ny do j=1,ny do i=1,nx write(27,*) x(i,j),y(i,j) enddo enddo close(27) end subroutine write_stzmin subroutine write_Igm_file(iunit,ispec2D,NGLL1,NGLL2,ie,je,js,il) implicit none integer iunit,ispec2D,NGLL1,NGLL2,ie,je,js,il integer i,j do j=1,NGLL2 do i=1,NGLL1 write(iunit,*) i,j,ispec2D,(NGLL1-1)*ie+i,(NGLL2-1)*je+j+js,il enddo enddo end subroutine write_Igm_file subroutine compute_rotation_matrix(rotation_matrix, lon_center_chunk,lat_center_chunk, chunk_azi) implicit none double precision rotation_matrix(3,3),lon_center_chunk,lat_center_chunk, chunk_azi double precision R0(3,3),R1(3,3),R2(3,3),axe_rotation(3),R00(3,3) ! je met le chunk en 0,0 axe_rotation(1)=0.d0; axe_rotation(2)=1.d0; axe_rotation(3)=0.d0 call rotation_matrix_axe(R00,axe_rotation,90.d0) ! je ramene le chunk en (0,0) ! rotation de l'azimuth du chunk axe_rotation(1)=1.d0; axe_rotation(2)=0.d0; axe_rotation(3)=0.d0 call rotation_matrix_axe(R0,axe_rotation,90.-chunk_azi) ! on met le chunk a la bonne latitude axe_rotation(1)=0.d0; axe_rotation(2)=-1.d0; axe_rotation(3)=0.d0 call rotation_matrix_axe(R1,axe_rotation,lat_center_chunk) ! on met le chunk a la bonne longitude axe_rotation(1)=0.d0; axe_rotation(2)=0.d0; axe_rotation(3)=1.d0 call rotation_matrix_axe(R2,axe_rotation, lon_center_chunk) ! rotation resultante call compose4matrix(rotation_matrix,R00,R0,R1,R2) end subroutine compute_rotation_matrix ! ! ! ROUTINES POUR FAIRE DES ROTATIONS 3D ET DIVERS CHANGEMENTS DE REPERES ! ! Vadim Monteiller Mars 2013 ! !------------------------------------------------------------------------------- ! matrice de rotation 3D d'axe "axe" et d'angle theta (degrees) ! cette matrice est en complexe subroutine rotation_matrix_axe(R,axe,theta) implicit none double precision axe(3),theta,pi,deg2rad double precision R(3,3) double precision c,s,ux,uy,uz,norme_axe integer i,j pi=3.1415926535897932d0 deg2rad = pi / 180.d0 ! on normalise l'axe norme_axe=dsqrt(axe(1)**2 + axe(2)**2 + axe(3)**2) ! composantes de l'axe ux=axe(1)/norme_axe uy=axe(2)/norme_axe uz=axe(3)/norme_axe ! on calcule le cos et sin c=dcos(deg2rad * theta);s=dsin(deg2rad * theta) ! matrice de rotation complexe R(1,1)=(ux**2 + (1.d0-ux**2)*c) R(1,2)=(ux*uy*(1.d0-c)-uz*s) R(1,3)=(ux*uy*(1.d0-c)+uy*s) R(2,1)=(ux*uy*(1.d0-c)+uz*s) R(2,2)=(uy**2+(1.d0-uy**2)*c) R(2,3)=(uy*uz*(1.d0-c)-ux*s) R(3,1)=(ux*uz*(1.d0-c)-uy*s) R(3,2)=(uy*uz*(1.d0-c)+ux*s) R(3,3)=(uz**2+(1.d0-uz**2)*c) write(49,*) ' MATRICE ROTATION ' write(49,*) R(1,:) write(49,*) R(2,:) write(49,*) R(3,:) write(49,*) end subroutine rotation_matrix_axe !------------------------------------------------------------------------------- ! R=R2*R1*R0 subroutine compose4matrix(R,R00,R0,R1,R2) implicit none double precision R(3,3),R0(3,3),R1(3,3),R2(3,3),R00(3,3),Rtmp(3,3) integer i,j,k R(:,:)=0.d0 ! multiplication R=R0*R00 do j=1,3 do i=1,3 do k=1,3 R(i,j)=R(i,j) + R0(i,k)*R00(k,j) enddo enddo enddo ! multiplication R=R1*R Rtmp=R R(:,:)=0.d0 do j=1,3 do i=1,3 do k=1,3 R(i,j)=R(i,j) + R1(i,k)*Rtmp(k,j) enddo enddo enddo ! multiplication R=R2*R Rtmp=R R(:,:)=0.d0 do j=1,3 do i=1,3 do k=1,3 R(i,j)=R(i,j) + R2(i,k)*Rtmp(k,j) enddo enddo enddo write(49,*) ' MATRICE ROTATION COMPLETE ' write(49,*) R(1,:) write(49,*) R(2,:) write(49,*) R(3,:) write(49,*) end subroutine compose4matrix !------------------------------------------------------------------------------ ! rotation pour passer d'un repere local a un autre
gpl-2.0
T-J-Teru/binutils-gdb
gdb/testsuite/gdb.fortran/pointer-to-pointer.f90
5
1072
! Copyright 2020-2022 Free Software Foundation, Inc. ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 3 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. program allocate_array type l_buffer real, dimension(:), pointer :: alpha end type l_buffer type(l_buffer), pointer :: buffer allocate (buffer) allocate (buffer%alpha (5)) buffer%alpha (1) = 1.5 buffer%alpha (2) = 2.5 buffer%alpha (3) = 3.5 buffer%alpha (4) = 4.5 buffer%alpha (5) = 5.5 print *, buffer%alpha ! Break Here. end program allocate_array
gpl-2.0
kbai/specfem3d
utils/Cubit_or_Gmsh/multiply_coordinates_of_the_whole_mesh_by_1000.f90
4
3536
!===================================================================== ! ! S p e c f e m 3 D V e r s i o n 3 . 0 ! --------------------------------------- ! ! Main historical authors: Dimitri Komatitsch and Jeroen Tromp ! Princeton University, USA ! and CNRS / University of Marseille, France ! (there are currently many more authors!) ! (c) Princeton University and CNRS / University of Marseille, July 2012 ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along ! with this program; if not, write to the Free Software Foundation, Inc., ! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ! !===================================================================== ! read an external mesh file and multiply its coordinates by 1000, ! for instance when it has been created in kilometers but the user wants it in meters ! Dimitri Komatitsch, CNRS, Marseille, France, June 2015. program multiply_coordinates_by_1000 implicit none ! ! work in single or in double precision (4 or 8 bytes) ! integer, parameter :: CUSTOM_REAL = 4 ! 8 !------------------------------------------------------------------------------------------------ integer, parameter :: NGNOD = 8 ! number of control nodes for hexahedral elements (can only be 8 or 27) character(len=*), parameter :: nodes_coords_file = 'MESH/nodes_coords_file' character(len=*), parameter :: nodes_coords_file_new = 'MESH/nodes_coords_file_new' !------------------------------------------------------------------------------------------------ integer :: NGLOB ! number of nodes integer :: i,iread,ier real(kind=CUSTOM_REAL) :: xtmp,ytmp,ztmp if (NGNOD /= 8) then print *,'error: multiply_coordinates_by_1000 only supports NGNOD == 8 for now' stop 'error in multiply_coordinates_by_1000' endif ! read the mesh print * print *,'start reading the existing node coordinate file: ',nodes_coords_file(1:len_trim(nodes_coords_file)) print *,'and writing the new one multiplied by 1000: ',nodes_coords_file_new(1:len_trim(nodes_coords_file_new)) open(unit=10,file=nodes_coords_file,status='old',action='read') open(unit=11,file=nodes_coords_file_new,status='unknown',action='write') read(10,*) NGLOB print *,' number of points: ',NGLOB write(11,*) NGLOB do i = 1,NGLOB ! gets node ID and position read(10,*,iostat=ier) iread,xtmp,ytmp,ztmp ! check if (ier /= 0) then print *,'error point read:',i,iread,xtmp,ytmp,ztmp stop 'error while reading points' endif ! checks if out-of-range if (iread < 1 .or. iread > NGLOB) then print *,'error at i,iread = ',i,iread stop 'wrong ID input for a point' endif ! write the new values multiplied by 1000 write(11,*) iread,xtmp*1000._CUSTOM_REAL,ytmp*1000._CUSTOM_REAL,ztmp*1000._CUSTOM_REAL enddo close(10) close(11) end program multiply_coordinates_by_1000
gpl-2.0
skywalker00/sabermod_rom_toolchain
gcc/testsuite/gfortran.dg/c_funloc_tests_6.f90
30
1065
! { dg-do compile } ! { dg-options "-std=f2008" } ! ! Check relaxed TS29113 constraints for procedures ! and c_f_*pointer argument checking for c_ptr/c_funptr. ! use iso_c_binding implicit none type(c_ptr) :: cp type(c_funptr) :: cfp interface subroutine sub() bind(C) end subroutine sub end interface integer(c_int), pointer :: int procedure(sub), pointer :: fsub integer, external :: noCsub procedure(integer), pointer :: fint cp = c_funloc (sub) ! { dg-error "Can't convert TYPE.c_funptr. to TYPE.c_ptr." }) cfp = c_loc (int) ! { dg-error "Can't convert TYPE.c_ptr. to TYPE.c_funptr." } call c_f_pointer (cfp, int) ! { dg-error "Argument CPTR at .1. to C_F_POINTER shall have the type TYPE.C_PTR." } call c_f_procpointer (cp, fsub) ! { dg-error "Argument CPTR at .1. to C_F_PROCPOINTER shall have the type TYPE.C_FUNPTR." } cfp = c_funloc (noCsub) ! { dg-error "TS 29113: Noninteroperable procedure at .1. to C_FUNLOC" } call c_f_procpointer (cfp, fint) ! { dg-error "TS 29113: Noninteroperable procedure pointer at .1. to C_F_PROCPOINTER" } end
gpl-2.0
kbai/specfem3d
src/auxiliaries/combine_surf_data.f90
4
12688
!===================================================================== ! ! S p e c f e m 3 D V e r s i o n 3 . 0 ! --------------------------------------- ! ! Main historical authors: Dimitri Komatitsch and Jeroen Tromp ! Princeton University, USA ! and CNRS / University of Marseille, France ! (there are currently many more authors!) ! (c) Princeton University and CNRS / University of Marseille, July 2012 ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along ! with this program; if not, write to the Free Software Foundation, Inc., ! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ! !===================================================================== program combine_surf_data ! puts the output of SPECFEM3D in ParaView format. ! see http://www.paraview.org for details ! combines the database files on several slices. ! the local database file needs to have been collected onto the frontend (copy_local_database.pl) use constants implicit none integer :: i,j,k,ispec, it integer :: iproc, proc1, proc2, num_node, node_list(300), nspec, nglob integer :: np, ne, npp, nee, npoint, nelement, njunk, n1, n2, n3, n4 integer :: numpoin, iglob1, iglob2, iglob3, iglob4, iglob real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: data_3D real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: data_2D ! mesh coordinates real(kind=CUSTOM_REAL),dimension(:),allocatable :: xstore, ystore, zstore integer, dimension(:,:,:,:),allocatable :: ibool logical, dimension(:),allocatable :: mask_ibool integer :: NSPEC_AB,NGLOB_AB real :: x, y, z real, dimension(:,:,:,:), allocatable :: dat3D real, dimension(:,:,:), allocatable :: dat2D character(len=MAX_STRING_LEN) :: sline, arg(8), filename, indir, outdir, prname, surfname character(len=MAX_STRING_LEN*2) :: mesh_file, local_file, local_data_file, local_ibool_file character(len=MAX_STRING_LEN*2) :: local_ibool_surf_file ! integer :: num_ibool(NGLOB_AB) integer,dimension(:),allocatable :: num_ibool logical :: HIGH_RESOLUTION_MESH, FILE_ARRAY_IS_3D integer :: ires, nspec_surf, npoint1, npoint2, ispec_surf, inx, iny, idimval, ier integer,dimension(:), allocatable :: ibelm_surf do i = 1, 8 call get_command_argument(i,arg(i)) if (i < 6 .and. trim(arg(i)) == '') then print *, 'Usage: xcombine_surface start_slice end_slice filename surfacename input_dir output_dir high/low-resolution 3D/2D' print *, ' or xcombine_surface slice_list filename surfacename input_dir output_dir high/low-resolution 3D/2D' print *, ' possible filenames are kappastore(NGLLX,NGLLY,NGLLZ,nspec), alpha_kernel(NGLLX,NGLLY,nspec_surf)' print *, ' possible surface name: moho as in ibelm_moho.bin' print *, ' files have been collected in input_dir, output mesh file goes to output_dir ' print *, ' give 0 for low resolution and 1 for high resolution' print *, ' give 0 for 2D and 1 for 3D filenames' stop ' Reenter command line options' endif enddo ! get slice list if (trim(arg(8)) == '') then num_node = 0 open(unit = 20, file = trim(arg(1)), status = 'unknown',iostat = ier) if (ier /= 0) then print *,'Error opening ',trim(arg(1)) stop endif do while (1 == 1) read(20,'(a)',iostat=ier) sline if (ier /= 0) exit read(sline,*,iostat=ier) njunk if (ier /= 0) exit num_node = num_node + 1 node_list(num_node) = njunk enddo close(20) filename = arg(2) surfname = arg(3) indir= arg(4) outdir = arg(5) read(arg(6),*) ires read(arg(7),*) idimval else read(arg(1),*) proc1 read(arg(2),*) proc2 do iproc = proc1, proc2 node_list(iproc - proc1 + 1) = iproc enddo num_node = proc2 - proc1 + 1 filename = arg(3) surfname = arg(4) indir = arg(5) outdir = arg(6) read(arg(7),*) ires read(arg(8),*) idimval endif if (ires == 0) then HIGH_RESOLUTION_MESH = .false. inx = NGLLX-1 iny = NGLLY-1 else HIGH_RESOLUTION_MESH = .true. inx = 1 iny = 1 endif if (idimval == 0) then FILE_ARRAY_IS_3D = .false. else FILE_ARRAY_IS_3D = .true. endif print *, 'Slice list: ' print *, node_list(1:num_node) ! open paraview output mesh file mesh_file = trim(outdir) // '/' // trim(filename)//'.surf' call open_file_create(trim(mesh_file)//char(0)) ! nspec = NSPEC_AB ! nglob = NGLOB_AB np = 0 ! ======= loop over all slices, write point and scalar information ====== do it = 1, num_node iproc = node_list(it) print *, ' ' print *, 'Reading slice ', iproc write(prname,'(a,i6.6,a)') trim(indir)//'/proc',iproc,'_' ! gets number of elements and global points for this partition open(unit=27,file=prname(1:len_trim(prname))//'external_mesh.bin',& status='old',action='read',form='unformatted',iostat=ier) read(27) NSPEC_AB read(27) NGLOB_AB close(27) nspec = NSPEC_AB nglob = NGLOB_AB ! allocates arrays allocate(ibool(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & mask_ibool(NGLOB_AB), & num_ibool(NGLOB_AB), & xstore(NGLOB_AB),ystore(NGLOB_AB),zstore(NGLOB_AB),stat=ier) if (ier /= 0) stop 'error allocating array ibool etc.' ! surface file local_ibool_surf_file = trim(prname) // 'ibelm_' //trim(surfname)// '.bin' open(unit = 28,file = trim(local_ibool_surf_file),status='old', iostat = ier, form='unformatted') if (ier /= 0) then print *,'Error opening ',trim(local_ibool_surf_file) stop endif read(28) nspec_surf read(28) npoint1 read(28) npoint2 if (it == 1) then allocate(ibelm_surf(nspec_surf),stat=ier) if (ier /= 0) stop 'error allocating array ibelm_surf' endif read(28) ibelm_surf close(28) print *, trim(local_ibool_surf_file) if (it == 1) then if (FILE_ARRAY_IS_3D) then allocate(data_3D(NGLLX,NGLLY,NGLLZ,NSPEC_AB),dat3D(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier) if (ier /= 0) stop 'error allocating array data_3D' else allocate(data_2D(NGLLX,NGLLY,nspec_surf),dat2D(NGLLX,NGLLY,nspec_surf),stat=ier) if (ier /= 0) stop 'error allocating array data_2D' endif endif ! data file local_data_file = trim(prname) // trim(filename) // '.bin' open(unit = 27,file = trim(local_data_file),status='old', iostat = ier,form ='unformatted') if (ier /= 0) then print *,'Error opening ',trim(local_data_file) stop endif if (FILE_ARRAY_IS_3D) then read(27) data_3D dat3D = data_3D else read(27) data_2D dat2D = data_2D endif close(27) print *, trim(local_data_file) ! ibool file local_ibool_file = trim(prname) // 'ibool' // '.bin' open(unit = 28,file = trim(local_ibool_file),status='old', iostat = ier, form='unformatted') if (ier /= 0) then print *,'Error opening ',trim(local_data_file) stop endif read(28) ibool close(28) print *, trim(local_ibool_file) mask_ibool(:) = .false. numpoin = 0 if (it == 1) then if (HIGH_RESOLUTION_MESH) then npoint = npoint2 else npoint = npoint1 endif npp = npoint * num_node call write_integer(npp) endif local_file = trim(prname)//'x.bin' open(unit = 27,file = trim(prname)//'x.bin',status='old', iostat = ier,form ='unformatted') if (ier /= 0) then print *,'Error opening ',trim(local_file) stop endif read(27) xstore close(27) local_file = trim(prname)//'y.bin' open(unit = 27,file = trim(prname)//'y.bin',status='old', iostat = ier,form ='unformatted') if (ier /= 0) then print *,'Error opening ',trim(local_file) stop endif read(27) ystore close(27) local_file = trim(prname)//'z.bin' open(unit = 27,file = trim(prname)//'z.bin',status='old', iostat = ier,form ='unformatted') if (ier /= 0) then print *,'Error opening ',trim(local_file) stop endif read(27) zstore close(27) do ispec_surf=1,nspec_surf ispec = ibelm_surf(ispec_surf) k = 1 do j = 1, NGLLY, iny do i = 1, NGLLX, inx iglob = ibool(i,j,k,ispec) if (.not. mask_ibool(iglob)) then numpoin = numpoin + 1 x = xstore(iglob) y = ystore(iglob) z = zstore(iglob) call write_real(x) call write_real(y) call write_real(z) if (FILE_ARRAY_IS_3D) then call write_real(dat3D(i,j,k,ispec)) else call write_real(dat2D(i,j,ispec_surf)) endif mask_ibool(iglob) = .true. endif enddo ! i enddo ! j enddo !ispec if (numpoin /= npoint) stop 'Error: number of points are not consistent' np = np + npoint ! frees arrays deallocate(ibool,mask_ibool,num_ibool,xstore,ystore,zstore) enddo ! all slices for points if (np /= npp) stop 'Error: Number of total points are not consistent' print *, 'Total number of points: ', np print *, ' ' ne = 0 ! ============ write element information ===================== do it = 1, num_node iproc = node_list(it) print *, 'Reading slice ', iproc write(prname,'(a,i6.6,a)') trim(indir)//'/proc',iproc,'_' ! gets number of elements and global points for this partition open(unit=27,file=prname(1:len_trim(prname))//'external_mesh.bin',& status='old',action='read',form='unformatted',iostat=ier) read(27) NSPEC_AB read(27) NGLOB_AB close(27) nspec = NSPEC_AB nglob = NGLOB_AB ! allocates arrays allocate(ibool(NGLLX,NGLLY,NGLLZ,NSPEC_AB), & mask_ibool(NGLOB_AB), & num_ibool(NGLOB_AB),stat=ier) if (ier /= 0) stop 'error allocating array ibool etc.' np = npoint * (it-1) ! surface file local_ibool_surf_file = trim(prname) // 'ibelm_' //trim(surfname)// '.bin' open(unit = 28,file = trim(local_ibool_surf_file),status='old', iostat = ier, form='unformatted') read(28) nspec_surf read(28) njunk read(28) njunk read(28) ibelm_surf close(28) ! ibool file local_ibool_file = trim(prname) // 'ibool' // '.bin' open(unit = 28,file = trim(local_ibool_file),status='old', iostat = ier, form='unformatted') read(28) ibool close(28) if (it == 1) then if (HIGH_RESOLUTION_MESH) then nelement = nspec_surf * (NGLLX-1) * (NGLLY-1) else nelement = nspec_surf endif nee = nelement * num_node call write_integer(nee) endif numpoin = 0 mask_ibool = .false. do ispec_surf=1,nspec_surf ispec = ibelm_surf(ispec_surf) k = 1 do j = 1, NGLLY, iny do i = 1, NGLLX, inx iglob = ibool(i,j,k,ispec) if (.not. mask_ibool(iglob)) then numpoin = numpoin + 1 num_ibool(iglob) = numpoin mask_ibool(iglob) = .true. endif enddo ! i enddo ! j enddo !ispec do ispec_surf = 1, nspec_surf ispec = ibelm_surf(ispec_surf) k = 1 do j = 1, NGLLY-1, iny do i = 1, NGLLX-1, inx iglob1 = ibool(i,j,k,ispec) iglob2 = ibool(i+inx,j,k,ispec) iglob3 = ibool(i+inx,j+iny,k,ispec) iglob4 = ibool(i,j+iny,k,ispec) n1 = num_ibool(iglob1)+np-1 n2 = num_ibool(iglob2)+np-1 n3 = num_ibool(iglob3)+np-1 n4 = num_ibool(iglob4)+np-1 call write_integer(n1) call write_integer(n2) call write_integer(n3) call write_integer(n4) enddo enddo enddo ne = ne + nelement ! frees arrays deallocate(ibool,mask_ibool,num_ibool) enddo ! num_node if (ne /= nee) stop 'Number of total elements are not consistent' print *, 'Total number of elements: ', ne call close_file() print *, 'Done writing '//trim(mesh_file) end program combine_surf_data
gpl-2.0
skywalker00/sabermod_rom_toolchain
libgfortran/generated/_exp_c10.F90
35
1484
! Copyright (C) 2002-2014 Free Software Foundation, Inc. ! Contributed by Paul Brook <paul@nowt.org> ! !This file is part of the GNU Fortran 95 runtime library (libgfortran). ! !GNU libgfortran is free software; you can redistribute it and/or !modify it under the terms of the GNU General Public !License as published by the Free Software Foundation; either !version 3 of the License, or (at your option) any later version. !GNU libgfortran is distributed in the hope that it will be useful, !but WITHOUT ANY WARRANTY; without even the implied warranty of !MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !GNU General Public License for more details. ! !Under Section 7 of GPL version 3, you are granted additional !permissions described in the GCC Runtime Library Exception, version !3.1, as published by the Free Software Foundation. ! !You should have received a copy of the GNU General Public License and !a copy of the GCC Runtime Library Exception along with this program; !see the files COPYING3 and COPYING.RUNTIME respectively. If not, see !<http://www.gnu.org/licenses/>. ! !This file is machine generated. #include "config.h" #include "kinds.inc" #include "c99_protos.inc" #if defined (HAVE_GFC_COMPLEX_10) #ifdef HAVE_CEXPL elemental function _gfortran_specific__exp_c10 (parm) complex (kind=10), intent (in) :: parm complex (kind=10) :: _gfortran_specific__exp_c10 _gfortran_specific__exp_c10 = exp (parm) end function #endif #endif
gpl-2.0
prool/ccx_prool
ARPACK/LAPACK/slasr.f
5
11491
SUBROUTINE SLASR( SIDE, PIVOT, DIRECT, M, N, C, S, A, LDA ) * * -- LAPACK auxiliary routine (version 2.0) -- * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., * Courant Institute, Argonne National Lab, and Rice University * October 31, 1992 * * .. Scalar Arguments .. CHARACTER DIRECT, PIVOT, SIDE INTEGER LDA, M, N * .. * .. Array Arguments .. REAL A( LDA, * ), C( * ), S( * ) * .. * * Purpose * ======= * * SLASR performs the transformation * * A := P*A, when SIDE = 'L' or 'l' ( Left-hand side ) * * A := A*P', when SIDE = 'R' or 'r' ( Right-hand side ) * * where A is an m by n real matrix and P is an orthogonal matrix, * consisting of a sequence of plane rotations determined by the * parameters PIVOT and DIRECT as follows ( z = m when SIDE = 'L' or 'l' * and z = n when SIDE = 'R' or 'r' ): * * When DIRECT = 'F' or 'f' ( Forward sequence ) then * * P = P( z - 1 )*...*P( 2 )*P( 1 ), * * and when DIRECT = 'B' or 'b' ( Backward sequence ) then * * P = P( 1 )*P( 2 )*...*P( z - 1 ), * * where P( k ) is a plane rotation matrix for the following planes: * * when PIVOT = 'V' or 'v' ( Variable pivot ), * the plane ( k, k + 1 ) * * when PIVOT = 'T' or 't' ( Top pivot ), * the plane ( 1, k + 1 ) * * when PIVOT = 'B' or 'b' ( Bottom pivot ), * the plane ( k, z ) * * c( k ) and s( k ) must contain the cosine and sine that define the * matrix P( k ). The two by two plane rotation part of the matrix * P( k ), R( k ), is assumed to be of the form * * R( k ) = ( c( k ) s( k ) ). * ( -s( k ) c( k ) ) * * This version vectorises across rows of the array A when SIDE = 'L'. * * Arguments * ========= * * SIDE (input) CHARACTER*1 * Specifies whether the plane rotation matrix P is applied to * A on the left or the right. * = 'L': Left, compute A := P*A * = 'R': Right, compute A:= A*P' * * DIRECT (input) CHARACTER*1 * Specifies whether P is a forward or backward sequence of * plane rotations. * = 'F': Forward, P = P( z - 1 )*...*P( 2 )*P( 1 ) * = 'B': Backward, P = P( 1 )*P( 2 )*...*P( z - 1 ) * * PIVOT (input) CHARACTER*1 * Specifies the plane for which P(k) is a plane rotation * matrix. * = 'V': Variable pivot, the plane (k,k+1) * = 'T': Top pivot, the plane (1,k+1) * = 'B': Bottom pivot, the plane (k,z) * * M (input) INTEGER * The number of rows of the matrix A. If m <= 1, an immediate * return is effected. * * N (input) INTEGER * The number of columns of the matrix A. If n <= 1, an * immediate return is effected. * * C, S (input) REAL arrays, dimension * (M-1) if SIDE = 'L' * (N-1) if SIDE = 'R' * c(k) and s(k) contain the cosine and sine that define the * matrix P(k). The two by two plane rotation part of the * matrix P(k), R(k), is assumed to be of the form * R( k ) = ( c( k ) s( k ) ). * ( -s( k ) c( k ) ) * * A (input/output) REAL array, dimension (LDA,N) * The m by n matrix A. On exit, A is overwritten by P*A if * SIDE = 'R' or by A*P' if SIDE = 'L'. * * LDA (input) INTEGER * The leading dimension of the array A. LDA >= max(1,M). * * ===================================================================== * * .. Parameters .. REAL ONE, ZERO PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 ) * .. * .. Local Scalars .. INTEGER I, INFO, J REAL CTEMP, STEMP, TEMP * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test the input parameters * INFO = 0 IF( .NOT.( LSAME( SIDE, 'L' ) .OR. LSAME( SIDE, 'R' ) ) ) THEN INFO = 1 ELSE IF( .NOT.( LSAME( PIVOT, 'V' ) .OR. LSAME( PIVOT, $ 'T' ) .OR. LSAME( PIVOT, 'B' ) ) ) THEN INFO = 2 ELSE IF( .NOT.( LSAME( DIRECT, 'F' ) .OR. LSAME( DIRECT, 'B' ) ) ) $ THEN INFO = 3 ELSE IF( M.LT.0 ) THEN INFO = 4 ELSE IF( N.LT.0 ) THEN INFO = 5 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = 9 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'SLASR ', INFO ) RETURN END IF * * Quick return if possible * IF( ( M.EQ.0 ) .OR. ( N.EQ.0 ) ) $ RETURN IF( LSAME( SIDE, 'L' ) ) THEN * * Form P * A * IF( LSAME( PIVOT, 'V' ) ) THEN IF( LSAME( DIRECT, 'F' ) ) THEN DO 20 J = 1, M - 1 CTEMP = C( J ) STEMP = S( J ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 10 I = 1, N TEMP = A( J+1, I ) A( J+1, I ) = CTEMP*TEMP - STEMP*A( J, I ) A( J, I ) = STEMP*TEMP + CTEMP*A( J, I ) 10 CONTINUE END IF 20 CONTINUE ELSE IF( LSAME( DIRECT, 'B' ) ) THEN DO 40 J = M - 1, 1, -1 CTEMP = C( J ) STEMP = S( J ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 30 I = 1, N TEMP = A( J+1, I ) A( J+1, I ) = CTEMP*TEMP - STEMP*A( J, I ) A( J, I ) = STEMP*TEMP + CTEMP*A( J, I ) 30 CONTINUE END IF 40 CONTINUE END IF ELSE IF( LSAME( PIVOT, 'T' ) ) THEN IF( LSAME( DIRECT, 'F' ) ) THEN DO 60 J = 2, M CTEMP = C( J-1 ) STEMP = S( J-1 ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 50 I = 1, N TEMP = A( J, I ) A( J, I ) = CTEMP*TEMP - STEMP*A( 1, I ) A( 1, I ) = STEMP*TEMP + CTEMP*A( 1, I ) 50 CONTINUE END IF 60 CONTINUE ELSE IF( LSAME( DIRECT, 'B' ) ) THEN DO 80 J = M, 2, -1 CTEMP = C( J-1 ) STEMP = S( J-1 ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 70 I = 1, N TEMP = A( J, I ) A( J, I ) = CTEMP*TEMP - STEMP*A( 1, I ) A( 1, I ) = STEMP*TEMP + CTEMP*A( 1, I ) 70 CONTINUE END IF 80 CONTINUE END IF ELSE IF( LSAME( PIVOT, 'B' ) ) THEN IF( LSAME( DIRECT, 'F' ) ) THEN DO 100 J = 1, M - 1 CTEMP = C( J ) STEMP = S( J ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 90 I = 1, N TEMP = A( J, I ) A( J, I ) = STEMP*A( M, I ) + CTEMP*TEMP A( M, I ) = CTEMP*A( M, I ) - STEMP*TEMP 90 CONTINUE END IF 100 CONTINUE ELSE IF( LSAME( DIRECT, 'B' ) ) THEN DO 120 J = M - 1, 1, -1 CTEMP = C( J ) STEMP = S( J ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 110 I = 1, N TEMP = A( J, I ) A( J, I ) = STEMP*A( M, I ) + CTEMP*TEMP A( M, I ) = CTEMP*A( M, I ) - STEMP*TEMP 110 CONTINUE END IF 120 CONTINUE END IF END IF ELSE IF( LSAME( SIDE, 'R' ) ) THEN * * Form A * P' * IF( LSAME( PIVOT, 'V' ) ) THEN IF( LSAME( DIRECT, 'F' ) ) THEN DO 140 J = 1, N - 1 CTEMP = C( J ) STEMP = S( J ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 130 I = 1, M TEMP = A( I, J+1 ) A( I, J+1 ) = CTEMP*TEMP - STEMP*A( I, J ) A( I, J ) = STEMP*TEMP + CTEMP*A( I, J ) 130 CONTINUE END IF 140 CONTINUE ELSE IF( LSAME( DIRECT, 'B' ) ) THEN DO 160 J = N - 1, 1, -1 CTEMP = C( J ) STEMP = S( J ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 150 I = 1, M TEMP = A( I, J+1 ) A( I, J+1 ) = CTEMP*TEMP - STEMP*A( I, J ) A( I, J ) = STEMP*TEMP + CTEMP*A( I, J ) 150 CONTINUE END IF 160 CONTINUE END IF ELSE IF( LSAME( PIVOT, 'T' ) ) THEN IF( LSAME( DIRECT, 'F' ) ) THEN DO 180 J = 2, N CTEMP = C( J-1 ) STEMP = S( J-1 ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 170 I = 1, M TEMP = A( I, J ) A( I, J ) = CTEMP*TEMP - STEMP*A( I, 1 ) A( I, 1 ) = STEMP*TEMP + CTEMP*A( I, 1 ) 170 CONTINUE END IF 180 CONTINUE ELSE IF( LSAME( DIRECT, 'B' ) ) THEN DO 200 J = N, 2, -1 CTEMP = C( J-1 ) STEMP = S( J-1 ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 190 I = 1, M TEMP = A( I, J ) A( I, J ) = CTEMP*TEMP - STEMP*A( I, 1 ) A( I, 1 ) = STEMP*TEMP + CTEMP*A( I, 1 ) 190 CONTINUE END IF 200 CONTINUE END IF ELSE IF( LSAME( PIVOT, 'B' ) ) THEN IF( LSAME( DIRECT, 'F' ) ) THEN DO 220 J = 1, N - 1 CTEMP = C( J ) STEMP = S( J ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 210 I = 1, M TEMP = A( I, J ) A( I, J ) = STEMP*A( I, N ) + CTEMP*TEMP A( I, N ) = CTEMP*A( I, N ) - STEMP*TEMP 210 CONTINUE END IF 220 CONTINUE ELSE IF( LSAME( DIRECT, 'B' ) ) THEN DO 240 J = N - 1, 1, -1 CTEMP = C( J ) STEMP = S( J ) IF( ( CTEMP.NE.ONE ) .OR. ( STEMP.NE.ZERO ) ) THEN DO 230 I = 1, M TEMP = A( I, J ) A( I, J ) = STEMP*A( I, N ) + CTEMP*TEMP A( I, N ) = CTEMP*A( I, N ) - STEMP*TEMP 230 CONTINUE END IF 240 CONTINUE END IF END IF END IF * RETURN * * End of SLASR * END
gpl-2.0
prool/ccx_prool
CalculiX/ccx_2.8p2/src/e_c3d.f
2
56011
! ! CalculiX - A 3-dimensional finite element program ! Copyright (C) 1998-2015 Guido Dhondt ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License as ! published by the Free Software Foundation(version 2); ! ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! subroutine e_c3d(co,kon,lakonl,p1,p2,omx,bodyfx,nbody,s,sm, & ff,nelem,nmethod,elcon,nelcon,rhcon,nrhcon,alcon,nalcon,alzero, & ielmat,ielorien,norien,orab,ntmat_, & t0,t1,ithermal,vold,iperturb,nelemload, & sideload,xload,nload,idist,sti,stx,iexpl,plicon, & nplicon,plkcon,nplkcon,xstiff,npmat_,dtime, & matname,mi,ncmat_,mass,stiffness,buckling,rhsi,intscheme, & ttime,time,istep,iinc,coriolis,xloadold,reltime, & ipompc,nodempc,coefmpc,nmpc,ikmpc,ilmpc,veold,springarea, & nstate_,xstateini,xstate,ne0,ipkon,thicke, & integerglob,doubleglob,tieset,istartset,iendset,ialset,ntie, & nasym,pslavsurf,pmastsurf,mortar,clearini,ielprop,prop) ! ! computation of the element matrix and rhs for the element with ! the topology in konl ! ! ff: rhs without temperature and eigenstress contribution ! ! nmethod=0: check for positive Jacobian ! nmethod=1: stiffness matrix + right hand side ! nmethod=2: stiffness matrix + mass matrix ! nmethod=3: static stiffness + buckling stiffness ! nmethod=4: stiffness matrix + mass matrix ! implicit none ! logical mass,stiffness,buckling,rhsi,coriolis ! character*1 entity character*8 lakonl character*20 sideload(*) character*80 matname(*),amat character*81 tieset(3,*) ! integer konl(26),ifaceq(9,6),nelemload(2,*),nbody,nelem, & mi(*),iloc,jfaces,igauss,mortar,kon(*),ielprop(*),null, & mattyp,ithermal,iperturb(*),nload,idist,i,j,k,l,i1,i2,j1, & nmethod,k1,l1,ii,jj,ii1,jj1,id,ipointer,ig,m1,m2,m3,m4,kk, & nelcon(2,*),nrhcon(*),nalcon(2,*),ielmat(mi(3),*),six, & ielorien(mi(3),*),ilayer,nlayer,ki,kl,ipkon(*),indexe, & ntmat_,nope,nopes,norien,ihyper,iexpl,kode,imat,mint2d, & mint3d,ifacet(7,4),nopev,iorien,istiff,ncmat_,iface, & ifacew(8,5),intscheme,n,ipointeri,ipointerj,istep,iinc, & layer,kspt,jltyp,iflag,iperm(60),m,ipompc(*),nodempc(3,*), & nmpc,ikmpc(*),ilmpc(*),iscale,nstate_,ne0,iselect(6), & istartset(*),iendset(*),ialset(*),ntie,integerglob(*),nasym, & nplicon(0:ntmat_,*),nplkcon(0:ntmat_,*),npmat_,nopered ! real*8 co(3,*),xl(3,26),shp(4,26),xs2(3,7),veold(0:mi(2),*), & s(100,100),w(3,3),p1(3),p2(3),bodyf(3),bodyfx(3),ff(100), & bf(3),q(3),shpj(4,26),elcon(0:ncmat_,ntmat_,*),t(3), & rhcon(0:1,ntmat_,*),xkl(3,3),eknlsign,reltime,prop(*), & alcon(0:6,ntmat_,*),alzero(*),orab(7,*),t0(*),t1(*), & anisox(3,3,3,3),voldl(0:mi(2),26),vo(3,3),xloadold(2,*), & xl2(3,9),xsj2(3),shp2(7,9),vold(0:mi(2),*),xload(2,*), & xstate(nstate_,mi(1),*),xstateini(nstate_,mi(1),*), & v(3,3,3,3),springarea(2,*),thickness,tlayer(4),dlayer(4), & om,omx,e,un,al,um,xi,et,ze,tt,const,xsj,xsjj,sm(100,100), & sti(6,mi(1),*),stx(6,mi(1),*),s11,s22,s33,s12,s13,s23,s11b, & s22b,s33b,s12b,s13b,s23b,t0l,t1l,coefmpc(*),xlayer(mi(3),4), & senergy,senergyb,rho,elas(21),summass,summ,thicke(mi(3),*), & sume,factorm,factore,alp,elconloc(21),eth(6),doubleglob(*), & weight,coords(3),dmass,xl1(3,9),term,clearini(3,9,*), & plicon(0:2*npmat_,ntmat_,*),plkcon(0:2*npmat_,ntmat_,*), & xstiff(27,mi(1),*),plconloc(802),dtime,ttime,time,tvar(2), & sax(100,100),ffax(100),gs(8,4),a,stress(6),stre(3,3), & pslavsurf(3,*),pmastsurf(6,*) ! data ifaceq /4,3,2,1,11,10,9,12,21, & 5,6,7,8,13,14,15,16,22, & 1,2,6,5,9,18,13,17,23, & 2,3,7,6,10,19,14,18,24, & 3,4,8,7,11,20,15,19,25, & 4,1,5,8,12,17,16,20,26/ data ifacet /1,3,2,7,6,5,11, & 1,2,4,5,9,8,12, & 2,3,4,6,10,9,13, & 1,4,3,8,10,7,14/ data ifacew /1,3,2,9,8,7,0,0, & 4,5,6,10,11,12,0,0, & 1,2,5,4,7,14,10,13, & 2,3,6,5,8,15,11,14, & 4,6,3,1,12,15,9,13/ data iflag /3/ data null /0/ data iperm /13,14,-15,16,17,-18,19,20,-21,22,23,-24, & 1,2,-3,4,5,-6,7,8,-9,10,11,-12, & 37,38,-39,40,41,-42,43,44,-45,46,47,-48, & 25,26,-27,28,29,-30,31,32,-33,34,35,-36, & 49,50,-51,52,53,-54,55,56,-57,58,59,-60/ ! include "gauss.f" ! tvar(1)=time tvar(2)=ttime+time ! summass=0.d0 ! indexe=ipkon(nelem) c Bernhardi start if(lakonl(1:5).eq.'C3D8I') then nope=11 nopev=8 nopes=4 elseif(lakonl(4:5).eq.'20') then c Bernhardi end nope=20 nopev=8 nopes=8 elseif(lakonl(4:4).eq.'2') then ! ! nopes for C3D26 is a default value which can be overwritten ! while integrating over the element faces ! nope=26 nopev=8 nopes=8 elseif(lakonl(4:4).eq.'8') then nope=8 nopev=8 nopes=4 elseif(lakonl(4:5).eq.'10') then nope=10 nopev=4 nopes=6 elseif(lakonl(4:5).eq.'14') then ! ! nopes for C3D14 is a default value which can be overwritten ! while integrating over the element faces ! nope=14 nopev=4 nopes=6 elseif(lakonl(4:4).eq.'4') then nope=4 nopev=4 nopes=3 elseif(lakonl(4:5).eq.'15') then nope=15 nopev=6 elseif(lakonl(4:4).eq.'6') then nope=6 nopev=6 elseif(lakonl(1:2).eq.'ES') then if(lakonl(7:7).eq.'C') then if(mortar.eq.0) then read(lakonl(8:8),'(i1)') nope nope=nope+1 konl(nope+1)=kon(indexe+nope+1) elseif(mortar.eq.1) then nope=kon(indexe) endif else read(lakonl(8:8),'(i1)') nope nope=nope+1 endif endif ! ! material and orientation ! if(lakonl(7:8).ne.'LC') then ! imat=ielmat(1,nelem) amat=matname(imat) if(norien.gt.0) then iorien=ielorien(1,nelem) else iorien=0 endif ! if(nelcon(1,imat).lt.0) then ihyper=1 else ihyper=0 endif else ! ! composite materials ! ! determining the number of layers ! nlayer=0 do k=1,mi(3) if(ielmat(k,nelem).ne.0) then nlayer=nlayer+1 endif enddo mint2d=4 ! ! determining the layer thickness and global thickness ! at the shell integration points ! iflag=1 do kk=1,mint2d xi=gauss3d2(1,kk) et=gauss3d2(2,kk) call shape8q(xi,et,xl2,xsj2,xs2,shp2,iflag) tlayer(kk)=0.d0 do i=1,nlayer thickness=0.d0 do j=1,nopes thickness=thickness+thicke(i,indexe+j)*shp2(4,j) enddo tlayer(kk)=tlayer(kk)+thickness xlayer(i,kk)=thickness enddo enddo iflag=3 ! ilayer=0 do i=1,4 dlayer(i)=0.d0 enddo ! endif ! if(intscheme.eq.0) then if(lakonl(4:5).eq.'8R') then mint2d=1 mint3d=1 elseif(lakonl(4:7).eq.'20RB') then if((lakonl(8:8).eq.'R').or.(lakonl(8:8).eq.'C')) then mint2d=4 mint3d=50 else mint2d=4 call beamintscheme(lakonl,mint3d,ielprop(nelem),prop, & null,xi,et,ze,weight) endif elseif((lakonl(4:4).eq.'8').or.(lakonl(4:6).eq.'20R').or. & (lakonl(4:6).eq.'26R')) then if(((lakonl(7:7).eq.'A').or.(lakonl(7:7).eq.'S').or. & (lakonl(7:7).eq.'E')).and.(lakonl(4:6).ne.'26R')) then mint2d=2 mint3d=4 else mint2d=4 if(lakonl(7:8).eq.'LC') then mint3d=8*nlayer else mint3d=8 endif endif elseif(lakonl(4:4).eq.'2') then mint2d=9 mint3d=27 elseif((lakonl(4:5).eq.'10').or.(lakonl(4:5).eq.'14')) then mint2d=3 mint3d=4 elseif(lakonl(4:4).eq.'4') then mint2d=1 mint3d=1 elseif(lakonl(4:5).eq.'15') then mint3d=9 elseif(lakonl(4:4).eq.'6') then mint3d=2 else mint3d=0 endif else if((lakonl(4:4).eq.'8').or.(lakonl(4:4).eq.'2')) then mint3d=27 if(lakonl(4:4).eq.'8') then if(lakonl(5:5).eq.'R') then mint2d=1 else mint2d=4 endif else if(lakonl(6:6).eq.'R') then mint2d=4 else mint2d=9 endif endif elseif((lakonl(4:5).eq.'10').or.(lakonl(4:4).eq.'4').or. & (lakonl(4:5).eq.'14')) then mint3d=15 if((lakonl(4:5).eq.'10').or.(lakonl(4:5).eq.'14')) then mint2d=3 else mint2d=1 endif elseif((lakonl(4:5).eq.'15').or.(lakonl(4:4).eq.'6')) then mint3d=18 else mint3d=0 endif endif ! ! computation of the coordinates of the local nodes ! do i=1,nope konl(i)=kon(indexe+i) do j=1,3 xl(j,i)=co(j,konl(i)) enddo enddo ! ! initialisation for distributed forces ! if(rhsi) then if(idist.ne.0) then do i=1,3*nope ff(i)=0.d0 enddo endif endif ! ! displacements for 2nd order static and modal theory ! if(((iperturb(1).eq.1).or.(iperturb(2).eq.1)).and. & stiffness.and.(.not.buckling)) then do i1=1,nope do i2=1,3 voldl(i2,i1)=vold(i2,konl(i1)) enddo enddo endif ! ! initialisation of sm ! if(mass.or.buckling.or.coriolis) then do i=1,3*nope do j=1,3*nope sm(i,j)=0.d0 enddo enddo endif ! ! initialisation of s ! do i=1,3*nope do j=1,3*nope s(i,j)=0.d0 enddo enddo ! ! calculating the stiffness matrix for the contact spring elements ! if(mint3d.eq.0) then ! ! for a ! first step in a displacement-driven geometrically nonlinear ! calculation or a nonlinear calculation with linear strains ! the next block has to be evaluated ! if(iperturb(2).eq.0) then do i1=1,nope do i2=1,3 voldl(i2,i1)=vold(i2,konl(i1)) enddo enddo endif ! kode=nelcon(1,imat) if(lakonl(7:7).eq.'A') then t0l=0.d0 t1l=0.d0 if(ithermal.eq.1) then t0l=(t0(konl(1))+t0(konl(2)))/2.d0 t1l=(t1(konl(1))+t1(konl(2)))/2.d0 elseif(ithermal.ge.2) then t0l=(t0(konl(1))+t0(konl(2)))/2.d0 t1l=(vold(0,konl(1))+vold(0,konl(2)))/2.d0 endif else ! ! as soon as the first contact element is discovered ne0 is ! determined and saved ! if(ne0.eq.0) ne0=nelem-1 endif if((lakonl(7:7).eq.'A').or.(mortar.eq.0)) then call springstiff_n2f(xl,elas,konl,voldl,s,imat,elcon,nelcon, & ncmat_,ntmat_,nope,lakonl,t1l,kode,elconloc,plicon, & nplicon,npmat_,iperturb,springarea(1,konl(nope+1)),nmethod, & mi,ne0,nstate_,xstateini,xstate,reltime,nasym) elseif(mortar.eq.1) then iloc=kon(indexe+nope+1) jfaces=kon(indexe+nope+2) igauss=kon(indexe+nope+1) call springstiff_f2f(xl,elas,voldl,s,imat,elcon,nelcon, & ncmat_,ntmat_,nope,lakonl,t1l,kode,elconloc,plicon, & nplicon,npmat_,iperturb,springarea(1,iloc),nmethod, & mi,ne0,nstate_,xstateini,xstate,reltime, & nasym,iloc,jfaces,igauss,pslavsurf, & pmastsurf,clearini) endif return endif ! ! computation of the matrix: loop over the Gauss points ! do kk=1,mint3d if(intscheme.eq.0) then if(lakonl(4:5).eq.'8R') then xi=gauss3d1(1,kk) et=gauss3d1(2,kk) ze=gauss3d1(3,kk) weight=weight3d1(kk) elseif(lakonl(4:7).eq.'20RB') then if((lakonl(8:8).eq.'R').or.(lakonl(8:8).eq.'C')) then xi=gauss3d13(1,kk) et=gauss3d13(2,kk) ze=gauss3d13(3,kk) weight=weight3d13(kk) else call beamintscheme(lakonl,mint3d,ielprop(nelem),prop, & kk,xi,et,ze,weight) endif elseif((lakonl(4:4).eq.'8').or.(lakonl(4:6).eq.'20R').or. & (lakonl(4:6).eq.'26R')) & then if(lakonl(7:8).ne.'LC') then xi=gauss3d2(1,kk) et=gauss3d2(2,kk) ze=gauss3d2(3,kk) weight=weight3d2(kk) else kl=mod(kk,8) if(kl.eq.0) kl=8 ! xi=gauss3d2(1,kl) et=gauss3d2(2,kl) ze=gauss3d2(3,kl) weight=weight3d2(kl) ! ki=mod(kk,4) if(ki.eq.0) ki=4 ! if(kl.eq.1) then ilayer=ilayer+1 if(ilayer.gt.1) then do i=1,4 dlayer(i)=dlayer(i)+xlayer(ilayer-1,i) enddo endif endif ze=2.d0*(dlayer(ki)+(ze+1.d0)/2.d0*xlayer(ilayer,ki))/ & tlayer(ki)-1.d0 weight=weight*xlayer(ilayer,ki)/tlayer(ki) ! ! material and orientation ! imat=ielmat(ilayer,nelem) amat=matname(imat) if(norien.gt.0) then iorien=ielorien(ilayer,nelem) else iorien=0 endif ! if(nelcon(1,imat).lt.0) then ihyper=1 else ihyper=0 endif endif elseif(lakonl(4:4).eq.'2') then xi=gauss3d3(1,kk) et=gauss3d3(2,kk) ze=gauss3d3(3,kk) weight=weight3d3(kk) elseif((lakonl(4:5).eq.'10').or.(lakonl(4:5).eq.'14')) then xi=gauss3d5(1,kk) et=gauss3d5(2,kk) ze=gauss3d5(3,kk) weight=weight3d5(kk) elseif(lakonl(4:4).eq.'4') then xi=gauss3d4(1,kk) et=gauss3d4(2,kk) ze=gauss3d4(3,kk) weight=weight3d4(kk) elseif(lakonl(4:5).eq.'15') then xi=gauss3d8(1,kk) et=gauss3d8(2,kk) ze=gauss3d8(3,kk) weight=weight3d8(kk) elseif(lakonl(4:4).eq.'6') then xi=gauss3d7(1,kk) et=gauss3d7(2,kk) ze=gauss3d7(3,kk) weight=weight3d7(kk) endif else if((lakonl(4:4).eq.'8').or.(lakonl(4:4).eq.'2')) then xi=gauss3d3(1,kk) et=gauss3d3(2,kk) ze=gauss3d3(3,kk) weight=weight3d3(kk) elseif((lakonl(4:5).eq.'10').or.(lakonl(4:4).eq.'4')) then xi=gauss3d6(1,kk) et=gauss3d6(2,kk) ze=gauss3d6(3,kk) weight=weight3d6(kk) else xi=gauss3d9(1,kk) et=gauss3d9(2,kk) ze=gauss3d9(3,kk) weight=weight3d9(kk) endif endif c if(nelem.eq.1) then c write(*,*) 'kk', kk c write(*,*) 'coords',xi,et,ze c write(*,*) 'weight',weight c write(*,*) 'dlayer',dlayer(ki) c endif ! ! calculation of the shape functions and their derivatives ! in the gauss point ! c Bernhardi start if(lakonl(1:5).eq.'C3D8R') then call shape8hr(xl,xsj,shp,gs,a) elseif(lakonl(1:5).eq.'C3D8I') then call shape8hu(xi,et,ze,xl,xsj,shp,iflag) elseif(nope.eq.20) then c Bernhardi end if(lakonl(7:7).eq.'A') then call shape20h_ax(xi,et,ze,xl,xsj,shp,iflag) elseif((lakonl(7:7).eq.'E').or.(lakonl(7:7).eq.'S')) then call shape20h_pl(xi,et,ze,xl,xsj,shp,iflag) else call shape20h(xi,et,ze,xl,xsj,shp,iflag) endif elseif(nope.eq.26) then call shape26h(xi,et,ze,xl,xsj,shp,iflag,konl) elseif(nope.eq.8) then call shape8h(xi,et,ze,xl,xsj,shp,iflag) elseif(nope.eq.10) then call shape10tet(xi,et,ze,xl,xsj,shp,iflag) elseif(nope.eq.14) then call shape14tet(xi,et,ze,xl,xsj,shp,iflag,konl) elseif(nope.eq.4) then call shape4tet(xi,et,ze,xl,xsj,shp,iflag) elseif(nope.eq.15) then call shape15w(xi,et,ze,xl,xsj,shp,iflag) else call shape6w(xi,et,ze,xl,xsj,shp,iflag) endif ! ! check the jacobian determinant ! if(xsj.lt.1.d-20) then write(*,*) '*ERROR in e_c3d: nonpositive jacobian' write(*,*) ' determinant in element',nelem write(*,*) xsj=dabs(xsj) nmethod=0 endif ! c if((iperturb(1).ne.0).and.stiffness.and.(.not.buckling)) if(((iperturb(1).eq.1).or.(iperturb(2).eq.1)).and. & stiffness.and.(.not.buckling))then ! ! stresses for 2nd order static and modal theory ! s11=sti(1,kk,nelem) s22=sti(2,kk,nelem) s33=sti(3,kk,nelem) s12=sti(4,kk,nelem) s13=sti(5,kk,nelem) s23=sti(6,kk,nelem) endif ! ! calculating the temperature in the integration ! point ! t0l=0.d0 t1l=0.d0 if(ithermal.eq.1) then if(lakonl(4:5).eq.'8 ') then do i1=1,nope t0l=t0l+t0(konl(i1))/8.d0 t1l=t1l+t1(konl(i1))/8.d0 enddo elseif((lakonl(4:6).eq.'20 ').or.(lakonl(4:6).eq.'26 '))then nopered=20 call lintemp(t0,t1,konl,nopered,kk,t0l,t1l) else do i1=1,nope t0l=t0l+shp(4,i1)*t0(konl(i1)) t1l=t1l+shp(4,i1)*t1(konl(i1)) enddo endif elseif(ithermal.ge.2) then if(lakonl(4:5).eq.'8 ') then do i1=1,nope t0l=t0l+t0(konl(i1))/8.d0 t1l=t1l+vold(0,konl(i1))/8.d0 enddo elseif((lakonl(4:6).eq.'20 ').or.(lakonl(4:6).eq.'26 '))then nopered=20 call lintemp_th(t0,vold,konl,nopered,kk,t0l,t1l,mi) else do i1=1,nope t0l=t0l+shp(4,i1)*t0(konl(i1)) t1l=t1l+shp(4,i1)*vold(0,konl(i1)) enddo endif endif tt=t1l-t0l ! ! calculating the coordinates of the integration point ! for material orientation purposes (for cylindrical ! coordinate systems) ! if(iorien.gt.0) then do j=1,3 coords(j)=0.d0 do i1=1,nope coords(j)=coords(j)+shp(4,i1)*co(j,konl(i1)) enddo enddo endif ! ! for deformation plasticity: calculating the Jacobian ! and the inverse of the deformation gradient ! needed to convert the stiffness matrix in the spatial ! frame of reference to the material frame ! kode=nelcon(1,imat) ! ! material data and local stiffness matrix ! istiff=1 call materialdata_me(elcon,nelcon,rhcon,nrhcon,alcon,nalcon, & imat,amat,iorien,coords,orab,ntmat_,elas,rho, & nelem,ithermal,alzero,mattyp,t0l,t1l, & ihyper,istiff,elconloc,eth,kode,plicon, & nplicon,plkcon,nplkcon,npmat_, & plconloc,mi(1),dtime,nelem,kk, & xstiff,ncmat_) ! if(mattyp.eq.1) then c write(*,*) 'elastic co', elas(1),elas(2) e=elas(1) un=elas(2) um=e/(1.d0+un) al=un*um/(1.d0-2.d0*un) um=um/2.d0 elseif(mattyp.eq.2) then c call orthotropic(elas,anisox) else call anisotropic(elas,anisox) endif ! ! initialisation for the body forces ! om=omx*rho if(rhsi) then if(nbody.ne.0) then do ii=1,3 bodyf(ii)=bodyfx(ii)*rho enddo endif endif ! if(buckling) then ! ! buckling stresses ! s11b=stx(1,kk,nelem) s22b=stx(2,kk,nelem) s33b=stx(3,kk,nelem) s12b=stx(4,kk,nelem) s13b=stx(5,kk,nelem) s23b=stx(6,kk,nelem) ! endif ! ! incorporating the jacobian determinant in the shape ! functions ! xsjj=dsqrt(xsj) do i1=1,nope shpj(1,i1)=shp(1,i1)*xsjj shpj(2,i1)=shp(2,i1)*xsjj shpj(3,i1)=shp(3,i1)*xsjj shpj(4,i1)=shp(4,i1)*xsj enddo ! ! determination of the stiffness, and/or mass and/or ! buckling matrix ! if(stiffness.or.mass.or.buckling.or.coriolis) then ! if(((iperturb(1).ne.1).and.(iperturb(2).ne.1)).or.buckling) & then jj1=1 do jj=1,nope ! ii1=1 do ii=1,jj ! ! all products of the shape functions for a given ii ! and jj ! do i1=1,3 do j1=1,3 w(i1,j1)=shpj(i1,ii)*shpj(j1,jj) enddo enddo ! ! the following section calculates the static ! part of the stiffness matrix which, for buckling ! calculations, is done in a preliminary static ! call ! if(.not.buckling) then ! if(mattyp.eq.1) then ! s(ii1,jj1)=s(ii1,jj1)+(al*w(1,1)+ & um*(2.d0*w(1,1)+w(2,2)+w(3,3)))*weight ! s(ii1,jj1+1)=s(ii1,jj1+1)+(al*w(1,2)+ & um*w(2,1))*weight s(ii1,jj1+2)=s(ii1,jj1+2)+(al*w(1,3)+ & um*w(3,1))*weight s(ii1+1,jj1)=s(ii1+1,jj1)+(al*w(2,1)+ & um*w(1,2))*weight s(ii1+1,jj1+1)=s(ii1+1,jj1+1)+(al*w(2,2)+ & um*(2.d0*w(2,2)+w(1,1)+w(3,3)))*weight s(ii1+1,jj1+2)=s(ii1+1,jj1+2)+(al*w(2,3)+ & um*w(3,2))*weight s(ii1+2,jj1)=s(ii1+2,jj1)+(al*w(3,1)+ & um*w(1,3))*weight s(ii1+2,jj1+1)=s(ii1+2,jj1+1)+(al*w(3,2)+ & um*w(2,3))*weight s(ii1+2,jj1+2)=s(ii1+2,jj1+2)+(al*w(3,3)+ & um*(2.d0*w(3,3)+w(2,2)+w(1,1)))*weight ! elseif(mattyp.eq.2) then ! s(ii1,jj1)=s(ii1,jj1)+(elas(1)*w(1,1)+ & elas(7)*w(2,2)+elas(8)*w(3,3))*weight s(ii1,jj1+1)=s(ii1,jj1+1)+(elas(2)*w(1,2)+ & elas(7)*w(2,1))*weight s(ii1,jj1+2)=s(ii1,jj1+2)+(elas(4)*w(1,3)+ & elas(8)*w(3,1))*weight s(ii1+1,jj1)=s(ii1+1,jj1)+(elas(7)*w(1,2)+ & elas(2)*w(2,1))*weight s(ii1+1,jj1+1)=s(ii1+1,jj1+1)+ & (elas(7)*w(1,1)+ & elas(3)*w(2,2)+elas(9)*w(3,3))*weight s(ii1+1,jj1+2)=s(ii1+1,jj1+2)+ & (elas(5)*w(2,3)+ & elas(9)*w(3,2))*weight s(ii1+2,jj1)=s(ii1+2,jj1)+ & (elas(8)*w(1,3)+ & elas(4)*w(3,1))*weight s(ii1+2,jj1+1)=s(ii1+2,jj1+1)+ & (elas(9)*w(2,3)+ & elas(5)*w(3,2))*weight s(ii1+2,jj1+2)=s(ii1+2,jj1+2)+ & (elas(8)*w(1,1)+ & elas(9)*w(2,2)+elas(6)*w(3,3))*weight ! else ! do i1=1,3 do j1=1,3 do k1=1,3 do l1=1,3 s(ii1+i1-1,jj1+j1-1)= & s(ii1+i1-1,jj1+j1-1) & +anisox(i1,k1,j1,l1) & *w(k1,l1)*weight enddo enddo enddo enddo ! endif ! ! mass matrix ! if(mass) then sm(ii1,jj1)=sm(ii1,jj1) & +rho*shpj(4,ii)*shp(4,jj)*weight sm(ii1+1,jj1+1)=sm(ii1,jj1) sm(ii1+2,jj1+2)=sm(ii1,jj1) endif ! ! Coriolis matrix ! if(coriolis) then dmass=2.d0* & rho*shpj(4,ii)*shp(4,jj)*weight*dsqrt(omx) sm(ii1,jj1+1)=sm(ii1,jj1+1)-p2(3)*dmass sm(ii1,jj1+2)=sm(ii1,jj1+2)+p2(2)*dmass sm(ii1+1,jj1)=sm(ii1+1,jj1)+p2(3)*dmass sm(ii1+1,jj1+2)=sm(ii1+1,jj1+2)-p2(1)*dmass sm(ii1+2,jj1)=sm(ii1+2,jj1)-p2(2)*dmass sm(ii1+2,jj1+1)=sm(ii1+2,jj1+1)+p2(1)*dmass endif ! else ! ! buckling matrix ! senergyb= & (s11b*w(1,1)+s12b*(w(1,2)+w(2,1)) & +s13b*(w(1,3)+w(3,1))+s22b*w(2,2) & +s23b*(w(2,3)+w(3,2))+s33b*w(3,3))*weight sm(ii1,jj1)=sm(ii1,jj1)-senergyb sm(ii1+1,jj1+1)=sm(ii1+1,jj1+1)-senergyb sm(ii1+2,jj1+2)=sm(ii1+2,jj1+2)-senergyb ! endif ! ii1=ii1+3 enddo jj1=jj1+3 enddo else ! ! stiffness matrix for static and modal ! 2nd order calculations ! ! large displacement stiffness ! do i1=1,3 do j1=1,3 vo(i1,j1)=0.d0 do k1=1,nope vo(i1,j1)=vo(i1,j1)+shp(j1,k1)*voldl(i1,k1) enddo enddo enddo ! if(mattyp.eq.1) then call wcoef(v,vo,al,um) endif ! ! calculating the total mass of the element for ! lumping purposes: only for explicit nonlinear ! dynamic calculations ! if(mass.and.(iexpl.gt.1)) then summass=summass+rho*xsj endif ! jj1=1 do jj=1,nope ! ii1=1 do ii=1,jj ! ! all products of the shape functions for a given ii ! and jj ! do i1=1,3 do j1=1,3 w(i1,j1)=shpj(i1,ii)*shpj(j1,jj) enddo enddo ! if(mattyp.eq.1) then ! do m1=1,3 do m2=1,3 do m3=1,3 do m4=1,3 s(ii1+m2-1,jj1+m1-1)= & s(ii1+m2-1,jj1+m1-1) & +v(m4,m3,m2,m1)*w(m4,m3)*weight enddo enddo enddo enddo ! elseif(mattyp.eq.2) then ! call orthonl(w,vo,elas,s,ii1,jj1,weight) ! else ! call anisonl(w,vo,elas,s,ii1,jj1,weight) ! endif ! ! stress stiffness ! senergy= & (s11*w(1,1)+s12*(w(1,2)+w(2,1)) & +s13*(w(1,3)+w(3,1))+s22*w(2,2) & +s23*(w(2,3)+w(3,2))+s33*w(3,3))*weight s(ii1,jj1)=s(ii1,jj1)+senergy s(ii1+1,jj1+1)=s(ii1+1,jj1+1)+senergy s(ii1+2,jj1+2)=s(ii1+2,jj1+2)+senergy ! ! stiffness contribution of centrifugal forces ! if(mass.and.(om.gt.0.d0)) then dmass=shpj(4,ii)*shp(4,jj)*weight*om do m1=1,3 s(ii1+m1-1,jj1+m1-1)=s(ii1+m1-1,jj1+m1-1)- & dmass do m2=1,3 s(ii1+m1-1,jj1+m2-1)=s(ii1+m1-1,jj1+m2-1)+ & dmass*p2(m1)*p2(m2) enddo enddo endif ! ! mass matrix ! if(mass) then sm(ii1,jj1)=sm(ii1,jj1) & +rho*shpj(4,ii)*shp(4,jj)*weight sm(ii1+1,jj1+1)=sm(ii1,jj1) sm(ii1+2,jj1+2)=sm(ii1,jj1) endif ! ! Coriolis matrix ! if(coriolis) then dmass=2.d0* & rho*shpj(4,ii)*shp(4,jj)*weight*dsqrt(omx) sm(ii1,jj1+1)=sm(ii1,jj1+1)-p2(3)*dmass sm(ii1,jj1+2)=sm(ii1,jj1+2)+p2(2)*dmass sm(ii1+1,jj1)=sm(ii1+1,jj1)+p2(3)*dmass sm(ii1+1,jj1+2)=sm(ii1+1,jj1+2)-p2(1)*dmass sm(ii1+2,jj1)=sm(ii1+2,jj1)-p2(2)*dmass sm(ii1+2,jj1+1)=sm(ii1+2,jj1+1)+p2(1)*dmass endif ! ii1=ii1+3 enddo jj1=jj1+3 enddo endif ! endif ! ! add hourglass control stiffnesses: C3D8R only. if(lakonl(1:5).eq.'C3D8R') then call hgstiffness(s,elas,a,gs) endif ! ! computation of the right hand side ! if(rhsi) then ! ! distributed body flux ! if(nload.gt.0) then call nident2(nelemload,nelem,nload,id) do if((id.eq.0).or.(nelemload(1,id).ne.nelem)) exit if((sideload(id)(1:2).ne.'BX').and. & (sideload(id)(1:2).ne.'BY').and. & (sideload(id)(1:2).ne.'BZ')) then id=id-1 cycle endif if(sideload(id)(3:4).eq.'NU') then do j=1,3 coords(j)=0.d0 do i1=1,nope coords(j)=coords(j)+ & shp(4,i1)*xl(j,i1) enddo enddo if(sideload(id)(1:2).eq.'BX') then jltyp=1 elseif(sideload(id)(1:2).eq.'BY') then jltyp=2 elseif(sideload(id)(1:2).eq.'BZ') then jltyp=3 endif iscale=1 call dload(xload(1,id),istep,iinc,tvar,nelem,i, & layer,kspt,coords,jltyp,sideload(id),vold,co, & lakonl,konl,ipompc,nodempc,coefmpc,nmpc,ikmpc, & ilmpc,iscale,veold,rho,amat,mi) if((nmethod.eq.1).and.(iscale.ne.0)) & xload(1,id)=xloadold(1,id)+ & (xload(1,id)-xloadold(1,id))*reltime endif jj1=1 do jj=1,nope if(sideload(id)(1:2).eq.'BX') & ff(jj1)=ff(jj1)+xload(1,id)*shpj(4,jj)*weight if(sideload(id)(1:2).eq.'BY') & ff(jj1+1)=ff(jj1+1)+xload(1,id)*shpj(4,jj)*weight if(sideload(id)(1:2).eq.'BZ') & ff(jj1+2)=ff(jj1+2)+xload(1,id)*shpj(4,jj)*weight jj1=jj1+3 enddo id=id-1 enddo endif ! ! body forces ! if(nbody.ne.0) then if(om.gt.0.d0) then do i1=1,3 ! ! computation of the global coordinates of the gauss ! point ! q(i1)=0.d0 c if(iperturb(1).eq.0) then if((iperturb(1).ne.1).and.(iperturb(2).ne.1)) then do j1=1,nope q(i1)=q(i1)+shp(4,j1)*xl(i1,j1) enddo else do j1=1,nope q(i1)=q(i1)+shp(4,j1)* & (xl(i1,j1)+voldl(i1,j1)) enddo endif ! q(i1)=q(i1)-p1(i1) enddo const=q(1)*p2(1)+q(2)*p2(2)+q(3)*p2(3) ! ! inclusion of the centrifugal force into the body force ! do i1=1,3 bf(i1)=bodyf(i1)+(q(i1)-const*p2(i1))*om enddo else do i1=1,3 bf(i1)=bodyf(i1) enddo endif jj1=1 do jj=1,nope ff(jj1)=ff(jj1)+bf(1)*shpj(4,jj)*weight ff(jj1+1)=ff(jj1+1)+bf(2)*shpj(4,jj)*weight ff(jj1+2)=ff(jj1+2)+bf(3)*shpj(4,jj)*weight jj1=jj1+3 enddo endif ! endif ! enddo ! c write(*,*) nelem c write(*,'(6(1x,e11.4))') ((s(i1,j1),i1=1,j1),j1=1,60) c write(*,*) c if((.not.buckling).and.(nload.ne.0)) then ! ! distributed loads ! call nident2(nelemload,nelem,nload,id) do if((id.eq.0).or.(nelemload(1,id).ne.nelem)) exit if(sideload(id)(1:1).ne.'P') then id=id-1 cycle endif read(sideload(id)(2:2),'(i1)') ig ! ! check whether 8 or 9-nodes face ! if(nope.eq.26) then if(konl(20+ig).eq.konl(20)) then nopes=8 else nopes=9 endif elseif(nope.eq.14) then if(konl(10+ig).eq.konl(10)) then nopes=6 else nopes=7 endif endif ! ! treatment of wedge faces ! if(lakonl(4:4).eq.'6') then mint2d=1 if(ig.le.2) then nopes=3 else nopes=4 endif endif if(lakonl(4:5).eq.'15') then if(ig.le.2) then mint2d=3 nopes=6 else mint2d=4 nopes=8 endif endif ! c Bernhardi start if((nope.eq.26).or.(nope.eq.20).or.(nope.eq.8).or. & (nope.eq.11)) then c Bernhardi end c if(iperturb(1).eq.0) then if((iperturb(1).ne.1).and.(iperturb(2).ne.1)) then do i=1,nopes do j=1,3 xl2(j,i)=co(j,konl(ifaceq(i,ig))) enddo enddo else if(mass) then do i=1,nopes do j=1,3 xl1(j,i)=co(j,konl(ifaceq(i,ig))) enddo enddo endif do i=1,nopes do j=1,3 xl2(j,i)=co(j,konl(ifaceq(i,ig)))+ & vold(j,konl(ifaceq(i,ig))) enddo enddo endif elseif((nope.eq.10).or.(nope.eq.4)) then c if(iperturb(1).eq.0) then if((iperturb(1).ne.1).and.(iperturb(2).ne.1)) then do i=1,nopes do j=1,3 xl2(j,i)=co(j,konl(ifacet(i,ig))) enddo enddo else if(mass) then do i=1,nopes do j=1,3 xl1(j,i)=co(j,konl(ifacet(i,ig))) enddo enddo endif do i=1,nopes do j=1,3 xl2(j,i)=co(j,konl(ifacet(i,ig)))+ & vold(j,konl(ifacet(i,ig))) enddo enddo endif else c if(iperturb(1).eq.0) then if((iperturb(1).ne.1).and.(iperturb(2).ne.1)) then do i=1,nopes do j=1,3 xl2(j,i)=co(j,konl(ifacew(i,ig))) enddo enddo else if(mass) then do i=1,nopes do j=1,3 xl1(j,i)=co(j,konl(ifacew(i,ig))) enddo enddo endif do i=1,nopes do j=1,3 xl2(j,i)=co(j,konl(ifacew(i,ig)))+ & vold(j,konl(ifacew(i,ig))) enddo enddo endif endif ! do i=1,mint2d if((lakonl(4:5).eq.'8R').or. & ((lakonl(4:4).eq.'6').and.(nopes.eq.4))) then xi=gauss2d1(1,i) et=gauss2d1(2,i) weight=weight2d1(i) elseif((lakonl(4:4).eq.'8').or. & (lakonl(4:6).eq.'20R').or.(lakonl(4:6).eq.'26R').or. & ((lakonl(4:5).eq.'15').and.(nopes.eq.8))) then xi=gauss2d2(1,i) et=gauss2d2(2,i) weight=weight2d2(i) elseif(lakonl(4:4).eq.'2') then xi=gauss2d3(1,i) et=gauss2d3(2,i) weight=weight2d3(i) elseif((lakonl(4:5).eq.'10').or.(lakonl(4:5).eq.'14').or. & ((lakonl(4:5).eq.'15').and.(nopes.eq.6))) then xi=gauss2d5(1,i) et=gauss2d5(2,i) weight=weight2d5(i) elseif((lakonl(4:4).eq.'4').or. & ((lakonl(4:4).eq.'6').and.(nopes.eq.3))) then xi=gauss2d4(1,i) et=gauss2d4(2,i) weight=weight2d4(i) endif ! if(rhsi) then if(nopes.eq.9) then call shape9q(xi,et,xl2,xsj2,xs2,shp2,iflag) elseif(nopes.eq.8) then call shape8q(xi,et,xl2,xsj2,xs2,shp2,iflag) elseif(nopes.eq.4) then call shape4q(xi,et,xl2,xsj2,xs2,shp2,iflag) elseif(nopes.eq.6) then call shape6tri(xi,et,xl2,xsj2,xs2,shp2,iflag) elseif(nopes.eq.7) then call shape7tri(xi,et,xl2,xsj2,xs2,shp2,iflag) else call shape3tri(xi,et,xl2,xsj2,xs2,shp2,iflag) endif ! ! for nonuniform load: determine the coordinates of the ! point (transferred into the user subroutine) ! if(sideload(id)(3:4).eq.'NU') then do k=1,3 coords(k)=0.d0 do j=1,nopes coords(k)=coords(k)+xl2(k,j)*shp2(4,j) enddo enddo read(sideload(id)(2:2),'(i1)') jltyp jltyp=jltyp+20 iscale=1 call dload(xload(1,id),istep,iinc,tvar,nelem,i,layer, & kspt,coords,jltyp,sideload(id),vold,co,lakonl, & konl,ipompc,nodempc,coefmpc,nmpc,ikmpc,ilmpc, & iscale,veold,rho,amat,mi) if((nmethod.eq.1).and.(iscale.ne.0)) & xload(1,id)=xloadold(1,id)+ & (xload(1,id)-xloadold(1,id))*reltime elseif(sideload(id)(3:4).eq.'SM') then ! ! submodel boundary: interpolation from the ! global model ! do k=1,3 coords(k)=0.d0 do j=1,nopes coords(k)=coords(k)+xl2(k,j)*shp2(4,j) enddo enddo read(sideload(id)(2:2),'(i1)') jltyp ! entity='T' six=6 do k=1,6 iselect(k)=k+4 enddo iface=10*nelem+jltyp call interpolsubmodel(integerglob,doubleglob,stress, & coords,iselect,six,iface,tieset,istartset, & iendset,ialset,ntie,entity) c write(*,*) 'e_c3d ',(stress(k),k=1,6) ! ! cave: stress order of cgx: xx,yy,zz,xy,yz,xz ! t(1)=stress(1)*xsj2(1)+stress(4)*xsj2(2)+ & stress(6)*xsj2(3) t(2)=stress(4)*xsj2(1)+stress(2)*xsj2(2)+ & stress(5)*xsj2(3) t(3)=stress(6)*xsj2(1)+stress(5)*xsj2(2)+ & stress(3)*xsj2(3) ! xload(1,id)=-1.d0 do k=1,3 xsj2(k)=t(k) enddo endif ! do k=1,nopes c Bernhardi start if((nope.eq.26).or.(nope.eq.20).or.(nope.eq.8).or. & (nope.eq.11)) then c Bernhardi end ipointer=(ifaceq(k,ig)-1)*3 elseif((nope.eq.10).or.(nope.eq.4)) then ipointer=(ifacet(k,ig)-1)*3 else ipointer=(ifacew(k,ig)-1)*3 endif ff(ipointer+1)=ff(ipointer+1)-shp2(4,k)*xload(1,id) & *xsj2(1)*weight ff(ipointer+2)=ff(ipointer+2)-shp2(4,k)*xload(1,id) & *xsj2(2)*weight ff(ipointer+3)=ff(ipointer+3)-shp2(4,k)*xload(1,id) & *xsj2(3)*weight enddo ! ! stiffness contribution of the distributed load ! reference: Dhondt G., The Finite Element Method for ! three-dimensional thermomechanical Applications, ! Wiley, 2004, p 153, eqn. (3.54). ! c elseif((mass).and.(iperturb(1).ne.0)) then elseif((mass).and. & ((iperturb(1).eq.1).or.(iperturb(2).eq.1))) then if(nopes.eq.9) then call shape9q(xi,et,xl1,xsj2,xs2,shp2,iflag) elseif(nopes.eq.8) then call shape8q(xi,et,xl1,xsj2,xs2,shp2,iflag) elseif(nopes.eq.4) then call shape4q(xi,et,xl1,xsj2,xs2,shp2,iflag) elseif(nopes.eq.6) then call shape6tri(xi,et,xl1,xsj2,xs2,shp2,iflag) elseif(nopes.eq.7) then call shape7tri(xi,et,xl1,xsj2,xs2,shp2,iflag) else call shape3tri(xi,et,xl1,xsj2,xs2,shp2,iflag) endif ! ! for nonuniform load: determine the coordinates of the ! point (transferred into the user subroutine) ! if(sideload(id)(3:4).eq.'NU') then do k=1,3 coords(k)=0.d0 do j=1,nopes coords(k)=coords(k)+xl1(k,j)*shp2(4,j) enddo enddo read(sideload(id)(2:2),'(i1)') jltyp jltyp=jltyp+20 iscale=1 call dload(xload(1,id),istep,iinc,tvar,nelem,i,layer, & kspt,coords,jltyp,sideload(id),vold,co,lakonl, & konl,ipompc,nodempc,coefmpc,nmpc,ikmpc,ilmpc, & iscale,veold,rho,amat,mi) if((nmethod.eq.1).and.(iscale.ne.0)) & xload(1,id)=xloadold(1,id)+ & (xload(1,id)-xloadold(1,id))*reltime elseif(sideload(id)(3:4).eq.'SM') then ! ! submodel boundary: interpolation from the ! global model ! do k=1,3 coords(k)=0.d0 do j=1,nopes coords(k)=coords(k)+xl2(k,j)*shp2(4,j) enddo enddo read(sideload(id)(2:2),'(i1)') jltyp ! entity='T' six=6 do k=1,6 iselect(k)=k+4 enddo iface=10*nelem+jltyp call interpolsubmodel(integerglob,doubleglob,stress, & coords,iselect,six,iface,tieset,istartset, & iendset,ialset,ntie,entity) c write(*,*) 'e_c3d ',(stress(k),k=1,6) ! stre(1,1)=stress(1) stre(1,2)=stress(4) stre(1,3)=stress(6) stre(2,1)=stress(4) stre(2,2)=stress(2) stre(2,3)=stress(5) stre(3,1)=stress(6) stre(3,2)=stress(5) stre(3,3)=stress(3) endif ! ! calculation of the deformation gradient ! do k=1,3 do l=1,3 xkl(k,l)=0.d0 do ii=1,nopes xkl(k,l)=xkl(k,l)+shp2(l,ii)*xl2(k,ii) enddo enddo enddo ! do ii=1,nopes c Bernhardi start if((nope.eq.26).or.(nope.eq.20).or.(nope.eq.8).or. & (nope.eq.11)) then c Bernhardi end ipointeri=(ifaceq(ii,ig)-1)*3 elseif((nope.eq.10).or.(nope.eq.4).or. & (nope.eq.14))then ipointeri=(ifacet(ii,ig)-1)*3 else ipointeri=(ifacew(ii,ig)-1)*3 endif do jj=1,nopes c Bernhardi start if((nope.eq.26).or.(nope.eq.20).or.(nope.eq.8) & .or.(nope.eq.11)) then c Bernhardi end ipointerj=(ifaceq(jj,ig)-1)*3 elseif((nope.eq.10).or.(nope.eq.4).or. & (nope.eq.14)) then ipointerj=(ifacet(jj,ig)-1)*3 else ipointerj=(ifacew(jj,ig)-1)*3 endif ! ! if no submodel: only pressure ! else: complete stress vector ! if(sideload(id)(3:4).ne.'SM') then do k=1,3 do l=1,3 if(k.eq.l) cycle eknlsign=1.d0 if(k*l.eq.2) then n=3 if(k.lt.l) eknlsign=-1.d0 elseif(k*l.eq.3) then n=2 if(k.gt.l) eknlsign=-1.d0 else n=1 if(k.lt.l) eknlsign=-1.d0 endif term=weight*xload(1,id)*shp2(4,ii)* & eknlsign*(xsj2(1)* & (xkl(n,2)*shp2(3,jj)-xkl(n,3)* & shp2(2,jj))+xsj2(2)* & (xkl(n,3)*shp2(1,jj)-xkl(n,1)* & shp2(3,jj))+xsj2(3)* & (xkl(n,1)*shp2(2,jj)-xkl(n,2)* & shp2(1,jj))) s(ipointeri+k,ipointerj+l)= & s(ipointeri+k,ipointerj+l)+term/2.d0 s(ipointerj+l,ipointeri+k)= & s(ipointerj+l,ipointeri+k)+term/2.d0 enddo enddo else do kk=1,3 do k=1,3 do l=1,3 if(k.eq.l) cycle eknlsign=1.d0 if(k*l.eq.2) then n=3 if(k.lt.l) eknlsign=-1.d0 elseif(k*l.eq.3) then n=2 if(k.gt.l) eknlsign=-1.d0 else n=1 if(k.lt.l) eknlsign=-1.d0 endif term=-weight*stre(kk,k)*shp2(4,ii)* & eknlsign*(xsj2(1)* & (xkl(n,2)*shp2(3,jj)-xkl(n,3)* & shp2(2,jj))+xsj2(2)* & (xkl(n,3)*shp2(1,jj)-xkl(n,1)* & shp2(3,jj))+xsj2(3)* & (xkl(n,1)*shp2(2,jj)-xkl(n,2)* & shp2(1,jj))) s(ipointeri+kk,ipointerj+l)= & s(ipointeri+kk,ipointerj+l)+term/2.d0 s(ipointerj+l,ipointeri+kk)= & s(ipointerj+l,ipointeri+kk)+term/2.d0 enddo enddo enddo endif enddo enddo ! endif enddo ! id=id-1 enddo endif ! ! for axially symmetric and plane stress/strain elements: ! complete s and sm ! if(((lakonl(4:5).eq.'8 ').or. & ((lakonl(4:6).eq.'20R').and.(lakonl(7:8).ne.'BR'))).and. & ((lakonl(7:7).eq.'A').or.(lakonl(7:7).eq.'S').or. & (lakonl(7:7).eq.'E'))) then do i=1,60 do j=i,60 k=abs(iperm(i)) l=abs(iperm(j)) if(k.gt.l) then m=k k=l l=m endif sax(i,j)=s(k,l)*iperm(i)*iperm(j)/(k*l) enddo enddo do i=1,60 do j=i,60 s(i,j)=s(i,j)+sax(i,j) enddo enddo ! if((nload.ne.0).or.(nbody.ne.0)) then do i=1,60 k=abs(iperm(i)) ffax(i)=ff(k)*iperm(i)/k enddo do i=1,60 ff(i)=ff(i)+ffax(i) enddo endif ! if(mass) then summass=2.d0*summass do i=1,60 do j=i,60 k=abs(iperm(i)) l=abs(iperm(j)) if(k.gt.l) then m=k k=l l=m endif sax(i,j)=sm(k,l)*iperm(i)*iperm(j)/(k*l) enddo enddo do i=1,60 do j=i,60 sm(i,j)=sm(i,j)+sax(i,j) enddo enddo endif endif ! if(mass.and.(iexpl.gt.1)) then ! ! scaling the diagonal terms of the mass matrix such that the total mass ! is right (LUMPING; for explicit dynamic calculations) ! sume=0.d0 summ=0.d0 do i=1,3*nopev,3 sume=sume+sm(i,i) enddo do i=3*nopev+1,3*nope,3 summ=summ+sm(i,i) enddo ! if((nope.eq.26).or.(nope.eq.20)) then c alp=.2215d0 alp=.2917d0 ! maybe alp=.2917d0 is better?? elseif((nope.eq.10).or.(nope.eq.14)) then alp=0.1203d0 elseif(nope.eq.15) then alp=0.2141d0 endif ! if((nope.eq.26).or.(nope.eq.20).or.(nope.eq.10).or. & (nope.eq.15).or.(nope.eq.14)) then factore=summass*alp/(1.d0+alp)/sume factorm=summass/(1.d0+alp)/summ else factore=summass/sume endif ! do i=1,3*nopev,3 sm(i,i)=sm(i,i)*factore sm(i+1,i+1)=sm(i,i) sm(i+2,i+2)=sm(i,i) enddo do i=3*nopev+1,3*nope,3 sm(i,i)=sm(i,i)*factorm sm(i+1,i+1)=sm(i,i) sm(i+2,i+2)=sm(i,i) enddo ! endif ! c if(nelem.eq.1) then c write(*,'(8(1x,e11.4))') ((s(i,j),i=1,60),j=1,60) c endif return end
gpl-2.0
prool/ccx_prool
CalculiX/ccx_2.12/src/umat.f
6
2859
! ! CalculiX - A 3-dimensional finite element program ! Copyright (C) 1998-2015 Guido Dhondt ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License as ! published by the Free Software Foundation(version 2); ! ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! subroutine umat(stress,statev,ddsdde,sse,spd,scd, & rpl,ddsddt,drplde,drpldt, & stran,dstran,time,dtime,temp,dtemp,predef,dpred,cmname, & ndi,nshr,ntens,nstatv,props,nprops,coords,drot,pnewdt, & celent,dfgrd0,dfgrd1,noel,npt,layer,kspt,kstep,kinc) ! ! here, an ABAQUS umat routine can be inserted ! ! note that reals should be double precision (REAL*8) ! implicit none ! character*80 cmname ! integer ndi,nshr,ntens,nstatv,nprops,noel,npt,layer,kspt, & kstep,kinc ! real*8 stress(ntens),statev(nstatv), & ddsdde(ntens,ntens),ddsddt(ntens),drplde(ntens), & stran(ntens),dstran(ntens),time(2),celent, & props(nprops),coords(3),drot(3,3),dfgrd0(3,3),dfgrd1(3,3), & sse,spd,scd,rpl,drpldt,dtime,temp,dtemp,predef,dpred, & pnewdt ! ! START EXAMPLE LINEAR ELASTIC MATERIAL ! integer i,j real*8 e,un,al,um,am1,am2 ! c write(*,*) 'noel,npt ',noel,npt c write(*,*) 'stress ',(stress(i),i=1,6) c write(*,*) 'stran ',(stran(i),i=1,6) c write(*,*) 'dstran ',(dstran(i),i=1,6) c write(*,*) 'drot ',((drot(i,j),i=1,3),j=1,3) e=props(1) un=props(2) al=un*e/(1.d0+un)/(1.d0-2.d0*un) um=e/2.d0/(1.d0+un) am1=al+2.d0*um am2=um ! ! stress ! stress(1)=stress(1)+am1*dstran(1)+al*(dstran(2)+dstran(3)) stress(2)=stress(2)+am1*dstran(2)+al*(dstran(1)+dstran(3)) stress(3)=stress(3)+am1*dstran(3)+al*(dstran(1)+dstran(2)) stress(4)=stress(4)+am2*dstran(4) stress(5)=stress(5)+am2*dstran(5) stress(6)=stress(6)+am2*dstran(6) ! ! stiffness ! do i=1,6 do j=1,6 ddsdde(i,j)=0.d0 enddo enddo ddsdde(1,1)=al+2.d0*um ddsdde(1,2)=al ddsdde(2,1)=al ddsdde(2,2)=al+2.d0*um ddsdde(1,3)=al ddsdde(3,1)=al ddsdde(2,3)=al ddsdde(3,2)=al ddsdde(3,3)=al+2.d0*um ddsdde(4,4)=um ddsdde(5,5)=um ddsdde(6,6)=um ! ! END EXAMPLE LINEAR ELASTIC MATERIAL ! return end
gpl-2.0
prool/ccx_prool
CalculiX/ccx_2.8p2/src/umat.f
6
2859
! ! CalculiX - A 3-dimensional finite element program ! Copyright (C) 1998-2015 Guido Dhondt ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License as ! published by the Free Software Foundation(version 2); ! ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! subroutine umat(stress,statev,ddsdde,sse,spd,scd, & rpl,ddsddt,drplde,drpldt, & stran,dstran,time,dtime,temp,dtemp,predef,dpred,cmname, & ndi,nshr,ntens,nstatv,props,nprops,coords,drot,pnewdt, & celent,dfgrd0,dfgrd1,noel,npt,layer,kspt,kstep,kinc) ! ! here, an ABAQUS umat routine can be inserted ! ! note that reals should be double precision (REAL*8) ! implicit none ! character*80 cmname ! integer ndi,nshr,ntens,nstatv,nprops,noel,npt,layer,kspt, & kstep,kinc ! real*8 stress(ntens),statev(nstatv), & ddsdde(ntens,ntens),ddsddt(ntens),drplde(ntens), & stran(ntens),dstran(ntens),time(2),celent, & props(nprops),coords(3),drot(3,3),dfgrd0(3,3),dfgrd1(3,3), & sse,spd,scd,rpl,drpldt,dtime,temp,dtemp,predef,dpred, & pnewdt ! ! START EXAMPLE LINEAR ELASTIC MATERIAL ! integer i,j real*8 e,un,al,um,am1,am2 ! c write(*,*) 'noel,npt ',noel,npt c write(*,*) 'stress ',(stress(i),i=1,6) c write(*,*) 'stran ',(stran(i),i=1,6) c write(*,*) 'dstran ',(dstran(i),i=1,6) c write(*,*) 'drot ',((drot(i,j),i=1,3),j=1,3) e=props(1) un=props(2) al=un*e/(1.d0+un)/(1.d0-2.d0*un) um=e/2.d0/(1.d0+un) am1=al+2.d0*um am2=um ! ! stress ! stress(1)=stress(1)+am1*dstran(1)+al*(dstran(2)+dstran(3)) stress(2)=stress(2)+am1*dstran(2)+al*(dstran(1)+dstran(3)) stress(3)=stress(3)+am1*dstran(3)+al*(dstran(1)+dstran(2)) stress(4)=stress(4)+am2*dstran(4) stress(5)=stress(5)+am2*dstran(5) stress(6)=stress(6)+am2*dstran(6) ! ! stiffness ! do i=1,6 do j=1,6 ddsdde(i,j)=0.d0 enddo enddo ddsdde(1,1)=al+2.d0*um ddsdde(1,2)=al ddsdde(2,1)=al ddsdde(2,2)=al+2.d0*um ddsdde(1,3)=al ddsdde(3,1)=al ddsdde(2,3)=al ddsdde(3,2)=al ddsdde(3,3)=al+2.d0*um ddsdde(4,4)=um ddsdde(5,5)=um ddsdde(6,6)=um ! ! END EXAMPLE LINEAR ELASTIC MATERIAL ! return end
gpl-2.0
epfl-cosmo/q-e
GWW/pw4gww/mp_wave_parallel.f90
9
11158
! ! Copyright (C) 2001-2013 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! MODULE mp_wave_parallel IMPLICIT NONE SAVE CONTAINS SUBROUTINE mergewfp ( npw,pw, pwt, ngwl, ig_l2g, mpime, nproc, root, comm ) ! ... This subroutine merges the pieces of a wave functions (pw) splitted across ! ... processors into a total wave function (pwt) containing al the components ! ... in a pre-defined order (the same as if only one processor is used) USE kinds USE parallel_include USE io_global, ONLY :stdout IMPLICIT NONE INTEGER, INTENT(in) :: npw,ngwl COMPLEX(DP), intent(in) :: PW(npw,nproc) COMPLEX(DP), intent(out) :: PWT(:) INTEGER, INTENT(IN) :: mpime ! index of the calling processor ( starting from 0 ) INTEGER, INTENT(IN) :: nproc ! number of processors INTEGER, INTENT(IN) :: root ! root processor ( the one that should receive the data ) INTEGER, INTENT(IN) :: comm ! communicator INTEGER, INTENT(IN) :: ig_l2g(:) INTEGER, ALLOCATABLE :: ig_ip(:) COMPLEX(DP), ALLOCATABLE :: pw_ip(:) INTEGER :: ierr, i, ip, ngw_ip, ngw_lmax, itmp, igwx, gid, req #if defined __MPI INTEGER :: istatus(MPI_STATUS_SIZE) #endif INTEGER :: iorig, idest ! ! ... Subroutine Body ! igwx = MAXVAL( ig_l2g(1:ngwl) ) #if defined __MPI gid = comm ! ... Get local and global wavefunction dimensions CALL MPI_ALLREDUCE( ngwl, ngw_lmax, 1, MPI_INTEGER, MPI_MAX, gid, IERR ) CALL MPI_ALLREDUCE( igwx, itmp, 1, MPI_INTEGER, MPI_MAX, gid, IERR ) igwx = itmp #endif IF( igwx > SIZE( pwt ) ) & CALL errore(' mergewf ',' wrong size for pwt ',SIZE(pwt) ) #if defined __MPI ALLOCATE(ig_ip(ngw_lmax)) ALLOCATE(pw_ip(ngw_lmax)) do ip = 0, nproc-1 if( ip/=0) then ! ... In turn each processors send to root the wave components and their indexes in the ! ... global array idest=mpime+ip if(idest>nproc-1)idest=idest-nproc iorig=mpime-ip if(iorig<0)iorig=iorig+nproc CALL MPI_ISEND( ig_l2g, ngwl, MPI_INTEGER, idest, IP, gid, req,IERR ) CALL MPI_RECV( ig_ip, ngw_lmax, MPI_INTEGER, iorig, IP, gid, istatus, IERR ) CALL MPI_WAIT(req,istatus,ierr) CALL MPI_ISEND( pw(1,idest+1), ngwl, MPI_DOUBLE_COMPLEX, idest, IP, gid, req,IERR ) CALL MPI_RECV( pw_ip, ngw_lmax, MPI_DOUBLE_COMPLEX, iorig, IP, gid, istatus, IERR ) CALL MPI_GET_COUNT( istatus, MPI_DOUBLE_COMPLEX, ngw_ip, ierr ) CALL MPI_WAIT(req,istatus,ierr) DO I = 1, ngw_ip PWT(ig_ip(i)) = pw_ip(i) END DO ELSE DO I = 1, ngwl PWT(ig_l2g(i)) = pw(i,mpime+1) END DO END IF CALL MPI_BARRIER( gid, IERR ) END DO DEALLOCATE(ig_ip) DEALLOCATE(pw_ip) #elif ! defined __MPI DO I = 1, ngwl PWT( ig_l2g(i) ) = pw(i,1) END DO #else CALL errore(' MERGEWF ',' no communication protocol ',0) #endif RETURN END SUBROUTINE mergewfp SUBROUTINE splitwfp (npw, pw, pwt, ngwl, ig_l2g, mpime, nproc,root, comm ) ! ... This subroutine splits a total wave function (pwt) containing al the components ! ... in a pre-defined order (the same as if only one processor is used), across ! ... processors (pw). USE kinds USE parallel_include USE io_global, ONLY : stdout IMPLICIT NONE INTEGER, INTENT(in) :: npw,nproc COMPLEX(DP), INTENT(OUT) :: PW(npw,nproc) COMPLEX(DP), INTENT(IN) :: PWT(:) INTEGER, INTENT(IN) :: mpime, root INTEGER, INTENT(IN) :: comm ! communicator INTEGER, INTENT(IN) :: ig_l2g(:) INTEGER, INTENT(IN) :: ngwl INTEGER, ALLOCATABLE :: ig_ip(:) COMPLEX(DP), ALLOCATABLE :: pw_ip(:) INTEGER ierr, i, ngw_ip, ip, ngw_lmax, gid, igwx, itmp,len, req #if defined __MPI integer istatus(MPI_STATUS_SIZE) #endif INTEGER :: iorig, idest ! ! ... Subroutine Body ! igwx = MAXVAL( ig_l2g(1:ngwl) ) #if defined __MPI gid = comm ! ... Get local and global wavefunction dimensions CALL MPI_ALLREDUCE(ngwl, ngw_lmax, 1, MPI_INTEGER, MPI_MAX, gid, IERR ) CALL MPI_ALLREDUCE(igwx, itmp , 1, MPI_INTEGER, MPI_MAX, gid, IERR ) igwx = itmp #endif IF( igwx > SIZE( pwt ) ) & CALL errore(' splitwf ',' wrong size for pwt ',SIZE(pwt) ) #if defined __MPI ALLOCATE(ig_ip(ngw_lmax)) ALLOCATE(pw_ip(ngw_lmax)) DO ip = 0, nproc-1 idest=mpime+ip if(idest>nproc-1)idest=idest-nproc iorig=mpime-ip if(iorig<0)iorig=iorig+nproc if(ip/=0) then CALL MPI_ISEND( ig_l2g, ngwl, MPI_INTEGER, iorig, IP, gid,req,IERR) CALL MPI_RECV( ig_ip, ngw_lmax, MPI_INTEGER, idest, IP, gid, istatus, IERR ) CALL MPI_GET_COUNT(istatus, MPI_INTEGER, ngw_ip, ierr) DO i = 1, ngw_ip pw_ip(i) = PWT(ig_ip(i)) END DO CALL MPI_WAIT(req,istatus,ierr) CALL MPI_ISEND( pw_ip, ngw_ip, MPI_DOUBLE_COMPLEX, idest, IP, gid,req, IERR ) CALL MPI_RECV( pw(1,iorig+1), ngwl, MPI_DOUBLE_COMPLEX, iorig, IP, gid, istatus, IERR ) !CALL MPI_GET_COUNT(istatus, MPI_INTEGER, ngw_ip, ierr) CALL MPI_WAIT(req,istatus,ierr) ELSE DO i = 1, ngwl pw(i,mpime+1) = PWT(ig_l2g(i)) END DO END IF CALL MPI_BARRIER(gid, IERR) END DO DEALLOCATE(ig_ip) DEALLOCATE(pw_ip) #elif ! defined __MPI DO I = 1, ngwl pw(i,1) = pwt( ig_l2g(i) ) END DO #else CALL errore(' SPLITWF ',' no communication protocol ',0) #endif RETURN END SUBROUTINE splitwfp END MODULE mp_wave_parallel SUBROUTINE reorderwfp (nbands,npw1, npw2,pw1,pw2, ngwl1,ngwl2, ig_l2g1,ig_l2g2,n_g,mpime, nproc,root, comm ) USE kinds USE parallel_include USE io_global, ONLY : stdout USE mp_wave_parallel IMPLICIT NONE INTEGER, INTENT(in) :: npw1,npw2,nbands COMPLEX(DP), INTENT(OUT) :: pw1(npw1,nbands),pw2(npw2,nbands) INTEGER, INTENT(IN) :: mpime, root, nproc INTEGER, INTENT(IN) :: comm ! communicator INTEGER, INTENT(IN) :: ig_l2g1(ngwl1),ig_l2g2(ngwl2) INTEGER, INTENT(IN) :: ngwl1,ngwl2 INTEGER, INTENT(in) :: n_g!global maximum number of G vectors for both grids COMPLEX(kind=DP), ALLOCATABLE :: cbuf1(:,:),cbuf2(:,:), pwt(:) INTEGER :: ii, ilast allocate(cbuf1(npw1,nproc),cbuf2(npw2,nproc)) allocate(pwt(n_g)) cbuf1(:,:)=(0.d0,0.d0) cbuf2(:,:)=(0.d0,0.d0) !loop on block of states do ii=1,nbands,nproc ilast=min(nbands,ii+nproc-1) cbuf1(1:npw1,1:(ilast-ii+1))=pw1(1:npw1,ii:ilast) call mergewfp ( npw1,cbuf1, pwt, ngwl1, ig_l2g1, mpime, nproc, root, comm ) call splitwfp (npw2, cbuf2, pwt, ngwl2, ig_l2g2, mpime, nproc,root, comm ) pw2(1:npw2,ii:ilast)=cbuf2(1:npw2,1:(ilast-ii+1)) enddo deallocate(cbuf1,cbuf2) deallocate(pwt) return END SUBROUTINE reorderwfp SUBROUTINE reorderwfp_col (nbands,npw1, npw2,pw1,pw2, ngwl1,ngwl2, ig_l2g1,ig_l2g2,n_g,mpime, nproc, comm ) !routine using collective mpi calls USE kinds USE parallel_include USE io_global, ONLY : stdout USE mp_wave_parallel IMPLICIT NONE INTEGER, INTENT(in) :: npw1,npw2,nbands COMPLEX(kind=DP) :: pw1(npw1,nbands),pw2(npw2,nbands) INTEGER, INTENT(IN) :: mpime, nproc INTEGER, INTENT(IN) :: comm ! communicator INTEGER, INTENT(IN) :: ig_l2g1(ngwl1),ig_l2g2(ngwl2) INTEGER, INTENT(IN) :: ngwl1,ngwl2 INTEGER, INTENT(in) :: n_g!global maximum number of G vectors for both grids INTEGER :: ngwl1_max,ngwl2_max,npw1_max,npw2_max INTEGER :: gid,ierr INTEGER, ALLOCATABLE :: npw1_loc(:),npw2_loc(:) INTEGER, ALLOCATABLE :: ig_l2g1_tot(:,:),ig_l2g2_tot(:,:), itmp(:) INTEGER :: ii,ip,ilast,iband COMPLEX(kind=DP), ALLOCATABLE :: pw1_tot(:,:),pw2_tot(:,:) COMPLEX(kind=DP), ALLOCATABLE :: pw1_tmp(:),pw2_tmp(:), pw_global(:) gid=comm #if defined __MPI allocate(npw1_loc(nproc),npw2_loc(nproc)) !all procs gather correspondance arrays CALL MPI_ALLREDUCE( ngwl1, ngwl1_max, 1, MPI_INTEGER, MPI_MAX, gid, IERR ) CALL MPI_ALLREDUCE( ngwl2, ngwl2_max, 1, MPI_INTEGER, MPI_MAX, gid, IERR ) CALL MPI_ALLREDUCE( npw1, npw1_max, 1, MPI_INTEGER, MPI_MAX, gid, IERR ) CALL MPI_ALLREDUCE( npw2, npw2_max, 1, MPI_INTEGER, MPI_MAX, gid, IERR ) CALL MPI_ALLGATHER (npw1,1,MPI_INTEGER,npw1_loc,1,MPI_INTEGER,gid,IERR) CALL MPI_ALLGATHER (npw2,1,MPI_INTEGER,npw2_loc,1,MPI_INTEGER,gid,IERR) allocate(ig_l2g1_tot(ngwl1_max,nproc),ig_l2g2_tot(ngwl2_max,nproc)) allocate(itmp(ngwl1_max)) itmp(1:ngwl1)=ig_l2g1(1:ngwl1) CALL MPI_ALLGATHER (itmp,ngwl1_max,MPI_INTEGER,ig_l2g1_tot,ngwl1_max,MPI_INTEGER,gid,IERR) deallocate(itmp) allocate(itmp(ngwl2_max)) itmp(1:ngwl2)=ig_l2g2(1:ngwl2) CALL MPI_ALLGATHER (itmp,ngwl2_max,MPI_INTEGER,ig_l2g2_tot,ngwl2_max,MPI_INTEGER,gid,IERR) deallocate(itmp) allocate(pw1_tot(npw1_max,nproc),pw2_tot(npw2_max,nproc)) allocate(pw1_tmp(npw1_max),pw2_tmp(npw2_max)) allocate(pw_global(n_g)) do ii=1,nbands,nproc ilast=min(nbands,ii+nproc-1) do iband=ii,ilast ip=mod(iband,nproc)!ip starts from 1 to nproc-1 pw1_tmp(1:npw1)=pw1(1:npw1,iband) CALL MPI_GATHER (pw1_tmp,npw1_max,MPI_DOUBLE_COMPLEX,pw1_tot,npw1_max,MPI_DOUBLE_COMPLEX,ip,gid,ierr) enddo pw_global=0.d0 do ip=1,nproc pw_global(ig_l2g1_tot(1:npw1_loc(ip),ip))=pw1_tot(1:npw1_loc(ip),ip) enddo do ip=1,nproc pw2_tot(1:npw2_loc(ip),ip)=pw_global(ig_l2g2_tot(1:npw2_loc(ip),ip)) enddo do iband=ii,ilast ip=mod(iband,nproc) CALL MPI_SCATTER (pw2_tot,npw2_max,MPI_DOUBLE_COMPLEX,pw2_tmp,npw2_max ,MPI_DOUBLE_COMPLEX,ip,gid,ierr) pw2(1:npw2,iband)=pw2_tmp(1:npw2) enddo enddo deallocate(npw1_loc,npw2_loc) deallocate(ig_l2g1_tot,ig_l2g2_tot) deallocate(pw1_tot,pw2_tot) deallocate(pw1_tmp,pw2_tmp) deallocate(pw_global) #endif return END SUBROUTINE reorderwfp_col
gpl-2.0
techno/gcc-mist32
libgfortran/generated/_acosh_r8.F90
47
1477
! Copyright (C) 2002-2015 Free Software Foundation, Inc. ! Contributed by Paul Brook <paul@nowt.org> ! !This file is part of the GNU Fortran 95 runtime library (libgfortran). ! !GNU libgfortran is free software; you can redistribute it and/or !modify it under the terms of the GNU General Public !License as published by the Free Software Foundation; either !version 3 of the License, or (at your option) any later version. !GNU libgfortran is distributed in the hope that it will be useful, !but WITHOUT ANY WARRANTY; without even the implied warranty of !MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !GNU General Public License for more details. ! !Under Section 7 of GPL version 3, you are granted additional !permissions described in the GCC Runtime Library Exception, version !3.1, as published by the Free Software Foundation. ! !You should have received a copy of the GNU General Public License and !a copy of the GCC Runtime Library Exception along with this program; !see the files COPYING3 and COPYING.RUNTIME respectively. If not, see !<http://www.gnu.org/licenses/>. ! !This file is machine generated. #include "config.h" #include "kinds.inc" #include "c99_protos.inc" #if defined (HAVE_GFC_REAL_8) #ifdef HAVE_ACOSH elemental function _gfortran_specific__acosh_r8 (parm) real (kind=8), intent (in) :: parm real (kind=8) :: _gfortran_specific__acosh_r8 _gfortran_specific__acosh_r8 = acosh (parm) end function #endif #endif
gpl-2.0
prool/ccx_prool
CalculiX/ccx_2.16/src/negativepressure.f
1
1444
! ! CalculiX - A 3-dimensional finite element program ! Copyright (C) 1998-2019 Guido Dhondt ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License as ! published by the Free Software Foundation(version 2); ! ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! subroutine negativepressure(ne0,ne,mi,stx,pressureratio) ! ! calculating the ratio of the smallest pressure to the ! largest pressure for face-to-face contact ! if the pressure is somewhere negative, this ratio will ! be negative ! implicit none ! integer ne0,ne,mi(*),i ! real*8 stx(6,mi(1),*),presmin,presmax,pressureratio ! presmax=0.d0 presmin=0.d0 ! do i=ne0+1,ne if(stx(4,1,i).gt.presmax) then presmax=stx(4,1,i) elseif(stx(4,1,i).lt.presmin) then presmin=stx(4,1,i) endif enddo pressureratio=presmin/presmax ! return end
gpl-2.0
prool/ccx_prool
CalculiX/ccx_2.11/src/loadadd.f
6
3794
! ! CalculiX - A 3-dimensional finite element program ! Copyright (C) 1998-2015 Guido Dhondt ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License as ! published by the Free Software Foundation(version 2); ! ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! subroutine loadadd(nelement,label,value,nelemload,sideload, & xload,nload,nload_,iamload,iamplitude,nam,isector,idefload) ! ! adds a facial dload condition to the data base ! implicit none ! character*20 label,sideload(*) ! integer nelemload(2,*),iamload(2,*),nelement,nload,nload_,j, & iamplitude,nam,isector,id,idefload(*) ! real*8 xload(2,*),value ! call nident2(nelemload,nelement,nload,id) if(id.gt.0) then ! ! it is possible that several *DLOAD, *FILM or ! *RADIATE boundary conditions are applied to one ! and the same element ! if(nelemload(1,id).eq.nelement) then do if (sideload(id).eq.label) then if(nelemload(2,id).eq.isector) then ! ! loading on same element face and sector ! detected: values are replaced ! if(idefload(id).eq.0) then xload(1,id)=value idefload(id)=1 else xload(1,id)=xload(1,id)+value endif xload(2,id)=0.d0 if(nam.gt.0) then iamload(1,id)=iamplitude iamload(2,id)=iamplitude endif return elseif(nelemload(2,id).lt.isector) then c id=id-1 exit endif elseif(sideload(id).lt.label) then c id=id-1 exit endif id=id-1 if((id.eq.0).or.(nelemload(1,id).ne.nelement)) then c id=id-1 exit endif enddo endif endif ! ! loading a element face on which no previous loading ! was applied ! ! loading conditions on one and the same element are ! alphabetized based on field sideload ! ! loading conditions on one and the same element and ! of one and the same sideload type are ordered based ! on field nelemload(2,*) ! nload=nload+1 if(nload.gt.nload_) then write(*,*) '*ERROR in loadadd: increase nload_' call exit(201) endif ! ! shifting existing loading ! do j=nload,id+2,-1 nelemload(1,j)=nelemload(1,j-1) nelemload(2,j)=nelemload(2,j-1) idefload(j)=idefload(j-1) sideload(j)=sideload(j-1) xload(1,j)=xload(1,j-1) xload(2,j)=xload(2,j-1) if(nam.gt.0) then iamload(1,j)=iamload(1,j-1) iamload(2,j)=iamload(2,j-1) endif enddo ! ! inserting new loading ! nelemload(1,id+1)=nelement nelemload(2,id+1)=isector idefload(id+1)=1 sideload(id+1)=label xload(1,id+1)=value xload(2,id+1)=0. if(nam.gt.0) then iamload(1,id+1)=iamplitude iamload(2,id+1)=0 endif ! return end
gpl-2.0
prool/ccx_prool
CalculiX/ccx_2.12/src/loadadd.f
6
3794
! ! CalculiX - A 3-dimensional finite element program ! Copyright (C) 1998-2015 Guido Dhondt ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License as ! published by the Free Software Foundation(version 2); ! ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! subroutine loadadd(nelement,label,value,nelemload,sideload, & xload,nload,nload_,iamload,iamplitude,nam,isector,idefload) ! ! adds a facial dload condition to the data base ! implicit none ! character*20 label,sideload(*) ! integer nelemload(2,*),iamload(2,*),nelement,nload,nload_,j, & iamplitude,nam,isector,id,idefload(*) ! real*8 xload(2,*),value ! call nident2(nelemload,nelement,nload,id) if(id.gt.0) then ! ! it is possible that several *DLOAD, *FILM or ! *RADIATE boundary conditions are applied to one ! and the same element ! if(nelemload(1,id).eq.nelement) then do if (sideload(id).eq.label) then if(nelemload(2,id).eq.isector) then ! ! loading on same element face and sector ! detected: values are replaced ! if(idefload(id).eq.0) then xload(1,id)=value idefload(id)=1 else xload(1,id)=xload(1,id)+value endif xload(2,id)=0.d0 if(nam.gt.0) then iamload(1,id)=iamplitude iamload(2,id)=iamplitude endif return elseif(nelemload(2,id).lt.isector) then c id=id-1 exit endif elseif(sideload(id).lt.label) then c id=id-1 exit endif id=id-1 if((id.eq.0).or.(nelemload(1,id).ne.nelement)) then c id=id-1 exit endif enddo endif endif ! ! loading a element face on which no previous loading ! was applied ! ! loading conditions on one and the same element are ! alphabetized based on field sideload ! ! loading conditions on one and the same element and ! of one and the same sideload type are ordered based ! on field nelemload(2,*) ! nload=nload+1 if(nload.gt.nload_) then write(*,*) '*ERROR in loadadd: increase nload_' call exit(201) endif ! ! shifting existing loading ! do j=nload,id+2,-1 nelemload(1,j)=nelemload(1,j-1) nelemload(2,j)=nelemload(2,j-1) idefload(j)=idefload(j-1) sideload(j)=sideload(j-1) xload(1,j)=xload(1,j-1) xload(2,j)=xload(2,j-1) if(nam.gt.0) then iamload(1,j)=iamload(1,j-1) iamload(2,j)=iamload(2,j-1) endif enddo ! ! inserting new loading ! nelemload(1,id+1)=nelement nelemload(2,id+1)=isector idefload(id+1)=1 sideload(id+1)=label xload(1,id+1)=value xload(2,id+1)=0. if(nam.gt.0) then iamload(1,id+1)=iamplitude iamload(2,id+1)=0 endif ! return end
gpl-2.0
prool/ccx_prool
CalculiX/ccx_2.11/src/onedint.f
6
7365
! ! CalculiX - A 3-dimensional finite element program ! Copyright (C) 1998-2015 Guido Dhondt ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License as ! published by the Free Software Foundation(version 2); ! ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! C C 1. TASK INTERPOLATION OF A FUNCTION DEFINED POINT BY POINT C ********* THE X COORDINATES ARE USER SPECIFIED. C THE INTERPOLATION PROCESS CAN BE EITHER CONSTANT,LINEAR c OR EVEN dOUBLE QUADRATIC WITH EXTRAPOLATION USING THE c POLYNOM HIGHEST ORDER C thE DOUBLE QUADRATIC INTERPOLATION IS A 3RD ORDER METHOD c BY WHICH 2 PARABOLS ENCOMPASSING EACH 3 AND 4 sAMPLING POINTS c ARE DEFINED. c THE SOLUTION IS A LINEAR COMBINATION OF THE CONCERNED c PARABOLS VALUES DEPENDING ON THE DEFINITION OF THE ACTUAL c SAMPLING POINT INTERVAL C C C 2.INPUT CALL ONEDINT(XE,YE,NE,XA,YA,NA,IART,IEXP,IER) C *********** XE = ABSCISSE VECTOR OF THE SAMPLING POINTS C YE = ORDINATE VECTOR OF THE SAMPLING POINTS C NE = LENGHT OF THE SAMPLING POINT VECTOR C XA = ASCISSE VECTOR OF THE INTERPOLATION POINT(INPUT) C YA = ORDINATE VECTOR OF THE INTERPOLATION POINT(OUTPUT) C NA = LENGTH OF THE INTERPOLATION VECTOR c IART = tYPE OF INTERPOLATION C =0: CONSTANT C =1: LINEAR C =2: DOUBLE QUADRATIC C IEXP = TYPE OF EXTRAPOLATION C IEXP = 10*IEX1 + IEXN C IEX1 EXTRAPOLATIONS BEYOND THE C 1. SAMPLING POINT IN THE VECTOR C IEXN EXTRAPOLATION BEYOND THE C LAST SAMPLING POINT IN THE VECTOR C SELECTION OF THE EXTRAPOLATION TYPE AS C FOR IART. C IER = ERROR CODE C = 0: NORMAL PROCEEDING C =-1:PROBLEM IN TH EGIVEN VALUES C PROGRAMM STOPS. C C 3.RESTRICTION ABSCISSE VECTOR XE MUST BE STRICTLY MONOTONIC INCREASING SORTED C *************** AUTOMATIC CONTROL INSIDE TEH SUBROUTINE: C NE = 0: ERROR INTERRUPTION C NE = 1: ONLY CONSTANT INTER- EXTRAPOLATION C NE = 2: MAXIMAL LINEAR INTER- EXTRAPOLATION C NE = 3: MAXIMAL QUADRATIC INTER- EXTRAPOLATIO C THE PARAMETER FOR THE TYPE OF EXTRAPOLATION c MUST NOT BE GREATER THAN THE ONE FOR TH EINTERPOLATION TYPE C OTHERWISE THE VALUE IS AUTOMATICALLY ADAPTATED C SUBROUTINE ONEDINT(XE,YE,NE,XA,YA,NA,IART,IEXP,IER) implicit none INTEGER NE,NA,NA1,NE1,IG,IER,IA,IART,IE2,I,IEXP,IE1,L REAL*8 XE(NE),YE(NE),XA(NA),YA(NA),ZW1,ZW2,XO,YO,RAB,XD,YD, & XZ,YZ,XU,YU,EQ,EQD,X C C INTERPOLATION FUNCTION C ------------------------ EQ(X) = YU + YU * (X-XU) / XU + 1 ((YZ-YU)/(XZ-XU) - YU/XU) * (X-XU) * X / XZ EQD(X) = YZ * X / XZ + 1 (YD / XD - YZ / XZ) * X * (X - XZ) / (XD - XZ) C C INPUT/DATA TEST,INTERPOLATION DIVERGENCE,EXTRAPOLATION LIMIT C---------------------------------------------------------------- NA1 = NA - 1 IF (NA .LE. 0) GO TO 900 NE1 = NE - 1 IF (NE1.lt.0) then go to 900 elseif(ne1.eq.0) then go to 22 else go to 18 endif 18 DO 20 L = 1,NE1 20 IF ((XE(L+1)-XE(L)) .LE. 0) GO TO 900 22 IE1 = IEXP / 10 IE2 = IEXP - 10*IE1 IA = IART IF (NE1 .LT. IA) IA = NE1 IF (IA .LT. IE1) IE1 = IA IF (IA .LT. IE2) IE2 = IA C C SUCCESSIVE PROCESSING THE INTERPOLATION EXIGENCES C------------------------------------------------------- C C ZUR ERHOEHUNG DER NUMERISCHEN GENAUIGKEIT WIRD EINE C TRANSLATION VON (XO,YO) IN (0,0) DURCHGEFUEHRT. DIES C BEWIRKT AUSSERDEM EINE BESCHLEUNIGUNG DES VERFAHRENS. C DO 100 I = 1,NA DO 24 L = 1,NE IF (XA(I) .LT. XE(L)) GO TO 30 24 CONTINUE L = NE IF ((IE2 - 1).lt.0) then go to 50 elseif((ie2-1).eq.0) then go to 35 else go to 70 endif 30 IF (L .GT. 1) GO TO 40 IF ((IE1 - 1).lt.0) then go to 50 elseif((ie1-1).eq.0) then go to 25 else go to 70 endif 40 IF ((IA-1).lt.0) then go to 45 elseif((ia-1).eq.0) then go to 60 else go to 70 endif C C CONSTANT INTERPOLATION C ----------------------- 45 L = L - 1 50 YA(I) = YE(L) GO TO 100 C C LINEAR EXTRAPOLATION C ------------------------------ 25 IF (IA .EQ. 1) GO TO 60 XO = XE(2) XU = XE(1) - XO YO = YE(2) YU = YE(1) - YO XZ = XE(3) - XO YZ = YE(3) - YO GO TO 38 35 IF (IA .EQ. 1) GO TO 60 XO = XE(NE1) XZ = XE(NE1-1) - XO XU = XE(NE) - XO YO = YE(NE1) YZ = YE(NE1-1) - YO YU = YE(NE) - YO C C LINEAR EXTRAPOLATION WITH QUADRATIC INTERPOLATION C ----------------------------------------------------- 38 RAB = YU / XU + XU * ((YZ-YU) / (XZ-XU) - YU/XU) / XZ YA(I) = YU + YO + (XA(I) -XU-XO)*RAB GO TO 100 C C LINEAR INTERPOLATION C --------------------- 60 IG = L - 1 IF (IG .LT. 1) IG = 1 YA(I) = YE(IG) + (XA(I)-XE(IG))*(YE(IG+1)-YE(IG)) 1 / (XE(IG+1)-XE(IG)) GO TO 100 70 IF (L .GT. 2) GO TO 80 XO = XE(2) XU = XE(1) - XO YO = YE(2) YU = YE(1) - YO XZ = XE(3) - XO YZ = YE(3) - YO GO TO 85 80 IF (L .LT. NE) GO TO 90 XO = XE(NE1) XU = XE(NE1-1) - XO XZ = XE(NE) - XO YO = YE(NE1) YU = YE(NE1-1) - YO YZ = YE(NE) - YO 85 YA(I) = EQ(XA(I)-XO) + YO GO TO 100 C C DOUBLE QUADRATIC INTERPOLATION C ---------------------------------- 90 XO = XE(L-1) XU = XE(L-2) - XO XZ = XE(L) - XO XD = XE(L+1) - XO YO = YE(L-1) YU = YE(L-2) - YO YZ = YE(L) - YO YD = YE(L+1) - YO ZW1 = EQ(XA(I)-XO) ZW2 = EQD(XA(I)-XO) YA(I) = ZW1 + (ZW2 - ZW1) * (XA(I) - XO)/XZ + YO 100 CONTINUE C C RETURN BY NORMAL PROCEEDING C ------------------------------- IER = 0 RETURN C C ERROR RETURN C ------------ 900 IER = -1 RETURN END
gpl-2.0
prool/ccx_prool
CalculiX/ccx_2.11/src/rectcyl.f
6
23567
! ! CalculiX - A 3-dimensional finite element program ! Copyright (C) 1998-2015 Guido Dhondt ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License as ! published by the Free Software Foundation(version 2); ! ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! subroutine rectcyl(co,v,fn,stn,qfn,een,cs,n,icntrl,t,filab, & imag,mi,emn) ! ! icntrl=1: rectangular to cylindrical coordinates for nodal ! coordinates in field co ! icntrl=-1: cylindrical to rectangular coordinates for nodal ! coordinates in field co ! icntrl=2: rectangular to cylindrical coordinates for fields ! v,fn,stn,een and emn ! icntrl=-2: cylindrical to rectangular coordinates for fields ! v,fn,stn, een and emn ! ! the axis of the cylindrical coordinates is defined by points ! a with coordinates csab(1..3) and b with coordinates csab(4..6). ! Theta=0 (2nd cylindrical coordinate) is defined by the vector t, ! which is perpendicular to the axis. The subroutine should be called ! with icntrl=1 before calling it with icntrl=-1. ! ! for icntrl=2 the imaginary part is extra taken into account if ! imag=1 ! implicit none ! character*87 filab(*) integer i,j,n,icntrl,imag,mi(*) real*8 co(3,*),v(0:mi(2),*),fn(0:mi(2),*),stn(6,*),een(6,*), & a(3,3),emn(6,*), & xr,xt,xz,b(3,3),cs(17,*),t(3),u(3),qfn(3,*),csab(7), & xn(3),r(3),z,theta,rr,c(3,3),ctm,ct,st,ddx,ddy,dd ! do i=1,7 csab(i)=cs(5+i,1) enddo ! if(icntrl.eq.1) then ! ! normal along the cylindrical axis ! xn(1)=csab(4)-csab(1) xn(2)=csab(5)-csab(2) xn(3)=csab(6)-csab(3) dd=dsqrt(xn(1)*xn(1)+xn(2)*xn(2)+xn(3)*xn(3)) do i=1,3 xn(i)=xn(i)/dd enddo ! ! normal to the cylindrical axis (vector t) ! if(dabs(xn(1)).gt.1.d-10) then t(2)=1.d0 t(3)=0.d0 t(1)=-xn(2)/xn(1) elseif(dabs(xn(2)).gt.1.d-10) then t(3)=1.d0 t(1)=0.d0 t(2)=-xn(3)/xn(2) else t(1)=1.d0 t(2)=0.d0 t(3)=-xn(1)/xn(3) endif dd=dsqrt(t(1)*t(1)+t(2)*t(2)+t(3)*t(3)) do i=1,3 t(i)=t(i)/dd enddo ! ! normal to xn and t ! u(1)=xn(2)*t(3)-xn(3)*t(2) u(2)=-xn(1)*t(3)+xn(3)*t(1) u(3)=xn(1)*t(2)-xn(2)*t(1) ! ! loop over all nodes to convert ! do i=1,n do j=1,3 r(j)=co(j,i)-csab(j) enddo z=r(1)*xn(1)+r(2)*xn(2)+r(3)*xn(3) do j=1,3 r(j)=r(j)-z*xn(j) enddo rr=dsqrt(r(1)*r(1)+r(2)*r(2)+r(3)*r(3)) if(dabs(rr).lt.1.d-10) then theta=0.d0 else do j=1,3 r(j)=r(j)/rr enddo ddx=t(1)*r(1)+t(2)*r(2)+t(3)*r(3) ddy=u(1)*r(1)+u(2)*r(2)+u(3)*r(3) theta=datan2(ddy,ddx) endif co(1,i)=rr co(2,i)=theta co(3,i)=z enddo elseif(icntrl.eq.-1) then ! ! normal along the cylindrical axis ! xn(1)=csab(4)-csab(1) xn(2)=csab(5)-csab(2) xn(3)=csab(6)-csab(3) dd=dsqrt(xn(1)*xn(1)+xn(2)*xn(2)+xn(3)*xn(3)) do i=1,3 xn(i)=xn(i)/dd enddo ! ! loop over all nodes to convert ! do i=1,n rr=co(1,i) theta=co(2,i) c write(*,*) 'rectcyl',i,co(2,i) z=co(3,i) ct=dcos(theta) st=dsin(theta) ctm=1.d0-ct ! ! rotation matrix ! c(1,1)=ct+ctm*xn(1)*xn(1) c(1,2)=-st*xn(3)+ctm*xn(1)*xn(2) c(1,3)=st*xn(2)+ctm*xn(1)*xn(3) c(2,1)=st*xn(3)+ctm*xn(2)*xn(1) c(2,2)=ct+ctm*xn(2)*xn(2) c(2,3)=-st*xn(1)+ctm*xn(2)*xn(3) c(3,1)=-st*xn(2)+ctm*xn(3)*xn(1) c(3,2)=st*xn(1)+ctm*xn(3)*xn(2) c(3,3)=ct+ctm*xn(3)*xn(3) ! co(1,i)=csab(1)+z*xn(1)+ & rr*(c(1,1)*t(1)+c(1,2)*t(2)+c(1,3)*t(3)) co(2,i)=csab(2)+z*xn(2)+ & rr*(c(2,1)*t(1)+c(2,2)*t(2)+c(2,3)*t(3)) co(3,i)=csab(3)+z*xn(3)+ & rr*(c(3,1)*t(1)+c(3,2)*t(2)+c(3,3)*t(3)) enddo elseif(icntrl.eq.2) then do i=1,n j=i call transformatrix(csab,co(1,i),a) ! if((filab(1)(1:3).eq.'U ').or. & (filab(11)(1:4).eq.'PU')) then xr=v(1,j)*a(1,1)+v(2,j)*a(2,1)+v(3,j)*a(3,1) xt=v(1,j)*a(1,2)+v(2,j)*a(2,2)+v(3,j)*a(3,2) xz=v(1,j)*a(1,3)+v(2,j)*a(2,3)+v(3,j)*a(3,3) v(1,j)=xr v(2,j)=xt v(3,j)=xz endif ! if((filab(3)(1:4).eq.'S ').or. & (filab(18)(1:4).eq.'PHS ')) then b(1,1)=stn(1,j)*a(1,1)+stn(4,j)*a(2,1)+stn(5,j)*a(3,1) b(1,2)=stn(1,j)*a(1,2)+stn(4,j)*a(2,2)+stn(5,j)*a(3,2) b(1,3)=stn(1,j)*a(1,3)+stn(4,j)*a(2,3)+stn(5,j)*a(3,3) b(2,1)=stn(4,j)*a(1,1)+stn(2,j)*a(2,1)+stn(6,j)*a(3,1) b(2,2)=stn(4,j)*a(1,2)+stn(2,j)*a(2,2)+stn(6,j)*a(3,2) b(2,3)=stn(4,j)*a(1,3)+stn(2,j)*a(2,3)+stn(6,j)*a(3,3) b(3,1)=stn(5,j)*a(1,1)+stn(6,j)*a(2,1)+stn(3,j)*a(3,1) b(3,2)=stn(5,j)*a(1,2)+stn(6,j)*a(2,2)+stn(3,j)*a(3,2) b(3,3)=stn(5,j)*a(1,3)+stn(6,j)*a(2,3)+stn(3,j)*a(3,3) ! stn(1,j)=a(1,1)*b(1,1)+a(2,1)*b(2,1)+a(3,1)*b(3,1) stn(2,j)=a(1,2)*b(1,2)+a(2,2)*b(2,2)+a(3,2)*b(3,2) stn(3,j)=a(1,3)*b(1,3)+a(2,3)*b(2,3)+a(3,3)*b(3,3) stn(4,j)=a(1,1)*b(1,2)+a(2,1)*b(2,2)+a(3,1)*b(3,2) stn(5,j)=a(1,1)*b(1,3)+a(2,1)*b(2,3)+a(3,1)*b(3,3) stn(6,j)=a(1,2)*b(1,3)+a(2,2)*b(2,3)+a(3,2)*b(3,3) endif ! if(filab(4)(1:4).eq.'E ') then b(1,1)=een(1,j)*a(1,1)+een(4,j)*a(2,1)+een(5,j)*a(3,1) b(1,2)=een(1,j)*a(1,2)+een(4,j)*a(2,2)+een(5,j)*a(3,2) b(1,3)=een(1,j)*a(1,3)+een(4,j)*a(2,3)+een(5,j)*a(3,3) b(2,1)=een(4,j)*a(1,1)+een(2,j)*a(2,1)+een(6,j)*a(3,1) b(2,2)=een(4,j)*a(1,2)+een(2,j)*a(2,2)+een(6,j)*a(3,2) b(2,3)=een(4,j)*a(1,3)+een(2,j)*a(2,3)+een(6,j)*a(3,3) b(3,1)=een(5,j)*a(1,1)+een(6,j)*a(2,1)+een(3,j)*a(3,1) b(3,2)=een(5,j)*a(1,2)+een(6,j)*a(2,2)+een(3,j)*a(3,2) b(3,3)=een(5,j)*a(1,3)+een(6,j)*a(2,3)+een(3,j)*a(3,3) ! een(1,j)=a(1,1)*b(1,1)+a(2,1)*b(2,1)+a(3,1)*b(3,1) een(2,j)=a(1,2)*b(1,2)+a(2,2)*b(2,2)+a(3,2)*b(3,2) een(3,j)=a(1,3)*b(1,3)+a(2,3)*b(2,3)+a(3,3)*b(3,3) een(4,j)=a(1,1)*b(1,2)+a(2,1)*b(2,2)+a(3,1)*b(3,2) een(5,j)=a(1,1)*b(1,3)+a(2,1)*b(2,3)+a(3,1)*b(3,3) een(6,j)=a(1,2)*b(1,3)+a(2,2)*b(2,3)+a(3,2)*b(3,3) endif ! if(filab(5)(1:4).eq.'RF ') then xr=fn(1,j)*a(1,1)+fn(2,j)*a(2,1)+fn(3,j)*a(3,1) xt=fn(1,j)*a(1,2)+fn(2,j)*a(2,2)+fn(3,j)*a(3,2) xz=fn(1,j)*a(1,3)+fn(2,j)*a(2,3)+fn(3,j)*a(3,3) fn(1,j)=xr fn(2,j)=xt fn(3,j)=xz endif ! if(filab(9)(1:4).eq.'HFL ') then xr=qfn(1,j)*a(1,1)+qfn(2,j)*a(2,1)+qfn(3,j)*a(3,1) xt=qfn(1,j)*a(1,2)+qfn(2,j)*a(2,2)+qfn(3,j)*a(3,2) xz=qfn(1,j)*a(1,3)+qfn(2,j)*a(2,3)+qfn(3,j)*a(3,3) qfn(1,j)=xr qfn(2,j)=xt qfn(3,j)=xz endif ! if(filab(32)(1:4).eq.'ME ') then b(1,1)=emn(1,j)*a(1,1)+emn(4,j)*a(2,1)+emn(5,j)*a(3,1) b(1,2)=emn(1,j)*a(1,2)+emn(4,j)*a(2,2)+emn(5,j)*a(3,2) b(1,3)=emn(1,j)*a(1,3)+emn(4,j)*a(2,3)+emn(5,j)*a(3,3) b(2,1)=emn(4,j)*a(1,1)+emn(2,j)*a(2,1)+emn(6,j)*a(3,1) b(2,2)=emn(4,j)*a(1,2)+emn(2,j)*a(2,2)+emn(6,j)*a(3,2) b(2,3)=emn(4,j)*a(1,3)+emn(2,j)*a(2,3)+emn(6,j)*a(3,3) b(3,1)=emn(5,j)*a(1,1)+emn(6,j)*a(2,1)+emn(3,j)*a(3,1) b(3,2)=emn(5,j)*a(1,2)+emn(6,j)*a(2,2)+emn(3,j)*a(3,2) b(3,3)=emn(5,j)*a(1,3)+emn(6,j)*a(2,3)+emn(3,j)*a(3,3) ! emn(1,j)=a(1,1)*b(1,1)+a(2,1)*b(2,1)+a(3,1)*b(3,1) emn(2,j)=a(1,2)*b(1,2)+a(2,2)*b(2,2)+a(3,2)*b(3,2) emn(3,j)=a(1,3)*b(1,3)+a(2,3)*b(2,3)+a(3,3)*b(3,3) emn(4,j)=a(1,1)*b(1,2)+a(2,1)*b(2,2)+a(3,1)*b(3,2) emn(5,j)=a(1,1)*b(1,3)+a(2,1)*b(2,3)+a(3,1)*b(3,3) emn(6,j)=a(1,2)*b(1,3)+a(2,2)*b(2,3)+a(3,2)*b(3,3) endif ! ! imaginary part for cyclic symmetry frequency calculations ! if(imag.eq.1) then ! j=i+n ! if((filab(1)(1:3).eq.'U ').or. & (filab(11)(1:4).eq.'PU')) then xr=v(1,j)*a(1,1)+v(2,j)*a(2,1)+v(3,j)*a(3,1) xt=v(1,j)*a(1,2)+v(2,j)*a(2,2)+v(3,j)*a(3,2) xz=v(1,j)*a(1,3)+v(2,j)*a(2,3)+v(3,j)*a(3,3) v(1,j)=xr v(2,j)=xt v(3,j)=xz endif ! if((filab(3)(1:4).eq.'S ').or. & (filab(18)(1:4).eq.'PHS ')) then b(1,1)=stn(1,j)*a(1,1)+stn(4,j)*a(2,1)+stn(5,j)*a(3,1) b(1,2)=stn(1,j)*a(1,2)+stn(4,j)*a(2,2)+stn(5,j)*a(3,2) b(1,3)=stn(1,j)*a(1,3)+stn(4,j)*a(2,3)+stn(5,j)*a(3,3) b(2,1)=stn(4,j)*a(1,1)+stn(2,j)*a(2,1)+stn(6,j)*a(3,1) b(2,2)=stn(4,j)*a(1,2)+stn(2,j)*a(2,2)+stn(6,j)*a(3,2) b(2,3)=stn(4,j)*a(1,3)+stn(2,j)*a(2,3)+stn(6,j)*a(3,3) b(3,1)=stn(5,j)*a(1,1)+stn(6,j)*a(2,1)+stn(3,j)*a(3,1) b(3,2)=stn(5,j)*a(1,2)+stn(6,j)*a(2,2)+stn(3,j)*a(3,2) b(3,3)=stn(5,j)*a(1,3)+stn(6,j)*a(2,3)+stn(3,j)*a(3,3) ! stn(1,j)=a(1,1)*b(1,1)+a(2,1)*b(2,1)+a(3,1)*b(3,1) stn(2,j)=a(1,2)*b(1,2)+a(2,2)*b(2,2)+a(3,2)*b(3,2) stn(3,j)=a(1,3)*b(1,3)+a(2,3)*b(2,3)+a(3,3)*b(3,3) stn(4,j)=a(1,1)*b(1,2)+a(2,1)*b(2,2)+a(3,1)*b(3,2) stn(5,j)=a(1,1)*b(1,3)+a(2,1)*b(2,3)+a(3,1)*b(3,3) stn(6,j)=a(1,2)*b(1,3)+a(2,2)*b(2,3)+a(3,2)*b(3,3) endif ! if(filab(4)(1:4).eq.'E ') then b(1,1)=een(1,j)*a(1,1)+een(4,j)*a(2,1)+een(5,j)*a(3,1) b(1,2)=een(1,j)*a(1,2)+een(4,j)*a(2,2)+een(5,j)*a(3,2) b(1,3)=een(1,j)*a(1,3)+een(4,j)*a(2,3)+een(5,j)*a(3,3) b(2,1)=een(4,j)*a(1,1)+een(2,j)*a(2,1)+een(6,j)*a(3,1) b(2,2)=een(4,j)*a(1,2)+een(2,j)*a(2,2)+een(6,j)*a(3,2) b(2,3)=een(4,j)*a(1,3)+een(2,j)*a(2,3)+een(6,j)*a(3,3) b(3,1)=een(5,j)*a(1,1)+een(6,j)*a(2,1)+een(3,j)*a(3,1) b(3,2)=een(5,j)*a(1,2)+een(6,j)*a(2,2)+een(3,j)*a(3,2) b(3,3)=een(5,j)*a(1,3)+een(6,j)*a(2,3)+een(3,j)*a(3,3) ! een(1,j)=a(1,1)*b(1,1)+a(2,1)*b(2,1)+a(3,1)*b(3,1) een(2,j)=a(1,2)*b(1,2)+a(2,2)*b(2,2)+a(3,2)*b(3,2) een(3,j)=a(1,3)*b(1,3)+a(2,3)*b(2,3)+a(3,3)*b(3,3) een(4,j)=a(1,1)*b(1,2)+a(2,1)*b(2,2)+a(3,1)*b(3,2) een(5,j)=a(1,1)*b(1,3)+a(2,1)*b(2,3)+a(3,1)*b(3,3) een(6,j)=a(1,2)*b(1,3)+a(2,2)*b(2,3)+a(3,2)*b(3,3) endif ! if(filab(5)(1:4).eq.'RF ') then xr=fn(1,j)*a(1,1)+fn(2,j)*a(2,1)+fn(3,j)*a(3,1) xt=fn(1,j)*a(1,2)+fn(2,j)*a(2,2)+fn(3,j)*a(3,2) xz=fn(1,j)*a(1,3)+fn(2,j)*a(2,3)+fn(3,j)*a(3,3) fn(1,j)=xr fn(2,j)=xt fn(3,j)=xz endif ! if(filab(9)(1:4).eq.'HFL ') then xr=qfn(1,j)*a(1,1)+qfn(2,j)*a(2,1)+qfn(3,j)*a(3,1) xt=qfn(1,j)*a(1,2)+qfn(2,j)*a(2,2)+qfn(3,j)*a(3,2) xz=qfn(1,j)*a(1,3)+qfn(2,j)*a(2,3)+qfn(3,j)*a(3,3) qfn(1,j)=xr qfn(2,j)=xt qfn(3,j)=xz endif ! if(filab(32)(1:4).eq.'ME ') then b(1,1)=emn(1,j)*a(1,1)+emn(4,j)*a(2,1)+emn(5,j)*a(3,1) b(1,2)=emn(1,j)*a(1,2)+emn(4,j)*a(2,2)+emn(5,j)*a(3,2) b(1,3)=emn(1,j)*a(1,3)+emn(4,j)*a(2,3)+emn(5,j)*a(3,3) b(2,1)=emn(4,j)*a(1,1)+emn(2,j)*a(2,1)+emn(6,j)*a(3,1) b(2,2)=emn(4,j)*a(1,2)+emn(2,j)*a(2,2)+emn(6,j)*a(3,2) b(2,3)=emn(4,j)*a(1,3)+emn(2,j)*a(2,3)+emn(6,j)*a(3,3) b(3,1)=emn(5,j)*a(1,1)+emn(6,j)*a(2,1)+emn(3,j)*a(3,1) b(3,2)=emn(5,j)*a(1,2)+emn(6,j)*a(2,2)+emn(3,j)*a(3,2) b(3,3)=emn(5,j)*a(1,3)+emn(6,j)*a(2,3)+emn(3,j)*a(3,3) ! emn(1,j)=a(1,1)*b(1,1)+a(2,1)*b(2,1)+a(3,1)*b(3,1) emn(2,j)=a(1,2)*b(1,2)+a(2,2)*b(2,2)+a(3,2)*b(3,2) emn(3,j)=a(1,3)*b(1,3)+a(2,3)*b(2,3)+a(3,3)*b(3,3) emn(4,j)=a(1,1)*b(1,2)+a(2,1)*b(2,2)+a(3,1)*b(3,2) emn(5,j)=a(1,1)*b(1,3)+a(2,1)*b(2,3)+a(3,1)*b(3,3) emn(6,j)=a(1,2)*b(1,3)+a(2,2)*b(2,3)+a(3,2)*b(3,3) endif endif enddo elseif(icntrl.eq.-2) then do i=1,n j=i call transformatrix(csab,co(1,i),a) ! if((filab(1)(1:3).eq.'U ').or. & (filab(11)(1:4).eq.'PU')) then xr=v(1,j)*a(1,1)+v(2,j)*a(1,2)+v(3,j)*a(1,3) xt=v(1,j)*a(2,1)+v(2,j)*a(2,2)+v(3,j)*a(2,3) xz=v(1,j)*a(3,1)+v(2,j)*a(3,2)+v(3,j)*a(3,3) v(1,j)=xr v(2,j)=xt v(3,j)=xz endif ! if((filab(3)(1:4).eq.'S ').or. & (filab(18)(1:4).eq.'PHS ')) then b(1,1)=stn(1,j)*a(1,1)+stn(4,j)*a(1,2)+stn(5,j)*a(1,3) b(1,2)=stn(1,j)*a(2,1)+stn(4,j)*a(2,2)+stn(5,j)*a(2,3) b(1,3)=stn(1,j)*a(3,1)+stn(4,j)*a(3,2)+stn(5,j)*a(3,3) b(2,1)=stn(4,j)*a(1,1)+stn(2,j)*a(1,2)+stn(6,j)*a(1,3) b(2,2)=stn(4,j)*a(2,1)+stn(2,j)*a(2,2)+stn(6,j)*a(2,3) b(2,3)=stn(4,j)*a(3,1)+stn(2,j)*a(3,2)+stn(6,j)*a(3,3) b(3,1)=stn(5,j)*a(1,1)+stn(6,j)*a(1,2)+stn(3,j)*a(1,3) b(3,2)=stn(5,j)*a(2,1)+stn(6,j)*a(2,2)+stn(3,j)*a(2,3) b(3,3)=stn(5,j)*a(3,1)+stn(6,j)*a(3,2)+stn(3,j)*a(3,3) ! stn(1,j)=a(1,1)*b(1,1)+a(1,2)*b(2,1)+a(1,3)*b(3,1) stn(2,j)=a(2,1)*b(1,2)+a(2,2)*b(2,2)+a(2,3)*b(3,2) stn(3,j)=a(3,1)*b(1,3)+a(3,2)*b(2,3)+a(3,3)*b(3,3) stn(4,j)=a(1,1)*b(1,2)+a(1,2)*b(2,2)+a(1,3)*b(3,2) stn(5,j)=a(1,1)*b(1,3)+a(1,2)*b(2,3)+a(1,3)*b(3,3) stn(6,j)=a(2,1)*b(1,3)+a(2,2)*b(2,3)+a(2,3)*b(3,3) endif ! if(filab(4)(1:4).eq.'E ') then b(1,1)=een(1,j)*a(1,1)+een(4,j)*a(1,2)+een(5,j)*a(1,3) b(1,2)=een(1,j)*a(2,1)+een(4,j)*a(2,2)+een(5,j)*a(2,3) b(1,3)=een(1,j)*a(3,1)+een(4,j)*a(3,2)+een(5,j)*a(3,3) b(2,1)=een(4,j)*a(1,1)+een(2,j)*a(1,2)+een(6,j)*a(1,3) b(2,2)=een(4,j)*a(2,1)+een(2,j)*a(2,2)+een(6,j)*a(2,3) b(2,3)=een(4,j)*a(3,1)+een(2,j)*a(3,2)+een(6,j)*a(3,3) b(3,1)=een(5,j)*a(1,1)+een(6,j)*a(1,2)+een(3,j)*a(1,3) b(3,2)=een(5,j)*a(2,1)+een(6,j)*a(2,2)+een(3,j)*a(2,3) b(3,3)=een(5,j)*a(3,1)+een(6,j)*a(3,2)+een(3,j)*a(3,3) ! een(1,j)=a(1,1)*b(1,1)+a(1,2)*b(2,1)+a(1,3)*b(3,1) een(2,j)=a(2,1)*b(1,2)+a(2,2)*b(2,2)+a(2,3)*b(3,2) een(3,j)=a(3,1)*b(1,3)+a(3,2)*b(2,3)+a(3,3)*b(3,3) een(4,j)=a(1,1)*b(1,2)+a(1,2)*b(2,2)+a(1,3)*b(3,2) een(5,j)=a(1,1)*b(1,3)+a(1,2)*b(2,3)+a(1,3)*b(3,3) een(6,j)=a(2,1)*b(1,3)+a(2,2)*b(2,3)+a(2,3)*b(3,3) endif ! if(filab(5)(1:4).eq.'RF ') then xr=fn(1,j)*a(1,1)+fn(2,j)*a(1,2)+fn(3,j)*a(1,3) xt=fn(1,j)*a(2,1)+fn(2,j)*a(2,2)+fn(3,j)*a(2,3) xz=fn(1,j)*a(3,1)+fn(2,j)*a(3,2)+fn(3,j)*a(3,3) fn(1,j)=xr fn(2,j)=xt fn(3,j)=xz endif ! if(filab(9)(1:4).eq.'HFL ') then xr=qfn(1,j)*a(1,1)+qfn(2,j)*a(1,2)+qfn(3,j)*a(1,3) xt=qfn(1,j)*a(2,1)+qfn(2,j)*a(2,2)+qfn(3,j)*a(2,3) xz=qfn(1,j)*a(3,1)+qfn(2,j)*a(3,2)+qfn(3,j)*a(3,3) qfn(1,j)=xr qfn(2,j)=xt qfn(3,j)=xz endif ! if(filab(32)(1:4).eq.'ME ') then b(1,1)=emn(1,j)*a(1,1)+emn(4,j)*a(1,2)+emn(5,j)*a(1,3) b(1,2)=emn(1,j)*a(2,1)+emn(4,j)*a(2,2)+emn(5,j)*a(2,3) b(1,3)=emn(1,j)*a(3,1)+emn(4,j)*a(3,2)+emn(5,j)*a(3,3) b(2,1)=emn(4,j)*a(1,1)+emn(2,j)*a(1,2)+emn(6,j)*a(1,3) b(2,2)=emn(4,j)*a(2,1)+emn(2,j)*a(2,2)+emn(6,j)*a(2,3) b(2,3)=emn(4,j)*a(3,1)+emn(2,j)*a(3,2)+emn(6,j)*a(3,3) b(3,1)=emn(5,j)*a(1,1)+emn(6,j)*a(1,2)+emn(3,j)*a(1,3) b(3,2)=emn(5,j)*a(2,1)+emn(6,j)*a(2,2)+emn(3,j)*a(2,3) b(3,3)=emn(5,j)*a(3,1)+emn(6,j)*a(3,2)+emn(3,j)*a(3,3) ! emn(1,j)=a(1,1)*b(1,1)+a(1,2)*b(2,1)+a(1,3)*b(3,1) emn(2,j)=a(2,1)*b(1,2)+a(2,2)*b(2,2)+a(2,3)*b(3,2) emn(3,j)=a(3,1)*b(1,3)+a(3,2)*b(2,3)+a(3,3)*b(3,3) emn(4,j)=a(1,1)*b(1,2)+a(1,2)*b(2,2)+a(1,3)*b(3,2) emn(5,j)=a(1,1)*b(1,3)+a(1,2)*b(2,3)+a(1,3)*b(3,3) emn(6,j)=a(2,1)*b(1,3)+a(2,2)*b(2,3)+a(2,3)*b(3,3) endif ! ! imaginary part for cyclic symmetry frequency calculations ! if(imag.eq.1) then ! j=i+n ! if((filab(1)(1:3).eq.'U ').or. & (filab(11)(1:4).eq.'PU')) then xr=v(1,j)*a(1,1)+v(2,j)*a(1,2)+v(3,j)*a(1,3) xt=v(1,j)*a(2,1)+v(2,j)*a(2,2)+v(3,j)*a(2,3) xz=v(1,j)*a(3,1)+v(2,j)*a(3,2)+v(3,j)*a(3,3) v(1,j)=xr v(2,j)=xt v(3,j)=xz endif ! if((filab(3)(1:4).eq.'S ').or. & (filab(18)(1:4).eq.'PHS ')) then b(1,1)=stn(1,j)*a(1,1)+stn(4,j)*a(1,2)+stn(5,j)*a(1,3) b(1,2)=stn(1,j)*a(2,1)+stn(4,j)*a(2,2)+stn(5,j)*a(2,3) b(1,3)=stn(1,j)*a(3,1)+stn(4,j)*a(3,2)+stn(5,j)*a(3,3) b(2,1)=stn(4,j)*a(1,1)+stn(2,j)*a(1,2)+stn(6,j)*a(1,3) b(2,2)=stn(4,j)*a(2,1)+stn(2,j)*a(2,2)+stn(6,j)*a(2,3) b(2,3)=stn(4,j)*a(3,1)+stn(2,j)*a(3,2)+stn(6,j)*a(3,3) b(3,1)=stn(5,j)*a(1,1)+stn(6,j)*a(1,2)+stn(3,j)*a(1,3) b(3,2)=stn(5,j)*a(2,1)+stn(6,j)*a(2,2)+stn(3,j)*a(2,3) b(3,3)=stn(5,j)*a(3,1)+stn(6,j)*a(3,2)+stn(3,j)*a(3,3) ! stn(1,j)=a(1,1)*b(1,1)+a(1,2)*b(2,1)+a(1,3)*b(3,1) stn(2,j)=a(2,1)*b(1,2)+a(2,2)*b(2,2)+a(2,3)*b(3,2) stn(3,j)=a(3,1)*b(1,3)+a(3,2)*b(2,3)+a(3,3)*b(3,3) stn(4,j)=a(1,1)*b(1,2)+a(1,2)*b(2,2)+a(1,3)*b(3,2) stn(5,j)=a(1,1)*b(1,3)+a(1,2)*b(2,3)+a(1,3)*b(3,3) stn(6,j)=a(2,1)*b(1,3)+a(2,2)*b(2,3)+a(2,3)*b(3,3) endif ! if(filab(4)(1:4).eq.'E ') then b(1,1)=een(1,j)*a(1,1)+een(4,j)*a(1,2)+een(5,j)*a(1,3) b(1,2)=een(1,j)*a(2,1)+een(4,j)*a(2,2)+een(5,j)*a(2,3) b(1,3)=een(1,j)*a(3,1)+een(4,j)*a(3,2)+een(5,j)*a(3,3) b(2,1)=een(4,j)*a(1,1)+een(2,j)*a(1,2)+een(6,j)*a(1,3) b(2,2)=een(4,j)*a(2,1)+een(2,j)*a(2,2)+een(6,j)*a(2,3) b(2,3)=een(4,j)*a(3,1)+een(2,j)*a(3,2)+een(6,j)*a(3,3) b(3,1)=een(5,j)*a(1,1)+een(6,j)*a(1,2)+een(3,j)*a(1,3) b(3,2)=een(5,j)*a(2,1)+een(6,j)*a(2,2)+een(3,j)*a(2,3) b(3,3)=een(5,j)*a(3,1)+een(6,j)*a(3,2)+een(3,j)*a(3,3) ! een(1,j)=a(1,1)*b(1,1)+a(1,2)*b(2,1)+a(1,3)*b(3,1) een(2,j)=a(2,1)*b(1,2)+a(2,2)*b(2,2)+a(2,3)*b(3,2) een(3,j)=a(3,1)*b(1,3)+a(3,2)*b(2,3)+a(3,3)*b(3,3) een(4,j)=a(1,1)*b(1,2)+a(1,2)*b(2,2)+a(1,3)*b(3,2) een(5,j)=a(1,1)*b(1,3)+a(1,2)*b(2,3)+a(1,3)*b(3,3) een(6,j)=a(2,1)*b(1,3)+a(2,2)*b(2,3)+a(2,3)*b(3,3) endif ! if(filab(5)(1:4).eq.'RF ') then xr=fn(1,j)*a(1,1)+fn(2,j)*a(1,2)+fn(3,j)*a(1,3) xt=fn(1,j)*a(2,1)+fn(2,j)*a(2,2)+fn(3,j)*a(2,3) xz=fn(1,j)*a(3,1)+fn(2,j)*a(3,2)+fn(3,j)*a(3,3) fn(1,j)=xr fn(2,j)=xt fn(3,j)=xz endif ! if(filab(9)(1:4).eq.'HFL ') then xr=qfn(1,j)*a(1,1)+qfn(2,j)*a(1,2)+qfn(3,j)*a(1,3) xt=qfn(1,j)*a(2,1)+qfn(2,j)*a(2,2)+qfn(3,j)*a(2,3) xz=qfn(1,j)*a(3,1)+qfn(2,j)*a(3,2)+qfn(3,j)*a(3,3) qfn(1,j)=xr qfn(2,j)=xt qfn(3,j)=xz endif ! if(filab(32)(1:4).eq.'ME ') then b(1,1)=emn(1,j)*a(1,1)+emn(4,j)*a(1,2)+emn(5,j)*a(1,3) b(1,2)=emn(1,j)*a(2,1)+emn(4,j)*a(2,2)+emn(5,j)*a(2,3) b(1,3)=emn(1,j)*a(3,1)+emn(4,j)*a(3,2)+emn(5,j)*a(3,3) b(2,1)=emn(4,j)*a(1,1)+emn(2,j)*a(1,2)+emn(6,j)*a(1,3) b(2,2)=emn(4,j)*a(2,1)+emn(2,j)*a(2,2)+emn(6,j)*a(2,3) b(2,3)=emn(4,j)*a(3,1)+emn(2,j)*a(3,2)+emn(6,j)*a(3,3) b(3,1)=emn(5,j)*a(1,1)+emn(6,j)*a(1,2)+emn(3,j)*a(1,3) b(3,2)=emn(5,j)*a(2,1)+emn(6,j)*a(2,2)+emn(3,j)*a(2,3) b(3,3)=emn(5,j)*a(3,1)+emn(6,j)*a(3,2)+emn(3,j)*a(3,3) ! emn(1,j)=a(1,1)*b(1,1)+a(1,2)*b(2,1)+a(1,3)*b(3,1) emn(2,j)=a(2,1)*b(1,2)+a(2,2)*b(2,2)+a(2,3)*b(3,2) emn(3,j)=a(3,1)*b(1,3)+a(3,2)*b(2,3)+a(3,3)*b(3,3) emn(4,j)=a(1,1)*b(1,2)+a(1,2)*b(2,2)+a(1,3)*b(3,2) emn(5,j)=a(1,1)*b(1,3)+a(1,2)*b(2,3)+a(1,3)*b(3,3) emn(6,j)=a(2,1)*b(1,3)+a(2,2)*b(2,3)+a(2,3)*b(3,3) endif endif ! enddo endif ! return end
gpl-2.0
jabbaqin/p3dfft
build/ftran.F90
3
24413
! This file is part of P3DFFT library ! ! P3DFFT ! ! Software Framework for Scalable Fourier Transforms in Three Dimensions ! ! Copyright (C) 2006-2014 Dmitry Pekurovsky ! Copyright (C) 2006-2014 University of California ! Copyright (C) 2010-2011 Jens Henrik Goebbert ! ! This program is free software: you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation, either version 3 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. ! ! !---------------------------------------------------------------------------- ! This is a C wrapper routine !======================================================== subroutine p3dfft_ftran_r2c_many_w (XgYZ,dim_in,XYZg,dim_out,nv,op) BIND(C,NAME='p3dfft_ftran_r2c_many') !======================================================== use, intrinsic :: iso_c_binding real(mytype), TARGET :: XgYZ(nx_fft,jistart:jiend,kjstart:kjend) #ifdef STRIDE1 complex(mytype), TARGET :: XYZg(nzc,iistart:iiend,jjstart:jjend) #else complex(mytype), TARGET :: XYZg(iistart:iiend,jjstart:jjend,nzc) #endif integer dim_in,dim_out,nv character, dimension(*), target :: op character(4), pointer :: lcl_op call c_f_pointer(c_loc(op), lcl_op) call p3dfft_ftran_r2c_many (XgYZ,dim_in,XYZg,dim_out,nv,lcl_op) end subroutine ! Forward R2C transform of multiple variables (nv) !======================================================== subroutine p3dfft_ftran_r2c_many (XgYZ,dim_in,XYZg,dim_out,nv,op) !======================================================== use fft_spec implicit none integer dim_in,dim_out real(mytype), TARGET :: XgYZ(dim_in,nv) complex(mytype), TARGET :: XYZg(dim_out,nv) integer x,y,z,i,nx,ny,nz,ierr,dnz,nv,j,err,n1,n2 integer(i8) Nl character(len=3) op if(.not. mpi_set) then print *,'P3DFFT error: call setup before other routines' return endif if(dim_in .lt. nx_fft*jisize*kjsize) then print *,taskid,': ftran error: input array dimensions are too low: ',dim_in,' while expecting ',nx_fft*jisize*kjsize endif if(dim_out .lt. nzc*jjsize*iisize) then print *,taskid,': ftran error: output array dimensions are too low: ',dim_out,' while expecting ',nzc*jjsize*iisize endif ! preallocate memory for FFT-Transforms if(nv .gt. nv_preset) then nv_preset = nv deallocate(buf1,buf2,buf) allocate (buf(nxhp*jisize*(kjsize+padi)*nv), stat=err) if (err /= 0) then print *, 'Error ', err, ' allocating array buf' end if ! initialize buf to avoid "floating point invalid" errors in debug mode buf = 0.d0 #ifdef USE_EVEN n1 = nv * IfCntMax * iproc /(mytype*2) n2 = nv * KfCntMax * jproc / (mytype*2) n1 = max(n1,n2) allocate(buf1(n1)) allocate(buf2(n1)) #else if(taskid .eq. 0) then print *,'nm=',nm endif allocate(buf1(nm*nv)) allocate(buf2(nm*nv)) #endif endif nx = nx_fft ny = ny_fft nz = nz_fft ! For FFT libraries that require explicit allocation of work space, ! such as ESSL, initialize here #ifdef DEBUG print *,taskid,': Enter ftran',nv,nv_preset #endif ! FFT transform (R2C) in X for all z and y if(jisize * kjsize .gt. 0) then call init_f_r2c(XgYZ,nx,buf,nxhp,nx,jisize*kjsize) timers(5) = timers(5) - MPI_Wtime() call f_r2c_many(XgYZ,nx,buf,nxhp,nx,jisize*kjsize,dim_in,nv) timers(5) = timers(5) + MPI_Wtime() endif ! Exchange data in rows if(iproc .gt. 1) then #ifdef DEBUG print *,taskid,': Calling fcomm1' #endif call fcomm1_many(buf,buf,nv,timers(1),timers(6)) #ifdef STRIDE1 else call reorder_f1_many(buf,buf,buf1,nv) #endif endif ! FFT transform (C2C) in Y for all x and z, one Z plane at a time #ifdef DEBUG print *,taskid,': Transforming in Y' #endif if(iisize * kjsize .gt. 0) then #ifdef STRIDE1 call init_f_c(buf,1,ny,buf,1,ny,ny,iisize*kjsize) timers(7) = timers(7) - MPI_Wtime() call f_c1_many(buf,1,ny,ny,iisize*kjsize,iisize*kjsize*ny,nv) timers(7) = timers(7) + MPI_Wtime() #else call init_f_c(buf,iisize,1,buf,iisize,1,ny,iisize) timers(7) = timers(7) - MPI_Wtime() do z=1,kjsize*nv call ftran_y_zplane(buf,z-1,iisize,kjsize,iisize,1, buf,z-1,iisize,kjsize,iisize,1,ny,iisize) enddo timers(7) = timers(7) + MPI_Wtime() #endif endif #ifdef DEBUG print *,taskid,': Calling fcomm2' #endif ! Exchange data in columns if(jproc .gt. 1) then #ifdef STRIDE1 ! For stride1 option combine second transpose with transform in Z call init_f_c(buf,1,nz, XYZg,1,nz,nz,jjsize,op) call fcomm2_trans_many(buf,XYZg,buf,dim_out,nv,op,timers(2),timers(8)) #else ! FFT Transform (C2C) in Z for all x and y dnz = nz - nzc if(dnz .gt. 0) then ! Transpose y-z call fcomm2_many(buf,buf,iisize*jjsize*nz,nv,timers(2),timers(8)) ! In forward transform we can safely use output array as one of the buffers ! This speeds up FFTW since it is non-stride-1 transform and it is ! faster than done in-place #ifdef DEBUG print *,taskid,': Transforming in Z' #endif if(iisize * jjsize .gt. 0) then call ztran_f_same_many(buf,iisize*jjsize,1,nz,iisize*jjsize,iisize*jjsize*nz,nv,op) call seg_copy_z_f_many(buf,XYZg,1,iisize,1,jjsize,1,nzhc,0,iisize,jjsize,nz,dim_out,nv) call seg_copy_z_f_many(buf,XYZg,1,iisize,1,jjsize,nzhc+1,nzc,dnz,iisize,jjsize,nz,dim_out,nv) endif else call fcomm2_many(buf,XYZg,dim_out,nv,timers(2),timers(8)) ! In forward transform we can safely use output array as one of the buffers ! This speeds up FFTW since it is non-stride-1 transform and it is ! faster than done in-place #ifdef DEBUG print *,taskid,': Transforming in Z' #endif if(iisize * jjsize .gt. 0) then call ztran_f_same_many(XYZg,iisize*jjsize,1,nz,iisize*jjsize,dim_out,nv,op) endif endif #endif else timers(8) = timers(8) - MPI_Wtime() #ifdef STRIDE1 call reorder_trans_f2_many(buf,XYZg,buf1,dim_out,nv,op) #else Nl = iisize*jjsize*nz dnz = nz - nzc if(dnz .gt. 0) then call ztran_f_same_many(buf,iisize*jjsize,1,nz,iisize*jjsize,iisize*jjsize*nz,nv,op) call seg_copy_z_f_many(buf,XYZg,1,iisize,1,jjsize,1,nzhc,0,iisize,jjsize,nz,dim_out,nv) call seg_copy_z_f_many(buf,XYZg,1,iisize,1,jjsize,nzhc+1,nzc,dnz,iisize,jjsize,nz,dim_out,nv) else call ar_copy_many(buf,iisize*jjsize*nz,XYZg,dim_out,Nl,nv) call ztran_f_same_many(XYZg,iisize*jjsize,1,nz,iisize*jjsize,dim_out,nv,op) endif #endif timers(8) = timers(8) + MPI_Wtime() endif ! deallocate(buf) return end subroutine ! This is a C wrapper routine !======================================================== subroutine p3dfft_ftran_cheby_many_w (XgYZ,dim_in,XYZg,dim_out,nv,Lz) BIND(C,NAME='p3dfft_cheby_many') !======================================================== real(mytype), TARGET :: XgYZ(nx_fft,jistart:jiend,kjstart:kjend) #ifdef STRIDE1 complex(mytype), TARGET :: XYZg(nzc,iistart:iiend,jjstart:jjend) #else complex(mytype), TARGET :: XYZg(iistart:iiend,jjstart:jjend,nzc) #endif integer dim_in,dim_out,nv real(mytype) Lz call p3dfft_cheby_many (XgYZ,dim_in,XYZg,dim_out,nv,Lz) end subroutine ! Chebyshev transform (2D R2C forward FFT + Chebyshev) for multiple variables !======================================================== subroutine p3dfft_cheby_many(in,dim_in,out,dim_out,nv,Lz) !======================================================== integer dim_in,dim_out,nv,j real(mytype) Lz real(mytype), dimension(dim_in,nv), target :: in complex(mytype), dimension (dim_out,nv), target :: out call p3dfft_ftran_r2c_many(in,dim_in,out,dim_out,nv,'ffc') do j=1,nv call p3dfft_cheby(in(1,j),out(1,j),Lz) enddo return end subroutine ! This is a C wrapper routine !======================================================== subroutine p3dfft_cheby_w(in,out,Lz) BIND(C,NAME='p3dfft_cheby') !======================================================== real(mytype), dimension(nx_fft, & jisize, & kjsize), target :: in #ifdef STRIDE1 complex(mytype), dimension(nzc, & jjsize,& iisize), target :: out #else complex(mytype), dimension(iisize, & jjsize, & nzc), target :: out #endif real(mytype) Lz call p3dfft_cheby(in,out,Lz) end subroutine ! Chebyshev transform (2D R2C forward FFT + Chebyshev) for a single variable !============================================================== subroutine p3dfft_cheby(in,out,Lz) !======================================================== ! ! function args real(mytype), dimension(nx_fft, & jisize, & kjsize), target :: in #ifdef STRIDE1 complex(mytype), dimension(nzc, & jjsize,& iisize), target :: out complex(mytype) Old, New, Tmp #else complex(mytype), dimension(iisize, & jjsize, & nzc), target :: out complex(mytype),dimension(:,:),pointer :: ptrOld, ptrNew, ptrTmp #endif real(mytype) :: Lfactor,Lz integer k,nz,i,j nz = nzc call p3dfft_ftran_r2c(in,out,'ffc') out = out *(1.d0/(dble(nx_fft*ny_fft)*dble(nzc-1))) ! less tmp-memory version (but difficult to read) Lfactor = 4.d0/dble(Lz) #ifdef STRIDE1 ! first and last cheby-coeff needs to gets multiplied by factor 0.5 ! because of relation between cheby and discrete cosinus transforms do i=1,iisize do j=1,jjsize Old = out(nzc-1,j,i) out(nzc-1,j,i) = Lfactor *dble(nzc-1) *out(nzc,j,i) * 0.5d0 out(nzc,j,i) = cmplx(0.d0,0.d0) do k = nzc-2, 1, -1 New = out(k,j,i) out(k,j,i) = Lfactor *dble(k) *Old +out(k+2,j,i) Tmp = New New = Old Old = Tmp enddo out(1,j,i) = out(1,j,i) *0.5d0 enddo enddo #else allocate(ptrOld(iisize,jjsize)) allocate(ptrNew(iisize,jjsize)) ptrOld(:,:) = out(:,:,nzc-1) out(:,:,nzc-1) = Lfactor *dble(nzc-1) *out(:,:,nzc) *0.5d0 out(:,:,nzc ) = cmplx(0.d0,0.d0) do k = nzc-2, 1, -1 ptrNew(:,:) = out(:,:,k) out(:,:,k) = Lfactor *dble(k) *ptrOld(:,:) +out(:,:,k+2) ptrTmp => ptrNew ptrNew => ptrOld ptrOld => ptrTmp enddo out(:,:,1) = out(:,:,1) *0.5d0 deallocate(ptrOld) deallocate(ptrNew) #endif ! ! easy to read version (but more tmp-memory needed) ! Lfactor = 4.d0/Lz ! ctest10 = out ! out(:,:,n3 ) = cmplx(0.d0,0.d0) !ok ! out(:,:,n3-1) = Lfactor *dble(n3-1) *ctest10(:,:,n3) !ok ! do k = n3-2, 1, -1 ! out(:,:,k) = Lfactor *dble(k) *ctest10(:,:,k+1) +out(:,:,k+2) ! enddo ! out(:,:,1) = out(:,:,1) *0.5d0 return end subroutine p3dfft_cheby ! This is a C wrapper routine !======================================================== subroutine p3dfft_ftran_r2c_w (XgYZ,XYZg,op) BIND(C,NAME='p3dfft_ftran_r2c') !======================================================== use, intrinsic :: iso_c_binding real(mytype), TARGET :: XgYZ(nx_fft,jistart:jiend,kjstart:kjend) #ifdef STRIDE1 complex(mytype), TARGET :: XYZg(nzc,iistart:iiend,jjstart:jjend) #else complex(mytype), TARGET :: XYZg(iistart:iiend,jjstart:jjend,nzc) #endif integer dim_in,dim_out,nv character, dimension(*), target :: op character(4), pointer :: lcl_op call c_f_pointer(c_loc(op), lcl_op) call p3dfft_ftran_r2c (XgYZ,XYZg,lcl_op) end subroutine ! Forward R2C transform of 1 variable !======================================================== subroutine p3dfft_ftran_r2c (XgYZ,XYZg,op) !======================================================== use fft_spec implicit none real(mytype), TARGET :: XgYZ(nx_fft,jistart:jiend,kjstart:kjend) #ifdef STRIDE1 complex(mytype), TARGET :: XYZg(nzc,iistart:iiend,jjstart:jjend) #else complex(mytype), TARGET :: XYZg(iistart:iiend,jjstart:jjend,nzc) #endif integer x,y,z,i,nx,ny,nz,ierr,dnz integer(i8) Nl character(len=3) op if(.not. mpi_set) then print *,'P3DFFT error: call setup before other routines' return endif nx = nx_fft ny = ny_fft nz = nz_fft ! For FFT libraries that require explicit allocation of work space, ! such as ESSL, initialize here #ifdef DEBUG print *,taskid,': Enter ftran' #endif ! FFT transform (R2C) in X for all z and y if(jisize * kjsize .gt. 0) then call init_f_r2c(XgYZ,nx,buf,nxhp,nx,jisize*kjsize) timers(5) = timers(5) - MPI_Wtime() call exec_f_r2c(XgYZ,nx,buf,nxhp,nx,jisize*kjsize) timers(5) = timers(5) + MPI_Wtime() endif ! Exchange data in rows if(iproc .gt. 1) then #ifdef DEBUG print *,taskid,': Calling fcomm1' #endif call fcomm1(buf,buf,timers(1),timers(6)) #ifdef STRIDE1 else call reorder_f1(buf,buf,buf1) #endif endif ! FFT transform (C2C) in Y for all x and z, one Z plane at a time #ifdef DEBUG print *,taskid,': Transforming in Y' #endif if(iisize * kjsize .gt. 0) then #ifdef STRIDE1 call init_f_c(buf,1,ny,buf,1,ny,ny,iisize*kjsize) timers(7) = timers(7) - MPI_Wtime() call exec_f_c1(buf,1,ny,buf,1,ny,ny,iisize*kjsize) timers(7) = timers(7) + MPI_Wtime() #else call init_f_c(buf,iisize,1,buf,iisize,1,ny,iisize) timers(7) = timers(7) - MPI_Wtime() do z=1,kjsize call ftran_y_zplane(buf,z-1,iisize,kjsize,iisize,1, buf,z-1,iisize,kjsize,iisize,1,ny,iisize) enddo timers(7) = timers(7) + MPI_Wtime() #endif endif #ifdef DEBUG print *,taskid,': Calling fcomm2' #endif ! Exchange data in columns if(jproc .gt. 1) then #ifdef STRIDE1 ! For stride1 option combine second transpose with transform in Z call init_f_c(buf,1,nz, XYZg,1,nz,nz,jjsize,op) call fcomm2_trans(buf,XYZg,buf,op,timers(2),timers(8)) #else ! FFT Transform (C2C) in Z for all x and y dnz = nz - nzc if(dnz .gt. 0) then ! Transpose y-z call fcomm2(buf,buf,timers(2),timers(8)) ! In forward transform we can safely use output array as one of the buffers ! This speeds up FFTW since it is non-stride-1 transform and it is ! faster than done in-place #ifdef DEBUG print *,taskid,': Transforming in Z' #endif if(iisize * jjsize .gt. 0) then if(op(3:3) == 't' .or. op(3:3) == 'f') then call init_f_c(buf,iisize*jjsize, 1, buf,iisize*jjsize, 1,nz,iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_f_c2_same(buf,iisize*jjsize, 1,buf,iisize*jjsize, 1,nz,iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) == 'c') then call init_ctrans_r2(buf,2*iisize*jjsize, 1, buf,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_ctrans_r2_same(buf,2*iisize*jjsize, 1,buf,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) == 's') then call init_strans_r2(buf,2*iisize*jjsize, 1, buf,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_strans_r2_same(buf,2*iisize*jjsize, 1,buf,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) .ne. 'n' .and. op(3:3) .ne. '0') then print *,'Unknown transform type: ',op(3:3) call MPI_Abort(MPI_COMM_WORLD,ierr) endif call seg_copy_z(buf,XYZg,1,iisize,1,jjsize,1,nzhc,0,iisize,jjsize,nz) call seg_copy_z(buf,XYZg,1,iisize,1,jjsize,nzhc+1,nzc,dnz,iisize,jjsize,nz) endif else call fcomm2(buf,XYZg,timers(2),timers(8)) ! In forward transform we can safely use output array as one of the buffers ! This speeds up FFTW since it is non-stride-1 transform and it is ! faster than done in-place #ifdef DEBUG print *,taskid,': Transforming in Z' #endif if(iisize * jjsize .gt. 0) then if(op(3:3) == 't' .or. op(3:3) == 'f') then call init_f_c(XYZg,iisize*jjsize, 1, XYZg,iisize*jjsize, 1,nz,iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_f_c2_same(XYZg,iisize*jjsize, 1,XYZg,iisize*jjsize, 1,nz,iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) == 'c') then call init_ctrans_r2(XYZg,2*iisize*jjsize, 1, XYZg,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_ctrans_r2_same(XYZg,2*iisize*jjsize, 1,XYZg,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) == 's') then call init_strans_r2(XYZg,2*iisize*jjsize, 1, XYZg,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_strans_r2_same(XYZg,2*iisize*jjsize, 1,XYZg,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) .ne. 'n' .and. op(3:3) .ne. '0') then print *,'Unknown transform type: ',op(3:3) call MPI_Abort(MPI_COMM_WORLD,ierr) endif endif endif #endif else timers(8) = timers(8) - MPI_Wtime() #ifdef STRIDE1 call reorder_trans_f2(buf,XYZg,buf1,op) #else Nl = iisize*jjsize*nz dnz = nz - nzc if(dnz .gt. 0) then if(op(3:3) == 't' .or. op(3:3) == 'f') then call init_f_c(buf,iisize*jjsize, 1,buf,iisize*jjsize, 1,nz,iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_f_c2_same(buf,iisize*jjsize, 1,buf,iisize*jjsize, 1,nz,iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) == 'c') then call init_ctrans_r2(buf,2*iisize*jjsize, 1,buf,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_ctrans_r2_same(buf,2*iisize*jjsize, 1,buf,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) == 's') then call init_strans_r2(buf,2*iisize*jjsize, 1,buf,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_strans_r2_same(buf,2*iisize*jjsize, 1,buf,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) /= 'n' .and. op(3:3) /= '0') then print *,'Unknown transform type: ',op(3:3) call MPI_Abort(MPI_COMM_WORLD,ierr) endif call seg_copy_z(buf,XYZg,1,iisize,1,jjsize,1,nzhc,0,iisize,jjsize,nz) call seg_copy_z(buf,XYZg,1,iisize,1,jjsize,nzhc+1,nzc,dnz,iisize,jjsize,nz) else call ar_copy(buf,XYZg,Nl) if(op(3:3) == 't' .or. op(3:3) == 'f') then call init_f_c(XYZg,iisize*jjsize, 1, XYZg,iisize*jjsize, 1,nz,iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_f_c2_same(XYZg,iisize*jjsize, 1,XYZg,iisize*jjsize, 1,nz,iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) == 'c') then call init_ctrans_r2(XYZg,2*iisize*jjsize, 1, XYZg,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_ctrans_r2_same(XYZg,2*iisize*jjsize, 1,XYZg,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) == 's') then call init_strans_r2(XYZg,2*iisize*jjsize, 1, XYZg,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) - MPI_Wtime() call exec_strans_r2_same(XYZg,2*iisize*jjsize, 1,XYZg,2*iisize*jjsize, 1,nz,2*iisize*jjsize) timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) /= 'n' .and. op(3:3) /= '0') then print *,'Unknown transform type: ',op(3:3) call MPI_Abort(MPI_COMM_WORLD,ierr) endif endif #endif timers(8) = timers(8) + MPI_Wtime() endif return end subroutine ! -------------------------------------- ! ! p3dfft_ftran_r2c_1d(..) ! ! -------------------------------------- subroutine p3dfft_ftran_r2c_1d (rXgYZ, cXgYZ) use fft_spec implicit none real (mytype), target :: rXgYZ (NX_fft, jistart:jiend, kjstart:kjend) real (mytype), target :: cXgYZ (NX_fft+2, jistart:jiend, kjstart:kjend) ! complex(mytype), allocatable :: XYgZ(:,:,:) integer x, y, z, i, err, nx, ny, nz if ( .not. mpi_set) then print *, 'P3DFFT error: call setup before other routines' return end if nx = NX_fft ny = NY_fft nz = NZ_fft ! ! FFT transform (R2C) in X for all z and y ! if (jisize*kjsize > 0) then call init_f_r2c (rXgYZ, nx, cXgYZ, nxhp, nx, jisize*kjsize) call exec_f_r2c (rXgYZ, nx, cXgYZ, nxhp, nx, jisize*kjsize) end if end subroutine p3dfft_ftran_r2c_1d ! call f_r2c(XgYZ,nx,buf,nxhp,nx,jisize*kjsize,nv) subroutine f_r2c_many(source,str1,dest,str2,n,m,dim,nv) integer str1,str2,n,m,nv,j,dim real(mytype) source(dim,nv) complex(mytype) dest(n/2+1,m,nv) do j=1,nv call exec_f_r2c(source(1,j),str1,dest(1,1,j),str2,n,m) enddo return end subroutine subroutine f_c1_many(A,str1,str2,n,m,dim,nv) integer n,m,nv,j,str1,str2,dim complex(mytype) A(dim,nv) do j=1,nv call exec_f_c1(A(1,j),str1,str2,A(1,j),str1,str2,n,m) enddo return end subroutine subroutine ztran_f_same_many(A,str1,str2,n,m,dim,nv,op) integer str1,str2,n,m,nv,j,ierr,dim complex(mytype) A(dim,nv) character(len=3) op if(op(3:3) == 't' .or. op(3:3) == 'f') then call init_f_c(A,str1,str2,A,str1,str2,n,m) timers(8) = timers(8) - MPI_Wtime() do j=1,nv call exec_f_c2_same(A(1,j),str1,str2,A(1,j),str1,str2,n,m) enddo timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) == 'c') then call init_ctrans_r2(A,str1,str2,A,str1,str2,n,m) timers(8) = timers(8) - MPI_Wtime() do j=1,nv call exec_ctrans_r2_same(A(1,j),2*str1,str2,A(1,j),2*str1,str2,n,2*m) enddo timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) == 's') then call init_strans_r2(A,str1,str2,A,str1,str2,n,m) timers(8) = timers(8) - MPI_Wtime() do j=1,nv call exec_strans_r2_same(A(1,j),2*str1,str2,A(1,j),2*str1,str2,n,2*m) enddo timers(8) = timers(8) + MPI_Wtime() else if(op(3:3) .ne. 'n' .and. op(3:3) .ne. '0') then print *,'Unknown transform type: ',op(3:3) call MPI_Abort(MPI_COMM_WORLD,ierr) endif return end subroutine
gpl-3.0
prool/ccx_prool
CalculiX/ccx_2.8p2/src/mafillem.f
4
23787
! ! CalculiX - A 3-dimensional finite element program ! Copyright (C) 1998-2015 Guido Dhondt ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License as ! published by the Free Software Foundation(version 2); ! ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! subroutine mafillem(co,nk,kon,ipkon,lakon,ne,nodeboun,ndirboun, & xboun,nboun, & ipompc,nodempc,coefmpc,nmpc,nodeforc,ndirforc,xforc, & nforc,nelemload,sideload,xload,nload,xbody,ipobody,nbody,cgr, & ad,au,fext,nactdof,icol,jq,irow,neq,nzl,nmethod, & ikmpc,ilmpc,ikboun,ilboun,elcon,nelcon,rhcon, & nrhcon,alcon,nalcon,alzero,ielmat,ielorien,norien,orab,ntmat_, & t0,t1,ithermal,prestr, & iprestr,vold,iperturb,sti,nzs,stx,adb,aub,iexpl,plicon, & nplicon,plkcon,nplkcon,xstiff,npmat_,dtime, & matname,mi,ncmat_,mass,stiffness,buckling,rhsi,intscheme, & physcon,shcon,nshcon,cocon,ncocon,ttime,time,istep,iinc, & coriolis,ibody,xloadold,reltime,veold,springarea,nstate_, & xstateini,xstate,thicke,integerglob,doubleglob, & tieset,istartset,iendset,ialset,ntie,nasym,iactive,h0, & pslavsurf,pmastsurf,mortar,clearini,ielprop,prop) ! ! filling the stiffness matrix in spare matrix format (sm) ! ! domain 1: phi-domain (air) ! domain 2: A,V-domain (body) ! domain 3: A-domain (air, the union of domain 2 and 3 should ! be simple connected) ! implicit none ! logical mass(2),stiffness,buckling,rhsi,stiffonly(2),coriolis ! character*8 lakon(*) character*20 sideload(*) character*80 matname(*) character*81 tieset(3,*) ! integer kon(*),nodeboun(*),ndirboun(*),ipompc(*),nodempc(3,*), & nodeforc(2,*),ndirforc(*),nelemload(2,*),icol(*),jq(*),ikmpc(*), & ilmpc(*),ikboun(*),ilboun(*),mi(*),nstate_,ne0,nasym, & nactdof(0:mi(2),*),konl(26),irow(*),icolumn,ialset(*), & nelcon(2,*),nrhcon(*),nalcon(2,*),ielmat(mi(3),*),ntie, & ielorien(mi(3),*),integerglob(*),istartset(*),iendset(*), & ipkon(*),intscheme,ncocon(2,*),nshcon(*),ipobody(2,*),nbody, & ibody(3,*),nk,ne,nboun,nmpc,nforc,nload,neq(2),nzl,nmethod, & ithermal(2),iprestr,iperturb(*),nzs(3),i,j,k,l,m,idist,jj, & ll,id,id1,id2,ist,ist1,ist2,index,jdof1,jdof2,idof1,idof2, & mpc1,mpc2,index1,index2,jdof,node1,node2,kflag,icalccg, & ntmat_,indexe,nope,norien,iexpl,i0,ncmat_,istep,iinc,mortar, & nplicon(0:ntmat_,*),nplkcon(0:ntmat_,*),npmat_,iactive(3), & ielprop(*) ! real*8 co(3,*),xboun(*),coefmpc(*),xforc(*),xload(2,*),p1(3), & p2(3),ad(*),au(*),bodyf(3),fext(*),xloadold(2,*),reltime, & t0(*),t1(*),prestr(6,mi(1),*),vold(0:mi(2),*),s(100,100), & sti(6,mi(1),*),sm(100,100),stx(6,mi(1),*),adb(*),aub(*), & elcon(0:ncmat_,ntmat_,*),rhcon(0:1,ntmat_,*),springarea(2,*), & alcon(0:6,ntmat_,*),physcon(*),cocon(0:6,ntmat_,*),ff(100), & xstate(nstate_,mi(1),*),xstateini(nstate_,mi(1),*), & shcon(0:3,ntmat_,*),alzero(*),orab(7,*),xbody(7,*),cgr(4,*), & plicon(0:2*npmat_,ntmat_,*),plkcon(0:2*npmat_,ntmat_,*), & xstiff(27,mi(1),*),veold(0:mi(2),*),om,valu2,value,dtime,ttime, & time,thicke(mi(3),*),doubleglob(*),h0(3,*), & pslavsurf(3,*),pmastsurf(6,*),clearini(3,9,*),prop(*) ! kflag=2 i0=0 icalccg=0 ! if(stiffness.and.(.not.mass(1))) then stiffonly(1)=.true. else stiffonly(1)=.false. endif if(stiffness.and.(.not.mass(2))) then stiffonly(2)=.true. else stiffonly(2)=.false. endif ! ! determining nzl ! nzl=0 do i=neq(2),1,-1 if(icol(i).gt.0) then nzl=i exit endif enddo ! ! initializing the matrices ! do i=1,neq(2) ad(i)=0.d0 enddo do i=1,nzs(3) au(i)=0.d0 enddo ! if(rhsi) then do i=1,neq(2) fext(i)=0.d0 enddo endif ! if(mass(1)) then do i=1,neq(1) adb(i)=0.d0 enddo do i=1,nzs(1) aub(i)=0.d0 enddo endif if(mass(2)) then do i=neq(1)+1,neq(2) adb(i)=0.d0 enddo do i=nzs(1)+1,nzs(2) aub(i)=0.d0 enddo endif ! ! electromagnetic force should always be taken into account ! if(rhsi) idist=1 ! if((ithermal(1).le.1).or.(ithermal(1).eq.3)) then ! ! electromagnetic analysis: loop over all elements ! ne0=0 do i=1,ne ! if(ipkon(i).lt.0) cycle indexe=ipkon(i) if(lakon(i)(4:5).eq.'20') then nope=20 elseif(lakon(i)(4:4).eq.'8') then nope=8 elseif(lakon(i)(4:5).eq.'10') then nope=10 elseif(lakon(i)(4:4).eq.'4') then nope=4 elseif(lakon(i)(4:5).eq.'15') then nope=15 elseif(lakon(i)(4:4).eq.'6') then nope=6 else cycle endif ! do j=1,nope konl(j)=kon(indexe+j) enddo ! call e_c3d_em(co,konl,lakon(i),s,sm,ff,i,nmethod, & ielmat,ntmat_,t1,ithermal,vold, & idist,matname,mi,mass(1),rhsi, & ncmat_,elcon,nelcon,h0,iactive, & alcon,nalcon,istartset,iendset,ialset) ! do jj=1,5*nope ! j=(jj-1)/5+1 k=jj-5*(j-1) ! node1=kon(indexe+j) jdof1=nactdof(k,node1) ! do ll=jj,5*nope ! l=(ll-1)/5+1 m=ll-5*(l-1) ! node2=kon(indexe+l) jdof2=nactdof(m,node2) ! ! check whether one of the DOF belongs to a SPC or MPC ! if((jdof1.ne.0).and.(jdof2.ne.0)) then if(stiffonly(1)) then call add_sm_st(au,ad,jq,irow,jdof1,jdof2, & s(jj,ll),jj,ll) else call add_sm_ei(au,ad,aub,adb,jq,irow,jdof1,jdof2, & s(jj,ll),sm(jj,ll),jj,ll) endif elseif((jdof1.ne.0).or.(jdof2.ne.0)) then ! ! idof1: genuine DOF ! idof2: nominal DOF of the SPC/MPC ! if(jdof1.eq.0) then idof1=jdof2 idof2=(node1-1)*8+k else idof1=jdof1 idof2=(node2-1)*8+m endif if(nmpc.gt.0) then call nident(ikmpc,idof2,nmpc,id) if((id.gt.0).and.(ikmpc(id).eq.idof2)) then ! ! regular DOF / MPC ! id=ilmpc(id) ist=ipompc(id) index=nodempc(3,ist) if(index.eq.0) cycle do idof2=nactdof(nodempc(2,index),nodempc(1,index)) value=-coefmpc(index)*s(jj,ll)/coefmpc(ist) if(idof1.eq.idof2) value=2.d0*value if(idof2.ne.0) then if(stiffonly(1)) then call add_sm_st(au,ad,jq,irow,idof1, & idof2,value,i0,i0) else valu2=-coefmpc(index)*sm(jj,ll)/ & coefmpc(ist) c if(idof1.eq.idof2) valu2=2.d0*valu2 c call add_sm_ei(au,ad,aub,adb,jq,irow, & idof1,idof2,value,valu2,i0,i0) endif endif index=nodempc(3,index) if(index.eq.0) exit enddo cycle endif endif ! ! regular DOF / SPC ! if(rhsi) then elseif(nmethod.eq.2) then value=s(jj,ll) call nident(ikboun,idof2,nboun,id) icolumn=neq(2)+ilboun(id) call add_bo_st(au,jq,irow,idof1,icolumn,value) endif else idof1=(node1-1)*8+k idof2=(node2-1)*8+m mpc1=0 mpc2=0 if(nmpc.gt.0) then call nident(ikmpc,idof1,nmpc,id1) if((id1.gt.0).and.(ikmpc(id1).eq.idof1)) mpc1=1 call nident(ikmpc,idof2,nmpc,id2) if((id2.gt.0).and.(ikmpc(id2).eq.idof2)) mpc2=1 endif if((mpc1.eq.1).and.(mpc2.eq.1)) then id1=ilmpc(id1) id2=ilmpc(id2) if(id1.eq.id2) then ! ! MPC id1 / MPC id1 ! ist=ipompc(id1) index1=nodempc(3,ist) if(index1.eq.0) cycle do idof1=nactdof(nodempc(2,index1), & nodempc(1,index1)) index2=index1 do idof2=nactdof(nodempc(2,index2), & nodempc(1,index2)) value=coefmpc(index1)*coefmpc(index2)* & s(jj,ll)/coefmpc(ist)/coefmpc(ist) if((idof1.ne.0).and.(idof2.ne.0)) then if(stiffonly(1)) then call add_sm_st(au,ad,jq,irow, & idof1,idof2,value,i0,i0) else valu2=coefmpc(index1)*coefmpc(index2)* & sm(jj,ll)/coefmpc(ist)/coefmpc(ist) call add_sm_ei(au,ad,aub,adb,jq, & irow,idof1,idof2,value,valu2,i0,i0) endif endif ! index2=nodempc(3,index2) if(index2.eq.0) exit enddo index1=nodempc(3,index1) if(index1.eq.0) exit enddo else ! ! MPC id1 / MPC id2 ! ist1=ipompc(id1) index1=nodempc(3,ist1) if(index1.eq.0) cycle do idof1=nactdof(nodempc(2,index1), & nodempc(1,index1)) ist2=ipompc(id2) index2=nodempc(3,ist2) if(index2.eq.0) then index1=nodempc(3,index1) if(index1.eq.0) then exit else cycle endif endif do idof2=nactdof(nodempc(2,index2), & nodempc(1,index2)) value=coefmpc(index1)*coefmpc(index2)* & s(jj,ll)/coefmpc(ist1)/coefmpc(ist2) if(idof1.eq.idof2) value=2.d0*value if((idof1.ne.0).and.(idof2.ne.0)) then if(stiffonly(1)) then call add_sm_st(au,ad,jq,irow, & idof1,idof2,value,i0,i0) else valu2=coefmpc(index1)*coefmpc(index2)* & sm(jj,ll)/coefmpc(ist1)/coefmpc(ist2) c if(idof1.eq.idof2) valu2=2.d0*valu2 c call add_sm_ei(au,ad,aub,adb,jq, & irow,idof1,idof2,value,valu2,i0,i0) endif endif ! index2=nodempc(3,index2) if(index2.eq.0) exit enddo index1=nodempc(3,index1) if(index1.eq.0) exit enddo endif endif endif enddo ! if(rhsi) then ! ! distributed forces ! if(idist.ne.0) then if(jdof1.eq.0) then if(nmpc.ne.0) then idof1=(node1-1)*8+k call nident(ikmpc,idof1,nmpc,id) if((id.gt.0).and.(ikmpc(id).eq.idof1)) then id=ilmpc(id) ist=ipompc(id) index=nodempc(3,ist) if(index.eq.0) cycle do jdof1=nactdof(nodempc(2,index), & nodempc(1,index)) if(jdof1.ne.0) then fext(jdof1)=fext(jdof1) & -coefmpc(index)*ff(jj) & /coefmpc(ist) endif index=nodempc(3,index) if(index.eq.0) exit enddo endif endif cycle endif fext(jdof1)=fext(jdof1)+ff(jj) endif endif ! enddo enddo ! endif if(ithermal(1).gt.1) then ! ! thermal analysis: loop over all elements ! do i=1,ne ! if(ipkon(i).lt.0) cycle ! ! only elements belonging to the A-V-domain should be ! included in the thermal analysis ! if(int(elcon(2,1,ielmat(1,i))).ne.2) cycle indexe=ipkon(i) if(lakon(i)(4:5).eq.'20') then nope=20 elseif(lakon(i)(4:4).eq.'8') then nope=8 elseif(lakon(i)(4:5).eq.'10') then nope=10 elseif(lakon(i)(4:4).eq.'4') then nope=4 elseif(lakon(i)(4:5).eq.'15') then nope=15 elseif(lakon(i)(4:4).eq.'6') then nope=6 elseif((lakon(i)(1:1).eq.'E').and.(lakon(i)(7:7).ne.'A')) then ! ! advection elements ! read(lakon(i)(8:8),'(i1)') nope nope=nope+1 elseif(lakon(i)(1:2).eq.'D ') then ! ! asymmetrical contribution -> mafillsmas.f ! cycle else cycle endif ! call e_c3d_th(co,nk,kon,lakon(i),s,sm, & ff,i,nmethod,rhcon,nrhcon,ielmat,ielorien,norien,orab, & ntmat_,t0,t1,ithermal,vold,iperturb,nelemload, & sideload,xload,nload,idist,iexpl,dtime, & matname,mi(1),mass(2),stiffness,buckling,rhsi,intscheme, & physcon,shcon,nshcon,cocon,ncocon,ttime,time,istep,iinc, & xstiff,xloadold,reltime,ipompc,nodempc,coefmpc,nmpc,ikmpc, & ilmpc,springarea,plkcon,nplkcon,npmat_,ncmat_,elcon,nelcon, & lakon,pslavsurf,pmastsurf,mortar,clearini,plicon,nplicon, & ipkon,ielprop,prop) ! do jj=1,nope ! j=jj ! node1=kon(indexe+j) jdof1=nactdof(0,node1) ! do ll=jj,nope ! l=ll ! node2=kon(indexe+l) jdof2=nactdof(0,node2) ! ! check whether one of the DOF belongs to a SPC or MPC ! if((jdof1.ne.0).and.(jdof2.ne.0)) then if(stiffonly(2)) then call add_sm_st(au,ad,jq,irow,jdof1,jdof2, & s(jj,ll),jj,ll) else call add_sm_ei(au,ad,aub,adb,jq,irow,jdof1,jdof2, & s(jj,ll),sm(jj,ll),jj,ll) endif elseif((jdof1.ne.0).or.(jdof2.ne.0)) then ! ! idof1: genuine DOF ! idof2: nominal DOF of the SPC/MPC ! if(jdof1.eq.0) then idof1=jdof2 idof2=(node1-1)*8 else idof1=jdof1 idof2=(node2-1)*8 endif if(nmpc.gt.0) then call nident(ikmpc,idof2,nmpc,id) if((id.gt.0).and.(ikmpc(id).eq.idof2)) then ! ! regular DOF / MPC ! id=ilmpc(id) ist=ipompc(id) index=nodempc(3,ist) if(index.eq.0) cycle do idof2=nactdof(nodempc(2,index),nodempc(1,index)) value=-coefmpc(index)*s(jj,ll)/coefmpc(ist) if(idof1.eq.idof2) value=2.d0*value if(idof2.ne.0) then if(stiffonly(2)) then call add_sm_st(au,ad,jq,irow,idof1, & idof2,value,i0,i0) else valu2=-coefmpc(index)*sm(jj,ll)/ & coefmpc(ist) ! if(idof1.eq.idof2) valu2=2.d0*valu2 ! call add_sm_ei(au,ad,aub,adb,jq,irow, & idof1,idof2,value,valu2,i0,i0) endif endif index=nodempc(3,index) if(index.eq.0) exit enddo cycle endif endif ! ! regular DOF / SPC ! if(rhsi) then elseif(nmethod.eq.2) then value=s(jj,ll) call nident(ikboun,idof2,nboun,id) icolumn=neq(2)+ilboun(id) call add_bo_st(au,jq,irow,idof1,icolumn,value) endif else idof1=(node1-1)*8 idof2=(node2-1)*8 mpc1=0 mpc2=0 if(nmpc.gt.0) then call nident(ikmpc,idof1,nmpc,id1) if((id1.gt.0).and.(ikmpc(id1).eq.idof1)) mpc1=1 call nident(ikmpc,idof2,nmpc,id2) if((id2.gt.0).and.(ikmpc(id2).eq.idof2)) mpc2=1 endif if((mpc1.eq.1).and.(mpc2.eq.1)) then id1=ilmpc(id1) id2=ilmpc(id2) if(id1.eq.id2) then ! ! MPC id1 / MPC id1 ! ist=ipompc(id1) index1=nodempc(3,ist) if(index1.eq.0) cycle do idof1=nactdof(nodempc(2,index1), & nodempc(1,index1)) index2=index1 do idof2=nactdof(nodempc(2,index2), & nodempc(1,index2)) value=coefmpc(index1)*coefmpc(index2)* & s(jj,ll)/coefmpc(ist)/coefmpc(ist) if((idof1.ne.0).and.(idof2.ne.0)) then if(stiffonly(2)) then call add_sm_st(au,ad,jq,irow, & idof1,idof2,value,i0,i0) else valu2=coefmpc(index1)*coefmpc(index2)* & sm(jj,ll)/coefmpc(ist)/coefmpc(ist) call add_sm_ei(au,ad,aub,adb,jq, & irow,idof1,idof2,value,valu2,i0,i0) endif endif ! index2=nodempc(3,index2) if(index2.eq.0) exit enddo index1=nodempc(3,index1) if(index1.eq.0) exit enddo else ! ! MPC id1 / MPC id2 ! ist1=ipompc(id1) index1=nodempc(3,ist1) if(index1.eq.0) cycle do idof1=nactdof(nodempc(2,index1), & nodempc(1,index1)) ist2=ipompc(id2) index2=nodempc(3,ist2) if(index2.eq.0) then index1=nodempc(3,index1) if(index1.eq.0) then exit else cycle endif endif do idof2=nactdof(nodempc(2,index2), & nodempc(1,index2)) value=coefmpc(index1)*coefmpc(index2)* & s(jj,ll)/coefmpc(ist1)/coefmpc(ist2) if(idof1.eq.idof2) value=2.d0*value if((idof1.ne.0).and.(idof2.ne.0)) then if(stiffonly(2)) then call add_sm_st(au,ad,jq,irow, & idof1,idof2,value,i0,i0) else valu2=coefmpc(index1)*coefmpc(index2)* & sm(jj,ll)/coefmpc(ist1)/coefmpc(ist2) ! if(idof1.eq.idof2) valu2=2.d0*valu2 ! call add_sm_ei(au,ad,aub,adb,jq, & irow,idof1,idof2,value,valu2,i0,i0) endif endif ! index2=nodempc(3,index2) if(index2.eq.0) exit enddo index1=nodempc(3,index1) if(index1.eq.0) exit enddo endif endif endif enddo ! if(rhsi) then ! ! distributed forces ! if(idist.ne.0) then if(jdof1.eq.0) then if(nmpc.ne.0) then idof1=(node1-1)*8 call nident(ikmpc,idof1,nmpc,id) if((id.gt.0).and.(ikmpc(id).eq.idof1)) then id=ilmpc(id) ist=ipompc(id) index=nodempc(3,ist) if(index.eq.0) cycle do jdof1=nactdof(nodempc(2,index), & nodempc(1,index)) if(jdof1.ne.0) then fext(jdof1)=fext(jdof1) & -coefmpc(index)*ff(jj) & /coefmpc(ist) endif index=nodempc(3,index) if(index.eq.0) exit enddo endif endif cycle endif fext(jdof1)=fext(jdof1)+ff(jj) endif endif ! enddo enddo ! endif ! return end
gpl-2.0
epfl-cosmo/q-e
PHonon/PH/dvqpsi_us.f90
7
6447
! ! Copyright (C) 2001-2016 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !---------------------------------------------------------------------- subroutine dvqpsi_us (ik, uact, addnlcc) !---------------------------------------------------------------------- ! ! This routine calculates dV_bare/dtau * psi for one perturbation ! with a given q. The displacements are described by a vector u. ! The result is stored in dvpsi. The routine is called for each k point ! and for each pattern u. It computes simultaneously all the bands. ! It implements Eq. B29 of PRB 64, 235118 (2001). The contribution ! of the local pseudopotential is calculated here, that of the nonlocal ! pseudopotential in dvqpsi_us_only. ! ! USE kinds, only : DP USE ions_base, ONLY : nat, ityp USE cell_base, ONLY : tpiba USE fft_base, ONLY : dfftp, dffts USE fft_interfaces, ONLY: fwfft, invfft USE gvect, ONLY : eigts1, eigts2, eigts3, mill, g, nl, & ngm USE gvecs, ONLY : ngms, doublegrid, nls USE lsda_mod, ONLY : lsda, isk USE noncollin_module, ONLY : npol use uspp_param,ONLY : upf USE wvfct, ONLY : nbnd, npwx USE wavefunctions_module, ONLY: evc USE nlcc_ph, ONLY : drc USE uspp, ONLY : nlcc_any USE eqv, ONLY : dvpsi, dmuxc, vlocq USE qpoint, ONLY : xq, eigqts, ikqs, ikks USE klist, ONLY : ngk, igk_k implicit none ! ! The dummy variables ! integer, intent(in) :: ik ! input: the k point complex(DP) :: uact (3 * nat) ! input: the pattern of displacements logical :: addnlcc ! ! And the local variables ! integer :: npw, npwq, na, mu, ikq, ikk, iks, ig, nt, ibnd, ir, is, ip ! counter on atoms ! counter on modes ! the point k ! counter on G vectors ! the type of atom ! counter on bands ! counter on real mesh complex(DP) :: gtau, gu, fact, u1, u2, u3, gu0 complex(DP) , allocatable, target :: aux (:) complex(DP) , allocatable :: aux1 (:), aux2 (:) complex(DP) , pointer :: auxs (:) call start_clock ('dvqpsi_us') if (nlcc_any.and.addnlcc) then allocate (aux( dfftp%nnr)) if (doublegrid) then allocate (auxs(dffts%nnr)) else auxs => aux endif endif allocate (aux1(dffts%nnr)) allocate (aux2(dffts%nnr)) ! ! We start by computing the contribution of the local potential. ! The computation of the derivative of the local potential is done in ! reciprocal space while the product with the wavefunction is done in ! real space ! dvpsi(:,:) = (0.d0, 0.d0) aux1(:) = (0.d0, 0.d0) do na = 1, nat fact = tpiba * (0.d0, -1.d0) * eigqts (na) mu = 3 * (na - 1) if (abs (uact (mu + 1) ) + abs (uact (mu + 2) ) + abs (uact (mu + & 3) ) .gt.1.0d-12) then nt = ityp (na) u1 = uact (mu + 1) u2 = uact (mu + 2) u3 = uact (mu + 3) gu0 = xq (1) * u1 + xq (2) * u2 + xq (3) * u3 do ig = 1, ngms gtau = eigts1 (mill(1,ig), na) * eigts2 (mill(2,ig), na) * & eigts3 (mill(3,ig), na) gu = gu0 + g (1, ig) * u1 + g (2, ig) * u2 + g (3, ig) * u3 aux1 (nls (ig) ) = aux1 (nls (ig) ) + vlocq (ig, nt) * gu * & fact * gtau enddo endif enddo ! ! add NLCC when present ! if (nlcc_any.and.addnlcc) then aux(:) = (0.d0, 0.d0) do na = 1,nat fact = tpiba*(0.d0,-1.d0)*eigqts(na) mu = 3*(na-1) if (abs(uact(mu+1))+abs(uact(mu+2)) & +abs(uact(mu+3)).gt.1.0d-12) then nt=ityp(na) u1 = uact(mu+1) u2 = uact(mu+2) u3 = uact(mu+3) gu0 = xq(1)*u1 +xq(2)*u2+xq(3)*u3 if (upf(nt)%nlcc) then do ig = 1,ngm gtau = eigts1(mill(1,ig),na)* & eigts2(mill(2,ig),na)* & eigts3(mill(3,ig),na) gu = gu0+g(1,ig)*u1+g(2,ig)*u2+g(3,ig)*u3 aux(nl(ig))=aux(nl(ig))+drc(ig,nt)*gu*fact*gtau enddo endif endif enddo CALL invfft ('Dense', aux, dfftp) if (.not.lsda) then do ir=1,dfftp%nnr aux(ir) = aux(ir) * dmuxc(ir,1,1) end do else is=isk(ikk) do ir=1,dfftp%nnr aux(ir) = aux(ir) * 0.5d0 * & (dmuxc(ir,is,1)+dmuxc(ir,is,2)) enddo endif CALL fwfft ('Dense', aux, dfftp) if (doublegrid) then auxs(:) = (0.d0, 0.d0) do ig=1,ngms auxs(nls(ig)) = aux(nl(ig)) enddo endif aux1(:) = aux1(:) + auxs(:) endif ! ! Now we compute dV_loc/dtau in real space ! ikk = ikks(ik) ikq = ikqs(ik) npw = ngk(ikk) npwq= ngk(ikq) CALL invfft ('Smooth', aux1, dffts) do ibnd = 1, nbnd do ip=1,npol aux2(:) = (0.d0, 0.d0) if (ip==1) then do ig = 1, npw aux2 (nls (igk_k (ig,ikk) ) ) = evc (ig, ibnd) enddo else do ig = 1, npw aux2 (nls (igk_k (ig,ikk) ) ) = evc (ig+npwx, ibnd) enddo end if ! ! This wavefunction is computed in real space ! CALL invfft ('Wave', aux2, dffts) do ir = 1, dffts%nnr aux2 (ir) = aux2 (ir) * aux1 (ir) enddo ! ! and finally dV_loc/dtau * psi is transformed in reciprocal space ! CALL fwfft ('Wave', aux2, dffts) if (ip==1) then do ig = 1, npwq dvpsi (ig, ibnd) = aux2 (nls (igk_k (ig,ikq) ) ) enddo else do ig = 1, npwq dvpsi (ig+npwx, ibnd) = aux2 (nls (igk_k (ig,ikq) ) ) enddo end if enddo enddo ! deallocate (aux2) deallocate (aux1) if (nlcc_any.and.addnlcc) then deallocate (aux) if (doublegrid) deallocate (auxs) endif ! ! We add the contribution of the nonlocal potential in the US form ! First a term similar to the KB case. ! Then a term due to the change of the D coefficients. ! call dvqpsi_us_only (ik, uact) call stop_clock ('dvqpsi_us') return end subroutine dvqpsi_us
gpl-2.0
prool/ccx_prool
CalculiX/ccx_2.10/src/dfluxs.f
4
9170
! ! CalculiX - A 3-dimensional finite element program ! Copyright (C) 1998-2015 Guido Dhondt ! ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License as ! published by the Free Software Foundation(version 2); ! ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! subroutine dfluxs(inpc,textpart,set,istartset,iendset, & ialset,nset,nelemload,sideload,xload,nload,nload_, & ielmat,ntmat_,iamload, & amname,nam,lakon,ne,dflux_flag,istep,istat,n,iline,ipol,inl, & ipoinp,inp,nam_,namtot_,namta,amta,ipoinpc,mi,idefload) ! ! reading the input deck: *DFLUX ! implicit none ! logical dflux_flag ! character*1 inpc(*) character*8 lakon(*) character*20 sideload(*),label character*80 amname(*),amplitude character*81 set(*),elset character*132 textpart(16) ! integer istartset(*),iendset(*),ialset(*),nelemload(2,*),mi(*), & ielmat(mi(3),*),nset,nload,nload_,ntmat_,istep,istat,n,i,j,l, & key,idefload(*), & iamload(2,*),nam,iamplitude,ipos,ne,iline,ipol,inl,ipoinp(2,*), & inp(3,*),nam_,namtot,namtot_,namta(3,*),idelay,isector, & ipoinpc(0:*) ! real*8 xload(2,*),xmagnitude,amta(2,*) ! iamplitude=0 idelay=0 isector=0 ! if(istep.lt.1) then write(*,*) '*ERROR in dfluxes: *DFLUX should only be used' write(*,*) ' within a STEP' call exit(201) endif ! do i=2,n if((textpart(i)(1:6).eq.'OP=NEW').and.(.not.dflux_flag)) then do j=1,nload if((sideload(j)(1:1).eq.'S').or. & (sideload(j)(1:2).eq.'BF')) then xload(1,j)=0.d0 endif enddo elseif(textpart(i)(1:10).eq.'AMPLITUDE=') then read(textpart(i)(11:90),'(a80)') amplitude do j=nam,1,-1 if(amname(j).eq.amplitude) then iamplitude=j exit endif enddo if(j.eq.0) then write(*,*)'*ERROR in dfluxes: nonexistent amplitude' write(*,*) ' ' call inputerror(inpc,ipoinpc,iline, &"*DFLUX%") call exit(201) endif iamplitude=j elseif(textpart(i)(1:10).eq.'TIMEDELAY=') THEN if(idelay.ne.0) then write(*,*) '*ERROR in dfluxes: the parameter TIME DELAY' write(*,*) ' is used twice in the same keyword' write(*,*) ' ' call inputerror(inpc,ipoinpc,iline, &"*DFLUX%") call exit(201) else idelay=1 endif nam=nam+1 if(nam.gt.nam_) then write(*,*) '*ERROR in dfluxes: increase nam_' call exit(201) endif amname(nam)=' & ' if(iamplitude.eq.0) then write(*,*) '*ERROR in dfluxes: time delay must be' write(*,*) ' preceded by the amplitude parameter' call exit(201) endif namta(3,nam)=sign(iamplitude,namta(3,iamplitude)) iamplitude=nam if(nam.eq.1) then namtot=0 else namtot=namta(2,nam-1) endif namtot=namtot+1 if(namtot.gt.namtot_) then write(*,*) '*ERROR dfluxes: increase namtot_' call exit(201) endif namta(1,nam)=namtot namta(2,nam)=namtot read(textpart(i)(11:30),'(f20.0)',iostat=istat) & amta(1,namtot) if(istat.gt.0) call inputerror(inpc,ipoinpc,iline, &"*DFLUX%") else write(*,*) & '*WARNING in dfluxes: parameter not recognized:' write(*,*) ' ', & textpart(i)(1:index(textpart(i),' ')-1) call inputwarning(inpc,ipoinpc,iline, &"*DFLUX%") endif enddo ! do call getnewline(inpc,textpart,istat,n,key,iline,ipol,inl, & ipoinp,inp,ipoinpc) if((istat.lt.0).or.(key.eq.1)) return ! read(textpart(2)(1:20),'(a20)',iostat=istat) label ! ! compatibility with ABAQUS for shells ! if(label(2:4).eq.'NEG') label(2:4)='1 ' if(label(2:4).eq.'POS') label(2:4)='2 ' if(label(2:2).eq.'N') label(2:2)='5' if(label(2:2).eq.'P') label(2:2)='6' ! read(textpart(3)(1:20),'(f20.0)',iostat=istat) xmagnitude ! if(istat.gt.0) call inputerror(inpc,ipoinpc,iline, &"*DFLUX%") if(((label(1:2).ne.'S1').and.(label(1:2).ne.'S2').and. & (label(1:2).ne.'S3').and.(label(1:2).ne.'S4').and. & (label(1:2).ne.'S5').and.(label(1:2).ne.'S6').and. & (label(1:2).ne.'BF').and.(label(1:2).ne.'S ')).or. & ((label(3:4).ne.' ').and.(label(3:4).ne.'NU'))) then call inputerror(inpc,ipoinpc,iline, &"*DFLUX%") endif ! read(textpart(1)(1:10),'(i10)',iostat=istat) l if(istat.eq.0) then if(l.gt.ne) then write(*,*) '*ERROR in dfluxes: element ',l write(*,*) ' is not defined' call exit(201) endif ! if((lakon(l)(1:2).eq.'CP').or. & (lakon(l)(2:2).eq.'A').or. & (lakon(l)(7:7).eq.'E').or. & (lakon(l)(7:7).eq.'S').or. & (lakon(l)(7:7).eq.'A')) then if(label(1:2).eq.'S1') then label(1:2)='S3' elseif(label(1:2).eq.'S2') then label(1:2)='S4' elseif(label(1:2).eq.'S3') then label(1:2)='S5' elseif(label(1:2).eq.'S4') then label(1:2)='S6' elseif(label(1:2).eq.'S5') then label(1:2)='S1' elseif(label(1:2).eq.'S6') then label(1:2)='S2' endif elseif((lakon(l)(1:1).eq.'B').or. & (lakon(l)(7:7).eq.'B')) then elseif((lakon(l)(1:1).eq.'S').or. & (lakon(l)(7:7).eq.'L')) then endif call loadadd(l,label,xmagnitude,nelemload,sideload, & xload,nload,nload_,iamload,iamplitude, & nam,isector,idefload) else read(textpart(1)(1:80),'(a80)',iostat=istat) elset elset(81:81)=' ' ipos=index(elset,' ') elset(ipos:ipos)='E' do i=1,nset if(set(i).eq.elset) exit enddo if(i.gt.nset) then elset(ipos:ipos)=' ' write(*,*) '*ERROR in dfluxes: element set ',elset write(*,*) ' has not yet been defined. ' call inputerror(inpc,ipoinpc,iline, &"*DFLUX%") call exit(201) endif ! l=ialset(istartset(i)) if((lakon(l)(1:2).eq.'CP').or. & (lakon(l)(2:2).eq.'A').or. & (lakon(l)(7:7).eq.'E').or. & (lakon(l)(7:7).eq.'S').or. & (lakon(l)(7:7).eq.'A')) then if(label(1:2).eq.'S1') then label(1:2)='S3' elseif(label(1:2).eq.'S2') then label(1:2)='S4' elseif(label(1:2).eq.'S3') then label(1:2)='S5' elseif(label(1:2).eq.'S4') then label(1:2)='S6' endif elseif((lakon(l)(1:1).eq.'B').or. & (lakon(l)(7:7).eq.'B')) then if(label(1:2).eq.'S2') label(1:2)='S5' elseif((lakon(l)(1:1).eq.'S').or. & (lakon(l)(7:7).eq.'L')) then label(1:2)='S1' endif ! do j=istartset(i),iendset(i) if(ialset(j).gt.0) then l=ialset(j) call loadadd(l,label,xmagnitude,nelemload,sideload, & xload,nload,nload_,iamload,iamplitude, & nam,isector,idefload) else l=ialset(j-2) do l=l-ialset(j) if(l.ge.ialset(j-1)) exit call loadadd(l,label,xmagnitude,nelemload, & sideload,xload,nload,nload_, & iamload,iamplitude,nam,isector,idefload) enddo endif enddo endif enddo ! return end
gpl-2.0