Skip to content

Commit

Permalink
update readme with example
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeolson committed May 10, 2017
1 parent 8534a86 commit d90e76b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
build/
*.swp
.ipynb_checkpoints
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ To view the solution, modify the `poisson.cc` file to include
outfile.close();
```
Then `make`. Here there will be `np` different solution files `solution-*.txt`. This can be viewed in Python:
Then `make`. Here there will be `np` different solution files `solution-*.txt`. This can be viewed in Python for example in [example_output.ipynb](tools/example_output.ipynb), which gives the following for the processor layout (`mpirun -np 6`) and the solution:
![](tools/example_output.png)
# Citing
Expand Down
103 changes: 103 additions & 0 deletions tools/example_output.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"nproc = 6\n",
"data = []\n",
"for p in range(nproc):\n",
" d = np.loadtxt('../build/solution-%d.txt'%p, delimiter=',',\n",
" usecols=[1,2,3], dtype='int,int,float', unpack=True)\n",
" d[0] -= 1 # zero-based\n",
" d[1] -= 1 # zero-based\n",
" data.append(d)\n",
"xmin = min([d[0].min() for d in data])\n",
"ymin = min([d[1].min() for d in data])\n",
"xmax = max([d[0].max() for d in data])\n",
"ymax = max([d[1].max() for d in data])\n",
"nx = xmax - xmin + 1 + 2 # for boundaries\n",
"ny = ymax - ymin + 1 + 2 # for boundaries\n",
"print(nx, ny)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"X, Y = np.mgrid[0:1:nx*1j,0:1:ny*1j]\n",
"Z = np.zeros(X.shape)\n",
"P = np.zeros(X.shape)\n",
"for p in range(nproc):\n",
" I = data[p][0]\n",
" J = data[p][1]\n",
" Z[I,J] = data[p][2]\n",
" P[I,J] = p"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"f, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))\n",
"ax1.pcolormesh(X, Y, P)\n",
"ax2.pcolormesh(X, Y, Z)\n",
"plt.savefig('example_output.png')"
]
}
],
"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.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Binary file added tools/example_output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d90e76b

Please sign in to comment.