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)
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()
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)
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)
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
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
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
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
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)
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
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
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') vecs.add(PISM.model.createEnthalpyVec(grid), 'enthalpy') vecs.add(PISM.model.createIceMaskVec(grid)) vecs.add(PISM.model.createNoModelMaskVec(grid), 'no_model_mask') vecs.add( PISM.model.create2dVelocityVec(grid, name='_ssa_bc',