Error: Transposed is only defined for rank 2 tensors

I am getting the following error at the line where a is defined:
ufl.log.UFLException: Transposed is only defined for rank 2 tensors.

My code is below, please assist if you can, thank you!

""" Boundary Conditions (Part 1) """
class PeriodicBoundary_x(SubDomain):
	def inside(self, x, on_boundary):
		return x[0] == 0 and on_boundary
	def map ( self, x, y ):
		y[0] = x[0] - Le
		y[1] = x[1]
pbc_x = PeriodicBoundary_x()

""" Define Mesh and Function Spaces """
domain = Rectangle(Point(0.0, 0.0), Point(Le, He))
mesh = generate_mesh(domain, 16.0) 
V = FiniteElement("CG", mesh.ufl_cell(), 2)
Q = FiniteElement("CG", mesh.ufl_cell(), 1)
W_elem = MixedElement([V, Q])
W = FunctionSpace(mesh, W_elem, constrained_domain = pbc_x)

""" Boundary Conditions (Part 2) """
def LowerBoundary(x, on_boundary):
	return x[1] < DOLFIN_EPS and on_boundary
SlipRate = Expression("(3.0 + 1.7*sin(2.0*pi*x[0]/L))", degree = 1, L = 31557686.4)
bcD = DirichletBC(W.sub(0), SlipRate, LowerBoundary)

""" Define Variational Problem """
(v_i, q_i) = TestFunctions(W)
(u_i, p_i) = TrialFunctions(W)
a = (0.5*mu*inner(grad(v_i) + grad(v_i).T, grad(u_i) + grad(u_i).T) - div(v_i)*pi + q_i*div(u_i))*dx
L = inner(v_i, G)*dx

As V is a scalar element, grad(u) is a vector, and is does not make sense to transpose the vector, as you cannot add a (2,) vector with a (,2) vector

1 Like

How would I go about fixing this issue as I am still confused, would I change the rank to be 1 instead of 2?

You Need to write out your variational form for me to be of any further help.


This is the variational form, let me know if you may need anything else for further assistance.

1 Like

So here \mathbf{u} is a vector, therefore

has to be replaced by

V = VectorElement("CG", mesh.ufl_cell(), 2)
1 Like

Thank you, this has fixed my issue, but now I am getting another error with the solve portion of the code as seen below.

U = Function(W)
solve(a==L, U, bcD)
(u, p) = U.split()

Traceback (most recent call last):
File “main.py”, line 46, in
solve(a==L, U, bcD)
File “/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/solving.py”, line 233, in solve
_solve_varproblem(*args, **kwargs)
File “/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/solving.py”, line 268, in _solve_varproblem
problem = LinearVariationalProblem(eq.lhs, eq.rhs, u, bcs,
File “/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/problem.py”, line 59, in init
a = Form(a, form_compiler_parameters=form_compiler_parameters)
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
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 26, in map_expr_dag
result, = map_expr_dags(function, [expression], compress=compress)
File “/usr/lib/python3/dist-packages/ufl/corealg/map_dag.py”, line 75, in map_expr_dags
r = handlers[v.ufl_typecode](v, *[vcache[u] for u in v.ufl_operands])
File “/usr/lib/python3/dist-packages/ufl/algorithms/check_arities.py”, line 48, in sum
raise ArityMismatch(“Adding expressions with non-matching form arguments {0} vs {1}.”.format(_afmt(a), _afmt(b)))
ufl.algorithms.check_arities.ArityMismatch: Adding expressions with non-matching form arguments (‘v_0’,) vs (‘v_0’, ‘v_1’).

Please note that the code you have supplied is not complete, and can not reproduce your error message. For further questions, I would recommend you to follow the examples posted at: Read before posting: How do I get my question answered? - #4 by nate
and make sure your code reproduces your error message.

For this particular problem, the culprit is most likely

as I think you meant to use p_i and not pi