Skip to content

Commit

Permalink
LETS GOOOOOOOOO
Browse files Browse the repository at this point in the history
  • Loading branch information
danshapero committed Oct 16, 2023
1 parent 2af389e commit c2c2b13
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions demos/larsen/simulate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import subprocess
import numpy as np
import geojson
import xarray
Expand All @@ -11,7 +12,7 @@
parser = argparse.ArgumentParser()
parser.add_argument("--input", default="larsen-extrapolated.h5")
parser.add_argument("--degree", type=int, default=1)
parser.add_argument("--output")
parser.add_argument("--output", default="larsen-simulation.h5")
args = parser.parse_args()

# Read in the starting data
Expand Down Expand Up @@ -132,22 +133,45 @@
h_problem = firedrake.NonlinearVariationalProblem(G, h)
h_solver = firedrake.NonlinearVariationalSolver(h_problem)

for step in range(num_steps):
h_solver.solve()
h.interpolate(firedrake.max_value(0, h))
# Load in the outline of Larsen in 2019
outline_filename = icepack.datasets.fetch_outline("larsen-2019")
with open(outline_filename, "r") as outline_file:
outline = geojson.load(outline_file)

geometry = icepack.meshing.collection_to_geo(outline)
with open("larsen-2019.geo", "w") as geometry_file:
geometry_file.write(geometry.get_code())

command = "gmsh -2 -v 0 -o larsen-2019.msh larsen-2019.geo"
subprocess.run(command.split())

# Create a mask to remove ice where the calving event occurred
mesh_2019 = firedrake.Mesh("larsen-2019.msh")
Q_2019 = firedrake.FunctionSpace(mesh_2019, "CG", 1)
μ = firedrake.Function(Q_2019)
μ.assign(Constant(1.0))
μ = firedrake.project(μ, Q)
μ.interpolate(firedrake.max_value(0, firedrake.min_value(1, μ)))

h_c = firedrake.Constant(1.0)
with firedrake.CheckpointFile(args.output, "w") as chk:
chk.save_function(h, name="thickness", idx=0)

for step in range(num_steps):
h_solver.solve()
h.interpolate(firedrake.conditional(h < h_c, 0, h))
h_n.assign(h)
u_solver.solve()
chk.save_function(h, name="thickness", idx=step + 1)

print("IT CALVING NOW")
h.interpolate(μ * h)
h_n.assign(h)
u_solver.solve()

import matplotlib.pyplot as plt
fig, axes = plt.subplots()
axes.set_aspect("equal")
colors = firedrake.tripcolor(h, axes=axes)
fig.colorbar(colors)
plt.show()

fig, axes = plt.subplots()
axes.set_aspect("equal")
δh = firedrake.interpolate(h - h0, Q)
colors = firedrake.tripcolor(δh, vmin=-50, vmax=+50, cmap="RdBu_r", axes=axes)
fig.colorbar(colors)
plt.show()
for step in range(num_steps):
h_solver.solve()
h.interpolate(firedrake.conditional(h < h_c, 0, h))
h_n.assign(h)
u_solver.solve()
chk.save_function(h, name="thickness", idx=step + num_steps + 1)

0 comments on commit c2c2b13

Please sign in to comment.