Mirrored truncated pyramid within cube mesh
I like to construct a mesh by stacking planes along one direction. Each rectangular plane shall have identical side length but also a rectangular area inside that is better resolved. The better resolved area shall always have the same number of grid points but it shrinks linearly with the distance from plane to plane to a certain point. After that, it should get bigger again. I hope this is somehow understandable. I made a really crappy sketch in the hope to help the interested reader...
from dolfin import * mesh = UnitCubeMesh(8,8,8) NLEVELS = 6 MIN_WIDTH = 1.0/(2.0**(NLEVELS-1)) levelHeight = 0.5 for i in range(0,NLEVELS): markers = MeshFunction("bool",mesh,mesh.topology().dim()) markers.set_all(False) for cell in cells(mesh): p = cell.midpoint() if(abs(p-0.5)<levelHeight and (abs(p-0.5)<abs(p-0.5) or abs(p-0.5)<MIN_WIDTH/2.0) and (abs(p-0.5)<abs(p-0.5) or abs(p-0.5)<MIN_WIDTH/2.0)): markers[cell] = True levelHeight /= 2.0 mesh = refine(mesh,markers) V = FunctionSpace(mesh,"CG",1) f = Function(V) File("output.pvd") << f