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

Use of mshr in c++

+3 votes

Hello,

i have recently updated my libraries via sudo apt-get update and now I can't create any meshes with fenics. Before the update I was using

dolfin::CircleMesh mesh(dolfin::Point(0.0,0.0), radius, 0.03);

but this isn't working anymore. I can the error following error message

*** 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
*** DOLFIN version: 1.4.0
*** Git changeset: unknown

I found out that something has changed with the mesh creation with the last update, but I couldn't exactly find a c++ code sample how I have to change my code (only found python examples). I already reinstalled fenics to check if dependencies were destroyed or something like that, but it didn't help.

Can anyone help me to fix this problem? I assume it is still possible to create a simple circle mesh, if I would just know right lines of code. :)

Thank you!

asked Dec 14, 2014 by soply FEniCS Novice (400 points)

1 Answer

+1 vote

You should be able to use mshr from C++.
See https://bitbucket.org/benjamik/mshr/wiki/API

answered Dec 14, 2014 by chris_richardson FEniCS Expert (31,740 points)

Thanks, I wanted to use this, but somehow im missing the right includes?

I tried the following:

mshr::Circle circle(dolfin::Point(0,0),heartwood_thickness + sapwood_thickness + bark_thickness);
dolfin::Mesh mesh(circle, 0.03);

but i am getting " mshr has not been declared error". What do I have to import here?

#include <mshr> 

wont work, because it couldn't be found. In python I could use from mshr import *, but what is the c++ code for that?

Thanks!

Try including mshr.h, it works for me on debian testing.

Thanks that worked. Now with the API I want to create a mesh with

mshr::Circle circle(dolfin::Point(0.0,0.0),radius);
mshr::CSGCGALMeshGenerator2D mesh_generator;
dolfin::Mesh mesh;  
mesh_generator.generate(circle, mesh);

but I'm getting undefined reference errors on any mshr classes like

/usr/include/mshr/CSGPrimitive.h:29: Non defined reference to mshr::CSGGeometry::~CSGGeometry()' /usr/include/mshr/CSGPrimitive.h:29: Non defined reference tomshr::CSGGeometry::~CSGGeometry()'

Do I have to change my SCons file to add mshr library? Im sorry, I guess this is a very simple problem but I can't figure out a solution because i'm new to all this stuff. :)

I put this in my CMakeLists.txt

# Find mshr
find_library(MSHR_LIBRARY mshr)

add_executable(myTarget main.cpp)

target_link_libraries(myTarget ${DOLFIN_LIBRARIES}
${DOLFIN_3RD_PARTY_LIBRARIES} ${MSHR_LIBRARY})

You should have something similar somewhere.

Yes that was the main problem, I had to add the line

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

to the SCons file for compiling my programm.

...