455 lines
66 KiB
Plaintext
Raw Normal View History

2022-04-07 18:46:57 +02:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Description\n",
"\n",
"This notebook intends to gather all the functionalities you'll have to implement for assignment 2.2.\n",
"\n",
"# Load libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import igl\n",
"import meshplot as mp\n",
"import time\n",
"\n",
"import sys as _sys\n",
"_sys.path.append(\"../src\")\n",
"from elasticsolid import *\n",
"from elasticenergy import *\n",
"from matplotlib import gridspec\n",
"import matplotlib.pyplot as plt\n",
"\n",
"shadingOptions = {\n",
" \"flat\":True,\n",
" \"wireframe\":False, \n",
"}\n",
"\n",
"rot = np.array(\n",
" [[1, 0, 0 ],\n",
" [0, 0, 1],\n",
" [0, -1, 0 ]]\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load mesh\n",
"\n",
"Several meshes are available for you to play with under `data/`: `ball.obj`, `dinosaur.obj`, and `beam.obj`. You can also uncomment the few commented lines below to manipulate a simple mesh made out of 2 tetrahedra."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fb09ceba0f474ff6a670b5386fe53817",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-1.987469…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
" v, _, _, t, _, _ = igl.read_obj(\"../data/dinosaur.obj\")\n",
"#v, _, _, t, _, _ = igl.read_obj(\"../data/beam.obj\")\n",
"\n",
"# t = np.array([\n",
"# [0, 1, 2, 3],\n",
"# [1, 2, 3, 4]\n",
"# ])\n",
"# v = np.array([\n",
"# [0., 0., 0.],\n",
"# [1., 0., 0.],\n",
"# [0., 1., 0.],\n",
"# [0., 0., 1.],\n",
"# [2/3, 2/3, 2/3]\n",
"# ])\n",
"\n",
"be = igl.edges(igl.boundary_facets(t))\n",
"e = igl.edges(t)\n",
"\n",
"aabb = np.max(v, axis=0) - np.min(v, axis=0)\n",
"length_scale = np.mean(aabb)\n",
"\n",
"p = mp.plot(v @ rot.T, t, shading=shadingOptions)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Linear/Non-Linear Elastic Solid\n",
"\n",
"## Instantiation\n",
"\n",
"We first specify the elasticity model to use for the elastic solid, as well as pinned vertices, and volumetric forces."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"rho = 131 # [kg.m-3]\n",
"young = 10e6 # [Pa] \n",
"poisson = 0.2\n",
"force_mass = np.zeros(shape = (3,))\n",
"force_mass[2] = - rho * 9.81\n",
"\n",
"minX = np.min(v[:, 0])\n",
"pin_idx = np.arange(v.shape[0])[v[:, 0] < minX + 0.2*aabb[0]]\n",
"\n",
"lin_ee = LinearElasticEnergy(young, poisson)\n",
"neo_ee = NeoHookeanElasticEnergy(young, poisson)\n",
"\n",
"lin_solid = ElasticSolid(v, t, lin_ee, rho=rho, pin_idx=pin_idx, f_mass=force_mass)\n",
"neo_solid = ElasticSolid(v, t, neo_ee, rho=rho, pin_idx=pin_idx, f_mass=force_mass)\n",
"\n",
"solid = neo_solid\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Deform the mesh\n",
"\n",
"This should now involve elastic forces computation."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/notebooks/assignment_2_2/notebook/../src/elasticenergy.py:145: RuntimeWarning: invalid value encountered in log\n",
" self.logJ = np.log(np.linalg.det(jac))\n",
"/opt/notebooks/assignment_2_2/notebook/../src/elasticenergy.py:131: RuntimeWarning: invalid value encountered in log\n",
" j = np.log(np.linalg.det(jac))\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "327564baf8ad4d3fb73b223d8fd921f9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-0.865849…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"v_def = v.copy()\n",
"v_def[:, 0] *= 2.\n",
"solid.update_def_shape(v_def)\n",
"\n",
"p = mp.plot(solid.v_def @ rot.T, solid.t, shading=shadingOptions)\n",
"p.add_points(solid.v_def[solid.pin_idx, :] @ rot.T, shading={\"point_color\":\"black\", \"point_size\": 0.1 * length_scale})\n",
"forcesScale = 2 * np.max(np.linalg.norm(solid.f_ext, axis=1))\n",
"p.add_lines(solid.v_def @ rot.T, (solid.v_def + solid.f_ext / forcesScale) @ rot.T)\n",
"p.add_edges(v @ rot.T, be, shading={\"line_color\": \"blue\"})\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Find equilibrium\n",
"\n",
"We compare different methods: number of steps, computation time."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"n_steps = 1000\n",
"thresh = 1.\n",
"v_init = v.copy()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Gradient descent"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "59861d218fad43e6b57b45bed934c9a3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-1.987468…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"report_GD = equilibrium_convergence_report_GD(solid, v_init, n_steps, 5e-5, thresh=thresh)\n",
"energies_el_GD = report_GD['energies_el']\n",
"energies_ext_GD = report_GD['energies_ext']\n",
"energy_GD = energies_el_GD + energies_ext_GD\n",
"residuals_GD = report_GD['residuals']\n",
"times_GD = report_GD['times']\n",
"idx_stop_GD = report_GD['idx_stop']\n",
"v_def_GD = solid.v_def.copy()\n",
"\n",
"# Lastly, plot the resulting shape\n",
"p = mp.plot(v_def_GD @ rot.T, solid.t, shading=shadingOptions)\n",
"forcesScale = 2 * np.max(np.linalg.norm(solid.f_ext, axis=1))\n",
"p.add_lines(v_def_GD @ rot.T, (solid.v_def + solid.f_ext / forcesScale) @ rot.T)\n",
"p.add_points(v_def_GD[pin_idx, :] @ rot.T, shading={\"point_color\":\"black\", \"point_size\": 0.1 * length_scale})\n",
"p.add_edges(v @ rot.T, be, shading={\"line_color\": \"blue\"})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## BFGS\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4fac36847fef413586d1026fc645eeae",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-3.283369…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"report_BFGS = equilibrium_convergence_report_BFGS(solid, v_init, n_steps, 1e-7, thresh=thresh)\n",
"energies_el_BFGS = report_BFGS['energies_el']\n",
"energies_ext_BFGS = report_BFGS['energies_ext']\n",
"energy_BFGS = energies_el_BFGS + energies_ext_BFGS\n",
"residuals_BFGS = report_BFGS['residuals']\n",
"times_BFGS = report_BFGS['times']\n",
"idx_stop_BFGS = report_BFGS['idx_stop']\n",
"v_def_BFGS = solid.v_def.copy()\n",
"\n",
"# Lastly, plot the resulting shape\n",
"p = mp.plot(v_def_BFGS @ rot.T, solid.t, shading=shadingOptions)\n",
"forcesScale = 2 * np.max(np.linalg.norm(solid.f_ext, axis=1))\n",
"p.add_lines(v_def_BFGS @ rot.T, (solid.v_def + solid.f_ext / forcesScale) @ rot.T)\n",
"p.add_points(v_def_BFGS[pin_idx, :] @ rot.T, shading={\"point_color\":\"black\", \"point_size\": 0.1 * length_scale})\n",
"p.add_edges(v @ rot.T, be, shading={\"line_color\": \"blue\"})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Compare the different algorithms"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAloAAAGHCAYAAABoE/yGAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAABVm0lEQVR4nO3dd5xU1fnH8c+zvS9IR5qgIKIggtgSXYwaK9ZobLFEYyyJxqixROz+1CgxxhY1xi4ajBqxxrJixQ7SREWa9L4LbD+/P+6dYXbZMgNzZ3Z3vu/Xa147c9t5nrvL7sM5595rzjlEREREJP7Skh2AiIiISHulQktEREQkICq0RERERAKiQktEREQkICq0RERERAKiQktEREQkICq0RNoAM7vWzKa1sM3dZlYaQNvOzI6L93FbIzMrNbO7t/IY/fxzNjJecTXRziNmNjHINkRk66nQEtlK/h88579qzGy+md1nZh3j2MztwH5xPF5KM7PTzay8kVXHAFds5eEXAD2Ar7byOACYWYn/s9W5waoLgVPi0YaIBCcj2QGItBNvAqfi/ZvaCXgY6ACcGI+DO+fKgcYKA4kj59yqOByjFlgSh3Baamdt0G2IyNZTj5ZIfFQ655Y45xY6594AngEOitzAzM4wsxlmVmFms83sD2aWFrH+HH95hZktN7PXzSzDX1dv6NDM0s3sdjNb7b/uBNIbtLfZMFjD4SYzO9jM3vOPscpvc3BziZrZWDObZ2aVZrbEzB5rZtt0M/unmf1gZhvN7Fszu6xB3ruY2Vt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WiIiISFumQktEREQkIK32PlqdO3d2/fr1C7SN9evXk5/f6A2t271UzT1
"text/plain": [
"<Figure size 720x432 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"cmap = plt.get_cmap('viridis')\n",
"colors = cmap(np.linspace(0., 1., 4))\n",
"\n",
"gs = gridspec.GridSpec(nrows=1, ncols=1, width_ratios=[1], height_ratios=[1])\n",
"fig = plt.figure(figsize=(10, 6))\n",
"\n",
"axTmp = plt.subplot(gs[0, 0])\n",
"axTmp.plot(times_GD[:idx_stop_GD+1], residuals_GD[:idx_stop_GD+1], c=colors[0], \n",
" label=\"Gradient Descent ({:}its)\".format(idx_stop_GD))\n",
"axTmp.plot(times_BFGS[:idx_stop_BFGS+1], residuals_BFGS[:idx_stop_BFGS+1], c=colors[2], \n",
" label=\"BFGS ({:}its)\".format(idx_stop_BFGS))\n",
"y_lim = axTmp.get_ylim()\n",
"axTmp.set_title(\"Residuals as optimization goes\", fontsize=14)\n",
"axTmp.set_xlabel(\"Computation time [s]\", fontsize=12)\n",
"axTmp.set_ylabel(\"Force residuals [N]\", fontsize=12)\n",
"axTmp.set_ylim(y_lim)\n",
"plt.legend(fontsize=12)\n",
"plt.grid()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmMAAAGHCAYAAAD89VV0AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAABJ6UlEQVR4nO3deXxU5dn/8c+VdUImJGELIAiCgoiKCIJiVbAuuOLC09aqFfe61da9DxX3/ty7PFatWuterEtF1NYdcV8ryK5SlEV2Akkg+/3745ykk5hlEmZyJjPf9+s1r8yc9brOTDJX7vs+55hzDhEREREJRlrQAYiIiIikMhVjIiIi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653f0m7cXOuT4tLP9v4ALn3HsdFaNIKjOzbLwi5jbn3B2N5i0AHnfO3RRIcC3w/7b8B9jHOfdJK4tLG7X0uRBJNZ16zFhj/niH/5jZ/4A3viPymkj+tYwKiThbR0Riy8xGmneh1J3NbCTe9bPygCcjlullZhfjtQb+OZhIpSNF87kQSVWdupvSzP6G18zew8xW4DW9nwzcY2a/wTuVejr/bdY/CZjuOntzoEjiuwQYijdm6XO8a0etiJi/Bm+M07nOufUdH54EpLXPhUhK6vTdlCIiIiKdWVJ1U4qIiIh0NirGRERERALUaceM9ejRww0cODCu+ygrKyM3Nzeu+0hUyj31ck/VvEG5K/fUkqp5Q7C5f/rpp+udcz2bmtdpi7GBAwfyySfxPdt81qxZjB8/Pq77SFTKfXzQYXS4VM0blLtyTy2pmjcEm7uZfdPcPHVTioiIiARIxZiIiIhIgFSMiYiIiARIxZiIiIhIgFSMiYiIiARIxZi
"text/plain": [
"<Figure size 720x432 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"gs = gridspec.GridSpec(nrows=1, ncols=1, width_ratios=[1], height_ratios=[1])\n",
"fig = plt.figure(figsize=(10, 6))\n",
"\n",
"axTmp = plt.subplot(gs[0, 0])\n",
"axTmp.plot(times_GD[:idx_stop_GD+1], energy_GD[:idx_stop_GD+1], c=colors[0], \n",
" label=\"Gradient Descent ({:}its)\".format(idx_stop_GD))\n",
"axTmp.plot(times_BFGS[:idx_stop_BFGS+1], energy_BFGS[:idx_stop_BFGS+1], c=colors[2], \n",
" label=\"BFGS ({:}its)\".format(idx_stop_BFGS))\n",
"y_lim = axTmp.get_ylim()\n",
"axTmp.set_title(\"Total energy as optimization goes\", fontsize=14)\n",
"axTmp.set_xlabel(\"Computation time [s]\", fontsize=12)\n",
"axTmp.set_ylabel(\"Energy [J]\", fontsize=12)\n",
"axTmp.set_ylim(y_lim)\n",
"plt.legend(fontsize=12)\n",
"plt.grid()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.7"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}