Hello,
I am new to Fenics. I am trying to solve a simple 2d problem(code below).
\nabla^2 v_\alpha =\xi v_\alpha + g_\alpha (x,y) (alpha=x or y)
from fenics import *
import numpy as np
import matplotlib.pyplot as plt
a=Constant(100)
xi=Constant(100)
mesh = UnitSquareMesh(32, 32)
P1 = FiniteElement('P', triangle, 1)
element = MixedElement([P1, P1])
V = FunctionSpace(mesh, element)
v1, v2 = TestFunctions(V)
u = Function(V)
u1, u2 = split(u)
g=Expression('exp(-((x[0]-0.5)*(x[0]-0.5)+(x[1]-0.5)*(x[1]-0.5))/0.05)',degree=2)
F=-dot(grad(u1),grad(v1))-dot(grad(u2),grad(v2))-xi*(u1*v1+u2*v2)-g*v2
a=-dot(grad(u1),grad(v1))*dx-dot(grad(u2),grad(v2))*dx
L=xi*(u1*v1+u2*v2)*dx+g*v2*dx
be = Constant(0)
def boundary_L(x, on_boundary):
return on_boundary and near(x[0], 0, 1e-14)
def boundary_R(x, on_boundary):
return on_boundary and near(x[0], 1, 1e-14)
def boundary_B(x, on_boundary):
return on_boundary and near(x[1], 0, 1e-14)
def boundary_T(x, on_boundary):
return on_boundary and near(x[1], 1, 1e-14)
def boundary(x,on_boundary):
return on_boundary
bcs=[DirichletBC(V.sub(0), be, boundary_L),DirichletBC(V.sub(0), be, boundary_R),DirichletBC(V.sub(1), be, boundary_B),DirichletBC(V.sub(1), be, boundary_T)]
solve(a==L,u,bcs)
However, I am getting the error: Unable to define linear variational problem a(u, v) == L(v) for all v.
With reason: Expecting the left-hand side to be a bilinear form (not rank 1).
What am I doing wrong?