Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
markuswess committed Jun 18, 2024
1 parent 9dfdb12 commit bb911ff
Show file tree
Hide file tree
Showing 30 changed files with 3,504 additions and 185 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
406 changes: 406 additions & 0 deletions _sources/examples/basics.ipynb

Large diffs are not rendered by default.

234 changes: 234 additions & 0 deletions _sources/examples/grad.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "8fd56fc3",
"metadata": {},
"source": [
"# Computing the gradient of a Gaussian peak in dual cell spaces\n",
"\n",
"### by M. Wess, 2024\n",
"*This Notebook is part of the `dualcellspaces` [documentation](https://ngsolve.github.io/dcm) for the addon package implementing the Dual Cell method in [NGSolve](https://ngsolve.org).*"
]
},
{
"cell_type": "markdown",
"id": "0b129f3c",
"metadata": {},
"source": [
"We verify our implementation by projecting a Gaussian peak\n",
"\n",
"$$\n",
"f(\\mathbf x) = \\frac{1}{2}\\exp(-100 \\|\\mathbf x - (\\tfrac{1}{2},\\tfrac{1}{2})^\\top\\|^2),\n",
"$$\n",
"\n",
" in $\\mathbb R^2$ into the discrete space $\\tilde X^{\\mathrm{grad}}_P(\\tilde{\\mathcal T})$ and computing the discrete gradient in $X^{\\mathrm{div}}_P({\\mathcal T})$.\n"
]
},
{
"cell_type": "markdown",
"id": "ee49f25a",
"metadata": {},
"source": [
"We import the packages and define the necessary spaces"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "60f2ed24",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"DoFs H1Primal: 154870\n",
"DoFs HDivDual: 344250\n"
]
}
],
"source": [
"from ngsolve import *\n",
"import dualcellspaces as dcs\n",
"from ngsolve.webgui import Draw\n",
"from time import time\n",
"\n",
"mesh = Mesh(unit_square.GenerateMesh(maxh = 0.03))\n",
"\n",
"order = 4\n",
"h1 = dcs.H1DualCells(mesh, order = order)\n",
"hdiv = dcs.HDivPrimalCells(mesh, order = order)\n",
"\n",
"print(\"DoFs H1Primal: {}\".format(h1.ndof))\n",
"print(\"DoFs HDivDual: {}\".format(hdiv.ndof))"
]
},
{
"cell_type": "markdown",
"id": "97e8613e",
"metadata": {},
"source": [
"We obtain the (lumped) mass matrix by using `Mass`. We assemble the right hand side for the projection using the lumped integration rule and solve the projection problem to find $p\\in \\tilde X^{\\mathrm{grad}}_P(\\tilde {\\mathcal T})$\n",
"\n",
"$$\n",
"(p,q)_h = (f,q)_h,\n",
"$$\n",
"\n",
"where $(\\cdot,\\cdot)_h$ is the lumped approximation of the $L^2$ inner product."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5f43a2c0",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7e38079058ea4fae9ce05e0b895c631d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"WebGuiWidget(layout=Layout(height='50vh', width='100%'), value={'gui_settings': {'camera': {'euler_angles': [-…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"mass_h1_inv = h1.Mass(1).Inverse()\n",
"\n",
"dx_h1 = dx(intrules = h1.GetIntegrationRules())\n",
"peak = CF( 0.5 * exp(-100*( (x-0.5)**2 + (y-0.5)**2 )) )\n",
"\n",
"p,q = h1.TnT()\n",
"rhs = LinearForm(peak*q*dx_h1).Assemble().vec\n",
"\n",
"gfp = GridFunction(h1)\n",
"gfp.vec.data = mass_h1_inv * rhs\n",
"\n",
"Draw(gfp, order = 2, points = dcs.GetWebGuiPoints(2), deformation = True, euler_angles = [-40,-4,-150]);"
]
},
{
"cell_type": "markdown",
"id": "e495bd22",
"metadata": {},
"source": [
"Next we need to assemble the differential operator (including the boundary terms)\n",
"$$\n",
"b(p,v) = \\sum_{T\\in\\mathcal T} -\\int_T p \\,\\mathrm{div} v dx +\\int_{\\partial T} p v\\cdot n ds.\n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "7cb4ebf7",
"metadata": {},
"outputs": [],
"source": [
"n = specialcf.normal(2)\n",
"\n",
"dSw = dx(element_boundary = True, intrules = dcs.GetIntegrationRules(2*order - 1))\n",
"dxw = dx(intrules = dcs.GetIntegrationRules(2*order -1))\n",
"\n",
"v = hdiv.TestFunction()\n",
"grad = BilinearForm(-p*div(v)*dxw + p*(v*n)*dSw, geom_free = True).Assemble().mat"
]
},
{
"cell_type": "markdown",
"id": "974ab5bb",
"metadata": {},
"source": [
"The flag `geom_free = True` tells the `BilinearForm` that the element contributions of the matrix are independent of specific element and the geometric quantities (i.e., all Jacobian matrices of the transformation cancel out)."
]
},
{
"cell_type": "markdown",
"id": "e5a38e20",
"metadata": {},
"source": [
"Lastly we solve the weak problem to find $u\\in X^{\\mathrm{div}}_P(\\mathcal T)$ such that\n",
"$$\n",
"(u,v)_h = b(p,v)\n",
"$$\n",
"for all $v$.\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e781f39d",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cfe8e4d589ae4d228c0ed86cab6c41e8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"WebGuiWidget(layout=Layout(height='50vh', width='100%'), value={'gui_settings': {'camera': {'euler_angles': [-…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gfu = GridFunction(hdiv)\n",
"\n",
"mass_hdiv_inv = hdiv.Mass().Inverse()\n",
"\n",
"gfu.vec.data = mass_hdiv_inv @ grad * gfp.vec\n",
"\n",
"Draw(gfu, order = 2, points = dcs.GetWebGuiPoints(2), vectors = True, euler_angles = [-40,-4,-150]);"
]
},
{
"cell_type": "markdown",
"id": "4c548f6b",
"metadata": {},
"source": [
"### Exercises\n",
"* Add/Remove the flag `geom_free = True` and study the application and setup times of the discrete differential operator."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "24c64bf9",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
354 changes: 354 additions & 0 deletions _sources/examples/mass_lumping.ipynb

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions _sources/examples/qualitative_dispersion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
"cells": [
{
"cell_type": "markdown",
"id": "98d572eb",
"id": "2bf23c77",
"metadata": {},
"source": [
"# A plane wave on a square\n",
"\n",
"\n",
"### by M. Wess, 2024\n",
"*This Notebook is part of the `dualcellspaces` [documentation](https://ngsolve.github.io/dcm) for the addon package implementing the Dual Cell method in [NGSolve](https://ngsolve.org).*"
]
},
{
"cell_type": "markdown",
"id": "98d572eb",
"metadata": {},
"source": [
"We solve the two-dimensional wave equation to find $H: [0,T]\\to H^1(\\Omega)$ and the vector field $E: [0,T]\\to H(\\mathrm{div})$ are\n",
"\n",
"$$\n",
Expand All @@ -18,7 +28,7 @@
"H(t,x) &= 0,&t\\in(0,T),x\\in\\partial\\Omega\n",
"\\end{aligned}\n",
"$$\n",
"for $\\Omega=(0,1)^2$ and a suitable source term $f$.\n"
"for $\\Omega=(0,1)^2$ and a suitable source term $f$."
]
},
{
Expand Down
12 changes: 11 additions & 1 deletion _sources/examples/ring_resonator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
"cells": [
{
"cell_type": "markdown",
"id": "d3eb1974",
"id": "d4a64fd4",
"metadata": {},
"source": [
"# Ring resonator\n",
"\n",
"\n",
"### by M. Wess, J. Schöberl, 2024\n",
"*This Notebook is part of the `dualcellspaces` [documentation](https://ngsolve.github.io/dcm) for the addon package implementing the Dual Cell method in [NGSolve](https://ngsolve.org).*"
]
},
{
"cell_type": "markdown",
"id": "d3eb1974",
"metadata": {},
"source": [
"We simulate the propagation of an electromagnetic TM-Wave through a ring resonator device using the [dual cell method](https://ngsolve.github.io/dcm/intro.html) add on for [NGSolve](https://ngsolve.org).\n",
"\n",
"The desired geometry is sketched below, where the horizontal waveguides are supposed to be unbounded.\n",
Expand Down
6 changes: 5 additions & 1 deletion _sources/examples/waveguide_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"id": "75f138b9",
"metadata": {},
"source": [
"# Electromagnetic 3d waveguide"
"# Electromagnetic 3d waveguide\n",
"\n",
"\n",
"### by M. Wess, 2024\n",
"*This Notebook is part of the `dualcellspaces` [documentation](https://ngsolve.github.io/dcm) for the addon package implementing the Dual Cell method in [NGSolve](https://ngsolve.org).*"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions _sources/maxwell/hcurl.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ print("number of (primal) elements in mesh: ", mesh_curl.ne)
print("number of dofs per element: ", hcurl.ndof/mesh_curl.ne)
```

We may take a look at the basis functions:
```{code-cell} ipython
gfu_curl = GridFunction(hcurl,multidim = hcurl.ndof)
for i in range(hcurl.ndof):
gfu_curl.vecs[i][i] = 1
Draw(gfu_curl, animate = True, min = 0, max = 1,vectors = True, intpoints = dcs.GetWebGuiPoints(2),order = 2,);
%We may take a look at the basis functions:
%```{code-cell} ipython
%gfu_curl = GridFunction(hcurl,multidim = hcurl.ndof)
%for i in range(hcurl.ndof):
% gfu_curl.vecs[i][i] = 1
%Draw(gfu_curl, animate = True, min = 0, max = 1,vectors = True, intpoints = dcs.GetWebGuiPoints(2),order = 2,);
```
Expand Down
24 changes: 15 additions & 9 deletions examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<script>DOCUMENTATION_OPTIONS.pagename = 'examples';</script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="3.1. A plane wave on a square" href="examples/qualitative_dispersion.html" />
<link rel="next" title="3.1. Basics on dual cell spaces" href="examples/basics.html" />
<link rel="prev" title="2.7. Bibliography" href="maxwell/bibliography.html" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="docsearch:language" content="en"/>
Expand Down Expand Up @@ -189,9 +189,12 @@
</ul>
</li>
<li class="toctree-l1 current active has-children"><a class="current reference internal" href="#">3. Examples</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-2"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="examples/qualitative_dispersion.html">3.1. A plane wave on a square</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/ring_resonator.html">3.2. Ring resonator</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/waveguide_3d.html">3.3. Electromagnetic 3d waveguide</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/basics.html">3.1. Basics on dual cell spaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/mass_lumping.html">3.2. Mass Lumping for dual cell spaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/grad.html">3.3. Computing the gradient of a Gaussian peak in dual cell spaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/qualitative_dispersion.html">3.4. A plane wave on a square</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/ring_resonator.html">3.5. Ring resonator</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples/waveguide_3d.html">3.6. Electromagnetic 3d waveguide</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -395,9 +398,12 @@ <h1>Examples</h1>
<span id="id1"></span><h1><span class="section-number">3. </span>Examples<a class="headerlink" href="#examples" title="Link to this heading">#</a></h1>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="examples/qualitative_dispersion.html">3.1. A plane wave on a square</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/ring_resonator.html">3.2. Ring resonator</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/waveguide_3d.html">3.3. Electromagnetic 3d waveguide</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/basics.html">3.1. Basics on dual cell spaces</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/mass_lumping.html">3.2. Mass Lumping for dual cell spaces</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/grad.html">3.3. Computing the gradient of a Gaussian peak in dual cell spaces</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/qualitative_dispersion.html">3.4. A plane wave on a square</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/ring_resonator.html">3.5. Ring resonator</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/waveguide_3d.html">3.6. Electromagnetic 3d waveguide</a></li>
</ul>
</div>
</section>
Expand Down Expand Up @@ -442,11 +448,11 @@ <h1>Examples</h1>
</div>
</a>
<a class="right-next"
href="examples/qualitative_dispersion.html"
href="examples/basics.html"
title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title"><span class="section-number">3.1. </span>A plane wave on a square</p>
<p class="prev-next-title"><span class="section-number">3.1. </span>Basics on dual cell spaces</p>
</div>
<i class="fa-solid fa-angle-right"></i>
</a>
Expand Down
Loading

0 comments on commit bb911ff

Please sign in to comment.