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

how to create defect (hole) in mesh with subregions

0 votes

I'm asking for some advice regarding how to create (mesh) a hole in a solid with different subregions.

Initially I had a block of two materials glued together. I want to model a contact gap/crack in a material. It would be OK by me if I could somehow separate a part of the materials interface to create a crack. I was unable to do that, but if anyone has an idea, then please tell.

Then I tried to create a small hole region in material, but it seems that the hole is closed by meshing program as soon as I try to designate some subregions inside it? Question is, how can I fix or sidestep the problem?

from dolfin import *
from mshr import Rectangle, Circle, Ellipse, generate_mesh

# height and width of square with defect width and thickness
height = 20e-3
width = 20e-3
defectwidth = width/2.0
defectthickness = height/20.0

# the block itself
geometry1 = Rectangle(Point(0, 0),
                      Point(width, height))
# the defect in the middle of the block
geometry2 =  Rectangle(Point(width/4.0, (height- defectthickness)/2.0),
                       Point(width*3.0/4.0, (height +  defectthickness)/2.0))

# just see how the block with defect looks
geometry = geometry1  - geometry2
plot(generate_mesh(geometry, 20), interactive=True)




# I now want to set some subdomains in the solid region (not even close to the defect)
geometry.set_subdomain(1, Rectangle(Point(0,0),
                                    Point(width, height/4)))
geometry.set_subdomain(2, Rectangle(Point(0, height/1.5),
                                    Point(width, height)))


# the defect is gone?
plot(generate_mesh(geometry, 20), interactive=True)
asked Mar 25, 2016 by mrtn184 FEniCS Novice (120 points)

2 Answers

+1 vote

That behaviour is a known bug of the mshr 1.6 library (see here and here). To fix your problem you need to install the development version of the mshr library (or dev version of fenics).

answered Mar 30, 2016 by hernan_mella FEniCS Expert (19,460 points)

(i have tested your code using fenics 1.7dev version and works fine)

0 votes

Another option is to use the program GMSH to define your geometry and the corresponding mesh, and then import this in FEniCS to work with. I have no experience with mshr, but I do believe GMSH will be easier if you need less conventional shapes.

answered Apr 1, 2016 by maartent FEniCS User (3,910 points)
...