Esempio n. 1
0
def test_reading():
    mesh = icepack.read_msh("tests/rectangle.msh")
    assert mesh.n_active_cells() == 16
    assert mesh.n_vertices() == 25

    boundary_ids = mesh.get_boundary_ids()
    assert len(boundary_ids) == 2
    assert boundary_ids.count(1) == 1
    assert boundary_ids.count(2) == 1
#!/usr/bin/env python3

import numpy as np
import matplotlib.pyplot as plt
import icepack, icepack.plot

# 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.
Esempio n. 3
0
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
Esempio n. 4
0
import icepack
import matplotlib.pyplot as plt
import numpy as np

# First we'll call a helper script to generate a simple example mesh. This is
# in the script `make_mesh.py` in this folder.
import make_mesh
length, width = 20.0e3, 20.0e3
make_mesh.main(length, width, "rectangle.geo")

# This function reads in an unstructured mesh from a file stored in the gmsh
# `.msh` format.
mesh = icepack.read_msh("rectangle.msh")

# The `mesh` object is a python wrapper around a data structure from the
# library deal.II, which provides all of the underlying finite element
# modelling tools that icepack is built on.
print("Data type of mesh objects: {}".format(type(mesh)))

# Mesh objects have several operations for querying their size and contents.
print("Number of vertices: {}".format(mesh.n_vertices()))
print("Number of cells:    {}".format(mesh.n_active_cells()))

# We can access the vertex locations too. We can make a scatter plot of all the
# vertex locations as a sanity check.
X = [x[0] for x in mesh.get_vertices()]
Y = [x[1] for x in mesh.get_vertices()]

fig, ax = plt.subplots()
ax.scatter(X, Y)
Esempio n. 5
0
def test_refining():
    mesh = icepack.read_msh("tests/rectangle.msh")
    num_cells = mesh.n_active_cells()
    mesh.refine_global(1)
    assert mesh.n_active_cells() == 4 * num_cells
Esempio n. 6
0
#!/usr/bin/env python3

import numpy as np
import matplotlib.pyplot as plt
import icepack, icepack.plot

# 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.