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

What is the advantage of handling domains with different materials using subdomains?

+2 votes

Dear all,

So I have been looking at the tutorial about using subdomains and there must be something I do not understand because I have always been doing as follows:

def isInRegion1(x):
    return   x[1]<0.5e-2 

class MyCrossSection(Expression):
    def eval(self, value, x):
        if  isInRegion1(x):
            value[0] = sigma_t_1
        else:
            value[0] = sigma_t_2

    def value_shape(self):
        return (1,)

Sigma_t = MyCrossSection()
...
a += (Sigma_t[0]+1/(c*dt))*psi*v*dx  # some component of the bilinear form

Which seems easier to me to use than subdomains.

So I probably don't get the full potential of using subdomains. Are there cases in which subdomains could help do something that the method above could not?

Thanks a lot!
Vincent

asked Sep 4, 2014 by V_L FEniCS User (4,440 points)

3 Answers

+1 vote
 
Best answer

Hi,

I personally prefer the subdomains approach, as it allows me to write one version of the weak form and specify material regions programmatically (by subclassing SubDomain and manually marking the subdomains MeshFunction as described in the tutorial) in simple cases, while use GMSH for more complicated material regions (to be honest, I use GMSH even for simpler regions as I like to see what is marked before I run the calculation).

So I typically create a mesh and specify physical regions in GMSH, run the .msh file through dolfin_convert and just use

subdomains = MeshFunction("size_t", mesh, "mesh_physical_regions.xml")

with the generated physical regions file (analogous approach can be used also for boundaries).

answered Sep 5, 2014 by mhanus FEniCS Novice (930 points)
selected Sep 8, 2014 by V_L

I think I better understand why using subdomains is preferable, thanks a lot!

+1 vote

Hi,

I find it convenient to use subdomains when I am dealing with materials with rough, irregular interfaces. It also means I can write a script that robustly imports different meshes from external specialist mesh programs like GMSH.

answered Sep 4, 2014 by sixtysymbols FEniCS User (2,280 points)

Thanks for the answer! :)

What confuses me is that in both cases you need to define a function to explicit what is in a given region and what is not (isInRegion1(x) in the example above and inside(self, x, on_boundary) if using subdomains)

So could you explain to me why the second approach is more robust?

I am asking this because I precisely imported a mesh from GMSH and the solver takes forever (compared to if I use a similar mesh using RectangleMesh) so I am wondering if it is because I should use subdomains or not

Thanks for the help!

+1 vote

Suppose you have a circular subdomain. Of course you can treat it as above. But after obtaining the solution, suppose you want to evaluate an integral on the subdomain, you can compute it very easily as Fdx(i) where i is ith subdomain .

You might be able to do this your own way, but I think it will be painful .

answered Sep 5, 2014 by shriram FEniCS User (1,540 points)

That's indeed a good reason to use subdomains, thanks!

...