[petsc-users] Elementwise pow/exponential-function on PETSc-vectors and matrices
Barry Smith
bsmith at petsc.dev
Tue Jan 5 18:44:49 CST 2021
Use VecGetArray() and then loop over the array entries performing whatever element operations you like.
For dense matrices use MatDenseGetArray() and loop over the entries. For sequential AIJ matrices uses MatSeqAIJGetArray() For MPIAIJ use MatMPIAIJGetSeqAIJ() then use MatSeqAIJGetArray on each of the two matrices.
Barry
> On Jan 5, 2021, at 9:24 AM, Roland Richter <roland.richter at ntnu.no> wrote:
>
> Hei,
>
> is there a function to square/cube etc. each element of a matrix or
> vector in PETSc? It is rather useful for things like intensity
> calculations (I = |E|^2), and should work also for distributed matrices.
>
> Thanks!
>
> Regards,
>
> Roland Richter
>
More information about the petsc-users
mailing list