AttributeError: 'NoneType' object has no attribute 'get_unique_vars'

Hey all,

I am trying to solve a staggered scheme of phase-field modeling of fracture. The elasticity problem should also take into account plasticity, for which I used this tutorial.

The solution of the elasto-plastic problem is going well, but when trying to solve the phase-field problem I’m getting AttributeError: ‘NoneType’ object has no attribute ‘get_unique_vars’.

According to the plasticity tutorial, I used the following definitions:

parameters["form_compiler"]["representation"] = 'quadrature'
import warnings
from ffc.quadrature.deprecation import QuadratureRepresentationDeprecationWarning
warnings.simplefilter("once", QuadratureRepresentationDeprecationWarning)

U = VectorFunctionSpace(mesh, 'CG', 2) # displacemenst
P = FunctionSpace(mesh, 'CG', 2) # phase-field, strain energy
deg_stress = 2 # quadrature degree
metadata = {"quadrature_degree": deg_stress, "quadrature_scheme": "default"}
dxm = dx(metadata=metadata)
Se = VectorElement("Quadrature", mesh.ufl_cell(), degree=deg_stress, dim=6, quad_scheme='default')
S = FunctionSpace(mesh, Se) # stresses, evaluated at quadrature points only
Epe = FiniteElement("Quadrature", mesh.ufl_cell(), degree=deg_stress, quad_scheme='default')
Ep = FunctionSpace(mesh, Epe) # plastic-strain, evaluated at quadrature points only

u, v = TrialFunction(U), TestFunction(U)
du = Function(U) # iteration correction

phi, q = TrialFunction(P), TestFunction(P)
pnew = Function(P)

Hc = Function(Ep)

sig = Function(S)

L_u = (((1.0-pold)**2) + c_eta)*inner(grad(v),sigma_tang(u))*dxm
R_u = -inner(epsilon(v), as_3D_tensor(sig))*dxm

L_phi = (c_Gc * c_l * inner(c_omega, outer(grad(phi), grad(q))) \
            + ((c_Gc/c_l) + 2.0 * Hc ) * inner(phi, q) ) * dxm
R_phi = 2.0 * Hc * q * dxm

A, Res = assemble_system(L_u, R_u, bc_u)
solve(A, du.vector(), Res, "mumps")

A_phi, B_phi = assemble_system(L_phi, R_phi, bc_phi) # this is where the error occurs
solve(A_phi, pnew.vector(), B_phi)

I tried to omit everything that I thought is not important to understand the problem. The error occurs when the code tries to assemble the phase-field problem.
I would very much appreciate your help.
Thanks,
Yaron

Were you able to resolve this issue? I am working on the same problem and facing a very different issue. I would like to know whether you were able to figure this out.
Thanks
Anupama

It would be helpful to have a minimal reproducible problem, i.e. a code that can be copied and executed on any system.
The code above is incomplete.

1 Like

I apologize for the delay in response. I assume my error is coming from displacement control loading. I am trying to convert Elasto-plastic analysis of a 2D von Mises material — Numerical tours of continuum mechanics using FEniCS master documentation to a displacement control loading. I want to plot a load - displacement curve and validate the results. What I am trying to do here is,
Traction = sigma.n
f_y = Traction * ds
This is my code


from dolfin import *
import numpy as np
parameters["form_compiler"]["representation"] = 'quadrature'
import warnings
from ffc.quadrature.deprecation import QuadratureRepresentationDeprecationWarning
warnings.simplefilter("once", QuadratureRepresentationDeprecationWarning)


# material parameters
E = Constant(70e3)
nu = Constant(0.3)
lmbda = E*nu/(1+nu)/(1-2*nu)
mu = E/2./(1+nu)
sig0 = Constant(250.)  # yield strength
Et = E/100.  # tangent modulus
H = E*Et/(E-Et)  # hardening modulus

mesh = Mesh("mesh.xml")

# Boundary conditions
# normal AND
# ds, load:user expression
top = CompiledSubDomain("near(x[1], 0.5) && on_boundary")

# bottom boundary
bot = CompiledSubDomain("near(x[1], -0.5) && on_boundary")




deg_u = 2
deg_stress = 2
V = VectorFunctionSpace(mesh, "CG", deg_u)
We = VectorElement("Quadrature", mesh.ufl_cell(), degree=deg_stress, dim=4, quad_scheme='default')
W = FunctionSpace(mesh, We)
W0e = FiniteElement("Quadrature", mesh.ufl_cell(), degree=deg_stress, quad_scheme='default')
W0 = FunctionSpace(mesh, W0e)

