I encountered an error message as follow. I tried some online solutions but they don’t work in my case. Would anyone be able to offer me some guidance or assistance?
Found different Arguments with same number and part.
Did you combine test or trial functions from different spaces?
The Arguments found are:
v_0
v_1
v_1
v_0
ERROR:UFL:Found different Arguments with same number and part.
Did you combine test or trial functions from different spaces?
The Arguments found are:
v_0
v_1
v_1
v_0
Traceback (most recent call last):
File "/Users/victoriachan/Documents/CityU Doc/FYP/python_files/ProgramV3.py", line 53, in <module>
a = form(inner(kappa * div(w), div(p)) * dx + inner(grad(kappa * div(w)), p - grad(v)) * ds + inner(w - grad(u), grad(kappa * div(p))) * ds + tau/h**2 * inner(kappa*(w - grad(u)), p - grad(v)) * ds)
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 176, in form
return _create_form(form)
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 171, in _create_form
return _form(form)
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 145, in _form
ufcx_form, module, code = jit.ffcx_jit(mesh.comm, form,
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/dolfinx/jit.py", line 56, in mpi_jit
return local_jit(*args, **kwargs)
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/dolfinx/jit.py", line 204, in ffcx_jit
r = ffcx.codegeneration.jit.compile_forms([ufl_object], options=p_ffcx, **p_jit)
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/ffcx/codegeneration/jit.py", line 165, in compile_forms
ffcx.naming.compute_signature(forms, _compute_option_signature(p)
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/ffcx/naming.py", line 33, in compute_signature
object_signature += ufl_object.signature()
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/ufl/form.py", line 435, in signature
self._compute_signature()
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/ufl/form.py", line 685, in _compute_signature
self._compute_renumbering())
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/ufl/form.py", line 648, in _compute_renumbering
cn = self.coefficient_numbering()
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/ufl/form.py", line 421, in coefficient_numbering
self._analyze_form_arguments()
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/ufl/form.py", line 635, in _analyze_form_arguments
arguments, coefficients = extract_arguments_and_coefficients(self)
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/ufl/algorithms/analysis.py", line 139, in extract_arguments_and_coefficients
error(msg)
File "/Users/victoriachan/opt/anaconda3/envs/fenicsdolxconda/lib/python3.10/site-packages/ufl/log.py", line 135, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Found different Arguments with same number and part.
Did you combine test or trial functions from different spaces?
The Arguments found are:
v_0
v_1
v_1
v_0
My code:
import numpy as np
import ufl
from dolfinx import cpp as _cpp
from dolfinx import fem
from dolfinx.fem import (Constant, Function, FunctionSpace, dirichletbc,
extract_function_spaces, form,
locate_dofs_geometrical, locate_dofs_topological)
from dolfinx.io import XDMFFile
from dolfinx.mesh import (CellType, GhostMode, create_rectangle,
locate_entities_boundary)
from ufl import div, ds, dx, grad, inner
from mpi4py import MPI
from petsc4py import PETSc
# Create mesh
msh = create_rectangle(MPI.COMM_WORLD,
[np.array([0, 0]), np.array([1, 1])],
[32, 32],
CellType.triangle, GhostMode.none)
def noslip_boundary(x):
return np.logical_or(np.logical_or(np.isclose(x[0], 0.0),
np.isclose(x[0], 1.0)),
np.logical_or(np.isclose(x[1], 0.0),
np.isclose(x[1], 1.0)))
P2 = ufl.VectorElement("Lagrange", msh.ufl_cell(), 2)
P1 = ufl.FiniteElement("Lagrange", msh.ufl_cell(), 1)
V, Q = FunctionSpace(msh, P2), FunctionSpace(msh, P1)
noslip = np.zeros(msh.geometry.dim, dtype=PETSc.ScalarType)
facets = locate_entities_boundary(msh, 1, noslip_boundary)
bc0 = dirichletbc(noslip, locate_dofs_topological(V, 1, facets), V)
bcs = [bc0] # For more than 1 boundary conditions: bcs = [bc0, bc1]
# Define variational problem
(w, u) = ufl.TrialFunction(V), ufl.TrialFunction(Q)
(p, v) = ufl.TestFunction(V), ufl.TestFunction(Q)
kappa = 1.0
tau = 1.0
h = 3.0
# a = inner(kappa * div(w), div(p)) * dx + inner(grad(kappa * div(w)), p - grad(v)) * ds + inner(w - grad(u), grad(kappa * div(p))) * ds + tau/h**2 * inner(kappa*(w - grad(u)), p - grad(v)) * ds
a = form(inner(kappa * div(w), div(p)) * dx + inner(grad(kappa * div(w)), p - grad(v)) * ds + inner(w - grad(u), grad(kappa * div(p))) * ds + tau/h**2 * inner(kappa*(w - grad(u)), p - grad(v)) * ds)
A = fem.petsc.assemble_matrix(a, bcs=bcs)
A.assemble()