コード例 #1
0
def case_8_(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 8a.")

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

    opts.hfun_hmax = 0.04  # set HFUN limits

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

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

    print("Saving case_8a.vtk file.")

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

    print("Saving case_8b.vtk file.")

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

    return
コード例 #2
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
コード例 #3
0
ファイル: compose.py プロジェクト: DOE-ICoM/icom-mesh
def setinit():

    init = jigsawpy.jigsaw_msh_t()

    #------------------------------------ set initial conditions

    print("BUILDING MESH INIT.")

    filename = os.path.join(HERE, "..", "delaware_60_30_5_2", "tmp",
                            "mesh.msh")

    if os.path.isfile(filename):  # load from init.

        jigsawpy.loadmsh(filename, init)

    else:

        raise Exception("File not found: first run delaware_60_30_5_2"
                        " to form initial conditions!")

    geom = copy.deepcopy(GEOM[0])
    spac = copy.deepcopy(SPAC[0])

    zipnear(init, geom, spac, near=+1.E+01)

    return init
コード例 #4
0
def case_6_(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, "piece.msh")

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

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

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

    jigsawpy.loadmsh(opts.geom_file, geom)

    print("Saving case_6a.vtk file.")

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

    opts.hfun_hmax = 0.03  # set HFUN limits

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

    jigsawpy.cmd.jigsaw(opts, mesh)

    print("Saving case_6b.vtk file.")

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

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

    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

    jigsawpy.cmd.jigsaw(opts, mesh)

    print("Saving case_6c.vtk file.")

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

    return
コード例 #5
0
ファイル: geom.py プロジェクト: pvelissariou1/geomesh
    def geom(self):
        """
        This is the global geom
        """
        try:
            name = self.__geom_tmpfile.name
            geom = jigsaw_msh_t()
            loadmsh(name, geom)
            return geom

        except AttributeError:

            # jigsawpy.msh_t.jigsaw_msh_t
            if isinstance(self._geom, jigsaw_msh_t):
                self._logger.debug('self.geom:AttributeError:jigsaw_msh_t')
                self._geom.edge2 = geomesh.utils.edge2_from_msh_t(self._geom)
                geom = self._geom

            elif isinstance(self._geom, (Polygon, MultiPolygon)):
                msg = 'self.geom:AttributeError:(Polygon, MultiPolygon)'
                self._logger.debug(msg)
                geom = self._get_geom_from_shapely()

            # RasterCollection
            elif isinstance(
                self._geom,
                (
                    geomesh.Raster,
                    geomesh.RasterCollection
                )
                    ):
                msg = 'self.geom:AttributeError:(Raster, RasterCollection)'
                self._logger.debug(msg)
                geom = self._get_geom_from_raster()

            else:
                self._logger.debug('self.geom:AttributeError:Undefined')
                msg = f"Undefined handler for geom type {self._geom}"
                raise NotImplementedError(msg)

            tmpfile = tempfile.NamedTemporaryFile(
                prefix=geomesh.tmpdir, suffix='.msh')
            savemsh(tmpfile.name, geom)
            self.__geom_tmpfile = tmpfile
            # spherical mesh
            if self._radii is not None:
                geom.radii = self._radii
                geom.mshID = self._mshID
            return geom
コード例 #6
0
def read_msh(msh_file):

    mesh = jigsawpy.jigsaw_msh_t()
    jigsawpy.loadmsh(msh_file, mesh)
    nn = len(mesh.point)
    lon_mesh = np.zeros(nn)
    lat_mesh = np.zeros(nn)
    for i in range(nn):
        lon_mesh[i] = mesh.point[i][0][0]
        lat_mesh[i] = mesh.point[i][0][1]

    ne = len(mesh.tria3)
    ect = np.zeros((ne, 3))
    for i in range(ne):
        ect[i, :] = mesh.tria3['index'][i][:]

    return lon_mesh, lat_mesh
コード例 #7
0
ファイル: compose.py プロジェクト: DOE-ICoM/icom-mesh
def setspac():

    spac = jigsawpy.jigsaw_msh_t()

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

    print("BUILDING MESH SPAC.")

    filename = os.path.join(HERE, "..", "delaware_60_30_5_2", "tmp",
                            "spac.msh")

    if os.path.isfile(filename):  # load from init.

        jigsawpy.loadmsh(filename, spac)

    else:

        raise Exception("File not found: first run delaware_60_30_5_2"
                        " to form initial conditions!")

    SPAC[0] = spac  # save a "pointer"

    return spac
コード例 #8
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
コード例 #9
0
ファイル: case_3_.py プロジェクト: pgierz/jigsaw-geo-python
def case_3_(src_path, dst_path):

    # DEMO-3: generate multi-resolution spacing, via local refi-
    # nement 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()

    hraw = jigsawpy.jigsaw_msh_t()
    hlim = 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.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)

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

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

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

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

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

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

    hraw.value[mask] = hfn0

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

    hlim = copy.copy(hraw)

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

    jigsawpy.savemsh(opts.hfun_file, hlim)

    jigsawpy.cmd.marche(opts, hlim)

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

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

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

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

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

    return
