Skip to content

Commit 425ef71

Browse files
committed
added routine to change bounds.
1 parent f50ffcc commit 425ef71

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

src/numerical_differentiation_module.f90

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ module numerical_differentiation_module
172172
!! when by the perturbations.
173173
procedure,public :: select_finite_diff_method_for_partition_group !! version of [[select_finite_diff_method]]
174174
!! for partitioned sparsity pattern.
175+
procedure,public :: set_numdiff_bounds !! can be called to change the variable bounds.
175176

176177
! internal routines:
177178
procedure :: destroy_sparsity_pattern !! destroy the sparsity pattern
@@ -778,6 +779,39 @@ subroutine initialize_numdiff_for_diff(me,n,m,xlow,xhigh,&
778779
end subroutine initialize_numdiff_for_diff
779780
!*******************************************************************************
780781

782+
!*******************************************************************************
783+
!>
784+
! Change the variable bounds in a [[numdiff_type]].
785+
!
786+
!@note The bounds must be set when the class is initialized,
787+
! but this routine can be used to change them later if required.
788+
789+
subroutine set_numdiff_bounds(me,xlow,xhigh)
790+
791+
implicit none
792+
793+
class(numdiff_type),intent(inout) :: me
794+
real(wp),dimension(:),intent(in) :: xlow !! lower bounds on `x`
795+
real(wp),dimension(:),intent(in) :: xhigh !! upper bounds on `x`
796+
797+
if (size(xlow)/=me%n .or. size(xhigh)/=me%n) then
798+
error stop 'error in set_numdiff_bounds: invalid size of xlow or xhigh'
799+
else if (any(xlow>=xhigh)) then
800+
error stop 'Error: all xlow must be < xhigh'
801+
else
802+
803+
if (allocated(me%xlow)) deallocate(me%xlow)
804+
if (allocated(me%xhigh)) deallocate(me%xhigh)
805+
allocate(me%xlow(me%n))
806+
allocate(me%xhigh(me%n))
807+
me%xlow = xlow
808+
me%xhigh = xhigh
809+
810+
end if
811+
812+
end subroutine set_numdiff_bounds
813+
!*******************************************************************************
814+
781815
!*******************************************************************************
782816
!>
783817
! Initialize a [[numdiff_type]] class. This must be called first.
@@ -1003,8 +1037,6 @@ subroutine columns_in_partition_group(me,igroup,n_cols,cols,nonzero_rows,indices
10031037
!! (if none, then it is not allocated)
10041038
integer,dimension(:),allocatable,intent(out) :: nonzero_rows !! the row numbers of all the nonzero
10051039
!! Jacobian elements in this group
1006-
!! note: can contain duplicate indices, since
1007-
!! a function can depend on more than one variable
10081040
integer,dimension(:),allocatable,intent(out) :: indices !! nonzero indices in `jac` for a group
10091041

10101042
integer :: i !! counter

0 commit comments

Comments
 (0)