Exemple #1
0
def case_0a(src_path, dst_path):

    opts = jigsawpy.jigsaw_jig_t()

    geom = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()

#------------------------------------ define JIGSAW geometry

    geom.mshID = "euclidean-mesh"
    geom.ndims = +2
    geom.vert2 = np.array([   # list of xy "node" coordinate
        ((0, 0), 0),          # outer square
        ((9, 0), 0),
        ((9, 9), 0),
        ((0, 9), 0),
        ((4, 4), 0),          # inner square
        ((5, 4), 0),
        ((5, 5), 0),
        ((4, 5), 0)],
        dtype=geom.VERT2_t)

    geom.edge2 = np.array([   # list of "edges" between vert
        ((0, 1), 0),          # outer square
        ((1, 2), 0),
        ((2, 3), 0),
        ((3, 0), 0),
        ((4, 5), 0),          # inner square
        ((5, 6), 0),
        ((6, 7), 0),
        ((7, 4), 0)],
        dtype=geom.EDGE2_t)

#------------------------------------ build mesh via JIGSAW!

    print("Call libJIGSAW: case 0a.")

    opts.hfun_hmax = 0.05               # push HFUN limits

    opts.mesh_dims = +2                 # 2-dim. simplexes

    opts.optm_qlim = +.95

    opts.mesh_top1 = True               # for sharp feat's
    opts.geom_feat = True

    jigsawpy.lib.jigsaw(opts, geom, mesh)

    scr2 = jigsawpy.triscr2(            # "quality" metric
        mesh.point["coord"],
        mesh.tria3["index"])

    print("Saving case_0a.vtk file.")

    jigsawpy.savevtk(os.path.join(
        dst_path, "case_0a.vtk"), mesh)

    return
Exemple #2
0
def runjgsw(mesh_path, make_bool, projector):
    """
    RUNJGSW: main call to JIGSAW to build the triangulation.

    MESH-PATH should point to a user-defined mesh directory,
    containing the COMPOSE.py template.

    Firstly, MESH-PATH/COMPOSE.py is called to build
    user-defined geometry, initial conditions, mesh spacing
    and mesh configuration information.

    The boolean flags MAKE-BOOL control whether mesh
    information is built from scratch, or if an exitsing an
    existing file is to be used. For example, setting
    MAKE-BOOL.SPAC = FALSE relies on an existing spacing
    pattern be available in MESH-PATH/tmp/.

    This information is written to MESH-PATH/tmp/ to be
    accessed by subsequent calls to JIGSAW.

    Finally, JIGSAW is run to build the triangular mesh,
    calling either the multi-level (TETRIS) or single-level
    (JIGSAW) algorithms. Cells are assigned ID-tags via
    the polygon/regions defined in GEOM.BOUNDS.

    Returns full-dimensional and 2d-projected msh_t objects.

    """
    # Authors: Darren Engwirda

    mesh = jigsawpy.jigsaw_msh_t()
    mprj = jigsawpy.jigsaw_msh_t()
    gprj = jigsawpy.jigsaw_msh_t()

#------------------------------------ setup via user COMPOSE

    base = \
        mesh_path.replace(os.path.sep, ".")

    if (make_bool.geom):
        geom = getattr(import_module(
            base + ".compose"), "setgeom")()

    if (make_bool.spac):
        spac = getattr(import_module(
            base + ".compose"), "setspac")()

    if (make_bool.init):
        init = getattr(import_module(
            base + ".compose"), "setinit")()

    if (make_bool.opts):
        opts = getattr(import_module(
            base + ".compose"), "setopts")()

#------------------------------------ setup files for JIGSAW

    opts.geom_file = os.path.join(
        mesh_path, "tmp", "geom.msh")

    opts.jcfg_file = os.path.join(
        mesh_path, "tmp", "opts.jig")

    opts.init_file = os.path.join(
        mesh_path, "tmp", "init.msh")

    opts.hfun_file = os.path.join(
        mesh_path, "tmp", "spac.msh")

    opts.mesh_file = os.path.join(
        mesh_path, "tmp", "mesh.msh")

    opts.hfun_tags = "precision = 9"    # less float prec.

    jigsawpy.savemsh(opts.geom_file, geom,
                     opts.geom_tags)

    jigsawpy.savemsh(opts.hfun_file, spac,
                     opts.hfun_tags)

    jigsawpy.savemsh(opts.init_file, init,
                     opts.init_tags)

#------------------------------------ make mesh using JIGSAW

    if (not hasattr(opts, "bisection")):

        opts.bisection = +0

    if (opts.bisection < +0):           # bisect heuristic

        rbar = np.mean(geom.radii)
        hbar = np.mean(spac.value)

        nlev = round(math.log2(
            rbar / math.sin(.4 * math.pi) / hbar)
        )

        nlev = nlev - 1

        ttic = time.time()

        jigsawpy.cmd.tetris(opts, nlev - 0, mesh)

        ttoc = time.time()

        print("CPUSEC =", (ttoc - ttic))
        print("BISECT =", +nlev)

    elif (opts.bisection > +0):         # bisect specified

        nlev = opts.bisection

        ttic = time.time()

        jigsawpy.cmd.tetris(opts, nlev - 0, mesh)

        ttoc = time.time()

        print("CPUSEC =", (ttoc - ttic))
        print("BISECT =", +nlev)

    else:                               # do non-recursive

        ttic = time.time()

        jigsawpy.cmd.jigsaw(opts, mesh)

        ttoc = time.time()

        print("CPUSEC =", (ttoc - ttic))

