Skip to content

Commit

Permalink
adding applications and sphinx documentation of psydac and sympde
Browse files Browse the repository at this point in the history
  • Loading branch information
ratnania committed Feb 23, 2024
1 parent 7abe7d8 commit c59e452
Show file tree
Hide file tree
Showing 32 changed files with 1,872 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ usr

.env
.iga-python

*_autosummary*
4 changes: 4 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@ html:
sphinx:
extra_extensions:
- sphinx_proof
- sphinx.ext.autodoc
- sphinx.ext.autosummary
config:
autosummary_generate: True

exclude_patterns: [README.md, .iga-python]
34 changes: 33 additions & 1 deletion _toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ parts:
chapters:
- file: chapter2/poisson
- file: chapter2/poisson-nitsche
- file: chapter2/elliptic-general-form
- file: chapter2/biharmonic
- file: chapter2/vector-poisson
- file: chapter2/advection-diffusion
Expand Down Expand Up @@ -65,4 +66,35 @@ parts:
- file: chapter4/subdomains
sections:
- file: chapter4/poisson-nitsche

- caption: Applications
chapters:
- file: chapter5/cfd
sections:
- file: chapter5/buoyancy-driven_natural_convection
- file: chapter5/compressible_flow_in_a_nozzle
- file: chapter5/convection-diffusion_equation_in_a_channel
- file: chapter5/free_surface_flow
- file: chapter5/heat_conduction_in_a_solid
- file: chapter5/incompressible_flow_past_a_cylinder
- file: chapter5/magnetohydrodynamics_flow
- file: chapter5/particle-laden_flow
- file: chapter5/stokes_flow_in_a_lid-driven_cavity
- file: chapter5/two-phase_flow
- file: chapter5/non-newtonian-fluids
sections:
- file: chapter5/power_law_fluid_flow_in_a_channel
- file: chapter5/bingham_plastic_flow_in_a_pipe
- file: chapter5/oldroyd-b_fluid_flow_in_a_channel
- file: chapter5/herschel-bulkley_fluid_flow_in_a_pipe
- file: chapter5/cross_power_law_fluid_flow_in_a_channel
- file: chapter5/casson_fluid_flow_in_a_channel
- file: chapter5/papanastasiou_fluid_flow_in_a_channel
- file: chapter5/fsi
- file: chapter5/electromagnetics
- file: chapter5/mhd
- file: chapter5/material-science
- file: chapter5/multiphysics
- caption: Documentation
chapters:
- file: documentation/sympde
- file: documentation/psydac
278 changes: 278 additions & 0 deletions chapter2/elliptic-general-form.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "b5e0474c",
"metadata": {},
"source": [
"# Elliptic equation in the general form\n",
"\n",
"We consider here, the following general form of an elliptic partial differential equation,\n",
"\n",
"$$\n",
"\\begin{align}\n",
"- \\nabla \\cdot \\left( A \\nabla u \\right) + \\mathbf{b} \\cdot \\nabla u + c u &= f, \\quad \\Omega \\\\\n",
"u &= 0, \\quad \\partial \\Omega\n",
"\\end{align}\n",
"$$\n",
"\n",
"## Variational Formulation\n",
"\n",
"An $H^1$-conforming variational formulation of reads\n",
"\n",
"$$\n",
"\\begin{align}\n",
" \\text{find $u \\in V$ such that} \\quad a(u,v) = l(v) \\quad \\forall v \\in V,\n",
"\\end{align}\n",
"$$\n",
"\n",
"where \n",
"\n",
"- $V \\subset H^1(\\Omega)$, \n",
"- $a(u,v) := \\int_{\\Omega} \\left( \\left( A \\nabla u \\right) \\cdot \\nabla v + \\left( \\mathbf{b} \\cdot \\nabla u \\right) v + cuv \\right) ~ d\\Omega$,\n",
"- $l(v) := \\int_{\\Omega} f v ~ d\\Omega$.\n"
]
},
{
"cell_type": "markdown",
"id": "c5c944a1",
"metadata": {},
"source": [
"## Formal Model"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "c2cee2d9",
"metadata": {},
"outputs": [],
"source": [
"from sympde.expr import BilinearForm, LinearForm, integral\n",
"from sympde.expr import find, EssentialBC, Norm, SemiNorm\n",
"from sympde.topology import ScalarFunctionSpace, Square, element_of\n",
"from sympde.calculus import grad, dot, div\n",
"from sympde.core import Vector, Matrix\n",
"\n",
"from sympy import pi, sin\n",
"\n",
"from psydac.api.discretization import discretize\n",
"\n",
"domain = Square()\n",
"\n",
"V = ScalarFunctionSpace('V', domain)\n",
"\n",
"x,y = domain.coordinates\n",
"\n",
"u,v = [element_of(V, name=i) for i in ['u', 'v']]\n",
"\n",
"c = x*y\n",
"b = Vector([1e-2, 1e-1], name='b')\n",
"A = Matrix([[1,1], [0,1]], name='A')\n",
"\n",
"# bilinear form\n",
"expr = dot(grad(v), A * grad(u)) + dot(b, grad(u))*v + c*u*v\n",
"a = BilinearForm((u,v), integral(domain, expr))"
]
},
{
"cell_type": "markdown",
"id": "366c2d67",
"metadata": {},
"source": [
"### Manifactured solution"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "2b05c79f",
"metadata": {},
"outputs": [],
"source": [
"# the analytical solution and its rhs\n",
"ue = sin(pi * x) * sin(pi * y)\n",
"\n",
"L = lambda u: - div(A*grad(u)) + dot(b,grad(u)) + c*u\n",
"f = L(ue)"
]
},
{
"cell_type": "markdown",
"id": "66b50430",
"metadata": {},
"source": [
"### Formal Equation"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "d0d386a2",
"metadata": {},
"outputs": [],
"source": [
"l = LinearForm(v, integral(domain, f*v))\n",
"\n",
"# Dirichlet boundary conditions\n",
"bc = [EssentialBC(u, 0, domain.boundary)]\n",
"\n",
"# Variational problem\n",
"equation = find(u, forall=v, lhs=a(u, v), rhs=l(v), bc=bc)"
]
},
{
"cell_type": "markdown",
"id": "0614c740",
"metadata": {},
"source": [
"## Discretization"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "96c29a27",
"metadata": {},
"outputs": [],
"source": [
"degree = [2,2]\n",
"ncells = [8,8]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "ef6a9709",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/ranania/PYCCEL/IGA-Python/.iga-python/lib/python3.10/site-packages/sympy/matrices/repmatrix.py:90: SymPyDeprecationWarning: \n",
"\n",
"non-Expr objects in a Matrix has been deprecated since SymPy 1.9. Use\n",
"list of lists, TableForm or some other data structure instead. See\n",
"https://github.com/sympy/sympy/issues/21497 for more info.\n",
"\n",
" ).warn()\n"
]
}
],
"source": [
"# Create computational domain from topological domain\n",
"domain_h = discretize(domain, ncells=ncells, comm=None)\n",
"\n",
"# Create discrete spline space\n",
"Vh = discretize(V, domain_h, degree=degree)\n",
"\n",
"# Discretize equation\n",
"equation_h = discretize(equation, domain_h, [Vh, Vh])"
]
},
{
"cell_type": "markdown",
"id": "c286e572",
"metadata": {},
"source": [
"### Solving the PDE"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "3bafe9f5",
"metadata": {},
"outputs": [],
"source": [
"equation_h.set_solver('gmres', info=False, tol=1e-8)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "b88daf50",
"metadata": {},
"outputs": [],
"source": [
"uh = equation_h.solve()"
]
},
{
"cell_type": "markdown",
"id": "d865a17f",
"metadata": {},
"source": [
"## Computing the error norm"
]
},
{
"cell_type": "markdown",
"id": "be88e26c",
"metadata": {},
"source": [
"### Computing the $L^2$ norm"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "3440e74a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.00021948770944141364\n"
]
}
],
"source": [
"u = element_of(V, name='u')\n",
"\n",
"# create the formal Norm object\n",
"l2norm = Norm(u - ue, domain, kind='l2')\n",
"\n",
"# discretize the norm\n",
"l2norm_h = discretize(l2norm, domain_h, Vh)\n",
"\n",
"# assemble the norm\n",
"l2_error = l2norm_h.assemble(u=uh)\n",
"\n",
"# print the result\n",
"print(l2_error)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5d7d9180",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".iga-python",
"language": "python",
"name": ".iga-python"
},
"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.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit c59e452

Please sign in to comment.