Skip to content

Commit

Permalink
initialize dual array
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Mar 28, 2024
1 parent 8e65c6f commit 33b8b39
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/forwarddiff_dual.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module forwarddiff_dual
private

public :: dual
public :: initialize_dual_array

public :: assignment (=)
public :: operator (+), operator (-)
Expand All @@ -26,6 +27,12 @@ module forwarddiff_dual
interface dual
module procedure :: create_dual1
end interface

interface initialize_dual_array
module procedure :: initialize_dual_array_1
module procedure :: initialize_dual_array_2
module procedure :: initialize_dual_array_3
end interface

!~~~ operator overloading ~~~!

Expand Down Expand Up @@ -216,6 +223,39 @@ function create_dual1(ndv) result(b)
allocate(b%der(ndv))
end function

subroutine initialize_dual_array_1(arr, ndv)
type(dual), intent(inout) :: arr(:)
integer, intent(in) :: ndv
integer :: i
do i = 1,size(arr)
allocate(arr(i)%der(ndv))
enddo
end subroutine

subroutine initialize_dual_array_2(arr, ndv)
type(dual), intent(inout) :: arr(:,:)
integer, intent(in) :: ndv
integer :: i, j
do i = 1,size(arr,2)
do j = 1,size(arr,1)
allocate(arr(j,i)%der(ndv))
enddo
enddo
end subroutine

subroutine initialize_dual_array_3(arr, ndv)
type(dual), intent(inout) :: arr(:,:,:)
integer, intent(in) :: ndv
integer :: i, j, k
do i = 1,size(arr,3)
do j = 1,size(arr,2)
do k = 1,size(arr,1)
allocate(arr(k,j,i)%der(ndv))
enddo
enddo
enddo
end subroutine

!~~~ assignment ~~~!

elemental subroutine assign_di(u, i)
Expand Down

0 comments on commit 33b8b39

Please sign in to comment.