File: del2mat.py

package info (click to toggle)
petsc4py 3.23.1-1exp2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,448 kB
  • sloc: python: 12,503; ansic: 1,697; makefile: 343; f90: 313; sh: 14
file content (34 lines) | stat: -rw-r--r-- 839 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# file: del2mat.py

from numpy import zeros
from del2lib import del2apply

class Del2Mat:

    def __init__(self, n=1):
        self.N = (n, n, n)
        self.F = zeros([n+2]*3, order='f')

    def create(self, A):
        N = self.N
        mat_size = A.getSize()
        grid_eqs = N[0]*N[1]*N[2]
        assert mat_size[0] == grid_eqs
        assert mat_size[1] == grid_eqs

    def mult(self, A, x, y):
        "y <- A * x"
        N, F = self.N, self.F
        # get 3D arrays from vectos
        xx = x.getArray(readonly=1).reshape(N, order='f')
        yy = y.getArray(readonly=0).reshape(N, order='f')
        # call Fortran subroutine
        del2apply(F, xx, yy)

    def multTranspose(self, A, x, y):
        "y <- A' * x"
        self.mult(x, y)

    def getDiagonal(self, A, D):
        "D[i] <- A[i,i]"
        D[...] = 6.0