There are many problems with your code, including several typos.
Here is a code that compiles, where I use a MixedElement
to define the function space.
Also there are typos in your class Entree
, and in your variational problem in solve you have issues as well.
from dolfin import *
from fenics import *
nu=1E-5
tol=1E-14
X=10
Y=2
from mshr import *
nx=100
ny=20
mesh2 = RectangleMesh(Point(0.0, -1.0), Point(X, Y-1.0), nx, ny, "left")
Ve = VectorElement("P",triangle, 2)
Qe = FiniteElement("P",triangle, 1)
W = FunctionSpace(mesh2, MixedElement([Ve, Qe]))
class Bord(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and ((abs(x[1] - 1) < tol) or (abs(x[1] + 1) < tol))
class Entree(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and (abs(x[0] - 0))
class Sortie(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and (abs(x[0] - 10) < tol)
b_haut_bas = Bord()
bhbD = DirichletBC(W.sub(0), (0, 0), b_haut_bas)
b_in = Entree()
b_ex = Sortie()
inD = DirichletBC(W.sub(1), Constant(10), b_in)
exD = DirichletBC(W.sub(1), Constant(8), b_ex)
bcu = [bhbD,inD,exD]
class BordFlux(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and ((abs(x[0] - 0) < tol) or (abs(x[0] - 10) < tol))
bfN = BordFlux()
boundaries = MeshFunction("size_t", mesh2, mesh2.topology().dim()-1, 0)
bfN.mark(boundaries, 0)
ds = Measure("ds", domain=mesh2, subdomain_data=boundaries)
v, q = TestFunctions(W)
u, p = TrialFunctions(W)
a1 = nu*inner(grad(u), grad(v))*dx - inner(p, div(v))*dx - inner(q, div(u))*dx
l1 = inner(Constant((0,0)), v)*dx
up = Function(W)
u, p = split(up)
solve(a1 == l1, up, bcu)