I am trying to find out the displacement and acceleration data when a hyperelastic plate is stretched uniaxially by giving only Dirichlet boundary condition at left and right side using linear momentum balance similar to tutorial given in dolfin with topic “time dependent integration of elastodynamics equation”. But it is giving an error as mentioned below.
Please help!!!
from dolfin import *
import fenics as fe
import numpy as np
## Defining Boundaries
def left(x, on_boundary):
return (on_boundary and fe.near(x[0], 0.0, 1.0e-5))
def right(x, on_boundary):
return (on_boundary and fe.near(x[0], 1.0, 1.0e-5))
# Mass density
rho = Constant(1.0)
# Generalized-alpha method parameters
alpha_m = Constant(0.2)
alpha_f = Constant(0.4)
gamma = Constant(0.5+alpha_f-alpha_m)
beta = Constant((gamma+0.5)**2/4.)
# # Time-stepping parameters
T = 1.0
Nsteps = 10
dt = Constant(T/Nsteps)
mesh = RectangleMesh(Point(0., 0.), Point(1., 1.), 40, 40)
# Define function space for displacement, velocity and acceleration
V = VectorFunctionSpace(mesh, "Lagrange", 1)
# Current (unknown) displacement
u = Function(V, name="displacement")
# Fields from previous time step (displacement, velocity, acceleration)
u_old = Function(V)
v_old = Function(V)
a_old = Function(V)
# Test and trial functions
du = TrialFunction(V)
u_ = TestFunction(V)
I = Identity(len(u))
bc_l = DirichletBC(V.sub(0), 0.0, left)
bc_r = DirichletBC(V.sub(0), 0.1, right)
bc = [bc_l,bc_r]
# Mass form
def m(u, u_):
return rho*inner(u, u_)*dx
def P(u,I,u_):
return inner(dWdf(u,I),grad(u_))*dx
def dWdf(u,I):
F = I + grad(u) # Deformation gradient
J = det(F)
C = F.T*F # Right Cauchy-Green tensor
B = F*F.T
I1 = tr(C) + 1 # Invariants of deformation tensors
I2 = 0.5*((tr(C)+1)**2 - (tr(C*C)+1))
I3 = J**2
I1_bar = J**(-2/3)*I1
I2_bar = J**(-4/3)*I2
F_inv = inv(I) - (1/(1+tr(grad(u)*inv(I))))*(inv(I)*grad(u)*inv(I))
dWdF = (J*F_inv)*((((2*(0.5))/J**(5/3))*B)-(2/(3*J))*(I1_bar*0.5)*I+(3*J-3.0)*I)
return dWdF
def avg(x_old, x_new, alpha):
return alpha*x_old + (1-alpha)*x_new
a_new = (du-u_old-dt*v_old)/beta/dt**2 - (1-2*beta)/2/beta*a_old
v_new = v_old + dt*((1-gamma)*a_old + gamma*a_new)
F = m(avg(a_old, a_new, alpha_m), u_) + P(avg(u_old, u, alpha_f),I,u_)
solve(F == 0, u, bc)
And I am getting this error
No Jacobian form specified for nonlinear variational problem.
Differentiating residual form F to obtain Jacobian J = F'.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Traceback (most recent call last):
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "/Users/mohammad.anas7777gmail.com/Downloads/untitled13.py", line 59, in <module>
solve(F == 0, u, bc)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/fem/solving.py", line 220, in solve
_solve_varproblem(*args, **kwargs)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/fem/solving.py", line 260, in _solve_varproblem
problem = NonlinearVariationalProblem(eq.lhs, u, bcs, J,
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/fem/problem.py", line 90, in __init__
F = Form(F, form_compiler_parameters=form_compiler_parameters)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/fem/form.py", line 43, in __init__
ufc_form = ffc_jit(form, form_compiler_parameters=form_compiler_parameters,
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/jit/jit.py", line 47, in mpi_jit
return local_jit(*args, **kwargs)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/jit/jit.py", line 97, in ffc_jit
return ffc.jit(ufl_form, parameters=p)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/jitcompiler.py", line 217, in jit
module = jit_build(ufl_object, module_name, parameters)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/jitcompiler.py", line 130, in jit_build
module, signature = dijitso.jit(jitable=ufl_object,
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dijitso/jit.py", line 165, in jit
header, source, dependencies = generate(jitable, name, signature, params["generator"])
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/jitcompiler.py", line 65, in jit_generate
code_h, code_c, dependent_ufl_objects = compile_object(ufl_object,
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/compiler.py", line 142, in compile_form
return compile_ufl_objects(forms, "form", object_names,
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/compiler.py", line 185, in compile_ufl_objects
analysis = analyze_ufl_objects(ufl_objects, kind, parameters)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/analysis.py", line 89, in analyze_ufl_objects
form_datas = tuple(_analyze_form(form, parameters)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/analysis.py", line 89, in <genexpr>
form_datas = tuple(_analyze_form(form, parameters)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/analysis.py", line 169, in _analyze_form
form_data = compute_form_data(form,
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ufl/algorithms/compute_form_data.py", line 387, in compute_form_data
check_form_arity(preprocessed_form, self.original_form.arguments()) # Currently testing how fast this is
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ufl/algorithms/check_arities.py", line 152, in check_form_arity
check_integrand_arity(itg.integrand(), arguments)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ufl/algorithms/check_arities.py", line 145, in check_integrand_arity
args = map_expr_dag(rules, expr, compress=False)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ufl/corealg/map_dag.py", line 37, in map_expr_dag
result, = map_expr_dags(function, [expression], compress=compress)
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ufl/corealg/map_dag.py", line 86, in map_expr_dags
r = handlers[v._ufl_typecode_](v, *[vcache[u] for u in v.ufl_operands])
File "/Users/mohammad.anas7777gmail.com/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ufl/algorithms/check_arities.py", line 42, in sum
raise ArityMismatch("Adding expressions with non-matching form arguments {0} vs {1}.".format(a, b))
ArityMismatch: Adding expressions with non-matching form arguments () vs (Argument(FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2), 6), VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2)), 1, None),).