Пример #1
0
def cubedsphere(opts, nlev, mesh):
    """
    CUBEDSPHERE Nth-level cubedsphere mesh of the ellipsoid.

    """

    if (not isinstance(opts, jigsaw_jig_t)):
        raise Exception("Incorrect type: OPTS.")

    if (not isinstance(mesh, jigsaw_msh_t)):
        raise Exception("Incorrect type: MESH.")

    geom = jigsaw_msh_t()

    loadmsh(opts.geom_file, geom)

#-------------------------------- setup cubedsphere geometry
    aval = math.atan(
        +math.sqrt(+2.0) / +2.0)

    mesh.mshID = "euclidean-mesh"
    apos = np.array([
        (+0.25 * np.pi, -aval),
        (+0.75 * np.pi, -aval),
        (-0.75 * np.pi, -aval),
        (-0.25 * np.pi, -aval),
        (+0.25 * np.pi, +aval),
        (+0.75 * np.pi, +aval),
        (-0.75 * np.pi, +aval),
        (-0.25 * np.pi, +aval)])

    mesh.vert3 = np.zeros(+ 8, dtype=mesh.VERT3_t)

    mesh.vert3["coord"] = S2toR3(geom.radii, apos)

    mesh.vert3["IDtag"] = - 1               # fix "corners"

#-------------------------------- setup cubedsphere topology
    mesh.quad4 = np.array([
        ((0,  1,  2,  3),  0),              # noqa
        ((0,  1,  5,  4),  1),              # noqa
        ((1,  2,  6,  5),  2),              # noqa
        ((2,  3,  7,  6),  3),              # noqa
        ((3,  0,  4,  7),  4),              # noqa
        ((4,  5,  6,  7),  5)],             # noqa
        dtype=mesh.QUAD4_t)

    if (nlev <= +0): return

    opts.init_file = opts.mesh_file

    savemsh(opts.init_file, mesh)

    refine(opts, nlev, mesh)

    return
Пример #2
0
def refine(opts, nlev, mesh=None):
    """
    REFINE generate a mesh using an inc. bisection strategy.

    """

    if (not isinstance(opts, jigsaw_jig_t)):
        raise Exception("Incorrect type: OPTS.")

    if (mesh is not None and not
            isinstance(mesh, jigsaw_msh_t)):
        raise Exception("Incorrect type: MESH.")

#---------------------------- call JIGSAW via inc. bisection
    opts.mesh_iter = +0
    opts.optm_div_ = False
    opts.optm_zip_ = False

    for ilev in reversed(range(nlev + 1)):

        if (opts.optm_dual is not None):
    #------------------------ create/write current DUAL data
            opts.optm_dual = ilev == 0

    #------------------------ call JIGSAW kernel at this lev
        jigsaw(opts, mesh)

        if (ilev <= +0): break

        if (opts.mesh_file is not None):
    #------------------------ create/write current INIT data
            path = Path(opts.mesh_file).parent
            name = Path(opts.mesh_file).stem
            fext = Path(opts.mesh_file).suffix

            name = str(name)
            fext = str(fext)
            name = name + "-ITER" + fext

            opts.init_file = str(path / name)

            bisect(mesh)
            attach(mesh)

            savemsh(opts.init_file, mesh,
                    opts.mesh_tags)

    return
Пример #3
0
def icosahedron(opts, nlev, mesh):
    """
    ICOSAHEDRON Nth-level icosahedral mesh of the ellipsoid.

    """

    if (not isinstance(opts, jigsaw_jig_t)):
        raise Exception("Incorrect type: OPTS.")

    if (not isinstance(mesh, jigsaw_msh_t)):
        raise Exception("Incorrect type: MESH.")

    geom = jigsaw_msh_t()

    loadmsh(opts.geom_file, geom)

    #-------------------------------- setup icosahedron geometry
    la = math.atan(0.5)

    lo = 2.0 / 10.0 * np.pi

    PI = np.pi
    mesh.mshID = "euclidean-mesh"
    apos = np.array([(+0.0 * PI, -0.5 * PI), (+0.0 * PI, +0.5 * PI),
                     (+0.0 * lo, +1.0 * la), (+1.0 * lo, -1.0 * la),
                     (+2.0 * lo, +1.0 * la), (+3.0 * lo, -1.0 * la),
                     (+4.0 * lo, +1.0 * la), (+5.0 * lo, -1.0 * la),
                     (+6.0 * lo, +1.0 * la), (+7.0 * lo, -1.0 * la),
                     (+8.0 * lo, +1.0 * la), (+9.0 * lo, -1.0 * la)])

    mesh.vert3 = np.zeros(+12, dtype=mesh.VERT3_t)

    mesh.vert3["coord"] = S2toR3(geom.radii, apos)

    mesh.vert3["IDtag"] = -1  # fix "corners"

    #-------------------------------- setup icosahedron topology
    mesh.tria3 = np.array(
        [
            ((0, 3, 5), 0),  # noqa
            ((0, 5, 7), 1),  # noqa
            ((0, 7, 9), 2),  # noqa
            ((0, 9, 11), 3),  # noqa
            ((0, 11, 3), 4),  # noqa
            ((1, 2, 4), 5),  # noqa
            ((1, 4, 6), 6),  # noqa
            ((1, 6, 8), 7),  # noqa
            ((1, 8, 10), 8),  # noqa
            ((1, 10, 2), 9),  # noqa
            ((3, 2, 4), 10),  # noqa
            ((5, 4, 6), 11),  # noqa
            ((7, 6, 8), 12),  # noqa
            ((9, 8, 10), 13),  # noqa
            ((11, 10, 2), 14),  # noqa
            ((4, 3, 5), 15),  # noqa
            ((6, 5, 7), 16),  # noqa
            ((8, 7, 9), 17),  # noqa
            ((10, 9, 11), 18),  # noqa
            ((2, 11, 3), 19)
        ],  # noqa
        dtype=mesh.TRIA3_t)

    if (nlev <= +0): return

    opts.init_file = opts.mesh_file

    savemsh(opts.init_file, mesh)

    refine(opts, nlev, mesh)

    return
