build_conn_upto_n Subroutine

public subroutine build_conn_upto_n(adj, n, res, start_id)

Build connectivity matrices up to starting from . Results are stored in an array of boolean sparse matrix in Yale format in such a way that ; since FORTRAN is 1-based the useless is not stored.

Arguments

Type IntentOptional Attributes Name
type(yale_sparse), intent(in) :: adj

Adjacency matrix in Yale format

integer(kind=ip), intent(in) :: n

Maximum level of connectivity that should be computed

type(yale_sparse), intent(out), allocatable :: res(:)

Results connectivity matrices

logical :: start_id

Specifies if the first matrix allocated res(1) should be the identity (true) or the adjacency (false).


Calls

proc~~build_conn_upto_n~~CallsGraph proc~build_conn_upto_n build_conn_upto_n proc~sparse_identity sparse_identity proc~build_conn_upto_n->proc~sparse_identity proc~copy_yale_sparse copy_yale_sparse proc~build_conn_upto_n->proc~copy_yale_sparse proc~mat_mult mat_mult proc~build_conn_upto_n->proc~mat_mult proc~free_yale_sparse free_yale_sparse proc~build_conn_upto_n->proc~free_yale_sparse proc~mat_andnot mat_andnot proc~build_conn_upto_n->proc~mat_andnot proc~reallocate_mat reallocate_mat proc~mat_mult->proc~reallocate_mat proc~mat_andnot->proc~reallocate_mat

Called by

proc~~build_conn_upto_n~~CalledByGraph proc~build_conn_upto_n build_conn_upto_n proc~check_conn_matrix check_conn_matrix proc~check_conn_matrix->proc~build_conn_upto_n proc~mmpol_init_from_xyz mmpol_init_from_xyz proc~mmpol_init_from_xyz->proc~build_conn_upto_n proc~mmpol_init_from_xyz->proc~check_conn_matrix proc~mmpol_prepare mmpol_prepare proc~mmpol_init_from_xyz->proc~mmpol_prepare proc~ommp_system_from_qm_helper ommp_system_from_qm_helper proc~ommp_system_from_qm_helper->proc~build_conn_upto_n proc~ommp_system_from_qm_helper->proc~check_conn_matrix proc~ommp_system_from_qm_helper->proc~mmpol_prepare proc~mmpol_prepare->proc~build_conn_upto_n proc~init_vdw_for_link_atom init_vdw_for_link_atom proc~init_vdw_for_link_atom->proc~check_conn_matrix proc~mmpol_init_from_mmp mmpol_init_from_mmp proc~mmpol_init_from_mmp->proc~mmpol_prepare proc~init_bonded_for_link_atom init_bonded_for_link_atom proc~init_bonded_for_link_atom->proc~check_conn_matrix proc~c_ommp_system_from_qm_helper C_ommp_system_from_qm_helper proc~c_ommp_system_from_qm_helper->proc~ommp_system_from_qm_helper proc~ommp_init_xyz ommp_init_xyz proc~ommp_init_xyz->proc~mmpol_init_from_xyz proc~ommp_create_link_atom ommp_create_link_atom proc~ommp_create_link_atom->proc~init_vdw_for_link_atom proc~ommp_create_link_atom->proc~init_bonded_for_link_atom proc~c_ommp_init_xyz C_ommp_init_xyz proc~c_ommp_init_xyz->proc~ommp_init_xyz proc~ommp_init_mmp ommp_init_mmp proc~ommp_init_mmp->proc~mmpol_init_from_mmp proc~c_ommp_create_link_atom C_ommp_create_link_atom proc~c_ommp_create_link_atom->proc~ommp_create_link_atom proc~c_ommp_init_mmp C_ommp_init_mmp proc~c_ommp_init_mmp->proc~ommp_init_mmp

Contents

Source Code


Source Code

        subroutine build_conn_upto_n(adj, n, res, start_id)
            !! Build connectivity matrices up to \(\mathbb C_n\) 
            !! starting from \(\mathbb C_1\). Results are stored in an
            !! array of boolean sparse matrix in Yale format in such a way that
            !! \(res(n) := \mathbb C_n\); since FORTRAN is 1-based the useless
            !! \(\mathbb C_0\) is not stored.
            implicit none
            
            type(yale_sparse), intent(in) :: adj
            !! Adjacency matrix in Yale format
            integer(ip), intent(in) :: n
            !! Maximum level of connectivity that should be computed
            type(yale_sparse), intent(out), allocatable :: res(:)
            !! Results connectivity matrices
            logical :: start_id
            !! Specifies if the first matrix allocated res(1) should be the 
            !! identity (true) or the adjacency (false).

            integer(ip) :: i, adj_idx
            type(yale_sparse) :: tmp, id

            if(start_id) then
                allocate(res(n+1))
                call sparse_identity(adj%n, res(1))
                adj_idx = 2
            else
                allocate(res(n))
                adj_idx = 1
            end if
            call copy_yale_sparse(adj, res(adj_idx))
            
            do i=adj_idx+1, adj_idx+n-1
                if(size(res(i-1)%ci) == 0) then
                    ! Create a null matrix
                    res(i)%n = res(i-1)%n
                    allocate(res(i)%ri(res(i)%n+1))
                    res(i)%ri = 1
                    allocate(res(i)%ci(0))
                else
                    call mat_mult(res(i-1), res(adj_idx), res(i))
                    !call matcpy(res(i-1), res(i))
                    call mat_andnot(res(i), res(i-1), tmp)
                    if(i == adj_idx+1) then
                        call sparse_identity(adj%n, id)
                        call mat_andnot(tmp, id, res(i))
                        if(start_id) then
                            call copy_yale_sparse(id, res(1))
                        end if
                        call free_yale_sparse(id)
                    else
                        call mat_andnot(tmp, res(i-2), res(i))
                    end if
                end if
            end do
            call free_yale_sparse(tmp)
        end subroutine build_conn_upto_n