예제 #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 tripod(opts, tria=None):
    """
    TRIPOD cmd-line interface to TRIPOD.

    TRIPOD(OPTS, TRIA=None)

    Call the TRIPOD tessellation util. using the config. opt
    specified in the OPTS structure.

    OPTS is a user-defined set of meshing options. See JIG_t
    for details.

    """
    jexename = Path()

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

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

    savejig(opts.jcfg_file, opts)

    if (jexename == Path()):
        #---------------------------- set-up path for "local" binary

        #   stackoverflow.com/questions/2632199/
        #       how-do-i-get-the-
        #       path-of-the-current-executed-file-in-python
        filename = \
            inspect.getsourcefile(lambda:0) # noqa

        filepath = \
            Path(filename).resolve().parent

        if (os.name == "nt"):
            jexename = filepath / "_bin" / "tripod.exe"

        elif (os.name == "posix"):
            jexename = filepath / "_bin" / "tripod"

        if (not jexename.is_file()):
            jexename = Path()

    if (jexename == Path()):
        #---------------------------- search machine path for binary
        jexescan = shutil.which("tripod")

        if (jexescan is not None):
            jexename = Path(jexescan)

    if (jexename != Path()):
        #---------------------------- call JIGSAW and capture output
        subprocess.run([str(jexename), opts.jcfg_file], check=True)

        if (tria is not None):
            loadmsh(opts.mesh_file, tria)

    else:

        raise Exception("TRIPOD executable not found!")

    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 marche(opts, ffun=None):
    """
    MARCHE cmd-line interface to MARCHE.

    MARCHE(OPTS, FFUN=None)

    Call the "fast-marching" solver MARCHE using the config.
    options specified in the OPTS structure. MARCHE solves
    the Eikonal equations

    MAX(||dh/dx||, g) = g,

    where g = g(x) is a gradient threshold applied to h. See
    the SAVEMSH/LOADMSH functions for a description of the
    HFUN output structure.

    OPTS is a user-defined set of meshing options. See JIG_t
    for details.

    """
    jexename = Path()

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

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

    savejig(opts.jcfg_file, opts)

    if (jexename == Path()):
        #---------------------------- set-up path for "local" binary

        #   stackoverflow.com/questions/2632199/
        #       how-do-i-get-the-
        #       path-of-the-current-executed-file-in-python
        filename = \
            inspect.getsourcefile(lambda:0) # noqa

        filepath = \
            Path(filename).resolve().parent

        if (os.name == "nt"):
            jexename = filepath / "_bin" / "marche.exe"

        elif (os.name == "posix"):
            jexename = filepath / "_bin" / "marche"

        if (not jexename.is_file()):
            jexename = Path()

    if (jexename == Path()):
        #---------------------------- search machine path for binary
        jexescan = shutil.which("marche")

        if (jexescan is not None):
            jexename = Path(jexescan)

    if (jexename != Path()):
        #---------------------------- call JIGSAW and capture output
        subprocess.run([str(jexename), opts.jcfg_file], check=True)

        if (ffun is not None):
            loadmsh(opts.hfun_file, ffun)

    else:

        raise Exception("MARCHE executable not found!")

    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
예제 #7
0
def jigsaw(opts, mesh=None):
    """
    JIGSAW cmd-line interface to JIGSAW.

    JIGSAW(OPTS, MESH=None)

    Call the JIGSAW mesh generator using the config. options
    specified in the OPTS structure.

    OPTS is a user-defined set of meshing options. See JIG_t
    for details.

    """
    jexename = Path()

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

    savejig(opts.jcfg_file, opts)

    if (jexename == Path()):
#---------------------------- set-up path for "local" binary

    #   stackoverflow.com/questions/2632199/
    #       how-do-i-get-the-
    #       path-of-the-current-executed-file-in-python
        filename = \
            inspect.getsourcefile(lambda:0)

        filepath = \
            Path(filename).resolve().parent

        if   (os.name == "nt"):
            jexename = filepath / "_bin" / "jigsaw.exe"

        elif (os.name == "posix"):
            jexename = filepath / "_bin" / "jigsaw"

        if (not jexename.is_file()):
            jexename = Path()

    if (jexename == Path()):
#---------------------------- search machine path for binary
        jexescan = shutil.which("jigsaw")

        if (jexescan is not None):
            jexename = Path(jexescan)

    if (jexename != Path()):
#---------------------------- call JIGSAW and capture output
        subprocess.run([
            str(jexename), opts.jcfg_file], check=True)

        if (mesh is not None):
            loadmsh(opts.mesh_file, mesh)

    else:

        raise Exception("JIGSAW executable not found!")

    return