I want to build a geometry which looks like a “Y” - 2 rectangles each rotated by 30 degrees off vertical, and a third below. I have found making the three rectangles separately, I can rotate the meshes, but then I cannot recombine them into one domain.
Is it possible to combine meshes, or is it possible to rotate a CSG geometry object before generating a mesh?
This should be doable with mshr.Polygon. Since mshr is not maintained, I would suggest using an external mesh generator, such as Gmsh (with/without pygmsh). Another nice tool that I have used for smaller applications is @nschloe 's excellent dmsh.
See the following for something that should give you what you need:
import numpy as np
import dmsh as dm
import meshio
from dolfin import *
# define the corners of the polygon
Lo, bo = 2., 1
polygon = np.array([
[0., 0],
[bo, 0],
[bo, Lo],
[Lo * np.cos(pi/6) + bo, Lo * np.sin(pi/6) + Lo],
[0.5*bo + Lo * np.cos(pi/6), 3**(0.5) * bo/2. + Lo + Lo * np.sin(pi/6)],
[0.5*bo, Lo + 3**(0.5) * bo/2.],
[0.5*bo - Lo * np.cos(pi/6), 3**(0.5) * bo/2. + Lo + Lo * np.sin(pi/6)],
[-Lo * np.cos(pi/6), Lo * np.sin(pi/6) + Lo],
[0, Lo],
], float)
points, cells = dm.generate(dm.Polygon(polygon), 0.1 )
meshio.xdmf.write("Yshaped.xdmf", meshio.Mesh(points, cells = {"triangle": cells}))
mesh = Mesh()
XDMFFile("Yshaped.xdmf").read(mesh)
plot(mesh)