Exemple #1
0
    def __init__(self, grid, part_grid=False):

        self.grid = grid

        if part_grid:
            grid.ctx().config().set_boolean("geometry.part_grid.enabled", True)

        self.v = PISM.IceModelVec2V(grid, "velocity", PISM.WITHOUT_GHOSTS)
        self.Q = PISM.IceModelVec2Stag(grid, "Q", PISM.WITHOUT_GHOSTS)
        self.v_bc_mask = PISM.IceModelVec2Int(grid, "v_bc_mask", PISM.WITHOUT_GHOSTS)
        self.H_bc_mask = PISM.IceModelVec2Int(grid, "H_bc_mask", PISM.WITHOUT_GHOSTS)

        self.ge = PISM.GeometryEvolution(grid)

        self.geometry = PISM.Geometry(grid)

        self.reset()
Exemple #2
0
def run(Mx, My, t_final, part_grid, C=1.0):
    "Test GeometryEvolution::step()"

    ctx = PISM.Context().ctx

    config = PISM.Context().config

    config.set_flag("geometry.part_grid.enabled", part_grid)

    grid = PISM.IceGrid_Shallow(ctx, 1, 1, 0, 0, Mx, My, PISM.CELL_CORNER,
                                PISM.NOT_PERIODIC)

    assert t_final <= 1.0

    L = min(grid.Lx(), grid.Ly())
    R_inner = 0.25 * L
    spreading_velocity = 0.7
    R_outer = R_inner + spreading_velocity * t_final

    geometry = PISM.Geometry(grid)

    v = PISM.IceModelVec2V(grid, "velocity", PISM.WITHOUT_GHOSTS)
    Q = PISM.IceModelVec2Stag(grid, "Q", PISM.WITHOUT_GHOSTS)
    v_bc_mask = PISM.IceModelVec2Int(grid, "v_bc_mask", PISM.WITHOUT_GHOSTS)
    H_bc_mask = PISM.IceModelVec2Int(grid, "H_bc_mask", PISM.WITHOUT_GHOSTS)

    ge = PISM.GeometryEvolution(grid)

    # grid info
    geometry.latitude.set(0.0)
    geometry.longitude.set(0.0)
    # environment
    geometry.bed_elevation.set(-10.0)
    geometry.sea_level_elevation.set(0.0)
    # set initial ice thickness
    disc(geometry.ice_thickness, 0, 0, 1, R_inner, R_inner)
    geometry.ice_area_specific_volume.set(0.0)

    geometry.ensure_consistency(0.0)

    set_velocity(spreading_velocity, v)
    v_bc_mask.set(0.0)
    disc(H_bc_mask, 0, 0, 1, R_inner, R_inner)

    profiling = ctx.profiling()
    profiling.start()

    t = 0.0
    j = 0
    profiling.stage_begin("ge")
    while t < t_final:
        cfl_data = PISM.max_timestep_cfl_2d(geometry.ice_thickness,
                                            geometry.cell_type, v)

        dt = cfl_data.dt_max.value() * C

        if t + dt > t_final:
            dt = t_final - t

        log.message(2, "{}, {}\n".format(t, dt))

        profiling.begin("step")
        ge.flow_step(geometry, dt, v, Q, v_bc_mask, H_bc_mask)
        profiling.end("step")

        profiling.begin("modify")
        ge.apply_flux_divergence(geometry)
        geometry.ensure_consistency(0.0)
        profiling.end("modify")

        t += dt
        j += 1
    profiling.stage_end("ge")

    profiling.report("profiling_%d_%d.py" % (Mx, My))

    return geometry