コード例 #10
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
コード例 #11
0
def getInitialMesh(topofile, meshfile, spacefile, outfile, dst_path, hfn):

    t0 = process_time()
    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()

    jigsawpy.loadmsh(topofile, topo)
    print("Load topography grid (%0.02f seconds)" % (process_time() - t0))

    t0 = process_time()
    opts.geom_file = os.path.join(dst_path, "topology.msh")
    opts.jcfg_file = os.path.join(dst_path, "config.jig")
    opts.mesh_file = meshfile
    opts.hfun_file = spacefile

    geom.mshID = "ellipsoid-mesh"
    geom.radii = np.full(3, 6.371e003, dtype=geom.REALS_t)
    jigsawpy.savemsh(opts.geom_file, geom)

    hmat.mshID = "ellipsoid-grid"
    hmat.radii = geom.radii
    hmat.xgrid = topo.xgrid * np.pi / 180.0
    hmat.ygrid = topo.ygrid * np.pi / 180.0

    # Set HFUN gradient-limiter
    hmat.value = np.full(topo.value.shape, hfn[0], dtype=hmat.REALS_t)
    hmat.value[topo.value > -1000] = hfn[1]
    hmat.value[topo.value > 0] = hfn[2]

    hmat.slope = np.full(topo.value.shape, +0.050, dtype=hmat.REALS_t)
    jigsawpy.savemsh(opts.hfun_file, hmat)
    jigsawpy.cmd.marche(opts, hmat)
    print("Build space function (%0.02f seconds)" % (process_time() - t0))

    t0 = process_time()
    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)
    print("Perform triangulation (%0.02f seconds)" % (process_time() - t0))

    t0 = process_time()
    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)

    jigsawpy.savevtk(outfile, mesh)
    jigsawpy.savemsh(opts.mesh_file, mesh)
    print("Get unstructured mesh (%0.02f seconds)" % (process_time() - t0))

    return
コード例 #12
0
ファイル: run_jigsaw.py プロジェクト: sbrus89/ww3_utils
def waves_mesh(cfg):

    pwd = os.getcwd()
    src_path = pwd
    dst_path = pwd

    opts = jigsawpy.jigsaw_jig_t()

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

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

    opts.geom_file = \
        str(Path(dst_path)/"geom.msh") # GEOM file

    opts.jcfg_file = \
        str(Path(dst_path)/"jcfg.jig") # JCFG file

    opts.hfun_file = \
        str(Path(dst_path)/"hfun.msh") # HFUN file

    opts.mesh_file = \
        str(Path(dst_path)/"mesh.msh") # MESH file

    opts.init_file = \
        str(Path(dst_path)/"init.msh") # INIT file

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

    if cfg['coastlines']:
        print('Defining coastline geometry')
        create_coastline_geometry(cfg['shpfiles'], opts.geom_file,
                                  cfg['sphere_radius'])
    else:
        geom = jigsawpy.jigsaw_msh_t()
        geom.mshID = 'ELLIPSOID-MESH'
        geom.radii = cfg['sphere_radius'] * np.ones(3, float)
        jigsawpy.savemsh(opts.geom_file, geom)

