CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   multi-dimensional dynamic array allocation for multi-block solver using fortran (https://www.cfd-online.com/Forums/main/103700-multi-dimensional-dynamic-array-allocation-multi-block-solver-using-fortran.html)

 mano June 24, 2012 04:48

multi-dimensional dynamic array allocation for multi-block solver using fortran

I am converting my CFD solver to multi-block solver. I had used dynamic array allocation for the single block solver, but for multi-block, the dynamic array allocation syntax is not clear to me. I tried a sample code, but end up in error "Error: Expression at (1) must be scalar". I also don't know how to pass the multi dimensional allocated array to subroutines. Please, suggest solution, regards
common/iteration/nb
integer, dimension (:),allocatable::nib,njb,nkb
real, dimension (:,:,:,:),allocatable::x,y,z
allocate (nib(nb),njb(nb),nkb(nb))
do l=1,nb
ni=nib(l)
nj=njb(l)
nk=nkb(l)
allocate (x(l,ni,nj,nk),y(l,ni,nj,nk),z(l,ni,nj,nk))
enddo
call gridatt (x,y,z,nib,njb,nkb)
deallocate(x,y,z,nib,njb,nkb)
end
c
subroutine gridatt (x,y,z,nib,njb,nkb)
common/iteration/nb
integer, dimension (nb)::nib,njb,nkb
real, dimension (nb,nib,njb,nkb)::x,y,z
return
end

you can not declare an array with variable values for different indexes. thry should be fixed values. i know in this way you waist some amount of memory but there is no way ( as i know). your code should be like this:

common/iteration/nb
integer, dimension ( : ),allocatable::nib,njb,nkb
real, dimension (:,:,:,: ),allocatable::x,y,z
allocate (nib(nb),njb(nb),nkb(nb))
c calculate maximum value of ni, nj and nk in all blocks and store them in MaxNi,MaxNj and MaxNk respectively
allocate(x(nb,MaxNi,MaxNj,MaxNk),y(nb,MaxNi,MaxNj, MaxNk),z(nb,MaxNi,MaxNj,MaxNk))
call gridatt (x,y,z,MaxNi,MaxNj,MaxNk)
deallocate(x,y,z,nib,njb,nkb)
end
c
subroutine gridatt (x,y,z,MaxNi,MaxNj,MaxNk)
common/iteration/nb
integer, dimension (nb)::MaxNi,MaxNj,MaxNk
real, dimension (nb,MaxNi,MaxNj,MaxNk)::x,y,z
return
end

 mano June 25, 2012 10:24