SetSparsity
This subroutine sets the sparsity pattern in the CSRSparsity
object.
When you are done setting the sparsity pattern, you must call SetSparsity()
without arguments. This subroutine then creates a compact data inside the instance of CSRSparsity_
.
Interface 1 (Sparsity by row and column)
- Interface
- example
- ↢ close
MODULE SUBROUTINE SetSparsity( obj, Row, Col )
TYPE( CSRSparsity_ ), INTENT( INOUT ) :: obj
INTEGER( I4B ), INTENT( IN ) :: Row
INTEGER( I4B ), INTENT( IN ) :: Col( : )
END SUBROUTINE SetSparsity
This subroutine sets the sparsity pattern of a given row. If obj%tdof
is equal to 1, then Col
is sorted in increasing order and appended to obj%Row(Row)
. If obj%tdof
is not equal to 1, then based on the storage format and Col
, connectivity information is generated. The second interface is similar to the first one, however, this times several rows can be given.
Example 4
This example shows how to set sparsity pattern in an instance of CSRSparsity_
.
The storage pattern is FMT_NODES
, and matrix is not a block matrix.
setSparsity
Setting sparsity pattern. The row
and col
are the row and column number of the matrix.
PROGRAM main
USE easifemBase
IMPLICIT NONE
TYPE( CSRSparsity_ ) :: obj
TYPE( DOF_ ) :: dofobj
INTEGER( I4B ) :: i
CALL Initiate( &
& obj=dofobj, &
& tNodes=[12], &
& names=['K'], &
& spaceCompo=[1], &
& timeCompo=[1], &
& storageFMT=NODES_FMT )
CALL Initiate( &
& obj, &
& ncol=(.tnodes. dofobj), &
& nrow=(.tnodes. dofobj), &
& idof=dofobj, &
& jdof=dofobj )
CALL Setsparsity( obj, row=1, col=[1,2,6,5] )
CALL Setsparsity( obj, row=2, col=[2,1,3,5,6,7] )
CALL Setsparsity( obj, row=3, col=[3,2,4,6,7,8] )
CALL Setsparsity( obj, row=4, col=[4,3,7,8] )
CALL Setsparsity( obj, row=5, col=[5,1,9,2,6,10] )
CALL Setsparsity( obj, row=6, col=[6,2,10,1,5,9,3,7,11] )
CALL Setsparsity( obj, row=7, col=[7,6,8,2,3,4,10,11,12] )
CALL Setsparsity( obj, row=8, col=[8,4,12,3,7,11] )
CALL Setsparsity( obj, row=9, col=[9,5,6,10] )
CALL Setsparsity( obj, row=10, col=[10,9,11,5,6,7] )
CALL Setsparsity( obj, row=11, col=[11,10,12,6,7,8] )
CALL Setsparsity( obj, row=12, col=[12,7,8,11] )
CALL setSparsity( obj )
CALL Display( obj, "obj=" )
CALL Deallocate( dofobj )
CALL Deallocate( obj )
END PROGRAM main
Interface 2 (Sparsity by row and cols)
- Interface
- example
- ↢ close
MODULE SUBROUTINE SetSparsity( obj, Row, Col )
TYPE( CSRSparsity_ ), INTENT( INOUT ) :: obj
INTEGER( I4B ), INTENT( IN ) :: Row( : )
!! row number
TYPE( IntVector_ ), INTENT( IN ) :: Col( : )
!! column number
END SUBROUTINE SetSparsity
Example 5
This example shows how to set sparsity pattern in an instance of CSRSparsity_
.
The storage pattern is FMT_DOF
, and matrix is not a block matrix.
SetSparsity
Setting sparsity pattern. The row
and col
are the row and column number of the matrix.
PROGRAM main
USE easifemBase
IMPLICIT NONE
TYPE( CSRSparsity_ ) :: obj
TYPE( DOF_ ) :: dofobj
INTEGER( i4b ) :: i
CALL Initiate( &
& obj=dofobj, &
& tNodes=[12], &
& names=['K'], &
& spaceCompo=[3], &
& timeCompo=[2], &
& storageFMT=DOF_FMT )
CALL Initiate( obj, ncol=.tNodes. dofobj, nrow=.tNodes. dofobj, idof=dofobj, &
& jdof=dofobj )
CALL SetSparsity( obj, 1, [1,2,6,5] )
CALL SetSparsity( obj, 2, [2,1,3,5,6,7] )
CALL SetSparsity( obj, 3, [3,2,4,6,7,8] )
CALL SetSparsity( obj, 4, [4,3,7,8] )
CALL SetSparsity( obj, 5, [5,1,9,2,6,10] )
CALL SetSparsity( obj, 6, [6,2,10,1,5,9,3,7,11] )
CALL SetSparsity( obj, 7, [7,6,8,2,3,4,10,11,12] )
CALL SetSparsity( obj, 8, [8,4,12,3,7,11] )
CALL SetSparsity( obj, 9, [9,5,6,10] )
CALL SetSparsity( obj, 10, [10,9,11,5,6,7] )
CALL SetSparsity( obj, 11, [11,10,12,6,7,8] )
CALL SetSparsity( obj, 12, [12,7,8,11] )
CALL SetSparsity(obj)
CALL Display( obj, "obj=" )
CALL Deallocate( dofobj )
CALL Deallocate( obj )
END PROGRAM main
Interface 3 (Sparsity for block matrix)
To handle the block sparsity we can use following routines.
- Interface
- example
- ↢ close
INTERFACE SetSparsity
MODULE SUBROUTINE obj_SetSparsity3(obj, row, col, ivar, jvar)
TYPE(CSRSparsity_), INTENT(INOUT) :: obj
INTEGER(I4B), INTENT(IN) :: row
!! row number
INTEGER(I4B), INTENT(IN) :: col(:)
!! sparsity of row, column numbers
INTEGER(I4B), INTENT(IN) :: ivar
!! block address (row index)
INTEGER(I4B), INTENT(IN) :: jvar
!! block address (col index)
END SUBROUTINE obj_SetSparsity3
END INTERFACE SetSparsity
While calling SetSparsity()
user has to deal with the mesh 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.
Example 3
This example shows how to Set sparsity pattern in an instance of CSRSparsity_
. The storage pattern is FMT_DOF
, and matrix is block matrix.
- Make an instance of
DOF_
which contains the storage pattern. - Initiate an instance of
CSRSparsity_
.
SetSparsity
In this example we will set sparsity pattern in each block. The block address is given by
ivar and jvar. row
and col
are the row and column number in that
block.
We should now call SetSparsity()
to indicate that setting of sparsity pattern is finished. This step will compact the storage.
Usage
PROGRAM main
USE easifemBase
IMPLICIT NONE
TYPE( CSRSparsity_ ) :: obj
TYPE( DOF_ ) :: dofobj
INTEGER( I4B ) :: i
CALL Initiate( &
& obj=dofobj, &
& tNodes=[6, 3], &
& names=['V', 'P'], &
& spaceCompo=[3, 1], &
& timeCompo=[1, 1], &
& storageFMT=FMT_DOF )
CALL Initiate( &
& obj, &
& ncol=(.tnodes. dofobj), &
& nrow=(.tNodes. dofobj), &
& idof=dofobj, &
& jdof=dofobj )
!Block 1,1 ( V, V )
CALL SetSparsity( obj=obj, row=1, col=[1,2,3,4,5,6], ivar=1, jvar=1 )
CALL SetSparsity( obj=obj, row=2, col=[1,2,3,4,5,6], ivar=1, jvar=1 )
CALL SetSparsity( obj=obj, row=3, col=[1,2,3,4,5,6], ivar=1, jvar=1 )
CALL SetSparsity( obj=obj, row=4, col=[1,2,3,4,5,6], ivar=1, jvar=1 )
CALL SetSparsity( obj=obj, row=5, col=[1,2,3,4,5,6], ivar=1, jvar=1 )
CALL SetSparsity( obj=obj, row=6, col=[1,2,3,4,5,6], ivar=1, jvar=1 )
!Block 1,2 (V, P)
CALL SetSparsity( obj=obj, row=1, col=[1,2,3], ivar=1, jvar=2 )
CALL SetSparsity( obj=obj, row=2, col=[1,2,3], ivar=1, jvar=2 )
CALL SetSparsity( obj=obj, row=3, col=[1,2,3], ivar=1, jvar=2 )
CALL SetSparsity( obj=obj, row=4, col=[1,2,3], ivar=1, jvar=2 )
CALL SetSparsity( obj=obj, row=5, col=[1,2,3], ivar=1, jvar=2 )
CALL SetSparsity( obj=obj, row=6, col=[1,2,3], ivar=1, jvar=2 )
!Block 2,1 (P,V)
CALL SetSparsity( obj=obj, row=1, col=[1,2,3,4,5,6], ivar=2, jvar=1 )
CALL SetSparsity( obj=obj, row=2, col=[1,2,3,4,5,6], ivar=2, jvar=1 )
CALL SetSparsity( obj=obj, row=3, col=[1,2,3,4,5,6], ivar=2, jvar=1 )
!Block 2,2 (P,P)
CALL SetSparsity( obj=obj, row=1, col=[1,2,3], ivar=2, jvar=2 )
CALL SetSparsity( obj=obj, row=2, col=[1,2,3], ivar=2, jvar=2 )
CALL SetSparsity( obj=obj, row=3, col=[1,2,3], ivar=2, jvar=2 )
CALL SetSparsity( obj )
CALL Display( obj, "" )
CALL Deallocate( dofobj )
CALL Deallocate( obj )
END PROGRAM main
Interface 4 (Sparsity for block matrix)
INTERFACE SetSparsity
MODULE SUBROUTINE obj_SetSparsity4(obj, Row, Col, iVar, jVar)
TYPE(CSRSparsity_), INTENT(INOUT) :: obj
INTEGER(I4B), INTENT(IN) :: Row(:)
!! several row numbers
TYPE(IntVector_), INTENT(IN) :: Col(:)
!! column index for each row number
INTEGER(I4B), INTENT(IN) :: iVar
!! block address (row index)
INTEGER(I4B), INTENT(IN) :: jVar
!! block address (col index)
END SUBROUTINE obj_SetSparsity4
END INTERFACE SetSparsity
Interface 5 (Sparsity by graph)
- Interface
- Interface 2
- example
- example 2
- ↢ close
INTERFACE SetSparsity
MODULE SUBROUTINE obj_SetSparsity5(obj, graph)
TYPE(CSRSparsity_), INTENT(INOUT) :: obj
INTEGER(I4B), INTENT(IN) :: graph(:, :)
!! graph of sparsity
!! If graph( i, j ) .EQ. 0, then i and j are not connected
!! else they are connected.
END SUBROUTINE obj_SetSparsity5
END INTERFACE SetSparsity
This subroutine Sets the sparsity pattern by using the graph. graph( i, j ) is either 0 or 1, if zero then there is not connection between row-i and row-j
INTERFACE SetSparsity
MODULE SUBROUTINE obj_SetSparsity6(obj, graph)
TYPE(CSRSparsity_), INTENT(INOUT) :: obj
LOGICAL(LGT), INTENT(IN) :: graph(:, :)
!! graph of sparsity
!! If graph( i, j ) .EQ. FALSE, then i and j are not connected
!! else they are connected.
END SUBROUTINE obj_SetSparsity6
END INTERFACE SetSparsity
example 7
This example shows how to set sparsity pattern by using a graph matrix. A graph matrix is a two-d array of 1 and 0. If graph( i, j ) is 1 then row-i and row-j are connected.
PROGRAM main
USE easifemBase
IMPLICIT NONE
TYPE( CSRSparsity_) :: obj
INTEGER( I4B ), PARAMETER :: nrow=5, ncol=5
INTEGER( I4B ) :: i, graph( 5, 5 )
graph = 0
graph( 1,2 ) = 1
graph( 2,3 ) = 1
graph( 2,4 ) = 1
graph( 2,5 ) = 1
CALL Initiate( obj=obj, nrow=nrow, ncol=ncol )
CALL SetSparsity(obj, graph=graph)
CALL SetSparsity(obj)
CALL Display( obj, "obj" )
CALL Deallocate( obj )
END PROGRAM main
example 8
This example shows how to set sparsity pattern by using a graph matrix. A graph matrix is a two-d array of true and false. if graph( i, j ) is true then row-i and row-j are connected.
PROGRAM main
USE easifemBase
IMPLICIT NONE
TYPE( CSRSparsity_) :: obj
INTEGER( I4B ), PARAMETER :: nrow=5, ncol=5
INTEGER( I4B ) :: i
LOGICAL( LGT ) :: graph( nrow, ncol )
graph = .FALSE.
graph( 1,2 ) = .TRUE.
graph( 2,3 ) = .TRUE.
graph( 2,4 ) = .TRUE.
graph( 2,5 ) = .TRUE.
CALL Initiate( obj=obj, nrow=nrow, ncol=ncol )
CALL SetSparsity(obj, graph=graph)
CALL SetSparsity(obj)
CALL Display( obj, "obj" )
CALL Deallocate( obj )
END PROGRAM main