matrix_coo.F90 Source File


This file depends on

sourcefile~~matrix_coo.f90~~EfferentGraph sourcefile~matrix_coo.f90 matrix_coo.F90 sourcefile~core.f90 core.F90 sourcefile~matrix_coo.f90->sourcefile~core.f90 sourcefile~domain.f90 domain.F90 sourcefile~matrix_coo.f90->sourcefile~domain.f90 sourcefile~matrix_base.f90 matrix_base.F90 sourcefile~matrix_coo.f90->sourcefile~matrix_base.f90 sourcefile~allocate.f90 allocate.F90 sourcefile~core.f90->sourcefile~allocate.f90 sourcefile~check_range.f90 check_range.F90 sourcefile~core.f90->sourcefile~check_range.f90 sourcefile~deallocate.f90 deallocate.F90 sourcefile~core.f90->sourcefile~deallocate.f90 sourcefile~error.f90 error.F90 sourcefile~core.f90->sourcefile~error.f90 sourcefile~fortran_utils.f90 fortran_utils.F90 sourcefile~core.f90->sourcefile~fortran_utils.f90 sourcefile~string_utils.f90 string_utils.F90 sourcefile~core.f90->sourcefile~string_utils.f90 sourcefile~types.f90 types.F90 sourcefile~core.f90->sourcefile~types.f90 sourcefile~unique.f90 unique.F90 sourcefile~core.f90->sourcefile~unique.f90 sourcefile~vtk.f90 vtk.F90 sourcefile~core.f90->sourcefile~vtk.f90 sourcefile~vtk_constants.f90 vtk_constants.F90 sourcefile~core.f90->sourcefile~vtk_constants.f90 sourcefile~adjacency.f90 adjacency.F90 sourcefile~domain.f90->sourcefile~adjacency.f90 sourcefile~domain_manager.f90 domain_manager.F90 sourcefile~domain.f90->sourcefile~domain_manager.f90 sourcefile~element.f90 element.F90 sourcefile~domain.f90->sourcefile~element.f90 sourcefile~element_factory.f90 element_factory.F90 sourcefile~domain.f90->sourcefile~element_factory.f90 sourcefile~multicoloring.f90 multicoloring.F90 sourcefile~domain.f90->sourcefile~multicoloring.f90 sourcefile~reordering.f90 reordering.F90 sourcefile~domain.f90->sourcefile~reordering.f90 sourcefile~side.f90 side.F90 sourcefile~domain.f90->sourcefile~side.f90 sourcefile~side_factory.f90 side_factory.F90 sourcefile~domain.f90->sourcefile~side_factory.f90 sourcefile~matrix_base.f90->sourcefile~domain.f90 sourcefile~adjacency_element.f90 adjacency_element.F90 sourcefile~adjacency.f90->sourcefile~adjacency_element.f90 sourcefile~adjacency_node.f90 adjacency_node.F90 sourcefile~adjacency.f90->sourcefile~adjacency_node.f90 sourcefile~allocate.f90->sourcefile~error.f90 sourcefile~deallocate.f90->sourcefile~error.f90 sourcefile~domain_manager.f90->sourcefile~core.f90 sourcefile~domain_manager.f90->sourcefile~adjacency.f90 sourcefile~domain_manager.f90->sourcefile~element.f90 sourcefile~domain_manager.f90->sourcefile~element_factory.f90 sourcefile~domain_manager.f90->sourcefile~multicoloring.f90 sourcefile~domain_manager.f90->sourcefile~reordering.f90 sourcefile~domain_manager.f90->sourcefile~side.f90 sourcefile~domain_manager.f90->sourcefile~side_factory.f90 sourcefile~input.f90 input.F90 sourcefile~domain_manager.f90->sourcefile~input.f90 sourcefile~element.f90->sourcefile~core.f90 sourcefile~element.f90->sourcefile~input.f90 sourcefile~element_factory.f90->sourcefile~core.f90 sourcefile~element_factory.f90->sourcefile~element.f90 sourcefile~element_factory.f90->sourcefile~input.f90 sourcefile~memory_stats_wrapper.f90 memory_stats_wrapper.F90 sourcefile~fortran_utils.f90->sourcefile~memory_stats_wrapper.f90 sourcefile~signal_flag_wrapper.f90 signal_flag_wrapper.F90 sourcefile~fortran_utils.f90->sourcefile~signal_flag_wrapper.f90 sourcefile~system_info_wrapper.f90 system_info_wrapper.F90 sourcefile~fortran_utils.f90->sourcefile~system_info_wrapper.f90 sourcefile~multicoloring.f90->sourcefile~core.f90 sourcefile~multicoloring.f90->sourcefile~adjacency_element.f90 sourcefile~reordering.f90->sourcefile~core.f90 sourcefile~reordering.f90->sourcefile~element.f90 sourcefile~reordering.f90->sourcefile~adjacency_node.f90 sourcefile~side.f90->sourcefile~core.f90 sourcefile~side.f90->sourcefile~input.f90 sourcefile~side_factory.f90->sourcefile~core.f90 sourcefile~side_factory.f90->sourcefile~side.f90 sourcefile~side_factory.f90->sourcefile~input.f90 sourcefile~string_utils.f90->sourcefile~allocate.f90 sourcefile~array.f90 array.F90 sourcefile~types.f90->sourcefile~array.f90 sourcefile~gauss.f90 gauss.F90 sourcefile~types.f90->sourcefile~gauss.f90 sourcefile~pointer.f90 pointer.F90 sourcefile~types.f90->sourcefile~pointer.f90 sourcefile~variable.f90 variable.F90 sourcefile~types.f90->sourcefile~variable.f90 sourcefile~vector.f90 vector.F90 sourcefile~types.f90->sourcefile~vector.f90 sourcefile~unique.f90->sourcefile~allocate.f90 sourcefile~vtk.f90->sourcefile~allocate.f90 sourcefile~vtk.f90->sourcefile~deallocate.f90 sourcefile~vtk.f90->sourcefile~unique.f90 sourcefile~vtk.f90->sourcefile~vtk_constants.f90 sourcefile~vtk.f90->sourcefile~array.f90 sourcefile~vtk_wrapper.f90 vtk_wrapper.F90 sourcefile~vtk.f90->sourcefile~vtk_wrapper.f90 sourcefile~vtu_wrapper.f90 vtu_wrapper.F90 sourcefile~vtk.f90->sourcefile~vtu_wrapper.f90 sourcefile~adjacency_element.f90->sourcefile~core.f90 sourcefile~adjacency_element.f90->sourcefile~element.f90 sourcefile~adjacency_node.f90->sourcefile~core.f90 sourcefile~array.f90->sourcefile~allocate.f90 sourcefile~array.f90->sourcefile~deallocate.f90 sourcefile~input_interface.f90 input_interface.F90 sourcefile~input.f90->sourcefile~input_interface.f90 sourcefile~c_utils.f90 c_utils.F90 sourcefile~memory_stats_wrapper.f90->sourcefile~c_utils.f90 sourcefile~signal_flag.f90 signal_flag.F90 sourcefile~signal_flag_wrapper.f90->sourcefile~signal_flag.f90 sourcefile~system_info_wrapper.f90->sourcefile~c_utils.f90 sourcefile~variable.f90->sourcefile~allocate.f90 sourcefile~c_utils.f90->sourcefile~signal_flag.f90 sourcefile~memory_stats.f90 memory_stats.F90 sourcefile~c_utils.f90->sourcefile~memory_stats.f90 sourcefile~system_info.f90 system_info.F90 sourcefile~c_utils.f90->sourcefile~system_info.f90 sourcefile~input_interface.f90->sourcefile~core.f90 sourcefile~project_settings.f90 project_settings.F90 sourcefile~input_interface.f90->sourcefile~project_settings.f90 sourcefile~project_settings.f90->sourcefile~core.f90

