This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Subdomains defining

0 votes

Hello
I want to define a domain that I want to call "domain of interest". This domain includes multiple subdomains. In my case the geometry is kind of complicated. For example please take a look at below image (it is just an example):

enter image description here

The red area is the domain of interest and the white, blue, black and green areas are the subdomains. I can simply define the subdomains (Omega1,Omega2,Omega3,Omega4)
For example:

#Domain 1
class Omega1(SubDomain):
 def inside(self, x, on_boundary):
  return True if b<x[0]<=(b+d) and 0<=x[1]<=b else False

#Domain 2
class Omega2(SubDomain):
 def inside(self, x, on_boundary):
   return True if b<x[0]<=(b+d) and b<x[1]<=(b+d) else False

#Domain 3
class Omega3(SubDomain):
  def inside(self, x, on_boundary):
   return True if 0<=x[0]<=b and b<x[1]<=(b+d) else False

#Domain 4
  class Omega4(SubDomain):
    def inside(self, x, on_boundary):
      return True if b<x[0]<=(b+d) and b<x[1]<=(b+d) else False

I want to define the red area as another subdomain (omega 5) in a way that if the rest of the geometry does not include the Omega1,Omega2,Omega3,Omega4 it is equal to omega5 which is the red area. In other words I do not want to define the geometry mathematically for the red area because it is not that easy.
Does anybody know how I can do that in FEniCS?
Thanks!

asked Jun 4, 2016 by Ramon FEniCS Novice (340 points)

1 Answer

0 votes
 
Best answer

Hi, you can mark whole domain 'red' first and then change the colors for the shapes with simpler geometrical description, i.e. Omega_5 = Omega - (Omega_1+Omega_2+...).

from dolfin import *

mesh = UnitSquareMesh(10, 10)
# All is tagged as 'red' first
domains = CellFunction('size_t', mesh, 5)
# Let some shape mark its domain
uh = CompiledSubDomain('x[1] > 0.5')
uh.mark(domains, 1)

plot(domains)
interactive()
answered Jun 4, 2016 by MiroK FEniCS Expert (80,920 points)
selected Jun 6, 2016 by Ramon

Thank You! That was helpful.

...