-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/aleksejs-fomins/snippets-…
- Loading branch information
Showing
14 changed files
with
2,551 additions
and
18 deletions.
There are no files selected for viewing
1,783 changes: 1,783 additions & 0 deletions
1,783
dynamical_systems/eigenvalue-problems/fdtd_ode_eigensolution_stackoverflow.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
118 changes: 118 additions & 0 deletions
118
dynamical_systems/pde/pde_fdtd_3fields_stackoverflow.ipynb
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,118 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Original equations\n", | ||
"$$\n", | ||
"\\begin{eqnarray}\n", | ||
" \\frac{\\partial H}{\\partial x}+\\beta_h (H - W) &=& 0 \\\\\n", | ||
" \\frac{\\partial C}{\\partial y} + \\beta_c (C - W) &=& 0 \\\\\n", | ||
" \\lambda_h \\frac{\\partial^2 W}{\\partial x^2} + \\lambda_c V\\frac{\\partial^2 W}{\\partial y^2}\n", | ||
" - \\frac{\\partial H}{\\partial x} - V\\frac{\\partial C}{\\partial y} &=& 0\n", | ||
"\\end{eqnarray}\n", | ||
"$$\n", | ||
"\n", | ||
"Central differences\n", | ||
"$$\n", | ||
"\\begin{eqnarray}\n", | ||
" H_{i+1, j} - H_{i-1, j} + 2\\Delta x\\beta_h H_{ij} &=& 2\\Delta x\\beta_h W_{ij} \\\\\n", | ||
" C_{i, j+1} - C_{i, j-1} + 2\\Delta y\\beta_c C_{ij} &=& 2\\Delta y\\beta_c W_{ij} \\\\\n", | ||
" \\lambda_h (W_{i+1, j} - 2W_{i,j} + W_{i-1, j})\n", | ||
" + \\lambda_c V \\eta^2 (W_{i, j+1} - 2W_{i,j} + W_{i, j-1})\n", | ||
" + 2(\\beta_h + V \\beta_c)\\Delta x^2 W_{ij}\n", | ||
" &=& 2\\beta_h \\Delta x^2 H_{ij} + 2V\\beta_c \\Delta x^2 C_{ij}\n", | ||
"\\end{eqnarray}\n", | ||
"$$\n", | ||
"\n", | ||
"Constraints\n", | ||
"$$\\theta_w(0,y)=1, \\theta_w(x,0)=0$$\n", | ||
"$$\\frac{\\partial \\theta_w(1,y)}{\\partial x}=\\frac{\\partial \\theta_w(x,1)}{\\partial y}=0$$\n", | ||
"$$\\theta_h(0,y)=1, \\theta_c(x,0)=0$$\n", | ||
"\n", | ||
"* (@i = 1) : $W_{i-1,j} = 1$, $H_{i-1,j} = 1$\n", | ||
"* (@j = 1) : $W_{i,j-1} = 0$, $H_{i,j-1} = 0$\n", | ||
"* (@i = n) : $W_{i-1,j} = W_{i+1,j}$\n", | ||
"* (@j = n) : $W_{i,j-1} = W_{i,j+1}$\n", | ||
"\n", | ||
"Problem: Need to find 2nd boundary condition for $H$ and $C$. Use trick - take second derivative\n", | ||
"$$\n", | ||
"\\begin{eqnarray}\n", | ||
" \\partial_x^2 H + \\beta_h (\\partial_x H - \\partial_x W) &=& 0 \\\\\n", | ||
" \\partial_y^2 C + \\beta_c (\\partial_y C - \\partial_y W) &=& 0\n", | ||
"\\end{eqnarray}\n", | ||
"$$\n", | ||
"Discretize\n", | ||
"$$\n", | ||
"\\begin{eqnarray}\n", | ||
" (H_{i+1,j} - 2H_{i,j} + H_{i-1,j}) + \\frac{\\beta_h \\Delta X}{2} (H_{i+1, j} - H_{i-1, j})\n", | ||
" &=& \\frac{\\beta_h \\Delta X}{2} (W_{i+1, j} - W_{i-1, j}) \\\\\n", | ||
" (C_{i,j+1} - 2C_{i,j} + C_{i,j-1}) + \\frac{\\beta_c \\Delta Y}{2} (C_{i, j+1} - C_{i, j-1})\n", | ||
" &=& \\frac{\\beta_h \\Delta Y}{2} (W_{i, j+1} - W_{i, j-1}) \\\\\n", | ||
"\\end{eqnarray}\n", | ||
"$$\n", | ||
"\n", | ||
"At the outer edge derivatives of W are zero. Can solve for the outer edge of $H$ and $C$\n", | ||
"\n", | ||
"$$\n", | ||
"\\begin{eqnarray}\n", | ||
" (\\frac{\\beta_h \\Delta X}{2} + 1) H_{i+1, j} &=& 2H_{i,j} - (1 - \\frac{\\beta_h \\Delta X}{2}) H_{i-1,j} \\\\\n", | ||
" (\\frac{\\beta_c \\Delta Y}{2} + 1) C_{i, j+1} &=& 2C_{i,j} - (1 - \\frac{\\beta_c \\Delta Y}{2}) C_{i,j-1}\n", | ||
"\\end{eqnarray}\n", | ||
"$$\n", | ||
"Thus, at the outer boundaries, we have\n", | ||
"$$\n", | ||
"\\begin{eqnarray}\n", | ||
" (\\frac{\\beta_h^2 \\Delta X^2}{2} + \\beta_h \\Delta c + 1) H_{i,j} - H_{i-1,j}\n", | ||
" &=& \\Delta x\\beta_h (\\frac{\\beta_h \\Delta c}{2} + 1) W_{ij} \\\\\n", | ||
" (\\frac{\\beta_c^2 \\Delta Y^2}{2} + \\beta_c \\Delta y + 1) C_{i,j} - C_{i,j-1}\n", | ||
" &=& \\Delta y\\beta_c (\\frac{\\beta_c \\Delta y}{2} + 1) W_{ij} \\\\\n", | ||
"\\end{eqnarray}\n", | ||
"$$" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"nEq = 3\n", | ||
"nRow = 10\n", | ||
"nCol = 10\n", | ||
"nRowBig = nRow * nCol * nEq\n", | ||
"bigMat = np.zeros((nRowBig, nRowBig))\n", | ||
"\n", | ||
"big_mapper = lambda iEq, iRow, iCol: iCol + iRow * nCol + iEq * nRow * nCol\n", | ||
"\n", | ||
"iRowBig = 0\n", | ||
"for iRow in range(nRow):\n", | ||
" for iCol in range(nCol):\n", | ||
" \n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python (nest)", | ||
"language": "python", | ||
"name": "py36nest" | ||
}, | ||
"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.6.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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
Oops, something went wrong.