Re: [petsc-users] Fwd: what is the equivalent DMDAVecRestoreArray() function in petsc4py?

2018-02-15 Thread Jed Brown
HeeHo Park  writes:

> Yes, this works.
>
> u = da.getVecArray(U)
> for i in range(mstart, mend):
> u[i] = np.sin(np.pi*i*6.*h) + 3.*np.sin(np.pi*i*2.*h)
>
> The code above also worked without restoreVecArray. I guess the u just
> points at the array U.

It won't be restored until u goes out of scope, and even that would
depend on the Python implementation.  Use the "with" context manager.


Re: [petsc-users] Fwd: what is the equivalent DMDAVecRestoreArray() function in petsc4py?

2018-02-15 Thread HeeHo Park
Yes, this works.

u = da.getVecArray(U)
for i in range(mstart, mend):
u[i] = np.sin(np.pi*i*6.*h) + 3.*np.sin(np.pi*i*2.*h)

The code above also worked without restoreVecArray. I guess the u just
points at the array U.
I think your code is clearer to understand what is happening.

Thank you,


On Wed, Feb 14, 2018 at 5:57 PM, Matthew Knepley  wrote:

> On Wed, Feb 14, 2018 at 6:05 PM, HeeHo Park  wrote:
>
>> I just found a user group on PETSc website. Can someone please answer the
>> question below?
>>
>
> I think it will work using
>
>   with da.getVecArray(U) as u
> for i in range(mstart, mend):
> u[i] = np.sin(np.pi*i*6.*h) + 3.*np.sin(np.pi*i*2.*h)
>
> Does it?
>
>   Thanks,
>
>  Matt
>
> Thanks!
>>
>> -- Forwarded message --
>> From: HeeHo Park 
>> Date: Wed, Feb 14, 2018 at 5:04 PM
>> Subject: what is the equivalent DMDAVecRestoreArray() function in
>> petsc4py?
>> To: dalc...@gmail.com
>>
>>
>> Hi Lisandro,
>>
>> I cannot find DMDAVecRestoreArray() equivalent in petsc4py.
>> I'm trying to set a 1D initial condition like this.
>>
>> def initial_conditions(ts, U, appctx):
>> da = ts.getDM()
>> mstart,xm = da.getCorners()
>> mstart = mstart[0]
>> xm = xm[0]
>> M = da.getSizes()[0]
>> h = 1.0/M
>> mend = mstart + xm
>>
>> u = da.getVecArray(U)
>> for i in range(mstart, mend):
>> u[i] = np.sin(np.pi*i*6.*h) + 3.*np.sin(np.pi*i*2.*h)
>>
>> da.getVecRestoreArray(u)
>>
>> Also, is there a better way to ask questions about petsc4py? a forum? or
>> google-group?
>>
>> Thanks,
>>
>> --
>> HeeHo Daniel Park
>>
>>
>>
>> --
>> HeeHo Daniel Park
>>
>
>
>
> --
> 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
>
> https://www.cse.buffalo.edu/~knepley/ 
>



-- 
HeeHo Daniel Park


Re: [petsc-users] Fwd: what is the equivalent DMDAVecRestoreArray() function in petsc4py?

2018-02-14 Thread Matthew Knepley
On Wed, Feb 14, 2018 at 6:05 PM, HeeHo Park  wrote:

> I just found a user group on PETSc website. Can someone please answer the
> question below?
>

I think it will work using

  with da.getVecArray(U) as u
for i in range(mstart, mend):
u[i] = np.sin(np.pi*i*6.*h) + 3.*np.sin(np.pi*i*2.*h)

Does it?

  Thanks,

 Matt

Thanks!
>
> -- Forwarded message --
> From: HeeHo Park 
> Date: Wed, Feb 14, 2018 at 5:04 PM
> Subject: what is the equivalent DMDAVecRestoreArray() function in petsc4py?
> To: dalc...@gmail.com
>
>
> Hi Lisandro,
>
> I cannot find DMDAVecRestoreArray() equivalent in petsc4py.
> I'm trying to set a 1D initial condition like this.
>
> def initial_conditions(ts, U, appctx):
> da = ts.getDM()
> mstart,xm = da.getCorners()
> mstart = mstart[0]
> xm = xm[0]
> M = da.getSizes()[0]
> h = 1.0/M
> mend = mstart + xm
>
> u = da.getVecArray(U)
> for i in range(mstart, mend):
> u[i] = np.sin(np.pi*i*6.*h) + 3.*np.sin(np.pi*i*2.*h)
>
> da.getVecRestoreArray(u)
>
> Also, is there a better way to ask questions about petsc4py? a forum? or
> google-group?
>
> Thanks,
>
> --
> HeeHo Daniel Park
>
>
>
> --
> HeeHo Daniel Park
>



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

https://www.cse.buffalo.edu/~knepley/