Fix broken equation
This commit is contained in:
parent
02629dc106
commit
eeb83fe268
File diff suppressed because one or more lines are too long
@ -40,7 +40,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 33,
|
||||
"execution_count": 1,
|
||||
"id": "05d4e22c-3d7d-4ac2-bf22-59b78aa40b84",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@ -64,7 +64,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 61,
|
||||
"execution_count": 18,
|
||||
"id": "82bb4a02-1ecf-4c84-8b9d-b753dee75337",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@ -78,10 +78,10 @@
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"-0.20000000000000007"
|
||||
"array([-0.14798801, -0.13453456])"
|
||||
]
|
||||
},
|
||||
"execution_count": 61,
|
||||
"execution_count": 18,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@ -91,27 +91,32 @@
|
||||
" displacement: np.ndarray,\n",
|
||||
" i: Tuple[int, int],\n",
|
||||
" j: Tuple[int, int]\n",
|
||||
") -> float:\n",
|
||||
") -> np.ndarray:\n",
|
||||
" u_ij = displacement[i] - displacement[j]\n",
|
||||
" x_ij = np.array(i, dtype=float) - np.array(j, dtype=float)\n",
|
||||
" K_ij = np.linalg.norm(x_ij) ** 2\n",
|
||||
" r_ij = x_ij + u_ij\n",
|
||||
"\n",
|
||||
" print(f\"{j=} {K_ij=} {u_ij=} {x_ij=}\")\n",
|
||||
"\n",
|
||||
" return -K_ij * np.dot(u_ij, x_ij)\n",
|
||||
" return -K_ij * np.dot(u_ij, x_ij) * r_ij / np.linalg.norm(r_ij)\n",
|
||||
"\n",
|
||||
"def calculate_force_bond(\n",
|
||||
" displacement: np.ndarray,\n",
|
||||
" i: Tuple[int, int],\n",
|
||||
" j: Tuple[int, int]\n",
|
||||
") -> float:\n",
|
||||
" return 0.0\n",
|
||||
") -> np.ndarray:\n",
|
||||
" u_ij = displacement[i] - displacement[j]\n",
|
||||
" x_ij = np.array(i, dtype=float) - np.array(j, dtype=float)\n",
|
||||
" c_ij = 1.0\n",
|
||||
"\n",
|
||||
" return (-c_ij * u_ij) / (np.linalg.norm(x_ij) ** 2)\n",
|
||||
"\n",
|
||||
"def calculate_force(\n",
|
||||
" displacement: np.ndarray,\n",
|
||||
" i: Tuple[int, int],\n",
|
||||
" j: Tuple[int, int]\n",
|
||||
") -> float:\n",
|
||||
") -> np.ndarray:\n",
|
||||
" return calculate_force_elastic(displacement, i, j) + calculate_force_bond(displacement, i, j)\n",
|
||||
"\n",
|
||||
"displacement = np.array([\n",
|
||||
@ -124,19 +129,19 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 71,
|
||||
"execution_count": 19,
|
||||
"id": "f7a019c2-8d20-4e84-9e0c-ef788781a07a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "89618a87c5514c6698d62e3344092fdf",
|
||||
"model_id": "78145432b809422bb171f675b00d05a6",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
"text/plain": [
|
||||
"interactive(children=(FloatSlider(value=0.0, description='dp_x', max=1.0, min=-1.0, step=0.05), FloatSlider(va…"
|
||||
"interactive(children=(FloatSlider(value=0.0, description='dp_x', max=1.5, min=-1.5, step=0.05), FloatSlider(va…"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
@ -148,7 +153,7 @@
|
||||
"<function __main__.do_plot(dp_x: float, dp_y: float) -> None>"
|
||||
]
|
||||
},
|
||||
"execution_count": 71,
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@ -172,16 +177,14 @@
|
||||
" ys.append(y + displacement[j][1])\n",
|
||||
"\n",
|
||||
" if j != i:\n",
|
||||
" F_ij = calculate_force_elastic(displacement, i, j)\n",
|
||||
" F_ij_vec = (\n",
|
||||
" (i + displacement[i])\n",
|
||||
" - (j + displacement[j])\n",
|
||||
" ) * F_ij\n",
|
||||
" print(f\"{F_ij_vec=}\")\n",
|
||||
" elastic_xs.append(F_ij_vec[0])\n",
|
||||
" elastic_ys.append(F_ij_vec[1])\n",
|
||||
" F_ij = calculate_force(displacement, i, j)\n",
|
||||
" print(f\"{F_ij=}\")\n",
|
||||
" elastic_xs.append(F_ij[0])\n",
|
||||
" elastic_ys.append(F_ij[1])\n",
|
||||
"\n",
|
||||
" pi = i + displacement[i]\n",
|
||||
" plt.xlim(-1, 3)\n",
|
||||
" plt.ylim(-1, 3)\n",
|
||||
" plt.scatter(xs, ys)\n",
|
||||
" plt.quiver(\n",
|
||||
" [pi[0]] * len(elastic_xs),\n",
|
||||
@ -189,6 +192,7 @@
|
||||
" elastic_xs,\n",
|
||||
" elastic_ys,\n",
|
||||
" scale = 5,\n",
|
||||
" angles = \"xy\",\n",
|
||||
" pivot = \"tip\",\n",
|
||||
" width = 0.005\n",
|
||||
" )\n",
|
||||
@ -198,14 +202,15 @@
|
||||
" sum(elastic_ys),\n",
|
||||
" pivot = \"tip\",\n",
|
||||
" scale = 5,\n",
|
||||
" angles = \"xy\",\n",
|
||||
" color = \"red\"\n",
|
||||
" )\n",
|
||||
" \n",
|
||||
"\n",
|
||||
"interact(\n",
|
||||
" do_plot,\n",
|
||||
" dp_x = (-1.0, 1.0, 0.05),\n",
|
||||
" dp_y = (-1.0, 1.0, 0.05)\n",
|
||||
" dp_x = (-1.5, 1.5, 0.05),\n",
|
||||
" dp_y = (-1.5, 1.5, 0.05)\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
@ -216,6 +221,14 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f283012a-6b7c-48c3-8bdc-f45f5b458edc",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user