#------------------------------------ form local projections

    gprj = copy.deepcopy(geom)          # local 2d objects
    mprj = copy.deepcopy(mesh)

    if (mesh.vert3.size > +0):
        project(geom, mesh, gprj, mprj, projector)

#------------------------------------ assign IDtag's to cell

    if (geom.bound is not None and
            geom.bound.size > +0):      # tags per polygon

        imin = np.amin(geom.bound["IDtag"])
        imax = np.amax(geom.bound["IDtag"])

        for itag in range(
                imin + 0, imax + 1):

            tagcell(geom, mesh, gprj, mprj, itag)

#------------------------------------ check mesh for quality

    cost = jigsawpy.triscr2(            # quality metrics!
        mesh.point["coord"],
        mesh.tria3["index"])

    print("TRISCR =", np.min(cost), np.mean(cost))

    cost = jigsawpy.pwrscr2(
        mesh.point["coord"],
        mesh.power,
        mesh.tria3["index"])

    print("PWRSCR =", np.min(cost), np.mean(cost))

    tbad = jigsawpy.centre2(
        mesh.point["coord"],
        mesh.power,
        mesh.tria3["index"])

    print("OBTUSE =",
          +np.count_nonzero(np.logical_not(tbad)))

    ndeg = jigsawpy.trideg2(
        mesh.point["coord"],
        mesh.tria3["index"])

    print("TOPOL. =",
          +np.count_nonzero(ndeg==+6) / ndeg.size)

#------------------------------------ save mesh for Paraview

    jigsawpy.savevtk(os.path.join(
        mesh_path, "out", "geom.vtk"), geom)
    jigsawpy.savevtk(os.path.join(
        mesh_path, "out", "spac.vtk"), spac)
    jigsawpy.savevtk(os.path.join(
        mesh_path, "out", "init.vtk"), init)
    jigsawpy.savevtk(os.path.join(
        mesh_path, "out", "mesh.vtk"), mesh)

    jigsawpy.savevtk(os.path.join(
        mesh_path, "out", "geom_prj.vtk"), gprj)
    jigsawpy.savevtk(os.path.join(
        mesh_path, "out", "mesh_prj.vtk"), mprj)

    return geom, gprj, mesh, mprj
Exemple #3
0
def case_2_(src_path, dst_path):

    # DEMO-2: generate a regionally-refined global grid with a
    # high-resolution 37.5km patch embedded in a uniform 150km
    # background grid.

    opts = jigsawpy.jigsaw_jig_t()

    topo = jigsawpy.jigsaw_msh_t()

    geom = jigsawpy.jigsaw_msh_t()
    hfun = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()

    #------------------------------------ setup files for JIGSAW

    opts.geom_file = \
        os.path.join(src_path, "eSPH.msh")

    opts.jcfg_file = \
        os.path.join(dst_path, "eSPH.jig")

    opts.mesh_file = \
        os.path.join(dst_path, "mesh.msh")

    opts.hfun_file = \
        os.path.join(dst_path, "spac.msh")

    #------------------------------------ define JIGSAW geometry

    geom.mshID = "ellipsoid-mesh"
    geom.radii = np.full(3, 6.371E+003, dtype=geom.REALS_t)

    jigsawpy.savemsh(opts.geom_file, geom)

    #------------------------------------ define spacing pattern

    hfun.mshID = "ellipsoid-grid"
    hfun.radii = geom.radii

    hfun.xgrid = np.linspace(-1. * np.pi, +1. * np.pi, 360)

    hfun.ygrid = np.linspace(-.5 * np.pi, +.5 * np.pi, 180)

    xmat, ymat = \
        np.meshgrid(hfun.xgrid, hfun.ygrid)

    hfun.value = +150. - 112.5 * np.exp(-(+1.5 * (xmat + 1.0)**2 + +1.5 *
                                          (ymat - 0.5)**2)**4)

    jigsawpy.savemsh(opts.hfun_file, hfun)

    #------------------------------------ make mesh using JIGSAW

    opts.hfun_scal = "absolute"
    opts.hfun_hmax = float("inf")  # null HFUN limits
    opts.hfun_hmin = float(+0.00)

    opts.mesh_dims = +2  # 2-dim. simplexes

    opts.optm_qlim = +9.5E-01  # tighter opt. tol
    opts.optm_iter = +32
    opts.optm_qtol = +1.0E-05

    jigsawpy.cmd.tetris(opts, 3, mesh)

    scr2 = jigsawpy.triscr2(  # "quality" metric
        mesh.point["coord"], mesh.tria3["index"])

    #------------------------------------ save mesh for Paraview

    jigsawpy.loadmsh(os.path.join(src_path, "topo.msh"), topo)

    #------------------------------------ a very rough land mask

    apos = jigsawpy.R3toS2(geom.radii, mesh.point["coord"][:])

    apos = apos * 180. / np.pi

    zfun = interpolate.RectBivariateSpline(topo.ygrid, topo.xgrid, topo.value)

    mesh.value = zfun(apos[:, 1], apos[:, 0], grid=False)

    cell = mesh.tria3["index"]

    zmsk = \
        mesh.value[cell[:, 0]] + \
        mesh.value[cell[:, 1]] + \
        mesh.value[cell[:, 2]]
    zmsk = zmsk / +3.0

    mesh.tria3 = mesh.tria3[zmsk < +0.]

    print("Saving to ../cache/case_2a.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_2a.vtk"), mesh)

    print("Saving to ../cache/case_2b.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_2b.vtk"), hfun)

    return
