Exemple #1
0
def initGrid(ctx, Lx, Ly, Lz, Mx, My, Mz, p):
    """Initialize a :cpp:class:`IceGrid` intended for 3-d computations.

    :param ctx:  The execution context.
    :param Lx:   Half width of the ice model grid in x-direction (m)
    :param Ly:   Half width of the ice model grid in y-direction (m)
    :param Lz:   Extent of the grid in the vertical direction (m)
    :param Mx:   number of grid points in the x-direction
    :param My:   number of grid points in the y-direction
    :param Mz:   number of grid points in the z-direction
    :param p:    grid periodicity (one of ``PISM.NOT_PERIODIC``, ``PISM.X_PERIODIC``,
                  ``PISM.Y_PERIODIC``, or ``PISM.XY_PERIODIC``)
    """
    P = PISM.GridParameters()

    P.Lx = Lx
    P.Ly = Ly
    P.Mx = Mx
    P.My = My
    P.periodicity = p
    z = PISM.IceGrid.compute_vertical_levels(Lz, Mz, PISM.EQUAL)
    P.z = PISM.DoubleVector(z)
    P.horizontal_extent_from_options()
    P.ownership_ranges_from_options(ctx.size)

    return PISM.IceGrid(ctx.ctx, P)
Exemple #2
0
def initGrid(ctx, Lx, Ly, Lz, Mx, My, Mz, r):
    """Initialize a :cpp:class:`IceGrid` intended for 3-d computations.

    :param ctx:  The execution context.
    :param Lx:   Half width of the ice model grid in x-direction (m)
    :param Ly:   Half width of the ice model grid in y-direction (m)
    :param Lz:   Extent of the grid in the vertical direction (m)
    :param Mx:   number of grid points in the x-direction
    :param My:   number of grid points in the y-direction
    :param Mz:   number of grid points in the z-direction
    :param r:    grid registration (one of ``PISM.CELL_CENTER``, ``PISM.CELL_CORNER``)
    """
    P = PISM.GridParameters(ctx.config)

    P.Lx = Lx
    P.Ly = Ly
    P.Mx = Mx
    P.My = My
    P.registration = r
    z = PISM.IceGrid.compute_vertical_levels(Lz, Mz, PISM.EQUAL)
    P.z = PISM.DoubleVector(z)
    P.horizontal_extent_from_options(ctx.unit_system)
    P.ownership_ranges_from_options(ctx.size)

    return PISM.IceGrid(ctx.ctx, P)
Exemple #3
0
    def __init__(self, Mz, dt):
        self.Lz = 1000.0
        self.z = np.linspace(0, self.Lz, Mz)

        param = PISM.GridParameters()
        param.Lx = 1e5
        param.Ly = 1e5
        param.z = PISM.DoubleVector(self.z)
        param.Mx = 3
        param.My = 3
        param.Mz = Mz

        param.ownership_ranges_from_options(1)

        self.dt = dt

        self.grid = PISM.IceGrid(ctx.ctx, param)
        grid = self.grid

        self.enthalpy = PISM.model.createEnthalpyVec(grid)

        self.strain_heating = PISM.model.createStrainHeatingVec(grid)

        self.u, self.v, self.w = PISM.model.create3DVelocityVecs(grid)

        self.sys = PISM.enthSystemCtx(grid.z(), "energy.enthalpy", grid.dx(),
                                      grid.dy(), self.dt, config,
                                      self.enthalpy, self.u, self.v, self.w,
                                      self.strain_heating, EC)

        # zero ice velocity:
        self.reset_flow()
        # no strain heating:
        self.reset_strain_heating()
Exemple #4
0
    def __init__(self, prefix, Mz, dt, Lz=1000.0):
        self.Lz = Lz
        self.z = np.linspace(0, self.Lz, Mz)

        param = PISM.GridParameters()
        param.Lx = 1e5
        param.Ly = 1e5
        param.z = PISM.DoubleVector(self.z)
        param.Mx = 3
        param.My = 3
        param.Mz = Mz

        param.ownership_ranges_from_options(1)

        self.dt = dt

        self.grid = PISM.IceGrid(ctx.ctx, param)
        grid = self.grid

        self.enthalpy = PISM.model.createEnthalpyVec(grid)

        self.strain_heating = PISM.model.createStrainHeatingVec(grid)
        self.strain_heating.set(0.0)

        self.u, self.v, self.w = PISM.model.create3DVelocityVecs(grid)
        self.u.set(0.0)
        self.v.set(0.0)
        self.w.set(0.0)

        self.sys = PISM.enthSystemCtx(grid.z(), prefix, grid.dx(), grid.dy(),
                                      self.dt, config, self.enthalpy, self.u,
                                      self.v, self.w, self.strain_heating, EC)
