Hello,
I having problem trying to assemble the global matrix manually.
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
---------------------------------------------------------------------------
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