# This function pulls in the mesh and observational data that we'll use. import preprocess preprocess.main() # Read in the observational data. vx_obs = icepack.read_arc_ascii_grid(open("ross-vx.txt", "r")) vy_obs = icepack.read_arc_ascii_grid(open("ross-vy.txt", "r")) h_obs = icepack.read_arc_ascii_grid(open("ross-h.txt", "r")) mesh = icepack.read_msh("ross.msh") fig, ax = plt.subplots() ax.set_aspect('equal') icepack.plot.plot_mesh(ax, mesh) plt.show(fig) discretization = icepack.make_discretization(mesh, 1) v = icepack.interpolate(discretization, vx_obs, vy_obs) h = icepack.interpolate(discretization, h_obs) # Make a dumb guess for the ice temperature. In "real life", you would want to # use an inverse method that would tune the temperature to fit observations. theta = icepack.interpolate(discretization, lambda x: 253.0) # Solve for the ice velocity, assuming this guess for the temperature. dirichlet_boundary_ids = {2, 3, 4, 5} ice_shelf = icepack.IceShelf(dirichlet_boundary_ids) u = ice_shelf.solve(h, theta, v) print("Misfit between computed and observed velocities: {}" .format(icepack.dist(u, v) / icepack.norm(v)))
import icepack mesh = icepack.read_msh("tests/rectangle.msh") mesh.refine_global(2) discretization = icepack.make_discretization(mesh, 1) def test_discretization(): assert discretization.triangulation is not None def test_interpolating(): u = icepack.interpolate(discretization, lambda x: x[0] * x[1]) assert u.discretization is discretization assert icepack.max(u) <= 1.0 def test_algebra(): u = icepack.interpolate(discretization, lambda x: x[0] - x[1]) v = icepack.interpolate(discretization, lambda x: x[0] * x[1]) w = icepack.interpolate(discretization, lambda x: x[0] - x[1] + x[0] * x[1]) assert icepack.dist(u + v, w) / icepack.norm(w) < 1.0e-8 w = icepack.interpolate(discretization, lambda x: x[0] - x[1] - x[0] * x[1]) assert icepack.dist(u - v, w) / icepack.norm(w) < 1.0e-8 w = icepack.interpolate(discretization, lambda x: 2 * x[0] * x[1]) assert icepack.dist(2.0 * v, w) / icepack.norm(w) < 1.0e-8