def case_6_(src_path, dst_path):

    # DEMO-6: generate a 2-dim. grid for the Australian coastal
    # region, using scaled ocean-depth as a mesh-resolution
    # heuristic. A local stereographic projection is employed.

    opts = jigsawpy.jigsaw_jig_t()

    topo = jigsawpy.jigsaw_msh_t()

    geom = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()
    hmat = jigsawpy.jigsaw_msh_t()

    proj = jigsawpy.jigsaw_prj_t()

    #------------------------------------ setup files for JIGSAW

    opts.geom_file = \
        os.path.join(dst_path, "geom.msh")

    opts.jcfg_file = \
        os.path.join(dst_path, "aust.jig")

    opts.mesh_file = \
        os.path.join(dst_path, "mesh.msh")

    opts.hfun_file = \
        os.path.join(dst_path, "spac.msh")

    #------------------------------------ define JIGSAW geometry

    jigsawpy.loadmsh(os.path.join(src_path, "aust.msh"), geom)

    jigsawpy.loadmsh(os.path.join(src_path, "topo.msh"), topo)

    xmin = np.min(geom.point["coord"][:, 0])
    ymin = np.min(geom.point["coord"][:, 1])
    xmax = np.max(geom.point["coord"][:, 0])
    ymax = np.max(geom.point["coord"][:, 1])

    zlev = topo.value

    xmsk = np.logical_and(topo.xgrid > xmin, topo.xgrid < xmax)
    ymsk = np.logical_and(topo.ygrid > ymin, topo.ygrid < ymax)

    zlev = zlev[:, xmsk]
    zlev = zlev[ymsk, :]

    #------------------------------------ define spacing pattern

    hmat.mshID = "ellipsoid-grid"
    hmat.radii = np.full(+3, +6371.0, dtype=jigsawpy.jigsaw_msh_t.REALS_t)

    hmat.xgrid = \
        topo.xgrid[xmsk] * np.pi / 180.
    hmat.ygrid = \
        topo.ygrid[ymsk] * np.pi / 180.

    hmin = +1.0E+01
    hmax = +1.0E+02

    hmat.value = \
        np.sqrt(np.maximum(-zlev, 0.)) / 0.5

    hmat.value = \
        np.maximum(hmat.value, hmin)
    hmat.value = \
        np.minimum(hmat.value, hmax)

    hmat.slope = np.full(hmat.value.shape,
                         +0.1500,
                         dtype=jigsawpy.jigsaw_msh_t.REALS_t)

    #------------------------------------ do stereographic proj.

    geom.point["coord"][:, :] *= np.pi / 180.

    proj.prjID = 'stereographic'
    proj.radii = +6.371E+003
    proj.xbase = \
        +0.500 * (xmin + xmax) * np.pi / 180.
    proj.ybase = \
        +0.500 * (ymin + ymax) * np.pi / 180.

    jigsawpy.project(geom, proj, "fwd")
    jigsawpy.project(hmat, proj, "fwd")

    jigsawpy.savemsh(opts.geom_file, geom)
    jigsawpy.savemsh(opts.hfun_file, hmat)

    #------------------------------------ set HFUN grad.-limiter

    jigsawpy.cmd.marche(opts, hmat)

    #------------------------------------ make mesh using JIGSAW

    opts.hfun_scal = "absolute"
    opts.hfun_hmax = float("inf")  # null HFUN limits
    opts.hfun_hmin = float(+0.00)

    opts.mesh_dims = +2  # 2-dim. simplexes
    opts.mesh_eps1 = +1.

    ttic = time.time()

    jigsawpy.cmd.jigsaw(opts, mesh)

    ttoc = time.time()

    print("CPUSEC =", (ttoc - ttic))

    cost = jigsawpy.triscr2(  # quality metrics!
        mesh.point["coord"], mesh.tria3["index"])

    print("TRISCR =", np.min(cost), np.mean(cost))

    cost = jigsawpy.pwrscr2(mesh.point["coord"], mesh.power,
                            mesh.tria3["index"])

    print("PWRSCR =", np.min(cost), np.mean(cost))

    tbad = jigsawpy.centre2(mesh.point["coord"], mesh.power,
                            mesh.tria3["index"])

    print("OBTUSE =", +np.count_nonzero(np.logical_not(tbad)))

    #------------------------------------ save mesh for Paraview

    print("Saving to ../cache/case_6a.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_6a.vtk"), mesh)

    print("Saving to ../cache/case_6b.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_6b.vtk"), hmat)

    return
