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

Boolean operation on two dolfin meshes with mshr

+2 votes

Hello,

I would like to perform a boolean operation on two dolfin meshes in mshr, but I cannot find any tutorial for that. Is it possible with mshr lib. in python?

Petr

asked Feb 11, 2016 by petrH FEniCS Novice (580 points)

2 Answers

0 votes

I don't use Python, I use C++, but it should be the same (python wraps C++).

You should be able just to use - to create holes, for instance in C++:

    // Polyline
    mshr::Polygon polyline(pts);

    // Create the holes
    mshr::Circle hole1(center1, radius1);
    mshr::Circle hole2(center2, radius2);
    mshr::Circle hole3(center3, radius3);

    // Create the polygon with holes
    auto difference = polyline - hole1 - hole2 - hole3;

So I think you may try other operators as well.

Hope this helps!

answered Feb 12, 2016 by senseiwa FEniCS User (2,620 points)

Thank you,
and what about two meshes from xml:

mesh1 = Mesh("file1.xml")
mesh2 = Mesh("file2.xml")

mesh_diff = mesh1 - mesh2  # it does not work

I understand that meshes must be domain in mshr somehow. What is the right way?

I don't know in Python, but there are APIs in mshr to read files (STL, for instance). You can try to match these functions with a Python-esque syntax.

I hope it helps.

+1 vote

Hello, Petr

I suggest you try:

# Importing libraries
from dolfin import *
from mshr import *

# Generating geometry
ret = Rectangle(Point(0,0), Point(1,2))
circ = Circle(Point(0.5,1),0.15)

# Define domain and resolution
domain = ret - circ
res = 125

# Generate mesh
mesh = generate_mesh(domain, res)
plot(mesh)

By doing so, you generate a geometric domain by combining domains with mshr and then build a mesh inside your desired domain.

Hope it helps...

Best Regards!
Diego

answered Jul 13, 2016 by prado.dis FEniCS Novice (230 points)

Excelent!

It worked for me perfectly.

Thanks,
Bruno

...