Files dependent on this one

sourcefile~~matrix_coo.f90~~AfferentGraph sourcefile~matrix_coo.f90 matrix_coo.F90 sourcefile~matrix.f90 matrix.F90 sourcefile~matrix.f90->sourcefile~matrix_coo.f90 sourcefile~matrix_crs.f90 matrix_crs.F90 sourcefile~matrix.f90->sourcefile~matrix_crs.f90 sourcefile~matrix_crs.f90->sourcefile~matrix_coo.f90 sourcefile~boundary_interface.f90 boundary_interface.F90 sourcefile~boundary_interface.f90->sourcefile~matrix.f90 sourcefile~boundary_manager.f90 boundary_manager.F90 sourcefile~boundary_manager.f90->sourcefile~matrix.f90 sourcefile~boundary_manager.f90->sourcefile~boundary_interface.f90 sourcefile~output_interface.f90 output_interface.F90 sourcefile~output_interface.f90->sourcefile~matrix.f90 sourcefile~solver_factory.f90 solver_factory.F90 sourcefile~solver_factory.f90->sourcefile~matrix.f90 sourcefile~thermal_interface.f90 thermal_interface.F90 sourcefile~thermal_interface.f90->sourcefile~matrix.f90 sourcefile~boundary.f90 boundary.F90 sourcefile~thermal_interface.f90->sourcefile~boundary.f90 sourcefile~solver.f90 solver.F90 sourcefile~thermal_interface.f90->sourcefile~solver.f90 sourcefile~boundary.f90->sourcefile~boundary_interface.f90 sourcefile~boundary.f90->sourcefile~boundary_manager.f90 sourcefile~boundary_adiabatic.f90 boundary_adiabatic.F90 sourcefile~boundary_adiabatic.f90->sourcefile~boundary_interface.f90 sourcefile~boundary_base.f90 boundary_base.F90 sourcefile~boundary_base.f90->sourcefile~boundary_interface.f90 sourcefile~boundary_dirichlet.f90 boundary_dirichlet.F90 sourcefile~boundary_dirichlet.f90->sourcefile~boundary_interface.f90 sourcefile~ftdss.f90 ftdss.F90 sourcefile~ftdss.f90->sourcefile~thermal_interface.f90 sourcefile~ftdss.f90->sourcefile~boundary.f90 sourcefile~output.f90 output.F90 sourcefile~ftdss.f90->sourcefile~output.f90 sourcefile~initial.f90 initial.F90 sourcefile~ftdss.f90->sourcefile~initial.f90 sourcefile~output.f90->sourcefile~output_interface.f90 sourcefile~output_base.f90 output_base.F90 sourcefile~output_base.f90->sourcefile~output_interface.f90 sourcefile~output_observation.f90 output_observation.F90 sourcefile~output_observation.f90->sourcefile~output_interface.f90 sourcefile~output_overall_base.f90 output_overall_base.F90 sourcefile~output_overall_base.f90->sourcefile~output_interface.f90 sourcefile~output_overall_vtk.f90 output_overall_vtk.F90 sourcefile~output_overall_vtk.f90->sourcefile~output_interface.f90 sourcefile~output_overall_vtu.f90 output_overall_vtu.F90 sourcefile~output_overall_vtu.f90->sourcefile~output_interface.f90 sourcefile~output_system_logger.f90 output_system_logger.F90 sourcefile~output_system_logger.f90->sourcefile~output_interface.f90 sourcefile~solver.f90->sourcefile~solver_factory.f90 sourcefile~thermal.f90 thermal.F90 sourcefile~thermal.f90->sourcefile~thermal_interface.f90 sourcefile~thermal_3phase.f90 thermal_3phase.F90 sourcefile~thermal_3phase.f90->sourcefile~thermal_interface.f90 sourcefile~initial_interface.f90 initial_interface.F90 sourcefile~initial_interface.f90->sourcefile~boundary.f90 sourcefile~initial.f90->sourcefile~initial_interface.f90 sourcefile~initial_manager.f90 initial_manager.F90 sourcefile~initial.f90->sourcefile~initial_manager.f90 sourcefile~initial_laplace.f90 initial_laplace.F90 sourcefile~initial_laplace.f90->sourcefile~initial_interface.f90 sourcefile~initial_manager.f90->sourcefile~initial_interface.f90 sourcefile~initial_uniform.f90 initial_uniform.F90 sourcefile~initial_uniform.f90->sourcefile~initial_interface.f90