def case_2_(src_path, dst_path):

    # DEMO-2: generate a regionally-refined global grid with a
    # high-resolution 37.5km patch embedded in a uniform 150km
    # background grid.

    opts = jigsawpy.jigsaw_jig_t()

    topo = jigsawpy.jigsaw_msh_t()

    geom = jigsawpy.jigsaw_msh_t()
    hfun = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()

    #------------------------------------ setup files for JIGSAW

    opts.geom_file = \
        os.path.join(dst_path, "geom.msh")

    opts.jcfg_file = \
        os.path.join(dst_path, "opts.jig")

    opts.mesh_file = \
        os.path.join(dst_path, "mesh.msh")

    opts.hfun_file = \
        os.path.join(dst_path, "spac.msh")

    #------------------------------------ define JIGSAW geometry

    geom.mshID = "ellipsoid-mesh"
    geom.radii = np.full(3, 6.371E+003, dtype=geom.REALS_t)

    jigsawpy.savemsh(opts.geom_file, geom)

    #------------------------------------ define spacing pattern

    hfun.mshID = "ellipsoid-grid"
    hfun.radii = geom.radii

    hfun.xgrid = np.linspace(-1. * np.pi, +1. * np.pi, 360)

    hfun.ygrid = np.linspace(-.5 * np.pi, +.5 * np.pi, 180)

    xmat, ymat = \
        np.meshgrid(hfun.xgrid, hfun.ygrid)

    hfun.value = +150. - 112.5 * np.exp(-(+1.5 * (xmat + 1.0)**2 + +1.5 *
                                          (ymat - 0.5)**2)**4)

    jigsawpy.savemsh(opts.hfun_file, hfun)

    #------------------------------------ make mesh using JIGSAW

    opts.hfun_scal = "absolute"
    opts.hfun_hmax = float("inf")  # null HFUN limits
    opts.hfun_hmin = float(+0.00)

    opts.mesh_dims = +2  # 2-dim. simplexes

    opts.optm_qlim = +9.5E-01  # tighter opt. tol
    opts.optm_iter = +32
    opts.optm_qtol = +1.0E-05

    #   opts.optm_kern = "cvt+dqdx"

    rbar = np.mean(geom.radii)  # bisect heuristic
    hbar = np.mean(hfun.value)
    nlev = round(math.log2(rbar / math.sin(.4 * math.pi) / hbar))

    ttic = time.time()

    jigsawpy.cmd.tetris(opts, nlev - 1, mesh)

    ttoc = time.time()

    print("CPUSEC =", (ttoc - ttic))

    print("BISECT =", +nlev)

    cost = jigsawpy.triscr2(  # quality metrics!
        mesh.point["coord"], mesh.tria3["index"])

    print("TRISCR =", np.min(cost), np.mean(cost))

    cost = jigsawpy.pwrscr2(mesh.point["coord"], mesh.power,
                            mesh.tria3["index"])

    print("PWRSCR =", np.min(cost), np.mean(cost))

    tbad = jigsawpy.centre2(mesh.point["coord"], mesh.power,
                            mesh.tria3["index"])

    print("OBTUSE =", +np.count_nonzero(np.logical_not(tbad)))

    ndeg = jigsawpy.trideg2(mesh.point["coord"], mesh.tria3["index"])

    print("TOPOL. =", +np.count_nonzero(ndeg == +6) / ndeg.size)

    #------------------------------------ save mesh for Paraview

    jigsawpy.loadmsh(os.path.join(src_path, "topo.msh"), topo)

    #------------------------------------ a very rough land mask

    apos = jigsawpy.R3toS2(geom.radii, mesh.point["coord"][:])

    apos = apos * 180. / np.pi

    zfun = interpolate.RectBivariateSpline(topo.ygrid, topo.xgrid, topo.value)

    mesh.value = zfun(apos[:, 1], apos[:, 0], grid=False)

    cell = mesh.tria3["index"]

    zmsk = \
        mesh.value[cell[:, 0]] + \
        mesh.value[cell[:, 1]] + \
        mesh.value[cell[:, 2]]
    zmsk = zmsk / +3.0

    mesh.tria3 = mesh.tria3[zmsk < +0.]

    print("Saving to ../cache/case_2a.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_2a.vtk"), mesh)

    print("Saving to ../cache/case_2b.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_2b.vtk"), hfun)

    return
def case_3_(src_path, dst_path):

    opts = jigsawpy.jigsaw_jig_t()

    geom = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()

#------------------------------------ setup files for JIGSAW

    opts.geom_file = \
        os.path.join(src_path, "bunny.msh")

    opts.jcfg_file = \
        os.path.join(dst_path, "bunny.jig")

    opts.mesh_file = \
        os.path.join(dst_path, "bunny.msh")