#------------------------------------ define mesh size function

    print('Defining mesh size function')

    lon_min = -180.0
    lon_max = 180.0
    dlon = cfg['hfun_grid_spacing']
    nlon = int((lon_max - lon_min) / dlon) + 1
    lat_min = -90.0
    lat_max = 90.0
    nlat = int((lat_max - lat_min) / dlon) + 1
    dlat = cfg['hfun_grid_spacing']

    xlon = np.linspace(lon_min, lon_max, nlon)
    ylat = np.linspace(lat_min, lat_max, nlat)
    print('   hfun grid dimensions: {}, {}'.format(xlon.size, ylat.size))

    define_hfunction.depth_threshold_refined = cfg['depth_threshold_refined']
    define_hfunction.distance_threshold_refined = cfg[
        'distance_threshold_refined']
    define_hfunction.depth_threshold_global = cfg['depth_threshold_global']
    define_hfunction.distance_threshold_global = cfg[
        'distance_threshold_global']
    define_hfunction.refined_res = cfg['refined_res']
    define_hfunction.maxres = cfg['maxres']

    hfunction = define_hfunction.cell_widthVsLatLon(xlon, ylat,
                                                    cfg['shpfiles'],
                                                    cfg['sphere_radius'],
                                                    cfg['ocean_mesh'])
    hfunction = hfunction / km

    hfun.mshID = "ellipsoid-grid"
    hfun.radii = np.full(3,
                         cfg['sphere_radius'],
                         dtype=jigsawpy.jigsaw_msh_t.REALS_t)
    hfun.xgrid = np.radians(xlon)
    hfun.ygrid = np.radians(ylat)

    hfun.value = hfunction.astype(jigsawpy.jigsaw_msh_t.REALS_t)

    #------------------------------------ specify JIGSAW initial conditions

    print('Specifying initial fixed coordinate locations')
    create_initial_points(cfg['ocean_mesh'], xlon, ylat, hfunction,
                          cfg['sphere_radius'], opts.init_file)
    jigsawpy.loadmsh(opts.init_file, init)
    jigsawpy.savevtk(str(Path(dst_path) / "init.vtk"), init)

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

    print('Limiting mesh size function gradients')
    hfun.slope = np.full(  # |dH/dx| limits
        hfun.value.shape,
        cfg['hfun_slope_lim'],
        dtype=hfun.REALS_t)

    jigsawpy.savemsh(opts.hfun_file, hfun)

    jigsawpy.cmd.marche(opts, 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.mesh_eps1 = +.67  # relax edge error
    opts.mesh_rad2 = +1.2

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

    #jigsawpy.cmd.tetris(opts, 3, mesh)
    jigsawpy.cmd.jigsaw(opts, mesh)
    if cfg['coastlines']:
        segment.segment(mesh)

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

    print("Writing ex_h.vtk file.")

    jigsawpy.savevtk(str(Path(dst_path) / "_hfun.vtk"), hfun)

    jigsawpy.savevtk(str(Path(dst_path) / "waves_mesh.vtk"), mesh)

    jigsawpy.savemsh(str(Path(dst_path) / "waves_mesh.msh"), mesh)

    #------------------------------------ convert mesh to MPAS format

    jigsaw_to_netcdf(msh_filename='waves_mesh.msh',
                     output_name='waves_mesh_triangles.nc',
                     on_sphere=True,
                     sphere_radius=cfg['sphere_radius'])
    write_netcdf(
        convert(xarray.open_dataset('waves_mesh_triangles.nc'),
                dir='./',
                logger=None), 'waves_mesh.nc')

    #------------------------------------ cull mesh to ocean bounary

    if os.path.exists('./cull_waves_mesh'):
        f = open('cull_waves_mesh.nml', 'w')
        f.write('&inputs\n')
        f.write("    waves_mesh_file = 'waves_mesh.nc'\n")
        f.write("    ocean_mesh_file = '" + cfg['ocean_mesh'] + "'\n")
        f.write("/\n")
        f.write('&output\n')
        f.write("    waves_mesh_culled_vtk = 'waves_mesh_culled.vtk'\n")
        f.write("    waves_mesh_culled_gmsh = 'waves_mesh_culled.msh'\n")
        f.write("/\n")
        f.close()

        subprocess.call('./cull_waves_mesh', shell=True)


#------------------------------------ output ocean mesh polygons

    subprocess.call('paraview_vtk_field_extractor.py -f ' + cfg['ocean_mesh'] +
                    ' --ignore_time -v areaCell -o ' + cfg['ocean_mesh'] +
                    '.vtk',
                    shell=True)

    return
コード例 #13
0
def ex_9():

    # DEMO-9: 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.

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

    topo = jigsawpy.jigsaw_msh_t()

    geom = jigsawpy.jigsaw_msh_t()
    mesh = jigsawpy.jigsaw_msh_t()
    msph = 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, "proj.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.0E+00  # relax edge error

    opts.optm_iter = +32
    opts.optm_qtol = +1.0E-05

    jigsawpy.cmd.jigsaw(opts, mesh)

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

    msph = copy.deepcopy(mesh)

    jigsawpy.project(msph, proj, "inv")

    radii = np.full(+3, proj.radii, dtype=jigsawpy.jigsaw_msh_t.REALS_t)

    msph.vert3 = np.zeros((msph.vert2.size),
                          dtype=jigsawpy.jigsaw_msh_t.VERT3_t)

    msph.vert3["coord"] = \
        jigsawpy.S2toR3(
            radii, msph.point["coord"])

    msph.vert2 = None

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

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

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

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

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

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

    jigsawpy.savevtk(os.path.join(dst_path, "case_9c.vtk"), msph)

    return
コード例 #14
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
コード例 #15
0
ファイル: mesher.py プロジェクト: rinzeschuurmans/gospl
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
コード例 #16
0
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
コード例 #17
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
コード例 #18
0
def case_5_(src_path, dst_path):

    # DEMO-5: generate struct. icosahedral and cubedsphere grids

    opts = jigsawpy.jigsaw_jig_t()

    topo = jigsawpy.jigsaw_msh_t()

    geom = jigsawpy.jigsaw_msh_t()
    icos = jigsawpy.jigsaw_msh_t()
    cube = 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, 1.000E+000, dtype=geom.REALS_t)

    jigsawpy.savemsh(opts.geom_file, geom)

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

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

    opts.optm_iter = +512
    opts.optm_qtol = +1.0E-06

    #   opts.optm_kern = "cvt+dqdx"

    ttic = time.time()

    jigsawpy.cmd.icosahedron(opts, +6, icos)

    ttoc = time.time()

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

    ttic = time.time()

    jigsawpy.cmd.cubedsphere(opts, +6, cube)

    ttoc = time.time()

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

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

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

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

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

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

    apos = apos * 180. / np.pi

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

    cell = icos.tria3["index"]

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

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

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

    jigsawpy.savevtk(os.path.join(dst_path, "case_5a.vtk"), icos)

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

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

    apos = apos * 180. / np.pi

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

    cell = cube.quad4["index"]

    zmsk = \
        cube.value[cell[:, 0]] + \
        cube.value[cell[:, 1]] + \
        cube.value[cell[:, 2]] + \
        cube.value[cell[:, 3]]
    zmsk = zmsk / +4.0

    cube.quad4 = cube.quad4[zmsk < +0.]

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

    jigsawpy.savevtk(os.path.join(dst_path, "case_5b.vtk"), cube)

    return
