[petsc-users] about Vecgetarray()

陈乐平(Leping Chen) chenleping at yahoo.cn
Fri Apr 16 09:38:33 CDT 2010


  petsc teams,
      
       PetscOffset xx_i
       Vec         x
       double precision u(6) 
       
        call VecGetArray(x,u,xx_i,ierr)
        do 30 i=1,n
          u(i) = 1000.0*i
  30   continue
       call VecRestoreArray(x,u,xx_i,ierr)

I don't understand why x cannot be changed when u() has been changed?
how can I do it?
the output are as follows,
x vector:
10
20
30
40
50
60
u() array
1000
2000
3000
4000
5000
6000
thanks,
leping
  



发件人: Matthew Knepley 
发送时间: 2010-04-17  22:15:24 
收件人: chenleping; PETSc users list 
抄送: 
主题: Re: [petsc-users] about Vecgetarray() 
2010/4/16 陈乐平(Leping Chen) <chenleping at yahoo.cn>

petsc teams,

if I want create the relation between u() [array] and x [Vec] ,I can do it as follows,

#define u(ib)  xx_v(xx_i + (ib)) 
       call VecGetArray(x,xx_v,xx_i,ierr)
       do 30 i=1,n
          u(i) = 1000.0*i
  30   continue
       call VecRestoreArray(x,xx_v,xx_i,ierr)

However, I don't understand why can not I do it as follows,

      double precision u(1) or u(6)
       call VecGetArray(x,u,xx_i,ierr)
       do 30 i=1,n
          u(i) = 1000.0*i
  30   continue
       call VecRestoreArray(x,u,xx_i,ierr)

 Why u() must be created by #define, and u() cannot be defined again,for example "double precision u(1)" or u(5).


1) It does not have to be #define. This is shown for convenience.


2) You must still declare xx_v in your first example, probably exactly as you
    declare u in your second example.


These are not PETSc questions. They are basic Fortran programming questions.
There are many excellent books on this.


    Matt


By the way, if u() is a array of common blocks(fortran), how can I create the relation between u() and x?

thanks,

Leping 



 2010-04-16




-- 
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/20100416/59b02657/attachment.htm>


More information about the petsc-users mailing list