#------------------------------------ make mesh using JIGSAW

    jigsawpy.loadmsh(
        opts.geom_file, geom)

    print("Saving case_3a.vtk file.")

    jigsawpy.savevtk(os.path.join(
        dst_path, "case_3a.vtk"), geom)

    opts.mesh_kern = "delaunay"         # DELAUNAY kernel
    opts.mesh_dims = +2

    opts.optm_iter = +0

    opts.hfun_hmax = 0.03

    jigsawpy.cmd.jigsaw(opts, mesh)

    scr2 = jigsawpy.triscr2(            # "quality" metric
        mesh.point["coord"],
        mesh.tria3["index"])

    print("Saving case_3b.vtk file.")

    jigsawpy.savevtk(os.path.join(
        dst_path, "case_3b.vtk"), mesh)

#------------------------------------ make mesh using JIGSAW

    opts.mesh_kern = "delfront"         # DELFRONT kernel
    opts.mesh_dims = +2

    opts.optm_iter = +0

    opts.hfun_hmax = 0.03

    jigsawpy.cmd.jigsaw(opts, mesh)

    scr2 = jigsawpy.triscr2(            # "quality" metric
        mesh.point["coord"],
        mesh.tria3["index"])

    print("Saving case_3c.vtk file.")

    jigsawpy.savevtk(os.path.join(
        dst_path, "case_3c.vtk"), mesh)

    return
Exemple #7
0
def case_4_(src_path, dst_path):

    # DEMO-4: generate a multi-resolution mesh, via local refin-
    # ement along coastlines and shallow ridges. Global grid
    # resolution is 150KM, background resolution is 67KM and the
    # min. adaptive resolution is 33KM.

    opts = jigsawpy.jigsaw_jig_t()

    topo = jigsawpy.jigsaw_msh_t()

    geom = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()
    hmat = jigsawpy.jigsaw_msh_t()

    #------------------------------------ setup files for JIGSAW

    opts.geom_file = \
        os.path.join(src_path, "eSPH.msh")

    opts.jcfg_file = \
        os.path.join(dst_path, "eSPH.jig")

    opts.mesh_file = \
        os.path.join(dst_path, "mesh.msh")

    opts.hfun_file = \
        os.path.join(dst_path, "spac.msh")

    #------------------------------------ define JIGSAW geometry

    geom.mshID = "ellipsoid-mesh"
    geom.radii = np.full(3, 6.371E+003, dtype=geom.REALS_t)

    jigsawpy.savemsh(opts.geom_file, geom)

    #------------------------------------ define spacing pattern

    jigsawpy.loadmsh(os.path.join(src_path, "topo.msh"), topo)

    hmat.mshID = "ellipsoid-grid"
    hmat.radii = geom.radii

    hmat.xgrid = topo.xgrid * np.pi / 180.
    hmat.ygrid = topo.ygrid * np.pi / 180.

    hfn0 = +150.  # global spacing
    hfn2 = +33.  # adapt. spacing
    hfn3 = +67.  # arctic spacing

    hmat.value = np.sqrt(np.maximum(-topo.value, 0.0))

    hmat.value = \
        np.maximum(hmat.value, hfn2)
    hmat.value = \
        np.minimum(hmat.value, hfn3)

    mask = hmat.ygrid < 40. * np.pi / 180.

    hmat.value[mask] = hfn0

    #------------------------------------ set HFUN grad.-limiter

    hmat.slope = np.full(  # |dH/dx| limits
        topo.value.shape, +0.050, dtype=hmat.REALS_t)

    jigsawpy.savemsh(opts.hfun_file, hmat)

    jigsawpy.cmd.marche(opts, hmat)

    #------------------------------------ make mesh using JIGSAW

    opts.hfun_scal = "absolute"
    opts.hfun_hmax = float("inf")  # null HFUN limits
    opts.hfun_hmin = float(+0.00)

    opts.mesh_dims = +2  # 2-dim. simplexes

    opts.optm_qlim = +9.5E-01  # tighter opt. tol
    opts.optm_iter = +32
    opts.optm_qtol = +1.0E-05

    jigsawpy.cmd.tetris(opts, 3, mesh)

    scr2 = jigsawpy.triscr2(  # "quality" metric
        mesh.point["coord"], mesh.tria3["index"])

    #------------------------------------ save mesh for Paraview

    apos = jigsawpy.R3toS2(geom.radii, mesh.point["coord"][:])

    apos = apos * 180. / np.pi

    zfun = interpolate.RectBivariateSpline(topo.ygrid, topo.xgrid, topo.value)

    mesh.value = zfun(apos[:, 1], apos[:, 0], grid=False)

    cell = mesh.tria3["index"]

    zmsk = \
        mesh.value[cell[:, 0]] + \
        mesh.value[cell[:, 1]] + \
        mesh.value[cell[:, 2]]
    zmsk = zmsk / +3.0

    mesh.tria3 = mesh.tria3[zmsk < +0.]

    print("Saving to ../cache/case_4a.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_4a.vtk"), mesh)

    print("Saving to ../cache/case_4b.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_4b.vtk"), hmat)

    return
