From 4efc5064b7dfe510f6529f23bf477a3d8c11678a Mon Sep 17 00:00:00 2001 From: jorgensd Date: Sat, 9 Aug 2025 10:46:10 +0200 Subject: [PATCH] Resolve https://github.com/jorgensd/dolfinx-tutorial/issues/117 --- chapter2/hyperelasticity.ipynb | 12 +++++++++--- chapter2/hyperelasticity.py | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/chapter2/hyperelasticity.ipynb b/chapter2/hyperelasticity.ipynb index 8666c49f..c1a5b1da 100644 --- a/chapter2/hyperelasticity.ipynb +++ b/chapter2/hyperelasticity.ipynb @@ -323,7 +323,7 @@ "id": "28", "metadata": {}, "source": [ - "Define form F (we want to find u such that F(u) = 0)" + "Define the residual of the equation (we want to find u such that residual(u) = 0)" ] }, { @@ -333,7 +333,9 @@ "metadata": {}, "outputs": [], "source": [ - "F = ufl.inner(ufl.grad(v), P) * dx - ufl.inner(v, B) * dx - ufl.inner(v, T) * ds(2)" + "residual = (\n", + " ufl.inner(ufl.grad(v), P) * dx - ufl.inner(v, B) * dx - ufl.inner(v, T) * ds(2)\n", + ")" ] }, { @@ -364,7 +366,11 @@ " \"pc_factor_mat_solver_type\": \"mumps\",\n", "}\n", "problem = NonlinearProblem(\n", - " F, u, bcs=bcs, petsc_options=petsc_options, petsc_options_prefix=\"hyperelasticity\"\n", + " residual,\n", + " u,\n", + " bcs=bcs,\n", + " petsc_options=petsc_options,\n", + " petsc_options_prefix=\"hyperelasticity\",\n", ")" ] }, diff --git a/chapter2/hyperelasticity.py b/chapter2/hyperelasticity.py index 18839310..14394cd2 100644 --- a/chapter2/hyperelasticity.py +++ b/chapter2/hyperelasticity.py @@ -143,9 +143,11 @@ def right(x): ds = ufl.Measure("ds", domain=domain, subdomain_data=facet_tag, metadata=metadata) dx = ufl.Measure("dx", domain=domain, metadata=metadata) -# Define form F (we want to find u such that F(u) = 0) +# Define the residual of the equation (we want to find u such that residual(u) = 0) -F = ufl.inner(ufl.grad(v), P) * dx - ufl.inner(v, B) * dx - ufl.inner(v, T) * ds(2) +residual = ( + ufl.inner(ufl.grad(v), P) * dx - ufl.inner(v, B) * dx - ufl.inner(v, T) * ds(2) +) # As the varitional form is non-linear and written on residual form, # we use the non-linear problem class from DOLFINx to set up required structures to use a Newton solver. @@ -162,7 +164,11 @@ def right(x): "pc_factor_mat_solver_type": "mumps", } problem = NonlinearProblem( - F, u, bcs=bcs, petsc_options=petsc_options, petsc_options_prefix="hyperelasticity" + residual, + u, + bcs=bcs, + petsc_options=petsc_options, + petsc_options_prefix="hyperelasticity", ) # We create a function to plot the solution at each time step.