Hi dokken, I try to write the code again
import numpy as np
from mpi4py import MPI
from ufl import Identity, Measure, TestFunction, TrialFunction, VectorElement, dot, dx, inner, grad, nabla_div, sym
from dolfinx.generation import RectangleMesh
from dolfinx.mesh import CellType, locate_entities_boundary
from dolfinx.fem import (Constant, DirichletBC, Function, LinearProblem, FunctionSpace, VectorFunctionSpace,
locate_dofs_geometrical)
L = 1
nu = 0.499
mu = 1
lambda_ = mu*2*nu/(1-2*nu)
pixel = 1
mesh = RectangleMesh(MPI.COMM_WORLD, np.array([[0, 0, 0], [L, L, 0]]), [pixel, pixel], cell_type=CellType.quadrilateral)
V = VectorFunctionSpace(mesh, ("CG", 1))
Vy = V.sub(1).collapse()
uDy_high = Function(Vy)
with uDy_high.vector.localForm() as uDy_high_loc:
uDy_high_loc.set(-0.2*L)
def highside(x):
return np.logical_and(np.isclose(x[1], L), x[0]<L)
boundary_high = locate_dofs_geometrical((V.sub(1), Vy), highside)
bch = DirichletBC(uDy_high, boundary_high, V.sub(1))
uDy_low = Function(Vy)
with uDy_low.vector.localForm() as uDy_low_loc:
uDy_low_loc.set(0)
def lowside(x):
return np.logical_and(np.isclose(x[1], 0), x[0]<L)
boundary_low = locate_dofs_geometrical((V.sub(1), Vy), lowside)
bcl = DirichletBC(uDy_low, boundary_low, V.sub(1))
Vx = V.sub(0).collapse()
uDx = Function(Vx)
with uDx.vector.localForm() as uDx_loc:
uDx_loc.set(0)
def origin(x):
tol = 1E-14
return np.logical_and(np.isclose(x[0], 0), x[1]<tol)
boundary_origin = locate_dofs_geometrical((V.sub(0), Vx), origin)
bco = DirichletBC(uDx, boundary_origin, V.sub(0))
bcs = [bco, bcl, bch]
def epsilon(u):
return sym(grad(u))
def sigma(u):
return lambda_ * nabla_div(u) * Identity(u.geometric_dimension()) + 2*mu*epsilon(u)
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(mesh, (0, 0))
T = Constant(mesh, (0, 0))
ds = Measure("ds", domain=mesh)
a = inner(sigma(u), epsilon(v)) * dx
L = dot(f, v) * dx + dot(T, v) * ds
problem = LinearProblem(a, L, bcs=bcs, petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
uh = problem.solve()
But I get the error
ArityMismatch Traceback (most recent call last)
/tmp/ipykernel_15/3595350227.py in <module>
63 L = dot(f, v) * dx + dot(T, v) * ds
64
---> 65 problem = LinearProblem(a, L, bcs=bcs, petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
66 uh = problem.solve()
67
/usr/local/dolfinx-complex/lib/python3.8/dist-packages/dolfinx/fem/problem.py in __init__(self, a, L, bcs, u, petsc_options, form_compiler_parameters, jit_parameters)
61 self._A = fem.create_matrix(self._a)
62
---> 63 self._L = fem.Form(L, form_compiler_parameters=form_compiler_parameters, jit_parameters=jit_parameters)
64 self._b = fem.create_vector(self._L)
65
/usr/local/dolfinx-complex/lib/python3.8/dist-packages/dolfinx/fem/form.py in __init__(self, form, dtype, form_compiler_parameters, jit_parameters)
57 else:
58 raise RuntimeError(f"Unsupported scalar type {dtype} for Form.")
---> 59 self._ufc_form, module, self._code = jit.ffcx_jit(
60 mesh.comm,
61 form,
/usr/local/dolfinx-complex/lib/python3.8/dist-packages/dolfinx/jit.py in mpi_jit(comm, *args, **kwargs)
54 # Just call JIT compiler when running in serial
55 if comm.size == 1:
---> 56 return local_jit(*args, **kwargs)
57
58 # Default status (0 == ok, 1 == fail)
/usr/local/dolfinx-complex/lib/python3.8/dist-packages/dolfinx/jit.py in ffcx_jit(ufl_object, form_compiler_parameters, jit_parameters)
207 # Switch on type and compile, returning cffi object
208 if isinstance(ufl_object, ufl.Form):
--> 209 r = ffcx.codegeneration.jit.compile_forms([ufl_object], parameters=p_ffcx, **p_jit)
210 elif isinstance(ufl_object, ufl.FiniteElementBase):
211 r = ffcx.codegeneration.jit.compile_elements([ufl_object], parameters=p_ffcx, **p_jit)
/usr/local/lib/python3.9/dist-packages/ffcx/codegeneration/jit.py in compile_forms(forms, parameters, cache_dir, timeout, cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries)
164 decl += form_template.format(name=name)
165
--> 166 impl = _compile_objects(decl, forms, form_names, module_name, p, cache_dir,
167 cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries)
168 except Exception:
/usr/local/lib/python3.9/dist-packages/ffcx/codegeneration/jit.py in _compile_objects(decl, ufl_objects, object_names, module_name, parameters, cache_dir, cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries)
228 # JIT uses module_name as prefix, which is needed to make names of all struct/function
229 # unique across modules
--> 230 _, code_body = ffcx.compiler.compile_ufl_objects(ufl_objects, prefix=module_name, parameters=parameters)
231
232 ffibuilder = cffi.FFI()
/usr/local/lib/python3.9/dist-packages/ffcx/compiler.py in compile_ufl_objects(ufl_objects, object_names, prefix, parameters, visualise)
96 # Stage 1: analysis
97 cpu_time = time()
---> 98 analysis = analyze_ufl_objects(ufl_objects, parameters)
99 _print_timing(1, time() - cpu_time)
100
/usr/local/lib/python3.9/dist-packages/ffcx/analysis.py in analyze_ufl_objects(ufl_objects, parameters)
60 if isinstance(ufl_objects[0], ufl.form.Form):
61 forms = ufl_objects
---> 62 form_data = tuple(_analyze_form(form, parameters) for form in forms)
63
64 # Extract unique elements across forms
/usr/local/lib/python3.9/dist-packages/ffcx/analysis.py in <genexpr>(.0)
60 if isinstance(ufl_objects[0], ufl.form.Form):
61 forms = ufl_objects
---> 62 form_data = tuple(_analyze_form(form, parameters) for form in forms)
63
64 # Extract unique elements across forms
/usr/local/lib/python3.9/dist-packages/ffcx/analysis.py in _analyze_form(form, parameters)
166
167 # Compute form metadata
--> 168 form_data = ufl.algorithms.compute_form_data(
169 form,
170 do_apply_function_pullbacks=True,
/usr/local/lib/python3.9/dist-packages/ufl/algorithms/compute_form_data.py in compute_form_data(form, do_apply_function_pullbacks, do_apply_integral_scaling, do_apply_geometry_lowering, preserve_geometry_types, do_apply_default_restrictions, do_apply_restrictions, do_estimate_degrees, do_append_everywhere_integrals, complex_mode)
405 preprocessed_form = reconstruct_form_from_integral_data(self.integral_data)
406
--> 407 check_form_arity(preprocessed_form, self.original_form.arguments(), complex_mode) # Currently testing how fast this is
408
409 # TODO: This member is used by unit tests, change the tests to
/usr/local/lib/python3.9/dist-packages/ufl/algorithms/check_arities.py in check_form_arity(form, arguments, complex_mode)
175 def check_form_arity(form, arguments, complex_mode=False):
176 for itg in form.integrals():
--> 177 check_integrand_arity(itg.integrand(), arguments, complex_mode)
/usr/local/lib/python3.9/dist-packages/ufl/algorithms/check_arities.py in check_integrand_arity(expr, arguments, complex_mode)
168 for arg, conj in arg_tuples:
169 if arg.number() == 0 and not conj:
--> 170 raise ArityMismatch("Failure to conjugate test function in complex Form")
171 elif arg.number() > 0 and conj:
172 raise ArityMismatch("Argument {0} is spuriously conjugated in complex Form".format(arg))
ArityMismatch: Failure to conjugate test function in complex Form
So, would you please tell me if there is any error in my defination of boundary conditions(especially at the point(0,0)) or other parts?