[petsc-users] Averaging 3D DA global vector

Matthew Knepley knepley at gmail.com
Fri Apr 29 09:04:04 CDT 2016


On Fri, Apr 29, 2016 at 7:12 AM, Ilyas YILMAZ <ilyascfd at gmail.com> wrote:

> 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,
>

You can write the same code with DMDAVecGetArray().

  Thanks,

    Matt


>          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
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160429/35f50ad1/attachment.html>


More information about the petsc-users mailing list