From 2cafea4fc09169515459fb2785ab2b17ef1a92eb Mon Sep 17 00:00:00 2001 From: Daniel Shapero Date: Mon, 2 Oct 2023 13:23:21 -0700 Subject: [PATCH] Add arguments to preprocess script --- demos/helheim/preprocess.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/demos/helheim/preprocess.py b/demos/helheim/preprocess.py index f4b690f..8d6d7da 100644 --- a/demos/helheim/preprocess.py +++ b/demos/helheim/preprocess.py @@ -1,3 +1,4 @@ +import argparse import subprocess import numpy as np import geojson @@ -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: @@ -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 @@ -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(Δ) @@ -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")