Exemple #5
0
def create_grid():
    P = PISM.GridParameters(config)
    P.horizontal_size_from_options()
    P.horizontal_extent_from_options()
    P.vertical_grid_from_options(config)
    P.ownership_ranges_from_options(ctx.size)

    return PISM.IceGrid(ctx.ctx, P)
Exemple #6
0
def init(testname, L):

    # the domain is a square [0, L]*[0, L]
    P = PISM.GridParameters(config)
    P.Lx = L / 2.0
    P.Ly = L / 2.0
    P.x0 = L / 2.0
    P.y0 = L / 2.0
    P.periodicity = PISM.XY_PERIODIC
    P.z = PISM.DoubleVector(np.linspace(0, 2000, 201))
    P.horizontal_size_from_options()

    # use 3 grid points in the y direction for x-z tests
    if testname in "BD":
        P.My = 3

    P.ownership_ranges_from_options(ctx.size)

    grid = PISM.IceGrid(ctx.ctx, P)

    geometry = PISM.Geometry(grid)

    grid.variables().add(geometry.ice_thickness)
    grid.variables().add(geometry.cell_type)
    grid.variables().add(geometry.bed_elevation)

    # enthalpy values are irrelevant: these tests use an isothermal flow law
    enthalpy = PISM.IceModelVec3(grid, "enthalpy", PISM.WITHOUT_GHOSTS,
                                 grid.z())
    enthalpy.set_attrs("internal", "enthalpy of ice", "J kg-1", "J kg-1", "",
                       0)

    yield_stress = PISM.IceModelVec2S(grid, "tauc", PISM.WITHOUT_GHOSTS)
    yield_stress.set_attrs("internal", "basal yield stress", "Pa", "Pa", "", 0)

    with PISM.vec.Access(
        [yield_stress, geometry.ice_thickness, geometry.bed_elevation]):
        for (i, j) in grid.points():
            x = grid.x(i)
            y = grid.y(j)
            # Convert from "Pa year / m" to "Pa s / m"
            yield_stress[i, j] = tauc[testname](x, y, L) * seconds_per_year
            # Set ice thickness: it is not used by the Blatter-Pattyn solver itself but is
            # needed to compute vertically-averaged ice velocity, etc.
            geometry.ice_thickness[i, j] = s[testname](x, y, L) - b[testname](
                x, y, L)
            geometry.bed_elevation[i, j] = b[testname](x, y, L)

    geometry.sea_level_elevation.copy_from(geometry.bed_elevation)
    # ensure that the whole domain is grounded
    geometry.sea_level_elevation.shift(-100.0)

    geometry.ensure_consistency(0.0)

    return grid, geometry, enthalpy, yield_stress
Exemple #7
0
def allocate_grid(ctx):
    params = PISM.GridParameters(ctx.config)
    params.Lx = 1e5
    params.Ly = 1e5
    params.Lz = 1000
    params.Mx = 11
    params.My = 11
    params.Mz = 5
    params.registration = PISM.CELL_CORNER
    params.periodicity = PISM.NOT_PERIODIC
    params.ownership_ranges_from_options(ctx.size)
    return PISM.IceGrid(ctx.ctx, params)
Exemple #8
0
    def inputs(self, N):
        P = PISM.GridParameters(config)

        # Domain: [-50e3, 50e3] * [-dx, dx] * [0, 1000]
        Lx = 50e3
        Mx = N
        dx = (2 * Lx) / (Mx - 1)

        P.Lx = 50e3
        P.Mx = int(N)
        P.x0 = 0.0

        P.Ly = dx
        P.My = 3
        P.y0 = 0.0

        # this vertical grid is used to store ice enthalpy, not ice velocity, so 2 levels
        # is enough
        P.z = PISM.DoubleVector([0.0, self.H])
        P.registration = PISM.CELL_CORNER
        P.periodicity = PISM.Y_PERIODIC
        P.ownership_ranges_from_options(ctx.size)

        grid = PISM.IceGrid(ctx.ctx, P)

        geometry = PISM.Geometry(grid)

        enthalpy = PISM.IceModelVec3(grid, "enthalpy", PISM.WITHOUT_GHOSTS,
                                     grid.z())
        # initialize enthalpy (the value used here is irrelevant)
        enthalpy.set(1e5)

        yield_stress = PISM.IceModelVec2S(grid, "tauc", PISM.WITHOUT_GHOSTS)

        yield_stress.set(self.beta)

        with PISM.vec.Access(geometry.bed_elevation):
            for (i, j) in grid.points():
                x = grid.x(i)
                geometry.bed_elevation[
                    i, j] = self.s0 - self.H - self.alpha * x**2

        geometry.ice_thickness.set(self.H)

        # ensure that all ice is grounded
        geometry.sea_level_elevation.copy_from(geometry.bed_elevation)
        geometry.sea_level_elevation.shift(-1.0)

        geometry.ensure_consistency(0.0)

        return geometry, enthalpy, yield_stress
