Hi.
I'm working with 1D and 2D f90 arrays. Actually, for a fixed value of a
looping/iteration index, I have to form a 2D (dimension(6,6) )
array that holds some Jacobian matrix. Calling this iteration counter i,
where i ranges from 0 to n (say n=5000), this means I need to compute
the 6x6 Jacobian matrices (n+1) times.
In order to store ALL the Jacobian matrices, I have thought of defining
a new 3D array - dimension(1:6, 1:6, 0:n) . To fill out the 3D array, I
want to use one of the two ways shown in the following piece/extract of
code. What I then want to know is: (i) are these valid ways of doing what
I mean to do? (ii) if yes, which one would be more preferable?
In subsequent stages of my work, I will need the 6x6 2D jacobians per
slice of i. I would be happy if I could also get suggestions on how to
retrieve that. Would I need the "reshape" intrinsic function for that?
Your help will be highly appreciated.
I'm working with 1D and 2D f90 arrays. Actually, for a fixed value of a
looping/iteration index, I have to form a 2D (dimension(6,6) )
array that holds some Jacobian matrix. Calling this iteration counter i,
where i ranges from 0 to n (say n=5000), this means I need to compute
the 6x6 Jacobian matrices (n+1) times.
In order to store ALL the Jacobian matrices, I have thought of defining
a new 3D array - dimension(1:6, 1:6, 0:n) . To fill out the 3D array, I
want to use one of the two ways shown in the following piece/extract of
code. What I then want to know is: (i) are these valid ways of doing what
I mean to do? (ii) if yes, which one would be more preferable?
In subsequent stages of my work, I will need the 6x6 2D jacobians per
slice of i. I would be happy if I could also get suggestions on how to
retrieve that. Would I need the "reshape" intrinsic function for that?
Code:
..........
real, dimension(-1:n+1) :: u1, u2, u3, u4, u5, u6
real, dimension(-1:n+1) :: fun1, fun2, fun3, fun4, fun5, fun6
real, dimension(1:6, -1:n+1) :: fun_tmp, u_tmp
real, dimension(1:6, 0:n) :: dfun, du
real, dimension(1:6,1:6) :: jac_slice
real, dimension(1:6, 1:6, 0:n) :: jac
integer :: i, k
! Fill fun_tmp by rows
fun_tmp(1, -1:n+1) = fun1 ; fun_tmp(2, -1:n+1) = fun2
fun_tmp(3, -1:n+1) = fun3 ; fun_tmp(4, -1:n+1) = fun4
fun_tmp(5, -1:n+1) = fun5 ; fun_tmp(6, -1:n+1) = fun6
! Fill up u_tmp by rows
u_tmp(1, -1:n+1) = u1 ; u_tmp(2, -1:n+1) = u2
u_tmp(3, -1:n+1) = u3 ; u_tmp(4, -1:n+1) = u4
u_tmp(5, -1:n+1) = u5 ; u_tmp(6, -1:n+1) = u6
! Compute central differences for fun_tmp and u_tmp
dfun = fun_tmp(:, 1:) - fun_tmp(:, :n-1) ! 6x(n+1) - 2D array
du = u_tmp(:, 1:) - u_tmp(:, :n-1) ! 6x(n+1) - 2D array
!!! Now compute & store 6x6x(n+1) 3D array---The part I need HELP on!!!
! Option 1: Loop over all Jacobians for all "slices" of i in one stage
do i = 0, n
do k = 1, 6 ! loop over columns of "jac" matrix
jac(:, k, i) = dfun(:, i) / du(k, i) ! Fill matrix column-wise
end do
end do
! Option 2: Loop over ONE 6x6 2D Jacobian per slice of i (internal loop),
! then store it & proceed to next slice
do i = 0, n
do k = 1, 6
jac_slice(:, k) = dfun(:, i) / du(k, i)
end do
jac(1:6, 1:6, i) = jac_slice(1:6, 1:6)
end do
..............
Your help will be highly appreciated.