I am a beginner user of fenics. I am writing a code for phase field ductile fracture. The following is my code. I have removed the part for solution of damage variable in the staggered algorithm, and the function for return mapping algorithm.
# PHASE FIELD DUCTILE FRACTURE
# Von mises J2 plasticity
#------------------------------------------------
from dolfin import *
from matplotlib import pyplot
import numpy as np
#------------------------------------------------
# MESH
#------------------------------------------------
# Load mesh and plot
mesh = Mesh('mesh.xml')
plot(mesh, title="Finite element mesh")
pyplot.show()
#------------------------------------------------
# FUNCTION SPACE, FUNCTIONS & SOLUTION VARIABLES
#------------------------------------------------
Vp = FunctionSpace(mesh, 'CG', 1)
# DISPLACEMENT - u
# For displacement
W = VectorFunctionSpace(mesh, 'CG', 1)
v = TrialFunction(W)
u_ = TestFunction(W)
du = Function(W, name="iteration correction")
# For H+: Elastic strain energy
# Energy governing damage
WW = FunctionSpace(mesh, 'DG', 0)
# Solution space variables for u_{t} and u_{t-1} = unew, u_old
unew, uold = Function(W), Function(W)
# PLASTICITY: FOR HISTORY, FUNTIONS
WT = TensorFunctionSpace(mesh, 'CG', 1, shape = (3,3))
sig = Function(WT)
epsilon_p = Function(WT)
n_elas_p = Function(WT)
alpha = Function(Vp, name="Cumulative plastic strain")
delta_lmbda_p = Function(Vp, name="Plastic multiplier")
beta_1p = Function(Vp)
beta_2p = Function(Vp)
#------------------------------------------------
# MATERIAL PROPERTIES & DEGD FUNCTION PARAMETERS
#------------------------------------------------
# Gc: Critical energy release rate: Mpa mm
Gc = 9.31
# Lames parameters: MPa
lmbda = 53.473e3
mu = 27.280e3
# Bulk modulus
K_n = lmbda + 2*mu/3
# Yield stress: MPa
sigma_y = 345
# Hardening modulus: MPa
H_mod = 500
# Phase field parameters
# l :mm
l = 0.02
eta = 1e-5
#------------------------------------------------
# CONSTITUTIVE FUNCTIONS
#------------------------------------------------
# Macauly bracket
# Function required for def of stress
def mac_bracket_plus(a):
return 0.5*(a + abs(a))
def mac_bracket_minus(a):
return 0.5*(a - abs(a))
# Strain
def epsilon(u):
e = sym(grad(u))
return as_tensor([[e[0, 0], e[0, 1], 0],
[e[0, 1], e[1, 1], 0],
[0, 0, 0]])
def grad3(u):
k = grad(u)
return as_tensor([[k[0, 0], k[0, 1], 0],
[k[0, 1], k[1, 1], 0],
[0, 0, 0]])
def g_degd(p):
return (1-p)**2 + eta
# Stress elastic
def sigma_el(u):
ep = epsilon(u)
return g_degd(pold) * (K_n * mac_bracket_plus(tr(ep)) * Identity(3) + 2 * mu * dev(ep)) + K_n * mac_bracket_minus(tr(ep)) * Identity(3)
def psi_plus(u):
return 0.5*(K_n)*(mac_bracket_plus(tr(epsilon(u))))**2+\
mu*inner(dev(epsilon(u)),dev(epsilon(u)))
# Irreversibility condition: using conditional operator
# Function returns the maximum of tensile part of strain energy density
def H(uold,unew,Hold):
return conditional(lt(psi_plus(uold),psi_plus(unew)),psi_plus(unew),Hold)
def sigma_tangent(uu):
B = grad3(uu)
# print(epsilon(dui).ufl_shape)
return (K_n/2)* (g_degd(pold) *(B + B* tr(B)/abs(tr(B))) + (B -B * tr(B)/abs(tr(B)))) +\
(g_degd(pold) * 2 * mu * ( beta_2p * delta_lmbda_p - beta_1p)) * inner( n_elas_p, B) * n_elas_p +\
g_degd(pold) * 2 * mu * (1- beta_2p * delta_lmbda_p) * dev(B)
# -----------------------------------------------
# BOUNDARY CONDITIONS, NORMAL
# -----------------------------------------------
# top boundary
top = CompiledSubDomain("near(x[1], 1.0) && on_boundary")
# bottom boundary
bot = CompiledSubDomain("near(x[1], 0) && on_boundary")
# crack location
def Crack(x):
return ((x[1] > 0.499) & (x[1] < 0.501)) and x[0] <= 0.5
# load, defined using user expression, t
load = Expression("t", t = 0.0, degree=1)
# bc, bottom
bcbot = bcbot= DirichletBC(W, Constant((0.0,0.0)), bot)
# load applied on top u_y
# boundary condition on top
bctop = DirichletBC(W.sub(1), load, top)
# grouping disp bc together
bc_u = [bcbot, bctop]
# MeshFunction: identify the boundaries of the domain
boundaries = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
# initialize boundaries before marking
boundaries.set_all(0)
# mark the top boundary
top.mark(boundaries, 1)
# to integrate over boundari
ds = Measure("ds")(subdomain_data= boundaries)
# define normal to the surface/ boundaries
n = FacetNormal(mesh)
# -----------------------------------------------
# VARIATIONAL FORMULATION
# -----------------------------------------------
# Implementing Newton method manually
# K matrix
# recall the problem is
# K deltaU = f
# we will solve for deltaU and update U
a_Newton = inner(grad3(v), sigma_tangent(u_)) * dx
res = -inner( grad3(u_), sig) * dx
# -----------------------------------------------
# LOAD
# -----------------------------------------------
# specified as remote displacement
u_r = 0.01
# -----------------------------------------------
# ITERATIVE SCHEME
# -----------------------------------------------
# Newton - Raphson procedure parameters
Nitermax, tol = 200, 1e-4
# time step
deltaT = 0.01
t = 0
# Staggerd solution strategy
while t<=1.0:
t += deltaT
if t>=0.5:
deltaT = 0.005
load.t = t*u_r
iter = 0 # iteration counter
err = 1
A, Res = assemble_system(a_Newton, res, bc_u)
nRes0 = Res.norm("l2")
nRes = nRes0
unew.assign(uold)
while nRes/nRes0 > tol and niter < Nitermax:
solve(A, du.vector(), Res, "mumps")
unew.assign(unew + du)
epsilon_p_, alpha_, sig_, n_elas_p_, beta_1p_, beta_2p_, delta_lmbda_ = return_map(unew, epsilon_p, alpha, pold)
sig = project(sig_, WT)
beta_1p = project(beta_1p_, Vp)
beta_2p = project(beta_2p_, Vp)
n_elas_p = project(n_elas-p_, WT)
delta_lmbda_p = project(delta_lmbda_, Vp)
A, Res = assemble_system(a_Newton, res, bc)
nRes = Res.norm("l2")
iter += 1
while err > tol:
solver_phi.solve()
err = errornorm(pnew,pold,norm_type = 'l2',mesh = None)
uold.assign(unew)
pold.assign(pnew)
Hold.assign(project(psi(unew), WW))
alpha = project(alpha_, Vp)
While running the code, I am getting the following error. Can anyone help me with this?
At this stage, I have not used quadrature elements; could that cause any issue?
Calling FFC just-in-time (JIT) compiler, this may take some time.
Traceback (most recent call last):
File "/home/anupama/OneDrive/WORK_2023/PFM_nonlinearJUNE2023 (copy)/Ductile_new.py", line 286, in <module>
A, Res = assemble_system(a_Newton, res, bc_u)
File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/assembling.py", line 408, in assemble_system
A_dolfin_form = _create_dolfin_form(A_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 185, in compile_ufl_objects
analysis = analyze_ufl_objects(ufl_objects, kind, parameters)
File "/usr/lib/python3/dist-packages/ffc/analysis.py", line 89, in analyze_ufl_objects
form_datas = tuple(_analyze_form(form, parameters)
File "/usr/lib/python3/dist-packages/ffc/analysis.py", line 89, in <genexpr>
form_datas = tuple(_analyze_form(form, parameters)
File "/usr/lib/python3/dist-packages/ffc/analysis.py", line 169, in _analyze_form
form_data = compute_form_data(form,
File "/usr/lib/python3/dist-packages/ufl/algorithms/compute_form_data.py", line 407, in compute_form_data
check_form_arity(preprocessed_form, self.original_form.arguments(), complex_mode) # Currently testing how fast this is
File "/usr/lib/python3/dist-packages/ufl/algorithms/check_arities.py", line 177, in check_form_arity
check_integrand_arity(itg.integrand(), arguments, complex_mode)
File "/usr/lib/python3/dist-packages/ufl/algorithms/check_arities.py", line 159, in check_integrand_arity
arg_tuples = map_expr_dag(rules, expr, compress=False)
File "/usr/lib/python3/dist-packages/ufl/corealg/map_dag.py", line 36, in map_expr_dag
result, = map_expr_dags(function, [expression], compress=compress,
File "/usr/lib/python3/dist-packages/ufl/corealg/map_dag.py", line 97, in map_expr_dags
r = handlers[v._ufl_typecode_](v)
File "/usr/lib/python3/dist-packages/ufl/algorithms/check_arities.py", line 41, in nonlinear_operator
raise ArityMismatch("Applying nonlinear operator {0} to expression depending on form argument {1}.".format(o._ufl_class_.__name__, t))
ufl.algorithms.check_arities.ArityMismatch: Applying nonlinear operator Abs to expression depending on form argument v_0.