dealloc_global_rdm_data Subroutine

public subroutine dealloc_global_rdm_data()

Arguments

None

Contents


Source Code

    subroutine dealloc_global_rdm_data()

        ! This routine just deallocates the arrays allocated in InitRDMs.
        ! If the NECI calculation softexits before the RDMs start to fill,
        ! this is all that is called at the end.

        use CalcData, only: tEN2
        use FciMCData, only: Spawned_Parents, Spawned_Parents_Index
        use FciMCData, only: Spawned_ParentsTag, Spawned_Parents_IndexTag
        use FciMCData, only: AvNoatHF, IterRDM_HF
        use LoggingData, only: RDMExcitLevel, tExplicitAllRDM
        use rdm_data, only: two_rdm_main, two_rdm_recv, two_rdm_recv_2, two_rdm_spawn, en_pert_main
        use rdm_data, only: rdm_estimates, one_rdms, Sing_ExcDjs, Doub_ExcDjs
        use rdm_data, only: Sing_ExcDjs2, Doub_ExcDjs2, Sing_ExcDjsTag, Doub_ExcDjsTag
        use rdm_data, only: Sing_ExcDjs2Tag, Doub_ExcDjs2Tag
        use rdm_data, only: Sing_InitExcSlots, Doub_InitExcSlots, Sing_ExcList, Doub_ExcList
        use rdm_data_utils, only: dealloc_rdm_list_t, dealloc_rdm_spawn_t, dealloc_one_rdm_t
        use rdm_data_utils, only: dealloc_en_pert_t
        use rdm_estimators, only: dealloc_rdm_estimates_t
        use RotateOrbsData, only: SymLabelCounts2_rot, SymLabelList2_rot, SymLabelListInv_rot
        use RotateOrbsData, only: SymLabelCounts2_rotTag, SymLabelList2_rotTag
        use RotateOrbsData, only: SymLabelListInv_rotTag
        use RotateOrbsMod, only: FourIndInts, FourIndIntsTag

        character(len=*), parameter :: t_r = 'dealloc_global_rdm_data'

        integer :: irdm

        ! Deallocate global 2-RDM arrays, including the spawning object.
        call dealloc_rdm_list_t(two_rdm_main)
        call dealloc_rdm_list_t(two_rdm_recv)
        call dealloc_rdm_list_t(two_rdm_recv_2)
        call dealloc_rdm_spawn_t(two_rdm_spawn)
        ! deallocate the inits-only rdms
        if (tinitsRDM) then
            call dealloc_rdm_list_t(two_rdm_inits)
            call dealloc_rdm_spawn_t(two_rdm_inits_spawn)
        end if

        ! Deallocate the EN perturbation orbject.
        if (tEN2) then
            call dealloc_en_pert_t(en_pert_main)
        end if

        ! Deallocate the RDM estimates object.
        call dealloc_rdm_estimates_t(rdm_estimates)

        ! Deallocate all 1-RDM objects.
        if (allocated(one_rdms)) then
            do irdm = 1, size(one_rdms)
                call dealloc_one_rdm_t(one_rdms(irdm))
                if (tinitsRDM) call dealloc_one_rdm_t(inits_one_rdms(irdm))
            end do
            deallocate(one_rdms)
            if (tinitsRDM .and. allocated(inits_one_rdms)) deallocate(inits_one_rdms)
        end if

        if (tExplicitAllRDM) then
            ! This array contains the initial positions of the single
            ! excitations for each processor.
            deallocate(Sing_InitExcSlots)

            ! This array contains the current position of the single
            ! excitations as they're added.
            deallocate(Sing_ExcList)

            ! This array actually contains the single excitations in blocks of
            ! the processor they will be sent to.
            deallocate(Sing_ExcDjs)
            call LogMemDeAlloc(t_r, Sing_ExcDjsTag)

            deallocate(Sing_ExcDjs2)
            call LogMemDeAlloc(t_r, Sing_ExcDjs2Tag)

            if (RDMExcitLevel /= 1) then
                ! This array contains the initial positions of the
                ! single excitations for each processor.
                deallocate(Doub_InitExcSlots)

                ! This array contains the current position of the single
                ! excitations as they're added.
                deallocate(Doub_ExcList)

                ! This array actually contains the single excitations in
                ! blocks of the  processor they will be sent to.
                deallocate(Doub_ExcDjs)
                call LogMemDeAlloc(t_r, Doub_ExcDjsTag)

                deallocate(Doub_ExcDjs2)
                call LogMemDeAlloc(t_r, Doub_ExcDjs2Tag)
            end if
        else
            if (allocated(Spawned_Parents)) then
                deallocate(Spawned_Parents)
                call LogMemDeAlloc(t_r, Spawned_ParentsTag)
            end if

            if (allocated(Spawned_Parents_Index)) then
                deallocate(Spawned_Parents_Index)
                call LogMemDeAlloc(t_r, Spawned_Parents_IndexTag)
            end if
        end if

        if (allocated(FourIndInts)) then
            deallocate(FourIndInts)
            call LogMemDeAlloc(t_r, FourIndIntsTag)
        end if

        if (allocated(SymLabelCounts2_rot)) then
            deallocate(SymLabelCounts2_rot)
            call LogMemDeAlloc(t_r, SymLabelCounts2_rotTag)
        end if

        if (allocated(SymLabelList2_rot)) then
            deallocate(SymLabelList2_rot)
            call LogMemDeAlloc(t_r, SymLabelList2_rotTag)
        end if

        if (allocated(SymLabelListInv_rot)) then
            deallocate(SymLabelListInv_rot)
            call LogMemDeAlloc(t_r, SymLabelListInv_rotTag)
        end if

        if (allocated(AvNoatHF)) deallocate(AvNoatHF)
        if (allocated(IterRDM_HF)) deallocate(IterRDM_HF)

    end subroutine dealloc_global_rdm_data