Exemple #8
0
def case_7_(src_path, dst_path):

    # DEMO-7: generate a multi-part mesh of the (contiguous) USA
    # using state boundaries to partition the mesh. A local
    # stereographic projection is employed. The domain is meshed
    # using uniform resolution.

    opts = jigsawpy.jigsaw_jig_t()

    geom = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()

    proj = jigsawpy.jigsaw_prj_t()

    #------------------------------------ setup files for JIGSAW

    opts.geom_file = \
        os.path.join(dst_path, "geom.msh")

    opts.jcfg_file = \
        os.path.join(dst_path, "us48.jig")

    opts.mesh_file = \
        os.path.join(dst_path, "mesh.msh")

    #------------------------------------ define JIGSAW geometry

    jigsawpy.loadmsh(os.path.join(src_path, "us48.msh"), geom)

    xmin = np.min(geom.point["coord"][:, 0])
    ymin = np.min(geom.point["coord"][:, 1])
    xmax = np.max(geom.point["coord"][:, 0])
    ymax = np.max(geom.point["coord"][:, 1])

    geom.point["coord"][:, :] *= np.pi / 180.

    proj.prjID = 'stereographic'
    proj.radii = +6.371E+003
    proj.xbase = \
        +0.500 * (xmin + xmax) * np.pi / 180.
    proj.ybase = \
        +0.500 * (ymin + ymax) * np.pi / 180.

    jigsawpy.project(geom, proj, "fwd")

    jigsawpy.savemsh(opts.geom_file, geom)

    #------------------------------------ make mesh using JIGSAW

    opts.hfun_hmax = .005

    opts.mesh_dims = +2  # 2-dim. simplexes
    opts.mesh_eps1 = +1 / 6.

    ttic = time.time()

    jigsawpy.cmd.jigsaw(opts, mesh)

    ttoc = time.time()

    print("CPUSEC =", (ttoc - ttic))

    cost = jigsawpy.triscr2(  # quality metrics!
        mesh.point["coord"], mesh.tria3["index"])

    print("TRISCR =", np.min(cost), np.mean(cost))

    cost = jigsawpy.pwrscr2(mesh.point["coord"], mesh.power,
                            mesh.tria3["index"])

    print("PWRSCR =", np.min(cost), np.mean(cost))

    tbad = jigsawpy.centre2(mesh.point["coord"], mesh.power,
                            mesh.tria3["index"])

    print("OBTUSE =", +np.count_nonzero(np.logical_not(tbad)))

    #------------------------------------ save mesh for Paraview

    print("Saving to ../cache/case_7a.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_7a.vtk"), mesh)

    return
Exemple #9
0
def case_1_(src_path, dst_path):

# DEMO-1: generate a uniform resolution (150KM) global grid.

    opts = jigsawpy.jigsaw_jig_t()

    topo = jigsawpy.jigsaw_msh_t()

    geom = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()

#------------------------------------ setup files for JIGSAW

    opts.geom_file = \
        os.path.join(src_path, "eSPH.msh")

    opts.jcfg_file = \
        os.path.join(dst_path, "eSPH.jig")

    opts.mesh_file = \
        os.path.join(dst_path, "mesh.msh")

#------------------------------------ define JIGSAW geometry

    geom.mshID = "ellipsoid-mesh"
    geom.radii = np.full(
        3, 6.371E+003, dtype=geom.REALS_t)

    jigsawpy.savemsh(opts.geom_file, geom)

#------------------------------------ make mesh using JIGSAW

    opts.hfun_scal = "absolute"
    opts.hfun_hmax = +150.              # uniform at 150km

    opts.mesh_dims = +2                 # 2-dim. simplexes

    opts.optm_qlim = +9.5E-01           # tighter opt. tol
    opts.optm_iter = +32
    opts.optm_qtol = +1.0E-05

    jigsawpy.cmd.tetris(opts, 3, mesh)

    scr2 = jigsawpy.triscr2(            # "quality" metric
        mesh.point["coord"],
        mesh.tria3["index"])

#------------------------------------ save mesh for Paraview

    jigsawpy.loadmsh(os.path.join(
        src_path, "topo.msh"), topo)

#------------------------------------ a very rough land mask

    apos = jigsawpy.R3toS2(
        geom.radii, mesh.point["coord"][:])

    apos = apos * 180. / np.pi

    zfun = interpolate.RectBivariateSpline(
        topo.ygrid, topo.xgrid, topo.value)

    mesh.value = zfun(
        apos[:, 1], apos[:, 0], grid=False)

    cell = mesh.tria3["index"]

    zmsk = \
        mesh.value[cell[:, 0]] + \
        mesh.value[cell[:, 1]] + \
        mesh.value[cell[:, 2]]
    zmsk = zmsk / +3.0

    mesh.tria3 = mesh.tria3[zmsk < +0.]

    print("Saving to ../cache/case_1a.vtk")

    jigsawpy.savevtk(os.path.join(
        dst_path, "case_1a.vtk"), mesh)

    return
