[petsc-users] Averaging 3D DA global vector

Ilyas YILMAZ ilyascfd at gmail.com
Fri Apr 29 07:12:50 CDT 2016


Hello,

Somewhere in my code, I need to take spatial average of a global vector
created by 3D DA context and store it into another global vector.
It is like X3D(streamwise,normalwise,spanwise) --> Y3D(0,normalwise,0). It
is very easy to do serially in Fortran, for example,

         tot = (ni-2)*(nk-2)

         do k= 2,nkm1
         do j= 2,njm1
         do i= 2,nim1

            su(2,j,2)=su(2,j,2)+cs(i,j,k)/float(tot)

         end do
         end do
         end do

What could be the most efficient way of doing this in PETSC?

or Is it possible to do as follows using ADD_VALUES?

mxmz = mx*mz

do k=zs,zs+zm-1
        do j=ys,ys+ym-1
                do i=xs,xs+xm-1

                 row  = i   - gxs + (j - gys)*gxm  + (k - gzs)*gxm*gym + 1
                 rowj = xs - gxs + (j - gys)*gxm  + (zs - gzs)*gxm*gym + 1

                scaX3DAVE(idX3DAVE+*rowj*) =  scaX3DAVE(idX3DAVE+*rowj*) +
 scaX3D(idX3D+*row*)/float(mx*mz)

                end do
        end do
end do

call VecRestoreArray()
call DALocaltoGlobal(da,localX3DAVE,*ADD_VALUES*,X3DAVE,ierr)


Thanks.

IY
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160429/9bfff69c/attachment.html>


More information about the petsc-users mailing list