This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

create matrix and vector for epetra

0 votes

I am trying to use run the tutorial with preconditioners and is needed PyTrilinos.
As they suggest I try to create the matrix and the vector to test the script, however the matrix representation of python an using numpy seems not to be currect format once is executed

as_backend_type(A)

How the matrix and the vector must be created?

here is what I tried with no good results.

# create matrix A and vector b in the usual way

#With numpy
import numpy as np

A = np.matrix('-2 1 2; -4 -1 -5; 2 -3 1 ')
b = np.array( [0, 4, 6])

#without numpy
#A = [ [-2, 1, 2], [-4, -1, -5], [2, -3, 1]]
#b =  [0, 4, 6]

# u is a Function


# Fetch underlying Epetra objects
A_epetra = as_backend_type(A).mat()
b_epetra = as_backend_type(b).vec()
U_epetra = as_backend_type(u.vector()).vec()

And this is the error

Traceback (most recent call last):
  File "test.py", line 43, in <module>
    A_epetra = as_backend_type(A).mat()
  File "Work/FEniCS/lib/python2.7/site-packages/dolfin/cpp/la.py", line 5441, in    as_backend_type
    subclass = get_tensor_type(tensor)
  File "Work/FEniCS/lib/python2.7/site-packages/dolfin/cpp/la.py", line 5423, in   get_tensor_type
    if v(tensor):
TypeError: in method '_has_type_PETScVector', argument 1 of type 'std::shared_ptr<  dolfin::GenericTensor > const'
asked Jul 13, 2014 by user478 FEniCS Novice (230 points)
edited Jul 15, 2014 by user478
...