| 1 |
This demo illustrates how to: |
| 2 |
|
| 3 |
* Solve a nonlinear partial differential equation (in this case a nonlinear variant of Poisson's equation) |
| 4 |
* Create and apply Dirichlet boundary conditions |
| 5 |
* Define an :py:class:`Expression <dolfin.cpp.function.Expression>` |
| 6 |
* Define a :py:class:`FunctionSpace <dolfin.cpp.function.FunctionSpace>` |
| 7 |
* Create a :py:class:`SubDomain <dolfin.cpp.mesh.SubDomain>` |
| 8 |
|
| 9 |
The solution for :math:`u` in this demo will look as follows: |
| 10 |
|
| 11 |
.. image:: ../plot_u.png |
| 12 |
:scale: 75 % |
| 13 |
|
| 14 |
and the gradient of :math:`u` will look like this: |
| 15 |
|
| 16 |
.. image:: ../plot_u_gradient.png |
| 17 |
:scale: 75 % |
| 18 |
|
| 19 |
Equation and problem definition |
| 20 |
------------------------------- |
| 21 |
|
| 22 |
For a domain :math:`\Omega \subset \mathbb{R}^N` with boundary |
| 23 |
:math:`\partial \Omega = \Gamma_{D} \cup \Gamma_{N}`, we consider the |
| 24 |
following nonlinear Poisson equation with particular boundary |
| 25 |
conditions reads: |
| 26 |
|
| 27 |
.. math:: |
| 28 |
|
| 29 |
- \nabla\cdot((1 + u^2) \nabla u) &= f \quad {\rm in}\, \Omega,\\ |
| 30 |
u &= 1 \quad {\rm on}\, \Gamma_D,\\ |
| 31 |
\nabla u\cdot n &= 0 \quad {\rm on}\, \Gamma_N. |
| 32 |
|
| 33 |
Here :math:`f` is input data and :math:`n` denotes the outward |
| 34 |
directed boundary normal. The nonlinear variational form can be |
| 35 |
written in the following canonical form: find :math:`u \in V` such that |
| 36 |
|
| 37 |
.. math:: |
| 38 |
|
| 39 |
F(u;v)=0\quad \forall\,v\in\hat{V} |
| 40 |
|
| 41 |
Here :math:`F:V\times\hat{V}\rightarrow\mathbb{R}` is a semilinear |
| 42 |
form, linear in the argument subsequent to the semicolon, and |
| 43 |
:math:`V` is some suitable function space. The semilinear form is |
| 44 |
defined as follows: |
| 45 |
|
| 46 |
.. math:: |
| 47 |
|
| 48 |
F(u;v) = \int_\Omega (1 + u^2)\cdot\nabla u \cdot \nabla v - f v \,{\rm dx} = 0. |
| 49 |
|
| 50 |
To solve the nonlinear system :math:`b(U) = 0` by Newton's method we |
| 51 |
compute the Jacobian :math:`A = b'`, where :math:`U` is the |
| 52 |
coefficients of the linear combination in the finite element solution |
| 53 |
:math:`u_h = \sum_{j=1}^{N}U_j\phi_j, \; |
| 54 |
b:\mathbb{R}^N\rightarrow\mathbb{R}^N` and |
| 55 |
|
| 56 |
.. math:: |
| 57 |
|
| 58 |
b_i(U) = F(u_h;\hat{\phi}_i),\quad i = 1,2,\dotsc,N. |
| 59 |
|
| 60 |
Linearizing the semilinear form :math:`F` around :math:`u = u_h`, we obtain |
| 61 |
|
| 62 |
.. math:: |
| 63 |
|
| 64 |
F'(u_h;\delta u,v) = \int_\Omega [(2 \delta u\nabla u_h)\cdot\nabla v + ((1+u_h^2)\nabla\delta u)\nabla v] \,{\rm dx} |
| 65 |
|
| 66 |
We note that for each fixed :math:`u_h`, :math:`a = F'(u_h;\,\cdot\,,\,\cdot\,)` is a bilinear form and :math:`L = F(u_h;\,\cdot\,,\,\cdot\,)` is a linear form. In each Newton iteration, we thus solve a linear variational problem of the canonical form: |
| 67 |
find :math:`\delta u \in V_{h,0}` such that |
| 68 |
|
| 69 |
.. math:: |
| 70 |
|
| 71 |
|
| 72 |
F'(u_h;\delta u,v) = -F(u_h;v)\quad\forall\,v\in\hat{V}_h. |
| 73 |
|
| 74 |
|
| 75 |
In this demo, we shall consider the following definitions of the input function, the domain, and the boundaries: |
| 76 |
|
| 77 |
* :math:`\Omega = [0,1] \times [0,1]\,\,\,` (a unit square) |
| 78 |
* :math:`\Gamma_{D} = \{(1, y) \subset \partial \Omega\}\,\,\,` (Dirichlet boundary) |
| 79 |
* :math:`\Gamma_{N} = \{(x, 0) \cup (x, 1) \cup (0, y) \subset \partial \Omega\}\,\,\,` (Neumann boundary) |
| 80 |
* :math:`f(x, y) = x\sin(y)\,\,\,` (source term) |