Mirrored truncated pyramid within cube mesh


99
views
1
4 months ago by

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...

Community: FEniCS Project

1 Answer


0
4 months ago by
I don't know of a nice way to get a structured hex mesh with hanging nodes, as shown in the sketch, but, if I understand the desired geometry correctly, you can approximate the same overall refinement pattern in a tet mesh with something like the following:

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[2]-0.5)<levelHeight
           and
           (abs(p[0]-0.5)<abs(p[2]-0.5) or abs(p[0]-0.5)<MIN_WIDTH/2.0)
           and
           (abs(p[1]-0.5)<abs(p[2]-0.5) or abs(p[1]-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
​
Please login to add an answer/comment or follow this question.

Similar posts:
Search »