User talk:Egm6936.s11/FENICS/Python

=Derivations of Problems= This article lacks derivations of many problems as of now. Here, I'll work to derive the problems before transferring them to the main article.

Poisson's Equation
We start with Poisson's Equation.
 * {| style="width:100%" border="0"

$$ \displaystyle \nabla^2 u = f $$ (PE.1)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

We then multiply Eq. PE.1 by a test function and integrate over space.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \left(\nabla^2 u\right) v \, dx = \int_\Omega f v \, dx $$ (PE.2)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

We can lower the order of derivative in the left hand side of Eq. PE.2 by making use of Green's First Identity to integrate by parts.
 * {| style="width:100%" border="0"

$$ \displaystyle \oint_{\partial \Omega} \left(\nabla u \cdot \mathbf{n}\right) v \, ds - \int_\Omega \left(\nabla u\right) \cdot \left(\nabla v\right) \, dx = \int_\Omega f v \, dx $$ (PE.3)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

It is common to define Neumann boundary conditions for flow of a property over a boundary. This changes the normal derivative of the property to a function of position on the boundary.
 * {| style="width:100%" border="0"

$$ \displaystyle \nabla u \cdot \mathbf{n} = g $$ (PE.4)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

Substituting in Eqn. PE.4 to Eqn. PE.3, we obtain our final form, split into a bilinear left hand side, and a linear right hand side.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \left(\nabla u\right) \cdot \left(\nabla v\right) \, dx = \oint_{\partial \Omega} g v \, ds - \int_\Omega f v \, dx $$ (PE.5)
 * style="width:92%; padding:10px; border:2px solid #8888aa" |
 * style="width:92%; padding:10px; border:2px solid #8888aa" |
 * 
 * }

Two-Dimensional Problem
The problem is as follows:
 * $$u = u(\mathbf{x}) \; \forall \; x_i \in [0, 1], \; i = 0, 1$$
 * $$\mathbf{x}_s = \; <0.5, 0.5>$$
 * $$f = 10 \exp\left(-\frac{\left(\mathbf{x} - \mathbf{x}_s\right)^2}{0.02}\right)$$
 * $$g = \sin\left(5 x_0\right) \; \forall \; \mathbf{x} \in \partial \Omega$$
 * $$u = 0 \; \forall \; x_0 = 0, 1$$

Convection-Diffusion Equation
We start with the general form of the Convection-Diffusion Equation.
 * {| style="width:100%" border="0"

$$ \displaystyle \nabla \cdot \left(\nu \nabla u\right) - \nabla \cdot \left(\mathbf{v} u\right) + f = \frac{\partial u}{\partial t} $$ (CD.1)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

We will be working with a steady-state system, so we can set the right side of Eq. CD.1 equal to 0.
 * {| style="width:100%" border="0"

$$ \displaystyle \nabla \cdot \left(\nu \nabla u\right) - \nabla \cdot \left(\mathbf{v} u\right) + f = 0 $$ (CD.2)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

For this problem, we will make the following assumptions:
 * constant diffusivity
 * constant flow

These assumptions allow us to pull out our velocity and diffusivity coefficients from the derivatives in Eq. CD.2.
 * {| style="width:100%" border="0"

$$ \displaystyle \nu \nabla^2 u - \mathbf{v} \cdot \nabla u + f = 0 $$ (CD.3)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

Now, we multiply Eq. CD.3 by a test function and integrate over space.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \left(\nu \nabla^2 u - \mathbf{v} \cdot \nabla u + f\right) v \, dx = 0 $$ (CD.4)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

We can lower the order of derivative in the first term of Eq. CD.4 by making use of Green's First Identity to integrate by parts.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \nu \nabla u \cdot \nabla v + \left(\mathbf{v} \cdot \nabla u - f\right) v \, dx - \oint_{\partial\Omega} \nu \left( \nabla u \cdot \mathbf{n}\right) v \, ds= 0 $$ (CD.5)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

It is common to define Neumann boundary conditions for flow of a property over a boundary. This changes the normal derivative of the property to a function of position on the boundary.
 * {| style="width:100%" border="0"

$$ \displaystyle \nabla u \cdot \mathbf{n} = g $$ (CD.6)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

Substituting in Eq. CD.6, we can now split Eq. CD.5 into a bilinear left hand side, and linear right hand side.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \nu \nabla u \cdot \nabla v + \left(\mathbf{v} \cdot \nabla u\right) v \, dx = \int_\Omega f v \, dx + \oint_{\partial\Omega} \nu g v \, ds $$ (CD.7)
 * style="width:92%; padding:10px; border:2px solid #8888aa" |
 * style="width:92%; padding:10px; border:2px solid #8888aa" |
 * 
 * }

One-Dimensional Problem
The problem is as follows:
 * $$u = u(x) \; \forall \; x \in [0, 1]$$
 * $$u(0) = 0$$
 * $$u(1) = 1$$
 * $$\mathbf{v} = 1$$
 * $$\nu = 1$$
 * $$f = 0$$
 * $$g = 0$$

Burgers' Equation
We start with the general form of Burgers' Equation.
 * {| style="width:100%" border="0"

$$ \displaystyle \frac{\partial \mathbf{u}}{\partial t} + \mathbf{u} \cdot \nabla \mathbf{u} - \nu \Delta \mathbf{u} = \mathbf{f} $$ (BE.1)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

Steady Flow
First, we will develop a solution for steady flow. We therefore can set the time derivative of velocity in Eqn. BE.1 equal to 0.
 * {| style="width:100%" border="0"

$$ \displaystyle \mathbf{u} \cdot \nabla \mathbf{u} - \nu \nabla^2 \mathbf{u} = \mathbf{f} $$ (BE.2)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

Next, we take the dot product of both sides of Eqn. BE.2 with a test function, and integrate over space.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \left(\mathbf{u} \cdot \nabla \mathbf{u} - \nu \nabla^2 \mathbf{u}\right) \cdot \mathbf{v} \, dx = \int_\Omega \mathbf{f} \cdot \mathbf{v} \, dx $$ (BE.3)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

We desire to simplify to first derivatives of velocity. To that end, we first note the following identity applicable in Cartesian coordinates.
 * {| style="width:100%" border="0"

$$ \displaystyle \left(\nabla^2 \mathbf{A}\right)_i = \nabla^2 A_i $$ (BE.4)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

Using Eqn. BE.4, we notice that we can use Green's First Identity to integrate by parts.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \left(\nabla^2 \mathbf{u}\right) \cdot \mathbf{v} \, dx = \int_\Omega v_i \nabla^2 u_i \, dx = \oint_{\partial \Omega} v_i \frac{\partial u_i}{\partial x_j} n_j \, ds \; - \int_\Omega \frac{\partial u_i}{\partial x_j} \frac{\partial v_i}{\partial x_j} dx = \oint_{\partial \Omega} \mathbf{v} \cdot \left(\nabla \mathbf{u} \right) \cdot \mathbf{n} \, ds \; - \int_\Omega \left(\nabla \mathbf{u}\right) : \left(\nabla \mathbf{v}\right) \, dx $$ (BE.5)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

Now armed with Eqn. BE.5, we modify Eqn. BE.3 to only contain first derivatives of velocity.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \mathbf{u} \cdot \left(\nabla \mathbf{u}\right) \cdot \mathbf{v} + \nu \left(\nabla \mathbf{u}\right) : \left(\nabla \mathbf{v}\right) - \mathbf{f} \cdot \mathbf{v} \, dx - \oint_{\partial \Omega} \nu \mathbf{v} \cdot \left(\nabla \mathbf{u}\right) \cdot \mathbf{n} \, ds = 0 $$ (BE.6)
 * style="width:92%; padding:10px; border:2px solid #8888aa" |
 * style="width:92%; padding:10px; border:2px solid #8888aa" |
 * <p style="text-align:right">
 * }

Unsteady Flow
For the case of unsteady flow, we need to introduce a time-discretization scheme. First, we introduce a finite difference scheme obtained from the first order Taylor expansion of the partial derivative.
 * {| style="width:100%" border="0"

$$ \displaystyle \frac{\partial \mathbf{u}}{\partial t} \approx \frac{\mathbf{u}_{n} - \mathbf{u}_{n-1}}{dt} $$ (BE.7)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

We can then substitute Eqn. BE.7 into Eqn. BE.1.
 * {| style="width:100%" border="0"

$$ \displaystyle \frac{\mathbf{u}_{n} - \mathbf{u}_{n-1}}{dt} + \mathbf{u}_n \cdot \nabla \mathbf{u}_n - \nu \Delta \mathbf{u}_n = \mathbf{f} $$ (BE.8)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

Following the steps outlined in the last section from Eqn. BE.3 through Eqn. BE.6, we obtain the following time-discretized form from Eqn. BE.8.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \frac{\mathbf{u}_{n} - \mathbf{u}_{n-1}}{dt} \cdot \mathbf{v} + \mathbf{u}_n \cdot \left(\nabla \mathbf{u}_n\right) \cdot \mathbf{v} + \nu \left(\nabla \mathbf{u}_n\right) : \left(\nabla \mathbf{v}\right) - \mathbf{f} \cdot \mathbf{v} \, dx - \oint_{\partial \Omega} \nu \mathbf{v} \cdot \left(\nabla \mathbf{u}_n\right) \cdot \mathbf{n} \, ds = 0 $$ (BE.9)
 * style="width:92%; padding:10px; border:2px solid #8888aa" |
 * style="width:92%; padding:10px; border:2px solid #8888aa" |
 * <p style="text-align:right">
 * }

Navier-Stokes Equation
The unitless form of the incompressible Navier-Stokes Equation :
 * {| style="width:100%" border="0"

$$ \displaystyle \frac{\partial \mathbf{u}}{\partial t} + \mathbf{u} \cdot \nabla \mathbf{u} - \frac{1}{Re} \nabla^2 \mathbf{u} + \nabla p = \mathbf{f} $$ (NS.1a)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

The unitless form of the incompressible continuity equation :
 * {| style="width:100%" border="0"

$$ \displaystyle \nabla \cdot \mathbf{u} = 0 $$ (NS.1b)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

Steady Flow
First, we will develop a solution for steady flow. We therefore can set the time derivative of velocity in Eqn. NS.1a equal to 0.
 * {| style="width:100%" border="0"

$$ \displaystyle \mathbf{u} \cdot \nabla \mathbf{u} - \frac{1}{Re} \nabla^2 \mathbf{u} + \nabla p = \mathbf{f} $$ (NS.2)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

Next, we take the dot product of both sides of Eqn. BE.2 with a test function, and integrate over space.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \left(\mathbf{u} \cdot \nabla \mathbf{u} - \frac{1}{Re} \nabla^2 \mathbf{u} + \nabla p\right) \cdot \mathbf{v_u} \, dx = \int_\Omega \mathbf{f} \cdot \mathbf{v_u} \, dx $$ (NS.3)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

We desire to simplify to first derivatives of velocity. To that end, we first note the following identity applicable in Cartesian coordinates.
 * {| style="width:100%" border="0"

$$ \displaystyle \left(\nabla^2 \mathbf{A}\right)_i = \nabla^2 A_i $$ (NS.4)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

Using Eqn. NS.4, we notice that we can use Green's First Identity to integrate by parts.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \left(\nabla^2 \mathbf{u}\right) \cdot \mathbf{v_u} \, dx = \int_\Omega {v_u}_i \nabla^2 u_i \, dx = \oint_{\partial \Omega} {v_u}_i \frac{\partial u_i}{\partial x_j} n_j \, ds \; - \int_\Omega \frac{\partial u_i}{\partial x_j} \frac{\partial {v_u}_i}{\partial x_j} dx = \oint_{\partial \Omega} \mathbf{v_u} \cdot \left(\nabla \mathbf{u} \right) \cdot \mathbf{n} \, ds \; - \int_\Omega \left(\nabla \mathbf{u}\right) : \left(\nabla \mathbf{v_u}\right) \, dx $$ (NS.5)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

Another term of Eqn. NS.3 we can lower the derivative on is that containing the gradient of pressure. First, we integrate the term by parts.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \nabla p \cdot \mathbf{v_u} \; dx = \int_\Omega \nabla \cdot \left(p \mathbf{v_u}\right) - p \nabla \cdot \mathbf{v_u}\; dx $$ (NS.6)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

Then, we make use of the Divergence Theorem to eliminate the derivative in the first term of the right hand side of Eqn. NS.6.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \nabla p \cdot \mathbf{v_u} \; dx = \oint_{\partial \Omega} p \mathbf{v_u} \cdot \mathbf{n} \, ds - \int_\Omega p \nabla \cdot \mathbf{v_u}\; dx $$ (NS.7)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

Applying the results of Eqns. NS.5 and NS.7 to Eqn. NS.3, we obtain an expression involving only first derivatives of velocity and no derivatives of pressure.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \mathbf{u} \cdot \nabla \mathbf{u} \cdot \mathbf{v_u} + \frac{1}{Re} \left(\nabla \mathbf{u}\right) : \left(\nabla \mathbf{v_u}\right) \, - \, p \nabla \cdot \mathbf{v_u} - \mathbf{f} \cdot \mathbf{v_u} \; dx + \oint_{\partial \Omega} p \mathbf{v_u} \cdot \mathbf{n} - \frac{1}{Re} \mathbf{v_u} \cdot \left(\nabla \mathbf{u} \right) \cdot \mathbf{n} \, ds = 0 $$ (NS.8)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

Now, we multiply Eqn. NS.1b by a test function and integrate over space. The unitless form of the incompressible continuity equation :
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \left(\nabla \cdot \mathbf{u}\right) v_p \, dx = 0 $$ (NS.9)
 * style="width:95%" |
 * style="width:95%" |
 * <p style="text-align:right">
 * }

And by summing Eqns. NS.8 and NS.9, we obtain our final form.
 * {| style="width:100%" border="0"

$$ \displaystyle \int_\Omega \mathbf{u} \cdot \nabla \mathbf{u} \cdot \mathbf{v_u} + \frac{1}{Re} \left(\nabla \mathbf{u}\right) : \left(\nabla \mathbf{v_u}\right) \, - \, p \nabla \cdot \mathbf{v_u} - \mathbf{f} \cdot \mathbf{v_u} + \left(\nabla \cdot \mathbf{u}\right) v_p \; dx + \oint_{\partial \Omega} p \mathbf{v_u} \cdot \mathbf{n} - \frac{1}{Re} \mathbf{v_u} \cdot \left(\nabla \mathbf{u} \right) \cdot \mathbf{n} \, ds = 0 $$ (NS.10)
 * style="width:92%; padding:10px; border:2px solid #8888aa" |
 * style="width:92%; padding:10px; border:2px solid #8888aa" |
 * <p style="text-align:right">
 * }