@@ -1535,15 +1535,17 @@ subroutine dsm_wrapper(me,n,m,info)
1535
1535
integer ,intent (out ) :: info ! ! status output from [[dsm]]
1536
1536
1537
1537
integer :: mingrp ! ! for call to [[dsm]]
1538
- integer ,dimension (m+1 ) :: ipntr ! ! for call to [[dsm]]
1539
- integer ,dimension (n+1 ) :: jpntr ! ! for call to [[dsm]]
1540
- integer ,dimension (:),allocatable :: irow ! ! for call to [[dsm]]
1541
- ! ! (temp copy since [[dsm]]
1542
- ! ! will modify it)
1543
- integer ,dimension (:),allocatable :: icol ! ! for call to [[dsm]]
1544
- ! ! (temp copy since [[dsm]]
1545
- ! ! will modify it)
1546
-
1538
+ integer ,dimension (:),allocatable :: ipntr ! ! for call to [[dsm]]
1539
+ integer ,dimension (:),allocatable :: jpntr ! ! for call to [[dsm]]
1540
+ integer ,dimension (:),allocatable :: irow ! ! for call to [[dsm]]
1541
+ ! ! (temp copy since [[dsm]]
1542
+ ! ! will modify it)
1543
+ integer ,dimension (:),allocatable :: icol ! ! for call to [[dsm]]
1544
+ ! ! (temp copy since [[dsm]]
1545
+ ! ! will modify it)
1546
+
1547
+ allocate (ipntr(m+1 ))
1548
+ allocate (jpntr(n+1 ))
1547
1549
allocate (me% ngrp(n))
1548
1550
irow = me% irow
1549
1551
icol = me% icol
@@ -1659,7 +1661,7 @@ end subroutine compute_indices
1659
1661
! @note If specifying the linear pattern, all three optional arguments
1660
1662
! must be present.
1661
1663
1662
- subroutine set_sparsity_pattern (me ,irow ,icol ,linear_irow ,linear_icol ,linear_vals )
1664
+ subroutine set_sparsity_pattern (me ,irow ,icol ,linear_irow ,linear_icol ,linear_vals , maxgrp , ngrp )
1663
1665
1664
1666
implicit none
1665
1667
@@ -1669,6 +1671,10 @@ subroutine set_sparsity_pattern(me,irow,icol,linear_irow,linear_icol,linear_vals
1669
1671
integer ,dimension (:),intent (in ),optional :: linear_irow ! ! linear sparsity pattern nonzero elements row indices
1670
1672
integer ,dimension (:),intent (in ),optional :: linear_icol ! ! linear sparsity pattern nonzero elements column indices
1671
1673
real (wp),dimension (:),intent (in ),optional :: linear_vals ! ! linear sparsity values (constant elements of the Jacobian)
1674
+ integer ,intent (in ),optional :: maxgrp ! ! DSM sparsity partition
1675
+ ! ! [only used if `me%partition_sparsity_pattern=True`]
1676
+ integer ,dimension (:),intent (in ),optional :: ngrp ! ! DSM sparsity partition (size `n`)
1677
+ ! ! [only used if `me%partition_sparsity_pattern=True`]
1672
1678
1673
1679
integer :: info ! ! status output form [[dsm]]
1674
1680
@@ -1689,11 +1695,23 @@ subroutine set_sparsity_pattern(me,irow,icol,linear_irow,linear_icol,linear_vals
1689
1695
1690
1696
call me% sparsity% compute_indices()
1691
1697
if (me% partition_sparsity_pattern) then
1692
- call me% sparsity% dsm_wrapper(me% n,me% m,info)
1693
- if (info/= 1 ) then
1694
- call me% raise_exception(16 ,' set_sparsity_pattern' ,&
1695
- ' error partitioning sparsity pattern.' )
1696
- return
1698
+ if (present (maxgrp) .and. present (ngrp)) then
1699
+ ! use the user-input partition:
1700
+ if (maxgrp> 0 .and. all (ngrp>= 1 .and. ngrp<= maxgrp) .and. size (ngrp)==me% n) then
1701
+ me% sparsity% maxgrp = maxgrp
1702
+ me% sparsity% ngrp = ngrp
1703
+ else
1704
+ call me% raise_exception(28 ,' set_sparsity_pattern' ,&
1705
+ ' invalid sparsity partition inputs.' )
1706
+ return
1707
+ end if
1708
+ else
1709
+ call me% sparsity% dsm_wrapper(me% n,me% m,info)
1710
+ if (info/= 1 ) then
1711
+ call me% raise_exception(16 ,' set_sparsity_pattern' ,&
1712
+ ' error partitioning sparsity pattern.' )
1713
+ return
1714
+ end if
1697
1715
end if
1698
1716
end if
1699
1717
@@ -2163,7 +2181,9 @@ end subroutine compute_sparsity_pattern
2163
2181
! Returns the sparsity pattern from the class.
2164
2182
! If it hasn't been computed, the output arrays will not be allocated.
2165
2183
2166
- subroutine get_sparsity_pattern (me ,irow ,icol ,linear_irow ,linear_icol ,linear_vals )
2184
+ subroutine get_sparsity_pattern (me ,irow ,icol ,&
2185
+ linear_irow ,linear_icol ,linear_vals ,&
2186
+ maxgrp ,ngrp )
2167
2187
2168
2188
implicit none
2169
2189
@@ -2176,6 +2196,8 @@ subroutine get_sparsity_pattern(me,irow,icol,linear_irow,linear_icol,linear_vals
2176
2196
! ! elements column indices
2177
2197
real (wp),dimension (:),allocatable ,intent (out ),optional :: linear_vals ! ! linear sparsity values (constant
2178
2198
! ! elements of the Jacobian)
2199
+ integer ,intent (out ),optional :: maxgrp ! ! DSM sparsity partition
2200
+ integer ,dimension (:),allocatable ,intent (out ),optional :: ngrp ! ! DSM sparsity partition
2179
2201
2180
2202
if (me% exception_raised) return ! check for exceptions
2181
2203
@@ -2195,6 +2217,10 @@ subroutine get_sparsity_pattern(me,irow,icol,linear_irow,linear_icol,linear_vals
2195
2217
if (allocated (me% sparsity% linear_vals)) linear_vals = me% sparsity% linear_vals
2196
2218
end if
2197
2219
2220
+ ! optional DSM partition:
2221
+ if (present (ngrp) .and. allocated (me% sparsity% ngrp)) ngrp = me% sparsity% ngrp
2222
+ if (present (maxgrp)) maxgrp = me% sparsity% maxgrp
2223
+
2198
2224
end subroutine get_sparsity_pattern
2199
2225
! *******************************************************************************
2200
2226
0 commit comments