SetSparsity
SetSparsity()
method sets the sparsity pattern in the sparse matrix.
There are two interfaces for this purpose. The use of this method is exactly the same as the one described for CSRSparsity.
While calling SetSparsity()
user has to deal with the node numbers only, because this routine reads the information stored inside the DOF object field, and take care of sparsity patterns for all degrees of freedom.
please note that when you are done with setting the sparsity pattern make sure you call SetSparsity(obj)
. This will clean up the workspace, and prepare the compacted data inside CSRMatrix_
object.
Interface
- ܀ SetSparsity(obj, row, col)
- ܀ Example 1
- ↢
INTERFACE
MODULE SUBROUTINE SetSparsity(obj, row, col)
TYPE(CSRMatrix_), INTENT(INOUT) :: obj
INTEGER(I4B), INTENT(IN) :: row
INTEGER(I4B), INTENT(IN) :: col(:)
END SUBROUTINE SetSparsity
END INTERFACE
This method should be used for setting sparsity pattern for problems in which there is only primary unknown (i.e., single physical variable).
- This subroutine sets the sparsity pattern of a given row.
- If
obj%tdof
is equal to 1, thenCol
is sorted in increasing order, and appended toobj%Row(Row)
- If
obj%tdof
is not equal to 1, then based on the storage format (see DOF_) we generateCol
connectivity information.
PROGRAM main
USE easifemBase
IMPLICIT NONE
TYPE( CSRMatrix_ ) :: obj
TYPE( DOF_ ) :: dofobj
REAL(DFP), ALLOCATABLE :: m2(:,:)
INTEGER( I4B ) :: i, unitNo
CALL Initiate( obj=dofobj, tNodes=[5], names=['K'], &
& spaceCompo=[1], timeCompo=[1], storageFMT=FMT_NODES )
CALL Initiate( obj, ncol=(.tnodes. dofobj), &
& nrow=(.tnodes. dofobj), idof=dofobj, jdof=dofobj )
CALL Setsparsity( obj, 1, [1,2,3,5] )
CALL Setsparsity( obj, 2, [2,1,3] )
CALL Setsparsity( obj, 3, [3,1,2,4,5] )
CALL Setsparsity( obj, 4, [4,3,5] )
CALL Setsparsity( obj, 5, [5,1,3,4] )
CALL SetSparsity(obj)
obj = 2.0_DFP
CALL Display( obj, "obj" )
m2=obj
CALL Display(m2, "test-4:")
CALL Deallocate( obj )
END PROGRAM main
- ܀ SetSparsity(obj, row, col)
- ܀ Example
- ↢
INTERFACE
MODULE SUBROUTINE SetSparsity(obj, row, col)
TYPE(CSRMatrix_), INTENT(INOUT) :: obj
INTEGER(I4B), INTENT(IN) :: row(:)
!! row indices
TYPE(IntVector_), INTENT(IN) :: col(:)
!! each intVector, col(i), contains col indices of row(i)
END SUBROUTINE SetSparsity
END INTERFACE
TODO
- ܀ SetSparsity(obj, row, col, ivar, jvar)
- ܀ Example 1
- ܀ Example 2
- ↢
INTERFACE
MODULE SUBROUTINE SetSparsity(obj, row, col, ivar, jvar)
TYPE(CSRMatrix_), INTENT(INOUT) :: obj
INTEGER(I4B), INTENT(IN) :: row
!! row index
INTEGER(I4B), INTENT(IN) :: col(:)
!! col indices
INTEGER(I4B), INTENT(IN) :: ivar
!! physical variable i
INTEGER(I4B), INTENT(IN) :: jvar
!! physical variable j
END SUBROUTINE SetSparsity
END INTERFACE
To set sparsity patterns in multi-physics applications, use the following command.
PROGRAM main
USE easifemBase
IMPLICIT NONE
TYPE( CSRMatrix_ ) :: obj
TYPE( DOF_ ) :: dofobj
INTEGER( I4B ) :: i, unitNo
CALL Initiate( obj=dofobj, tNodes=[12, 5], names=['V', 'P'], &
& spaceCompo=[2, 1], timeCompo=[1,1], storageFMT=FMT_DOF )
CALL Initiate( obj, ncol=(.tnodes. dofobj), &
& nrow=(.tnodes. dofobj), idof=dofobj, jdof=dofobj )
CALL SetSparsity( obj, 1, [1,2,3,5,6,7,10,11,12], 1, 1 )
CALL SetSparsity( obj, 2, [2,1,3,6,7,11], 1, 1 )
CALL SetSparsity( obj, 3, [3,1,2,4,5,6,7,11,8,9,12,10], 1, 1 )
CALL SetSparsity( obj, 4, [4,3,5,8,9,12], 1, 1 )
CALL SetSparsity( obj, 5, [5,1,3,4,10,11,8,9,12], 1, 1 )
CALL SetSparsity( obj, 6, [6,1,2,3,7,11], 1, 1 )
CALL SetSparsity( obj, 7, [7,1,2,3,6,7,11], 1, 1 )
CALL SetSparsity( obj, 8, [8,3,4,5,8,9,12], 1, 1 )
CALL SetSparsity( obj, 9, [9,3,4,5,8,9,12], 1, 1 )
CALL SetSparsity( obj, 10, [10,1,3,5,11,12], 1, 1 )
CALL SetSparsity( obj, 11, [11,1,2,3,5,6,7,12,10], 1, 1 )
CALL SetSparsity( obj, 12, [12,1,3,4,5,10,11,8,9], 1, 1 )
CALL SetSparsity( obj, 1, [1,2,3,5], 1, 2 )
CALL SetSparsity( obj, 2, [2,1,3], 1, 2 )
CALL SetSparsity( obj, 3, [3,1,2,4,5], 1, 2 )
CALL SetSparsity( obj, 4, [4,3,5], 1, 2 )
CALL SetSparsity( obj, 5, [5,1,3,4], 1, 2 )
CALL SetSparsity( obj, 6, [1,2,3], 1, 2 )
CALL SetSparsity( obj, 7, [1,2,3], 1, 2 )
CALL SetSparsity( obj, 8, [3,4,5], 1, 2 )
CALL SetSparsity( obj, 9, [3,4,5], 1, 2 )
CALL SetSparsity( obj, 10, [1,3,5], 1, 2 )
CALL SetSparsity( obj, 11, [1,2,3,5], 1, 2 )
CALL SetSparsity( obj, 12, [1,3,4,5], 1, 2 )
CALL SetSparsity( obj, 1, [1,2,3,5,6,7,10,11,12], 2, 1 )
CALL SetSparsity( obj, 2, [2,1,3,6,7,11], 2, 1 )
CALL SetSparsity( obj, 3, [3,1,2,4,5,6,7,11,8,9,12,10], 2, 1 )
CALL SetSparsity( obj, 4, [4,3,5,12,8,9], 2, 1 )
CALL SetSparsity( obj, 5, [5,1,3,4,10,11,8,9,12], 2, 1 )
CALL SetSparsity( obj, 1, [1,2,3,5], 2, 2 )
CALL SetSparsity( obj, 2, [2,1,3], 2, 2 )
CALL SetSparsity( obj, 3, [3,1,2,4,5], 2, 2 )
CALL SetSparsity( obj, 4, [4,3,5], 2, 2 )
CALL SetSparsity( obj, 5, [5,1,3,4], 2, 2 )
CALL SetSparsity(obj)
obj = 2.0_DFP
CALL SPY( obj, "test_7", ".svg" )
!!! example "result"
!!! settings "Cleanup"
CALL Deallocate( obj )
END PROGRAM main
PROGRAM main
USE easifemBase
USE HDF5File_Class
IMPLICIT NONE
TYPE( CSRMatrix_ ) :: obj
TYPE( DOF_ ) :: dofobj
REAL( DFP ), ALLOCATABLE :: m2(:,:)
CALL Initiate( obj=dofobj, tNodes=[12, 5], names=['V', 'P'], &
& spaceCompo=[2, 1], timeCompo=[1,1], storageFMT=FMT_DOF )
CALL Initiate( obj, ncol=(.tnodes. dofobj), &
& nrow=(.tnodes. dofobj), idof=dofobj, jdof=dofobj )
CALL SetSparsity( obj=obj, row=1, col=[1,2,3,5,6,7,10,11,12], ivar=1, jvar=1 )
CALL SetSparsity( obj, 2, [2,1,3,6,7,11], 1, 1 )
CALL SetSparsity( obj, 3, [3,1,2,4,5,6,7,11,8,9,12,10], 1, 1 )
CALL SetSparsity( obj, 4, [4,3,5,8,9,12], 1, 1 )
CALL SetSparsity( obj, 5, [5,1,3,4,10,11,8,9,12], 1, 1 )
CALL SetSparsity( obj, 6, [6,1,2,3,7,11], 1, 1 )
CALL SetSparsity( obj, 7, [7,1,2,3,6,7,11], 1, 1 )
CALL SetSparsity( obj, 8, [8,3,4,5,8,9,12], 1, 1 )
CALL SetSparsity( obj, 9, [9,3,4,5,8,9,12], 1, 1 )
CALL SetSparsity( obj, 10, [10,1,3,5,11,12], 1, 1 )
CALL SetSparsity( obj, 11, [11,1,2,3,5,6,7,12,10], 1, 1 )
CALL SetSparsity( obj, 12, [12,1,3,4,5,10,11,8,9], 1, 1 )
CALL SetSparsity( obj, 1, [1,2,3,5], 1, 2 )
CALL SetSparsity( obj, 2, [2,1,3], 1, 2 )
CALL SetSparsity( obj, 3, [3,1,2,4,5], 1, 2 )
CALL SetSparsity( obj, 4, [4,3,5], 1, 2 )
CALL SetSparsity( obj, 5, [5,1,3,4], 1, 2 )
CALL SetSparsity( obj, 6, [1,2,3], 1, 2 )
CALL SetSparsity( obj, 7, [1,2,3], 1, 2 )
CALL SetSparsity( obj, 8, [3,4,5], 1, 2 )
CALL SetSparsity( obj, 9, [3,4,5], 1, 2 )
CALL SetSparsity( obj, 10, [1,3,5], 1, 2 )
CALL SetSparsity( obj, 11, [1,2,3,5], 1, 2 )
CALL SetSparsity( obj, 12, [1,3,4,5], 1, 2 )
CALL SetSparsity( obj, 1, [1,2,3,5,6,7,10,11,12], 2, 1 )
CALL SetSparsity( obj, 2, [2,1,3,6,7,11], 2, 1 )
CALL SetSparsity( obj, 3, [3,1,2,4,5,6,7,11,8,9,12,10], 2, 1 )
CALL SetSparsity( obj, 4, [4,3,5,12,8,9], 2, 1 )
CALL SetSparsity( obj, 5, [5,1,3,4,10,11,8,9,12], 2, 1 )
CALL SetSparsity( obj, 1, [1,2,3,5], 2, 2 )
CALL SetSparsity( obj, 2, [2,1,3], 2, 2 )
CALL SetSparsity( obj, 3, [3,1,2,4,5], 2, 2 )
CALL SetSparsity( obj, 4, [4,3,5], 2, 2 )
CALL SetSparsity( obj, 5, [5,1,3,4], 2, 2 )
CALL SetSparsity(obj)
obj = 1.0_DFP
m2=obj
CALL Display(m2, 'test8:')
CALL Deallocate( obj )
END PROGRAM main
- ܀ SetSparsity(obj, row, col, ivar, jvar)
- ܀ Example
- ↢
INTERFACE
MODULE SUBROUTINE SetSparsity(obj, row, col, ivar, jvar)
TYPE(CSRMatrix_), INTENT(INOUT) :: obj
INTEGER(I4B), INTENT(IN) :: row(:)
TYPE(IntVector_), INTENT(IN) :: col(:)
INTEGER(I4B), INTENT(IN) :: ivar
INTEGER(I4B), INTENT(IN) :: jvar
END SUBROUTINE SetSparsity
END INTERFACE
This routine is like Interface 3, but in this case we can specify many rows and corresponding columns.
TODO