Skip to content

Commit e092d5d

Browse files
committed
Merge branch '6-user-partition' of https://github.com/jacobwilliams/NumDiff into develop
2 parents 450260f + 840fe35 commit e092d5d

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

src/numerical_differentiation_module.f90

+42-16
Original file line numberDiff line numberDiff line change
@@ -1535,15 +1535,17 @@ subroutine dsm_wrapper(me,n,m,info)
15351535
integer,intent(out) :: info !! status output from [[dsm]]
15361536

15371537
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))
15471549
allocate(me%ngrp(n))
15481550
irow = me%irow
15491551
icol = me%icol
@@ -1659,7 +1661,7 @@ end subroutine compute_indices
16591661
!@note If specifying the linear pattern, all three optional arguments
16601662
! must be present.
16611663

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)
16631665

16641666
implicit none
16651667

@@ -1669,6 +1671,10 @@ subroutine set_sparsity_pattern(me,irow,icol,linear_irow,linear_icol,linear_vals
16691671
integer,dimension(:),intent(in),optional :: linear_irow !! linear sparsity pattern nonzero elements row indices
16701672
integer,dimension(:),intent(in),optional :: linear_icol !! linear sparsity pattern nonzero elements column indices
16711673
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`]
16721678

16731679
integer :: info !! status output form [[dsm]]
16741680

@@ -1689,11 +1695,23 @@ subroutine set_sparsity_pattern(me,irow,icol,linear_irow,linear_icol,linear_vals
16891695

16901696
call me%sparsity%compute_indices()
16911697
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
16971715
end if
16981716
end if
16991717

@@ -2163,7 +2181,9 @@ end subroutine compute_sparsity_pattern
21632181
! Returns the sparsity pattern from the class.
21642182
! If it hasn't been computed, the output arrays will not be allocated.
21652183

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)
21672187

21682188
implicit none
21692189

@@ -2176,6 +2196,8 @@ subroutine get_sparsity_pattern(me,irow,icol,linear_irow,linear_icol,linear_vals
21762196
!! elements column indices
21772197
real(wp),dimension(:),allocatable,intent(out),optional :: linear_vals !! linear sparsity values (constant
21782198
!! elements of the Jacobian)
2199+
integer,intent(out),optional :: maxgrp !! DSM sparsity partition
2200+
integer,dimension(:),allocatable,intent(out),optional :: ngrp !! DSM sparsity partition
21792201

21802202
if (me%exception_raised) return ! check for exceptions
21812203

@@ -2195,6 +2217,10 @@ subroutine get_sparsity_pattern(me,irow,icol,linear_irow,linear_icol,linear_vals
21952217
if (allocated(me%sparsity%linear_vals)) linear_vals = me%sparsity%linear_vals
21962218
end if
21972219

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+
21982224
end subroutine get_sparsity_pattern
21992225
!*******************************************************************************
22002226

0 commit comments

Comments
 (0)