Exemple #10
0
def unstMesh(esph, infile, hfn0=100.0, hfn1=30.0, hfn2=15, tmp="tmp/"):

    opts = jigsawpy.jigsaw_jig_t()
    topo = jigsawpy.jigsaw_msh_t()
    geom = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()
    hmat = jigsawpy.jigsaw_msh_t()

    opts.geom_file = esph
    opts.jcfg_file = os.path.join(tmp, "topo.jig")
    opts.mesh_file = os.path.join(tmp, "mesh.msh")
    opts.hfun_file = os.path.join(tmp, "spac.msh")

    # define JIGSAW geometry
    geom.mshID = "ellipsoid-mesh"
    geom.radii = np.full(3, 6.371e003, dtype=geom.REALS_t)

    jigsawpy.savemsh(opts.geom_file, geom)

    # define spacing pattern
    jigsawpy.loadmsh(infile, topo)

    hmat.mshID = "ellipsoid-grid"
    hmat.radii = geom.radii

    hmat.xgrid = topo.xgrid * np.pi / 180.0
    hmat.ygrid = topo.ygrid * np.pi / 180.0

    # Define grid resolution for each elevation domain
    hmat.value = np.full(topo.value.shape, hfn0, dtype=hmat.REALS_t)

    hmat.value[topo.value > -1000.0] = hfn1
    hmat.value[topo.value > 0.0] = hfn2

    # Set HFUN gradient-limiter
    hmat.slope = np.full(topo.value.shape, +0.025, dtype=hmat.REALS_t)

    jigsawpy.savemsh(opts.hfun_file, hmat)
    jigsawpy.cmd.marche(opts, hmat)

    # Make mesh using JIGSAW
    opts.hfun_scal = "absolute"
    opts.hfun_hmax = float("inf")  # null HFUN limits
    opts.hfun_hmin = float(+0.00)

    opts.mesh_dims = +2  # 2-dim. simplexes

    opts.optm_qlim = +9.5e-01  # tighter opt. tol
    opts.optm_iter = +32
    opts.optm_qtol = +1.0e-05

    jigsawpy.cmd.tetris(opts, 4, mesh)

    scr2 = jigsawpy.triscr2(  # "quality" metric
        mesh.point["coord"], mesh.tria3["index"])

    apos = jigsawpy.R3toS2(geom.radii, mesh.point["coord"][:])

    apos = apos * 180.0 / np.pi

    zfun = interpolate.RectBivariateSpline(topo.ygrid, topo.xgrid, topo.value)

    mesh.value = zfun(apos[:, 1], apos[:, 0], grid=False)

    coords = (mesh.vert3["coord"] / 6.371e003) * 6378137.0

    del scr2

    return coords, mesh.tria3["index"], mesh.value
def case_4_(src_path, dst_path):

    # DEMO-4: generate a multi-resolution mesh, via local refin-
    # ement along coastlines and shallow ridges. Global grid
    # resolution is 150KM, background resolution is 67KM and the
    # min. adaptive resolution is 33KM.

    opts = jigsawpy.jigsaw_jig_t()

    topo = jigsawpy.jigsaw_msh_t()

    geom = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()
    hmat = jigsawpy.jigsaw_msh_t()

    #------------------------------------ setup files for JIGSAW

    opts.geom_file = \
        os.path.join(dst_path, "geom.msh")

    opts.jcfg_file = \
        os.path.join(dst_path, "opts.jig")

    opts.mesh_file = \
        os.path.join(dst_path, "mesh.msh")

    opts.hfun_file = \
        os.path.join(dst_path, "spac.msh")

    #------------------------------------ define JIGSAW geometry

    geom.mshID = "ellipsoid-mesh"
    geom.radii = np.full(3, 6.371E+003, dtype=geom.REALS_t)

    jigsawpy.savemsh(opts.geom_file, geom)

    #------------------------------------ define spacing pattern

    jigsawpy.loadmsh(os.path.join(src_path, "topo.msh"), topo)

    hmat.mshID = "ellipsoid-grid"
    hmat.radii = geom.radii

    hmat.xgrid = topo.xgrid * np.pi / 180.
    hmat.ygrid = topo.ygrid * np.pi / 180.

    hfn0 = +150.  # global spacing
    hfn2 = +33.  # adapt. spacing
    hfn3 = +67.  # arctic spacing

    hmat.value = np.sqrt(np.maximum(-topo.value, 0.0))

    hmat.value = \
        np.maximum(hmat.value, hfn2)
    hmat.value = \
        np.minimum(hmat.value, hfn3)

    mask = hmat.ygrid < 40. * np.pi / 180.

    hmat.value[mask] = hfn0

    #------------------------------------ set HFUN grad.-limiter

    hmat.slope = np.full(  # |dH/dx| limits
        topo.value.shape, +0.050, dtype=hmat.REALS_t)

    jigsawpy.savemsh(opts.hfun_file, hmat)

    jigsawpy.cmd.marche(opts, hmat)

    #------------------------------------ make mesh using JIGSAW

    opts.hfun_scal = "absolute"
    opts.hfun_hmax = float("inf")  # null HFUN limits
    opts.hfun_hmin = float(+0.00)

    opts.mesh_dims = +2  # 2-dim. simplexes

    opts.optm_qlim = +9.5E-01  # tighter opt. tol
    opts.optm_iter = +32
    opts.optm_qtol = +1.0E-05

    #   opts.optm_kern = "cvt+dqdx"

    rbar = np.mean(geom.radii)  # bisect heuristic
    hbar = np.mean(hmat.value)
    nlev = round(math.log2(rbar / math.sin(.4 * math.pi) / hbar))

    ttic = time.time()

    jigsawpy.cmd.tetris(opts, nlev - 1, mesh)

    ttoc = time.time()

    print("CPUSEC =", (ttoc - ttic))

    print("BISECT =", +nlev)

    cost = jigsawpy.triscr2(  # quality metrics!
        mesh.point["coord"], mesh.tria3["index"])

    print("TRISCR =", np.min(cost), np.mean(cost))

    cost = jigsawpy.pwrscr2(mesh.point["coord"], mesh.power,
                            mesh.tria3["index"])

    print("PWRSCR =", np.min(cost), np.mean(cost))

    tbad = jigsawpy.centre2(mesh.point["coord"], mesh.power,
                            mesh.tria3["index"])

    print("OBTUSE =", +np.count_nonzero(np.logical_not(tbad)))

    ndeg = jigsawpy.trideg2(mesh.point["coord"], mesh.tria3["index"])

    print("TOPOL. =", +np.count_nonzero(ndeg == +6) / ndeg.size)

    #------------------------------------ save mesh for Paraview

    apos = jigsawpy.R3toS2(geom.radii, mesh.point["coord"][:])

    apos = apos * 180. / np.pi

    zfun = interpolate.RectBivariateSpline(topo.ygrid, topo.xgrid, topo.value)

    mesh.value = zfun(apos[:, 1], apos[:, 0], grid=False)

    cell = mesh.tria3["index"]

    zmsk = \
        mesh.value[cell[:, 0]] + \
        mesh.value[cell[:, 1]] + \
        mesh.value[cell[:, 2]]
    zmsk = zmsk / +3.0

    mesh.tria3 = mesh.tria3[zmsk < +0.]

    print("Saving to ../cache/case_4a.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_4a.vtk"), mesh)

    print("Saving to ../cache/case_4b.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_4b.vtk"), hmat)

    return
