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

Meshing a difference of boxes

+2 votes

I would like to mesh a difference of 3d boxes and controll the coarseness of the mesh. I've this working code

quader = Box(0, 0, 0, 10, 2, 1)
obstacle = Box(4, 0, 0, 4.5, 1, 1)
mesh = Mesh(quader-obstacle, 1)

but unfortunately couldn't find a documentation and didn't figure out what does the "1" stands for. Is there a way to make this mesh coarser?

asked Feb 25, 2014 by franp9am FEniCS Novice (590 points)
edited Feb 25, 2014 by franp9am

1 Answer

+1 vote

The second argument to Mesh is the resolution, where 1 gives you the coarsest mesh. I don't think there is functionality in DOLFIN for making a mesh coarser, but I might be wrong.

answered Feb 26, 2014 by johannr FEniCS Expert (17,350 points)

Hi, if you are working with C++ you could try LocalMeshCoarsening. Here's an example

#include <dolfin.h>                                                              
#include <dolfin/refinement/LocalMeshCoarsening.h>                               

using namespace dolfin;                                                          

int main()                                                                       
{                                                                                
  set_log_level(CRITICAL);                                                       
  Circle circle(1, 1, 1);                                                        
  Rectangle rectangle(0.5, 0.5, 1.5, 1.5);                                       

  Mesh mesh(circle-rectangle, 10);  //1                                          

  plot(mesh);                                                                    
  std::cout << "Number of cells of fine mesh " << mesh.num_cells() << std::endl; 

  const size_t n_coarsenings = 2;                                                

  for(int i = 0; i < n_coarsenings; i++)                                         
  {                                                                              
    CellFunction<bool> cell_marker(mesh, true);                                  

    LocalMeshCoarsening::coarsen_mesh_by_edge_collapse(mesh, cell_marker);       
    plot(mesh, "Coarsened");                                                     
    std::cout << "Number of cells of coarse mesh " << mesh.num_cells() << std::endl;
  }                                                                              

  interactive();                                                                 

  return 0;                                                                      
} 

Note that quality of the coarsened mesh is not great. Also, if you start with resolution parameter 1, the mesh does not change in the loop. Based on this I would say that you cannot coarsen mesh with resolution parameter = 1.

...