Пример #4
0
def tetris(opts, nlev, mesh=None):
    """
    TETRIS generate a mesh using an inc. bisection strategy.

    """

    if (not isinstance(opts, jigsaw_jig_t)):
        raise Exception("Incorrect type: OPTS.")

    if (mesh is not None and not isinstance(mesh, jigsaw_msh_t)):
        raise Exception("Incorrect type: MESH.")


#---------------------------- call JIGSAW via inc. bisection
    SCAL = +2.**nlev
    OPTS = copy.deepcopy(opts)
    flag = +1

    while (nlev >= +0):

        if (opts.optm_qlim is not None):
            #------------------------ create/write current QLIM data
            scal = min(2.0, (nlev + 1)**(1. / 4.))

            QLIM = opts.optm_qlim

            OPTS.optm_qlim = QLIM / scal

        else:
            scal = min(2.0, (nlev + 1)**(1. / 4.))

            QLIM = 0.93750

            OPTS.optm_qlim = QLIM / scal

        if (opts.optm_dual is not None):
            #------------------------ create/write current DUAL data
            OPTS.optm_dual = nlev == 0

        if (opts.hfun_hmax is not None):
            #------------------------ create/write current HMAX data
            OPTS.hfun_hmax = \
                opts.hfun_hmax * SCAL

        if (opts.hfun_hmin is not None):
            #------------------------ create/write current HMIN data
            OPTS.hfun_hmin = \
                opts.hfun_hmin * SCAL

        if (opts.hfun_file is not None):
            #------------------------ create/write current HFUN data
            path = Path(opts.hfun_file).parent
            name = Path(opts.hfun_file).stem
            fext = Path(opts.hfun_file).suffix

            name = str(name)
            fext = str(fext)
            name = name + "-ITER" + fext

            OPTS.hfun_file = str(path / name)

            HFUN = jigsaw_msh_t()

            loadmsh(opts.hfun_file, HFUN)

            HFUN.value = HFUN.value * SCAL

            savemsh(OPTS.hfun_file, HFUN, OPTS.hfun_tags)

        if (nlev <= 1 or flag == 0):
            #------------------------ call JIGSAW kernel at this lev
            ninc = min(64, nlev**2)

            flag = +1

            jitter(OPTS, 2 + ninc, 3, mesh)

        else:

            ninc = min(64, nlev**2)

            flag = +0

            jitter(OPTS, 2 + ninc, 2, mesh)

        nlev = nlev - 1
        SCAL = SCAL / 2.

        if (nlev < +0): break

        if (opts.init_file is not None):
            #------------------------ create/write current INIT data
            path = Path(opts.init_file).parent
            name = Path(opts.init_file).stem
            fext = Path(opts.init_file).suffix

            name = str(name)
            fext = str(fext)
            name = name + "-ITER" + fext

            OPTS.init_file = str(path / name)

            bisect(mesh)
            attach(mesh)

            savemsh(OPTS.init_file, mesh, OPTS.init_tags)

        else:
            #------------------------ create/write current INIT data
            path = Path(opts.mesh_file).parent
            name = Path(opts.mesh_file).stem
            fext = Path(opts.mesh_file).suffix

            name = str(name)
            fext = str(fext)
            name = name + "-ITER" + fext

            OPTS.init_file = str(path / name)

            bisect(mesh)
            attach(mesh)

            savemsh(OPTS.init_file, mesh, OPTS.mesh_tags)

    return
