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

Using the zero() function and setting the values of a matrix to zero

0 votes

Hi.

I try to use the following zero() function, see below: https://fenicsproject.org/documentation/dolfin/1.0.1/python/programmers-reference/cpp/GenericMatrix.html

Therefore I wrote a short example:

from dolfin import *
import numpy

mesh = UnitSquareMesh(50,50)
F = FunctionSpace(mesh, "Lagrange", 1)
x = TrialFunction(F)
y = TestFunction(F)

m = inner(grad(x),grad(y))*dx
M = assemble(m)

n = F.dim()
d = mesh.geometry().dim()
dof = F.tabulate_dof_coordinates().reshape(n,d)

o = numpy.array([], dtype=np.intc)
for i in xrange(0, len(dof)):
   if (i%100==0):
      u = numpy.array([i], dtype=np.intc)
      o = numpy.append(o, u)

n = len(o)
M.zero(n, o)

I receive the following error:
NotImplementedError: Wrong number or type of arguments for overloaded function 'Matrix_zero'.
Unfortunately, I have no idea how to solve it.

asked Nov 18, 2016 by MatheMagie FEniCS Novice (250 points)
edited Nov 18, 2016 by MatheMagie

1 Answer

0 votes

Try

M.zero_local(o)
answered Nov 25, 2016 by Brendan FEniCS Novice (890 points)

I figured out, how it works:

M.zero(o)

But thank you!

...