Impose condition on polygonal mesh

Hello community,
I am only starting with FeniCS, so I am taking it very slow. I have so far only worked with rectangular meshes and I have successfully solved my test problems. What happens if the boundary is a polygon?
My test code associates boundaries with colours, I am not imposing anything here, I am just trying to ‘find’ the boundary defined by the straight line x[1] == (a-1)/(0.5) * (x[0]-1) + a with x[0] >= 0.5. I can do it if I write a specific value for a (in this example, a = 0.2), but what if I want to write it for a general a? Ultimately, I want to have a for loop for different values of a, where I redefine the boundaries with respect to this a.

from dolfin import *
from mshr import *
# Define mesh and geometry
a = Constant(0.2)
domain = Polygon([Point(1, 0), Point(1, a), Point(0.5, 1), Point(0, 1), Point(0, 0)])
mesh = generate_mesh(domain, 50)
n = FacetNormal(mesh)

# Define Taylor--Hood function space W 
V = VectorElement("CG", triangle, 2)
Q = FiniteElement("CG", triangle, 1)
W = FunctionSpace(mesh, MixedElement([V, Q]))

# Define Function and TestFunction(s)
w = Function(W); (u, p) = split(w)
(v, q) = split(TestFunction(W))


colors = MeshFunction("size_t", mesh, mesh.topology().dim()-1)
colors.set_all(0) # default to zero
x = SpatialCoordinate(mesh)
CompiledSubDomain("near(x[0], 0.0)").mark(colors, 5)
CompiledSubDomain("near(x[1], 1.0) && x[0]<=0.5").mark(colors, 1)
# I can do this for a = 0.2 below, but how to write for just 'a' so that I can change 'a' and then automatically change this too 
CompiledSubDomain("near( ( (0.2-1) /0.5)*(x[0] - 1) + 0.2 - x[1], 0.0) && x[0]>=0.5").mark(colors, 2)
CompiledSubDomain("near(x[0], 1.0)").mark(colors, 3)  # wall
CompiledSubDomain("near(x[1], 0.0)").mark(colors, 4)  # outflow
File("Results/colours.pvd") << colors

Could anyone help me write out boundary 2 correctly for general 1? The problem I want to solve involves varying this constant ‘a’ until a flux condition is met.

Any help would be greatly appreciated!
Ali

I figured it out. In case anyone has a similar question (you never know!), here is how it’s defined

from dolfin import *
from mshr import *
# Define mesh and geometry
a = Constant(0.2)


domain = Polygon([Point(1, 0), Point(1, a), Point(0.5, 1), Point(0, 1), Point(0, 0)])
mesh = generate_mesh(domain, 50)
n = FacetNormal(mesh)

# Define Taylor--Hood function space W 
V = VectorElement("CG", triangle, 2)
Q = FiniteElement("CG", triangle, 1)
W = FunctionSpace(mesh, MixedElement([V, Q]))

# Define Function and TestFunction(s)
w = Function(W); (u, p) = split(w)
(v, q) = split(TestFunction(W))


colors = MeshFunction("size_t", mesh, mesh.topology().dim()-1)
colors.set_all(0) # default to zero

CompiledSubDomain("near(x[0], 0.0)").mark(colors, 5)
CompiledSubDomain("near(x[1], 1.0) && x[0]<=0.5").mark(colors, 1)
a1 = "0.2"
CompiledSubDomain("near( ( ("+a1+"-1) /0.5)*(x[0] - 1) +" + a1 + "- x[1], 0.0) && x[0]>=0.5").mark(colors, 2)
CompiledSubDomain("near(x[0], 1.0)").mark(colors, 3)  # wall
CompiledSubDomain("near(x[1], 0.0)").mark(colors, 4)  # outflow
File("Results/colours.pvd") << colors

CompiledSubDomain requires a string, and you can append the strings with ‘+’, so that you can use a predefined ‘a1’, instead of writing the explicit number.

Thanks anyway!