Set value in different subdomains

Asked by Melanie Jahny

My mesh consists of two different subdomains. I need a function k that is constant in each subdomain,
but contains different values for each subdomain. I did it as discribed in the manual:

mesh = Rectangle(0,0,1,1,10,10)
mesh.order()

class Channel(SubDomain):
   def inside(self,x,on_boundary):
       return True if x[1] > 0.5 else False

class Membrane(SubDomain):
   def inside(self,x,on_boundary):
       return True if x[1] <= 0.5 else False

subdomains = MeshFunction('uint', mesh, 2) # 2 dimensional subdomains

sub_channel = Channel()
sub_channel.mark(subdomains,0)

sub_membrane = Membrane()
sub_membrane.mark(subdomains,1)

V0 = FunctionSpace(mesh, "DG", 0)
k = Function(V0)

k_values = [1.5, 5] # values of k in the two subdomains
for cell_no in range(len(subdomains.values())):
 subdomain_no = subdomains.values()[cell_no]
 k.vector()[cell_no] = k_values[subdomain_no]

But using this syntax, I get the following error:

for cell_no in range(len(subdomains.values())):
AttributeError: 'MeshFunctionUInt' object has no attribute 'values'

Please can anybody help me how I can define the k-Function on different
subdomains. I'm using the Fenics-Version 1:1.0-beta2-2 for ubuntu.
Thanks a lot in advance!

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Praveen C
Solved:
Last query:
Last reply:
Revision history for this message
Best Praveen C (cpraveen) said :
#1

values() seems to be removed. Use subdomains.array() which works for me.

Revision history for this message
Melanie Jahny (melanie-jahny) said :
#2

Thanks a lot Praveen C, it works!!!