User:Egm6936.s11/FENICS/Python

 give a motivation for this article, i.e., explain why you wanted to write a separate article than Rodbourn's C++ FEniCS Tutorial. perhaps a gentler introduction, without a lot of assumed knowledge (e.g., finite element method, etc.). Egm6322.s12 (talk) 14:32, 20 July 2012 (UTC)

This tutorial demonstrates the solution of various PDEs of increasing complexity using FEniCS, starting with Poisson's Equation and incrementally building up to the solution of the Incompressible Navier-Stokes Equations.

 Kyle, please work on the article to remove the assumption of "some knowledge of Python", i.e., explain python for dummies. Egm6321.f12 (talk) 14:08, 27 July 2012 (UTC)

It is assumed the reader has some knowledge of variational calculus (to obtain the weak form of a problem), but is more beginner-friendly than Rodbourn's C++ FEniCS Tutorial.

This tutorial requires some knowledge of Python, see Introduction to Python for FEniCS for a brief introduction.

 point out specifically the features that made (or will make) this article beginner-friendlier than Rodbourn's C++ FEniCS Tutorial, and don't hesitate to improve the latter article as well. Egm6321.f12 (talk) 14:08, 27 July 2012 (UTC)

Useful Resources:
 * Rodbourn's C++ FEniCS Tutorial
 * tclamb's Python FEniCS Examples
 * Introduction to Python for FEniCS
 * The FEniCS Tutorial
 * The FEniCS Book (63.4 MB .pdf)
 * Computational Turbulent Incompressible Flow (22.4 MB .pdf)

=Installation= For Ubuntu-based Linux distributions, FEniCS is readily installed running the following three commands in a terminal.

An installer is provided for Windows and OSX here. For more information, see the FEniCS installation manual.

=Poisson's Equation= The general form of Poisson's Equation :
 * {| style="width:100%" border="0"

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

 What does this equation represent physically? What can $$u$$ represent? Gravitational potential, heat, magnetic field? kchristensen (talk) 18:20, 26 July 2012 (EDT)

Derivation of Weak Variational Form
We then multiply (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 (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 (PE.4) to (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" |
 * 
 * }

Problem Statement

 * $$u = u(\mathbf{x}) \; \forall \; x_i \in [0, 1], \; i = 0, 1$$
 * $$\mathbf{x}_s = \; <0.5, 0.5>$$
 * $$f = 10 e^{-\frac{\left(\mathbf{x} - \mathbf{x}_s\right)^2}{0.02}}$$
 * $$g = \sin\left(5 x_0\right) \; \forall \; \mathbf{x} \in \partial \Omega$$
 * $$u = 0 \; \forall \; x_0 = 0, 1$$

 What do these variables and expressions represent? Simple explanations after each line would be very useful for visualization. Ex: $$u = 0 \; \forall \; x_0 = 0, 1$$ sets the left and right boundaries of the unit square to $$0$$. kchristensen (talk) 18:46, 26 July 2012 (EDT)

Python Implementation
 Why does (PE.5) have integrals which are absent when defining "a" and "L" in the code? This will likely not need explanation past this problem so I'll omit this question on later codes. kchristensen (talk) 19:06, 26 July 2012 (EDT)

Solution

 * [[Image:Poisson-solution.png]]

Solution

 * [[image:NewtCooling.pdf|625px]]

While viewing the plot, the data can be saved as a "vtk" file by pressing "v". This vtk file can be opened in ParaView for further analysis. Below, a ParaView plot with isolines on every multiple of 0.25.


 * [[File:Nloc biunit.png]]]

ParaView can also be used to determine the value at a given point.

Solution

 * [[Image:L1DConDiff.png]]

Solution

 * [[Image:Burgers-solution.png]]

Derivation of Weak Variational Form
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%" |
 * 
 * }

We can then substitute (BE.7) into (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%" |
 * 
 * }

Following the steps outlined in the last section from (BE.3) through (BE.6), we obtain the following time-discretized form from (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" |
 * 
 * }

Solution

 * [[Image:Burger-1d-time-delay.gif]]

 How was this animation made? What is the FEniCS output for problems like this? kchristensen (talk) 18:20, 26 July 2012 (EDT)