Пример #5
0
def jitter(opts, imax, ibad, mesh=None):
    """
    JITTER call JIGSAW iteratively; try to improve topology.

    """

    if (not isinstance(opts, jigsaw_jig_t)):
        raise Exception("Incorrect type: OPTS.")

    if (mesh is not None and not isinstance(mesh, jigsaw_msh_t)):
        raise Exception("Incorrect type: MESH.")

    if (mesh is None): mesh = jigsaw_msh_t()

    #--------- call JIGSAW iteratively; try to improve topology.
    OPTS = copy.deepcopy(opts)

    best = metric(mesh)
    next = mesh
    done = False

    for iter in range(imax):

        if (next.point is not None and next.point.size != +0):

            nvrt = next.point.size

            keep = np.full((nvrt), True, dtype=bool)

            #------------------------------ setup initial conditions
            path = Path(opts.mesh_file).parent
            name = Path(opts.mesh_file).stem
            fext = Path(opts.mesh_file).suffix

            name = str(name)
            fext = str(fext)
            name = name + "-INIT" + fext

            OPTS.init_file = str(path / name)

            if (next.tria3 is not None and next.tria3.size != +0):
                #------------------------------ mark any irregular nodes
                vdeg = trideg2(next.point["coord"], next.tria3["index"])

                ierr = np.abs(vdeg - 6)  # err in topo. deg.

                ierr[vdeg > 6] = ierr[vdeg > 6] * 2

                ierr = ierr[next.tria3["index"]]

                M = np.sum(ierr, axis=1) >= ibad

                keep[next.tria3["index"][M, :]] = False

            if (next.edge2 is not None and next.edge2.size != +0):

                keep[next.edge2["index"][:, :]] = False

            if (np.count_nonzero(keep) <= +8):
                #------------------------------ don't delete everything!
                keep = np.full((nvrt), True, dtype=bool)

            done = np.all(keep)

            #------------------------------ keep nodes far from seam
            init = jigsaw_msh_t()
            init.point = next.point[keep]

            savemsh(OPTS.init_file, init, OPTS.mesh_tags)

    #------------------------------ call JIGSAW with new ICs
        jigsaw(OPTS, next)  # noqa

        cost = metric(next)

        if (cost > best):
            #------------------------------ keep "best" mesh so far!
            mesh = copy.deepcopy(next)
            best = cost

        if (done): return

    return
Пример #6
0
def tetris(opts, nlev, mesh=None):
    """
    TETRIS generate a mesh using an inc. bisection strategy.

    """

    if (not isinstance(opts, jigsaw_jig_t)):
        raise Exception("Incorrect type: OPTS.")

    if (mesh is not None and not
            isinstance(mesh, jigsaw_msh_t)):
        raise Exception("Incorrect type: MESH.")

#---------------------------- call JIGSAW via inc. bisection
    SCAL = +2. ** nlev

    OPTS = copy.copy(opts)

    while (nlev >= +0):

        if (opts.optm_dual is not None):

    #------------------------ create/write current DUAL data
            OPTS.optm_dual = nlev == 0

        if (opts.hfun_hmax is not None):

    #------------------------ create/write current HMAX data
            OPTS.hfun_hmax = \
                opts.hfun_hmax * SCAL

        if (opts.hfun_hmin is not None):

    #------------------------ create/write current HMIN data
            OPTS.hfun_hmin = \
                opts.hfun_hmin * SCAL

        if (opts.hfun_file is not None):

    #------------------------ create/write current HFUN data
            path = Path(opts.hfun_file).parent
            name = Path(opts.hfun_file).stem
            fext = Path(opts.hfun_file).suffix

            name = str(name)
            fext = str(fext)
            name = name + "-ITER" + fext

            OPTS.hfun_file = str(path / name)

            HFUN = jigsaw_msh_t()

            loadmsh(opts.hfun_file, HFUN)

            HFUN.value = HFUN.value * SCAL

            savemsh(OPTS.hfun_file, HFUN)

    #------------------------ call JIGSAW kernel at this lev
        if (nlev >= +1):

            njit = round(
                3 * (nlev + 1) ** (+5. / 4.))

            jitter(OPTS, njit, +1, mesh)

        else:

            njit = round(
                3 * (nlev + 1) ** (+5. / 4.))

            jitter(OPTS, njit, +1, mesh)

        nlev = nlev - 1
        SCAL = SCAL / 2.

        if (nlev < +0): break

        if (opts.init_file is not None):

    #------------------------ create/write current INIT data
            path = Path(opts.init_file).parent
            name = Path(opts.init_file).stem
            fext = Path(opts.init_file).suffix

            name = str(name)
            fext = str(fext)
            name = name + "-ITER" + fext

            OPTS.init_file = str(path / name)

            bisect(mesh)
            attach(mesh)

            savemsh(OPTS.init_file, mesh)

        else:

    #------------------------ create/write current INIT data
            path = Path(opts.mesh_file).parent
            name = Path(opts.mesh_file).stem
            fext = Path(opts.mesh_file).suffix

            name = str(name)
            fext = str(fext)
            name = name + "-ITER" + fext

            OPTS.init_file = str(path / name)

            bisect(mesh)
            attach(mesh)

            savemsh(OPTS.init_file, mesh)

    return