mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-13 09:28:23 +01:00
BTCS create_coeff_matrix
This commit is contained in:
parent
20067a6898
commit
498f813d2d
@ -2,7 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -68,7 +68,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -90,6 +90,84 @@
|
||||
" return delta_t / (2 * delta_x**2)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# creates the coeffiecient matrix for a given row\n",
|
||||
"def create_coeff_matrix(alpha_x, row_index, s_x, transpose=False):\n",
|
||||
" if (transpose):\n",
|
||||
" alpha_x = alpha_x.transpose()\n",
|
||||
"\n",
|
||||
" cm = np.zeros((alpha_x.shape[0]+2,alpha_x.shape[1]+2))\n",
|
||||
"\n",
|
||||
" offset = 2\n",
|
||||
" r = row_index\n",
|
||||
" for i in range(2, cm.shape[0]-2):\n",
|
||||
" j = offset\n",
|
||||
" cm[i,j-1] = -s_x * alpha_interblock(alpha_x[r, j-1], alpha_x[r, j])\n",
|
||||
" cm[i,j] = 1 + s_x * (alpha_interblock(alpha_x[r,j], alpha_x[r, j+1]) + alpha_interblock(alpha_x[r, j], alpha_x[r, j-1]))\n",
|
||||
" cm[i,j+1] = -s_x * alpha_interblock(alpha_x[r, j], alpha_x[r, j+1])\n",
|
||||
"\n",
|
||||
" offset += 1\n",
|
||||
"\n",
|
||||
" return cm\n",
|
||||
"\n",
|
||||
"# creates the solution vector for a given row\n",
|
||||
"def create_solution_vector(concentrations, alpha_y, row_index, s_x, transpose=False):\n",
|
||||
" pass\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def solve_row(A, b):\n",
|
||||
" # use existing implementation\n",
|
||||
" pass"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "IndexError",
|
||||
"evalue": "index 5 is out of bounds for axis 1 with size 5",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[0;32mIn[17], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m result \u001b[39m=\u001b[39m create_coeff_matrix(np\u001b[39m.\u001b[39;49mrandom\u001b[39m.\u001b[39;49mrandom_sample((\u001b[39m5\u001b[39;49m,\u001b[39m5\u001b[39;49m)), \u001b[39m0\u001b[39;49m, \u001b[39m3\u001b[39;49m)\n\u001b[1;32m 2\u001b[0m \u001b[39mprint\u001b[39m(result)\n",
|
||||
"Cell \u001b[0;32mIn[16], line 13\u001b[0m, in \u001b[0;36mcreate_coeff_matrix\u001b[0;34m(alpha_x, row_index, s_x, transpose)\u001b[0m\n\u001b[1;32m 11\u001b[0m j \u001b[39m=\u001b[39m offset\n\u001b[1;32m 12\u001b[0m cm[i,j\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m] \u001b[39m=\u001b[39m \u001b[39m-\u001b[39ms_x \u001b[39m*\u001b[39m alpha_interblock(alpha_x[r, j\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m], alpha_x[r, j])\n\u001b[0;32m---> 13\u001b[0m cm[i,j] \u001b[39m=\u001b[39m \u001b[39m1\u001b[39m \u001b[39m+\u001b[39m s_x \u001b[39m*\u001b[39m (alpha_interblock(alpha_x[r,j], alpha_x[r, j\u001b[39m+\u001b[39;49m\u001b[39m1\u001b[39;49m]) \u001b[39m+\u001b[39m alpha_interblock(alpha_x[r, j], alpha_x[r, j\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m]))\n\u001b[1;32m 14\u001b[0m cm[i,j\u001b[39m+\u001b[39m\u001b[39m1\u001b[39m] \u001b[39m=\u001b[39m \u001b[39m-\u001b[39ms_x \u001b[39m*\u001b[39m alpha_interblock(alpha_x[r, j], alpha_x[r, j\u001b[39m+\u001b[39m\u001b[39m1\u001b[39m])\n\u001b[1;32m 16\u001b[0m offset \u001b[39m+\u001b[39m\u001b[39m=\u001b[39m \u001b[39m1\u001b[39m\n",
|
||||
"\u001b[0;31mIndexError\u001b[0m: index 5 is out of bounds for axis 1 with size 5"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"result = create_coeff_matrix(np.random.random_sample((5,5)), 0, 3)\n",
|
||||
"print(result)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2\n",
|
||||
"3\n",
|
||||
"4\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"for i in range(2,5):\n",
|
||||
" print(i)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user