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

How to make a dolfin.cpp.la.Matrix

0 votes

First, I will give my code:

mesh = UnitCubeMesh(10, 10, 10)
V = VectorFunctionSpace(mesh, 'P', 1)
u = TrialFunction(V)
v = TestFunction(V)
a = dot(u, v)*dx
stif = assemble(a)
print(type(stif))
b = Vector(mesh.mpi_comm(), 10)
print(type(b))
c = Matrix(mesh.mpi_comm(), 10, 10)
print(type(c))

I have successfully created a dolfin.cpp.la.Vector b. However, when I create a dolfin.cpp.la.Matrix c, FEniCS tells me that:

c = Matrix(mesh.mpi_comm(), 10, 10)   File "/usr/lib/python2.7/dist-packages/dolfin/cpp/la.py", line 3934, in __init__
_la.Matrix_swiginit(self, _la.new_Matrix(*args)) NotImplementedError: Wrong number or type of arguments for overloaded

function 'new_Matrix'. Possible C/C++ prototypes are:
dolfin::Matrix::Matrix(MPI_Comm)
dolfin::Matrix::Matrix()
dolfin::Matrix::Matrix(dolfin::Matrix const &)
dolfin::Matrix::Matrix(dolfin::GenericMatrix const &)

Aborted (core dumped)

So my question is, how to create the Matrix c correctly.
Thank you.

asked Jun 5, 2017 by xuanyuan9288 FEniCS Novice (290 points)

1 Answer

0 votes

I don't know how to use the generic interface to create a Matrix since it lacks a method to set the sizes, but for PETSc the process looks like this.

You can wrap the PETSc matrix into a FEniCS Matrix wrapper with:

from dolfin import PETScMatrix
M = PETScMatrix(A)
answered Jun 5, 2017 by mdbenito FEniCS User (4,530 points)
...