Skip to content

Commit

Permalink
Use DG in gibbous demo
Browse files Browse the repository at this point in the history
  • Loading branch information
danshapero committed Jan 7, 2024
1 parent 16b4f4a commit c7ad7fd
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions demos/gibbous-ice-shelf/gibbous.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
NonlinearVariationalProblem,
NonlinearVariationalSolver,
)
import irksome
from icepack2 import model
from icepack2.constants import glen_flow_law as n

Expand Down Expand Up @@ -87,10 +88,11 @@

# Create some function spaces and some fields
cg = firedrake.FiniteElement("CG", "triangle", 1)
dg = firedrake.FiniteElement("DG", "triangle", 0)
Q = firedrake.FunctionSpace(mesh, cg)
dg0 = firedrake.FiniteElement("DG", "triangle", 0)
dg1 = firedrake.FiniteElement("DG", "triangle", 1)
Q = firedrake.FunctionSpace(mesh, dg1)
V = firedrake.VectorFunctionSpace(mesh, cg)
Σ = firedrake.TensorFunctionSpace(mesh, dg, symmetry=True)
Σ = firedrake.TensorFunctionSpace(mesh, dg0, symmetry=True)
Z = V * Σ

h0 = firedrake.interpolate(h_expr, Q)
Expand Down Expand Up @@ -190,16 +192,26 @@
diagnostic_solver.solve()

# Set up the prognostic problem and solver
h_n = h.copy(deepcopy=True)
φ = firedrake.TestFunction(Q)
prognostic_problem = model.mass_balance(
thickness=h,
velocity=u,
accumulation=firedrake.Constant(0.0),
thickness_inflow=h0,
test_function=firedrake.TestFunction(Q),
)
dt = firedrake.Constant(args.final_time / args.num_steps)
flux_cells = ((h - h_n) / dt * φ - inner(h * u, grad(φ))) * dx
ν = firedrake.FacetNormal(mesh)
flux_in = h0 * firedrake.min_value(0, inner(u, ν)) * φ * ds
flux_out = h * firedrake.max_value(0, inner(u, ν)) * φ * ds
G = flux_cells + flux_in + flux_out
prognostic_problem = NonlinearVariationalProblem(G, h)
prognostic_solver = NonlinearVariationalSolver(prognostic_problem)
t = firedrake.Constant(0.0)
method = irksome.BackwardEuler()
prognostic_params = {
"solver_parameters": {
"snes_type": "ksponly",
"ksp_type": "gmres",
"pc_type": "bjacobi",
},
}
prognostic_solver = irksome.TimeStepper(
prognostic_problem, method, t, dt, h, **prognostic_params
)

# Set up a calving mask
R = firedrake.Constant(60e3)
Expand All @@ -216,7 +228,7 @@
chk.save_function(h, name="thickness", idx=0)

for step in tqdm.trange(args.num_steps):
prognostic_solver.solve()
prognostic_solver.advance()

if args.calving_freq != 0.0:
if time_since_calving > args.calving_freq:
Expand All @@ -225,7 +237,6 @@
time_since_calving += float(dt)

h.interpolate(firedrake.max_value(0, h))
h_n.assign(h)

diagnostic_solver.solve()

Expand Down

0 comments on commit c7ad7fd

Please sign in to comment.