@@ -79,10 +79,10 @@ MODULE oft_la_utils
7979! > Real implementation for \ref create_vector
8080!- --------------------------------------------------------------------------------
8181SUBROUTINE create_vector_real (vec ,stitch_info ,maps ,native )
82- CLASS(oft_vector), POINTER , INTENT (inout ) :: vec
83- TYPE (seam_list), INTENT (inout ) :: stitch_info(:)
84- TYPE (map_list), INTENT (inout ) :: maps(:)
85- LOGICAL , OPTIONAL , INTENT (in ) :: native
82+ CLASS(oft_vector), POINTER , INTENT (inout ) :: vec ! < Resulting vector
83+ TYPE (seam_list), INTENT (inout ) :: stitch_info(:) ! < Array of seam structures
84+ TYPE (map_list), INTENT (inout ) :: maps(:) ! < Mapping from sub-vectors into full vector
85+ LOGICAL , OPTIONAL , INTENT (in ) :: native ! < Force native representation?
8686!- --
8787LOGICAL :: force_native
8888INTEGER (i4) :: i,offset,soffset,nblocks
@@ -210,10 +210,10 @@ END SUBROUTINE create_vector_real
210210! > Complex implementation for \ref create_vector
211211!- --------------------------------------------------------------------------------
212212SUBROUTINE create_vector_comp (vec ,stitch_info ,maps ,native )
213- CLASS(oft_cvector), POINTER , INTENT (inout ) :: vec
214- TYPE (seam_list), INTENT (inout ) :: stitch_info(:)
215- TYPE (map_list), INTENT (inout ) :: maps(:)
216- LOGICAL , OPTIONAL , INTENT (in ) :: native
213+ CLASS(oft_cvector), POINTER , INTENT (inout ) :: vec ! < Resulting vector
214+ TYPE (seam_list), INTENT (inout ) :: stitch_info(:) ! < Array of seam structures
215+ TYPE (map_list), INTENT (inout ) :: maps(:) ! < Mapping from sub-vectors into full vector
216+ LOGICAL , OPTIONAL , INTENT (in ) :: native ! < Force native representation?
217217!- --
218218LOGICAL :: force_native
219219INTEGER (i4) :: i,offset,soffset,nblocks
@@ -402,10 +402,10 @@ END SUBROUTINE condense_stitch
402402! > Real implementation for \ref create_matrix
403403!- --------------------------------------------------------------------------------
404404SUBROUTINE create_matrix_real (mat ,ingraphs ,row_vec ,col_vec ,native )
405- CLASS(oft_matrix), POINTER , INTENT (inout ) :: mat
406- TYPE (oft_graph_ptr), INTENT (in ) :: ingraphs(:,:)
407- CLASS(oft_vector), POINTER , INTENT (in ) :: row_vec
408- CLASS(oft_vector), POINTER , INTENT (in ) :: col_vec
405+ CLASS(oft_matrix), POINTER , INTENT (inout ) :: mat ! < Resulting matrix
406+ TYPE (oft_graph_ptr), INTENT (in ) :: ingraphs(:,:) ! < Array of graphs representing matix blocks
407+ CLASS(oft_vector), POINTER , INTENT (in ) :: row_vec ! < Vector representing matrix rows
408+ CLASS(oft_vector), POINTER , INTENT (in ) :: col_vec ! < Vector representing matrix columns
409409LOGICAL , OPTIONAL , INTENT (in ) :: native
410410LOGICAL :: force_native
411411INTEGER (i4) :: i,j,ni,nj,offset,soffset
@@ -570,10 +570,10 @@ END SUBROUTINE create_matrix_real
570570! > Real implementation for \ref create_matrix
571571!- --------------------------------------------------------------------------------
572572SUBROUTINE create_matrix_comp (mat ,ingraphs ,row_vec ,col_vec ,native )
573- CLASS(oft_cmatrix), POINTER , INTENT (inout ) :: mat
574- TYPE (oft_graph_ptr), INTENT (in ) :: ingraphs(:,:)
575- CLASS(oft_cvector), POINTER , INTENT (in ) :: row_vec
576- CLASS(oft_cvector), POINTER , INTENT (in ) :: col_vec
573+ CLASS(oft_cmatrix), POINTER , INTENT (inout ) :: mat ! < Resulting matrix
574+ TYPE (oft_graph_ptr), INTENT (in ) :: ingraphs(:,:) ! < Array of graphs representing matix blocks
575+ CLASS(oft_cvector), POINTER , INTENT (in ) :: row_vec ! < Vector representing matrix rows
576+ CLASS(oft_cvector), POINTER , INTENT (in ) :: col_vec ! < Vector representing matrix columns
577577LOGICAL , OPTIONAL , INTENT (in ) :: native
578578LOGICAL :: force_native
579579INTEGER (i4) :: i,j,ni,nj,offset,soffset
@@ -701,13 +701,13 @@ SUBROUTINE setup_native(this)
701701END SUBROUTINE setup_native
702702END SUBROUTINE create_matrix_comp
703703!- --------------------------------------------------------------------------------
704- ! > Needs Docs
704+ ! > Remove redundant column indices from a CSR graph
705705!- --------------------------------------------------------------------------------
706706SUBROUTINE csr_remove_redundant (nr ,kr ,nnz ,lc )
707- INTEGER (4 ), INTENT (in ) :: nr
708- INTEGER (4 ), INTENT (inout ) :: kr(nr+1 )
709- INTEGER (4 ), INTENT (inout ) :: nnz
710- INTEGER (4 ), POINTER , INTENT (inout ) :: lc(:)
707+ INTEGER (4 ), INTENT (in ) :: nr ! < Number of rows
708+ INTEGER (4 ), INTENT (inout ) :: kr(nr+1 ) ! < Row pointer
709+ INTEGER (4 ), INTENT (inout ) :: nnz ! < Number of non-zero entries
710+ INTEGER (4 ), POINTER , INTENT (inout ) :: lc(:) ! < Column indices
711711INTEGER (4 ) :: i,j,nremove,js
712712INTEGER (4 ), POINTER :: lctmp(:)
713713nremove= 0
@@ -970,9 +970,9 @@ end subroutine graph_add_full_col
970970! > Real implementation for \ref combine_matrices
971971!- --------------------------------------------------------------------------------
972972SUBROUTINE combine_matrices_real (mats ,nr ,nc ,mat )
973- TYPE (oft_matrix_ptr), INTENT (in ) :: mats(:,:)
974- INTEGER (i4), INTENT (in ) :: nr
975- INTEGER (i4), INTENT (in ) :: nc
973+ TYPE (oft_matrix_ptr), INTENT (in ) :: mats(:,:) ! < Array of sub-matrices to combine
974+ INTEGER (i4), INTENT (in ) :: nr ! < Number of row sub-matrices
975+ INTEGER (i4), INTENT (in ) :: nc ! < Number of column sub-matrices
976976CLASS(oft_matrix), POINTER , INTENT (inout ) :: mat
977977DEBUG_STACK_PUSH
978978SELECT TYPE (this= >mat)
@@ -1145,9 +1145,9 @@ END SUBROUTINE combine_matrices_real
11451145! > Real implementation for \ref combine_matrices
11461146!- --------------------------------------------------------------------------------
11471147SUBROUTINE combine_matrices_comp (mats ,nr ,nc ,mat )
1148- TYPE (oft_cmatrix_ptr), INTENT (in ) :: mats(:,:)
1149- INTEGER (i4), INTENT (in ) :: nr
1150- INTEGER (i4), INTENT (in ) :: nc
1148+ TYPE (oft_cmatrix_ptr), INTENT (in ) :: mats(:,:) ! < Array of matrices representing sub-matrices
1149+ INTEGER (i4), INTENT (in ) :: nr ! < Number of row sub-matrices
1150+ INTEGER (i4), INTENT (in ) :: nc ! < Number of column sub-matrices
11511151CLASS(oft_cmatrix), POINTER , INTENT (inout ) :: mat
11521152DEBUG_STACK_PUSH
11531153SELECT TYPE (this= >mat)
@@ -1203,4 +1203,110 @@ SUBROUTINE create_identity_graph(outgraph,vec)
12031203outgraph% lc= [(i,i= 1 ,outgraph% nr)]
12041204DEBUG_STACK_POP
12051205END SUBROUTINE create_identity_graph
1206+ !- -----------------------------------------------------------------------------
1207+ ! > Create a tri-diagonal graph for a given vector
1208+ !- -----------------------------------------------------------------------------
1209+ SUBROUTINE create_tridiag_graph (outgraph ,vec ,periodic )
1210+ TYPE (oft_graph), POINTER , INTENT (inout ) :: outgraph ! < Resulting graph
1211+ CLASS(oft_vector), POINTER , INTENT (in ) :: vec ! < Vector representing matrix rows/columns
1212+ LOGICAL , INTENT (in ) :: periodic ! < Apply periodic BCs?
1213+ INTEGER (i4) :: i
1214+ DEBUG_STACK_PUSH
1215+ IF (vec% n< 3 )CALL oft_abort(' Vector size must be at least 3 for tridiagonal graph' , &
1216+ ' create_tridiag_graph' ,__FILE__)
1217+ !- --Setup graph
1218+ ALLOCATE (outgraph)
1219+ IF (periodic)THEN
1220+ outgraph% nnz= 3 * vec% n
1221+ ELSE
1222+ outgraph% nnz= 3 * vec% n-2
1223+ END IF
1224+ outgraph% nr= vec% n
1225+ outgraph% nrg= vec% ng
1226+ outgraph% nc= vec% n
1227+ outgraph% ncg= vec% ng
1228+ !- --Create indexing
1229+ ALLOCATE (outgraph% kr(outgraph% nr+1 ))
1230+ ALLOCATE (outgraph% lc(outgraph% nnz))
1231+ outgraph% kr(1 )= 1
1232+ IF (periodic)THEN
1233+ outgraph% lc(1 :3 )= [1 ,2 ,vec% n]
1234+ outgraph% kr(2 )= 4
1235+ ELSE
1236+ outgraph% lc(1 :2 )= [1 ,2 ]
1237+ outgraph% kr(2 )= 3
1238+ END IF
1239+ DO i= 2 ,vec% n-1
1240+ outgraph% lc(outgraph% kr(i):outgraph% kr(i)+ 2 )= [i-1 ,i,i+1 ]
1241+ outgraph% kr(i+1 )= outgraph% kr(i)+ 3
1242+ END DO
1243+ IF (periodic)THEN
1244+ outgraph% lc(outgraph% nnz-2 :outgraph% nnz)= [1 ,vec% n-1 ,vec% n]
1245+ ELSE
1246+ outgraph% lc(outgraph% nnz-1 :outgraph% nnz)= [vec% n-1 ,vec% n]
1247+ END IF
1248+ outgraph% kr(vec% n+1 )= outgraph% nnz+1
1249+ DEBUG_STACK_POP
1250+ END SUBROUTINE create_tridiag_graph
1251+ !- -----------------------------------------------------------------------------
1252+ ! > Create a dense graph for a given vector
1253+ !- -----------------------------------------------------------------------------
1254+ SUBROUTINE create_dense_graph (outgraph ,rvec ,cvec )
1255+ TYPE (oft_graph), POINTER , INTENT (inout ) :: outgraph ! < Resulting graph
1256+ CLASS(oft_vector), POINTER , INTENT (in ) :: rvec ! < Vector representing matrix rows
1257+ CLASS(oft_vector), POINTER , OPTIONAL , INTENT (in ) :: cvec ! < Vector representing matrix columns (optional)
1258+ INTEGER (i4) :: i,j
1259+ CLASS(oft_vector), POINTER :: vec2
1260+ DEBUG_STACK_PUSH
1261+ IF (PRESENT (cvec))THEN
1262+ vec2= >cvec
1263+ ELSE
1264+ vec2= >rvec
1265+ END IF
1266+ !- --Setup graph
1267+ ALLOCATE (outgraph)
1268+ outgraph% nnz= rvec% n* vec2% n
1269+ outgraph% nr= rvec% n
1270+ outgraph% nrg= rvec% ng
1271+ outgraph% nc= vec2% n
1272+ outgraph% ncg= vec2% ng
1273+ !- --Create indexing
1274+ ALLOCATE (outgraph% kr(outgraph% nr+1 ))
1275+ ALLOCATE (outgraph% lc(outgraph% nnz))
1276+ outgraph% kr(1 )= 1
1277+ DO i= 1 ,rvec% n
1278+ outgraph% kr(i+1 )= outgraph% kr(i)+ vec2% n
1279+ outgraph% lc(outgraph% kr(i):outgraph% kr(i+1 )- 1 )= [(j,j= 1 ,vec2% n)]
1280+ END DO
1281+ DEBUG_STACK_POP
1282+ END SUBROUTINE create_dense_graph
1283+ !- -----------------------------------------------------------------------------
1284+ ! > Create stitch and map structures for local vector
1285+ !- -----------------------------------------------------------------------------
1286+ SUBROUTINE create_local_stitch (stitch ,map ,n )
1287+ TYPE (oft_seam), INTENT (out ) :: stitch ! < Stitching object
1288+ TYPE (oft_map), INTENT (inout ) :: map ! < Map object
1289+ INTEGER (i4), INTENT (in ) :: n ! < Size of local vector
1290+ INTEGER (i4) :: i
1291+ DEBUG_STACK_PUSH
1292+ !- --Setup stitching object
1293+ stitch% nproc_con= 0
1294+ ALLOCATE (stitch% be(n),stitch% kle(0 :stitch% nproc_con+1 ))
1295+ stitch% full= .TRUE.
1296+ stitch% nbe= 0
1297+ stitch% be= .FALSE.
1298+ stitch% kle= 0
1299+ !- --Setup map
1300+ map% per= .FALSE.
1301+ map% offset= 0
1302+ map% n= n
1303+ map% ng= n
1304+ map% nslice= n
1305+ ALLOCATE (map% slice(map% nslice))
1306+ map% slice= [(i,i= 1 ,n)]
1307+ ALLOCATE (map% lge(map% n))
1308+ map% lge= [(i,i= 1 ,n)]
1309+ map% gbe= >stitch% be
1310+ DEBUG_STACK_POP
1311+ END SUBROUTINE create_local_stitch
12061312END MODULE oft_la_utils
0 commit comments