# Problem assembling global rhs and lhs system

**URL:** <https://fenicsproject.discourse.group/t/problem-assembling-global-rhs-and-lhs-system/5932>\
**Category:** variational formulation\
**Created:** [June 1, 2021, 10:36pm UTC](https://fenicsproject.discourse.group/t/problem-assembling-global-rhs-and-lhs-system/5932 "2021-06-01T22:36:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mondragon](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mondragon](https://fenicsproject.discourse.group/u/Mondragon)\
**Post date:** [June 1, 2021, 10:36pm UTC](https://fenicsproject.discourse.group/t/problem-assembling-global-rhs-and-lhs-system/5932/1 "2021-06-01T22:36:50Z")

</div>

Hello,

I having problem trying to assemble the global matrix manually.

```auto
from dolfin import *
parameters["reorder_dofs_serial"] = False
import matplotlib.pyplot as plt
import math
import numpy as np
from petsc4py import PETSc
import scipy.sparse as sp_sparse
mesh =UnitCubeMesh(4, 4, 4)
# Defining the function spaces
V_c = FunctionSpace(mesh, 'P', 1)

#STABILIZATION CROSSWIND TERMS

alpha= Constant(0.6)
I= Identity(mesh.geometry().dim())
def q(c): 
    return (sqrt(dot(dot(u,grad(c)),dot(u,grad(c))))/sqrt(dot(grad(c),grad(c))))

# Define variational problem for Picard iteration
c = TrialFunction(V_c)
# Galerkin variational problem
F=(diff*dot(grad(c),grad(v))+dot(u,grad(c))*v)*dx-f*v*dx
# Add SUPG stabilization terms
F += dot(u,grad(v))*tau_supg*dot(u,grad(c))*dx
# Add crosswind stabilization terms
CWD=(I-(outer(u,u)/sqrt(dot(dot(u,u),dot(u,u)))))
F += dot(dot(0.5*alpha*h*q(c_k)*grad(c),CWD),grad(v))*dx

# Create bilinear and linear forms
a = lhs(F)
L = rhs(F)

# assemble the global matrix 
#assembling fenics way
A_g = assemble(a)
f_g = assemble(L)
# Get dofmap to construct cell-to-dof connectivity dofmap = V.dofmap()
dofmap = V_c.dofmap()
# Perform assembly
for cell in cells(mesh):
    dof_idx = dofmap.cell_dofs(cell.index())
    # Assemble local rhs and lhs system
    a_local = assemble_local(a, cell)
    L_local = assemble_local(L, cell)
    # Assemble global rhs and lhs system
    A_g.add_local(a_local,dof_idx, dof_idx)
    f_g.add_local(L_local,dof_idx)
# Finalize assembling
[bc.apply(A_g, f_g) for bc in bcs]

```

i get the following error

```auto
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-23-dbb22474b61e> in <module>
     10 L_local = assemble_local(L, cell)
     11 # Assemble global rhs and lhs system
---> 12 A_g.add_local(a_local,dof_idx, dof_idx)
     13 f_g.add_local(L_local,dof_idx)
     14 # Finalize assembling

AttributeError: 'dolfin.cpp.la.Matrix' object has no attribute 'add_local'

```

I have checked and Matrix has the attribute add\_local so i dont understand why is not working. Can please someone help me