#load, defined using user expression, t
load = Expression("t", t = 0.0, degree=1)

# bc, bottom
bcbot= DirichletBC(V, Constant((0.0,0.0)), bot)

# load applied on top u_y
# boundary condition on top
bctop = DirichletBC(V.sub(1), load, top)

# grouping disp bc together
bc = [bcbot, bctop]
n = FacetNormal(mesh)



sig = Function(W)
sig_old = Function(W)
n_elas = Function(W)
beta = Function(W0)
p = Function(W0, name="Cumulative plastic strain")
f_y = Function(W0, name = "vertical reaction")
u = Function(V, name="Total displacement")
du = Function(V, name="Iteration correction")
Du = Function(V, name="Current increment")
v = TrialFunction(V)
u_ = TestFunction(V)


def eps(v):
    e = sym(grad(v))
    return as_tensor([[e[0, 0], e[0, 1], 0],
                      [e[0, 1], e[1, 1], 0],
                      [0, 0, 0]])
def sigma(eps_el):
    return lmbda*tr(eps_el)*Identity(3) + 2*mu*eps_el
def as_3D_tensor(X):
    return as_tensor([[X[0], X[3], 0],
                      [X[3], X[1], 0],
                      [0, 0, X[2]]])


ppos = lambda x: (x+abs(x))/2.
def proj_sig(deps, old_sig, old_p):
    sig_n = as_3D_tensor(old_sig)
    sig_elas = sig_n + sigma(deps)
    s = dev(sig_elas)
    sig_eq = sqrt(3/2.*inner(s, s))
    f_elas = sig_eq - sig0 - H*old_p
    dp = ppos(f_elas)/(3*mu+H)
    n_elas = s/sig_eq*ppos(f_elas)/f_elas
    beta = 3*mu*dp/sig_eq
    new_sig = sig_elas-beta*s
    return as_vector([new_sig[0, 0], new_sig[1, 1], new_sig[2, 2], new_sig[0, 1]]), \
           as_vector([n_elas[0, 0], n_elas[1, 1], n_elas[2, 2], n_elas[0, 1]]), \
           beta, dp


def sigma_tang(e):
    N_elas = as_3D_tensor(n_elas)
    return sigma(e) - 3*mu*(3*mu/(3*mu+H)-beta)*inner(N_elas, e)*N_elas-2*mu*beta*dev(e)

metadata = {"quadrature_degree": deg_stress, "quadrature_scheme": "default"}
dxm = dx(metadata=metadata)

a_Newton = inner(eps(v), sigma_tang(eps(u_)))*dxm
res = -inner(eps(u_), as_3D_tensor(sig))*dxm 



def local_project(v, V, u=None):
    dv = TrialFunction(V)
    v_ = TestFunction(V)
    a_proj = inner(dv, v_)*dxm
    b_proj = inner(v, v_)*dxm
    solver = LocalSolver(a_proj, b_proj)
    solver.factorize()
    if u is None:
        u = Function(V)
        solver.solve_local_rhs(u)
        return u
    else:
        solver.solve_local_rhs(u)
        return

# XDMF : eXtensible Data Model and Format
# method to exchange scientific data
# XDMF will not handle quadrature space
# we define Functionspace P0
file_results = XDMFFile("plasticity_results.xdmf")
file_results.parameters["flush_output"] = True
file_results.parameters["functions_share_mesh"] = True
P0 = FunctionSpace(mesh, "DG", 0)
p_avg = Function(P0, name="Plastic strain")
load_vertical = Function(P0, name="vertical reaction")

u_r = 0.05
Nitermax, tol = 5, 1e-8  # parameters of the Newton-Raphson procedure
Nincr = 20
load_steps = np.linspace(0, 1.1, Nincr+1)[1:]**0.5
results = np.zeros((Nincr+1, 2))
for (i, t) in enumerate(load_steps):
    load.t = t*u_r
    A, Res = assemble_system(a_Newton, res, bc)
    nRes0 = Res.norm("l2")
    nRes = nRes0
    Du.interpolate(Constant((0, 0)))
    print("Increment:", str(i+1))
    niter = 0
    while nRes/nRes0 > tol and niter < Nitermax:
        solve(A, du.vector(), Res, "mumps")
        Du.assign(Du+du)
        deps = eps(Du)
        sig_, n_elas_, beta_, dp_ = proj_sig(deps, sig_old, p)
        local_project(sig_, W, sig)
        local_project(n_elas_, W, n_elas)
        local_project(beta_, W0, beta)
        A, Res = assemble_system(a_Newton, res, bc)
        nRes = Res.norm("l2")
        print("    Residual:", nRes)
        niter += 1
    u.assign(u+Du)
    p.assign(p+local_project(dp_, W0))
    sig_old.assign(sig)
    file_results.write(u, t)
    p_avg.assign(project(p, P0))
    sig_yy = project(sig_[1],P0)
    f_y = sigp[1] *ds(1)
    #load_vertical.assign(project(f_y, P0))
    file_results.write(str(assemble(f_y)), t)

    results[i+1, :] = (t*u_r, t)


