-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding applications and sphinx documentation of psydac and sympde
- Loading branch information
Showing
32 changed files
with
1,872 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ usr | |
|
||
.env | ||
.iga-python | ||
|
||
*_autosummary* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.