Exemple #9
0
    def inputs(self, N):
        P = PISM.GridParameters(config)

        # Domain: [0, 1] * [-dx, dx] * [-1, 0]
        Lx = 0.5 * self.L
        Mx = N
        dx = (2 * Lx) / (Mx - 1)

        P.Lx = Lx
        P.Mx = int(N)
        P.x0 = Lx

        P.Ly = dx
        P.My = 3
        P.y0 = 0.0

        # this vertical grid is used to store ice enthalpy, not ice velocity, so 2 levels
        # is enough
        P.z = PISM.DoubleVector([0.0, self.H])
        P.registration = PISM.CELL_CORNER
        P.periodicity = PISM.Y_PERIODIC
        P.ownership_ranges_from_options(ctx.size)

        grid = PISM.IceGrid(ctx.ctx, P)

        geometry = PISM.Geometry(grid)

        enthalpy = PISM.IceModelVec3(grid, "enthalpy", PISM.WITHOUT_GHOSTS,
                                     grid.z())
        # initialize enthalpy (the value used here is irrelevant)
        enthalpy.set(1e5)

        yield_stress = PISM.IceModelVec2S(grid, "tauc", PISM.WITHOUT_GHOSTS)
        # this value is not important: we use a compensatory term at the base instead of
        # the sliding law
        yield_stress.set(0.0)

        geometry.bed_elevation.set(-self.H)
        geometry.ice_thickness.set(self.H)
        geometry.ice_surface_elevation.set(0.0)
        geometry.cell_type.set(PISM.MASK_FLOATING)
        geometry.sea_level_elevation.set(0.0)

        # do *not* call geometry.ensure_consistency(): we want to keep surface elevation
        # at the sea levels

        return geometry, enthalpy, yield_stress
Exemple #10
0
def sia_test():
    "Test the PISM.sia module"
    ctx = PISM.Context()
    params = PISM.GridParameters(ctx.config)
    params.Lx = 1e5
    params.Ly = 1e5
    params.Lz = 1000
    params.Mx = 100
    params.My = 100
    params.Mz = 11
    params.registration = PISM.CELL_CORNER
    params.periodicity = PISM.NOT_PERIODIC
    params.ownership_ranges_from_options(ctx.size)
    grid = PISM.IceGrid(ctx.ctx, params)

    enthalpyconverter = PISM.EnthalpyConverter(ctx.config)

    mask = PISM.model.createIceMaskVec(grid)
    mask.set(PISM.MASK_GROUNDED)

    thk = PISM.model.createIceThicknessVec(grid)
    thk.set(1000.0)

    surface = PISM.model.createIceSurfaceVec(grid)
    surface.set(1000.0)

    bed = PISM.model.createBedrockElevationVec(grid)
    bed.set(0.0)

    enthalpy = PISM.model.createEnthalpyVec(grid)
    enthalpy.set(enthalpyconverter.enthalpy(270.0, 0.0, 0.0))

    modeldata = PISM.model.ModelData(grid)
    modeldata.setPhysics(enthalpyconverter)

    vecs = grid.variables()

    fields = [thk, surface, mask, bed, enthalpy]

    for field in fields:
        vecs.add(field)

    vel_sia = PISM.sia.computeSIASurfaceVelocities(modeldata)
Exemple #11
0
def regridding_test():
    "Test 2D regridding: same input and target grids."
    import numpy as np

    ctx = PISM.Context()
    params = PISM.GridParameters(ctx.config)
    params.Mx = 3
    params.My = 3
    params.ownership_ranges_from_options(1)

    grid = PISM.IceGrid(ctx.ctx, params)

    thk1 = PISM.model.createIceThicknessVec(grid)
    thk2 = PISM.model.createIceThicknessVec(grid)
    x = grid.x()
    x_min = np.min(x)
    x_max = np.max(x)
    y = grid.y()
    y_min = np.min(y)
    y_max = np.max(y)
    with PISM.vec.Access(nocomm=[thk1]):
        for (i, j) in grid.points():
            F_x = (x[i] - x_min) / (x_max - x_min)
            F_y = (y[j] - y_min) / (y_max - y_min)
            thk1[i, j] = (F_x + F_y) / 2.0

    file_name = filename("thickness")
    try:
        thk1.dump(file_name)

        thk2.regrid(file_name, critical=True)

        with PISM.vec.Access(nocomm=[thk1, thk2]):
            for (i, j) in grid.points():
                v1 = thk1[i, j]
                v2 = thk2[i, j]
                if np.abs(v1 - v2) > 1e-12:
                    raise AssertionError("mismatch at {},{}: {} != {}".format(
                        i, j, v1, v2))

    finally:
        os.remove(file_name)