Source Code

module matrix_coo
    use, intrinsic :: iso_fortran_env
    use :: module_core, only:allocate_array, deallocate_array, unique
    use :: module_domain, only:type_domain
    use :: matrix_base, only:abst_matrix
    implicit none
    private

    public :: type_coo

    type, extends(abst_matrix) :: type_coo
        integer(int32) :: nnz = 0 ! number of non-zero elements
        integer(int32), allocatable :: row(:)
        integer(int32), allocatable :: col(:)
        real(real64), allocatable :: val(:) ! non-zero values
    contains
        procedure, public, pass(self) :: initialize => initialize_type_coo
        procedure, public, pass(self) :: find => find_coo
        procedure, public, pass(self) :: copy => copy_coo
        procedure, public, pass(self) :: destory => destory_coo
    end type

contains

    subroutine initialize_type_coo(self, domain)
        implicit none
        class(type_coo), intent(inout) :: self
        type(type_domain), intent(inout) :: domain

        ! --- ローカル変数宣言 ---
        integer(int32) :: num_nodes, num_elements, num_sides, computation_dimension
        integer(int32) :: local_nodes
        integer(int32) :: num_total_cell_nodes
        integer(int32) :: i, j, k
        integer(int32) :: counter
        integer(int32), allocatable :: row_indices(:), col_indices(:)
        ! --- Variables for sorting and finding uniques ---
        integer(int64), allocatable :: packed_indices(:), unique_packed_indices(:)
        integer(int32) :: unique_idx
        integer(int64) :: last_key

        ! --- 初期設定 ---
        num_nodes = domain%get_num_nodes()
        num_sides = domain%get_num_sides()
        num_elements = domain%get_num_elements()

        self%nnz = 0

        ! --- 計算対象となる最大次元より低い次元のセルノード数を計算 ---
        ! これが最大のセルノード数となる
        num_total_cell_nodes = 0
        computation_dimension = domain%get_computation_dimension()
        if (computation_dimension == 3) then
            ! (3D implementation would go here)
        end if
        if (computation_dimension == 2) then
            do i = 1, num_elements
                num_total_cell_nodes = num_total_cell_nodes + domain%elements(i)%e%get_num_nodes()**2
            end do
            do i = 1, num_sides
                num_total_cell_nodes = num_total_cell_nodes + domain%sides(i)%s%get_num_nodes()**2
            end do
        end if

        if (num_total_cell_nodes <= 0) then
            print *, "Error: No valid nodes found in the domain."
            return
        else
            call allocate_array(row_indices, num_total_cell_nodes)
            call allocate_array(col_indices, num_total_cell_nodes)
        end if

        ! 重複ありですべての配置場所を割り当てる
        counter = 0
        if (computation_dimension == 3) then
            ! (3D implementation would go here)
        end if
        if (computation_dimension == 2) then
            do i = 1, num_elements
                local_nodes = domain%elements(i)%e%get_num_nodes()
                do j = 1, local_nodes
                    do k = 1, local_nodes
                        counter = counter + 1
                        row_indices(counter) = domain%elements(i)%e%connectivity(j)
                        col_indices(counter) = domain%elements(i)%e%connectivity(k)
                    end do
                end do
            end do
            do i = 1, num_sides
                local_nodes = domain%sides(i)%s%get_num_nodes()
                do j = 1, local_nodes
                    do k = 1, local_nodes
                        counter = counter + 1
                        row_indices(counter) = domain%sides(i)%s%connectivity(j)
                        col_indices(counter) = domain%sides(i)%s%connectivity(k)
                    end do
                end do
            end do
        end if

        ! --- 重複を削除し、最終的なCOO構造を構築 ---
        if (counter > 0) then
            ! Pack (row, col) into a single 64-bit integer for sorting
            call allocate_array(packed_indices, int(counter, kind=int64))
            do i = 1, counter
                packed_indices(i) = ishft(int(row_indices(i), int64), 32) + int(col_indices(i), int64)
            end do

            ! Sort the packed indices
            call unique(packed_indices, unique_packed_indices)

            ! --- COO配列を確保し、アンパックして格納 ---
            self%nnz = int(size(unique_packed_indices), kind=int32)
            call allocate_array(self%row, self%nnz)
            call allocate_array(self%col, self%nnz)
            call allocate_array(self%val, self%nnz)
            self%val(:) = 0.0d0

            do i = 1, self%nnz
                self%row(i) = int(ishft(unique_packed_indices(i), -32), kind=int32)
                self%col(i) = int(iand(unique_packed_indices(i), int(z'FFFFFFFF', int64)), kind=int32)
            end do

            ! --- 一時配列の解放 ---
            call deallocate_array(packed_indices)
            call deallocate_array(unique_packed_indices)
        end if

        ! Deallocate temporary arrays
        call deallocate_array(row_indices)
        call deallocate_array(col_indices)

    end subroutine initialize_type_coo

    subroutine find_coo(self, row, col, index)
        implicit none
        class(type_coo), intent(in) :: self
        integer(int32), intent(in) :: row, col
        integer(int32), intent(inout) :: index

        integer(int32) :: i

        if (self%nnz == 0) then
            index = -1
            return
        end if

        ! --- 二分探索で行と列の組み合わせを探す ---
        index = -1
        do i = 1, self%nnz
            if (self%row(i) == row .and. self%col(i) == col) then
                index = i
                return
            end if
        end do
    end subroutine find_coo

    function copy_coo(self) result(B)
        implicit none
        class(type_coo), intent(in) :: self
        class(abst_matrix), allocatable :: B

        allocate (type_coo :: B)
        select type (matrix => B)
        type is (type_coo)
            matrix%nnz = self%nnz
            call allocate_array(matrix%row, self%nnz)
            call allocate_array(matrix%col, self%nnz)
            call allocate_array(matrix%val, self%nnz)
            matrix%row(:) = self%row(:)
            matrix%col(:) = self%col(:)
            matrix%val(:) = self%val(:)
        end select
    end function copy_coo

    subroutine destory_coo(self)
        implicit none
        class(type_coo), intent(inout) :: self

        ! --- COO構造の解放 ---
        call deallocate_array(self%row)
        call deallocate_array(self%col)
        call deallocate_array(self%val)

        self%nnz = 0
    end subroutine destory_coo

end module matrix_coo