Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
4426a015fThis file is pinned to the selected release. Download the original to open it in your design tool.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"### Conforming Stokes approx.: Taylor-Hood element\n",
"\n",
"In a first step we want to discretize the Stokes equations with the well known Taylor-Hood finite element method. To this aim we choose the spaces\n",
"\n",
"$$\n",
"V_h = [H^1_{0,\\Gamma\\setminus\\Gamma_{\\text{out}}}(\\Omega)]^d \\cap [\\mathbb{P}^{k}]^d \n",
"\\quad \\text{and} \\quad\n",
"Q_h = H^1(\\Omega) \\cap \\mathbb{P}^{k-1}.\n",
"$$\n",
" \n",
"This is a suitable pair of spaces for the discretization of the Stokes problem, cf. [i-tutorials unit 2.6](https://docu.ngsolve.org/latest/i-tutorials/unit-2.6-stokes/stokes.html). \n",
"\n",
"As a first example we want to solve a Stokes flow around a NACA2412 airfoil ([naca_geometry.py](naca_geometry.py))."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ngsolve import *\n",
"from ngsolve.webgui import Draw\n",
"from netgen.occ import *\n",
"from naca_geometry import *\n",
"\n",
"naca_geo = OCCGeometry(occ_naca_profile(type = \"2412\", height=4, angle=4, h=0.05), dim=2)\n",
"mesh = Mesh(naca_geo.GenerateMesh(maxh=0.2, grading=0.9))\n",
"mesh.Curve(3)\n",
"Draw(mesh);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For the viscosity we choose $\\nu = 10^{-4}$. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nu = 1e-4"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As boundary conditions we consider wall boundary conditions on the surface of the airfoil ``` \"wall\" ``` and a constant inflow velocity in front of the airfoil, i.e. the boundary ``` \"inlet\" ```. The remaining boundaries are outflow boundaries."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"V = VectorH1(mesh, order = 3, dirichlet = \"inlet|wall\")\n",
"Q = H1(mesh, order = 2)\n",
"\n",
"X = V * Q "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We set up the variational formulation of the Stokes equation on the product space ``` X ``` and consider a zero right hand side."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(u,p), (v,q) = X.TnT()\n",
"\n",
"K = BilinearForm(X, symmetric = True)\n",
"K += (nu * InnerProduct(Grad(u), Grad(v)) - div(u) * q - div(v) * p) * dx\n",
"K.Assemble()\n",
"\n",
"F = LinearForm(X).Assemble()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To impose the boundary conditions we consider a standard homogenization step via the residual. Let ```gfu``` be the ```GridFunction``` that represents the solution $u,p$ on the product space. We impose the constant inflow value $u_D = (1,0)$, and solve the problem."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gfu = GridFunction(X)\n",
"gfu.components[0].Set(CF((1,0)), definedon = mesh.Boundaries(\"inlet\"))\n",
"\n",
"res = gfu.vec.CreateVector()\n",
"\n",
"res.data = F.vec - K.mat * gfu.vec\n",
"gfu.vec.data += K.mat.Inverse(X.FreeDofs()) * res\n",
"\n",
"Draw(gfu.components[1], mesh, \"p\");\n",
"Draw(gfu.components[0], mesh, \"u\");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}