Exemple #12
0
    def __init__(self, Mx, Mz, Lx, Lz, mg_levels, coarsening_factor):
        P = PISM.GridParameters(config)

        P.Mx = Mx
        P.Lx = Lx
        P.x0 = 0.0

        dx = (2 * P.Lx) / (P.Mx - 1)

        P.Ly = dx
        P.My = 3
        P.y0 = 0.0

        P.registration = PISM.CELL_CORNER
        P.periodicity = PISM.Y_PERIODIC
        P.z = PISM.DoubleVector([0.0, Lz])

        P.ownership_ranges_from_options(ctx.size)

        grid = PISM.IceGrid(ctx.ctx, P)

        geometry = PISM.Geometry(grid)

        enthalpy = PISM.IceModelVec3(grid, "enthalpy", PISM.WITHOUT_GHOSTS,
                                     grid.z())
        enthalpy.set_attrs("internal", "enthalpy of ice", "J kg-1", "J kg-1",
                           "", 0)

        yield_stress = PISM.IceModelVec2S(grid, "tauc", PISM.WITHOUT_GHOSTS)
        yield_stress.set_attrs("internal", "basal yield stress", "Pa", "Pa",
                               "", 0)

        # this value is not important (we use an isothermal flow law)
        enthalpy.set(1e5)

        self.grid = grid
        self.geometry = geometry
        self.enthalpy = enthalpy
        self.yield_stress = yield_stress
        self.Mz = Mz
        self.mg_levels = mg_levels
        self.coarsening_factor = coarsening_factor
Exemple #13
0
    def grid(self, Mx, Lx, x0):

        dx = (2 * Lx) / (Mx - 1)

        P = PISM.GridParameters(config)

        P.Lx = Lx
        P.Mx = Mx
        P.x0 = Lx

        P.Ly = dx
        P.My = 3
        P.y0 = 0.0

        # this vertical grid is used to store ice enthalpy, not ice velocity, so 2 levels
        # is enough
        P.z = PISM.DoubleVector([0.0, self.H0])
        P.registration = PISM.CELL_CORNER
        P.periodicity = PISM.Y_PERIODIC
        P.ownership_ranges_from_options(ctx.size)

        return PISM.IceGrid(ctx.ctx, P)
Exemple #14
0
    def create_grid(self, Mx=201):
        Lx = 1e5

        # compute dx and set Ly so that dy == dx
        dx = (2 * Lx) / (Mx - 1)
        dy = dx

        P = PISM.GridParameters(config)
        P.horizontal_size_from_options()
        P.Mx = Mx
        P.My = 3
        P.periodicity = PISM.Y_PERIODIC
        P.Lx = Lx
        P.x0 = 1.1 * Lx
        P.Ly = dy
        P.y0 = 0
        P.registration = PISM.CELL_CORNER
        P.z = PISM.DoubleVector([0, 1000])
        P.ownership_ranges_from_options(ctx.com.size)

        grid = PISM.IceGrid(ctx.ctx, P)

        return grid
Exemple #15
0
    def inputs(self, N):
        "Allocate stress balance inputs for a given grid size"

        P = PISM.GridParameters(config)

        # Domain: [0,1] * [0, 1] * [0, 1]
        P.Lx = 0.5
        P.Ly = 0.5
        P.x0 = 0.5
        P.y0 = 0.5
        # This vertical grid is used for the enthalpy field only *and* we use an
        # isothermal flow law, so 2 levels is enough.
        P.z = PISM.DoubleVector([0.0, 1.0])
        P.registration = PISM.CELL_CORNER
        P.Mx = int(N)
        P.My = int(N)
        P.ownership_ranges_from_options(ctx.size)

        grid = PISM.IceGrid(ctx.ctx, P)

        geometry = PISM.Geometry(grid)

        enthalpy = PISM.IceModelVec3(grid, "enthalpy", PISM.WITHOUT_GHOSTS,
                                     grid.z())
        # initialize enthalpy (the value used here is irrelevant)
        enthalpy.set(1e5)

        yield_stress = PISM.IceModelVec2S(grid, "tauc", PISM.WITHOUT_GHOSTS)
        yield_stress.set(0.0)

        geometry.bed_elevation.set(0.0)
        geometry.ice_thickness.set(1.0)
        geometry.sea_level_elevation.set(0.0)
        geometry.ensure_consistency(0.0)

        return geometry, enthalpy, yield_stress
