Skip to content

Commit

Permalink
Cut unnecessary initial solve
Browse files Browse the repository at this point in the history
  • Loading branch information
danshapero committed Oct 9, 2023
1 parent 4169dc7 commit 12bca93
Showing 1 changed file with 31 additions and 41 deletions.
72 changes: 31 additions & 41 deletions demos/helheim/helheim.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
" glen_flow_law as n,\n",
" weertman_sliding_law as m,\n",
")\n",
"import data"
"import data\n",
"from dualform import ice_stream"
]
},
{
Expand Down Expand Up @@ -280,16 +281,7 @@
"id": "05965a2c-91f2-4931-9fd6-9e968215007e",
"metadata": {},
"outputs": [],
"source": [
"from dualform import ice_stream\n",
"\n",
"fns = [\n",
" viscous_power,\n",
" friction_power,\n",
" ice_stream.boundary,\n",
" ice_stream.constraint,\n",
"]"
]
"source": []
},
{
"cell_type": "code",
Expand Down Expand Up @@ -320,43 +312,26 @@
" \"friction_yield_stress\": τ_f,\n",
"}\n",
"\n",
"boundary_ids = {\"outflow_ids\": outflow_ids}\n",
"\n",
"L = sum(fn(**fields, **params, **boundary_ids) for fn in fns)\n",
"F = firedrake.derivative(L, z)\n",
"J_1 = firedrake.derivative(F, z)\n",
"\n",
"sparams = {\n",
" \"solver_parameters\": {\n",
" \"snes_max_it\": 200,\n",
" \"snes_monitor\": None,\n",
" #\"snes_linesearch_monitor\": None,\n",
" \"snes_rtol\": 5e-7,\n",
" \"snes_type\": \"newtontr\",\n",
" #\"snes_linesearch_type\": \"bt\",\n",
" #\"snes_linesearch_max_it\": 8,\n",
" \"ksp_type\": \"gmres\",\n",
" \"pc_type\": \"lu\",\n",
" \"pc_factor_mat_solver_type\": \"mumps\",\n",
" },\n",
"}\n",
"\n",
"problem = firedrake.NonlinearVariationalProblem(F, z, bc)\n",
"solver = firedrake.NonlinearVariationalSolver(problem, **sparams)\n",
"solver.solve()"
"boundary_ids = {\"outflow_ids\": outflow_ids}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9206ddde-526f-4f46-82e4-c10e411db62f",
"id": "ca6907fd-959b-4f0d-9e98-d9cbcdc019a5",
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"ax.set_aspect(\"equal\")\n",
"colors = firedrake.tripcolor(z.sub(0), axes=ax)\n",
"fig.colorbar(colors);"
"fns = [\n",
" viscous_power,\n",
" friction_power,\n",
" ice_stream.boundary,\n",
" ice_stream.constraint,\n",
"]\n",
"\n",
"L = sum(fn(**fields, **params, **boundary_ids) for fn in fns)\n",
"F = firedrake.derivative(L, z)\n",
"J_1 = firedrake.derivative(F, z)"
]
},
{
Expand All @@ -382,7 +357,22 @@
"F = firedrake.derivative(L, z)\n",
"J = firedrake.derivative(F, z)\n",
"\n",
"β = firedrake.Constant(1e-3)\n",
"sparams = {\n",
" \"solver_parameters\": {\n",
" \"snes_max_it\": 200,\n",
" \"snes_monitor\": None,\n",
" #\"snes_linesearch_monitor\": None,\n",
" \"snes_rtol\": 5e-3,\n",
" \"snes_type\": \"newtontr\",\n",
" #\"snes_linesearch_type\": \"bt\",\n",
" #\"snes_linesearch_max_it\": 8,\n",
" \"ksp_type\": \"gmres\",\n",
" \"pc_type\": \"lu\",\n",
" \"pc_factor_mat_solver_type\": \"mumps\",\n",
" },\n",
"}\n",
"\n",
"β = firedrake.Constant(1e-4)\n",
"problem = firedrake.NonlinearVariationalProblem(F, z, bc, J=J + β * J_1)\n",
"solver = firedrake.NonlinearVariationalSolver(problem, **sparams)\n",
"solver.solve()"
Expand Down

0 comments on commit 12bca93

Please sign in to comment.