AttributeError: ‘list’ object has no attribute ‘_cpp_object’

Hello, I was trying to follow the tutorial and implemented code as my problem


I described about boundary condition on this link Boundary condition on 2D square mesh

#Generating Mesh
from mpi4py import MPI
from dolfinx import mesh
from dolfinx import *
domain = mesh.create_unit_square(MPI.COMM_WORLD, 100, 100, mesh.CellType.quadrilateral)

#RD
#Defining The Finnite Elemnet Function Space
from dolfinx.fem import FunctionSpace
U = FunctionSpace(domain, ("Lagrange", 1))

from dolfinx import fem
uD = fem.Function(U)
uD.interpolate(lambda c: (D0*eps**eta)*c[0])

#boundary condition 
def left(c):
    return np.isclose(c[0], 1)
def right(c):
    return np.isclose(c[0], 0)
def top(c):
    return np.isclose(c[1], 0)
def bottom(c):
    return np.isclose(c[1], 0)

fdim = domain.topology.dim - 1

left_facets = dolfinx.mesh.locate_entities_boundary(domain, fdim, left)
right_facets = dolfinx.mesh.locate_entities_boundary(domain, fdim, right)
top_facets = dolfinx.mesh.locate_entities_boundary(domain, fdim, top)
bottom_facets = dolfinx.mesh.locate_entities_boundary(domain, fdim, bottom)

with uD.vector.localForm() as loc:
    loc.set(0.0)

bc1 = fem.dirichletbc(uD, dolfinx.fem.locate_dofs_topological(U, fdim, left_facets))
bc2 = fem.dirichletbc(uD, dolfinx.fem.locate_dofs_topological(U, fdim, right_facets))
bc3 = fem.dirichletbc(uD, dolfinx.fem.locate_dofs_topological(U, fdim, top_facets))
bc4 = fem.dirichletbc(uD, dolfinx.fem.locate_dofs_topological(U, fdim, bottom_facets))

bc = [bc1, bc2, bc3, bc4]

#Defining the trial and test function
import ufl
u = ufl.TrialFunction(U)
uu = ufl.TestFunction(U)

#Defining the source term
from petsc4py import PETSc
default_scalar_type = PETSc.ScalarType

f = fem.Function(U)
f.interpolate(lambda c: -(k0*(1-eps)**gamma)*c[0])

#Defining the variational problem
ua = ufl.inner(ufl.grad(u), ufl.grad(uu)) * ufl.dx
uL = ufl.inner(f,uu)*ufl.dx

#Forming and solving the linear system
from dolfinx.fem.petsc import LinearProblem

problem = fem.petsc.LinearProblem(ua, uL, bcs=[bc], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
uh = problem.solve()

I want to solve concentration value (c) but it gives error at the final line of code “uh = problem.solve()”
AttributeError: ‘list’ object has no attribute ‘_cpp_object’

i’ve been stuck with this error, Could someone help me.

1 Like

Change this to bcs=bc

1 Like

it worked :laughing:, thank you for your helping

Hello, i have the same problem when i try to solve a stokes problem, and with thist recomendation nothing changes., AttributeError: ‘list’ object has no attribute ‘_cpp_object’, this error is in the problem_fine line, could someone help me please.

try:
    from petsc4py import PETSc

    import dolfinx

    if not dolfinx.has_petsc:
        print("This demo requires DOLFINx to be compiled with PETSc enabled.")
        exit(0)
except ModuleNotFoundError:
    print("This demo requires petsc4py.")
    exit(0)
import numpy as np
import ufl
from basix.ufl import element, mixed_element
from dolfinx import default_real_type, fem, la
from dolfinx.fem import (
    Constant,
    Function,
    dirichletbc,
    extract_function_spaces,
    form,
    functionspace,
    locate_dofs_topological,
)
from dolfinx.fem.petsc import apply_lifting, assemble_matrix, assemble_vector, set_bc
from dolfinx.io import XDMFFile
from dolfinx.mesh import CellType, create_rectangle, locate_entities_boundary
# Create mesh
msh = create_rectangle(
    MPI.COMM_WORLD, [np.array([0, 0]), np.array([1, 1])], [32, 32], CellType.triangle
)


# Function to mark x = 0, x = 1 and y = 0
def noslip_boundary(x):
    return np.isclose(x[0], 0.0) | np.isclose(x[0], 1.0) | np.isclose(x[1], 0.0)


# Function to mark the lid (y = 1)
def lid(x):
    return np.isclose(x[1], 1.0)


# Lid velocity
def lid_velocity_expression(x):
    return np.stack((np.ones(x.shape[1]), np.zeros(x.shape[1])))
P2 = element(
    "Lagrange", msh.basix_cell(), degree=2, shape=(msh.geometry.dim,), dtype=default_real_type
)
P1 = element("Lagrange", msh.basix_cell(), degree=1, dtype=default_real_type)
V, Q = functionspace(msh, P2), functionspace(msh, P1)
# No-slip condition on boundaries where x = 0, x = 1, and y = 0

noslip = np.zeros(msh.geometry.dim, dtype=PETSc.ScalarType) # type: ignore

facets = locate_entities_boundary(msh, 1, noslip_boundary)

bc0 = dirichletbc(noslip, locate_dofs_topological(V, 1, facets), V)

# Driving (lid) velocity condition on top boundary (y = 1)

lid_velocity = Function(V)

lid_velocity.interpolate(lid_velocity_expression)

facets = locate_entities_boundary(msh, 1, lid)

bc1 = dirichletbc(lid_velocity, locate_dofs_topological(V, 1, facets))

# Collect Dirichlet boundary conditions

bcs = [bc0, bc1]
# Define variational problem
(u, p) = ufl.TrialFunction(V), ufl.TrialFunction(Q)
(v, q) = ufl.TestFunction(V), ufl.TestFunction(Q)
f = Constant(msh, (PETSc.ScalarType(0), PETSc.ScalarType(0)))  # type: ignore

a = form(
    [
        [ufl.inner(ufl.grad(u), ufl.grad(v)) * ufl.dx, ufl.inner(p, ufl.div(v)) * ufl.dx],
        [ufl.inner(ufl.div(u), q) * ufl.dx, None],
    ]
)
L = form([ufl.inner(f, v) * ufl.dx, ufl.ZeroBaseForm((q,))])
# Resolver problema con LU

from dolfinx.fem.petsc import LinearProblem

problem = LinearProblem(a, L, bcs = [bc0, bc1], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})

uh= problem.solve() ```

As of now, the linear problem constructor doesn’t support blocked forms. I have an open pull request to make this a feature, see:

Thanks. But someone know another way to solve this problem? Without using this function.

You would have to call assemble_matrix_block, and assemble_vector_block and work directly with the PETSc KSP objects, as done in