Exemple #3
0
def grounding_line_flux_test():
    """Test that the grounding line flux approximation

    The grounding line flux should be zero if the direction of the flux is parallel to the
    grounding line.

    """

    # Mx and My have to be odd
    Mx = 51
    My = 51
    Lx = 1e5
    Ly = 1e5
    grid = PISM.testing.shallow_grid(Mx=Mx, My=My, Lx=Lx, Ly=Ly)

    geometry = PISM.Geometry(grid)

    with PISM.vec.Access([geometry.bed_elevation, geometry.ice_thickness]):
        for i, j in grid.points():
            x = grid.x(i)
            y = grid.y(j)
            C = 0.25 * (Lx + Ly)

            if x - y <= 0.0:
                geometry.bed_elevation[i, j] = 10.0
            elif x + y >= C:
                geometry.bed_elevation[i, j] = 10.0
            else:
                geometry.bed_elevation[i, j] = -10.0

            if i == 0 or j == 0 or i == Mx - 1 or j == My - 1:
                geometry.ice_thickness[i, j] = 0.0
            elif x + y < C:
                geometry.ice_thickness[i, j] = 10.0
            else:
                geometry.ice_thickness[i, j] = 0.0

    geometry.ensure_consistency(0)

    velocity = PISM.IceModelVec2V(grid, "velocity", PISM.WITHOUT_GHOSTS)
    thk_bc_mask = PISM.IceModelVec2Int(grid, "thk_bc_mask",
                                       PISM.WITHOUT_GHOSTS)
    thk_bc_mask.set(0)
    sia_flux = PISM.IceModelVec2Stag(grid, "sia_flux", PISM.WITHOUT_GHOSTS)
    sia_flux.set(0)

    dt = 365 * 86400
    V = 1.0 / dt
    with PISM.vec.Access(velocity):
        for i, j in grid.points():
            velocity[i, j].u = V
            velocity[i, j].v = V

    geometry_evolution = PISM.GeometryEvolution(grid)

    geometry_evolution.flow_step(geometry, dt, velocity, sia_flux, thk_bc_mask)

    gl_flux = PISM.IceModelVec2S(grid, "grounding_line_flux",
                                 PISM.WITHOUT_GHOSTS)
    PISM.grounding_line_flux(
        geometry.cell_type,
        geometry_evolution.flux_staggered(),
        dt,
        False,  # replace values instead of adding
        gl_flux)

    NORM_INFINITY = 3
    np.testing.assert_almost_equal(gl_flux.norm(NORM_INFINITY), 0.0)
Exemple #4
0
def mass_transport_test(t_final, C=1.0):
    "Test GeometryEvolution::step()"

    ctx = PISM.Context().ctx

    config = PISM.Context().config

    # config.set_boolean("geometry.part_grid.enabled", True)

    Mx = 101
    My = 101

    grid = PISM.IceGrid_Shallow(ctx, 1, 1, 0, 0, Mx, My, PISM.CELL_CORNER,
                                PISM.NOT_PERIODIC)

    geometry = PISM.Geometry(grid)

    v = PISM.model.create2dVelocityVec(grid)

    Q = PISM.IceModelVec2Stag()
    Q.create(grid, "Q", PISM.WITHOUT_GHOSTS)

    v_bc_mask = PISM.IceModelVec2Int()
    v_bc_mask.create(grid, "v_bc_mask", PISM.WITHOUT_GHOSTS)

    H_bc_mask = PISM.IceModelVec2Int()
    H_bc_mask.create(grid, "H_bc_mask", PISM.WITHOUT_GHOSTS)

    SMB = PISM.IceModelVec2S()
    SMB.create(grid, "SMB", PISM.WITHOUT_GHOSTS)

    BMR = PISM.IceModelVec2S()
    BMR.create(grid, "BMR", PISM.WITHOUT_GHOSTS)

    ge = PISM.GeometryEvolution(grid)

    # grid info
    geometry.cell_area().set(grid.dx() * grid.dy())
    geometry.latitude().set(0.0)
    geometry.longitude().set(0.0)
    # environment
    geometry.bed_elevation().set(-10.0)
    geometry.sea_level_elevation().set(0.0)
    # ice
    set_ice_thickness(geometry.ice_thickness(), time=1)
    geometry.ice_area_specific_volume().set(0.0)

    geometry.ensure_consistency(0.0)

    set_velocity(v)
    v_bc_mask.set(
        0.0)  # all points are velocity B.C. points (but it does not matter)
    H_bc_mask.set(0.0)
    SMB.set(0.0)
    BMR.set(0.0)

    profiling = ctx.profiling()
    profiling.start()

    t = 0.0
    j = 0
    profiling.stage_begin("ge")
    while t < t_final:

        dt = PISM.max_timestep_cfl_2d(geometry.ice_thickness(),
                                      geometry.cell_type(),
                                      v).dt_max.value() * C

        if t + dt > t_final:
            dt = t_final - t

        log.message(2, "{}, {}\n".format(t, dt))

        profiling.begin("dump")
        geometry.ice_thickness().dump("thk-%05d.nc" % (j + 1))
        geometry.ice_area_specific_volume().dump("Href-%05d.nc" % (j + 1))
        profiling.end("dump")

        profiling.begin("step")
        ge.step(geometry, dt, v, Q, v_bc_mask, H_bc_mask, SMB, BMR)
        profiling.end("step")

        profiling.begin("modify")
        geometry.ice_thickness().add(1.0, ge.thickness_change_due_to_flow())
        geometry.ice_area_specific_volume().add(
            1.0, ge.area_specific_volume_change_due_to_flow())
        geometry.ensure_consistency(0.0)
        profiling.end("modify")

        t += dt
        j += 1
    profiling.stage_end("ge")

    profiling.report("profiling.py")

    return geometry, dt