# defining subdomains in FEniCS (Python) using obtained (solved) variable [closed]

I'd very much appreciate if you could help me out with this as I think I'm missing something simple out or should be using alternate syntax:

I am running the following Python code in FEniCS, where I solve for a variable - the solution looking as I expect it to, so no problems there, now I wish to solve a next equation and I need to define the subdomains according to the obtained solution, but the resultant plot of subdomains for the new problem (in the same code) is erroneous. It looks as if it cannot take the solution variable as a legitimate parameter appearing in the subdomain definitions; perhaps I need to change/avoid the inside method?

solve(a == L, phi1)

plot(phi1, title="phi1_t01")

# S at t1
# define mesh
htopv = 0.5

mesh = Rectangle(0, 0, 1, htopv, 250, 250)

# define a meshfunction for numbering subdomains
subdomains = MeshFunction("uint", mesh, 2)

# define the subdomains
class Biomass(SubDomain):
def inside(self, x):
return True if phi1 <= 0 else False
class Interface(SubDomain):
def inside(self, x):
return True if phi1 >= 0 and phi1 <= 0.1 else False
class Bulk(SubDomain):
def inside(self, x):
return True if phi1 >= 0.1 else False
# note: it is essential to use <= and >= in the comparisons

# mark the subdomains with numbers
subdomain0 = Biomass()
subdomain0.mark(subdomains, 0)
subdomain1 = Interface()
subdomain1.mark(subdomains, 1)
subdomain2 = Bulk()
subdomain2.mark(subdomains, 2)

# plot the subdomains
plot(subdomains, title="S_t1 subdomains")

• Welcome to SciComp.SE! This is a (programming) question specifically about FEniCS, and not about the use of FEniCS in a scientific context. You will probably get much better answers at the FEniCS Q&A site. (When you post your question there, make sure to post a minimal, but complete code, i.e., code someone can just copy into a file and run. That makes helping you much easier.) – Christian Clason Jun 24 '13 at 17:42
• Thank you and sorry. Sure, I shall consult the FEniCS Q&A site for similar problems. – micawber Jun 24 '13 at 18:31
• No worries, it's a good question -- but now that the FEniCS developers created their own Q&A site, it makes sense to collect all FEniCS specific questions over there so people don't have to search (or post) on two sites. – Christian Clason Jun 24 '13 at 18:36

You need to evaluate the Function at the given point. Assuming phi1 is a scalar Function, try:

class Bulk(SubDomain):
def inside(self, x, on_boundary):
return phi1(x) >= 0.1


and similar for the other SubDomains