The error I am obtaining is

Traceback (most recent call last):
  File "/home/anupama/OneDrive/WORK_2023/von_mises_july/vonMises_plasticity/vonMises_plasticity.py", line 166, in <module>
    sig_yy = project(sig_[1],P0)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/projection.py", line 132, in project
    A, b = assemble_system(a, L, bcs=bcs,
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/assembling.py", line 409, in assemble_system
    b_dolfin_form = _create_dolfin_form(b_form, form_compiler_parameters)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/assembling.py", line 60, in _create_dolfin_form
    return Form(form,
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/form.py", line 43, in __init__
    ufc_form = ffc_jit(form, form_compiler_parameters=form_compiler_parameters,
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 50, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 100, in ffc_jit
    return ffc.jit(ufl_form, parameters=p)
  File "/usr/lib/python3/dist-packages/ffc/jitcompiler.py", line 217, in jit
    module = jit_build(ufl_object, module_name, parameters)
  File "/usr/lib/python3/dist-packages/ffc/jitcompiler.py", line 130, in jit_build
    module, signature = dijitso.jit(jitable=ufl_object,
  File "/usr/lib/python3/dist-packages/dijitso/jit.py", line 165, in jit
    header, source, dependencies = generate(jitable, name, signature, params["generator"])
  File "/usr/lib/python3/dist-packages/ffc/jitcompiler.py", line 65, in jit_generate
    code_h, code_c, dependent_ufl_objects = compile_object(ufl_object,
  File "/usr/lib/python3/dist-packages/ffc/compiler.py", line 142, in compile_form
    return compile_ufl_objects(forms, "form", object_names,
  File "/usr/lib/python3/dist-packages/ffc/compiler.py", line 190, in compile_ufl_objects
    ir = compute_ir(analysis, prefix, parameters, jit)
  File "/usr/lib/python3/dist-packages/ffc/representation.py", line 182, in compute_ir
    irs = [_compute_integral_ir(fd, form_id, prefix, element_numbers, classnames, parameters, jit)
  File "/usr/lib/python3/dist-packages/ffc/representation.py", line 182, in <listcomp>
    irs = [_compute_integral_ir(fd, form_id, prefix, element_numbers, classnames, parameters, jit)
  File "/usr/lib/python3/dist-packages/ffc/representation.py", line 455, in _compute_integral_ir
    ir = r.compute_integral_ir(itg_data,
  File "/usr/lib/python3/dist-packages/ffc/quadrature/quadraturerepresentation.py", line 77, in compute_integral_ir
    tabulate_basis(sorted_integrals, form_data, itg_data)
  File "/usr/lib/python3/dist-packages/ffc/quadrature/tabulate_basis.py", line 224, in tabulate_basis
    psi_table = _tabulate_psi_table(integral_type, cellname, tdim,
  File "/usr/lib/python3/dist-packages/ffc/quadrature/tabulate_basis.py", line 120, in _tabulate_psi_table
    psi_table[entity] = element.tabulate(deriv_order, entity_points)
  File "/usr/lib/python3/dist-packages/FIAT/mixed.py", line 76, in tabulate
    table = e.tabulate(order, points, entity)
  File "/usr/lib/python3/dist-packages/FIAT/quadrature_element.py", line 56, in tabulate
    raise AssertionError("Mismatch of quadrature points!")
AssertionError: Mismatch of quadrature points!

Can anyone suggest a way to extract vertical reaction force without this quadrature mismatch coming into the picture?
(I am working with a 2D unit square domain)

You should supply the projection with metadata, ie.

As this is required for assembly of functions in quadrature spaces. I would simply write out the projection operator, similar to:
https://simula-sscp.github.io/SSCP_2023_lectures/L12%20(FEniCS%20Intro)/L03_FEniCS_Darcy.html#advanced-reusable-projection
and add metadata to the dx measures.

This will also speed up your code by reusing the matrix and LU factorization.

1 Like

Thank you for the reply. I have one more doubt.
If I am calculating force as follows
(Rest of the code remains same)

sigma_tensor = as_3D_tensor(sig_)
normal = as_vector((n[0],n[1], 0))
Traction = dot(sigma_tensor, normal)
f_y = Traction[1] *ds(1)
file_results.write(str(assemble(f_y)), t)

Why exactly am I getting the following error?

  File "/home/anupama/OneDrive/WORK_2023/von_mises_july/vonMises_plasticity/vonMises_plasticity.py", line 172, in <module>
    file_results.write(str(assemble(f_y)), t)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/assembling.py", line 202, in assemble
    dolfin_form = _create_dolfin_form(form, form_compiler_parameters)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/assembling.py", line 60, in _create_dolfin_form
    return Form(form,
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/form.py", line 43, in __init__
    ufc_form = ffc_jit(form, form_compiler_parameters=form_compiler_parameters,
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 50, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 100, in ffc_jit
    return ffc.jit(ufl_form, parameters=p)
  File "/usr/lib/python3/dist-packages/ffc/jitcompiler.py", line 217, in jit
    module = jit_build(ufl_object, module_name, parameters)
  File "/usr/lib/python3/dist-packages/ffc/jitcompiler.py", line 130, in jit_build
    module, signature = dijitso.jit(jitable=ufl_object,
  File "/usr/lib/python3/dist-packages/dijitso/jit.py", line 165, in jit
    header, source, dependencies = generate(jitable, name, signature, params["generator"])
  File "/usr/lib/python3/dist-packages/ffc/jitcompiler.py", line 65, in jit_generate
    code_h, code_c, dependent_ufl_objects = compile_object(ufl_object,
  File "/usr/lib/python3/dist-packages/ffc/compiler.py", line 142, in compile_form
    return compile_ufl_objects(forms, "form", object_names,
  File "/usr/lib/python3/dist-packages/ffc/compiler.py", line 190, in compile_ufl_objects
    ir = compute_ir(analysis, prefix, parameters, jit)
  File "/usr/lib/python3/dist-packages/ffc/representation.py", line 182, in compute_ir
    irs = [_compute_integral_ir(fd, form_id, prefix, element_numbers, classnames, parameters, jit)
  File "/usr/lib/python3/dist-packages/ffc/representation.py", line 182, in <listcomp>
    irs = [_compute_integral_ir(fd, form_id, prefix, element_numbers, classnames, parameters, jit)
  File "/usr/lib/python3/dist-packages/ffc/representation.py", line 455, in _compute_integral_ir
    ir = r.compute_integral_ir(itg_data,
  File "/usr/lib/python3/dist-packages/ffc/quadrature/quadraturerepresentation.py", line 77, in compute_integral_ir
    tabulate_basis(sorted_integrals, form_data, itg_data)
  File "/usr/lib/python3/dist-packages/ffc/quadrature/tabulate_basis.py", line 224, in tabulate_basis
    psi_table = _tabulate_psi_table(integral_type, cellname, tdim,
  File "/usr/lib/python3/dist-packages/ffc/quadrature/tabulate_basis.py", line 120, in _tabulate_psi_table
    psi_table[entity] = element.tabulate(deriv_order, entity_points)
  File "/usr/lib/python3/dist-packages/FIAT/mixed.py", line 76, in tabulate
    table = e.tabulate(order, points, entity)
  File "/usr/lib/python3/dist-packages/FIAT/quadrature_element.py", line 56, in tabulate
    raise AssertionError("Mismatch of quadrature points!")
AssertionError: Mismatch of quadrature points!


I have not tried projecting into a quadrature space anywhere. I have difficulty understanding why this is happening. I am not able to integrate the traction over the boundary.

If any of the functions in the expression for sigma is in a quadrature space, they cannot be evaluated at any other point than at the quadrature points (Which are inside the volume of the mesh, not on the boundary). If you want to to use anything from a quadrature space on the boundary, you would first have to project the function into a suitable DG space.

1 Like

I have tried the following

  1. define a DG space
ST = TensorFunctionSpace(mesh, "DG", 0, shape =(3,3))
  1. tried projecting sigma
sigma_tensor = as_3D_tensor(sig_)
sigma_t = project(sigma_tensor, ST)

Still, getting quadrature mismatch error.
In conclusion,
I am not able to project this function into a DG space.
I am able to project this into a quadrature space, but then I cant evaluate it over the boundary.

My whole point from earlier still holds for the projection