Exemple #12
0
def case_1_(src_path, dst_path):

    # DEMO-1: generate a uniform resolution (150KM) global grid.

    opts = jigsawpy.jigsaw_jig_t()

    topo = jigsawpy.jigsaw_msh_t()

    geom = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()

    #------------------------------------ setup files for JIGSAW

    opts.geom_file = \
        os.path.join(dst_path, "geom.msh")

    opts.jcfg_file = \
        os.path.join(dst_path, "opts.jig")

    opts.mesh_file = \
        os.path.join(dst_path, "mesh.msh")

    #------------------------------------ define JIGSAW geometry

    geom.mshID = "ellipsoid-mesh"
    geom.radii = np.full(3, 6.371E+003, dtype=geom.REALS_t)

    jigsawpy.savemsh(opts.geom_file, geom)

    #------------------------------------ make mesh using JIGSAW

    opts.hfun_scal = "absolute"
    opts.hfun_hmax = +150.  # uniform at 150km

    opts.mesh_dims = +2  # 2-dim. simplexes

    opts.optm_qlim = +9.5E-01  # tighter opt. tol
    opts.optm_iter = +32
    opts.optm_qtol = +1.0E-05

    #   opts.optm_kern = "cvt+dqdx"

    rbar = np.mean(geom.radii)  # bisect heuristic

    nlev = round(math.log2(rbar / math.sin(.4 * math.pi) / opts.hfun_hmax))

    ttic = time.time()

    jigsawpy.cmd.tetris(opts, nlev - 1, mesh)

    ttoc = time.time()

    print("CPUSEC =", (ttoc - ttic))

    print("BISECT =", +nlev)

    cost = jigsawpy.triscr2(  # quality metrics!
        mesh.point["coord"], mesh.tria3["index"])

    print("TRISCR =", np.min(cost), np.mean(cost))

    cost = jigsawpy.pwrscr2(mesh.point["coord"], mesh.power,
                            mesh.tria3["index"])

    print("PWRSCR =", np.min(cost), np.mean(cost))

    tbad = jigsawpy.centre2(mesh.point["coord"], mesh.power,
                            mesh.tria3["index"])

    print("OBTUSE =", +np.count_nonzero(np.logical_not(tbad)))

    ndeg = jigsawpy.trideg2(mesh.point["coord"], mesh.tria3["index"])

    print("TOPOL. =", +np.count_nonzero(ndeg == +6) / ndeg.size)

    #------------------------------------ save mesh for Paraview

    jigsawpy.loadmsh(os.path.join(src_path, "topo.msh"), topo)

    #------------------------------------ a very rough land mask

    apos = jigsawpy.R3toS2(geom.radii, mesh.point["coord"][:])

    apos = apos * 180. / np.pi

    zfun = interpolate.RectBivariateSpline(topo.ygrid, topo.xgrid, topo.value)

    mesh.value = zfun(apos[:, 1], apos[:, 0], grid=False)

    cell = mesh.tria3["index"]

    zmsk = \
        mesh.value[cell[:, 0]] + \
        mesh.value[cell[:, 1]] + \
        mesh.value[cell[:, 2]]
    zmsk = zmsk / +3.0

    mesh.tria3 = mesh.tria3[zmsk < +0.]

    print("Saving to ../cache/case_1a.vtk")

    jigsawpy.savevtk(os.path.join(dst_path, "case_1a.vtk"), mesh)

    return