Ejemplo n.º 1
0
def case_7_(src_path, dst_path):

    opts = jigsawpy.jigsaw_jig_t()

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

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

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

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

    opts.hfun_hmax = 0.03  # set HFUN limits

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

    opts.geom_feat = True
    opts.mesh_top1 = True
    opts.mesh_top2 = True

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

    print("Saving case_7a.vtk file.")

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

    print("Saving case_7b.vtk file.")

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

    return
Ejemplo n.º 2
0
    def _write_to_file(self, out_format, out_file, hfun_collector, crs):

        _logger.info(f"Writing for file ({out_format}) ...")

        # NOTE: Combined mesh from collector is always in EPSG:4326
        jig_hfun = hfun_collector.msh_t()
        dst_crs = CRS.from_user_input(crs)
        if jig_hfun.crs != dst_crs:
            _logger.info(f"Reprojecting hfun to ({crs}) ...")
            utils.reproject(jig_hfun, dst_crs)

        # TODO: Check for correct extension on out_file
        if out_format in ("jigsaw", "vtk"):
            if out_format == "jigsaw":
                savemsh(out_file, jig_hfun)

            elif out_format == "vtk":
                savevtk(out_file, jig_hfun)

        elif out_format in ['2dm', 'sms']:
            # TODO: How to specify crs in 2dm file?
            mesh = Mesh(jig_hfun)
            mesh.write(out_file, format='2dm')

        else:
            raise NotImplementedError(
                f"Output type {out_format} is not supported")

        _logger.info("Done")
Ejemplo n.º 3
0
def ex_7():

    # DEMO-7: setup simple piecewise linear geometry definitions

    dst_path = \
        os.path.abspath(
            os.path.dirname(__file__))

    src_path = \
        os.path.join(dst_path, "..", "files")
    dst_path = \
        os.path.join(dst_path, "..", "cache")

    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, "pslg.msh")

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

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

    #------------------------------------ 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)

    jigsawpy.savemsh(opts.geom_file, geom)

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

    opts.hfun_scal = "absolute"
    opts.hfun_hmax = +2.5E-01  # uniform at 0.250

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

    opts.geom_feat = True  # do sharp feature
    opts.mesh_top1 = True  # preserve 1-topo.

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

    jigsawpy.cmd.jigsaw(opts, mesh)

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

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

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

    return
Ejemplo n.º 4
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(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