Skip to content

Commit

Permalink
Add arguments to preprocess script
Browse files Browse the repository at this point in the history
  • Loading branch information
danshapero committed Oct 2, 2023
1 parent efe09d7 commit 2cafea4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions demos/helheim/preprocess.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import subprocess
import numpy as np
import geojson
Expand All @@ -8,6 +9,12 @@
import icepack
import data

parser = argparse.ArgumentParser()
parser.add_argument("--num-levels", type=int, default=1)
parser.add_argument("--regularization", type=float, default=80.0)
parser.add_argument("--output")
args = parser.parse_args()

# Fetch the glacier outline, generate a mesh, and create a function space
outline_filename = icepack.datasets.fetch_outline("helheim")
with open(outline_filename, "r") as outline_file:
Expand All @@ -20,7 +27,9 @@
command = "gmsh -2 -v 0 -o helheim.msh helheim.geo"
subprocess.run(command.split())

mesh = firedrake.Mesh("helheim.msh")
coarse_mesh = firedrake.Mesh("helheim.msh")
mesh_hierarchy = firedrake.MeshHierarchy(coarse_mesh, args.num_levels)
mesh = mesh_hierarchy[-1]
V = firedrake.VectorFunctionSpace(mesh, "CG", 1)

# Read all the raw velocity data
Expand Down Expand Up @@ -73,7 +82,7 @@ def loss_functional(u):

def regularization(u):
Ω = Constant(area)
α = Constant(80.0) # TODO: tune this
α = Constant(args.regularization)
return 0.5 * α**2 / Ω * inner(grad(u), grad(u)) * dx

u_o = firedrake.Function(Δ)
Expand Down Expand Up @@ -105,6 +114,6 @@ def regularization(u):
firedrake.adjoint.pause_annotation()

# Save the results to disk
with firedrake.CheckpointFile("helheim.h5", "w") as chk:
with firedrake.CheckpointFile(args.output, "w") as chk:
chk.save_mesh(mesh)
chk.save_function(u, name="velocity")

0 comments on commit 2cafea4

Please sign in to comment.