Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions chapter2/hyperelasticity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
},
{
Expand All @@ -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",
")"
]
},
{
Expand Down Expand Up @@ -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",
")"
]
},
Expand Down
12 changes: 9 additions & 3 deletions chapter2/hyperelasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down