Exemple #16
0
def vertical_extrapolation_during_regridding_test():
    "Test extrapolation in the vertical direction"
    # create a grid with 11 levels, 1000m thick
    ctx = PISM.Context()
    params = PISM.GridParameters(ctx.config)
    params.Lx = 1e5
    params.Ly = 1e5
    params.Mx = 3
    params.My = 3
    params.Mz = 11
    params.Lz = 1000
    params.registration = PISM.CELL_CORNER
    params.periodicity = PISM.NOT_PERIODIC
    params.ownership_ranges_from_options(ctx.size)

    z = np.linspace(0, params.Lz, params.Mz)
    params.z[:] = z

    grid = PISM.IceGrid(ctx.ctx, params)

    # create an IceModelVec that uses this grid
    v = PISM.IceModelVec3()
    v.create(grid, "test", PISM.WITHOUT_GHOSTS)
    v.set(0.0)

    # set a column
    with PISM.vec.Access(nocomm=[v]):
        v.set_column(1, 1, z)

    # save to a file
    v.dump("test.nc")

    # create a taller grid (to 2000m):
    params.Lz = 2000
    params.Mz = 41
    z_tall = np.linspace(0, params.Lz, params.Mz)
    params.z[:] = z_tall

    tall_grid = PISM.IceGrid(ctx.ctx, params)

    # create an IceModelVec that uses this grid
    v_tall = PISM.IceModelVec3()
    v_tall.create(tall_grid, "test", PISM.WITHOUT_GHOSTS)

    # Try regridding without extrapolation. This should fail.
    try:
        ctx.ctx.log().disable()
        v_tall.regrid("test.nc", PISM.CRITICAL)
        ctx.ctx.log().enable()
        raise AssertionError("Should not be able to regrid without extrapolation")
    except RuntimeError as e:
        pass

    # allow extrapolation during regridding
    ctx.config.set_flag("grid.allow_extrapolation", True)

    # regrid from test.nc
    ctx.ctx.log().disable()
    v_tall.regrid("test.nc", PISM.CRITICAL)
    ctx.ctx.log().enable()

    # get a column
    with PISM.vec.Access(nocomm=[v_tall]):
        column = np.array(v_tall.get_column_vector(1, 1))

    # compute the desired result
    desired = np.r_[np.linspace(0, 1000, 21), np.zeros(20) + 1000]

    # compare
    np.testing.assert_almost_equal(column, desired)

    # clean up
    import os
    os.remove("test.nc")
Exemple #17
0
def create_dummy_grid():
    "Create a dummy grid"
    params = PISM.GridParameters(ctx.config)
    params.ownership_ranges_from_options(ctx.size)
    return PISM.IceGrid(ctx.ctx, params)
Exemple #18
0
    Mx = PISM.optionsInt("-Mx",
                         "Number of grid points in x-direction",
                         default=Mx)
    My = PISM.optionsInt("-My",
                         "Number of grid points in y-direction",
                         default=My)
    output_filename = PISM.optionsString("-o",
                                         "output file",
                                         default="tiny.nc")
    verbosity = PISM.optionsInt("-verbose", "verbosity level", default=3)

    # Build the grid.
    config = PISM.Context().config

    p = PISM.GridParameters(config)
    p.Mx = Mx
    p.My = My
    p.Lx = Lx
    p.Ly = Ly
    z = PISM.IceGrid.compute_vertical_levels(Lz, Mz, PISM.EQUAL, 4.0)
    p.z = PISM.DoubleVector(z)
    p.ownership_ranges_from_options(context.size)
    p.periodicity = PISM.NOT_PERIODIC
    grid = PISM.IceGrid(context.ctx, p)

    vecs = PISM.model.ModelVecs(grid.variables())
    vecs.add(PISM.model.createIceSurfaceVec(grid))
    vecs.add(PISM.model.createIceThicknessVec(grid))
    vecs.add(PISM.model.createBedrockElevationVec(grid))
    vecs.add(PISM.model.createYieldStressVec(grid), 'tauc')