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

PETScMatrix object has no attribute resize

0 votes

When I run the following code

temp = PETScMatrix()
temp.resize((10,10))

I get the following error message:

'PETScMatrix' object has no attribute 'resize'

Any suggestions as to why this is happening?

closed with the note: Real problem is that I am having problems with petsc4py
asked Jun 14, 2016 by sarah FEniCS Novice (430 points)
closed Jun 16, 2016 by sarah

1 Answer

+1 vote

You should access the underlying PETSc object and use the PETSc interface to modify the matrix manually. I think the fenics API was specifically intended not to re-invent the underlying linear algebra back-end's functionalities.

answered Jun 14, 2016 by Massimiliano Leoni FEniCS User (1,760 points)

Thanks for your help!

I am having trouble accessing the underlying PETSc object. What is the best way to do that?
It appears that the available attributes I have for temp are
temp.add
temp.add_local
temp.apply
temp.array
temp.assign
temp.axpy
temp.binary_dump
temp.copy
temp.empty
temp.factory
temp.get
temp.get_diagonal
temp.get_options_prefix
temp.getrow
temp.id
temp.ident
temp.ident_local
temp.ident_zeros
temp.init
temp.init_vector
temp.is_symmetric
temp.label
temp.local_range
temp.mat
temp.mpi_comm
temp.mult
temp.name
temp.nnz
temp.norm
temp.parameters
temp.petsc_error
temp.rank
temp.rename
temp.set
temp.set_diagonal
temp.set_local
temp.set_nullspace
temp.set_options_prefix
temp.setrow
temp.shared_instance
temp.size
temp.str
temp.this
temp.thisown
temp.transpmult
temp.zero
temp.zero_local

After I import petsc4py and petsc, if I instead try to create a PETSc object I get the message
'name 'PETSc' is not defined'

The mat method returns a pointer to a PETSc matrix object of type Mat, similarly for vectors.

Since you are using PETSc4py, it will be slightly different from what happens in C++.
A personal hint: download the petsc4py code and use its comments as documentation [or the imported python package if docstrings are set correctly] since the online documentation is empty.

Thanks for your help!

...