Upgrade from version 2016.2 to 2017 now produces std::bad_alloc error

9 months ago by
Last year I used to work with FEniCS version 2016.2 on my Ubuntu 16.04 installed via apt-get to solve a problem where the mesh was a rectangle with a circular hole inside. This mesh was constructed with mshr using the code
	auto rectangle = std::make_shared<mshr::Rectangle>(dolfin::Point(-width, height, 0.0), dolfin::Point(width, -height, 0.0));
	auto circle = std::make_shared<mshr::Circle>(dolfin::Point(0.0, 0.0, 0.0), size_obj);
	auto difference = std::make_shared<mshr::CSGDifference>(rectangle, circle);
	auto mesh = mshr::generate_mesh(difference, precision);​

The compilation was successful and I could solve the problem. Now I upgraded to the newest 2017 version and the same code that used to work now produces a std::bad_alloc error when I try to launch the solution.

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

I tried declaring a rectangular mesh without the circular hole and it works, so the problem must be in the difference object or in the mesh definition.

What changed between the version that now makes the code fail?

Community: FEniCS Project
Please provide a complete minimal example reproducing the behaviour.
written 9 months ago by Jan Blechta  
For the purposes of this problem I have slightly modified the Cahn-Hiliard demo: MWE.zip
Check in particular lines 82 and 83 of main.cpp.
written 9 months ago by Dario  

2 Answers

9 months ago by
I realized what is the problem: In the definition of rectangle, I used upper left and lower right corners to define it.
Simply using lower right and upper right ones (i.e. auto rectangle = std::make_shared<mshr::Rectangle>(dolfin::Point(-width, -height, 0.0), dolfin::Point(width, height, 0.0)); ) will produce the correct mesh.

Maybe there are precise specifications about mshr::Rectangle that I did not bother to read that specify this point :/

EDIT: the official bitbucket page states "Create rectangle defined by two opposite corners." and in fact the rectangular mesh is correctly created with whichever choice of opposite corners.
Problems start when using mshr::CSGDifference, for which the opposite corners must be precisely chosen.
3 months ago by

I tried to create a mesh for a rectengular domain with/without circular hole using the code shown above. For both cases, the compilation fails while linking the executables. For the case with hole, the following error occurs:

[ 25%] Building CXX object CMakeFiles/demo_poisson.dir/main.cpp.o
[ 50%] Linking CXX executable demo_poisson
CMakeFiles/demo_poisson.dir/main.cpp.o: In function `void __gnu_cxx::new_allocator<mshr::CSGDifference>::construct<mshr::CSGDifference, std::shared_ptr<mshr::Rectangle>&, std::shared_ptr<mshr::Circle>&>(mshr::CSGDifference*, std::shared_ptr<mshr::Rectangle>&, std::shared_ptr<mshr::Circle>&)':
/usr/include/c++/6/ext/new_allocator.h:120: undefined reference to `mshr::CSGDifference::CSGDifference(std::shared_ptr<mshr::CSGGeometry>, std::shared_ptr<mshr::CSGGeometry>)'

Any idea what goes wrong?

Regards, Nick
@Nick:  I was able to get the MWE zip code to compile and run (after commenting out plot() and interactive() ), thus no linking issues.

I am using Docker on MacOS: dolfin_version 2017.2.0.
written 3 months ago by jwinkle  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »