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

Problem during transition from CGAL to mshr

+3 votes

Hi everyone.
I am running on linux mint 17 [~ Ubuntu Trusty] and I recently got updates from apt for fenics from the custom PPA which broke the support for CSG.

I am aware of this conversation, dated July 2014, in which is said that the transition from CGAL to mshr should be seamless but, at least in my case, I have been less lucky than expected.

My programs using CSG now fail with

Error: Unable to create mesh from CSG geometry.
Reason: Mesh generation not available. Dolfin has been compiled without CGAL..
Where: This error was encountered inside CSGMeshGenerator.cpp.

How can I fix this?
Thanks for help,
Massimiliano

asked Nov 12, 2014 by Massimiliano Leoni FEniCS User (1,760 points)
reopened Dec 14, 2014 by Massimiliano Leoni

More or less seamless. You need to use the methods from mshr, see its demos.

Ok, I finally got it to work; it asked me to learn another bit of CMake, but that can't hurt :)

Im having the same error and trouble solving this problem. How did you do it?

Are you talking about using mshr or setting CMakeLists.txt?

I have to admit, I'm not quite sure. I guess im using the right mshr syntax but it somehow doesn't work:

Using the old syntax
dolfin::CircleMesh mesh(dolfin::Point(0.0,0.0), radius, 0.03);

gives me the error

*** Error: Unable to generate ellipse mesh.
*** Reason: Generation of ellipse meshes requires DOLFIN to be configured with CGAL.
*** Where: This error was encountered inside EllipseMesh.cpp.
*** Process: unknown

What would be the correct translation into new mshr syntax? I tried

dolfin::Circle circle(0.0, 0.0, radius);
dolfin::Mesh mesh(circle, 0.03);

but that gives me the error

*** Error: Unable to create mesh from CSG geometry.
*** Reason: Mesh generation not available. Dolfin has been compiled without CGAL..
*** Where: This error was encountered inside CSGMeshGenerator.cpp.
*** Process: unknown

which is the same as your error. I have reinstalled fenics via purging and adding the repository, but that didn't help. How did you solve this problem?

edit: What is the c++ alternative/syntax for from mshr import *? Using #include gives a mshr could be resolved error, like it hasn't been installed.

Try

#include <mshr.h>
[...]
mshr::Circle obstacle(Point(xc,yc,0),r);
Mesh mesh;
mshr::generate(mesh,obstacle,resolution);

Thanks it is finally working. After using your code I just had to add the line

env.Append(LIBS = ['mshr'])

to my SCons file.

2 Answers

+2 votes

Hi!

Here is a simple example of what you would do earlier:

from dolfin import *

res = 100
r1 = Rectangle(0, 0, 1, 2)
r2 = Rectangle(0.4, 0.4, 0.6, 0.7)

mesh = Mesh(r1 - r2, res)

This chunk of code as you have discovered returns the CGAL error. When applying mshr the syntax is slightly different:

from dolfin import *
from mshr import *

r1 = Rectangle(Point(0,0), Point(1,2))
r2 = Rectangle(Point(0.4, 0.4), Point(0.6, 0.7))

# Define domain and resolution
domain = r1 - r2
res = 100

# Generate mesh
mesh = generate_mesh(domain, res)

Just a basic example but you get the idea, check out mshr on bitbucket for more info: https://bitbucket.org/benjamik/mshr

answered Nov 12, 2014 by joakibo FEniCS User (1,140 points)
0 votes

Yes, I had figured that out earlier, reading through the API.
Also, the C++ interface is slightly different as the method is generate and has different signature.
However, I got it to work now, we can close this.

answered Nov 12, 2014 by Massimiliano Leoni FEniCS User (1,760 points)
...