Hello Everyone!,
I am trying to solve this system of equations:
\nabla{u_i}+u_i(\nabla{u_p})=0 here i=1,...n
&
\nabla.(\nabla{u_p})=-f\sum_{i=1}^{n}z_iu_i
here u_i and u_p are functions to be solved in a unit square domain.
I am trying to solve the system by using mixed element function such as described by the advection diffusion reaction tutorial. here is a mwe.
from fenics import *
#parameters inside variational form
z_a1 = 1
z_a2 = -1
f = Constant(43)
#Create mesh and define function space
mesh = UnitSquareMesh(8, 8)
degree = 1
P3 = FiniteElement('P', triangle, degree)
element = MixedElement([P3, P3, P3])
V = FunctionSpace(mesh, element)
a=d
(v_a1, v_a2, v_p) = TestFunctions(V)
u = Function(V)
(u_a1, u_a2, u_p) = split(u)
#Boundary connditions
tol = 1E-14
def boundary_R(x, on_boundary):
return on_boundary and (near(x[0], 0, tol))
def boundary_L(x, on_boundary):
return on_boundary and (near(x[0], 1, tol))
bc1 = DirichletBC(V.sub(0), Constant(1.0), boundary_R)
bc2 = DirichletBC(V.sub(1), Constant(1.0), boundary_L)
bc3 = DirichletBC(V.sub(2), Constant(-0.5), boundary_L)
bc4 = DirichletBC(V.sub(2), Constant(0.0), boundary_R)
bcs = [bc1, bc2, bc3, bc4]
#Variational Form residues residues
F_a1 = grad(u_a1) * v_a1 * dx + z_a1 * u_a1 * grad(u_p) * v_a1 * dx
F_a2 = grad(u_a2) * v_a2 * dx + z_a2 * u_a2 * grad(u_p) * v_a2 * dx
F_p = (-80)*dot(grad(u_p), grad(v_p)) * dx + (z_a1 * u_a1 + z_a2 * u_a2) * f * v_p * dx #poisson eqn
F = F_a1 + F_a2 + F_p
#Solver
solve(F == 0, u, bcs, solver_parameters={
'nonlinear_solver': 'newton',
'newton_solver': {
'linear_solver': 'mumps',
'maximum_iterations': 50,
'relative_tolerance': 1.0e-4}})
#Fetching the values
_u_a1, _u_a2, _u_p = u.split()
vtkfile_a1 = File('u1.pvd')
vtkfile_a1 << _u_a1
vtkfile_a2 = File('u2.pvd')
vtkfile_a2 << _u_a2
vtkfile_p = File('p.pvd')
vtkfile_p << _u_p
The error i am getting is
Can only integrate scalar expressions. The integrand is a tensor expression with value shape (2,) and free indices with labels ().
Traceback (most recent call last):
File “/home/PycharmProjects/MWE.py”, line 36, in
F_a1 = grad(u_a1) * v_a1 * dx + z_a1 * u_a1 * grad(u_p) * v_a1 * dx
File “/usr/lib/python3/dist-packages/ufl/measure.py”, line 406, in rmul
error("Can only integrate scalar expressions. The integrand is a "
File “/usr/lib/python3/dist-packages/ufl/log.py”, line 158, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Can only integrate scalar expressions. The integrand is a tensor expression with value shape (2,) and free indices with labels ().
Process finished with exit code 1.
It seems like my variational formulation for the first equation is not right. I was wondering how the system can be solved with the formulation such as in the mwe with mixed element method. I would really appreciate any help.