Hello,
I have a very basic question.
After the assembly of a linear system with matrix A and right hand side vector b, I want to insert changes in the matrix A.
To test the functions and methods I wrote this example, based on suggestions I found in this forum: https://answers.launchpad.net/dolfin/+question/190367
from dolfin import *
import numpy
set_log_level(ERROR)
parameters["linear_algebra_backend"] = 'PETSc'
# Create mesh and define function space
mesh = UnitSquareMesh(2,2)
V = FunctionSpace(mesh, 'Lagrange', 1)
# Define boundary conditions for initial guess
tol = 1E-14
def left_boundary(x, on_boundary):
return on_boundary and abs(x[0]) < tol
def right_boundary(x, on_boundary):
return on_boundary and abs(x[0]-1) < tol
Gamma_0 = DirichletBC(V, Constant(0.0), left_boundary)
Gamma_1 = DirichletBC(V, Constant(1.0), right_boundary)
bcs = [Gamma_0, Gamma_1]
# Define variational problem ans solve
u = TrialFunction(V)
v = TestFunction(V)
a = inner(nabla_grad(u), nabla_grad(v))*dx
f = Constant(0.0)
L = f*v*dx
A, b = assemble_system(a, L, bcs)
u_k = Function(V)
solve(A, u_k.vector(), b, 'lu')
print A
block = numpy.ones(2,dtype=numpy.float_)
print block
rows = numpy.array([0],dtype=numpy.uintc)
print rows
cols = numpy.array([1,2],dtype=numpy.uintc)
print cols
A.set(block,rows,cols)
When executed, I have the following error:
<Matrix wrapper of <PETScMatrix of size 9 x 9>>
[ 1. 1.]
[0]
[1 2]
Traceback (most recent call last):
File "set_matrix_ex.py", line 39, in <module>
A.set(block,rows,cols)
TypeError: contiguous numpy array of 'dolfin_index' expected. Make sure that the numpy array is contiguous, with 1 dimension, and uses dtype=intc.
Apparently there is a problem with the data type. I read all documentation I found and I cannot understand what I am doing wrong.
By the way, the matrix is of type "PETScMatrix" but I also try the "uBLAS" backend with the same error.
Thanks for your help!
Diego