Mesh: QuadTree: CreationΒΆ

You can give the refine method a function, which is evaluated on every cell of the TreeMesh.

Occasionally it is useful to initially refine to a constant level (e.g. 3 in this 32x32 mesh). This means the function is first evaluated on an 8x8 mesh (2^3).

(Source code, png, hires.png, pdf)

../../_images/Mesh_QuadTree_Creation-1.png
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from SimPEG import Mesh
import numpy as np
import matplotlib.pyplot as plt


def run(plotIt=True):
    """
        Mesh: QuadTree: Creation
        ========================

        You can give the refine method a function, which is evaluated on every
        cell of the TreeMesh.

        Occasionally it is useful to initially refine to a constant level
        (e.g. 3 in this 32x32 mesh). This means the function is first evaluated
        on an 8x8 mesh (2^3).

    """
    M = Mesh.TreeMesh([32, 32])
    M.refine(3)

    def refine(cell):
        xyz = cell.center
        for i in range(3):
            if np.abs(np.sin(xyz[0]*np.pi*2)*0.5 + 0.5 - xyz[1]) < 0.2*i:
                return 6-i
        return 0

    M.refine(refine)
    if plotIt:
        M.plotGrid()

if __name__ == '__main__':
    run()
    plt.show()