I have the following form and corresponding boundary conditions:
from fenics import *
mesh = UnitSquareMesh(16,16)
VectorSpaces=[["Lagrange",2],["Lagrange",1]]
V = VectorElement(VectorSpaces[0][0],mesh.ufl_cell(),VectorSpaces[0][1])
Q = FiniteElement(VectorSpaces[1][0],mesh.ufl_cell(),VectorSpaces[1][1])
K = FunctionSpace(mesh,"DG",0)#function space of piecewise constants
Welem = MixedElement([V,Q])
W = FunctionSpace(mesh,Welem)
up = TrialFunction(W)
u,p = split(up)
vq = TestFunction(W)
v,q = split(vq)
F = (
inner(dot(grad(u),u),v)*dx - #Nonlinear Advection Term
inner(p,div(v))*dx + #Pressure Gradient term
inner(grad(u),grad(v))*dx + #Diffusion Term
inner(q,div(u))*dx # Divergence-Free Condition Term
)
#boundary conditions
inflow = 'near(x[0], 0)'
outflow = 'near(x[0], 1)'
down = 'near(x[1], 0)'
up = 'near(x[1], 1)'
al = 'near(x[0], 0) || near(x[0], 1) || near(x[1], 0) || near(x[1], 1)'
# Define boundary conditions
bcu_down = DirichletBC(W.sub(0), Constant((0, 0)), down)
bcu_up = DirichletBC(W.sub(0), Constant((1, 0)), up)
bcp_inflow = DirichletBC(W.sub(1), Expression("0",degree=2), inflow)#0 pressu
bcp_outflow = DirichletBC(W.sub(1), Expression("0",degree=2), outflow)#
bdc = [bcp_inflow,bcp_outflow,bcu_up,bcu_down]
How would I obtain a dolfin.cpp.la.Vector
vector of the gradient of F
given a specific function up
.