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

Create Structured mesh when using Polygon()

0 votes

Hi there,

Below there is an example code which generates a unstructured mesh. How can I build up a structured mesh when using Polygon?

from dolfin import *
from mshr import *
from pylab import show,triplot
domain_vertices = [Point(0.0, 0.0125),
                  Point(0.0, -0.0125),
                  Point(1.0, -1.0),
                  Point(2.0, 0.0),
                  Point(1.0, 1.0)]
domain = Polygon(domain_vertices)
mesh = generate_mesh(domain,40)
coords = mesh.coordinates()
triplot(coords[:,0], coords[:,1], triangles=mesh.cells())
print mesh.num_cells()
show()

Thanks for any help,

asked Oct 10, 2016 by sapenacl FEniCS Novice (270 points)

1 Answer

0 votes

To the best of my knowledge mshr does not support generation of structured meshes.

I believe that your best bet is to proceed as follows:
1. generate a structured mesh using dolfin capabilities for structured meshing (e.g. UnitIntervalMesh, UnitSquareMesh etc)
2. devise a map that deforms the structured domain into your polygon
3. use the map to deform every point in mesh.coordinate()

For step 2, if your Polygon were a rectangle, a simple linear mapping with a diagonal matrix would have sufficed. If it were a rotated square, a simple linear mapping with a rotation matrix would have sufficed. Off the top of my head I cannot think of such a map for your case since in your case you have also "removed" a corner.

As a more general remark, why is it that you cannot use an unstructured mesh? I think that going through procedure 1+2+3 is not really worth the effort.

answered Oct 15, 2016 by francesco.ballarin FEniCS User (4,070 points)
...