|
8 | 8 | "# Weak imposition of Dirichlet conditions for the Poisson problem\n", |
9 | 9 | "Author: Jørgen S. Dokken\n", |
10 | 10 | "\n", |
11 | | - "In this section, we will go through how to solve the Poisson problem from the [Fundamentals](./fundamentals_code.ipynb) tutorial using Nitsche's method {cite}`Nitsche1971`.\n", |
12 | | - "The idea of weak imposition is that we add additional terms to the variational formulation to impose the boundary condition, instead of modifying the matrix system using strong imposition (lifting).\n", |
| 11 | + "In this section, we will go through how to solve the Poisson problem from the\n", |
| 12 | + "[Fundamentals](./fundamentals_code.ipynb) tutorial using Nitsche's method {cite}`nitsche-Nitsche1971`.\n", |
| 13 | + "The idea of weak imposition is that we add additional terms to the variational formulation to\n", |
| 14 | + "impose the boundary condition, instead of modifying the matrix system using strong imposition (lifting).\n", |
13 | 15 | "\n", |
14 | 16 | "We start by importing the required modules and creating the mesh and function space for our solution" |
15 | 17 | ] |
|
48 | 50 | "id": "2", |
49 | 51 | "metadata": {}, |
50 | 52 | "source": [ |
51 | | - "Next, we create a function containing the exact solution (which will also be used in the Dirichlet boundary condition) and the corresponding source function for the right hand side. Note that we use `ufl.SpatialCoordinate` to define the exact solution, which in turn is interpolated into `uD` and used to create the source function `f`." |
| 53 | + "Next, we create a function containing the exact solution (which will also be used in the Dirichlet boundary condition)\n", |
| 54 | + "and the corresponding source function for the right hand side. Note that we use {py:class}`ufl.SpatialCoordinate`\n", |
| 55 | + "to define the exact solution, which in turn is interpolated into {py:class}`uD<dolfinx.fem.Function>`\n", |
| 56 | + "by wrapping the {py:class}`ufl-expression<ufl.core.expr.Expr>` as a {py:class}`dolfinx.fem.Expression`.\n", |
| 57 | + "For the source function, we use the symbolic differentiation capabilities of UFL to\n", |
| 58 | + "compute the negative Laplacian of the exact solution, which we can use directly in the variational formulation." |
52 | 59 | ] |
53 | 60 | }, |
54 | 61 | { |
|
72 | 79 | "source": [ |
73 | 80 | "As opposed to the first tutorial, we now have to have another look at the variational form.\n", |
74 | 81 | "We start by integrating the problem by parts, to obtain\n", |
| 82 | + "\n", |
| 83 | + "$$\n", |
75 | 84 | "\\begin{align}\n", |
76 | | - " \\int_{\\Omega} \\nabla u \\cdot \\nabla v~\\mathrm{d}x - \\int_{\\partial\\Omega}\\nabla u \\cdot n v~\\mathrm{d}s = \\int_{\\Omega} f v~\\mathrm{d}x.\n", |
| 85 | + " \\int_{\\Omega} \\nabla u \\cdot \\nabla v~\\mathrm{d}x\n", |
| 86 | + " - \\int_{\\partial\\Omega}\\nabla u \\cdot n v~\\mathrm{d}s = \\int_{\\Omega} f v~\\mathrm{d}x.\n", |
77 | 87 | "\\end{align}\n", |
| 88 | + "$$\n", |
| 89 | + "\n", |
78 | 90 | "As we are not using strong enforcement, we do not set the trace of the test function to $0$ on the outer boundary.\n", |
79 | 91 | "Instead, we add the following two terms to the variational formulation\n", |
| 92 | + "\n", |
| 93 | + "$$\n", |
80 | 94 | "\\begin{align}\n", |
81 | | - " -\\int_{\\partial\\Omega} \\nabla v \\cdot n (u-u_D)~\\mathrm{d}s + \\frac{\\alpha}{h} \\int_{\\partial\\Omega} (u-u_D)v~\\mathrm{d}s.\n", |
| 95 | + " -\\int_{\\partial\\Omega} \\nabla v \\cdot n (u-u_D)~\\mathrm{d}s\n", |
| 96 | + " + \\frac{\\alpha}{h} \\int_{\\partial\\Omega} (u-u_D)v~\\mathrm{d}s.\n", |
82 | 97 | "\\end{align}\n", |
| 98 | + "$$\n", |
| 99 | + "\n", |
83 | 100 | "where the first term enforces symmetry to the bilinear form, while the latter term enforces coercivity.\n", |
84 | 101 | "$u_D$ is the known Dirichlet condition, and $h$ is the diameter of the circumscribed sphere of the mesh element.\n", |
85 | 102 | "We create bilinear and linear form, $a$ and $L$\n", |
| 103 | + "\n", |
| 104 | + "$$\n", |
86 | 105 | "\\begin{align}\n", |
87 | 106 | " a(u, v) &= \\int_{\\Omega} \\nabla u \\cdot \\nabla v~\\mathrm{d}x + \\int_{\\partial\\Omega}-(n \\cdot\\nabla u) v - (n \\cdot \\nabla v) u + \\frac{\\alpha}{h} uv~\\mathrm{d}s,\\\\\n", |
88 | 107 | " L(v) &= \\int_{\\Omega} fv~\\mathrm{d}x + \\int_{\\partial\\Omega} -(n \\cdot \\nabla v) u_D + \\frac{\\alpha}{h} u_Dv~\\mathrm{d}s\n", |
89 | | - "\\end{align}" |
| 108 | + "\\end{align}\n", |
| 109 | + "$$" |
90 | 110 | ] |
91 | 111 | }, |
92 | 112 | { |
|
112 | 132 | "id": "6", |
113 | 133 | "metadata": {}, |
114 | 134 | "source": [ |
115 | | - "As we now have the variational form, we can solve the linear problem" |
| 135 | + "As we now have the variational form, we can solve the arising\n", |
| 136 | + "{py:class}`linear problem<dolfinx.fem.petsc.LinearProblem>`" |
116 | 137 | ] |
117 | 138 | }, |
118 | 139 | { |
|
176 | 197 | "id": "12", |
177 | 198 | "metadata": {}, |
178 | 199 | "source": [ |
179 | | - "We observe that as we weakly impose the boundary condition, we no longer fullfill the equation to machine precision at the mesh vertices. We also plot the solution using `pyvista`" |
| 200 | + "We observe that as we weakly impose the boundary condition,\n", |
| 201 | + "we no longer fullfill the equation to machine precision at the mesh vertices.\n", |
| 202 | + "We also plot the solution using {py:mod}`pyvista`" |
180 | 203 | ] |
181 | 204 | }, |
182 | 205 | { |
|
206 | 229 | "metadata": {}, |
207 | 230 | "source": [ |
208 | 231 | "```{bibliography}\n", |
209 | | - " :filter: cited and ({\"chapter1/nitsche\"} >= docnames)\n", |
| 232 | + " :filter: cited\n", |
| 233 | + " :labelprefix:\n", |
| 234 | + " :keyprefix: nitsche-\n", |
210 | 235 | "```" |
211 | 236 | ] |
212 | 237 | } |
|
0 commit comments