-
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.
- Loading branch information
Showing
32 changed files
with
55,787 additions
and
0 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
en_array/.ipynb_checkpoints/double_grid-checkpoint.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,146 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"original_array = np.load(\"en_array.npy\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"(20, 18, 20)" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"shape = original_array.shape\n", | ||
"shape" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"(39, 35, 39)" | ||
] | ||
}, | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"new_shape = (2 * shape[0] - 1, 2 * shape[1] - 1, 2 * shape[2] - 1)\n", | ||
"new_shape" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"new_array = np.zeros(new_shape)\n", | ||
"new_array[::2, ::2, ::2] = original_array" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 22, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for i in range(new_shape[0]):\n", | ||
" for j in range(new_shape[1]):\n", | ||
" for k in range(new_shape[2]):\n", | ||
" # the odd index is the newly added while even is the old\n", | ||
" r_i = i % 2\n", | ||
" r_j = j % 2\n", | ||
" r_k = k % 2\n", | ||
" \n", | ||
" # original vertices of the array (all indices are even)\n", | ||
" if r_i == 0 and r_j == 0 and r_k == 0:\n", | ||
" continue\n", | ||
" \n", | ||
" assert(new_array[i, j, k] == 0)\n", | ||
" # cell center (all indices are odds)\n", | ||
" if r_i + r_j + r_k == 3:\n", | ||
" new_array[i, j, k] = (new_array[i-1, j-1, k-1] + new_array[i+1, j-1, k-1] + new_array[i-1, j+1, k-1] + new_array[i+1, j+1, k-1] + \n", | ||
" new_array[i-1, j-1, k+1] + new_array[i+1, j-1, k+1] + new_array[i-1, j+1, k+1] + new_array[i+1, j+1, k+1])/8\n", | ||
" # surface center (two indices are odds)\n", | ||
" elif r_i + r_j + r_k == 2: \n", | ||
" # on the i surface\n", | ||
" if r_i == 0:\n", | ||
" new_array[i, j, k] = (new_array[i, j-1, k-1] + new_array[i, j-1, k+1] + new_array[i, j+1, k-1] + new_array[i, j+1, k+1])/4\n", | ||
" # on the j surface\n", | ||
" elif r_j == 0:\n", | ||
" new_array[i, j, k] = (new_array[i-1, j, k-1] + new_array[i-1, j, k+1] + new_array[i+1, j, k-1] + new_array[i+1, j, k+1])/4\n", | ||
" # on the k surface\n", | ||
" else:\n", | ||
" new_array[i, j, k] = (new_array[i-1, j-1, k] + new_array[i-1, j+1, k] + new_array[i+1, j-1, k] + new_array[i+1, j+1, k])/4\n", | ||
" # edge middle\n", | ||
" else:\n", | ||
" if r_i == 1:\n", | ||
" new_array[i, j, k] = (new_array[i-1, j, k] + new_array[i+1, j, k])/2\n", | ||
" elif r_j == 1:\n", | ||
" new_array[i, j, k] = (new_array[i, j-1, k] + new_array[i, j+1, k])/2\n", | ||
" else:\n", | ||
" new_array[i, j, k] = (new_array[i, j, k-1] + new_array[i, j, k+1])/2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"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.7.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.