CP2K 2.4 (Revision 12889)

qs_scf_types.f90

Go to the documentation of this file.
00001 !-----------------------------------------------------------------------------!
00002 !   CP2K: A general program to perform molecular dynamics simulations         !
00003 !   Copyright (C) 2000 - 2013  CP2K developers group                          !
00004 !-----------------------------------------------------------------------------!
00005 
00006 ! *****************************************************************************
00012 MODULE qs_scf_types
00013   USE cp_dbcsr_operations,             ONLY: cp_dbcsr_deallocate_matrix_set
00014   USE cp_dbcsr_types,                  ONLY: cp_dbcsr_p_type
00015   USE cp_fm_types,                     ONLY: cp_fm_p_type,&
00016                                              cp_fm_release,&
00017                                              cp_fm_type
00018   USE cp_fm_vect,                      ONLY: cp_fm_vect_dealloc
00019   USE f77_blas
00020   USE input_section_types,             ONLY: section_vals_get_subs_vals,&
00021                                              section_vals_type,&
00022                                              section_vals_val_get
00023   USE kinds,                           ONLY: dp
00024   USE preconditioner_types,            ONLY: destroy_preconditioner,&
00025                                              preconditioner_p_type
00026   USE qs_block_davidson_types,         ONLY: block_davidson_release,&
00027                                              davidson_type
00028   USE qs_density_mixing_types,         ONLY: direct_mixing_nr,&
00029                                              mixing_storage_create,&
00030                                              mixing_storage_release,&
00031                                              mixing_storage_type
00032   USE qs_diis_types,                   ONLY: qs_diis_b_release,&
00033                                              qs_diis_buffer_type
00034   USE qs_ot_types,                     ONLY: qs_ot_destroy,&
00035                                              qs_ot_type
00036   USE timings,                         ONLY: timeset,&
00037                                              timestop
00038 #include "cp_common_uses.h"
00039 
00040   IMPLICIT NONE
00041   PRIVATE
00042 
00043   LOGICAL, PRIVATE, PARAMETER :: debug_this_module=.TRUE.
00044 
00045   CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_scf_types'
00046 
00047   INTEGER, PARAMETER, PUBLIC :: 
00048                                 general_diag_method_nr=1,
00049                                 special_diag_method_nr=2,
00050                                 ot_diag_method_nr=3,
00051                                 block_krylov_diag_method_nr=4,
00052                                 block_davidson_diag_method_nr=5,
00053                                 ot_method_nr=10
00054 
00055   INTEGER, SAVE, PRIVATE :: last_scf_env_id=0
00056 
00057   PUBLIC :: qs_scf_env_type,qs_outer_scf_type
00058   PUBLIC :: scf_env_retain, scf_env_release, scf_env_create, scf_env_did_change
00059   PUBLIC :: krylov_space_type, krylov_space_create, subspace_env_type
00060   PUBLIC :: diag_subspace_env_create
00061 
00062 ! *****************************************************************************
00068   TYPE qs_outer_scf_type
00069     INTEGER :: iter_count
00070 
00071     ! these are the variable of outer loop.
00072     ! right now, we assume that they can be easily written as
00073     ! small arrays, but we might want to go the cp_fm_types
00074     ! at a later stage
00075     ! also, we just store the full iteration history
00076     REAL(KIND=dp), DIMENSION(:), POINTER :: energy
00077     REAL(KIND=dp), DIMENSION(:,:), POINTER :: variables
00078     REAL(KIND=dp), DIMENSION(:,:), POINTER :: gradient
00079     INTEGER, DIMENSION(:), POINTER :: count
00080 
00081   END TYPE qs_outer_scf_type
00082 
00083   TYPE krylov_space_type
00084      INTEGER :: nkrylov, nblock, nmo_conv, nmo_nc, max_iter
00085      LOGICAL :: always_check_conv
00086      REAL(dp) :: eps_std_diag, eps_conv, eps_adapt, max_res_norm, min_res_norm
00087      REAL(dp), DIMENSION(:), POINTER :: c_eval, t_eval
00088      TYPE(cp_fm_p_type), DIMENSION(:), POINTER :: v_mat, mo_conv, mo_refine
00089      TYPE(cp_fm_type),  POINTER ::  tmp_mat
00090 !NOTE: the following matrices are small and could be used as standard array rather than distributed fm
00091      TYPE(cp_fm_type),  POINTER :: block1_mat, block2_mat, block3_mat, block4_mat, block5_mat
00092      TYPE(cp_fm_p_type), DIMENSION(:), POINTER ::  c_vec, chc_mat
00093   END TYPE
00094 
00095   TYPE subspace_env_type
00096       INTEGER :: max_iter, mixing_method
00097       REAL(dp) :: eps_diag_sub, eps_ene, eps_adapt
00098       TYPE(cp_dbcsr_p_type), DIMENSION(:), POINTER :: p_matrix_store,p_matrix_mix
00099       TYPE(cp_fm_p_type), DIMENSION(:), POINTER :: chc_mat, c_vec, c0
00100       TYPE(mixing_storage_type), POINTER :: mixing_store
00101   END TYPE
00102 
00103 
00104 
00105 ! *****************************************************************************
00106 TYPE qs_scf_env_type
00107    TYPE(qs_outer_scf_type) :: outer_scf
00108    INTEGER :: ref_count, id_nr, print_count, iter_count
00109    INTEGER :: cholesky_method, nelectron, method, mixing_method, nskip_mixing
00110    REAL(KIND = dp) :: iter_param, iter_delta, p_mix_alpha
00111    CHARACTER (len=15) :: iter_method
00112    COMPLEX(KIND=dp), DIMENSION(:,:,:), POINTER :: cc_buffer
00113    LOGICAL :: do_diag_sub, print_iter_line, skip_mixing, skip_diis
00114    TYPE(mixing_storage_type), POINTER :: mixing_store
00115    TYPE(cp_fm_p_type), DIMENSION(:), POINTER :: scf_work1
00116    TYPE(cp_fm_type), POINTER  :: scf_work2, ortho, ortho_m1, s_half, s_minus_one
00117    TYPE(krylov_space_type), POINTER :: krylov_space
00118    TYPE(cp_dbcsr_p_type), DIMENSION(:), POINTER :: p_delta, p_mix_new
00119    TYPE(preconditioner_p_type), DIMENSION(:), POINTER :: ot_preconditioner
00120    TYPE(qs_ot_type), POINTER, DIMENSION(:)  :: qs_ot_env
00121    TYPE(qs_diis_buffer_type), POINTER :: scf_diis_buffer
00122    TYPE(subspace_env_type), POINTER :: subspace_env
00123    TYPE(davidson_type), POINTER, DIMENSION(:) :: block_davidson_env
00124 END TYPE qs_scf_env_type
00125 
00126 CONTAINS
00127 
00128 ! *****************************************************************************
00137   SUBROUTINE scf_env_create(scf_env,  error)
00138     TYPE(qs_scf_env_type), POINTER           :: scf_env
00139     TYPE(cp_error_type), INTENT(inout)       :: error
00140 
00141     CHARACTER(len=*), PARAMETER :: routineN = 'scf_env_create', 
00142       routineP = moduleN//':'//routineN
00143 
00144     INTEGER                                  :: handle, stat
00145     LOGICAL                                  :: failure
00146 
00147     CALL timeset(routineN,handle)
00148 
00149     failure=.FALSE.
00150 
00151     ALLOCATE(scf_env, stat=stat)
00152     CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00153     IF (.NOT.failure) THEN
00154 
00155        scf_env%ref_count=1
00156        scf_env%print_count=0
00157        last_scf_env_id=last_scf_env_id+1
00158        scf_env%id_nr=last_scf_env_id
00159        scf_env%print_count=0
00160        scf_env%iter_count=0
00161        scf_env%nelectron=0
00162        scf_env%iter_param=0.0_dp
00163        scf_env%iter_delta=0.0_dp
00164        scf_env%iter_method=""
00165        scf_env%print_iter_line=.TRUE.
00166        scf_env%skip_mixing=.FALSE.
00167        scf_env%skip_diis=.FALSE.
00168        scf_env%do_diag_sub=.FALSE.
00169 
00170        scf_env%method= -1
00171        scf_env%mixing_method = -1
00172        scf_env%p_mix_alpha=1.0_dp
00173        scf_env%cholesky_method = -1
00174 
00175        scf_env%outer_scf%iter_count=0
00176        NULLIFY(scf_env%outer_scf%variables, &
00177             scf_env%outer_scf%gradient,scf_env%outer_scf%energy,scf_env%outer_scf%count)
00178 
00179        NULLIFY(scf_env%scf_work1, scf_env%scf_work2, scf_env%ortho, scf_env%ortho_m1,&
00180             scf_env%p_mix_new, scf_env%ot_preconditioner, scf_env%qs_ot_env,&
00181             scf_env%scf_diis_buffer)
00182        NULLIFY (scf_env%s_half, scf_env%p_delta,  scf_env%s_minus_one)
00183        NULLIFY(scf_env%cc_buffer)
00184        NULLIFY(scf_env%mixing_store)
00185        NULLIFY(scf_env%krylov_space)
00186        NULLIFY(scf_env%subspace_env)
00187        NULLIFY(scf_env%block_davidson_env)
00188 
00189     END IF
00190 
00191     CALL timestop(handle)
00192 
00193   END SUBROUTINE scf_env_create
00194 
00195 ! *****************************************************************************
00204   SUBROUTINE scf_env_retain(scf_env,error)
00205     TYPE(qs_scf_env_type), POINTER           :: scf_env
00206     TYPE(cp_error_type), INTENT(inout)       :: error
00207 
00208     CHARACTER(len=*), PARAMETER :: routineN = 'scf_env_retain', 
00209       routineP = moduleN//':'//routineN
00210 
00211     LOGICAL                                  :: failure
00212 
00213   failure=.FALSE.
00214 
00215   CPPrecondition(ASSOCIATED(scf_env),cp_failure_level,routineP,error,failure)
00216   IF (.NOT. failure) THEN
00217      CPPrecondition(scf_env%ref_count>0,cp_failure_level,routineP,error,failure)
00218      scf_env%ref_count=scf_env%ref_count+1
00219   END IF
00220   END SUBROUTINE scf_env_retain
00221 
00222 ! *****************************************************************************
00231   SUBROUTINE scf_env_did_change(scf_env,error)
00232     TYPE(qs_scf_env_type), POINTER           :: scf_env
00233     TYPE(cp_error_type), INTENT(inout)       :: error
00234 
00235     CHARACTER(len=*), PARAMETER :: routineN = 'scf_env_did_change', 
00236       routineP = moduleN//':'//routineN
00237 
00238     INTEGER                                  :: handle
00239     LOGICAL                                  :: failure
00240 
00241     CALL timeset(routineN,handle)
00242 
00243     failure=.FALSE.
00244 
00245   CPPrecondition(ASSOCIATED(scf_env),cp_failure_level,routineP,error,failure)
00246   CPPrecondition(scf_env%ref_count>0,cp_failure_level,routineP,error,failure)
00247   IF (.NOT.failure) THEN
00248      IF (ASSOCIATED(scf_env%p_mix_new)) THEN
00249         CALL cp_dbcsr_deallocate_matrix_set(scf_env%p_mix_new,error=error)
00250      END IF
00251      IF (ASSOCIATED(scf_env%p_delta)) THEN
00252         CALL cp_dbcsr_deallocate_matrix_set(scf_env%p_delta,error=error)
00253      END IF
00254   END IF
00255 
00256     CALL timestop(handle)
00257 
00258   END SUBROUTINE scf_env_did_change
00259 
00260 ! *****************************************************************************
00269   SUBROUTINE scf_env_release(scf_env,error)
00270     TYPE(qs_scf_env_type), POINTER           :: scf_env
00271     TYPE(cp_error_type), INTENT(inout)       :: error
00272 
00273     CHARACTER(len=*), PARAMETER :: routineN = 'scf_env_release', 
00274       routineP = moduleN//':'//routineN
00275 
00276     INTEGER                                  :: i, stat
00277     LOGICAL                                  :: failure
00278 
00279     failure=.FALSE.
00280 
00281     IF (ASSOCIATED(scf_env)) THEN
00282      CPPreconditionNoFail(scf_env%ref_count>0,cp_failure_level,routineP,error)
00283      scf_env%ref_count=scf_env%ref_count-1
00284      IF (scf_env%ref_count==0) THEN
00285         CALL cp_fm_vect_dealloc(scf_env%scf_work1,error=error)
00286         CALL cp_fm_release(scf_env%scf_work2,error=error)
00287         CALL cp_fm_release(scf_env%ortho,error=error)
00288         CALL cp_fm_release(scf_env%ortho_m1,error=error)
00289         CALL cp_fm_release(scf_env%s_half,error=error)
00290         CALL cp_fm_release(scf_env%s_minus_one,error=error)
00291         IF (ASSOCIATED(scf_env%p_mix_new)) THEN
00292            CPPreconditionNoFail(.TRUE.,cp_failure_level,routineP,error) ! we should not end up here, and give back using the pools
00293            CALL cp_dbcsr_deallocate_matrix_set(scf_env%p_mix_new,error=error)
00294         ENDIF
00295         IF (ASSOCIATED(scf_env%p_delta)) THEN
00296            CPPreconditionNoFail(.TRUE.,cp_failure_level,routineP,error) ! we should not end up here, and give back using the pools
00297            CALL cp_dbcsr_deallocate_matrix_set(scf_env%p_delta,error=error)
00298         ENDIF
00299         IF (ASSOCIATED(scf_env%ot_preconditioner)) THEN
00300            DO i=1,SIZE(scf_env%ot_preconditioner)
00301               CALL destroy_preconditioner(scf_env%ot_preconditioner(i)%preconditioner,error=error)
00302               DEALLOCATE(scf_env%ot_preconditioner(i)%preconditioner)
00303            ENDDO
00304            DEALLOCATE(scf_env%ot_preconditioner,stat=stat)
00305            CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00306         END IF
00307         IF (ASSOCIATED(scf_env%qs_ot_env)) THEN
00308            DO i=1,SIZE(scf_env%qs_ot_env)
00309               CALL qs_ot_destroy(scf_env%qs_ot_env(i),error=error)
00310            END DO
00311            DEALLOCATE(scf_env%qs_ot_env, stat=stat)
00312            CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00313         END IF
00314         CALL qs_diis_b_release(scf_env%scf_diis_buffer,error=error)
00315 
00316         IF (ASSOCIATED(scf_env%outer_scf%variables)) THEN
00317            DEALLOCATE(scf_env%outer_scf%variables,stat=stat)
00318            CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00319         ENDIF
00320         IF (ASSOCIATED(scf_env%outer_scf%count)) THEN
00321            DEALLOCATE(scf_env%outer_scf%count,stat=stat)
00322            CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00323         ENDIF
00324         IF (ASSOCIATED(scf_env%outer_scf%gradient)) THEN
00325            DEALLOCATE(scf_env%outer_scf%gradient,stat=stat)
00326            CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00327         ENDIF
00328         IF (ASSOCIATED(scf_env%outer_scf%energy)) THEN
00329            DEALLOCATE(scf_env%outer_scf%energy,stat=stat)
00330            CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00331         ENDIF
00332 
00333         IF (ASSOCIATED(scf_env%cc_buffer)) THEN
00334            DEALLOCATE(scf_env%cc_buffer,stat=stat)
00335            CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00336         ENDIF
00337 
00338         IF (ASSOCIATED(scf_env%mixing_store)) THEN
00339            CALL mixing_storage_release(scf_env%mixing_store,error=error)
00340         END IF
00341 
00342         IF (ASSOCIATED(scf_env%krylov_space)) THEN
00343            CALL krylov_space_release(scf_env%krylov_space,error=error)
00344         END IF
00345 
00346         IF (ASSOCIATED(scf_env%subspace_env)) THEN
00347            CALL diag_subspace_env_release(scf_env%subspace_env,error=error)
00348         END IF
00349 
00350         IF (ASSOCIATED(scf_env%block_davidson_env)) THEN
00351            CALL block_davidson_release(scf_env%block_davidson_env,error=error)
00352         END IF
00353 
00354         DEALLOCATE(scf_env, stat=stat)
00355         CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00356      END IF
00357     END IF
00358     NULLIFY(scf_env)
00359 
00360   END SUBROUTINE scf_env_release
00361 
00362 ! *****************************************************************************
00368  SUBROUTINE krylov_space_create(krylov_space,scf_section, error)
00369 
00370     TYPE(krylov_space_type), POINTER         :: krylov_space
00371     TYPE(section_vals_type), POINTER         :: scf_section
00372     TYPE(cp_error_type), INTENT(inout)       :: error
00373 
00374     CHARACTER(len=*), PARAMETER :: routineN = 'krylov_space_create', 
00375       routineP = moduleN//':'//routineN
00376 
00377     INTEGER                                  :: stat
00378     LOGICAL                                  :: failure
00379 
00380     failure=.FALSE.
00381 
00382     CPPrecondition(.NOT.ASSOCIATED(krylov_space),cp_failure_level,routineP,error,failure)
00383     IF(.NOT. failure) THEN
00384       ALLOCATE(krylov_space, stat=stat)
00385       CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00386       IF (.NOT.failure) THEN
00387 
00388 
00389         NULLIFY(krylov_space%c_eval,krylov_space%t_eval)
00390         NULLIFY(krylov_space%v_mat)
00391         NULLIFY(krylov_space%mo_conv, krylov_space%mo_refine)
00392         NULLIFY(krylov_space%chc_mat, krylov_space%c_vec)
00393         NULLIFY(krylov_space%tmp_mat)
00394         NULLIFY(krylov_space%block1_mat, krylov_space%block2_mat)
00395         NULLIFY(krylov_space%block3_mat, krylov_space%block4_mat, krylov_space%block5_mat)
00396 
00397         CALL section_vals_val_get(scf_section,"DIAGONALIZATION%MAX_ITER",&
00398              i_val=krylov_space%max_iter,error=error)
00399         CALL section_vals_val_get(scf_section,"DIAGONALIZATION%KRYLOV%NKRYLOV",&
00400              i_val=krylov_space%nkrylov,error=error)
00401         CALL section_vals_val_get(scf_section,"DIAGONALIZATION%KRYLOV%NBLOCK",&
00402              i_val=krylov_space%nblock,error=error)
00403         CALL section_vals_val_get(scf_section,"DIAGONALIZATION%KRYLOV%EPS_KRYLOV",&
00404              r_val=krylov_space%eps_conv,error=error)
00405         CALL section_vals_val_get(scf_section,"DIAGONALIZATION%KRYLOV%EPS_STD_DIAG",&
00406              r_val=krylov_space%eps_std_diag,error=error)
00407         CALL section_vals_val_get(scf_section,"DIAGONALIZATION%EPS_ADAPT",&
00408              r_val=krylov_space%eps_adapt,error=error)
00409         CALL section_vals_val_get(scf_section,"DIAGONALIZATION%KRYLOV%CHECK_MOS_CONV",&
00410              l_val=krylov_space%always_check_conv,error=error)
00411       END IF
00412     END IF
00413 
00414  END SUBROUTINE krylov_space_create
00415 
00416 ! *****************************************************************************
00422  SUBROUTINE krylov_space_release(krylov_space,error)
00423     TYPE(krylov_space_type), POINTER         :: krylov_space
00424     TYPE(cp_error_type), INTENT(inout)       :: error
00425 
00426     CHARACTER(len=*), PARAMETER :: routineN = 'krylov_space_release', 
00427       routineP = moduleN//':'//routineN
00428 
00429     INTEGER                                  :: i, stat
00430     LOGICAL                                  :: failure
00431 
00432     failure = .FALSE.
00433 
00434     IF(ASSOCIATED(krylov_space)) THEN
00435 
00436         DEALLOCATE(krylov_space%c_eval,STAT=stat)
00437       CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00438         DEALLOCATE(krylov_space%t_eval,STAT=stat)
00439       CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00440 
00441         DO i = 1,SIZE(krylov_space%v_mat)
00442           CALL cp_fm_release(krylov_space%v_mat(i)%matrix,error=error)
00443         END DO
00444         DEALLOCATE(krylov_space%v_mat,STAT=stat)
00445       CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00446 
00447         DO i = 1,SIZE(krylov_space%mo_conv)
00448           CALL cp_fm_release(krylov_space%mo_conv(i)%matrix,error=error)
00449         END DO
00450         DEALLOCATE(krylov_space%mo_conv,STAT=stat)
00451       CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00452 
00453         DO i = 1,SIZE(krylov_space%mo_refine)
00454           CALL cp_fm_release(krylov_space%mo_refine(i)%matrix,error=error)
00455         END DO
00456         DEALLOCATE(krylov_space%mo_refine,STAT=stat)
00457       CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00458 
00459         DO i = 1,SIZE(krylov_space%chc_mat)
00460           CALL cp_fm_release(krylov_space%chc_mat(i)%matrix,error=error)
00461         END DO
00462         DEALLOCATE(krylov_space%chc_mat,STAT=stat)
00463         DO i = 1,SIZE(krylov_space%c_vec)
00464           CALL cp_fm_release(krylov_space%c_vec(i)%matrix,error=error)
00465         END DO
00466         DEALLOCATE(krylov_space%c_vec,STAT=stat)
00467         CALL cp_fm_release(krylov_space%tmp_mat,error=error)
00468         CALL cp_fm_release(krylov_space%block1_mat,error=error)
00469         CALL cp_fm_release(krylov_space%block2_mat,error=error)
00470         CALL cp_fm_release(krylov_space%block3_mat,error=error)
00471         CALL cp_fm_release(krylov_space%block4_mat,error=error)
00472         CALL cp_fm_release(krylov_space%block5_mat,error=error)
00473 
00474         DEALLOCATE(krylov_space,STAT=stat)
00475         CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00476 
00477       NULLIFY(krylov_space)
00478     END IF
00479 
00480  END SUBROUTINE krylov_space_release
00481 
00482 ! *****************************************************************************
00488  SUBROUTINE diag_subspace_env_create(subspace_env,scf_section,ecut,error)
00489 
00490     TYPE(subspace_env_type), POINTER         :: subspace_env
00491     TYPE(section_vals_type), POINTER         :: scf_section
00492     REAL(dp), INTENT(IN)                     :: ecut
00493     TYPE(cp_error_type), INTENT(inout)       :: error
00494 
00495     CHARACTER(len=*), PARAMETER :: routineN = 'diag_subspace_env_create', 
00496       routineP = moduleN//':'//routineN
00497 
00498     INTEGER                                  :: stat
00499     LOGICAL                                  :: do_mixing, failure
00500     TYPE(section_vals_type), POINTER         :: mixing_section
00501 
00502     failure = .FALSE.
00503 
00504     CPPrecondition(.NOT.ASSOCIATED(subspace_env),cp_failure_level,routineP,error,failure)
00505     IF(.NOT. failure) THEN
00506       ALLOCATE(subspace_env, stat=stat)
00507       CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00508       IF (.NOT.failure) THEN
00509 
00510 
00511         NULLIFY(subspace_env%p_matrix_store)
00512         NULLIFY(subspace_env%p_matrix_mix)
00513         NULLIFY(subspace_env%chc_mat)
00514         NULLIFY(subspace_env%c_vec)
00515         NULLIFY(subspace_env%c0)
00516         NULLIFY(subspace_env%mixing_store)
00517         NULLIFY(mixing_section)
00518 
00519         CALL section_vals_val_get(scf_section,"DIAGONALIZATION%DIAG_SUB_SCF%MAX_ITER",&
00520              i_val=subspace_env%max_iter,error=error)
00521         CALL section_vals_val_get(scf_section,"DIAGONALIZATION%DIAG_SUB_SCF%EPS_ENE",&
00522              r_val=subspace_env%eps_ene,error=error)
00523         CALL section_vals_val_get(scf_section,"DIAGONALIZATION%DIAG_SUB_SCF%EPS_SKIP_SUB_DIAG",&
00524              r_val=subspace_env%eps_diag_sub,error=error)
00525         CALL section_vals_val_get(scf_section,"DIAGONALIZATION%DIAG_SUB_SCF%EPS_ADAPT_SCF",&
00526              r_val=subspace_env%eps_adapt,error=error)
00527         subspace_env%mixing_method = 0
00528         do_mixing = .FALSE.
00529         mixing_section => section_vals_get_subs_vals(scf_section,"DIAGONALIZATION%DIAG_SUB_SCF%MIXING",error=error)
00530         CALL section_vals_val_get(mixing_section,"_SECTION_PARAMETERS_",&
00531                                  l_val=do_mixing,&
00532                                  error=error)
00533         IF (do_mixing) THEN
00534           CALL section_vals_val_get(mixing_section,"METHOD",&
00535                                     i_val=subspace_env%mixing_method,&
00536                                     error=error)
00537           IF(subspace_env%mixing_method>=direct_mixing_nr)&
00538              CALL mixing_storage_create(subspace_env%mixing_store, mixing_section, &
00539                   subspace_env%mixing_method, ecut=ecut, error=error)
00540         END IF
00541 
00542       END IF
00543     END IF
00544 
00545  END SUBROUTINE diag_subspace_env_create
00546 
00547 ! *****************************************************************************
00553  SUBROUTINE diag_subspace_env_release(subspace_env,error)
00554     TYPE(subspace_env_type), POINTER         :: subspace_env
00555     TYPE(cp_error_type), INTENT(inout)       :: error
00556 
00557     CHARACTER(len=*), PARAMETER :: routineN = 'diag_subspace_env_release', 
00558       routineP = moduleN//':'//routineN
00559 
00560     INTEGER                                  :: i, stat
00561     LOGICAL                                  :: failure
00562 
00563     failure = .FALSE.
00564 
00565     IF(ASSOCIATED(subspace_env)) THEN
00566 
00567        IF (ASSOCIATED(subspace_env%p_matrix_store)) THEN
00568 
00569            CPPreconditionNoFail(.TRUE.,cp_failure_level,routineP,error) ! should be given back using the pools
00570            CALL cp_dbcsr_deallocate_matrix_set(subspace_env%p_matrix_store,error=error)
00571        ENDIF
00572        DO i = 1,SIZE(subspace_env%chc_mat)
00573          CALL cp_fm_release(subspace_env%chc_mat(i)%matrix,error=error)
00574        END DO
00575        DEALLOCATE(subspace_env%chc_mat,STAT=stat)
00576        DO i = 1,SIZE(subspace_env%c_vec)
00577          CALL cp_fm_release(subspace_env%c_vec(i)%matrix,error=error)
00578        END DO
00579        DEALLOCATE(subspace_env%c_vec,STAT=stat)
00580        DO i = 1,SIZE(subspace_env%c0)
00581          CALL cp_fm_release(subspace_env%c0(i)%matrix,error=error)
00582        END DO
00583        DEALLOCATE(subspace_env%c0,STAT=stat)
00584 
00585         IF (ASSOCIATED(subspace_env%mixing_store)) THEN
00586            CALL mixing_storage_release(subspace_env%mixing_store,error=error)
00587         END IF
00588 
00589        DEALLOCATE(subspace_env, stat=stat)
00590        CPPostconditionNoFail(stat==0,cp_warning_level,routineP,error)
00591     END IF
00592 
00593  END SUBROUTINE diag_subspace_env_release
00594 
00595 END MODULE qs_scf_types