コード例 #19
0
ファイル: case_1_.py プロジェクト: pgierz/jigsaw-geo-python
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
コード例 #20
0
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
コード例 #21
0
ファイル: ex_3.py プロジェクト: dengwirda/jigsaw-geo-tutorial
def ex_3():

# DEMO-3: generate a grid based on the "HR" spacing pattern,
# developed by the FESOM team at AWI.

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

    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

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

    hfun.value = +3. * hfun.value       # for fast example

    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.jigsaw(opts, mesh)

#------------------------------------ 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_3a.vtk")

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

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

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

    return
コード例 #22
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(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
コード例 #23
0
 def open_msh(cls, path, crs=None):
     msh = jigsawpy.jigsaw_msh_t()
     jigsawpy.loadmsh(path, msh)
     return cls.from_msh_t(msh, crs)
コード例 #24
0
ファイル: case_2_.py プロジェクト: pgierz/jigsaw-geo-python
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
コード例 #25
0
ファイル: case_6_.py プロジェクト: pgierz/jigsaw-geo-python
def case_6_(src_path, dst_path):

    # DEMO-6: 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(src_path, "proj.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.

    jigsawpy.cmd.jigsaw(opts, mesh)

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

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

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

    return
コード例 #26
0
def case_5_(src_path, dst_path):

    opts = jigsawpy.jigsaw_jig_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, "airfoil.msh")

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

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

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

    #------------------------------------ compute HFUN over GEOM

    jigsawpy.loadmsh(opts.geom_file, geom)

    xgeo = geom.vert2["coord"][:, 0]
    ygeo = geom.vert2["coord"][:, 1]

    xpos = np.linspace(xgeo.min(), xgeo.max(), 80)

    ypos = np.linspace(ygeo.min(), ygeo.max(), 40)

    xmat, ymat = np.meshgrid(xpos, ypos)

    fun1 = \
        +0.1 * (xmat - .40) ** 2 + \
        +2.0 * (ymat - .55) ** 2

    fun2 = \
        +0.7 * (xmat - .75) ** 2 + \
        +0.7 * (ymat - .45) ** 2

    hfun = np.minimum(fun1, fun2)

    hmin = 0.01
    hmax = 0.10

    hfun = 0.4 * np.maximum(np.minimum(hfun, hmax), hmin)

    hmat.mshID = "euclidean-grid"
    hmat.ndims = +2
    hmat.xgrid = np.array(xpos, dtype=hmat.REALS_t)
    hmat.ygrid = np.array(ypos, dtype=hmat.REALS_t)
    hmat.value = np.array(hfun, dtype=hmat.REALS_t)

    jigsawpy.savemsh(opts.hfun_file, 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_kern = "delfront"  # DELFRONT kernel
    opts.mesh_dims = +2

    opts.geom_feat = True
    opts.mesh_top1 = True

    jigsawpy.cmd.jigsaw(opts, mesh)

    print("Saving case_5a.vtk file.")

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

    print("Saving case_5b.vtk file.")

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

    return
コード例 #27
0
def ex_8():

# DEMO-8: build regional meshes via stereographic projection

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

    topo = jigsawpy.jigsaw_msh_t()

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

    proj = jigsawpy.jigsaw_prj_t()

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

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

    opts.jcfg_file = \
        os.path.join(dst_path, "paci.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, "paci.msh"), geom)

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

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

    xlon = np.linspace(xmin, xmax, 100)

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

    ylat = np.linspace(ymin, ymax, 100)

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

    hfun.mshID = "ellipsoid-grid"
    hfun.radii = np.full(
        +3, 6.371E+003,
        dtype=jigsawpy.jigsaw_msh_t.REALS_t)

    hfun.xgrid = xlon * np.pi / 180.
    hfun.ygrid = ylat * np.pi / 180.

    hfun.value = np.full(
        (ylat.size, xlon.size), 200.,
        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(hfun, proj, "fwd")

    jigsawpy.savemsh(opts.geom_file, geom)
    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.mesh_eps1 = +1.0E+00           # relax edge error

    opts.optm_iter = +32
    opts.optm_qtol = +1.0E-05

    jigsawpy.cmd.jigsaw(opts, mesh)

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

    msph = copy.deepcopy(mesh)

    jigsawpy.project(msph, proj, "inv")

    radii = np.full(
        +3, proj.radii,
        dtype=jigsawpy.jigsaw_msh_t.REALS_t)

    msph.vert3 = np.zeros(
        (msph.vert2.size),
        dtype=jigsawpy.jigsaw_msh_t.VERT3_t)

    msph.vert3["coord"] = \
        jigsawpy.S2toR3(
            radii, msph.point["coord"])

    msph.vert2 = None

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

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

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

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

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

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

    jigsawpy.savevtk(os.path.join(
        dst_path, "case_8c.vtk"), msph)

    return