Change coefficient of an assembled matrix

Asked by Bruno Luna

Hi all,

I am trying to implement a well model in a program for biphasic flow in porous media.
I assemble the matrix for the potential (pressure) problem as below:

 def Galerkin(self, delfineVar, parameter):
        """Assembles the elliptic problem in a Galerkin variational form with Dolfin."""

        # Get data from case initialization
        .
        .
        .

        # Create function space
        V = FunctionSpace(mesh, "CG", order)

        # Define distributed source terms (not wells)
        f = Source()

        # Define Neumman boundary conditions (vel.n=0 on borders)
        g = Expression("0.0")

        # Define variational problem
        v = TestFunction(V)
        u = TrialFunction(V)

        a = inner(grad(v), K*mob*grad(u))*dx
        L = v*f*dx - g*v*ds

        # Assemble matrices and vectors
        A, rhs = assemble_system(a, L)

After that, I would like to change the coefficient of the 'A' matrix relative to a specific vertex representing the well. I already managed to find the index of this vertex, so everything I would like to do is something like:
A[index][index] += value

For example, if my vertex index is 3, in finite differences it would look like:
-- --
|1 1 0 0 0|
|1 -2 -1 0 0|
|0 1 (-2+value) 1 0|
|0 0 1 -2 1|
|0 0 0 1 1|
-- --

How could I do that?? I am using uBlas as the linear algebra backend.

Thank you in advance,
Bruno

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Garth Wells
Solved:
Last query:
Last reply:
Revision history for this message
Best Garth Wells (garth-wells) said :
#1

You can use the DofMap to get the global dof index, and use the GenericMatrix::add function to add a value to the matrix entry.

Be aware that (a) you should not make any assumptions on the dof map numbering w.r.t the mesh numbering and (b) bad things may happen if you try to modify a term in a sparse matrix that is outside of the non-zero pattern.

Revision history for this message
Bruno Luna (brunoluna) said :
#2

Thanks Garth Wells, that solved my question.